Skip to content

Comments

Fix non-deterministic DXIL/PDB output for resource arrays (#8171)#8175

Merged
damyanp merged 5 commits intomicrosoft:mainfrom
damyanp:8171
Feb 21, 2026
Merged

Fix non-deterministic DXIL/PDB output for resource arrays (#8171)#8175
damyanp merged 5 commits intomicrosoft:mainfrom
damyanp:8171

Conversation

@damyanp
Copy link
Member

@damyanp damyanp commented Feb 19, 2026

DxilMutateResourceToHandle iterates a DenseSet<Value *> to process ConstantExpr GEPs on resource array globals. DenseSet iteration order depends on pointer hash values, which vary across runs due to ASLR. For each GEP, mutateCandidates() destroys the old ConstantExpr and creates a new one, prepending it to the global's use list. The non-deterministic processing order produces a non-deterministic use list, which TranslateDxilResourceUses later iterates to create named handles - resulting in different name suffixes across compilations.

The fix is to change MutateValSet from DenseSet<Value *> to SetVector<Value *>, which preserves insertion order while maintaining O(1) lookup. Since collectCandidates() traverses the IR in a deterministic order, the insertion order is stable, producing a deterministic use list and consistent handle names.

Fixes #8171

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

Copy link
Collaborator

@bogner bogner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we were doing a larger refactor here I would strongly suggest that we modify the algorithm into a stricter insert-than-query approach, especially given how painfully close it is to one today.

However, for a small code change that trades some extra memory overhead for determinism this looks perfectly reasonable.

@damyanp damyanp marked this pull request as ready for review February 19, 2026 22:30
@damyanp damyanp enabled auto-merge (squash) February 20, 2026 22:38
@damyanp damyanp merged commit 737f1de into microsoft:main Feb 21, 2026
12 checks passed
@github-project-automation github-project-automation bot moved this from New to Done in HLSL Roadmap Feb 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

PDB output non-deterministic when using array of resources

4 participants