-
Notifications
You must be signed in to change notification settings - Fork 923
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
Open
AsherJingkongChen
wants to merge
16
commits into
gfx-rs:trunk
Choose a base branch
from
AsherJingkongChen:pr/shader-flt32-atomic
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: Add 32-bit floating-point atomics (SHADER_FLOAT32_ATOMIC
)
#6234
AsherJingkongChen
wants to merge
16
commits into
gfx-rs:trunk
from
AsherJingkongChen:pr/shader-flt32-atomic
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* 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.
AsherJingkongChen
force-pushed
the
pr/shader-flt32-atomic
branch
from
October 9, 2024 00:09
05a9ccc
to
f3c8da7
Compare
AsherJingkongChen
changed the title
feat: Add 32-bit floating-point atomics
feat: Add 32-bit floating-point atomics (Oct 9, 2024
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. |
AsherJingkongChen
changed the title
feat: Add 32-bit floating-point atomics (
feat: Add 32-bit floating-point atomics
Oct 10, 2024
SHADER_FLT32_ATOMIC
)* Make branches tidy * Also revise old codes * Ensure the implementations are supported by Metal and Vulkan backends
AsherJingkongChen
changed the title
feat: Add 32-bit floating-point atomics
feat: Add 32-bit floating-point atomics (Oct 13, 2024
SHADER_FLOAT32_ATOMIC
)
This comment was marked as outdated.
This comment was marked as outdated.
AsherJingkongChen
force-pushed
the
pr/shader-flt32-atomic
branch
from
November 1, 2024 14:19
5d6f6c5
to
deb28a9
Compare
AsherJingkongChen
force-pushed
the
pr/shader-flt32-atomic
branch
from
November 1, 2024 14:57
a445c8c
to
ae7245a
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.