KhronosGroup / KhronosGroup/SPIRV-Cross

Bindings overlapped for atomically accessed RWBuffer when cross compiled to MSL

Open
#2,102 2 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
GLSL
Stars
2.5k
Forks
713
Avg merge
2d 18h
Merged PRs (30d)
16

Description

Hello,

I am facing an issue while compiling a HLSL shader undergoing following stages of compilation from HLSL->SPIRV->MSL, using DXC and Spirv-Cross for IOS.

Scenario is that I have a constant buffer binded to a CS shader at bind point 0. I also do have a RWBuffer, accessed atomically and at the bind point 0.
In this case when the MSL is generated with the command line option **"--msl-decoration-binding"**; has a texture_buffer at a bindpoint 0 as well as a buffer at bindpoint 0 which is in the device space and can be accessed atomically.

**This creates an error in MSL compilation of bindings overlapped, for the two buffers i.e., the constant buffer and the atomically accessed buffer.**

Following is a Simple HLSL reproducer of the issue:

struct SimpleConstants{ float4 SomeVar; };
cbuffer g_SimpleConstantBuffer : register(b0){ SimpleConstants simpleConstants; };
RWBuffer g_SimpleRWBuffer : register(u0);
[numthreads(64, 1, 1)]
void CS_Simple( uint3 threadID : SV_DispatchThreadID)
{
uint offset = threadID.z;
uint writePos = 0;
uint valuea = simpleConstants.SomeVar.x;
InterlockedAdd(g_SimpleRWBuffer[offset], valuea, writePos);
g_SimpleRWBuffer[offset * 2] = offset;
}

One solution is that I manage bind points in HLSL itself to circumvent the issue, but is there a way to handle this particular case inside spirv-cross ?

Command lines used:
- dxc.exe -spirv -T cs_6_0 -E CS_Simple -Fo SimpleCS.spirv SimpleCS.hlsl
- spirv-cross.exe --msl --msl-ios --msl-version 20300 --msl-texture-buffer-native --msl-ios-use-simdgroup-functions --msl-argument-buffers --msl-decoration-binding --output SimpleCS.metal SimpleCS.spirv

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the two listed DXC and spirv-cross commands with the Simple HLSL reproducer, then trace the MSL resource-binding handling for --msl-decoration-binding and atomically accessed RWBuffer resources. Done means the generated MSL assigns non-overlapping bindings to the constant buffer and RWBuffer and compiles successfully for iOS.

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
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.