From 92accc3ef7bd599e112a67ee0095b22dd48c3055 Mon Sep 17 00:00:00 2001 From: iwubcode Date: Tue, 19 Sep 2023 19:27:12 -0500 Subject: [PATCH] VideoCommon: add custom pixel shader constants as a buffer of data to be passed to all backends --- Source/Core/VideoCommon/PixelShaderManager.h | 6 ++++++ Source/Core/VideoCommon/VertexManagerBase.cpp | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Source/Core/VideoCommon/PixelShaderManager.h b/Source/Core/VideoCommon/PixelShaderManager.h index f0c8b5774f..5d3fe7257e 100644 --- a/Source/Core/VideoCommon/PixelShaderManager.h +++ b/Source/Core/VideoCommon/PixelShaderManager.h @@ -3,6 +3,8 @@ #pragma once +#include + #include "Common/CommonTypes.h" #include "VideoCommon/ConstantManager.h" @@ -52,6 +54,10 @@ public: PixelShaderConstants constants{}; bool dirty = false; + // Constants for custom shaders + std::span custom_constants; + bool custom_constants_dirty = false; + private: bool m_fog_range_adjusted_changed = false; bool m_viewport_changed = false; diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 2aac0f6f90..a7da900268 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -595,6 +595,7 @@ void VertexManagerBase::Flush() CustomPixelShaderContents custom_pixel_shader_contents; std::optional custom_pixel_shader; std::vector custom_pixel_texture_names; + std::span custom_pixel_shader_uniforms; for (int i = 0; i < texture_names.size(); i++) { const std::string& texture_name = texture_names[i]; @@ -644,6 +645,12 @@ void VertexManagerBase::Flush() // Now we can upload uniforms, as nothing else will override them. geometry_shader_manager.SetConstants(m_current_primitive_type); pixel_shader_manager.SetConstants(); + if (!custom_pixel_shader_uniforms.empty() && + pixel_shader_manager.custom_constants.data() != custom_pixel_shader_uniforms.data()) + { + pixel_shader_manager.custom_constants_dirty = true; + } + pixel_shader_manager.custom_constants = custom_pixel_shader_uniforms; UploadUniforms(); // Update the pipeline, or compile one if needed. @@ -1052,7 +1059,8 @@ void VertexManagerBase::OnEndFrame() return; // In order to reduce CPU readback latency, we want to kick a command buffer roughly halfway - // between the draw counters that invoked the readback, or every 250 draws, whichever is smaller. + // between the draw counters that invoked the readback, or every 250 draws, whichever is + // smaller. if (g_ActiveConfig.iCommandBufferExecuteInterval > 0) { u32 last_draw_counter = 0;