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

Draft
wants to merge 7 commits into
base: trunk
Choose a base branch
from

Conversation

AsherJingkongChen
Copy link
Contributor

@AsherJingkongChen AsherJingkongChen commented Sep 7, 2024

Connections

Resolves #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 on Metal.

Add and sub are supported for atomic_float.

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

Some floating-point atomic operations won't be implemented in this PR:

  • atomicAnd
  • atomicOr
  • atomicXor

The supported atomic operations by Metal and Vulkan are checked (✅) below:

Function Implemented? Supported by vendors? Implemented? Supported by vendors?
f32 Metal Metal Vulkan Vulkan
atomicStore
atomicLoad
atomicAdd
atomicSub 🚧
atomicMax 🚧
atomicMin 🚧
atomicExchange
atomicCompareExchangeWeak

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
Contributor 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.

@AsherJingkongChen AsherJingkongChen changed the title feat: Add 32-bit floating-point atomics feat: Add 32-bit floating-point atomics (SHADER_FLT32_ATOMIC) Oct 9, 2024
@AsherJingkongChen
Copy link
Contributor Author

Plan: Add fallback implementation for floating-point atomics

Description

Currently, the addition operation works on some recent chips like M1 Pro, NVIDIA RTX 4060, etc.

Without native supports, we can use more available operation, integer atomics, to simulate floating-point atomics.

This should support the following functions:

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

@AsherJingkongChen AsherJingkongChen marked this pull request as draft October 10, 2024 12:23
@AsherJingkongChen AsherJingkongChen changed the title feat: Add 32-bit floating-point atomics (SHADER_FLT32_ATOMIC) feat: Add 32-bit floating-point atomics Oct 10, 2024
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.

Support floating-point atomics
1 participant