Crash when two vertex inputs of different width share a semantic
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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).
- 主要言語
- C++
- スター
- 3.7k
- フォーク
- 926
- 平均マージ
- 3日 22時間
- マージ済み PR(30日)
- 45
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/DirectXShaderCompiler のほかの issue
-
bug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
microsoft/DirectXShaderCompiler#9173 ·
メンテナーはふだん 2 日以内に返信
-
bug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
microsoft/DirectXShaderCompiler#9155 · コメント 4 件 ·
メンテナーはふだん 2 日以内に返信
-
bug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
microsoft/DirectXShaderCompiler#9135 ·
メンテナーはふだん 2 日以内に返信
-
DXC emits DW_LANG_C_plus_plus instead of DW_LANG_HLSL for HLSL対応中かも @rj123-nv が 18 日前に担当しました。 オープンbug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
microsoft/DirectXShaderCompiler#9087 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
microsoft/DirectXShaderCompiler#9086 ·
メンテナーはふだん 2 日以内に返信
microsoft/DirectXShaderCompiler の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
feature:config kind:docs os:windows toolchain:cmake triaged
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
arch-based bug niri
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
noctalia-dev/noctalia#5552 ·
メンテナーはふだん 1 日以内に返信