澄清 Vulkan 多视图(立体 3D)功能

Clarification on Vulkan multiview (stereoscopic 3D) features

我对 Vulkan 中的立体 3D 有一些困惑。

  1. VK_KHR_multiview有什么用?如果我只使用计算着色器渲染图像,是否有必要呈现 3D 视觉?

  2. 必须启用哪些必要的扩展(设备和实例)才能呈现 3D 图像?我需要查询和创建什么?以什么顺序?

  3. "multiViewport"物理设备特性是什么意思?

VK_KHR_multiview is used in presenting two views from the same set of commands in a single render pass, rather than having to set up two render passes and two sets of commands. It does this via extension structs you attach to the pNext of, specifically VkRenderPassMultiviewCreateInfoKHR, attached to VkRenderPassCreateInfo

这更清楚地解释了此扩展提供的内容:

When you connect VkRenderPassMultiviewCreateInfo to VkRenderPassCreateInfo - you are telling Vulkan that you want to execute your pipeline TWICE ( or more - depending on the quantity of view masks set in VkRenderPassMultiviewCreateInfo, but we are talking about VR here ).

There are only two differences between these two executions :

  • gl_ViewIndex variable has different value for each run ( 0, or 1 ) - you can use it as an index to the uniform to retrieve specific camera matrices for each eye

  • results of the rendering go to different layer of the attachments ( layer 0, or layer 1 )

source

如果您已经通过计算着色器完成此操作,那么 VK_KHR_multiview 除非您使用 renderpass,否则不会有任何帮助。

Sascha Williems 示例来看,似乎需要以下扩展:

  • 显然 VK_KHR_multiview 设备扩展(通过 VK_KHR_MULTIVIEW_EXTENSION_NAME
  • VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME,用于 VK_KHR_get_physical_device_properties2(实例扩展)。这将启用多视图功能的查询。

此外,您需要修改 GLSL 多视图顶点着色器:

 #extension GL_EXT_multiview : enable

使用 gl_ViewIndex 有关扩展文档,请参阅 here for Sascha Willems shaders that show this, see here

除此设置外,您只需要渲染到多个图像(如 Saschas 示例所示)。正如在原始的 reddit post 中看到的那样,有多种方法可以实现这一点:

Sascha's demo renders these two layers into a single swapchain image ( because he uses single output image )

  • you could render it similarly, but use two Images as output attachments - create two render passes with two output attachments, use texture array as input storage image ( or combined image sampler if want to rescale the results )

  • you could just copy the results from texture array to your images using vkCmdCopyImage or vkCmdBlitImage ( if you want to rescale the results ).

  • you could create two VkImages that alias the same memory, that the image array is using

multiViewport物理设备特征定义如下:

multiViewport specifies whether more than one viewport is supported. If this feature is not enabled:

  • The viewportCount and scissorCount members of the VkPipelineViewportStateCreateInfo structure must be set to 1.

  • The firstViewport and viewportCount parameters to the vkCmdSetViewport command must be set to 0 and 1, respectively.

  • The firstScissor and scissorCount parameters to the vkCmdSetScissor command must be set to 0 and 1, respectively.

  • The exclusiveScissorCount member of the VkPipelineViewportExclusiveScissorStateCreateInfoNV structure must be set to 0 or 1.

  • The firstExclusiveScissor and exclusiveScissorCount parameters to the vkCmdSetExclusiveScissorNV command must be set to 0 and 1, respectively.

这基本上只是说明物理设备是否支持多个视图端口。