DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

Using templates in combination with `globallycoherent` fails to compile

Open DBouma opened this issue 2 years ago • 1 comments

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);
}

DBouma avatar Aug 09 '22 14:08 DBouma

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.

llvm-beanz avatar Oct 11 '22 18:10 llvm-beanz