Nested `static const` structs containing a matrix are miscompiled
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 55/100
Hướng nghiên cứu
Start with the reproducer shader and compile it with DXC; compare the three-level initializer with the working two-level case and the direct matrix store. Then read CGHLSLMSHelper::ReplaceConstStaticGlobals in tools/clang/lib/CodeGen/CGHLSLMSFinishCodeGen.cpp around line 1547. Done means nested static const matrix initializers preserve their values, the direct store yields 3, the conditional store yields 5, and the assertions-enabled build does not assert.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
When a static const struct is initialized from another static const struct, which is
itself initialized from a third one, and the innermost struct contains a matrix, DXC
loses the initializer:
- Release builds (v1.9.2602, v1.9.2609) silently treat the value as
undef. Depending on
how it is used this is either a silent miscompile (wrong value stored, no
diagnostic) or a confusing validation error ("Assignment of undefined values to UAV"). - An assertions-enabled build of
mainhitsDXASSERT(false, "invalid user of const static global")inCGHLSLMSHelper::ReplaceConstStaticGlobals
(tools/clang/lib/CodeGen/CGHLSLMSFinishCodeGen.cpp:1547), even when the globals are unused.
With only two levels of nesting (B b = {a}) everything works. Replacing the matrix with a
float4 also works; adding a sibling field next to the matrix (struct A { float2x2 m; float pad; })
does not help, so this seems unrelated to PR #8568.
Steps to Reproduce
static_const_matrix_select.hlsl:
struct A { float2x2 m; };
struct B { A a; };
struct C { B b; };
static const A a = {float2x2(1, 2, 3, 4)};
static const B b = {a};
static const C c = {b};
RWStructuredBuffer<float> output : register(u0);
[numthreads(1, 1, 1)]
void main() {
// c.b.a.m[1][0] is 3, so this should store 5.
output[0] = c.b.a.m[1][0] == 3.0f ? 5.0f : 7.0f;
}
dxc -T cs_6_0 -E main static_const_matrix_select.hlsl
Actual Behavior
Release v1.9.2609 compiles without any diagnostic, but stores 7:
call void @dx.op.bufferStore.f32(i32 69, %dx.types.Handle %1, i32 0, i32 0, float 7.000000e+00, ...)
The same shader with only two levels (struct B { A a; }; static const B b = {a}; and
b.a.m[1][0]) correctly stores 5.
Storing the value directly (output[0] = c.b.a.m[1][0];, see
static_const_matrix_use.hlsl) fails validation instead:
error: validation errors
static_const_matrix_use.hlsl:12:13: error: Assignment of undefined values to UAV.
note: at 'call void @dx.op.bufferStore.f32(i32 69, %dx.types.Handle %1, i32 0, i32 0, float undef, ...)'
On main built with LLVM_ENABLE_ASSERTIONS=ON, even the declarations alone (unused,
static_const_matrix.hlsl) assert:
Error: !(false)
File:
tools\clang\lib\CodeGen\CGHLSLMSFinishCodeGen.cpp(1547)
Func: CGHLSLMSHelper::ReplaceConstStaticGlobals.
invalid user of const static global
#00 CGHLSLMSHelper::ReplaceConstStaticGlobals (CGHLSLMSFinishCodeGen.cpp:1549)
#01 CGMSHLSLRuntime::FinishCodeGen (CGHLSLMS.cpp:3861)
#02 clang::CodeGen::CodeGenModule::Release (CodeGenModule.cpp:463)
#03 CodeGeneratorImpl::HandleTranslationUnit (ModuleBuilder.cpp:236)
Expected Behavior
output[0] is 5 (and 3 for the direct store), with no assert.
Environment
- DXC version: release v1.9.2609 (
1.9.2609.5 (01b62ad47)), v1.9.2602 (1.9.2602.17 (21d28f727));
assert onmain(c3a85328, 1.10.0.10001, built with assertions) - Host operating system: Windows Server 2025 (x64)
- Ngôn ngữ chính
- C++
- Star
- 3.7k
- Fork
- 926
- Merge trung bình
- 3 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 45
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/DirectXShaderCompiler
-
bug needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
microsoft/DirectXShaderCompiler#9173 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bug needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
microsoft/DirectXShaderCompiler#9155 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bug needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
microsoft/DirectXShaderCompiler#9135 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
DXC emits DW_LANG_C_plus_plus instead of DW_LANG_HLSL for HLSLCó thể đã có người làm @rj123-nv đã nhận 18 ngày trước. Đang mởbug needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
microsoft/DirectXShaderCompiler#9087 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
microsoft/DirectXShaderCompiler#9086 ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của microsoft/DirectXShaderCompiler
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
feature:config kind:docs os:windows toolchain:cmake triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
arch-based bug niri
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
noctalia-dev/noctalia#5552 ·
Maintainer thường phản hồi trong vòng 1 ngày