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

Align Storage Access enums to spec #6642

Merged
merged 12 commits into from
Dec 3, 2024
Merged

Conversation

atlv24
Copy link
Contributor

@atlv24 atlv24 commented Dec 2, 2024

Connections
Fixes #6599

Description
Rename enum variants and change logic to match webgpu storage access spec as concluded in #6599.
Write-only storage access is now verified correctly, and as such two tests had to be updated to use TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES to get write-only access on the formats they were using.

Future work

  • make RON usages enum string based instead of hardcoded integers clean up bitflag serde #6644
  • renumber bitfields to not be all jumbled
  • Give BufferUses::STORAGE_WRITE_ONLY and TextureUses::STORAGE_WRITE_ONLY a different bit?
  • evaluate whether mapping wgt::BufferUsages::STORAGE -> hal::BufferUses::STORAGE_READ_WRITE and wgt::TextureUsages::STORAGE_BINDING -> hal::TextureUses::STORAGE_READ_WRITE in wgpu-core/src/conv.rs is correct.
  • Figure out what the hell is going on with BufferBarrier/TextureBarrier usage: Range<BufferUses> and usage: Range<TextureUses>. This smells real fishy, ranges of bitfields dont sound like they should work. They're not ordered. Why Range<BufferUses> #6645

Testing
Existing tests pass.

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 a review from a team as a code owner December 2, 2024 10:30
Copy link
Contributor

@nical nical left a comment

Choose a reason for hiding this comment

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

Nice, thanks!

I think that in the case of bgra8unorm-storage, we should not have to request TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES (for write-only access, which seems to be the case for at least the bgra8unorm-storage test). Instead, the write-only capability should be added automatically when the BGRA8UNORM_STORAGE feature is requested (and granted).

wgpu-core/src/device/resource.rs Outdated Show resolved Hide resolved
wgpu-core/src/device/resource.rs Show resolved Hide resolved
wgpu-core/src/device/resource.rs Show resolved Hide resolved
wgpu-hal/src/lib.rs Outdated Show resolved Hide resolved
wgpu-hal/src/metal/adapter.rs Outdated Show resolved Hide resolved
@atlv24 atlv24 requested a review from nical December 2, 2024 17:47
@jimblandy jimblandy requested a review from teoxoy December 2, 2024 17:57
@atlv24 atlv24 mentioned this pull request Dec 2, 2024
7 tasks
wgpu-types/src/lib.rs Outdated Show resolved Hide resolved
@atlv24 atlv24 requested a review from nical December 3, 2024 09:57
@atlv24
Copy link
Contributor Author

atlv24 commented Dec 3, 2024

apologies, i thought i was doing a favor fixing the fact that storage write wasnt being set for other storages. pushed a better fix

@nical nical enabled auto-merge (squash) December 3, 2024 10:00
@nical
Copy link
Contributor

nical commented Dec 3, 2024

Looks like some of the tests where you previously added "TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES" now need "BGRA8UNORM_STORAGE".

@atlv24
Copy link
Contributor Author

atlv24 commented Dec 3, 2024

@nical I just tested locally and thats not enough to fix it -- zero-init-texture-binding.ron uses Rgba8Unorm not Bgra8Unorm so the feature doesnt apply.

auto-merge was automatically disabled December 3, 2024 10:28

Head branch was pushed to by a user without write access

@nical nical merged commit 0b6571a into gfx-rs:trunk Dec 3, 2024
27 checks passed
/// A read-write or write-only buffer used in a bind group.
const STORAGE_READ_ONLY = 1 << 7;
/// A write-only storage buffer used in a bind group.
const STORAGE_WRITE_ONLY = 1 << 8;
Copy link
Member

Choose a reason for hiding this comment

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

This occupies the same bit as STORAGE_READ_WRITE.

/// Read-write or write-only storage buffer usage.
const STORAGE_READ_ONLY = 1 << 8;
/// Write-only storage buffer usage.
const STORAGE_WRITE_ONLY = 1 << 9;
Copy link
Member

Choose a reason for hiding this comment

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

This occupies the same bit as STORAGE_READ_WRITE.

| Tfc::STORAGE_WRITE
| Tfc::STORAGE_READ_ONLY
| Tfc::STORAGE_WRITE_ONLY
| Tfc::STORAGE_READ_WRITE
Copy link
Member

Choose a reason for hiding this comment

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

all_caps should not include read-write usage; it should be based on the read-write tier.

attachment | TextureUsages::STORAGE_BINDING
let (bgra8unorm_f, bgra8unorm) = if device_features.contains(Features::BGRA8UNORM_STORAGE) {
(
msaa_resolve | TextureFormatFeatureFlags::STORAGE_WRITE_ONLY,
Copy link
Member

Choose a reason for hiding this comment

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

With the changes in this PR, all the formats below that support TextureUsages::STORAGE_BINDING need at least one of the TextureFormatFeatureFlags::STORAGE_* flags to be enabled to be used as storage textures.

wgpu::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES bypasses guaranteed_format_features and that's why it gets the ray tracing example and one of the player tests passing.

With this PR it is effectively impossible to use/bind a storage texture (unless you enable TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES; which should not be required).

Running cargo run --bin wgpu-examples storage_texture results in:

wgpu error: Validation Error

Caused by:
In Device::create_bind_group
The adapter does not support write access for storage textures of format Rgba8Unorm

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.

Strange usage of TextureFormatFeatureFlags::STORAGE_READ_WRITE
3 participants