QRhiRenderPassDescriptor Class
渲染通道资源。更多...
| 标题: | #include <rhi/qrhi.h> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS GuiPrivate) target_link_libraries(mytarget PRIVATE Qt6::GuiPrivate) |
| qmake: | QT += gui-private |
| 自: | Qt 6.6 |
| 继承自: | QRhiResource |
公共函数
| virtual bool | isCompatible(const QRhiRenderPassDescriptor *other) const = 0 |
| virtual const QRhiNativeHandles * | nativeHandles() |
| virtual QRhiRenderPassDescriptor * | newCompatibleRenderPassDescriptor() const = 0 |
| virtual QVector<quint32> | serializedFormat() const = 0 |
重新实现的公共函数
| virtual QRhiResource::Type | resourceType() const override |
成员函数文档
[pure virtual] bool QRhiRenderPassDescriptor::isCompatible(const QRhiRenderPassDescriptor *other) const
如果other QRhiRenderPassDescriptor 与当前渲染通道描述符兼容,则返回 true,这意味着在QRhiGraphicsPipeline::setRenderPassDescriptor() 中,this 和other 可以互换使用。
渲染通道描述符的兼容性概念与QRhiShaderResourceBindings 实例的layout compatibility 类似。它们允许更好地复用QRhiGraphicsPipeline 实例:例如,预计QRhiGraphicsPipeline 实例缓存会使用这些函数来查找匹配的管道,而不是仅仅比较指针,从而允许在管道中组合使用不同的QRhiRenderPassDescriptor 和QRhiShaderResourceBindings ,只要它们兼容即可。
兼容性的具体细节取决于底层图形 API。来自同一QRhiTextureRenderTarget 的两个渲染通道描述符created 始终兼容。
与QRhiShaderResourceBindings 类似,即使没有现成的两个对象,也可以测试兼容性。 通过调用serializedFormat() 提取不透明数据块,可以将返回的向量与另一个QRhiRenderPassDescriptor 的serializedFormat() 进行比较,从而测试兼容性。这在某些情况下很有用,因为即使最初用于构建管道的QRhiRenderPassDescriptor 已不可用(但其serializedFormat() 返回的数据仍然可用),也可以测试QRhiRenderPassDescriptor 与QRhiGraphicsPipeline 的兼容性。
另请参阅 newCompatibleRenderPassDescriptor() 和serializedFormat()。
[virtual] const QRhiNativeHandles *QRhiRenderPassDescriptor::nativeHandles()
返回一个指向后端特定QRhiNativeHandles 子类的指针,例如QRhiVulkanRenderPassNativeHandles 。如果后端不支持暴露底层本机资源,则返回值为nullptr 。
另请参见 QRhiVulkanRenderPassNativeHandles 。
[pure virtual] QRhiRenderPassDescriptor *QRhiRenderPassDescriptor::newCompatibleRenderPassDescriptor() const
返回一个新的QRhiRenderPassDescriptor 对象,该对象与当前对象compatible 。
此函数允许克隆一个QRhiRenderPassDescriptor 。返回的对象可立即使用,且所有权已转移给调用方。 克隆QRhiRenderPassDescriptor 对象在以下情况下非常有用:当对象存储在与图形管道相关的数据结构中(以便创建新管道,而新管道又需要renderpass描述符对象),且由渲染目标创建的renderpass描述符的生命周期可能比管道更短时。 (例如,因为引擎会与创建该渲染通道所用的纹理和渲染目标一起管理和销毁渲染通道)在这种情况下,将克隆版本存储在数据结构中并随之转移所有权会很有帮助。
另请参阅 isCompatible()。
[override virtual] QRhiResource::Type QRhiRenderPassDescriptor::resourceType() const
重写了:QRhiResource::resourceType() const。
返回资源类型。
[pure virtual] QVector<quint32> QRhiRenderPassDescriptor::serializedFormat() const
返回一个整数向量,其中包含一个描述与compatibility 相关数据的不透明数据块。
给定两个 `QRhiRenderPassDescriptor ` 对象 `rp1 ` 和 `rp2`,如果此函数返回的数据完全相同,则 `rp1->isCompatible(rp2)` 成立,反之亦然。
注意:调用 此函数应为低开销操作,因为后端不应在此函数中计算数据,而应返回已计算好的数据序列。
在作为库的一部分创建可重用组件时,若图形管道的创建和维护是针对由库客户端管理的渲染目标(QRhiRenderTarget )(无论是交换链还是纹理),则这些组件必须能够处理不断变化的渲染目标(QRhiRenderPassDescriptor )。 例如,由于渲染目标发生变化,导致先前渲染的QRhiRenderPassDescriptor 失效(至少针对新的渲染目标而言),因为其颜色格式和附件可能已发生改变;或者因为variable rate shading 被动态启用。 一个有助于处理此问题的简单模式是在每帧执行以下检查,以识别当渲染目标与先前帧相比发生了变化,从而需要将管道与新的QRhiRenderPassDescriptor 关联的情况:
QRhiRenderPassDescriptor *rp = m_renderTarget->renderPassDescriptor();
if (m_pipeline && rp->serializedFormat() != m_renderPassFormat) {
m_pipeline->setRenderPassDescriptor(rp);
m_renderPassFormat = rp->serializedFormat();
m_pipeline->create();
}
// remember to store m_renderPassFormat also when creating m_pipeline the first time另请参阅 isCompatible()。
© 2026 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.