Multiview Rendering
多视图渲染
Multiview rendering refers to instancing draw calls into layers of a 2D texture array. In Qt it is relevant in particular for VR/AR applications built with Qt Quick 3D Xr. Instead of independently doing scene traversal, rendering preparations, and render pass recording for the left and right eye's content, multiview rendering allows doing it once, with the draw calls in the single render pass being instanced into layer 0 and 1 of a texture array. The vertex shader uses a special variable indicating the view index, and computes per-view values based on that. Uniforms that contain view-dependent data, such as camera matrices, must be provided for both eyes. Multiview rendering is expected to decrease the renderer's load on the system, potentially leading to better performance. It comes at the expense of having to make the renderer and shaders aware of working with view-dependent data and texture array as appropriate.
多视图渲染是指将绘图调用实例化到2D纹理阵列的层中。在Qt中,它尤其适用于使用Qt Quick 3D Xr构建的VR/AR应用程序。多视图渲染允许只进行一次,而不是独立地对左眼和右眼的内容进行场景遍历、渲染准备和渲染过程记录,单个渲染过程中的绘制调用被实例化到纹理数组的层0和层1中。顶点着色器使用一个指示视图索引的特殊变量,并基于该变量计算每个视图的值。必须为双眼提供包含视图相关数据(如相机矩阵)的Uniform。多视图渲染有望降低渲染器在系统上的负载,从而可能带来更好的性能。它的代价是必须使渲染器和着色器意识到在适当的情况下使用依赖于视图的数据和纹理数组。
Low-Level Overview
低层概述
Qt application developers do not necessarily need a full understanding of how multiview rendering is enabled on the lower levels of the Qt rendering stack. The following links are provided for developers wishing to look more into the details under the hood.
Qt应用程序开发人员不一定需要完全了解如何在Qt渲染堆栈的较低级别上启用多视图渲染。以下链接为希望深入了解细节的开发人员提供。
Multiview support in 3D APIs
3D API中的多视图支持
Multiview rendering is available only when the underlying 3D API supports it at run time. For details, see the appropriate specifications and documentation:
只有当基础三维API在运行时支持多视图渲染时,多视图渲染才可用。有关详细信息,请参阅相应的规范和文档:
- OpenGL: https://registry.khronos.org/OpenGL/extensions/OVR/OVR_multiview.txt and https://registry.khronos.org/OpenGL/extensions/OVR/OVR_multiview2.txt
- Vulkan: VK_KHR_multiview(3)
- Direct 3D 12: DirectX-Specs | Engineering specs for DirectX features.
- Metal: Rendering to Multiple Texture Slices in a Draw Command | Apple Developer Documentation
Multiview support in Qt's rendering hardware interface
Qt渲染硬件接口中的多视图支持
In Qt, the 3D graphics APIs are abstracted by the QRhi class. Qt Quick and Qt Quick 3D uses this infrastructure for all their accelerated rendering. See the following for further low-level information on multiview rendering support:
在Qt中,3D图形API由QRhi类抽象。Qt Quick和Qt Quick 3D使用此基础架构进行所有加速渲染。有关多视图渲染支持的更多低级信息,请参阅以下内容:
Multiview Support in the Qt Quick - Quick 3D - Quick 3D XR Stack
Qt Quick 3D XR堆栈中的多视图支持
Multiview support in Qt Quick
Qt Quick中的多视图支持
Qt Quick is multiview-aware, but is never using multiview rendering on its own. Supporting multiview rendering becomes important in combination with Qt Quick 3D when 2D elements are embedded into the 3D scene. To render the 2D content correctly when the 3D scene is output to a multiview render target, the 2D renderer and its materials (shaders) must be prepared for multiview support.
Qt Quick支持多视图,但从未单独使用多视图渲染。当2D元素嵌入到3D场景中时,支持多视图渲染与Qt Quick 3D相结合变得非常重要。为了在将3D场景输出到多视图渲染目标时正确渲染2D内容,必须为多视图支持准备2D渲染器及其材质(着色器)。
Developers of Qt-based applications do not need to take this into consideration in many cases, because Qt Quick's built-in materials that items such as Rectangle, Image, or Text are built on are all multiview compatible.
在许多情况下,基于Qt的应用程序的开发人员不需要考虑这一点,因为Qt Quick内置的矩形、图像或文本等项目都是多视图兼容的。
However, when developing custom materials (QSGMaterial, QSGMaterialShader) or writing shaders for ShaderEffect, and the intention is to use that 2D content within a VR/AR scene in a Qt Quick 3D Xr application, the custom content must be multiview-aware. see QSGMaterial::viewCount() for details on this.
但是,在开发自定义材质(QSGMaterial、QSGMaterialShader)或为ShaderEffect编写着色器时,如果目的是在Qt Quick 3D Xr应用程序的VR/AR场景中使用该2D内容,则自定义内容必须支持多视图。有关详细信息,请参阅QSGMaterial::viewCount()。
Writing multiview-aware shaders is enabled by Qt's shader conditioning pipeline. See the Multiview sections in QSB Manual and Qt Shader Tools Build System Integration for details.
Qt的着色器调节管道支持编写多视图感知着色器。有关详细信息,请参阅QSB手册和Qt着色器工具构建系统集成中的多视图部分。
Multiview support in Qt Quick 3D
Qt Quick 3D中的多视图支持
Qt Quick 3D applications that do not use Qt Quick 3D Xr, meaning they are not VR/AR applications, cannot currently use multiview rendering. The 3D renderer is fully multiview-capable however, since Qt Quick 3D Xr is built on the same infrastructure. All standard, built-in features, such as Model or PrincipledMaterial are fully multiview compatible. Some deprecated functionality, such as the old, standalone effects module may not support multiview rendering, however.
不使用Qt Quick 3D-Xr的Qt Quick 3D应用程序,也就是说它们不是VR/AR应用程序,目前无法使用多视图渲染。然而,由于Qt Quick 3D-Xr构建在相同的基础设施上,因此3D渲染器完全支持多视图。所有标准的内置功能,如Model或PrincipledMaterial,都完全兼容多视图。然而,一些已弃用的功能,如旧的独立效果模块,可能不支持多视图渲染。
When custom shader snippets are involved in a CustomMaterial or Effect, the application-provided shader code needs to be written with multiview support in mind in order to function correctly in a Qt Quick 3D Xr application with multiview rendering enabled. See the documentation of these types on how to achieve this. The special keywords for which this is particularly important are VIEW_INDEX
, INPUT
, SCREEN_TEXTURE
, DEPTH_TEXTURE
, AO_TEXTURE
.
当自定义材质或效果中涉及自定义着色器片段时,应用程序提供的着色器代码需要在编写时考虑到多视图支持,以便在启用多视图渲染的Qt Quick 3D Xr应用程序中正常运行。关于如何实现这一点,请参阅这些类型的文档。这一点特别重要的特殊关键字是VIEW_INDEX、INPUT、SCREENT_EXTURE、DEPTH_TEXTURE、AO_TEXTURE。
For example, the following postprocessing effect is multiview compatible, because it is prepared for the case when INPUT
is a sampler2DArray
instead of sampler2D
:
例如,以下后处理效果与多视图兼容,因为它是为INPUT是sampler2DArray而不是sampler2D的情况准备的:
void MAIN()
{
vec4 c = texture(someTexture, TEXTURE_UV);
// ...
#if QSHADER_VIEW_COUNT >= 2
FRAGCOLOR = c * texture(INPUT, vec3(INPUT_UV, VIEW_INDEX));
#else
FRAGCOLOR = c * texture(INPUT, INPUT_UV);
#endif
}
Multiview support in Qt Quick 3D Xr
Qt Quick 3D Xr中的多视图支持
As of Qt 6.8, multiview rendering is disabled by default in Qt Quick 3D Xr applications. This is done to ensure the best level of compatibility. To enable multiview rendering, set multiviewRenderingEnabled on XrView to true
. This will have no effect when the underlying 3D API does not support multiview rendering. To query if multiview rendering can be supported, check the multiViewRenderingSupported property.
从Qt 6.8开始,Qt Quick 3D Xr应用程序中默认禁用多视图渲染。这样做是为了确保最佳的兼容性。要启用多视图渲染,请将XrView上的multiviewRenderingEnabled设置为true。当基础三维API不支持多视图渲染时,这将无效。若要查询是否可以支持多视图呈现,请检查multiViewRenderingSupported属性。
For development and testing purposes, it can be useful to force the usage of multiview rendering via an environment variable. This is done by setting QT_QUICK3D_XR_MULTIVIEW
to a non-zero value.
出于开发和测试目的,通过环境变量强制使用多视图渲染可能很有用。这是通过将QT_QUICK3D_XR_MULTIVIEW设置为非零值来实现的。
To query if multiview rendering is in use (regardless of how it was enabled), use the same multiviewRenderingEnabled property. The value stays false always if multiview rendering cannot be enabled.
要查询是否正在使用多视图渲染(无论如何启用),请使用相同的multiviewRenderingEnabled属性。如果无法启用多视图渲染,则该值始终为false。
In general, it is recommended that VR/AR applications enable multiview rendering unconditionally via the XrView property, once rendering is verified to work as expected in multiview mode during the development phase. Multiview rendering is expected to improve performance, reducing the GPU and especially the CPU load.
一般来说,建议VR/AR应用程序在开发阶段验证渲染在多视图模式下按预期工作后,通过XrView属性无条件启用多视图渲染。多视图渲染有望提高性能,减少GPU,特别是CPU负载。
© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.