KhronosGroup / SPIRV-Cross

SPIRV-Cross is a practical tool and library for performing reflection on SPIR-V and disassembling SPIR-V back to high level languages.
Apache License 2.0
1.96k stars 549 forks source link

SPIR-V to MSL conversion error: No backing variable for atomic operation. #2272

Closed awolven closed 3 months ago

awolven commented 5 months ago

Forgive me if this is a repost. I was told to post this here instead of MoltenVK.

Trying to translate the following shader using the command: MoltenVKShaderConverter -gi "test.frag" -mo "./test.frag.metal" It seems atomics have been supported as far back as 2018 but this won't translate.

version 450

extension GL_ARB_separate_shader_objects : enable

extension GL_EXT_buffer_reference2 : require

extension GL_EXT_shader_explicit_arithmetic_types_int64 : require

layout(buffer_reference, std430, buffer_reference_align = 4) buffer _table { uint val; };

layout(set = 0, binding = 1) uniform uniformBuffer { uint64_t table; uint table_capacity; } ub;

uint hash(uint x) { x ^= x >> 16; x = 0x7feb352dU; x ^= x >> 15; x = 0x846ca68bU; x ^= x >> 16; return x; }

bool sethash (uint value) { if ( value == 0 ) return true;

uint slot = hash(value) % (ub.table_capacity - 1);

uint count = 0;

while ( count < 50 ) { uint prev = atomicCompSwap(_table(ub.table + uint64_t(slot)).val, 0, value); if ( prev == 0 || prev == value ) { return true; } count += 1;

slot = (slot + 1) % (ub.table_capacity - 1); } return false; }

void main () { sethash(10103); }

HansKristian-Work commented 3 months ago

Seems to be a bug with BDA + atomics.