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 <andy.nichols@qt.io>
This commit is contained in:
parent
878baeda2b
commit
0e767eaa29
|
@ -503,57 +503,61 @@ QSGD3D12Material::UpdateResults QSGD3D12TextMaterial::updatePipeline(const QSGD3
|
||||||
}
|
}
|
||||||
p += TEXT_CB_SIZE_0;
|
p += TEXT_CB_SIZE_0;
|
||||||
|
|
||||||
if (state.isCachedMaterialDataDirty() || m_lastGlyphCacheSize != glyphCache()->currentSize()) {
|
const QSize sz = glyphCache()->currentSize();
|
||||||
m_lastGlyphCacheSize = glyphCache()->currentSize();
|
const float textureScale[] = { 1.0f / sz.width(), 1.0f / sz.height() };
|
||||||
const float textureScale[2] = { 1.0f / m_lastGlyphCacheSize.width(),
|
if (state.isCachedMaterialDataDirty() || memcmp(p, textureScale, TEXT_CB_SIZE_1)) {
|
||||||
1.0f / m_lastGlyphCacheSize.height() };
|
|
||||||
memcpy(p, textureScale, TEXT_CB_SIZE_1);
|
memcpy(p, textureScale, TEXT_CB_SIZE_1);
|
||||||
r |= UpdatedConstantBuffer;
|
r |= UpdatedConstantBuffer;
|
||||||
}
|
}
|
||||||
p += TEXT_CB_SIZE_1;
|
p += TEXT_CB_SIZE_1;
|
||||||
|
|
||||||
const float dpr = m_rc->engine()->windowDevicePixelRatio();
|
const float dpr = m_rc->engine()->windowDevicePixelRatio();
|
||||||
if (state.isCachedMaterialDataDirty() || m_lastDpr != dpr) {
|
if (state.isCachedMaterialDataDirty() || memcmp(p, &dpr, TEXT_CB_SIZE_2)) {
|
||||||
m_lastDpr = dpr;
|
|
||||||
memcpy(p, &dpr, TEXT_CB_SIZE_2);
|
memcpy(p, &dpr, TEXT_CB_SIZE_2);
|
||||||
r |= UpdatedConstantBuffer;
|
r |= UpdatedConstantBuffer;
|
||||||
}
|
}
|
||||||
p += TEXT_CB_SIZE_2;
|
p += TEXT_CB_SIZE_2;
|
||||||
|
|
||||||
if (state.isOpacityDirty() || m_lastColor != m_color) {
|
|
||||||
m_lastColor = m_color;
|
|
||||||
if (glyphCache()->glyphFormat() == QFontEngine::Format_A32) {
|
if (glyphCache()->glyphFormat() == QFontEngine::Format_A32) {
|
||||||
const QVector4D color = qsg_premultiply(m_color, state.opacity());
|
const QVector4D color = qsg_premultiply(m_color, state.opacity());
|
||||||
const float alpha = color.w();
|
const float alpha = color.w();
|
||||||
|
if (state.isOpacityDirty() || memcmp(p, &alpha, TEXT_CB_SIZE_3)) {
|
||||||
memcpy(p, &alpha, TEXT_CB_SIZE_3);
|
memcpy(p, &alpha, TEXT_CB_SIZE_3);
|
||||||
|
r |= UpdatedConstantBuffer;
|
||||||
|
}
|
||||||
} else if (glyphCache()->glyphFormat() == QFontEngine::Format_ARGB) {
|
} else if (glyphCache()->glyphFormat() == QFontEngine::Format_ARGB) {
|
||||||
const float opacity = m_color.w() * state.opacity();
|
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);
|
memcpy(p, &opacity, TEXT_CB_SIZE_3);
|
||||||
|
r |= UpdatedConstantBuffer;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const QVector4D color = qsg_premultiply(m_color, state.opacity());
|
const QVector4D color = qsg_premultiply(m_color, state.opacity());
|
||||||
const float f[4] = { color.x(), color.y(), color.z(), color.w() };
|
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);
|
memcpy(p + TEXT_CB_SIZE_3, f, TEXT_CB_SIZE_4);
|
||||||
}
|
|
||||||
r |= UpdatedConstantBuffer;
|
r |= UpdatedConstantBuffer;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
p += TEXT_CB_SIZE_3 + TEXT_CB_SIZE_4;
|
p += TEXT_CB_SIZE_3 + TEXT_CB_SIZE_4;
|
||||||
|
|
||||||
if (m_styleType == Styled && (state.isCachedMaterialDataDirty() || m_lastStyleShift != m_styleShift)) {
|
if (m_styleType == Styled) {
|
||||||
m_lastStyleShift = m_styleShift;
|
const float f[] = { m_styleShift.x(), m_styleShift.y() };
|
||||||
const float f[2] = { m_styleShift.x(), m_styleShift.y() };
|
if (state.isCachedMaterialDataDirty() || memcmp(p, f, TEXT_CB_SIZE_5)) {
|
||||||
memcpy(p, f, TEXT_CB_SIZE_5);
|
memcpy(p, f, TEXT_CB_SIZE_5);
|
||||||
r |= UpdatedConstantBuffer;
|
r |= UpdatedConstantBuffer;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
p += TEXT_CB_SIZE_5 + TEXT_CB_SIZE_5_PADDING;
|
p += TEXT_CB_SIZE_5 + TEXT_CB_SIZE_5_PADDING;
|
||||||
|
|
||||||
if ((m_styleType == Styled || m_styleType == Outlined)
|
if (m_styleType == Styled || m_styleType == Outlined) {
|
||||||
&& (state.isOpacityDirty() || m_lastStyleColor != m_styleColor)) {
|
|
||||||
m_lastStyleColor = m_styleColor;
|
|
||||||
const QVector4D color = qsg_premultiply(m_styleColor, state.opacity());
|
const QVector4D color = qsg_premultiply(m_styleColor, state.opacity());
|
||||||
const float f[4] = { color.x(), color.y(), color.z(), color.w() };
|
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);
|
memcpy(p, f, TEXT_CB_SIZE_6);
|
||||||
r |= UpdatedConstantBuffer;
|
r |= UpdatedConstantBuffer;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QSGD3D12TextureView &tv(pipelineState->shaders.rootSig.textureViews[0]);
|
QSGD3D12TextureView &tv(pipelineState->shaders.rootSig.textureViews[0]);
|
||||||
tv.filter = QSGD3D12TextureView::FilterNearest;
|
tv.filter = QSGD3D12TextureView::FilterNearest;
|
||||||
|
|
|
@ -224,11 +224,6 @@ private:
|
||||||
QVector4D m_styleColor;
|
QVector4D m_styleColor;
|
||||||
QRawFont m_font;
|
QRawFont m_font;
|
||||||
QExplicitlySharedDataPointer<QFontEngineGlyphCache> m_glyphCache;
|
QExplicitlySharedDataPointer<QFontEngineGlyphCache> m_glyphCache;
|
||||||
QSize m_lastGlyphCacheSize;
|
|
||||||
float m_lastDpr = 0;
|
|
||||||
QVector4D m_lastColor;
|
|
||||||
QVector2D m_lastStyleShift;
|
|
||||||
QVector4D m_lastStyleColor;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
Loading…
Reference in New Issue