DirectXShaderCompiler
DirectXShaderCompiler copied to clipboard
Using templates in combination with `globallycoherent` fails to compile
The use of templates, in particular when used to specify a texture value type, fails to compile.
I'm expecting this to be completely valid as this works without the globallycoherent
specifier.
But instead this error is thrown:
error: 'globallycoherent' is not a valid modifier for a non-UAV type
globallycoherent RWTexture2D<T> output = ResourceDescriptorHeap[0];
^
Example shader, compiled with -HV 2021
:
template<typename T> void doSomething(uint2 pos) {
globallycoherent RWTexture2D<T> output = ResourceDescriptorHeap[0];
output[pos] = 0;
}
[numthreads(8,8,1)]
void main(uint2 threadId: SV_DispatchThreadID) {
doSomething<float>(threadId);
}
The general issue here is that DXC verifies declaration attributes during first-pass parsing. This just flat out doesn't work with templates. With templates the attribute validation needs to be performed when the declaration is instantiated. There is no good easy fix for this. We really need to refactor and restructure how HLSL attributes are validated.