Hello,
I'm trying to implement an A-buffer algorithm in Metal, and I am getting this error when trying to use atomic_exchange_explicit() in a fragment shader:
"Execution of the command buffer was aborted due to an error during execution. Internal Error (IOAF code 1)"
I'm trying to exchange values in a screen-size buffer of uint32's. declared as device atomic_uint. I've been able to use atomic_fetch_add_explicit on a single uint counter, but it is giving me this error when trying to operate on the larger buffer. Any idea why that would happen? Here's the shader code:
fragment void stroke_abuffer_fragment(VertexIn interpolated [[stage_in]],
const device uint& color [[ buffer(0) ]],
constant Uniforms& uniforms [[ buffer(1) ]],
device FragLink* LinkBuffer [[ buffer(3) ]],
device atomic_uint &counter[[buffer(2)]],
device atomic_uint *StartBuffer[[buffer(4)]]
) {
uint pos = int(interpolated.position.x)+int(interpolated.position.y)*uniforms.displaySize[0];
uint value = atomic_fetch_add_explicit(&counter, 1, memory_order_relaxed);
value += 1;
FragLink F;
F.color = color;
F.depth = interpolated.position.z;
F.next = atomic_exchange_explicit(&StartBuffer[pos], value, memory_order_relaxed);
LinkBuffer[value] = F;
}
Thanks
Bob
Okay, I finally got this sorted out after several hours of utter incomprehension. It was several problems actually. The most frustrating was that after I bound my large buffer, I was unknowingly binding another buffer to the same index in a diffent part of the program. So Dan you were right, it was overwriting the buffer bounds because it was bound to the wrong buffer.
Then I ran into some issues because I was using 'UInt' in some places where I should have been using 'UInt32' - I didn't realize that 'UInt' is 8 bytes!
Anyway, it's working now, I can't believe it!