microsoft / microsoft/DirectXShaderCompiler

`as` casts on integer constant swizzles result in invalid module bitcode (or assert in debug)

Open
#5,389 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug correctness
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 11h
Merged PRs (30d)
44

Description

Description
Compiling a compute shader that we generate from Dawn (Chromium WebGPU implementation) fails with "Invalid record".

Steps to Reproduce

Given the following compute shader:

01: Texture2DMS<float4> tint_symbol : register(t0);
02: Texture2DMS<float4> tint_symbol_1 : register(t1);
03: 
04: RWByteAddressBuffer tint_symbol_5 : register(u2);
05: 
06: [numthreads(1, 1, 1)]
07: void tint_symbol_6() {
08:   {
09:     for(int tint_symbol_7 = 0; (tint_symbol_7 < 4); tint_symbol_7 = (tint_symbol_7 + 1)) {
10:       tint_symbol_5.Store((4u * uint(tint_symbol_7)), asuint(tint_symbol.Load((0).xx, tint_symbol_7).x));
11:       tint_symbol_5.Store((16u + (4u * uint(tint_symbol_7))), asuint(tint_symbol_1.Load(int3(0, 0, 0), tint_symbol_7).x));
12:     }
13:   }
14:   return;
15: }
16: 

When compiling with DXC:

C:\src\dawn>.\out\debug\dxc /T cs_6_0 /E tint_symbol_6 1976.hlsl
1976.hlsl:11:89: warning: implicit truncation of vector type [-Wconversion]
      tint_symbol_5.Store((16u + (4u * uint(tint_symbol_7))), asuint(tint_symbol_1.Load(int3(0, 0, 0), tint_symbol_7).x));
                                                                                        ^
error: validation errors
Invalid record
Validation failed.

Note that the warning is not important. In fact, commenting out line 11 still produces and error. However, commenting out line 10, DXC manages to compile correctly.

Actual Behavior
The shader should compile.

Environment

  • DXC version: dxcompiler.dll: 1.7 - 1.7.2212.40 (e043f4a12); dxil.dll: 1.7(101.7.2212.36)
  • Host Operating System: Windows 10

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided HLSL compute shader with the specified DXC version and compare validation with line 10 present or removed. Trace the DXC validation path for the generated module; done means the shader compiles without an “Invalid record” error or debug assertion.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.