Sergio0694/ComputeSharp

GloballyCoherentAttribute for StructuredBuffers

Avid29 opened this issue · 0 comments

Avid29 commented

Description (optional)

This section should contain an expanded description
of the proposal, if the title is not sufficient.

Rationale

The globallycoherent keyword would be a useful addition to be supported in the hlsl generator.

Proposed API

Adding an attribute to tag specify a StructuredBuffer should be marked globallycoherent.

Drawbacks

None

Alternatives

None

Other thoughts

Here's how I expect code generation would change with this proposal.

C# Code

[AutoConstructor]
[EmbeddedBytecode(DispatchAxis.XY)]
public partial struct SampleShader : IComputeShader
{
    [GloballyCoherent]
    ReadWriteBuffer<int> buffer;

    public void Execute()
    {
        ...
    }
}

Generated HLSL

cbuffer _ : register(b0)
{
    uint __x;
    uint __y;
    uint __z;
}

globallycoherent RWStructuredBuffer<int> sampleBuffer : register(u0);

[NumThreads(__GroupSize__get_X, __GroupSize__get_Y, __GroupSize__get_Z)]
void Execute(uint3 ThreadIds : SV_DispatchThreadID)
{
    if (ThreadIds.x < __x && ThreadIds.y < __y && ThreadIds.z < __z)
    {
        ...
    }
}