Compute shader imageAtomicAdd / extensions

Godot Version

4.2.1 macos arm

Question

I’m trying to write a compute shader which requires atomic operations, specifically I’m trying to use imageAtomicAdd (imageAtomicAdd reference page).
This basic shader does not compile:

#[compute]
#version 450

layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
layout(rgba32f, binding = 0) uniform coherent image2D image_out;

void main() {
	ivec2 pixel = ivec2(gl_GlobalInvocationID.xy);
	imageAtomicAdd(image_out, pixel, 500); //arbitrary uint to test
}

The error godot shows is:
ERROR: 0:9: 'imageAtomicAdd' : required extension not requested: GL_EXT_shader_atomic_float

If I add the line:
#extension GL_EXT_shader_atomic_float:enable

that error goes away:
Shader stage compiled without errors.

However, I now get an error at runtime:
Node2D.gd:44 @ setup_compute(): vkCreateComputePipelines failed with error -1000012000.

Got the hint reading another forum post that it may be significant that this is a ‘vk’ (vulkan) error, and a ‘gl’ (opengl) extension might not work? So I tried instead using:
#extension VK_EXT_shader_atomic_float:enable
That gives the original required extension not requested error, plus this warning:
WARNING: 0:3: '#extension' : extension not supported: VK_EXT_shader_atomic_float

If anyone knows how I can make these extensions work, or otherwise how to perform an imageAtomicAdd operation, I would be very grateful! Thanks!

1 Like

Godot uses MoltenVK to add support for Vulkan on MacOS. It seems that MoltenVK does not support that extension Vulkan features available with Metal 3? · KhronosGroup/MoltenVK · Discussion #1616 · GitHub

Ah, MoltenVK… I was missing that link in the chain! Thanks!

After crawling through their issues and pr’s, it seems that it was implemented:

(at the very bottom of the issue you linked to, there is discussion about implementing it, which seemingly led to this PR: enable availability of EXT_shader_atomic_float by rcoreilly · Pull Request #1836 · KhronosGroup/MoltenVK · GitHub)

Clearly I’m still missing something though. Any more ideas would be much appreciated!