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

Expose adapter specific formats features via Extension, support for storage read+write #1112

Merged
merged 6 commits into from
Jan 6, 2021

Conversation

Wumpf
Copy link
Member

@Wumpf Wumpf commented Dec 30, 2020

Connections
Draft until gfx-rs/gfx#3559 landed (then update and comment two lines in)
New & improved replacement for #1109

PR for wgpu-rs to be opened once there's some confidence that this is that it should look like. Preview

Description
Adapter exposes now per texture format specific features. Feature struct defined as allowed usages + flags. Flags describe only storage texture usage so far.

Query not used for validation unless TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES feature is enabled on a device. Otherwise uses hardcoded feature set guaranteed by webgpu.
Storage read/write binding can then be used as a consequence (storage atomic has no effect yet).

Testing
Manual testing with my fluid sim project through wgpu-rs which covers storage r/w for a few different formats and storage in general for formats that don't support this usage by default at all.
Ran tests and a couple of samples to see if anything broke with the feature disabled.

Copy link
Contributor

@monocodus monocodus bot left a comment

Choose a reason for hiding this comment

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

This is an autogenerated code review.

Checker summary (by rust_clippy):
The tool has found 82 warnings, 0 errors.

wgpu-core/src/device/mod.rs Outdated Show resolved Hide resolved
wgpu-core/src/device/mod.rs Outdated Show resolved Hide resolved
@@ -132,7 +133,8 @@ impl<B: GfxBackend> Adapter<B> {

let mut features = wgt::Features::default()
| wgt::Features::MAPPABLE_PRIMARY_BUFFERS
| wgt::Features::PUSH_CONSTANTS;
| wgt::Features::PUSH_CONSTANTS
| wgt::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES;
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we actually need this feature. I.e. can we pretend it's always supported? On the Web, we can just return the statically known features (until WebGPU gets a proper extension).

Copy link
Member Author

Choose a reason for hiding this comment

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

That thought crossed my mind as well but what kept me from it is

  • (most important) one might develop a cross platform application (e.g. web + desktop) and unknowingly break its portability if this is not an explicit opt-in. Imho a huge selling point of wgpu(-rs) is that it formulates a feature set that will work on a very wide variety of devices
  • other things in the limits struct need to be requested explicitly as well and default to the webgpu specification (e.g. how many storage bindings are supported)
  • if and when WebGPU gets an extension this may fit more nicely as a "free-for-all tier"

Copy link
Member

Choose a reason for hiding this comment

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

That's a very good point! Ideally I'd love to make it so you can't use a feature that you haven't either discovered or requested. This should apply to format features as well. So what you are saying makes total sense, and is much appreciated!

We can also go a slightly different route and consider the format features to be "basic" unless the user asks for them. This would make the same code portable across the web and non-web.

Copy link
Member Author

Choose a reason for hiding this comment

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

consider the format features to be "basic" unless the user asks for them

You're thinking that the user can request particular texture features ahead of time? That would make sense in regard to how the limit struct works and keeps all the missing-feature surprises to the device selection rather than some random texture binding.

Or did you mean something else? :)
Otherwise, the way it's done here would already be a manual opt-in by the user, only that it's a bit vague what one ends up with :/

Copy link
Member

Choose a reason for hiding this comment

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

No, I wasn't think about "ahead of time" kind of thing as we do for limits. I was thinking more simple: if the user didn't call get_texture_features (or whatever it's called), then they can only assume the base guaranteed feature set for this format specifically (and we validate that).

flags |= wgt::TextureFormatFeatureFlags::STORAGE_ATOMICS;
}
// TODO: hal update
//if texture_format_properties.contains(hal::format::ImageFeature::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.

can now be implemented thanks to you!

Copy link
Member Author

Choose a reason for hiding this comment

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

😊
once we managed to upgrade to newest gfx that is :)

wgpu-types/src/lib.rs Show resolved Hide resolved
wgpu-types/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@monocodus monocodus bot left a comment

Choose a reason for hiding this comment

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

This is an autogenerated code review.

Checker summary (by rust_clippy):
The tool has found 82 warnings, 0 errors.

@Wumpf
Copy link
Member Author

Wumpf commented Jan 6, 2021

Support for read+write textures is all operational but will always fail validation right now (see commented out code with TODO note in get_texture_format_features) until gfx/hal is updated (necessary changes there have landed!). Update is blocked right now by zakarumych/gpu-alloc#33

@Wumpf Wumpf marked this pull request as ready for review January 6, 2021 17:19
Copy link
Contributor

@monocodus monocodus bot left a comment

Choose a reason for hiding this comment

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

This is an autogenerated code review.

Checker summary (by rust_clippy):
The tool has found 82 warnings, 0 errors.

Copy link
Member

@kvark kvark left a comment

Choose a reason for hiding this comment

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

Very nice, thank you!
bors r+

@kvark
Copy link
Member

kvark commented Jan 6, 2021

I was going back and forth on some pieces, thinking if they could be written better... but no, it's all really good 🕶️ .

@bors
Copy link
Contributor

bors bot commented Jan 6, 2021

@bors bors bot merged commit 8c00cbc into gfx-rs:master Jan 6, 2021
@Wumpf Wumpf deleted the adapter-specific-format-feature branch January 6, 2021 19:29
bors bot added a commit that referenced this pull request Jan 10, 2021
1140: Enable storage read/write format feature r=kvark a=Wumpf

**Connections**
#1112

**Description**
Use `wgt::TextureFormatFeatureFlags::STORAGE_READ_WRITE` in `get_texture_format_features`.
This has been waiting for a gfx update which was enabled by @elartista 's workaround in #1136 \o/

Co-authored-by: Andreas Reich <[email protected]>
bors bot added a commit to gfx-rs/wgpu-rs that referenced this pull request Jan 13, 2021
713: Expose texture format feature query (and update to latest wgpu) r=kvark a=Wumpf

Exposes texture format feature query from gfx-rs/wgpu#1112
Updating wgpu-core led to breaking change of moving get_swap_chain_preferred_format from device to adapter.

Co-authored-by: Andreas Reich <[email protected]>
kvark pushed a commit to kvark/wgpu that referenced this pull request Jun 3, 2021
713: Expose texture format feature query (and update to latest wgpu) r=kvark a=Wumpf

Exposes texture format feature query from gfx-rs#1112
Updating wgpu-core led to breaking change of moving get_swap_chain_preferred_format from device to adapter.

Co-authored-by: Andreas Reich <[email protected]>
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.

2 participants