Skip to content

Commit c3ca872

Browse files
committed
use conversion cache
1 parent 4e3ba89 commit c3ca872

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
@@ -1440,6 +1440,8 @@ void CHyprOpenGLImpl::renderTextureWithDamage(SP<CTexture> tex, const CBox& box,
14401440
scissor(nullptr);
14411441
}
14421442

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

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

0 commit comments

Comments
 (0)