Skip to content
This repository was archived by the owner on Jan 29, 2025. It is now read-only.
This repository was archived by the owner on Jan 29, 2025. It is now read-only.

atomic load/store is not coherent #1488

@raphlinus

Description

@raphlinus

I've tried coding up my prefix sum example in WGSL; the code is in the prefix branch of compute-shader-101. It almost works, but the atomic stores sent by one workgroup are not coherently seen by atomic loads in another.

I'm not 100% sure what's going wrong, but a couple of clues. First, there's no coherent or volatile decoration on the StateBuf buffer in the naga spv output. The WGSL spec suggests OpMemberDecorate Volatile. I personally think coherent may be closer to what I need here, but am not sure; the distinction is pretty fuzzy to me.

Also, the loads and stores are mapping to OpAtomicLoad and OpAtomicStore. I'm not sure, but I think these may not do anything unless the Vulkan memory model is enabled. Or in any case there's no way to generate them from glsl unless the GL_KHR_memory_scope_semantics extension is enabled.

I did a little experimentation hacking on the spv assembly (adding Coherent/Volatile decoration), but was not able to get it to work. Doing a roundtrip through spirv-cross did, but that made a bigger change to the program, replacing atomicLoad with atomicAdd(, 0), and atomicStore with atomicExchange(). That did work correctly, suggesting that the problem is indeed respecting the atomic semantics, but of course with this kind of thing there's all sorts of things that can go wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions