You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
-Zi: a single-member struct inside an array of structs gets the wrong DW_OP_bit_piece offset #9186
Shader debuggers show wrong or missing values for variables whose type is an array of structs containing a single-member struct, such as a wrapper type. In the repro below:
b[1].w.v has no piece covering its bits, so a debugger shows it as unavailable.
b[0].tag gets b[1].w.v's value written over it, so it silently shows the wrong number.
With three or more elements, each b[i].w.v shows another element's value.
At -O3, the correct piece for b[0].tag can be dropped entirely.
This directly affects SM 6.10 linear algebra matrices. dx::linalg::Matrix is a single-member wrapper around its handle, so in struct { Matrix held; uint tag; } holders[2], holders[1].held lands on holders[0].tag. It also affects other single-member wrappers (strongly typed IDs/handles) and one-field base classes.
A nested struct with two or more members, and a plain array of the wrapper type, are both unaffected.
The debug type is correct (S is 64 bits, tag at offset 32). At -O3, 11's piece disappears and 20 still lands on 32. Pixel, vertex and library targets behave the same.
Cause
In addDebugInfoForElements (lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp), the array stride is only recorded if (NumInstances > 1 && Elems.size() > 1) (line 208); otherwise DIArrayDims.clear() (line 225).
Splitting [2 x S] records a 64-bit stride.
Splitting [2 x W] yields a single element, so that stride is thrown away and [2 x i32] ends up with no dx.dbg.varlayout.
Later splitting (DxilConditionalMem2Reg.cpp:235 at -Od, SROA.cpp at -O3) then uses the element size, 32, as the stride.
A likely fix is to keep the inherited DIArrayDims when Elems.size() == 1. I haven't tested it.
Versions
Reproduces on v1.10.2611 (b6a4228f9), 1.10.2605.24 (c1e1fc784) and 1.7.2308.16.
ScalarReplAggregatesHLSL.cpp is unchanged on main (4488d1caf).
Related: #2072 added the dx.dbg.varlayout stride metadata; this is a gap in it. #8754 has a similar symptom but for mesh shader output arguments.
Activity