Crash when two vertex inputs of different width share a semantic

Abierto
#9,172 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
55/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
cpp
Área
compilers

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug needs-triage

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") at ScalarReplAggregatesHLSL.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.
  • Host Operating System
    • Ubuntu 24.04.4 LTS, x86_64, kernel 6.8.
    • The Windows observation is from Windows 11 (10.0.26100).
Lenguaje dominante
C++
Estrellas
3.7k
Forks
926
Merge medio
3 d 22 h
PR fusionados (30 d)
45

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/DirectXShaderCompiler

Todos los issues de microsoft/DirectXShaderCompiler

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.