From 3073a454ffa6839768e6aa6e2477861ea623fbd5 Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Thu, 1 Apr 2021 11:48:09 -0400 Subject: [PATCH] Update to flag-based downlevel bools --- wgpu-core/src/command/compute.rs | 2 +- wgpu-core/src/device/mod.rs | 2 +- wgpu-core/src/instance.rs | 35 +++++++++++++++++++------ wgpu-core/src/lib.rs | 4 +-- wgpu-types/src/lib.rs | 45 ++++++++++++++++++-------------- 5 files changed, 56 insertions(+), 32 deletions(-) diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 57c86a97be..aa153a03bb 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -275,7 +275,7 @@ impl Global { }); } - if !cmd_buf.downlevel.compute_shaders { + if !cmd_buf.downlevel.flags.contains(wgt::DownlevelFlags::COMPUTE_SHADERS) { return Err(ComputePassError { scope: PassErrorScope::Pass(encoder_id), inner: ComputePassErrorInner::ComputeShadersUnsupported, diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 22a8ee1c4b..45dc4e46a0 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -1861,7 +1861,7 @@ impl Device { ), pipeline::CreateComputePipelineError, > { - if !self.downlevel.compute_shaders { + if !self.downlevel.flags.contains(wgt::DownlevelFlags::COMPUTE_SHADERS) { return Err(pipeline::CreateComputePipelineError::ComputeShadersUnsupported); } diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index e058adbc76..e836a0b9a9 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -275,20 +275,39 @@ impl Adapter { .max(MIN_PUSH_CONSTANT_SIZE), // As an extension, the default is always 0, so define a separate minimum. }; + let mut downlevel_flags = wgt::DownlevelFlags::empty(); + downlevel_flags.set( + wgt::DownlevelFlags::COMPUTE_SHADERS, + properties.downlevel.compute_shaders, + ); + downlevel_flags.set( + wgt::DownlevelFlags::STORAGE_IMAGES, + properties.downlevel.storage_images, + ); + downlevel_flags.set( + wgt::DownlevelFlags::READ_ONLY_DEPTH_STENCIL, + properties.downlevel.read_only_depth_stencil, + ); + downlevel_flags.set( + wgt::DownlevelFlags::DEVICE_LOCAL_IMAGE_COPIES, + properties.downlevel.device_local_image_copies, + ); + downlevel_flags.set( + wgt::DownlevelFlags::NON_POWER_OF_TWO_MIPMAPPED_TEXTURES, + properties.downlevel.non_power_of_two_mipmapped_textures, + ); + downlevel_flags.set( + wgt::DownlevelFlags::ANISOTROPIC_FILTERING, + private_features.anisotropic_filtering, + ); + let downlevel = wgt::DownlevelProperties { - compute_shaders: properties.downlevel.compute_shaders, + flags: downlevel_flags, shader_model: match properties.downlevel.shader_model { hal::DownlevelShaderModel::ShaderModel2 => wgt::ShaderModel::Sm2, hal::DownlevelShaderModel::ShaderModel4 => wgt::ShaderModel::Sm4, hal::DownlevelShaderModel::ShaderModel5 => wgt::ShaderModel::Sm5, }, - storage_images: properties.downlevel.storage_images, - read_only_depth_stencil: properties.downlevel.read_only_depth_stencil, - device_local_image_copies: properties.downlevel.device_local_image_copies, - non_power_of_two_mipmapped_textures: properties - .downlevel - .non_power_of_two_mipmapped_textures, - anisotropic_filtering: private_features.anisotropic_filtering, }; Self { diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs index f268997b23..a76c5014e4 100644 --- a/wgpu-core/src/lib.rs +++ b/wgpu-core/src/lib.rs @@ -241,12 +241,12 @@ const DOWNLEVEL_WARNING_MESSAGE: &str = "The underlying API or device in use doe support enough features to be a fully compliant implementation of WebGPU. A subset of the features can still be used. \ If you are running this program on native and not in a browser and wish to limit the features you use to the supported subset, \ call Adapter::downlevel_properties or Device::downlevel_properties to get a listing of the features the current \ -platform is supports."; +platform supports."; const DOWNLEVEL_ERROR_WARNING_MESSAGE: &str = "This is not an invalid use of WebGPU: the underlying API or device does not \ support enough features to be a fully compliant implementation. A subset of the features can still be used. \ If you are running this program on native and not in a browser and wish to work around this issue, call \ Adapter::downlevel_properties or Device::downlevel_properties to get a listing of the features the current \ -platform is supports."; +platform supports."; #[macro_export] macro_rules! gfx_select { diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index aef2c5a35b..fe65f91158 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -541,22 +541,10 @@ impl Default for Limits { /// Lists various ways the underlying platform does not conform to the WebGPU standard. #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct DownlevelProperties { - /// The device supports compiling and using compute shaders. - pub compute_shaders: bool, + /// Combined boolean flags. + pub flags: DownlevelFlags, /// Which collections of features shaders support. Defined in terms of D3D's shader models. pub shader_model: ShaderModel, - /// Supports creating storage images. - pub storage_images: bool, - /// Supports reading from a depth/stencil buffer while using as a read-only depth/stencil attachment. - pub read_only_depth_stencil: bool, - /// Supports: - /// - copy_image_to_image - /// - copy_buffer_to_image and copy_image_to_buffer with a buffer without a MAP_* usage - pub device_local_image_copies: bool, - /// Supports textures with mipmaps which have a non power of two size. - pub non_power_of_two_mipmapped_textures: bool, - /// Supports samplers with anisotropic filtering - pub anisotropic_filtering: bool, } impl Default for DownlevelProperties { @@ -564,13 +552,8 @@ impl Default for DownlevelProperties { // gfx-hal's equivalent structure defaults to all off. fn default() -> Self { Self { - compute_shaders: true, + flags: DownlevelFlags::COMPLIANT, shader_model: ShaderModel::Sm5, - storage_images: true, - read_only_depth_stencil: true, - device_local_image_copies: true, - non_power_of_two_mipmapped_textures: true, - anisotropic_filtering: true, } } } @@ -585,6 +568,28 @@ impl DownlevelProperties { } } +bitflags::bitflags! { + /// Binary flags listing various ways the underlying platform does not conform to the WebGPU standard. + pub struct DownlevelFlags: u32 { + /// The device supports compiling and using compute shaders. + const COMPUTE_SHADERS = 0x0000_0001; + /// Supports creating storage images. + const STORAGE_IMAGES = 0x0000_0002; + /// Supports reading from a depth/stencil buffer while using as a read-only depth/stencil attachment. + const READ_ONLY_DEPTH_STENCIL = 0x0000_0004; + /// Supports: + /// - copy_image_to_image + /// - copy_buffer_to_image and copy_image_to_buffer with a buffer without a MAP_* usage + const DEVICE_LOCAL_IMAGE_COPIES = 0x0000_0008; + /// Supports textures with mipmaps which have a non power of two size. + const NON_POWER_OF_TWO_MIPMAPPED_TEXTURES = 0x0000_0010; + /// Supports samplers with anisotropic filtering + const ANISOTROPIC_FILTERING = 0x0000_0020; + /// All flags are in their compliant state. + const COMPLIANT = 0x0000_003F; + } +} + /// Collections of shader features a device supports if they support less than WebGPU normally allows. // TODO: Fill out the differences between shader models more completely #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]