Open teoxoy opened 1 year ago
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.
Based on https://github.com/gpuweb/gpuweb/issues/2100#issuecomment-924536243 & https://github.com/gpuweb/gpuweb/issues/3638#issuecomment-1342646305
DX12
Clamps depth & has
DepthClipEnable
which corresponds to!unclippedDepth
https://github.com/gfx-rs/wgpu/blob/17143c149c13ea5af36909ef6033e776cecad28c/wgpu-hal/src/dx12/device.rs#L1345
TODO:
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:DEPTH_CLIP_CONTROL
featureunclippedDepth
{ setMTLDepthClipModeClamp
} else { setMTLDepthClipModeClip
and clampfrag_depth
in shader }else:
frag_depth
in shaderTODO:
Update the following to check for versions instead and rename the capability to
supports_set_depth_clip_mode
. https://github.com/gfx-rs/wgpu/blob/17143c149c13ea5af36909ef6033e776cecad28c/wgpu-hal/src/metal/adapter.rs#L737-L739Implement
frag_depth
clamping in the shaderVulkan
Has
depthClamp
&VK_EXT_depth_clip_enable
if both are available:
DEPTH_CLIP_CONTROL
featuredepthClampEnable
depthClipEnable
based onunclippedDepth
else if
depthClamp
is available:DEPTH_CLIP_CONTROL
featureunclippedDepth
{ setdepthClampEnable
} else { clampfrag_depth
in shader }else:
frag_depth
in shaderTODO:
Shader clamping was implemented in https://github.com/gfx-rs/naga/pull/1431 but wgpu is not setting the flag and it should also clamp between
viewport.minDepth
andviewport.maxDepth
(not 0 and 1)Implement the flow above; too many changes to list here (might be useful to undo part of https://github.com/gfx-rs/wgpu/pull/3892)