Skip to content

Commit

Permalink
Implement depth-clip-control using depthClamp (#3892)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbinBernhardssonARM committed Jun 29, 2023
1 parent 6158692 commit 7c34cc8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
31 changes: 2 additions & 29 deletions wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub struct PhysicalDeviceFeatures {
timeline_semaphore: Option<vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR>,
image_robustness: Option<vk::PhysicalDeviceImageRobustnessFeaturesEXT>,
robustness2: Option<vk::PhysicalDeviceRobustness2FeaturesEXT>,
depth_clip_enable: Option<vk::PhysicalDeviceDepthClipEnableFeaturesEXT>,
multiview: Option<vk::PhysicalDeviceMultiviewFeaturesKHR>,
astc_hdr: Option<vk::PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT>,
shader_float16: Option<(
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions wgpu-hal/src/vulkan/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,8 @@ impl crate::Device<super::Api> 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))
}
Expand All @@ -1622,13 +1623,6 @@ impl crate::Device<super::Api> 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 {
Expand Down

0 comments on commit 7c34cc8

Please sign in to comment.