microsoft / microsoft/DirectXShaderCompiler
Assigning a globallycoherent resource to a struct member results in a "global coherent mismatch" warning
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
While other RHIs still do not have dynamic resource indexing, it's convenient to implement a common platform-neutral interface with getters for various resource types. However, an issue seems to arise specifically when trying to return a globallycoherent annotated UAV from a function inside a structure. While the DXIL generated correctly annotates the resource as globallycoherent, the shader compilation result produces warnings. Please let me know if I missed something in the correct way to do this, thanks!
Description
Consider the following snippet:
struct Ret {RWTexture2D<float> v;};
// test.hlsl
Ret get_texture() {
globallycoherent RWTexture2D<float> output = ResourceDescriptorHeap[0];
Ret.v = output;
return Ret;
}
[numthreads(1, 1, 1)]
void CSMain() {
get_texture().v[uint2(0, 0)] = 1.0;
}
Compiling this as dxc.exe -E CSMain -T cs_6_6 -HV 2021 test.hlsl > test.dxil produces the following warning:
warning: implicit conversion from 'globallycoherent RWByteAddressBuffer' to 'RWByteAddressBuffer' loses globallycoherent annotation
However, there doesn't appear to be a clean way to propagate the annotation to the function's return type. For example, changing
struct Ret {RWTexture2D<float> v;};
to
struct Ret {globallycoherent RWTexture2D<float> v;};
will result in:
warning: 'globallycoherent' attribute only applies to variables and functions
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
Reproduce the warning with the test.hlsl snippet using dxc.exe -E CSMain -T cs_6_6 -HV 2021. Start by tracing how the globallycoherent annotation is handled when the resource is returned through Ret, then verify that the compiler no longer reports a global coherent mismatch while preserving the annotation in the generated DXIL.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100