-
Notifications
You must be signed in to change notification settings - Fork 988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add 32-bit floating-point atomics (SHADER_FLOAT32_ATOMIC
)
#6234
feat: Add 32-bit floating-point atomics (SHADER_FLOAT32_ATOMIC
)
#6234
Conversation
* Current supported platforms: Metal * Platforms to support in the future: Vulkan Related issues or PRs: * gfx-rs#1020
* atomicSub for f32 in the previous commits is removed.
This comment was marked as outdated.
This comment was marked as outdated.
05a9ccc
to
f3c8da7
Compare
SHADER_FLT32_ATOMIC
)
Optional: Add fallback implementation for floating-point atomicsDescription Currently, the addition operation works on some recent chips like By using atomic CAS loop, we can ensure the operation is atomic, but it is slower. |
SHADER_FLT32_ATOMIC
)* Make branches tidy * Also revise old codes * Ensure the implementations are supported by Metal and Vulkan backends
SHADER_FLOAT32_ATOMIC
)
This comment was marked as outdated.
This comment was marked as outdated.
5d6f6c5
to
deb28a9
Compare
a445c8c
to
ae7245a
Compare
6f4b69a
to
b51332b
Compare
Sorry for taking so long to get to this. |
Thank you for all the effort you put into thoroughly researching this and implementing it! Besides the minor comments I left I have no other concerns. |
Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com>
Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com>
Connections
Resolves #1020
Description
The wgpu feature
SHADER_FLOAT32_ATOMIC
allows 32-bit floating point atomic operations on native backends:The implemented or supported (natively) atomic operations by Metal and Vulkan are listed in the table (✅ is true, ❌ is false):
f32
atomicLoad
atomicStore
atomicAdd
atomicSub
atomicMax
atomicMin
atomicAnd
atomicOr
atomicXor
atomicExchange
atomicCompareExchangeWeak
There are some floating-point atomic operations not implemented on some backends in this PR:
storage
address space: Metal 3 supports theatomic_float
for device memory only. (Page 247)atomicAnd
: This bitwise operation is designed for integer types, not floating-point ones.atomicOr
: This bitwise operation is designed for integer types, not floating-point ones.atomicXor
: This bitwise operation is designed for integer types, not floating-point ones.atomicMax
: Metal does not supportatomic_fetch_max_explicit
(Page 250) on floating-point types.atomicMin
: Metal does not supportatomic_fetch_min_explicit
(Page 250) on floating-point types.atomicCompareExchangeWeak
: Vulkan only supportOpAtomicCompareExchange
on integer types.There are some floating-point atomic operations implemented on all backends in this PR:
storage
address space:atomicLoad
atomicStore
atomicAdd
atomicSub
atomicExchange
There are some hacks in this PR implementation:
atomicSub
: Vulkan does not have subtraction for floating-point types (noOpAtomicFSub
). We can simulate it by adding the negated value. They are mathematically equivalent sinceA - v == A + (-v)
.Testing
atomicOps-float32
is added.numeric_builtins::float32_atomic
is added.Checklist
cargo fmt
.cargo clippy
. If applicable, add:--target wasm32-unknown-unknown
--target wasm32-unknown-emscripten
winit
does not compile on my device.cargo xtask test
to run tests.CHANGELOG.md
. See simple instructions inside file.cargo xtask validate
to validate shaders.