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

Image atomics support #6706

Merged
merged 18 commits into from
Jan 13, 2025
Merged

Image atomics support #6706

merged 18 commits into from
Jan 13, 2025

Conversation

atlv24
Copy link
Collaborator

@atlv24 atlv24 commented Dec 11, 2024

Connections
Broken off from #5537

Description
Adds image atomics to Vulkan, DirectX, and Metal backends.

Testing
naga snapshot tests and runtime tests are included

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • 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.

@atlv24 atlv24 requested review from a team as code owners December 11, 2024 22:30
@atlv24 atlv24 mentioned this pull request Dec 11, 2024
6 tasks
@cwfitzgerald cwfitzgerald self-assigned this Dec 11, 2024
@atlv24 atlv24 force-pushed the image-atomics branch 5 times, most recently from 6685477 to d33c0ad Compare December 12, 2024 07:38
Copy link
Member

@jimblandy jimblandy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started reviewing with the Naga IR, and found something that should be addressed.

naga/src/lib.rs Outdated Show resolved Hide resolved
@jimblandy
Copy link
Member

@atlv24 I appreciate the docs!

@jimblandy

This comment was marked as outdated.

Copy link
Member

@jimblandy jimblandy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more requests.

naga/src/front/wgsl/lower/mod.rs Outdated Show resolved Hide resolved
naga/src/lib.rs Outdated Show resolved Hide resolved
naga/src/lib.rs Show resolved Hide resolved
@atlv24
Copy link
Collaborator Author

atlv24 commented Dec 16, 2024

@jimblandy what did you force push may i ask? and thanks for the review!

@jimblandy
Copy link
Member

@jimblandy what did you force push may i ask? and thanks for the review!

Just changing // to /// to make something a doc comment in the IR, in naga/src/lib.rs.

I always feel bad asking people to change stuff like that because it's trivial, so I just fix it myself, amend to keep the PR review a single commit, and force push. If you'd rather I not amend, that's fine. (And if you'd rather I make lots of minor change requests, I could do that too, but...)

@atlv24
Copy link
Collaborator Author

atlv24 commented Dec 16, 2024

nah its fine, was just curious. i can't see the diff and visual inspection yielded nothing

Copy link
Member

@jimblandy jimblandy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Validator::validate_entry_point, we have the following code:

let allowed_usage = match var.space {
    ...
    crate::AddressSpace::Private | crate::AddressSpace::WorkGroup => GlobalUse::all(),
    ...
};

By adding ATOMIC to GlobalUse, this became incorrect: atomic accesses to Private address space variables isn't permitted.

I think using atomics in local variables is already covered by Validator::validate_local_var, but validate_entry_point should still not say strange things.

@jimblandy
Copy link
Member

@atlv24 If it's ok, since I've requested some non-trivial changes, rather than finishing this review, I'm going to go review some other, simpler PRs first, and then come back to this one once you've got it revised.

@atlv24
Copy link
Collaborator Author

atlv24 commented Dec 16, 2024

@jimblandy thats fine. I am unsure how to remove the sample expression handle from the naga ir, because of the way spir-v wants to write cached expressions. before i added that field, i had tried for quite a while and not found a way to generate it on the fly once, so i settled on the dumb and simple solution.

@jimblandy
Copy link
Member

jimblandy commented Dec 17, 2024

@atlv24 If you call back::spv::Writer::get_constant_null, that should give you a SPIR-V id whose value is zero that you can use as the MS operand. That takes an argument that is a SPIR-V type id, which I think you can get from Writer::get_uint_type_id. Or, if it's easier, you could try Write::get_constant_scalar, something like here.

@atlv24 atlv24 force-pushed the image-atomics branch 2 times, most recently from 26598f2 to 00b45cc Compare December 18, 2024 04:25
@atlv24
Copy link
Collaborator Author

atlv24 commented Dec 18, 2024

@jimblandy resolved all feedback

@atlv24 atlv24 requested a review from jimblandy December 18, 2024 04:26
@atlv24 atlv24 force-pushed the image-atomics branch 2 times, most recently from 6c2359a to 5a4b0a8 Compare December 18, 2024 04:31
Copy link
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, we're getting close on the wgpu side.

I think we need some wgpu runtime tests of specifically the validation of:

  • Texture Usages
  • Wgpu Features

To ensure that they are correctly validated out when the features aren't enabled.

naga/tests/in/atomicTexture.param.ron Outdated Show resolved Hide resolved
wgpu-core/src/binding_model.rs Outdated Show resolved Hide resolved
wgpu-types/src/lib.rs Show resolved Hide resolved
wgpu-types/src/lib.rs Outdated Show resolved Hide resolved
@teoxoy
Copy link
Member

teoxoy commented Jan 9, 2025

Besides the few comments I left, the naga side of this looks good to me.

@teoxoy
Copy link
Member

teoxoy commented Jan 9, 2025

A design question that shouldn't block this PR is: Is it necessary to have an atomic access and atomic binding type? It seems to me that the atomic functionality works on read_write storage textures as long as the format supports atomic ops.

Co-authored-by: Teodor Tanasoaia <[email protected]>
@atlv24
Copy link
Collaborator Author

atlv24 commented Jan 10, 2025

Its needed because Metal needs atomic usage to be marked as a texture usage, and if we dont have the shader specify that a texture will be used atomically then we dont have a way to validate metal usage

Copy link
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, approving wgpu side.

I've also done a review of the naga side and I had a few comments, but everything looks fine @teoxoy can you just make sure that I didn't miss anything, then we can get this in.

naga/src/back/glsl/mod.rs Show resolved Hide resolved
naga/src/back/msl/writer.rs Outdated Show resolved Hide resolved
naga/src/back/wgsl/writer.rs Show resolved Hide resolved
naga/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Member

@teoxoy teoxoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@teoxoy teoxoy dismissed jimblandy’s stale review January 13, 2025 15:36

The concern was addressed.

@teoxoy teoxoy added this pull request to the merge queue Jan 13, 2025
Merged via the queue into gfx-rs:trunk with commit 18471d8 Jan 13, 2025
30 checks passed
@teoxoy
Copy link
Member

teoxoy commented Jan 14, 2025

Its needed because Metal needs atomic usage to be marked as a texture usage, and if we dont have the shader specify that a texture will be used atomically then we dont have a way to validate metal usage

Could you point out where metal requires this? For texture access I only see:

enum class access { sample, read, write, read_write };

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

Successfully merging this pull request may close these issues.

4 participants