diff options
Diffstat (limited to 'src/gui/rhi')
-rw-r--r-- | src/gui/rhi/qrhi.cpp | 13 | ||||
-rw-r--r-- | src/gui/rhi/qrhi_p.h | 51 | ||||
-rw-r--r-- | src/gui/rhi/qrhid3d11.cpp | 2 | ||||
-rw-r--r-- | src/gui/rhi/qrhid3d11_p_p.h | 4 | ||||
-rw-r--r-- | src/gui/rhi/qrhimetal.mm | 4 | ||||
-rw-r--r-- | src/gui/rhi/qrhimetal_p_p.h | 4 | ||||
-rw-r--r-- | src/gui/rhi/qrhivulkan.cpp | 3 | ||||
-rw-r--r-- | src/gui/rhi/qrhivulkan_p_p.h | 4 |
8 files changed, 58 insertions, 27 deletions
diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index 2bf8c3c7b6..fa0c5fadc0 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -2534,16 +2534,8 @@ QRhiResource::Type QRhiTextureRenderTarget::resourceType() const be used with the same pipeline, assuming the pipeline was built with one of them in the first place. - Creating and then using a new \c srb2 that is very similar to \c srb with - the exception of referencing another texture could be implemented like the - following: - \badcode srb2 = rhi->newShaderResourceBindings(); - QVector<QRhiShaderResourceBinding> bindings = srb->bindings(); - bindings[1] = QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, anotherTexture, sampler); - srb2->setBindings(bindings); - srb2->build(); ... cb->setGraphicsPipeline(ps); cb->setShaderResources(srb2); // binds srb2 @@ -3064,6 +3056,11 @@ QDebug operator<<(QDebug dbg, const QRhiShaderResourceBinding &b) #endif #ifndef QT_NO_DEBUG_STREAM +QDebug operator<<(QDebug dbg, const QVarLengthArray<QRhiShaderResourceBinding, 8> &bindings) +{ + return QtPrivate::printSequentialContainer(dbg, "Bindings", bindings); +} + QDebug operator<<(QDebug dbg, const QRhiShaderResourceBindings &srb) { QDebugStateSaver saver(dbg); diff --git a/src/gui/rhi/qrhi_p.h b/src/gui/rhi/qrhi_p.h index fec69c607f..f8f922cfdb 100644 --- a/src/gui/rhi/qrhi_p.h +++ b/src/gui/rhi/qrhi_p.h @@ -52,6 +52,7 @@ #include <QSize> #include <QMatrix4x4> #include <QVector> +#include <QVarLengthArray> #include <QThread> #include <QColor> #include <QImage> @@ -926,8 +927,22 @@ class Q_GUI_EXPORT QRhiShaderResourceBindings : public QRhiResource public: QRhiResource::Type resourceType() const override; - QVector<QRhiShaderResourceBinding> bindings() const { return m_bindings; } - void setBindings(const QVector<QRhiShaderResourceBinding> &b) { m_bindings = b; } + void setBindings(std::initializer_list<QRhiShaderResourceBinding> list) { m_bindings = list; } + + template<typename InputIterator> + void setBindings(InputIterator first, InputIterator last) + { + m_bindings.clear(); + std::copy(first, last, std::back_inserter(m_bindings)); + } + + void setBindings(const QVector<QRhiShaderResourceBinding> &bindings) // compat., to be removed + { + setBindings(bindings.cbegin(), bindings.cend()); + } + + const QRhiShaderResourceBinding *cbeginBindings() const { return m_bindings.cbegin(); } + const QRhiShaderResourceBinding *cendBindings() const { return m_bindings.cend(); } bool isLayoutCompatible(const QRhiShaderResourceBindings *other) const; @@ -935,7 +950,7 @@ public: protected: QRhiShaderResourceBindings(QRhiImplementation *rhi); - QVector<QRhiShaderResourceBinding> m_bindings; + QVarLengthArray<QRhiShaderResourceBinding, 8> m_bindings; #ifndef QT_NO_DEBUG_STREAM friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiShaderResourceBindings &); #endif @@ -1066,8 +1081,15 @@ public: FrontFace frontFace() const { return m_frontFace; } void setFrontFace(FrontFace f) { m_frontFace = f; } - QVector<TargetBlend> targetBlends() const { return m_targetBlends; } - void setTargetBlends(const QVector<TargetBlend> &blends) { m_targetBlends = blends; } + void setTargetBlends(std::initializer_list<TargetBlend> list) { m_targetBlends = list; } + template<typename InputIterator> + void setTargetBlends(InputIterator first, InputIterator last) + { + m_targetBlends.clear(); + std::copy(first, last, std::back_inserter(m_targetBlends)); + } + const TargetBlend *cbeginTargetBlends() const { return m_targetBlends.cbegin(); } + const TargetBlend *cendTargetBlends() const { return m_targetBlends.cend(); } bool hasDepthTest() const { return m_depthTest; } void setDepthTest(bool enable) { m_depthTest = enable; } @@ -1099,8 +1121,19 @@ public: float lineWidth() const { return m_lineWidth; } void setLineWidth(float width) { m_lineWidth = width; } - QVector<QRhiShaderStage> shaderStages() const { return m_shaderStages; } - void setShaderStages(const QVector<QRhiShaderStage> &stages) { m_shaderStages = stages; } + void setShaderStages(std::initializer_list<QRhiShaderStage> list) { m_shaderStages = list; } + template<typename InputIterator> + void setShaderStages(InputIterator first, InputIterator last) + { + m_shaderStages.clear(); + std::copy(first, last, std::back_inserter(m_shaderStages)); + } + void setShaderStages(const QVector<QRhiShaderStage> &stages) // compat., to be removed + { + setShaderStages(stages.cbegin(), stages.cend()); + } + const QRhiShaderStage *cbeginShaderStages() const { return m_shaderStages.cbegin(); } + const QRhiShaderStage *cendShaderStages() const { return m_shaderStages.cend(); } QRhiVertexInputLayout vertexInputLayout() const { return m_vertexInputLayout; } void setVertexInputLayout(const QRhiVertexInputLayout &layout) { m_vertexInputLayout = layout; } @@ -1119,7 +1152,7 @@ protected: Topology m_topology = Triangles; CullMode m_cullMode = None; FrontFace m_frontFace = CCW; - QVector<TargetBlend> m_targetBlends; + QVarLengthArray<TargetBlend, 8> m_targetBlends; bool m_depthTest = false; bool m_depthWrite = false; CompareOp m_depthOp = Less; @@ -1130,7 +1163,7 @@ protected: quint32 m_stencilWriteMask = 0xFF; int m_sampleCount = 1; float m_lineWidth = 1.0f; - QVector<QRhiShaderStage> m_shaderStages; + QVarLengthArray<QRhiShaderStage, 4> m_shaderStages; QRhiVertexInputLayout m_vertexInputLayout; QRhiShaderResourceBindings *m_shaderResourceBindings = nullptr; QRhiRenderPassDescriptor *m_renderPassDesc = nullptr; diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index a47f1ff86c..b82a68f3dd 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -3082,7 +3082,7 @@ bool QD3D11ShaderResourceBindings::build() if (!sortedBindings.isEmpty()) release(); - sortedBindings = m_bindings; + std::copy(m_bindings.cbegin(), m_bindings.cend(), std::back_inserter(sortedBindings)); std::sort(sortedBindings.begin(), sortedBindings.end(), [](const QRhiShaderResourceBinding &a, const QRhiShaderResourceBinding &b) { diff --git a/src/gui/rhi/qrhid3d11_p_p.h b/src/gui/rhi/qrhid3d11_p_p.h index cf4808510c..6699e7ad64 100644 --- a/src/gui/rhi/qrhid3d11_p_p.h +++ b/src/gui/rhi/qrhid3d11_p_p.h @@ -199,7 +199,7 @@ struct QD3D11ShaderResourceBindings : public QRhiShaderResourceBindings void release() override; bool build() override; - QVector<QRhiShaderResourceBinding> sortedBindings; + QVarLengthArray<QRhiShaderResourceBinding, 8> sortedBindings; uint generation = 0; // Keep track of the generation number of each referenced QRhi* to be able @@ -230,7 +230,7 @@ struct QD3D11ShaderResourceBindings : public QRhiShaderResourceBindings BoundStorageBufferData sbuf; }; }; - QVector<BoundResourceData> boundResourceData; + QVarLengthArray<BoundResourceData, 8> boundResourceData; QRhiBatchedBindings<ID3D11Buffer *> vsubufs; QRhiBatchedBindings<UINT> vsubufoffsets; diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm index ca6f829acf..4dc12f0691 100644 --- a/src/gui/rhi/qrhimetal.mm +++ b/src/gui/rhi/qrhimetal.mm @@ -2768,7 +2768,7 @@ bool QMetalShaderResourceBindings::build() if (!sortedBindings.isEmpty()) release(); - sortedBindings = m_bindings; + std::copy(m_bindings.cbegin(), m_bindings.cend(), std::back_inserter(sortedBindings)); std::sort(sortedBindings.begin(), sortedBindings.end(), [](const QRhiShaderResourceBinding &a, const QRhiShaderResourceBinding &b) { @@ -2782,7 +2782,7 @@ bool QMetalShaderResourceBindings::build() boundResourceData.resize(sortedBindings.count()); for (int i = 0, ie = sortedBindings.count(); i != ie; ++i) { - const QRhiShaderResourceBinding::Data *b = srbD->sortedBindings.at(i).data(); + const QRhiShaderResourceBinding::Data *b = sortedBindings.at(i).data(); QMetalShaderResourceBindings::BoundResourceData &bd(boundResourceData[i]); switch (b->type) { case QRhiShaderResourceBinding::UniformBuffer: diff --git a/src/gui/rhi/qrhimetal_p_p.h b/src/gui/rhi/qrhimetal_p_p.h index 7fd7aba923..688fec8147 100644 --- a/src/gui/rhi/qrhimetal_p_p.h +++ b/src/gui/rhi/qrhimetal_p_p.h @@ -188,7 +188,7 @@ struct QMetalShaderResourceBindings : public QRhiShaderResourceBindings void release() override; bool build() override; - QVector<QRhiShaderResourceBinding> sortedBindings; + QVarLengthArray<QRhiShaderResourceBinding, 8> sortedBindings; int maxBinding = -1; struct BoundUniformBufferData { @@ -217,7 +217,7 @@ struct QMetalShaderResourceBindings : public QRhiShaderResourceBindings BoundStorageBufferData sbuf; }; }; - QVector<BoundResourceData> boundResourceData; + QVarLengthArray<BoundResourceData, 8> boundResourceData; uint generation = 0; friend class QRhiMetal; diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index 36cbc06f5a..b7fc50d259 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -5697,7 +5697,8 @@ bool QVkShaderResourceBindings::build() for (int i = 0; i < QVK_FRAMES_IN_FLIGHT; ++i) descSets[i] = VK_NULL_HANDLE; - sortedBindings = m_bindings; + sortedBindings.clear(); + std::copy(m_bindings.cbegin(), m_bindings.cend(), std::back_inserter(sortedBindings)); std::sort(sortedBindings.begin(), sortedBindings.end(), [](const QRhiShaderResourceBinding &a, const QRhiShaderResourceBinding &b) { diff --git a/src/gui/rhi/qrhivulkan_p_p.h b/src/gui/rhi/qrhivulkan_p_p.h index a390bc3707..d83a338acd 100644 --- a/src/gui/rhi/qrhivulkan_p_p.h +++ b/src/gui/rhi/qrhivulkan_p_p.h @@ -232,7 +232,7 @@ struct QVkShaderResourceBindings : public QRhiShaderResourceBindings void release() override; bool build() override; - QVector<QRhiShaderResourceBinding> sortedBindings; + QVarLengthArray<QRhiShaderResourceBinding, 8> sortedBindings; int poolIndex = -1; VkDescriptorSetLayout layout = VK_NULL_HANDLE; VkDescriptorSet descSets[QVK_FRAMES_IN_FLIGHT]; // multiple sets to support dynamic buffers @@ -268,7 +268,7 @@ struct QVkShaderResourceBindings : public QRhiShaderResourceBindings BoundStorageBufferData sbuf; }; }; - QVector<BoundResourceData> boundResourceData[QVK_FRAMES_IN_FLIGHT]; + QVarLengthArray<BoundResourceData, 8> boundResourceData[QVK_FRAMES_IN_FLIGHT]; friend class QRhiVulkan; }; |