Skip to content

[PIX] Fix debug variable storage layout - #8851

Open
Damyan Pepper (damyanp) wants to merge 1 commit into
users/damyanp/pix-fixes-09from
users/damyanp/pix-fixes-10
Open

[PIX] Fix debug variable storage layout#8851
Damyan Pepper (damyanp) wants to merge 1 commit into
users/damyanp/pix-fixes-09from
users/damyanp/pix-fixes-10

Conversation

@damyanp

@damyanp Damyan Pepper (damyanp) commented Aug 27, 2026

Copy link
Copy Markdown
Member

Part 10 of 14 in the PIX instrumentation stack. It targets users/damyanp/pix-fixes-09. Its content depends on PR 2 for the shared helpers.

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

This changes only the PIX instrumentation, so it needs no release note.


Stack created with GitHub Stacks CLIGive Feedback 💬

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
@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

✅ With the latest revision this PR passed the C/C++ code formatter.

@damyanp
Damyan Pepper (damyanp) marked this pull request as ready for review August 27, 2026 23:54
Copilot AI balanced review requested due to automatic review settings August 27, 2026 23:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

3 participants