Crash when two vertex inputs of different width share a semantic
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 55/100
Direzione di ricerca
Start with SROA_Parameter_HLSL::allocateSemanticIndex and AllocateSemanticIndex in lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp, then trace how flattenArgument records semantic types. Reproduce with the included poc.hlsl and compare the left-wide and right-wide cases. Done means invalid overlapping semantics produce a diagnostic such as Semantic 'TEXCOORD' overlap without crashing or asserting.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
A vertex input struct with two members on the same semantic that flatten to a different number of rows is an invalid signature. DXC should reject it with Semantic 'TEXCOORD' overlap, and it does for most shapes. When the wider member is a struct of two or three float4 and comes first, DXC prints nothing and crashes while it writes the signature into the container: on an assertion in a build with assertions, on a null-pointer read without them, with a segmentation fault in the release build.
This is the assertion from #1771. The shape reported there (two members of equal width) is rejected today; the shapes below are not covered by that check.
The assertion is in DxilPSVWriter::SetPSVSigElement, lib/DxilContainer/DxilContainerAssembler.cpp, lines 1248–1255 at b43c5651:
DXASSERT_NOMSG(SE.GetRows() == SE.GetSemanticIndexVec().size()); // 1248
auto &SemIdx = SE.GetSemanticIndexVec();
...
for (uint32_t row = 0; row < SE.GetRows(); row++) {
if ((uint32_t)SemIdx[row] != m_SemanticIndexBuffer[offset + row]) { // 1255
The semantic-index vector is indexed by row, with only an assertion protecting the two sizes. Without assertions the vector is empty for this shader, so the read is from address 0.
Where the two sizes come apart, as far as I can tell from the code: semantic indices are assigned in SROA, in SROA_Parameter_HLSL::allocateSemanticIndex (lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp:4830–4867). It keeps one type per semantic name, recorded in flattenArgument from the last member that carries the semantic (lines 5549–5553; the members are visited from right to left). AllocateSemanticIndex (4774–4828) then walks that one type for every member with the semantic. So each member of such a group gets indices for the rightmost member's type instead of its own:
- When the member on the left is wider, the walk stops before its last rows, and its signature element has more rows than semantic indices. That is the assertion above.
- When the member on the right is wider, the walk runs past the entries of the member on the left. In a build with assertions that ends on
assert(false && "arg index out of bound")atScalarReplAggregatesHLSL.cpp:4806.
Steps to Reproduce
Three rows on the left, one row on the right, both on TEXCOORD0:
poc.hlsl
struct Inner { float4 x; float4 y; float4 z; };
struct S { Inner a : TEXCOORD0; float4 b : TEXCOORD0; };
struct VSOut { float4 pos : SV_Position; float4 c : TEXCOORD9; };
VSOut main(S s) { VSOut o; o.pos = s.a.x; o.c = s.b + s.a.z; return o; }
dxc -T vs_6_0 -E main poc.hlsl -Fo poc.dxil
The same with two rows on the left behaves the same:
poc_two_rows.hlsl
struct Inner { float4 x; float4 y; };
struct S { Inner a : TEXCOORD0; float4 b : TEXCOORD0; };
struct VSOut { float4 pos : SV_Position; float4 c : TEXCOORD9; };
VSOut main(S s) { VSOut o; o.pos = s.a.x; o.c = s.b + s.a.y; return o; }
Control, control.hlsl: the first shader with the second member on TEXCOORD3. It compiles on every build listed under Environment.
control.hlsl
struct Inner { float4 x; float4 y; float4 z; };
struct S { Inner a : TEXCOORD0; float4 b : TEXCOORD3; };
struct VSOut { float4 pos : SV_Position; float4 c : TEXCOORD9; };
VSOut main(S s) { VSOut o; o.pos = s.a.x; o.c = s.b + s.a.z; return o; }
Other shapes, in the same vertex shader (the two members of S, both on TEXCOORD0; the complete shaders are folded in below the table):
Members of S |
Release, and ASan without assertions | ASan with assertions |
|---|---|---|
float4 a; float4 b; |
error: Semantic 'TEXCOORD' overlap at 0. |
same |
float a; float b; (the #1771 repro; also as a pixel shader) |
same error | same |
float2 a; float4 b; |
same error | same |
float4x4 m; float4 b; |
same error | same |
float4 a; Inner b; (narrow, then wide; Inner has three float4) |
same error | assert(false && "arg index out of bound") at ScalarReplAggregatesHLSL.cpp:4806 in AllocateSemanticIndex |
Inner a; float4 b; (three float4, then one) |
no diagnostic, crash | the assertion at DxilContainerAssembler.cpp:1248 |
Inner a; float4 b; (two float4, then one) |
no diagnostic, crash | the assertion at DxilContainerAssembler.cpp:1248 |
The other six shapes as complete shaders
Equal width, two float4:
struct S { float4 a : TEXCOORD0; float4 b : TEXCOORD0; };
struct VSOut { float4 pos : SV_Position; float4 c : TEXCOORD9; };
VSOut main(S s) { VSOut o; o.pos = s.a; o.c = s.b; return o; }
Equal width, two float:
struct S { float a : TEXCOORD0; float b : TEXCOORD0; };
struct VSOut { float4 pos : SV_Position; float4 c : TEXCOORD9; };
VSOut main(S s) { VSOut o; o.pos = float4(s.a, 0, 0, 1); o.c = float4(s.b, 0, 0, 1); return o; }
The #1771 repro (pixel shader):
struct Input
{
float a : TEXCOORD0;
float b : TEXCOORD0;
};
float main(Input input) : SV_Target { return 1; }
float2, then float4:
struct S { float2 a : TEXCOORD0; float4 b : TEXCOORD0; };
struct VSOut { float4 pos : SV_Position; float4 c : TEXCOORD9; };
VSOut main(S s) { VSOut o; o.pos = float4(s.a, 0, 1); o.c = s.b; return o; }
Matrix, then float4:
struct S { float4x4 m : TEXCOORD0; float4 b : TEXCOORD0; };
struct VSOut { float4 pos : SV_Position; float4 c : TEXCOORD9; };
VSOut main(S s) { VSOut o; o.pos = s.m._m00_m01_m02_m03; o.c = s.b + s.m._m30_m31_m32_m33; return o; }
Narrow, then wide (float4, then Inner):
struct Inner { float4 x; float4 y; float4 z; };
struct S { float4 a : TEXCOORD0; Inner b : TEXCOORD0; };
struct VSOut { float4 pos : SV_Position; float4 c : TEXCOORD9; };
VSOut main(S s) { VSOut o; o.pos = s.a; o.c = s.b.z; return o; }
Actual Behavior
Build with assertions (AddressSanitizer): exit code 1. It stops on
Error: assert(SE.GetRows() == SE.GetSemanticIndexVec().size())
File: lib/DxilContainer/DxilContainerAssembler.cpp(1248)
Func: SetPSVSigElement
and then an ASan ILL report from the trap.
Stack of the assertion
#0 in llvm_assert_trap(...)
#1 in llvm_assert(...)
#2 in DxilPSVWriter::SetPSVSigElement(PSVSignatureElement0&, hlsl::DxilSignatureElement const&) libdxcompiler.so+0x12027c2
#3 in DxilPSVWriter::DxilPSVWriter(hlsl::DxilModule const&, unsigned int) libdxcompiler.so+0x12332df
#4 in hlsl::SerializeDxilContainerForModule(...) libdxcompiler.so+0x1280767
#5 in dxcutil::AssembleToContainer(dxcutil::AssembleInputs&) libdxcompiler.so+0xbb7632
#6 in dxcutil::ValidateAndAssembleToContainer(dxcutil::AssembleInputs&) libdxcompiler.so+0xbb7d1a
#7 in DxcCompiler::Compile(...)
Build with AddressSanitizer, assertions off: exit code 1, a null-pointer read in DxilPSVWriter::DxilPSVWriter.
ASan report
ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f4d110b2139 bp 0x7ffd0dea3a20 sp 0x7ffd0dea3610 T0)
The signal is caused by a READ memory access.
Hint: address points to the zero page.
#0 in DxilPSVWriter::DxilPSVWriter(hlsl::DxilModule const&, unsigned int) libdxcompiler.so+0xeb2139
#1 in hlsl::SerializeDxilContainerForModule(...)
#2 in dxcutil::AssembleToContainer(dxcutil::AssembleInputs&)
#3 in dxcutil::ValidateAndAssembleToContainer(dxcutil::AssembleInputs&)
#4 in DxcCompiler::Compile(...)
Release 1.9.2609.5: Segmentation fault, exit code 139.
No diagnostic is printed before the crash in any of the three builds. With the release build, the control and the first five rows of the table exit with code 5 and the overlap error.
Expected: error: Semantic 'TEXCOORD' overlap at 0. (or another diagnostic) and no crash.
The same shape was also compiled with the DXC that Dawn builds (1.10.2609.0, 5de1dbca) on Windows 11; its assertion is a report followed by a breakpoint instruction, which is where the process stops.
Environment
- DXC version
- Release 1.9.2609.5:
libdxcompiler.so: 1.9(5512-01b62ad4)(1.9.2609.5) - Built from source at
b43c5651d744e606552b3274668a160be21db0f8(main, 2026-11-24):libdxcompiler.so: 1.11(1-b43c5651)(1.10.0.10001), with AddressSanitizer, once with assertions and once without. - The code locations quoted above are the same on current main (
2600ae89a615); I have not compiled that revision.
- Release 1.9.2609.5:
- Host Operating System
- Ubuntu 24.04.4 LTS, x86_64, kernel 6.8.
- The Windows observation is from Windows 11 (10.0.26100).
- Lingua principale
- C++
- Stelle
- 3.7k
- Fork
- 926
- Merge medio
- 3g 22h
- PR unite (30g)
- 45
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di microsoft/DirectXShaderCompiler
-
bug needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
microsoft/DirectXShaderCompiler#9173 ·
I maintainer di solito rispondono entro 2 giorni
-
bug needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
microsoft/DirectXShaderCompiler#9155 · 4 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
bug needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
microsoft/DirectXShaderCompiler#9135 ·
I maintainer di solito rispondono entro 2 giorni
-
DXC emits DW_LANG_C_plus_plus instead of DW_LANG_HLSL for HLSLForse già presa @rj123-nv l’ha presa 18 giorni fa. Apertabug needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
microsoft/DirectXShaderCompiler#9087 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
microsoft/DirectXShaderCompiler#9086 ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di microsoft/DirectXShaderCompiler
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
feature:config kind:docs os:windows toolchain:cmake triaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
arch-based bug niri
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
noctalia-dev/noctalia#5552 ·
I maintainer di solito rispondono entro 1 giorno