-
Notifications
You must be signed in to change notification settings - Fork 983
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
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0ccad9a
wip adapter specific format features & rw storage
Wumpf 4207e57
validation against adapter specific format features
Wumpf c17b2dc
Expose adapter_get_texture_format_features
Wumpf 757d12a
map depth/stencil feature to RENDER_ATTACHMENT
Wumpf e29d17a
wgpu format features are again part of TextureFormatInfo
Wumpf 30c96bf
Added note on why hal update needed for STORAGE_READ_WRITE is blocked…
Wumpf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,6 +120,7 @@ impl crate::hub::Resource for Surface { | |
pub struct Adapter<B: hal::Backend> { | ||
pub(crate) raw: hal::adapter::Adapter<B>, | ||
features: wgt::Features, | ||
private_features: PrivateFeatures, | ||
limits: wgt::Limits, | ||
life_guard: LifeGuard, | ||
} | ||
|
@@ -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; | ||
features.set( | ||
wgt::Features::DEPTH_CLAMPING, | ||
adapter_features.contains(hal::Features::DEPTH_CLAMP), | ||
|
@@ -181,6 +183,20 @@ impl<B: GfxBackend> Adapter<B> { | |
//TODO: https://github.com/gfx-rs/gfx/issues/3346 | ||
features.set(wgt::Features::ADDRESS_MODE_CLAMP_TO_BORDER, true); | ||
|
||
let private_features = PrivateFeatures { | ||
anisotropic_filtering: adapter_features.contains(hal::Features::SAMPLER_ANISOTROPY), | ||
texture_d24: raw | ||
.physical_device | ||
.format_properties(Some(hal::format::Format::X8D24Unorm)) | ||
.optimal_tiling | ||
.contains(hal::format::ImageFeature::DEPTH_STENCIL_ATTACHMENT), | ||
texture_d24_s8: raw | ||
.physical_device | ||
.format_properties(Some(hal::format::Format::D24UnormS8Uint)) | ||
.optimal_tiling | ||
.contains(hal::format::ImageFeature::DEPTH_STENCIL_ATTACHMENT), | ||
}; | ||
|
||
let adapter_limits = raw.physical_device.limits(); | ||
|
||
let default_limits = wgt::Limits::default(); | ||
|
@@ -228,11 +244,60 @@ impl<B: GfxBackend> Adapter<B> { | |
Self { | ||
raw, | ||
features, | ||
private_features, | ||
limits, | ||
life_guard: LifeGuard::new("<Adapter>"), | ||
} | ||
} | ||
|
||
pub(crate) fn get_texture_format_features( | ||
&self, | ||
format: wgt::TextureFormat, | ||
) -> wgt::TextureFormatFeatures { | ||
let texture_format_properties = self | ||
.raw | ||
.physical_device | ||
.format_properties(Some(conv::map_texture_format( | ||
format, | ||
self.private_features, | ||
))) | ||
.optimal_tiling; | ||
|
||
let mut allowed_usages = wgt::TextureUsage::empty(); | ||
if texture_format_properties.contains(hal::format::ImageFeature::SAMPLED) { | ||
allowed_usages |= wgt::TextureUsage::SAMPLED; | ||
} | ||
if texture_format_properties.contains(hal::format::ImageFeature::STORAGE) { | ||
allowed_usages |= wgt::TextureUsage::STORAGE; | ||
} | ||
if texture_format_properties.contains(hal::format::ImageFeature::COLOR_ATTACHMENT) { | ||
allowed_usages |= wgt::TextureUsage::RENDER_ATTACHMENT; | ||
} | ||
if texture_format_properties.contains(hal::format::ImageFeature::DEPTH_STENCIL_ATTACHMENT) { | ||
allowed_usages |= wgt::TextureUsage::RENDER_ATTACHMENT; | ||
} | ||
if texture_format_properties.contains(hal::format::ImageFeature::BLIT_SRC) { | ||
allowed_usages |= wgt::TextureUsage::COPY_SRC; | ||
} | ||
if texture_format_properties.contains(hal::format::ImageFeature::BLIT_DST) { | ||
allowed_usages |= wgt::TextureUsage::COPY_DST; | ||
} | ||
|
||
let mut flags = wgt::TextureFormatFeatureFlags::empty(); | ||
if texture_format_properties.contains(hal::format::ImageFeature::STORAGE_ATOMIC) { | ||
flags |= wgt::TextureFormatFeatureFlags::STORAGE_ATOMICS; | ||
} | ||
// TODO: hal update | ||
//if texture_format_properties.contains(hal::format::ImageFeature::STORAGE_READ_WRITE) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can now be implemented thanks to you! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😊 |
||
// flags |= wgt::TextureFormatFeatureFlags::STORAGE_READ_WRITE; | ||
//} | ||
|
||
wgt::TextureFormatFeatures { | ||
allowed_usages, | ||
flags, | ||
} | ||
} | ||
|
||
fn create_device( | ||
&self, | ||
self_id: AdapterId, | ||
|
@@ -364,17 +429,6 @@ impl<B: GfxBackend> Adapter<B> { | |
} | ||
|
||
let mem_props = phd.memory_properties(); | ||
let private_features = PrivateFeatures { | ||
anisotropic_filtering: enabled_features.contains(hal::Features::SAMPLER_ANISOTROPY), | ||
texture_d24: phd | ||
.format_properties(Some(hal::format::Format::X8D24Unorm)) | ||
.optimal_tiling | ||
.contains(hal::format::ImageFeature::DEPTH_STENCIL_ATTACHMENT), | ||
texture_d24_s8: phd | ||
.format_properties(Some(hal::format::Format::D24UnormS8Uint)) | ||
.optimal_tiling | ||
.contains(hal::format::ImageFeature::DEPTH_STENCIL_ATTACHMENT), | ||
}; | ||
|
||
Device::new( | ||
gpu.device, | ||
|
@@ -385,7 +439,7 @@ impl<B: GfxBackend> Adapter<B> { | |
gpu.queue_groups.swap_remove(0), | ||
mem_props, | ||
limits, | ||
private_features, | ||
self.private_features, | ||
desc, | ||
trace_path, | ||
) | ||
|
@@ -708,6 +762,22 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> { | |
.map_err(|_| InvalidAdapter) | ||
} | ||
|
||
pub fn adapter_get_texture_format_features<B: GfxBackend>( | ||
&self, | ||
adapter_id: AdapterId, | ||
format: wgt::TextureFormat, | ||
) -> Result<wgt::TextureFormatFeatures, InvalidAdapter> { | ||
span!(_guard, INFO, "Adapter::get_texture_format_features"); | ||
|
||
let hub = B::hub(self); | ||
let mut token = Token::root(); | ||
let (adapter_guard, _) = hub.adapters.read(&mut token); | ||
adapter_guard | ||
.get(adapter_id) | ||
.map(|adapter| adapter.get_texture_format_features(format)) | ||
.map_err(|_| InvalidAdapter) | ||
} | ||
|
||
pub fn adapter_features<B: GfxBackend>( | ||
&self, | ||
adapter_id: AdapterId, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 :/
There was a problem hiding this comment.
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).