这是indexloc提供的服务,不要输入任何密码
Skip to content

Implement "depth_clamp" on D3D12  #2100

@Jiawei-Shao

Description

@Jiawei-Shao

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::depthClampEnable is enabled, before the sample’s zf is compared to za,zf is clamped to [min(n,f),max(n,f)], where n and f are the minDepth and maxDepth depth 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 DepthClipEnable is set to the default–TRUE, the hardware also clips the z value ", which means in D3D12 depthClip is 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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions