gfx-rs / wgpu

A cross-platform, safe, pure-Rust graphics API.
https://wgpu.rs
Apache License 2.0
12.67k stars 926 forks source link

Depth clamp/clip improvements #3900

Open teoxoy opened 1 year ago

teoxoy commented 1 year ago

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:

else:

TODO:

Vulkan

Has depthClamp & VK_EXT_depth_clip_enable

if both are available:

else if depthClamp is available:

else:

TODO:

JMS55 commented 6 months 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.