-
Notifications
You must be signed in to change notification settings - Fork 345
Description
When I was implementing the WebGPU extension depth_clamp on D3D12, I found D3D12_RASTERIZER_DESC.DepthClipEnable doesn't have the same functionality as VkPipelineRasterizationStateCreateInfo::depthClampEnable, so we cannot implement depth_clamping with D3D12_RASTERIZER_DESC.DepthClipEnable.
-
According to Vulkan SPEC, "if
VkPipelineRasterizationStateCreateInfo::depthClampEnableis enabled, before the sample’szfis compared toza,zfis clamped to[min(n,f),max(n,f)], wherenandfare theminDepthandmaxDepthdepth range values of the viewport used by this fragment, respectively", which implies in Vulkan "depthClamp" is done after fragment shader stage: clamp the depth value of the output fragment shader after the execution of fragment shader. -
According to D3D12 document, "the hardware always performs x and y clipping of rasterized coordinates. When
DepthClipEnableis set to the default–TRUE, the hardware also clips the z value ", which means in D3D12depthClipis executed before the pixel shader stage: discard the specific coordinates after rasterization.
I think the right way to implement depth_clamp is injecting the following at the end of fragment shaders, what do you think?
gl_FragDepth = clamp(0, 1, gl_FragDepth);