From 62e932b0a8c9e77d71d8e04533d196a0571763b0 Mon Sep 17 00:00:00 2001 From: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com> Date: Tue, 20 Dec 2022 18:21:54 +0100 Subject: [PATCH] Add missing `DEPTH_BIAS_CLAMP` and `FULL_DRAW_INDEX_UINT32` downlevel flags (#3316) * add missing `DEPTH_BIAS_CLAMP` and `FULL_DRAW_INDEX_UINT32` downlevel flags * add changelog entry * use require_downlevel_flags --- CHANGELOG.md | 1 + wgpu-core/src/device/mod.rs | 4 ++++ wgpu-hal/src/dx11/adapter.rs | 3 +++ wgpu-hal/src/gles/adapter.rs | 5 +++++ wgpu-hal/src/vulkan/adapter.rs | 18 +++++++++++++++++- wgpu-types/src/lib.rs | 10 ++++++++++ 6 files changed, 40 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55d18bacea..2cf685f91d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -116,6 +116,7 @@ Additionally `Surface::get_default_config` now returns an Option and returns Non - Lower the `max_buffer_size` limit value for compatibility with Apple2 and WebGPU compliance. By @jinleili in [#3255](https://github.com/gfx-rs/wgpu/pull/3255) - Dereferencing a buffer view is now marked inline. By @Wumpf in [#3307](https://github.com/gfx-rs/wgpu/pull/3307) - The `strict_assert` family of macros was moved to `wgpu-types`. By @i509VCB in [#3051](https://github.com/gfx-rs/wgpu/pull/3051) +- Add missing `DEPTH_BIAS_CLAMP` and `FULL_DRAW_INDEX_UINT32` downlevel flags. By @teoxoy in [#3316](https://github.com/gfx-rs/wgpu/pull/3316) #### WebGPU diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 5d756db99a..955e8b4c22 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -2738,6 +2738,10 @@ impl Device { if let Some(e) = error { return Err(pipeline::CreateRenderPipelineError::DepthStencilState(e)); } + + if ds.bias.clamp != 0.0 { + self.require_downlevel_flags(wgt::DownlevelFlags::DEPTH_BIAS_CLAMP)?; + } } if desc.layout.is_none() { diff --git a/wgpu-hal/src/dx11/adapter.rs b/wgpu-hal/src/dx11/adapter.rs index 9c9440d3fc..af9862c144 100644 --- a/wgpu-hal/src/dx11/adapter.rs +++ b/wgpu-hal/src/dx11/adapter.rs @@ -110,6 +110,8 @@ impl super::Adapter { downlevel |= wgt::DownlevelFlags::INDEPENDENT_BLEND; // formally FL9_1 supports aniso 2, but we don't support that level of distinction downlevel |= wgt::DownlevelFlags::ANISOTROPIC_FILTERING; + // this is actually the first FL that supports u32 at all + downlevel |= wgt::DownlevelFlags::FULL_DRAW_INDEX_UINT32; } if feature_level >= FL9_3 { @@ -120,6 +122,7 @@ impl super::Adapter { downlevel |= wgt::DownlevelFlags::INDEPENDENT_BLEND; downlevel |= wgt::DownlevelFlags::FRAGMENT_STORAGE; downlevel |= wgt::DownlevelFlags::FRAGMENT_WRITABLE_STORAGE; + downlevel |= wgt::DownlevelFlags::DEPTH_BIAS_CLAMP; features |= wgt::Features::DEPTH_CLIP_CONTROL; features |= wgt::Features::TIMESTAMP_QUERY; features |= wgt::Features::PIPELINE_STATISTICS_QUERY; diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index bf4d95148f..326b449bfb 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -255,6 +255,7 @@ impl super::Adapter { } else { 0 }; + let max_element_index = unsafe { gl.get_parameter_i32(glow::MAX_ELEMENT_INDEX) } as u32; // WORKAROUND: In order to work around an issue with GL on RPI4 and similar, we ignore a // zero vertex ssbo count if there are vertex sstos. (more info: @@ -316,6 +317,10 @@ impl super::Adapter { wgt::DownlevelFlags::UNRESTRICTED_INDEX_BUFFER, !cfg!(target_arch = "wasm32"), ); + downlevel_flags.set( + wgt::DownlevelFlags::FULL_DRAW_INDEX_UINT32, + max_element_index == u32::MAX, + ); let mut features = wgt::Features::empty() | wgt::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index 72ae9ce90e..fc03014ee2 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -316,7 +316,18 @@ impl PhysicalDeviceFeatures { | F::WRITE_TIMESTAMP_INSIDE_PASSES | F::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES | F::CLEAR_TEXTURE; - let mut dl_flags = Df::all(); + + let mut dl_flags = Df::COMPUTE_SHADERS + | Df::BASE_VERTEX + | Df::READ_ONLY_DEPTH_STENCIL + | Df::NON_POWER_OF_TWO_MIPMAPPED_TEXTURES + | Df::COMPARISON_SAMPLERS + | Df::VERTEX_STORAGE + | Df::FRAGMENT_STORAGE + | Df::DEPTH_TEXTURE_AND_BUFFER_COPIES + | Df::WEBGPU_TEXTURE_FORMAT_SUPPORT + | Df::BUFFER_BINDINGS_NOT_16_BYTE_ALIGNED + | Df::UNRESTRICTED_INDEX_BUFFER; dl_flags.set(Df::CUBE_ARRAY_TEXTURES, self.core.image_cube_array != 0); dl_flags.set(Df::ANISOTROPIC_FILTERING, self.core.sampler_anisotropy != 0); @@ -326,6 +337,11 @@ impl PhysicalDeviceFeatures { ); dl_flags.set(Df::MULTISAMPLED_SHADING, self.core.sample_rate_shading != 0); dl_flags.set(Df::INDEPENDENT_BLEND, self.core.independent_blend != 0); + dl_flags.set( + Df::FULL_DRAW_INDEX_UINT32, + self.core.full_draw_index_uint32 != 0, + ); + dl_flags.set(Df::DEPTH_BIAS_CLAMP, self.core.depth_bias_clamp != 0); features.set( F::INDIRECT_FIRST_INSTANCE, diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 365c884ab9..f6e1a44d60 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -1129,6 +1129,16 @@ bitflags::bitflags! { /// /// WebGL doesn't support this. const UNRESTRICTED_INDEX_BUFFER = 1 << 16; + + /// Supports full 32-bit range indices (2^32-1 as opposed to 2^24-1 without this flag) + /// + /// Corresponds to Vulkan's `VkPhysicalDeviceFeatures.fullDrawIndexUint32` + const FULL_DRAW_INDEX_UINT32 = 1 << 17; + + /// Supports depth bias clamping + /// + /// Corresponds to Vulkan's `VkPhysicalDeviceFeatures.depthBiasClamp` + const DEPTH_BIAS_CLAMP = 1 << 18; } }