MoltenVK icon indicating copy to clipboard operation
MoltenVK copied to clipboard

[mvk-error] SPIR-V to MSL conversion error: No backing variable for atomic operation.

Open awolven opened this issue 1 year ago • 1 comments

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); }

awolven avatar Jan 28 '24 00:01 awolven

This is a SPIRV-Cross bug. You should probably file an issue there.

cdavis5e avatar Jan 28 '24 01:01 cdavis5e