wgpu icon indicating copy to clipboard operation
wgpu copied to clipboard

Naga emits wrong HLSL for atomicMax() on u64 buffer

Open JMS55 opened this issue 1 year ago • 1 comments

Description Naga should be emitting buffer.InterlockedMax64, not buffer.InterlockedMax.

This only applies to RWByteAddressBuffer according to the spec.

This issue also applies to the other atomic functions.

Repro steps

@group(0) @binding(0) var<storage, read_write> buf: atomic<u64>;

atomicMax(&buf, 3147483647lu);

Platform Naga rev 82210e1c

JMS55 avatar Jun 30 '24 21:06 JMS55

Changing https://github.com/gfx-rs/wgpu/blob/92c8cf415c6c0d6dc9a89f60e36c4dc0bcb5a4b5/naga/src/back/hlsl/writer.rs#L1958 To

let width = match func_ctx.resolve_type(value, &module.types) {
    TypeInner::Scalar(Scalar { width: 8, .. }) => "64",
    _ => "",
};
write!(self.out, "{var_name}.Interlocked{fun_str}{width}(")?;

I think fixes it. Probably needs a test, and consideration for how it will work for texture atomics.

JMS55 avatar Jul 01 '24 05:07 JMS55