microsoft / microsoft/DirectXShaderCompiler

Assigning a globallycoherent resource to a struct member results in a "global coherent mismatch" warning

Open
#6,092 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type-system
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.