Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Depth clamp/clip improvements #3900

Open
teoxoy opened this issue Jun 30, 2023 · 1 comment
Open

Depth clamp/clip improvements #3900

teoxoy opened this issue Jun 30, 2023 · 1 comment
Labels
api: metal Issues with Metal api: vulkan Issues with Vulkan type: enhancement New feature or request

Comments

@teoxoy
Copy link
Member

teoxoy commented Jun 30, 2023

Based on gpuweb/gpuweb#2100 (comment) & gpuweb/gpuweb#3638 (comment)

DX12

Clamps depth & has DepthClipEnable which corresponds to !unclippedDepth

DepthClipEnable: BOOL::from(!desc.primitive.unclipped_depth),

TODO:

  • Nothing.

Metal

Has setDepthClipMode available on: iOS 11.0+ & macOS 10.11+

Note: I think if setDepthClipMode is not available, Metal will still clip by default.

if setDepthClipMode is available:

  • expose the DEPTH_CLIP_CONTROL feature
  • if unclippedDepth { set MTLDepthClipModeClamp } else { set MTLDepthClipModeClip and clamp frag_depth in shader }

else:

  • clamp frag_depth in shader

TODO:

  • Update the following to check for versions instead and rename the capability to supports_set_depth_clip_mode.

    //Depth clipping is supported on all macOS GPU families and iOS family 4 and later
    supports_depth_clip_control: os_is_mac
    || device.supports_feature_set(MTLFeatureSet::iOS_GPUFamily4_v1),

  • Implement frag_depth clamping in the shader

Vulkan

Has depthClamp & VK_EXT_depth_clip_enable

if both are available:

  • expose the DEPTH_CLIP_CONTROL feature
  • set depthClampEnable
  • set depthClipEnable based on unclippedDepth

else if depthClamp is available:

  • expose the DEPTH_CLIP_CONTROL feature
  • if unclippedDepth { set depthClampEnable } else { clamp frag_depth in shader }

else:

  • clamp frag_depth in shader

TODO:

@teoxoy teoxoy added type: enhancement New feature or request api: metal Issues with Metal api: vulkan Issues with Vulkan labels Jun 30, 2023
@teoxoy teoxoy added this to the WebGPU Specification V1 milestone Jun 30, 2023
@JMS55
Copy link
Contributor

JMS55 commented Apr 20, 2024

I noticed this on a stress test of my renderer (VK backend). When rendering directional light shadow maps with a fragment shader to output unclamped depth, Nvidia NSight says I would get a ~3x speedup in rasterization if ZCULL was enabled, which would require removing the fragment shader and using the pipeline-level depth clamping control.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: metal Issues with Metal api: vulkan Issues with Vulkan type: enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

2 participants