microsoft / microsoft/DirectXShaderCompiler
Ternary on a non-scalar loaded from a constant buffer
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
Description
Vague (and different than normal) error about non-scalar values in ternaries when those non-scalar values (say for example, a struct) comes from a constant buffer.
Steps to Reproduce
https://godbolt.org/z/qoed1s8f4
Expected Behavior
(produced with a RWByteAddressBuffer, not a ConstantBuffer)
<source>:##:##: error: conditional operator only supports results with numeric scalar, vector, or matrix types.
value = decider ? inBuffer.Load<MyStruct>(globalId) : inBuffer.Load<MyStruct>(globalId*2);
Actual Behavior
The ternary version compiles to dxil if validation is disabled (unconfirmed if it functions properly as the system it's in is complicated to test), but fails validation, and then also fails to compile to spirv.
The DXIL Validation error:
error: validation errors
Function: dx.hl.cast.handleToRes.%"struct.ConstantBuffer<MyStruct>" (i32, %dx.types.Handle): error: External function 'dx.hl.cast.handleToRes.%"struct.ConstantBuffer<MyStruct>" (i32, %dx.types.Handle)' is not a DXIL function.
Function: dx.hl.cast.handleToRes.%"struct.ConstantBuffer<MyStruct>" (i32, %dx.types.Handle): error: Function 'dx.hl.cast.handleToRes.%"struct.ConstantBuffer<MyStruct>" (i32, %dx.types.Handle)' uses resource in function signature.
<source>:39:13: error: Resource handle should returned by createHandle.
note: at '%6 = call %dx.types.Handle @"dx.op.createHandleForLib.struct.ConstantBuffer<MyStruct>"(i32 160, %"struct.ConstantBuffer<MyStruct>" %5)' in block '#0' of function 'main'.
<source>:39:13: error: Expect Cbuffer for CBufferLoad handle.
note: at '%6 = call %dx.types.Handle @"dx.op.createHandleForLib.struct.ConstantBuffer<MyStruct>"(i32 160, %"struct.ConstantBuffer<MyStruct>" %5)' in block '#0' of function 'main'.
<source>:39:13: error: opcode 'CreateHandleForLib' should only be used in 'Library'.
note: at '%6 = call %dx.types.Handle @"dx.op.createHandleForLib.struct.ConstantBuffer<MyStruct>"(i32 160, %"struct.ConstantBuffer<MyStruct>" %5)' in block '#0' of function 'main'.
Validation failed.
The SPIR-V error:
error: casting to type 'ConstantBuffer<MyStruct>' unimplemented
Environment
- DXC version 1.8.2403.37 (march 2024 patch 2)
- Host Operating System Windows 22H2 (Build 19045.4412)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked Godbolt reproduction and compare the ConstantBuffer case with the RWByteAddressBuffer case across the DXIL and SPIR-V compiler paths. Trace how the ternary expression and non-scalar loaded values are lowered, then verify that the result produces a valid diagnostic or valid output without the reported validation and casting errors.
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
- Mostly clear
- Newbie friendliness
- 35/100