diff options
author | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2016-05-26 15:04:17 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2016-06-01 10:32:15 +0000 |
commit | a6d3e3afcdd8f08893cff4deed7e866a5daf3cbd (patch) | |
tree | 3f1b519e4f541b03b2b1a8c9c6fb0c1854e5735d | |
parent | b34296671b0a1a314153cefd817c06478839d65d (diff) |
D3D12: Get rid of the material's RenderState duplication
Change-Id: Icd42a1bfff0f12f8162e888f204ad9b3a79aa911
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
9 files changed, 27 insertions, 110 deletions
diff --git a/src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials.cpp b/src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials.cpp index e17badf018..f51130deb7 100644 --- a/src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials.cpp +++ b/src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials.cpp @@ -98,7 +98,7 @@ void QSGD3D12VertexColorMaterial::preparePipeline(QSGD3D12PipelineState *pipelin pipelineState->shaders.psSize = sizeof(g_PS_VertexColor); } -QSGD3D12Material::UpdateResults QSGD3D12VertexColorMaterial::updatePipeline(const RenderState &state, +QSGD3D12Material::UpdateResults QSGD3D12VertexColorMaterial::updatePipeline(const QSGD3D12MaterialRenderState &state, QSGD3D12PipelineState *, ExtraState *, quint8 *constantBuffer) @@ -158,7 +158,7 @@ void QSGD3D12SmoothColorMaterial::preparePipeline(QSGD3D12PipelineState *pipelin pipelineState->shaders.psSize = sizeof(g_PS_SmoothColor); } -QSGD3D12Material::UpdateResults QSGD3D12SmoothColorMaterial::updatePipeline(const RenderState &state, +QSGD3D12Material::UpdateResults QSGD3D12SmoothColorMaterial::updatePipeline(const QSGD3D12MaterialRenderState &state, QSGD3D12PipelineState *, ExtraState *, quint8 *constantBuffer) @@ -224,7 +224,7 @@ void QSGD3D12TextureMaterial::preparePipeline(QSGD3D12PipelineState *pipelineSta pipelineState->shaders.rootSig.textureViewCount = 1; } -QSGD3D12Material::UpdateResults QSGD3D12TextureMaterial::updatePipeline(const RenderState &state, +QSGD3D12Material::UpdateResults QSGD3D12TextureMaterial::updatePipeline(const QSGD3D12MaterialRenderState &state, QSGD3D12PipelineState *pipelineState, ExtraState *, quint8 *constantBuffer) @@ -307,7 +307,7 @@ void QSGD3D12SmoothTextureMaterial::preparePipeline(QSGD3D12PipelineState *pipel pipelineState->shaders.rootSig.textureViewCount = 1; } -QSGD3D12Material::UpdateResults QSGD3D12SmoothTextureMaterial::updatePipeline(const RenderState &state, +QSGD3D12Material::UpdateResults QSGD3D12SmoothTextureMaterial::updatePipeline(const QSGD3D12MaterialRenderState &state, QSGD3D12PipelineState *pipelineState, ExtraState *, quint8 *constantBuffer) @@ -482,7 +482,7 @@ void QSGD3D12TextMaterial::preparePipeline(QSGD3D12PipelineState *pipelineState) pipelineState->shaders.rootSig.textureViewCount = 1; } -QSGD3D12Material::UpdateResults QSGD3D12TextMaterial::updatePipeline(const RenderState &state, +QSGD3D12Material::UpdateResults QSGD3D12TextMaterial::updatePipeline(const QSGD3D12MaterialRenderState &state, QSGD3D12PipelineState *pipelineState, ExtraState *extraState, quint8 *constantBuffer) diff --git a/src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials_p.h b/src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials_p.h index 6786d8fc06..c64ff52ab0 100644 --- a/src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials_p.h +++ b/src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials_p.h @@ -68,7 +68,7 @@ public: int constantBufferSize() const override; void preparePipeline(QSGD3D12PipelineState *pipelineState) override; - UpdateResults updatePipeline(const RenderState &state, + UpdateResults updatePipeline(const QSGD3D12MaterialRenderState &state, QSGD3D12PipelineState *pipelineState, ExtraState *extraState, quint8 *constantBuffer) override; @@ -86,7 +86,7 @@ public: int constantBufferSize() const override; void preparePipeline(QSGD3D12PipelineState *pipelineState) override; - UpdateResults updatePipeline(const RenderState &state, + UpdateResults updatePipeline(const QSGD3D12MaterialRenderState &state, QSGD3D12PipelineState *pipelineState, ExtraState *extraState, quint8 *constantBuffer) override; @@ -103,7 +103,7 @@ public: int constantBufferSize() const override; void preparePipeline(QSGD3D12PipelineState *pipelineState) override; - UpdateResults updatePipeline(const RenderState &state, + UpdateResults updatePipeline(const QSGD3D12MaterialRenderState &state, QSGD3D12PipelineState *pipelineState, ExtraState *extraState, quint8 *constantBuffer) override; @@ -143,7 +143,7 @@ public: int constantBufferSize() const override; void preparePipeline(QSGD3D12PipelineState *pipelineState) override; - UpdateResults updatePipeline(const RenderState &state, + UpdateResults updatePipeline(const QSGD3D12MaterialRenderState &state, QSGD3D12PipelineState *pipelineState, ExtraState *extraState, quint8 *constantBuffer) override; @@ -191,7 +191,7 @@ public: int constantBufferSize() const override; void preparePipeline(QSGD3D12PipelineState *pipelineState) override; - UpdateResults updatePipeline(const RenderState &state, + UpdateResults updatePipeline(const QSGD3D12MaterialRenderState &state, QSGD3D12PipelineState *pipelineState, ExtraState *extraState, quint8 *constantBuffer) override; diff --git a/src/plugins/scenegraph/d3d12/qsgd3d12material.cpp b/src/plugins/scenegraph/d3d12/qsgd3d12material.cpp index 3412a4b63b..1b638106ee 100644 --- a/src/plugins/scenegraph/d3d12/qsgd3d12material.cpp +++ b/src/plugins/scenegraph/d3d12/qsgd3d12material.cpp @@ -38,66 +38,9 @@ ****************************************************************************/ #include "qsgd3d12material_p.h" -#include <private/qsgrenderer_p.h> QT_BEGIN_NAMESPACE -QSGD3D12Material::RenderState QSGD3D12Material::makeRenderState(QSGRenderer *renderer, RenderState::DirtyStates dirty) -{ - RenderState rs; - rs.m_dirty = dirty; - rs.m_data = renderer; - return rs; -} - -float QSGD3D12Material::RenderState::opacity() const -{ - Q_ASSERT(m_data); - return static_cast<const QSGRenderer *>(m_data)->currentOpacity(); -} - -float QSGD3D12Material::RenderState::determinant() const -{ - Q_ASSERT(m_data); - return static_cast<const QSGRenderer *>(m_data)->determinant(); -} - -QMatrix4x4 QSGD3D12Material::RenderState::combinedMatrix() const -{ - Q_ASSERT(m_data); - return static_cast<const QSGRenderer *>(m_data)->currentCombinedMatrix(); -} - -float QSGD3D12Material::RenderState::devicePixelRatio() const -{ - Q_ASSERT(m_data); - return static_cast<const QSGRenderer *>(m_data)->devicePixelRatio(); -} - -QMatrix4x4 QSGD3D12Material::RenderState::modelViewMatrix() const -{ - Q_ASSERT(m_data); - return static_cast<const QSGRenderer *>(m_data)->currentModelViewMatrix(); -} - -QMatrix4x4 QSGD3D12Material::RenderState::projectionMatrix() const -{ - Q_ASSERT(m_data); - return static_cast<const QSGRenderer *>(m_data)->currentProjectionMatrix(); -} - -QRect QSGD3D12Material::RenderState::viewportRect() const -{ - Q_ASSERT(m_data); - return static_cast<const QSGRenderer *>(m_data)->viewportRect(); -} - -QRect QSGD3D12Material::RenderState::deviceRect() const -{ - Q_ASSERT(m_data); - return static_cast<const QSGRenderer *>(m_data)->deviceRect(); -} - QSGMaterialShader *QSGD3D12Material::createShader() const { return nullptr; diff --git a/src/plugins/scenegraph/d3d12/qsgd3d12material_p.h b/src/plugins/scenegraph/d3d12/qsgd3d12material_p.h index e9af8e68a0..65d53600c3 100644 --- a/src/plugins/scenegraph/d3d12/qsgd3d12material_p.h +++ b/src/plugins/scenegraph/d3d12/qsgd3d12material_p.h @@ -62,37 +62,11 @@ class QSGRenderer; // QSGMaterial and its GL program related bits are not suitable. Also, there is // no split like with QSGMaterialShader. +typedef QSGMaterialShader::RenderState QSGD3D12MaterialRenderState; + class QSGD3D12Material : public QSGMaterial { public: - struct RenderState { - enum DirtyState { - DirtyMatrix = 0x0001, - DirtyOpacity = 0x0002, - DirtyCachedMaterialData = 0x0004, - DirtyAll = 0xFFFF - }; - Q_DECLARE_FLAGS(DirtyStates, DirtyState) - - DirtyStates dirtyStates() const { return m_dirty; } - - bool isMatrixDirty() const { return m_dirty & DirtyMatrix; } - bool isOpacityDirty() const { return m_dirty & DirtyOpacity; } - bool isCachedMaterialDataDirty() const { return m_dirty & DirtyCachedMaterialData; } - - float opacity() const; - QMatrix4x4 combinedMatrix() const; - QMatrix4x4 modelViewMatrix() const; - QMatrix4x4 projectionMatrix() const; - QRect viewportRect() const; - QRect deviceRect() const; - float determinant() const; - float devicePixelRatio() const; - - DirtyStates m_dirty = 0; - void *m_data = nullptr; - }; - struct ExtraState { QVector4D blendFactor; }; @@ -104,11 +78,9 @@ public: }; Q_DECLARE_FLAGS(UpdateResults, UpdateResult) - static RenderState makeRenderState(QSGRenderer *renderer, RenderState::DirtyStates dirty); - virtual int constantBufferSize() const = 0; virtual void preparePipeline(QSGD3D12PipelineState *pipelineState) = 0; - virtual UpdateResults updatePipeline(const RenderState &state, + virtual UpdateResults updatePipeline(const QSGD3D12MaterialRenderState &state, QSGD3D12PipelineState *pipelineState, ExtraState *extraState, quint8 *constantBuffer) = 0; @@ -117,7 +89,6 @@ private: QSGMaterialShader *createShader() const override; // dummy, QSGMaterialShader is too GL dependent }; -Q_DECLARE_OPERATORS_FOR_FLAGS(QSGD3D12Material::RenderState::DirtyStates) Q_DECLARE_OPERATORS_FOR_FLAGS(QSGD3D12Material::UpdateResults) QT_END_NAMESPACE diff --git a/src/plugins/scenegraph/d3d12/qsgd3d12renderer.cpp b/src/plugins/scenegraph/d3d12/qsgd3d12renderer.cpp index a1643ae51f..5e5d7a13f8 100644 --- a/src/plugins/scenegraph/d3d12/qsgd3d12renderer.cpp +++ b/src/plugins/scenegraph/d3d12/qsgd3d12renderer.cpp @@ -130,7 +130,7 @@ void QSGD3D12Renderer::updateMatrices(QSGNode *node, QSGTransformNode *xform) updateMatrices(child, tn); } else { if (node->type() == QSGNode::GeometryNodeType || node->type() == QSGNode::ClipNodeType) { - m_nodeDirtyMap[node] |= QSGD3D12Material::RenderState::DirtyMatrix; + m_nodeDirtyMap[node] |= QSGD3D12MaterialRenderState::DirtyMatrix; QSGBasicGeometryNode *gnode = static_cast<QSGBasicGeometryNode *>(node); const QMatrix4x4 *newMatrix = xform ? &xform->combinedMatrix() : nullptr; // NB the newMatrix ptr is usually the same as before as it just @@ -155,7 +155,7 @@ void QSGD3D12Renderer::updateOpacities(QSGNode *node, float inheritedOpacity) updateOpacities(child, combined); } else { if (node->type() == QSGNode::GeometryNodeType) { - m_nodeDirtyMap[node] |= QSGD3D12Material::RenderState::DirtyOpacity; + m_nodeDirtyMap[node] |= QSGD3D12MaterialRenderState::DirtyOpacity; QSGGeometryNode *gn = static_cast<QSGGeometryNode *>(node); gn->setInheritedOpacity(inheritedOpacity); } @@ -498,19 +498,19 @@ void QSGD3D12Renderer::renderElement(int elementIndex) m->preparePipeline(&m_pipelineState); } - QSGD3D12Material::RenderState::DirtyStates dirtyState = m_nodeDirtyMap.value(e.node); + QSGD3D12MaterialRenderState::DirtyStates dirtyState = m_nodeDirtyMap.value(e.node); // After a rebuild everything in the cbuffer has to be updated. if (!e.cboPrepared) { e.cboPrepared = true; - dirtyState = QSGD3D12Material::RenderState::DirtyAll; + dirtyState = QSGD3D12MaterialRenderState::DirtyAll; } // DirtyMatrix does not include projection matrix changes that can arise // due to changing the render target's size (and there is no rebuild). // Accommodate for this. if (m_projectionChangedDueToDeviceSize) - dirtyState |= QSGD3D12Material::RenderState::DirtyMatrix; + dirtyState |= QSGD3D12MaterialRenderState::DirtyMatrix; quint8 *cboPtr = nullptr; if (e.cboSize > 0) @@ -520,7 +520,7 @@ void QSGD3D12Renderer::renderElement(int elementIndex) qDebug() << "dirty state for" << e.node << "is" << dirtyState; QSGD3D12Material::ExtraState extraState; - QSGD3D12Material::UpdateResults updRes = m->updatePipeline(QSGD3D12Material::makeRenderState(this, dirtyState), + QSGD3D12Material::UpdateResults updRes = m->updatePipeline(state(dirtyState), &m_pipelineState, &extraState, cboPtr); diff --git a/src/plugins/scenegraph/d3d12/qsgd3d12renderer_p.h b/src/plugins/scenegraph/d3d12/qsgd3d12renderer_p.h index bed34df3a1..df30a49f0d 100644 --- a/src/plugins/scenegraph/d3d12/qsgd3d12renderer_p.h +++ b/src/plugins/scenegraph/d3d12/qsgd3d12renderer_p.h @@ -116,7 +116,7 @@ private: QSGD3D12PipelineState m_pipelineState; QSGD3D12PipelineState m_freshPipelineState; - typedef QHash<QSGNode *, QSGD3D12Material::RenderState::DirtyStates> NodeDirtyMap; + typedef QHash<QSGNode *, QSGD3D12MaterialRenderState::DirtyStates> NodeDirtyMap; NodeDirtyMap m_nodeDirtyMap; QRect m_activeScissorRect; diff --git a/src/plugins/scenegraph/d3d12/qsgd3d12shadereffectnode.cpp b/src/plugins/scenegraph/d3d12/qsgd3d12shadereffectnode.cpp index e335fac0b0..b5c0b1d903 100644 --- a/src/plugins/scenegraph/d3d12/qsgd3d12shadereffectnode.cpp +++ b/src/plugins/scenegraph/d3d12/qsgd3d12shadereffectnode.cpp @@ -326,7 +326,7 @@ static inline QColor qsg_premultiply_color(const QColor &c) return QColor::fromRgbF(c.redF() * c.alphaF(), c.greenF() * c.alphaF(), c.blueF() * c.alphaF(), c.alphaF()); } -QSGD3D12Material::UpdateResults QSGD3D12ShaderEffectMaterial::updatePipeline(const RenderState &state, +QSGD3D12Material::UpdateResults QSGD3D12ShaderEffectMaterial::updatePipeline(const QSGD3D12MaterialRenderState &state, QSGD3D12PipelineState *pipelineState, ExtraState *, quint8 *constantBuffer) diff --git a/src/plugins/scenegraph/d3d12/qsgd3d12shadereffectnode_p.h b/src/plugins/scenegraph/d3d12/qsgd3d12shadereffectnode_p.h index c8994a78dd..41d366abda 100644 --- a/src/plugins/scenegraph/d3d12/qsgd3d12shadereffectnode_p.h +++ b/src/plugins/scenegraph/d3d12/qsgd3d12shadereffectnode_p.h @@ -107,7 +107,7 @@ public: int constantBufferSize() const override; void preparePipeline(QSGD3D12PipelineState *pipelineState) override; - UpdateResults updatePipeline(const RenderState &state, + UpdateResults updatePipeline(const QSGD3D12MaterialRenderState &state, QSGD3D12PipelineState *pipelineState, ExtraState *extraState, quint8 *constantBuffer) override; diff --git a/src/quick/scenegraph/coreapi/qsgmaterial.h b/src/quick/scenegraph/coreapi/qsgmaterial.h index 13d15a089e..114651653f 100644 --- a/src/quick/scenegraph/coreapi/qsgmaterial.h +++ b/src/quick/scenegraph/coreapi/qsgmaterial.h @@ -63,8 +63,10 @@ public: public: enum DirtyState { - DirtyMatrix = 0x0001, - DirtyOpacity = 0x0002 + DirtyMatrix = 0x0001, + DirtyOpacity = 0x0002, + DirtyCachedMaterialData = 0x0004, + DirtyAll = 0xFFFF }; Q_DECLARE_FLAGS(DirtyStates, DirtyState) @@ -72,6 +74,7 @@ public: inline bool isMatrixDirty() const { return m_dirty & DirtyMatrix; } inline bool isOpacityDirty() const { return m_dirty & DirtyOpacity; } + bool isCachedMaterialDataDirty() const { return m_dirty & DirtyCachedMaterialData; } float opacity() const; QMatrix4x4 combinedMatrix() const; |