Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Commit

Permalink
Merge #713
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bors[bot] and Wumpf authored Jan 13, 2021
2 parents da5fbcf + 5ad4f19 commit baf6c43
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/backend/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,19 @@ impl crate::Context for Context {
}
}

fn adapter_get_texture_format_features(
&self,
adapter: &Self::AdapterId,
format: wgt::TextureFormat,
) -> wgt::TextureFormatFeatures {
let global = &self.0;
match wgc::gfx_select!(*adapter => global.adapter_get_texture_format_features(*adapter, format))
{
Ok(info) => info,
Err(err) => self.handle_error_fatal(err, "Adapter::get_texture_format_features"),
}
}

fn device_features(&self, device: &Self::DeviceId) -> Features {
let global = &self.0;
match wgc::gfx_select!(device.id => global.device_features(device.id)) {
Expand Down
8 changes: 8 additions & 0 deletions src/backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,14 @@ impl crate::Context for Context {
}
}

fn adapter_get_texture_format_features(
&self,
_adapter: &Self::AdapterId,
format: wgt::TextureFormat,
) -> wgt::TextureFormatFeatures {
format.describe().guaranteed_format_features
}

fn device_features(&self, _device: &Self::DeviceId) -> wgt::Features {
// TODO: web-sys has no way of getting extensions on devices
wgt::Features::empty()
Expand Down
16 changes: 16 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ trait Context: Debug + Send + Sized + Sync {
fn adapter_features(&self, adapter: &Self::AdapterId) -> Features;
fn adapter_limits(&self, adapter: &Self::AdapterId) -> Limits;
fn adapter_get_info(&self, adapter: &Self::AdapterId) -> AdapterInfo;
fn adapter_get_texture_format_features(
&self,
adapter: &Self::AdapterId,
format: wgt::TextureFormat,
) -> wgt::TextureFormatFeatures;

fn device_features(&self, device: &Self::DeviceId) -> Features;
fn device_limits(&self, device: &Self::DeviceId) -> Limits;
Expand Down Expand Up @@ -1413,6 +1418,17 @@ impl Adapter {
pub fn get_info(&self) -> AdapterInfo {
Context::adapter_get_info(&*self.context, &self.id)
}

/// Returns the features supported for a given texture format by this adapter.
///
/// Note that the WebGPU spec further restricts the available usages/features.
/// To disable these restrictions on a device, request the [`Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES`] feature.
pub fn get_texture_format_features(
&self,
format: wgt::TextureFormat,
) -> wgt::TextureFormatFeatures {
Context::adapter_get_texture_format_features(&*self.context, &self.id, format)
}
}

impl Device {
Expand Down

0 comments on commit baf6c43

Please sign in to comment.