GCC 14.1/14.2 at -O2/-O3 miscompile resource component types (Texture2D<float4> becomes 4xU32)
Maintainer antworten meist innerhalb von 2 Tagen
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 72/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- cmake, cpp
- Bereich
- build-system, compilers
Rechercherichtung
Start with the GCC version guard in cmake/modules/HandleLLVMOptions.cmake and the resource-type remap in tools/clang/lib/CodeGen/CGHLSLMS.cpp; the report says -fno-if-conversion fixes the issue. Reproduce with GCC 14.2 Release and the Texture2D<float4> sampling example, then check that the shader validates and reflection reports float rather than uint.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Description
When DXC is built with GCC 14.1 or 14.2 at -O2/-O3 (the default Release flags), every typed SRV/UAV gets the wrong component type: Texture2D<float4> comes out as Texture2D<uint4>. On SM ≤ 6.6 this fails validation as soon as the resource is sampled. On SM 6.7+ the shader compiles without any error, but the binary carries the wrong metadata and reflection reports uint for float textures. Load is unaffected, so the bug stays hidden until something samples.
The output is already wrong at -fcgl, so the problem is in clang codegen, not in a DXIL pass. Cause: GCC miscompiles the "Boolean, 64-bit, and packed types are implemented with u32" remap in SetUAVSRV (tools/clang/lib/CodeGen/CGHLSLMS.cpp). The result is exactly inverted: plain types become U32, and the types that should be remapped keep their own kind. The difference is a single register-allocation change around a btq/cmovnc sequence. Here is a standalone C reduction, 14.2 vs 14.3 side by side: https://godbolt.org/z/s1W83v7sf (asm on 14.2: https://godbolt.org/z/EbxM1Mj4q).
- Affected versions: GCC 14.1/14.2 at -O2/-O3. GCC 12.x, 13.x, 14.3, 14.4, 15.x, 16.1 and clang are correct at every -O level, and 14.1/14.2 are correct at -O0/-O1/-Os. 14.2 is the default gcc-14 on Ubuntu 24.04 (
gcc-14package), 24.10 and 25.04, and on SteamOS. - Current guard doesn't help.
cmake/modules/HandleLLVMOptions.cmakeonly guards GCC 13 with-fno-unswitch-loops(PR109934), and that flag makes no difference here.-fno-if-conversionor-fno-tree-vrpfixes it. - Fix verified in DXC. Rebuilding only
CGHLSLMS.cppwith-fno-if-conversiongives the correctTexture2D<4xF32>, and the shader below validates. - Previous mention. This was noted in #8176 (damyanp: DXC doesn't build correctly with gcc-14, 14.2 affected, 14.3 not,
-fno-tree-vrpavoids a failure), but no guard or issue followed.
Suggested fix: a sibling guard, >= 14.0 AND < 14.3 → -fno-if-conversion, ideally reported with message(WARNING) so self-builders can see their toolchain is being compensated for. A gcc-14 CI leg would catch the next one; #7364's failure list looks like what this bug produces, so check-clang would likely flag it.
Steps to Reproduce
Build DXC with g++ 14.2 (-DCMAKE_BUILD_TYPE=Release, PredefinedParams.cmake), then run dxc -T cs_6_6 -E main repro.hlsl:
Texture2D<float4> tex : register(t0);
SamplerState samp : register(s0);
RWStructuredBuffer<float4> outBuf : register(u0);
[numthreads(1, 1, 1)]
void main(uint id : SV_DispatchThreadID) {
outBuf[id] = tex.SampleLevel(samp, float2(0.5, 0.5), 0);
}
Actual Behavior
error: validation errors
repro.hlsl:7:18: error: sample_* instructions require resource to be declared to return UNORM, SNORM or FLOAT.
With -Vd:
; tex texture u32 2d T0 t0 1
%5 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %2, %dx.types.ResourceProperties { i32 2, i32 1029 }) ; resource: Texture2D<4xU32>
Expected (clang build of the same commit): f32, { i32 2, i32 1033 }, Texture2D<4xF32>. -T cs_6_7 compiles without error and emits the u32 metadata.
Environment
- DXC version: main @ 31576b869 and main @ 75fba61 (libdxcompiler.so: 1.11(50-75fba619)(1.10.0.10050)), built with g++ 14.2.0 (Ubuntu 14.2.0-4ubuntu2~24.04.1), Release (-O3)
- Host Operating System: SteamOS; Ubuntu 24.04.5 LTS x86_64
- Vorherrschende Sprache
- C++
- Sterne
- 3.7k
- Forks
- 926
- Ø Merge
- 3 T. 22 Std.
- Gemergte PRs (30 T.)
- 45
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus microsoft/DirectXShaderCompiler
-
bug needs-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
microsoft/DirectXShaderCompiler#9173 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
bug needs-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
microsoft/DirectXShaderCompiler#9155 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 2 Tagen
-
bug needs-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
microsoft/DirectXShaderCompiler#9135 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
DXC emits DW_LANG_C_plus_plus instead of DW_LANG_HLSL for HLSLEvtl. vergeben @rj123-nv hat das vor 18 Tagen übernommen. Offenbug needs-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
microsoft/DirectXShaderCompiler#9087 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
microsoft/DirectXShaderCompiler#9086 ·
Maintainer antworten meist innerhalb von 2 Tagen
Alle Issues in microsoft/DirectXShaderCompiler
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
Maintainer antworten meist innerhalb von 1 Tag
-
table_translator 当一个 Prism 键映射到多个原码时,首个候选未按权重排序Evtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
feature:config kind:docs os:windows toolchain:cmake triaged
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
arch-based bug niri
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
noctalia-dev/noctalia#5552 ·
Maintainer antworten meist innerhalb von 1 Tag