From 7c34cc86e89632ba4eb65c58ce6de08651261646 Mon Sep 17 00:00:00 2001 From: AlbinBernhardssonARM <60749571+AlbinBernhardssonARM@users.noreply.github.com> Date: Thu, 29 Jun 2023 22:15:21 +0200 Subject: [PATCH] Implement depth-clip-control using depthClamp (#3892) --- CHANGELOG.md | 1 + wgpu-hal/src/vulkan/adapter.rs | 31 ++----------------------------- wgpu-hal/src/vulkan/device.rs | 10 ++-------- 3 files changed, 5 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94acb283f6..cf48c37ecf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ Bottom level categories: #### Vulkan - Work around [Vulkan-ValidationLayers#5671](https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/5671) by ignoring reports of violations of [VUID-vkCmdEndDebugUtilsLabelEXT-commandBuffer-01912](https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-vkCmdEndDebugUtilsLabelEXT-commandBuffer-01912). By @jimblandy in [#3809](https://github.com/gfx-rs/wgpu/pull/3809). +- Implement depth-clip-control using depthClamp instead of VK_EXT_depth_clip_enable. By @AlbinBernhardssonARM [#3892](https://github.com/gfx-rs/wgpu/pull/3892). ### Added/New Features diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index f8f26e422f..bfee8545b1 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -24,7 +24,6 @@ pub struct PhysicalDeviceFeatures { timeline_semaphore: Option, image_robustness: Option, robustness2: Option, - depth_clip_enable: Option, multiview: Option, astc_hdr: Option, shader_float16: Option<( @@ -61,9 +60,6 @@ impl PhysicalDeviceFeatures { if let Some(ref mut feature) = self.robustness2 { info = info.push_next(feature); } - if let Some(ref mut feature) = self.depth_clip_enable { - info = info.push_next(feature); - } if let Some(ref mut feature) = self.astc_hdr { info = info.push_next(feature); } @@ -179,6 +175,7 @@ impl PhysicalDeviceFeatures { .shader_int16(requested_features.contains(wgt::Features::SHADER_I16)) //.shader_resource_residency(requested_features.contains(wgt::Features::SHADER_RESOURCE_RESIDENCY)) .geometry_shader(requested_features.contains(wgt::Features::SHADER_PRIMITIVE_INDEX)) + .depth_clamp(requested_features.contains(wgt::Features::DEPTH_CLIP_CONTROL)) .build(), descriptor_indexing: if requested_features.intersects(indexing_features()) { Some( @@ -247,17 +244,6 @@ impl PhysicalDeviceFeatures { } else { None }, - depth_clip_enable: if enabled_extensions.contains(&vk::ExtDepthClipEnableFn::name()) { - Some( - vk::PhysicalDeviceDepthClipEnableFeaturesEXT::builder() - .depth_clip_enable( - requested_features.contains(wgt::Features::DEPTH_CLIP_CONTROL), - ) - .build(), - ) - } else { - None - }, multiview: if effective_api_version >= vk::API_VERSION_1_1 || enabled_extensions.contains(&vk::KhrMultiviewFn::name()) { @@ -472,9 +458,7 @@ impl PhysicalDeviceFeatures { } } - if let Some(ref feature) = self.depth_clip_enable { - features.set(F::DEPTH_CLIP_CONTROL, feature.depth_clip_enable != 0); - } + features.set(F::DEPTH_CLIP_CONTROL, self.core.depth_clamp != 0); if let Some(ref multiview) = self.multiview { features.set(F::MULTIVIEW, multiview.multiview != 0); @@ -699,11 +683,6 @@ impl PhysicalDeviceCapabilities { extensions.push(vk::ExtConservativeRasterizationFn::name()); } - // Require `VK_EXT_depth_clip_enable` if the associated feature was requested - if requested_features.contains(wgt::Features::DEPTH_CLIP_CONTROL) { - extensions.push(vk::ExtDepthClipEnableFn::name()); - } - // Require `VK_KHR_portability_subset` on macOS/iOS #[cfg(any(target_os = "macos", target_os = "ios"))] extensions.push(vk::KhrPortabilitySubsetFn::name()); @@ -898,12 +877,6 @@ impl super::InstanceShared { .insert(vk::PhysicalDeviceRobustness2FeaturesEXT::default()); builder = builder.push_next(next); } - if capabilities.supports_extension(vk::ExtDepthClipEnableFn::name()) { - let next = features - .depth_clip_enable - .insert(vk::PhysicalDeviceDepthClipEnableFeaturesEXT::default()); - builder = builder.push_next(next); - } if capabilities.supports_extension(vk::ExtTextureCompressionAstcHdrFn::name()) { let next = features .astc_hdr diff --git a/wgpu-hal/src/vulkan/device.rs b/wgpu-hal/src/vulkan/device.rs index 09b887772c..5e73044c89 100644 --- a/wgpu-hal/src/vulkan/device.rs +++ b/wgpu-hal/src/vulkan/device.rs @@ -1611,7 +1611,8 @@ impl crate::Device for super::Device { let mut vk_rasterization = vk::PipelineRasterizationStateCreateInfo::builder() .polygon_mode(conv::map_polygon_mode(desc.primitive.polygon_mode)) .front_face(conv::map_front_face(desc.primitive.front_face)) - .line_width(1.0); + .line_width(1.0) + .depth_clamp_enable(desc.primitive.unclipped_depth); if let Some(face) = desc.primitive.cull_mode { vk_rasterization = vk_rasterization.cull_mode(conv::map_cull_face(face)) } @@ -1622,13 +1623,6 @@ impl crate::Device for super::Device { if desc.primitive.conservative { vk_rasterization = vk_rasterization.push_next(&mut vk_rasterization_conservative_state); } - let mut vk_depth_clip_state = - vk::PipelineRasterizationDepthClipStateCreateInfoEXT::builder() - .depth_clip_enable(false) - .build(); - if desc.primitive.unclipped_depth { - vk_rasterization = vk_rasterization.push_next(&mut vk_depth_clip_state); - } let mut vk_depth_stencil = vk::PipelineDepthStencilStateCreateInfo::builder(); if let Some(ref ds) = desc.depth_stencil {