From 75e6c175de7efc602e486091d90ddef26d357e6d Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Tue, 15 Jun 2021 23:10:38 +1000 Subject: [PATCH] GPU/HW: Elide redundant UBO updates on draw mode change --- src/core/gpu_hw.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/core/gpu_hw.cpp b/src/core/gpu_hw.cpp index 3c90e6616..2766eabb5 100644 --- a/src/core/gpu_hw.cpp +++ b/src/core/gpu_hw.cpp @@ -1280,18 +1280,24 @@ void GPU_HW::DispatchRenderCommand() if (m_batch.transparency_mode != transparency_mode && transparency_mode != GPUTransparencyMode::Disabled) { static constexpr float transparent_alpha[4][2] = {{0.5f, 0.5f}, {1.0f, 1.0f}, {1.0f, 1.0f}, {0.25f, 1.0f}}; - m_batch_ubo_data.u_src_alpha_factor = transparent_alpha[static_cast(transparency_mode)][0]; - m_batch_ubo_data.u_dst_alpha_factor = transparent_alpha[static_cast(transparency_mode)][1]; - m_batch_ubo_dirty = true; + + const float src_alpha_factor = transparent_alpha[static_cast(transparency_mode)][0]; + const float dst_alpha_factor = transparent_alpha[static_cast(transparency_mode)][1]; + m_batch_ubo_dirty |= (m_batch_ubo_data.u_src_alpha_factor != src_alpha_factor || + m_batch_ubo_data.u_dst_alpha_factor != dst_alpha_factor); + m_batch_ubo_data.u_dst_alpha_factor = src_alpha_factor; + m_batch_ubo_data.u_src_alpha_factor = dst_alpha_factor; } - if (m_batch.check_mask_before_draw != m_GPUSTAT.check_mask_before_draw || - m_batch.set_mask_while_drawing != m_GPUSTAT.set_mask_while_drawing) + const bool check_mask_before_draw = m_GPUSTAT.check_mask_before_draw; + const bool set_mask_while_drawing = m_GPUSTAT.set_mask_while_drawing; + if (m_batch.check_mask_before_draw != check_mask_before_draw || + m_batch.set_mask_while_drawing != set_mask_while_drawing) { - m_batch.check_mask_before_draw = m_GPUSTAT.check_mask_before_draw; - m_batch.set_mask_while_drawing = m_GPUSTAT.set_mask_while_drawing; - m_batch_ubo_data.u_set_mask_while_drawing = BoolToUInt32(m_batch.set_mask_while_drawing); - m_batch_ubo_dirty = true; + m_batch.check_mask_before_draw = check_mask_before_draw; + m_batch.set_mask_while_drawing = set_mask_while_drawing; + m_batch_ubo_dirty |= (m_batch_ubo_data.u_set_mask_while_drawing != BoolToUInt32(set_mask_while_drawing)); + m_batch_ubo_data.u_set_mask_while_drawing = BoolToUInt32(set_mask_while_drawing); } m_batch.interlacing = IsInterlacedRenderingEnabled();