[HLSL] DXILLegalizePass assertion failure on dynamically-indexed local resource arrays
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
When compiling HLSL shaders that copy global resource array elements into a local resource array and then dynamically index the local array, clang-dxc crashes during the DXIL Legalizer pass.
Reproducer:
```hlsl
RWByteAddressBuffer gBufArray[4] : register(u0);
[numthreads(1,1,1)]
void main(uint3 tid : SV_DispatchThreadID) {
RWByteAddressBuffer arr[2];
arr[0] = gBufArray[0];
arr[1] = gBufArray[1];
arr[tid.x & 1].Store(0, 42);
}
```
Command:
`clang-dxc -T cs_6_0 -Fo out.o source.hlsl`
Error and stack trace:
```
error: Load of "arrayidx4.i4" is not a global resource handle
Assertion failed: ArrayTy->getArrayElementType() == LoadStoreTy &&
"Expected array element type to be the same as to the scalar load or store type",
file llvm/lib/Target/DirectX/DXILLegalizePass.cpp, line 448
Stack dump:
0. Program arguments: clang-dxc -T cs_6_0 -Fo out.o source.hlsl
1. parser at end of file
2. Code generation
3. Running pass 'Function Pass Manager' on module 'source.hlsl'
4. Running pass 'DXIL Legalizer' on function '@main'
#0 HandleAbort (llvm/lib/Support/Windows/Signals.inc:371)
#1 ucrtbased.dll+0x99e77
#2 ucrtbased.dll+0x9bab9
#3 ucrtbased.dll+0xa141f
#4 ucrtbased.dll+0x9f351
#5 ucrtbased.dll+0xa1c7f
#6 legalizeScalarLoadStoreOnArrays (llvm/lib/Target/DirectX/DXILLegalizePass.cpp:450)
#7 std::invoke<...> (type_traits:1688)
#8 std::_Func_impl_no_alloc<...>::_Do_call (functional:885)
#9 std::_Func_class<...>::operator() (functional:930)
#10 DXILLegalizationPipeline::runLegalizationPipeline (llvm/lib/Target/DirectX/DXILLegalizePass.cpp:472)
#11 DXILLegalizeLegacy::runOnFunction (llvm/lib/Target/DirectX/DXILLegalizePass.cpp:529)
```
Impact: Local resource arrays with dynamic indexing (e.g., arr[tid.x & 1]) crash Clang's DXIL backend. Static indexing of local resource arrays works fine. The same shader compiles and runs correctly with DXC.
Contributor guide
Assessment
This issue has not been assessed yet.