From 0e767eaa29ea0a7edb101ba87fb8367e9f056eed Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 2 Jun 2016 15:40:07 +0200 Subject: D3D12: Remove m_lastNN members from text material To reduce the data size. The data is anyway available in the element-dedicated area of the constant buffer (better said, the plain CPU memory the renderer uses to prepare the data for the engine), so compare with that instead. Note that while the memcmp-memcpy pair may seem to have little value at first, setting the UpdatedConstantBuffer flag only when needed does have its benefits since the GPU-visible buffer mapping can be skipped completely when nothing has changed. Change-Id: Ie5d6797a06cb4259bd65114c5b69b11ff165e871 Reviewed-by: Andy Nichols --- .../scenegraph/d3d12/qsgd3d12builtinmaterials.cpp | 60 ++++++++++++---------- .../scenegraph/d3d12/qsgd3d12builtinmaterials_p.h | 5 -- 2 files changed, 32 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials.cpp b/src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials.cpp index f51130deb7..b631dd9d6c 100644 --- a/src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials.cpp +++ b/src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials.cpp @@ -503,56 +503,60 @@ QSGD3D12Material::UpdateResults QSGD3D12TextMaterial::updatePipeline(const QSGD3 } p += TEXT_CB_SIZE_0; - if (state.isCachedMaterialDataDirty() || m_lastGlyphCacheSize != glyphCache()->currentSize()) { - m_lastGlyphCacheSize = glyphCache()->currentSize(); - const float textureScale[2] = { 1.0f / m_lastGlyphCacheSize.width(), - 1.0f / m_lastGlyphCacheSize.height() }; + const QSize sz = glyphCache()->currentSize(); + const float textureScale[] = { 1.0f / sz.width(), 1.0f / sz.height() }; + if (state.isCachedMaterialDataDirty() || memcmp(p, textureScale, TEXT_CB_SIZE_1)) { memcpy(p, textureScale, TEXT_CB_SIZE_1); r |= UpdatedConstantBuffer; } p += TEXT_CB_SIZE_1; const float dpr = m_rc->engine()->windowDevicePixelRatio(); - if (state.isCachedMaterialDataDirty() || m_lastDpr != dpr) { - m_lastDpr = dpr; + if (state.isCachedMaterialDataDirty() || memcmp(p, &dpr, TEXT_CB_SIZE_2)) { memcpy(p, &dpr, TEXT_CB_SIZE_2); r |= UpdatedConstantBuffer; } p += TEXT_CB_SIZE_2; - if (state.isOpacityDirty() || m_lastColor != m_color) { - m_lastColor = m_color; - if (glyphCache()->glyphFormat() == QFontEngine::Format_A32) { - const QVector4D color = qsg_premultiply(m_color, state.opacity()); - const float alpha = color.w(); + if (glyphCache()->glyphFormat() == QFontEngine::Format_A32) { + const QVector4D color = qsg_premultiply(m_color, state.opacity()); + const float alpha = color.w(); + if (state.isOpacityDirty() || memcmp(p, &alpha, TEXT_CB_SIZE_3)) { memcpy(p, &alpha, TEXT_CB_SIZE_3); - } else if (glyphCache()->glyphFormat() == QFontEngine::Format_ARGB) { - const float opacity = m_color.w() * state.opacity(); + r |= UpdatedConstantBuffer; + } + } else if (glyphCache()->glyphFormat() == QFontEngine::Format_ARGB) { + const float opacity = m_color.w() * state.opacity(); + if (state.isOpacityDirty() || memcmp(p, &opacity, TEXT_CB_SIZE_3)) { memcpy(p, &opacity, TEXT_CB_SIZE_3); - } else { - const QVector4D color = qsg_premultiply(m_color, state.opacity()); - const float f[4] = { color.x(), color.y(), color.z(), color.w() }; + r |= UpdatedConstantBuffer; + } + } else { + const QVector4D color = qsg_premultiply(m_color, state.opacity()); + const float f[] = { color.x(), color.y(), color.z(), color.w() }; + if (state.isOpacityDirty() || memcmp(p, f, TEXT_CB_SIZE_4)) { memcpy(p + TEXT_CB_SIZE_3, f, TEXT_CB_SIZE_4); + r |= UpdatedConstantBuffer; } - r |= UpdatedConstantBuffer; } p += TEXT_CB_SIZE_3 + TEXT_CB_SIZE_4; - if (m_styleType == Styled && (state.isCachedMaterialDataDirty() || m_lastStyleShift != m_styleShift)) { - m_lastStyleShift = m_styleShift; - const float f[2] = { m_styleShift.x(), m_styleShift.y() }; - memcpy(p, f, TEXT_CB_SIZE_5); - r |= UpdatedConstantBuffer; + if (m_styleType == Styled) { + const float f[] = { m_styleShift.x(), m_styleShift.y() }; + if (state.isCachedMaterialDataDirty() || memcmp(p, f, TEXT_CB_SIZE_5)) { + memcpy(p, f, TEXT_CB_SIZE_5); + r |= UpdatedConstantBuffer; + } } p += TEXT_CB_SIZE_5 + TEXT_CB_SIZE_5_PADDING; - if ((m_styleType == Styled || m_styleType == Outlined) - && (state.isOpacityDirty() || m_lastStyleColor != m_styleColor)) { - m_lastStyleColor = m_styleColor; + if (m_styleType == Styled || m_styleType == Outlined) { const QVector4D color = qsg_premultiply(m_styleColor, state.opacity()); - const float f[4] = { color.x(), color.y(), color.z(), color.w() }; - memcpy(p, f, TEXT_CB_SIZE_6); - r |= UpdatedConstantBuffer; + const float f[] = { color.x(), color.y(), color.z(), color.w() }; + if (state.isOpacityDirty() || memcmp(p, f, TEXT_CB_SIZE_6)) { + memcpy(p, f, TEXT_CB_SIZE_6); + r |= UpdatedConstantBuffer; + } } QSGD3D12TextureView &tv(pipelineState->shaders.rootSig.textureViews[0]); diff --git a/src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials_p.h b/src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials_p.h index c64ff52ab0..e3c3957160 100644 --- a/src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials_p.h +++ b/src/plugins/scenegraph/d3d12/qsgd3d12builtinmaterials_p.h @@ -224,11 +224,6 @@ private: QVector4D m_styleColor; QRawFont m_font; QExplicitlySharedDataPointer m_glyphCache; - QSize m_lastGlyphCacheSize; - float m_lastDpr = 0; - QVector4D m_lastColor; - QVector2D m_lastStyleShift; - QVector4D m_lastStyleColor; }; QT_END_NAMESPACE -- cgit v1.2.3