[PIX] Fix debug variable storage layout - #8851
Open
Damyan Pepper (damyanp) wants to merge 1 commit into
Open
Conversation
The debug passes tell PIX where each variable lives in the shadow storage. Four defects make that information disagree with the shader. The offset calculation ignores the full extent of an array, the padding in an aggregate, the position of a bitfield, and the layout of a matrix. An offset can therefore point into the storage of another variable. A dynamically indexed write to an alloca takes its register span from the length of the array. DxilAnnotateWithVirtualRegister records the true span in !pix-alloca-reg-write. The two values disagree for an array of aggregates, so a dynamic index can be limited against the wrong bound. IsAllocaRegisterWrite examines only one level of the ancestor GEP chain. A value three or more aggregates deep receives no metadata, so the debugger shows a stale value or no value. The function also uses a member index without a bound check and without a safe cast. The pass finds the storage of an embedded array by the name of the debug variable. DXC can flatten a multi-dimensional array and rename the module global. The debug variable keeps its name, so the lookup misses the global and every shadow store for that array is dropped. Two decisions are worth attention. IsAllocaRegisterWrite returns false for a member index that is not constant or is out of range, because a guess would attach metadata the debug record cannot honour. A backward move of the layout writes a message and continues, and a debug build does not stop the process. Assisted-by: Copilot Co-authored-by: Copilot App <[email protected]> Copilot-Session: 40dc9de3-617e-4caf-ab0d-fba0a033ed93
Damyan Pepper (damyanp)
requested a review
from Austin Kinross (austinkinross)
August 27, 2026 23:45
Contributor
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Austin Kinross (austinkinross)
approved these changes
Aug 27, 2026
Damyan Pepper (damyanp)
force-pushed
the
users/damyanp/pix-fixes-10
branch
from
August 27, 2026 23:53
85d2877 to
8658126
Compare
Damyan Pepper (damyanp)
marked this pull request as ready for review
August 27, 2026 23:54
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes PIX shadow-storage metadata so debugger variable locations better match shader layouts.
Changes:
- Corrects aggregate, array, bitfield, matrix, and constant-value handling.
- Uses annotated register spans and traverses deeper GEP chains.
- Adds extensive PIX regression coverage.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
lib/DxilPIXPasses/DxilDebugInstrumentation.cpp |
Uses metadata register spans for dynamic writes. |
lib/DxilPIXPasses/DxilDbgValueToDbgDeclare.cpp |
Corrects shadow-storage layout and global-array handling. |
lib/DxilPIXPasses/DxilAnnotateWithVirtualRegister.cpp |
Traverses ancestor GEP chains. |
tools/clang/unittests/HLSL/PixTest.cpp |
Adds pass-level regression tests. |
tools/clang/test/HLSLFileCheck/pix/DebugInstrumentation_dynamic_index_span.hlsl |
Tests dynamic-index payload sizing. |
tools/clang/test/HLSLFileCheck/pix/DbgValueToDbgDeclare_nested_aggregate_padding.hlsl |
Tests nested padding. |
tools/clang/test/HLSLFileCheck/pix/DbgValueToDbgDeclare_multidim_array.hlsl |
Tests flattened multidimensional arrays. |
tools/clang/test/HLSLFileCheck/pix/DbgValueToDbgDeclare_mixed_width_bitfields.hlsl |
Tests mixed-width bitfields. |
tools/clang/test/HLSLFileCheck/pix/DbgValueToDbgDeclare_matrix_after_padding.hlsl |
Tests matrix placement after padding. |
tools/clang/test/HLSLFileCheck/pix/DbgValueToDbgDeclare_front_and_tail_padding.hlsl |
Tests front and tail padding. |
tools/clang/test/HLSLFileCheck/pix/DbgValueToDbgDeclare_constant_local.hlsl |
Tests constant local shadow stores. |
tools/clang/test/HLSLFileCheck/pix/DbgValueToDbgDeclare_array_of_padded_structs.hlsl |
Tests arrays of padded structures. |
tools/clang/test/HLSLFileCheck/pix/DbgValueToDbgDeclare_aggregate_tail_padding.hlsl |
Tests aggregate tail padding. |
tools/clang/test/HLSLFileCheck/pix/DbgValueToDbgDeclare_16bit_tail_padding.hlsl |
Tests 16-bit tail padding. |
tools/clang/test/HLSLFileCheck/pix/DbgValueToDbgDeclare_16bit_bitfields.hlsl |
Tests 16-bit bitfields. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+1361
to
+1365
| // The register span for a dynamic write comes from the | ||
| // !pix-alloca-reg-write metadata the annotation pass attached to | ||
| // this instruction, so it always matches the virtual-register | ||
| // numbering the annotation pass assigned. | ||
| uint32_t MaxArraySize = std::max(1u, IandT->AllocaRegisterSize); |
Comment on lines
+889
to
+892
| llvm::DIType *OtherTy = | ||
| OtherDbgValue->getVariable()->getType().resolve(EmptyMap); | ||
| if (OtherTy != nullptr && DITypePeelTypeAlias(OtherTy) == UnaliasedTy) { | ||
| return true; |
Comment on lines
+393
to
+396
| uint64_t memberIndex = pStructMember->getLimitedValue(); | ||
| if (memberIndex > pStructType->getStructNumElements()) { | ||
| return false; | ||
| } |
Comment on lines
+377
to
+381
| for (auto *pAncestorGEP : AncestorGEPs) { | ||
| auto *pStructType = llvm::dyn_cast<llvm::StructType>( | ||
| pAncestorGEP->getPointerOperandType()->getPointerElementType()); | ||
| if (pStructType == nullptr) { | ||
| continue; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The debug passes tell PIX where each variable lives in the shadow storage. Four defects make that information disagree with the shader.
The offset calculation ignores the full extent of an array, the padding in an aggregate, the position of a bitfield, and the layout of a matrix. An offset can therefore point into the storage of another variable.
A dynamically indexed write to an alloca takes its register span from the length of the array. DxilAnnotateWithVirtualRegister records the true span in !pix-alloca-reg-write. The two values disagree for an array of aggregates, so a dynamic index can be limited against the wrong bound.
IsAllocaRegisterWrite examines only one level of the ancestor GEP chain. A value three or more aggregates deep receives no metadata, so the debugger shows a stale value or no value. The function also uses a member index without a bound check and without a safe cast.
The pass finds the storage of an embedded array by the name of the debug variable. DXC can flatten a multi-dimensional array and rename the module global. The debug variable keeps its name, so the lookup misses the global and every shadow store for that array is dropped.
Two decisions are worth attention. IsAllocaRegisterWrite returns false for a member index that is not constant or is out of range, because a guess would attach metadata the debug record cannot honour. A backward move of the layout writes a message and continues, and a debug build does not stop the process.
Assisted-by: Copilot
Stack created with GitHub Stacks CLI • Give Feedback 💬