Skip to content
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 #6234

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from

Conversation

AsherJingkongChen
Copy link

@AsherJingkongChen AsherJingkongChen commented Sep 7, 2024

Connections

#1020

Description

It enables 32-bit floating point atomic operations on backends including Metal v3.0+ (Apple 7+). Currently, it does not support Vulkan, which has a feature flag VK_EXT_shader_atomic_float though.

However, Metal doesn't support all atomic operations and all address spaces. The Metal specification (2024-06-06) said:

Metal 3 supports the atomic_float for device memory only.

This indicates we can't have workgroup-level floating-point atomic value.

Add and sub are supported for atomic_float.

It means that there are some read-modify-write functions we can't use.

The supported atomic operations by Metal are checked below:

  • atomicStore
  • atomicLoad
  • atomicAdd
  • atomicSub
  • atomicMax
  • atomicMin
  • atomicAnd
  • atomicOr
  • atomicXor
  • atomicExchange
  • atomicCompareExchangeWeak (Though it is unimplemented on MSL backend)

In wgpu-types, I have added the feature flag SHADER_FLT32_ATOMIC.

Testing

  • On Apple M2 Pro

Checklist

  • Run cargo fmt.
  • Run cargo clippy. If applicable, add:
    • --target wasm32-unknown-unknown
    • --target wasm32-unknown-emscripten
  • Run cargo xtask test to run tests.
  • Add change to CHANGELOG.md. See simple instructions inside file.
  • Run cargo xtask validate msl to validate shaders.
  • Run cargo xtask validate spv to validate shaders.

* Current supported platforms: Metal
* Platforms to support in the future: Vulkan

Related issues or PRs:

* gfx-rs#1020
@AsherJingkongChen
Copy link
Author

AsherJingkongChen commented Sep 9, 2024

Update: Add support for Vulkan

Description

Currently, it supports Vulkan through the device extension VK_EXT_shader_atomic_float.

Some operations that Vulkan can but not Metal, are not supported here including:

  • Workgroup-level atomics
  • Min-Max atomic operations on f32

The supported atomic operations by Vulkan with VK_EXT_shader_atomic_float are checked below:

  • atomicStore
  • atomicLoad
  • atomicAdd
  • atomicSub
  • atomicMax
  • atomicMin
  • atomicAnd
  • atomicOr
  • atomicXor
  • atomicExchange
  • atomicCompareExchangeWeak

Note

The recent update has removed validation for AtomicFunction::Subtract in naga, so no backend supports it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant