From 888b7ba33822dafea1ec19bda6d9ea06c8c5adad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Mon, 21 Jun 2021 19:25:08 -0400 Subject: [PATCH] radeonsi: optimize set_inlinable_constants when they don't change Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/gallium/drivers/radeonsi/si_descriptors.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/gallium/drivers/radeonsi/si_descriptors.c b/src/gallium/drivers/radeonsi/si_descriptors.c index 29178035deb..afa22d3ba0e 100644 --- a/src/gallium/drivers/radeonsi/si_descriptors.c +++ b/src/gallium/drivers/radeonsi/si_descriptors.c @@ -1231,9 +1231,21 @@ static void si_set_inlinable_constants(struct pipe_context *ctx, { struct si_context *sctx = (struct si_context *)ctx; - memcpy(sctx->inlinable_uniforms[shader], values, num_values * 4); - sctx->inlinable_uniforms_valid_mask |= 1 << shader; - sctx->do_update_shaders = true; + if (!(sctx->inlinable_uniforms_valid_mask & BITFIELD_BIT(shader))) { + /* It's the first time we set the constants. Always update shaders. */ + memcpy(sctx->inlinable_uniforms[shader], values, num_values * 4); + sctx->inlinable_uniforms_valid_mask |= BITFIELD_BIT(shader); + sctx->do_update_shaders = true; + return; + } + + /* We have already set inlinable constants for this shader. Update the shader only if + * the constants are being changed so as not to update shaders needlessly. + */ + if (memcmp(sctx->inlinable_uniforms[shader], values, num_values * 4)) { + memcpy(sctx->inlinable_uniforms[shader], values, num_values * 4); + sctx->do_update_shaders = true; + } } void si_get_pipe_constant_buffer(struct si_context *sctx, uint shader, uint slot,