简体   繁体   中英

How to store unrestricted depth range in Vulkan depth buffer

Primarily for debugging purpose I wish to store and reuse in future render calls depth buffer, which is not clamped to [0.0, 1.0] range, as bound by the Vulkan specification. The VK_EXT_depth_range_unrestricted seems to be exactly what I need, so I had

  1. Enabled VK_EXT_depth_range_unrestricted,
  2. Set depth range in viewport to [0.0, 10.0],
  3. Set VkPipelineDepthStencilStateCreateInfo's depth bounds to [0.0, 10.0], depthTestEnable and depthWriteEnable to VK_TRUE,
  4. Set depth clear value for renderpass to be equal to 10,
  5. Rasterized some triangles, depth of each vertex is equal to 3.0,

and found that all pixels of the depth map are equal to 1.0. But I expected rasterized pixels to have depth 3.0, and not rasterized to have 10.0 (checked both in renderdoc and by dumping the depth buffer to host memory).

Hence my question: is it possible to actually store the unnormalized depth in the depth buffer in Vulkan? If it is, how do I do it?

UPDATE: I crafted the reproducer from Sascha Willems' triangle drawing example. It's in the fork When running the example, validation does not report anything. What I see is the blank image (every pixel is cleared), however I expected a single triangle to be drawn (because each vertex of it has the depth 3, and the cleared depth is 5). Just in case, device is Vega RX, driver 18.50-ubuntu16.04.

From the extension specification's issues section, one can find a number of other things that have to happen. Since you didn't deign to show your code, here's a list:

  1. The image format of the depth buffer has to be floating-point. If it is fixed-point, then values will still be clamped to that range. Note that hardware does not have to support floating-point depth buffers (though, if it doesn't, then odds are good it doesn't support this extension either).

  2. Clipping may still apply. Primitives can be clipped to the [0, W c ] range, where "W c " is the fourth component of the clip-space vertex position. To stop this, you have to turn off depth clipping, via VkPipelineRasterizationStateCreateInfo::depthClampEnable = VK_TRUE (or VkPipelineRasterizationDepthClipStateCreateInfoEXT::depthClipEnable = VK_FALSE if you're using that extension).

  3. With depth clipping disabled, the depth values will still be clamped to the VkViewport::minDepth/maxDepth range. So you have to make sure that's big enough.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM