Skip to content

Commit 9f2be23

Browse files
committed
use conversion cache
1 parent ce2655a commit 9f2be23

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/render/OpenGL.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,8 @@ void CHyprOpenGLImpl::renderTextureWithDamage(SP<CTexture> tex, const CBox& box,
14411441
scissor(nullptr);
14421442
}
14431443

1444+
static std::map<std::pair<uint32_t, uint32_t>, std::array<GLfloat, 9>> primariesConversionCache;
1445+
14441446
void CHyprOpenGLImpl::passCMUniforms(const CShader& shader, const NColorManagement::SImageDescription& imageDescription,
14451447
const NColorManagement::SImageDescription& targetImageDescription, bool modifySDR) {
14461448
glUniform1i(shader.sourceTF, imageDescription.transferFunction);
@@ -1470,14 +1472,19 @@ void CHyprOpenGLImpl::passCMUniforms(const CShader& shader, const NColorManageme
14701472
glUniform1f(shader.sdrBrightness,
14711473
modifySDR && m_RenderData.pMonitor->sdrBrightness > 0 && targetImageDescription.transferFunction == NColorManagement::CM_TRANSFER_FUNCTION_ST2084_PQ ?
14721474
m_RenderData.pMonitor->sdrBrightness :
1475+
14731476
1.0f);
1474-
const auto mat = imageDescription.getPrimaries().convertMatrix(targetImageDescription.getPrimaries()).mat();
1475-
const GLfloat glConvertMatrix[9] = {
1476-
mat[0][0], mat[1][0], mat[2][0], //
1477-
mat[0][1], mat[1][1], mat[2][1], //
1478-
mat[0][2], mat[1][2], mat[2][2], //
1479-
};
1480-
glUniformMatrix3fv(shader.convertMatrix, 1, false, glConvertMatrix);
1477+
const auto cacheKey = std::make_pair(imageDescription.getId(), targetImageDescription.getId());
1478+
if (!primariesConversionCache.contains(cacheKey)) {
1479+
const auto mat = imageDescription.getPrimaries().convertMatrix(targetImageDescription.getPrimaries()).mat();
1480+
const std::array<GLfloat, 9> glConvertMatrix = {
1481+
mat[0][0], mat[1][0], mat[2][0], //
1482+
mat[0][1], mat[1][1], mat[2][1], //
1483+
mat[0][2], mat[1][2], mat[2][2], //
1484+
};
1485+
primariesConversionCache.insert(std::make_pair(cacheKey, glConvertMatrix));
1486+
}
1487+
glUniformMatrix3fv(shader.convertMatrix, 1, false, &primariesConversionCache[cacheKey][0]);
14811488
}
14821489

14831490
void CHyprOpenGLImpl::passCMUniforms(const CShader& shader, const SImageDescription& imageDescription) {

0 commit comments

Comments
 (0)