Commit 0e9cd8b4 authored by Gunnar Sletta's avatar Gunnar Sletta Committed by The Qt Project
Browse files

Cut performance cost in QSGContext::prepareMaterial()


The hash-lookup in this function is costing us a lot, and
since we're looking up the same materials again and again,
and the material has a place holder for it, we can store it
directly in the material at no extra cost. This was a 10%
gain in this particular benchmark.

Change-Id: I46b67791ce39f453fa86d1ee82f6f5c7785b46a1
Reviewed-by: default avatarYoann Lopes <yoann.lopes@digia.com>
Reviewed-by: default avatarSamuel Rødal <samuel.rodal@digia.com>
parent c23dfece
No related merge requests found
Showing with 10 additions and 1 deletion
...@@ -556,6 +556,7 @@ static void qt_print_material_count() ...@@ -556,6 +556,7 @@ static void qt_print_material_count()
QSGMaterial::QSGMaterial() QSGMaterial::QSGMaterial()
: m_flags(0) : m_flags(0)
, m_reserved(0)
{ {
#ifndef QT_NO_DEBUG #ifndef QT_NO_DEBUG
if (qsg_leak_check) { if (qsg_leak_check) {
......
...@@ -133,6 +133,7 @@ public: ...@@ -133,6 +133,7 @@ public:
void setFlag(Flags flags, bool on = true); void setFlag(Flags flags, bool on = true);
private: private:
friend class QSGContext;
Flags m_flags; Flags m_flags;
void *m_reserved; void *m_reserved;
Q_DISABLE_COPY(QSGMaterial) Q_DISABLE_COPY(QSGMaterial)
......
...@@ -478,10 +478,16 @@ QSGDepthStencilBufferManager *QSGContext::depthStencilBufferManager() ...@@ -478,10 +478,16 @@ QSGDepthStencilBufferManager *QSGContext::depthStencilBufferManager()
QSGMaterialShader *QSGContext::prepareMaterial(QSGMaterial *material) QSGMaterialShader *QSGContext::prepareMaterial(QSGMaterial *material)
{ {
Q_D(QSGContext); Q_D(QSGContext);
if (material->m_reserved)
return reinterpret_cast<QSGMaterialShader *>(material->m_reserved);
QSGMaterialType *type = material->type(); QSGMaterialType *type = material->type();
QSGMaterialShader *shader = d->materials.value(type); QSGMaterialShader *shader = d->materials.value(type);
if (shader) if (shader) {
material->m_reserved = shader;
return shader; return shader;
}
#ifndef QSG_NO_RENDER_TIMING #ifndef QSG_NO_RENDER_TIMING
if (qsg_render_timing || QQmlProfilerService::enabled) if (qsg_render_timing || QQmlProfilerService::enabled)
...@@ -489,6 +495,7 @@ QSGMaterialShader *QSGContext::prepareMaterial(QSGMaterial *material) ...@@ -489,6 +495,7 @@ QSGMaterialShader *QSGContext::prepareMaterial(QSGMaterial *material)
#endif #endif
shader = material->createShader(); shader = material->createShader();
material->m_reserved = shader;
shader->compile(); shader->compile();
shader->initialize(); shader->initialize();
d->materials[type] = shader; d->materials[type] = shader;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment