From 179ee963db1c8310e533daa4457b02b7a8141539 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Mon, 7 Jan 2019 01:11:03 -0300 Subject: [PATCH] gl_rasterizer_cache: Use dirty flags for color buffers --- src/video_core/engines/maxwell_3d.cpp | 9 +++++++++ src/video_core/engines/maxwell_3d.h | 3 +++ .../renderer_opengl/gl_rasterizer_cache.cpp | 14 ++++++++++---- .../renderer_opengl/gl_rasterizer_cache.h | 2 ++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp index 0ed7bc5d8c..88483eab9e 100644 --- a/src/video_core/engines/maxwell_3d.cpp +++ b/src/video_core/engines/maxwell_3d.cpp @@ -135,6 +135,15 @@ void Maxwell3D::CallMethod(const GPU::MethodCall& method_call) { if (regs.reg_array[method_call.method] != method_call.argument) { regs.reg_array[method_call.method] = method_call.argument; + // Color buffers + constexpr u32 first_rt_reg = MAXWELL3D_REG_INDEX(rt); + constexpr u32 registers_per_rt = sizeof(regs.rt[0]) / sizeof(u32); + if (method_call.method >= first_rt_reg && + method_call.method < first_rt_reg + registers_per_rt * Regs::NumRenderTargets) { + const std::size_t rt_index = (method_call.method - first_rt_reg) / registers_per_rt; + dirty_flags.color_buffer |= 1u << static_cast(rt_index); + } + // Shader constexpr u32 shader_registers_count = sizeof(regs.shader_config[0]) * Regs::MaxShaderProgram / sizeof(u32); diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h index d50e5a1261..8d0e18d808 100644 --- a/src/video_core/engines/maxwell_3d.h +++ b/src/video_core/engines/maxwell_3d.h @@ -1089,12 +1089,15 @@ public: MemoryManager& memory_manager; struct DirtyFlags { + u8 color_buffer = 0xFF; + bool shaders = true; bool vertex_attrib_format = true; u32 vertex_array = 0xFFFFFFFF; void OnMemoryWrite() { + color_buffer = 0xFF; shaders = true; vertex_array = 0xFFFFFFFF; } diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index d3dcb9a46b..0059b336ad 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp @@ -933,21 +933,27 @@ Surface RasterizerCacheOpenGL::GetDepthBufferSurface(bool preserve_contents) { } Surface RasterizerCacheOpenGL::GetColorBufferSurface(std::size_t index, bool preserve_contents) { - const auto& regs{Core::System::GetInstance().GPU().Maxwell3D().regs}; + auto& gpu{Core::System::GetInstance().GPU().Maxwell3D()}; + const auto& regs{gpu.regs}; + + if ((gpu.dirty_flags.color_buffer & (1u << static_cast(index))) == 0) { + return last_color_buffers[index]; + } + gpu.dirty_flags.color_buffer &= ~(1u << static_cast(index)); ASSERT(index < Tegra::Engines::Maxwell3D::Regs::NumRenderTargets); if (index >= regs.rt_control.count) { - return {}; + return last_color_buffers[index] = {}; } if (regs.rt[index].Address() == 0 || regs.rt[index].format == Tegra::RenderTargetFormat::NONE) { - return {}; + return last_color_buffers[index] = {}; } const SurfaceParams color_params{SurfaceParams::CreateForFramebuffer(index)}; - return GetSurface(color_params, preserve_contents); + return last_color_buffers[index] = GetSurface(color_params, preserve_contents); } void RasterizerCacheOpenGL::LoadSurface(const Surface& surface) { diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.h b/src/video_core/renderer_opengl/gl_rasterizer_cache.h index 7223700c48..3bdd141a7d 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.h +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.h @@ -396,6 +396,8 @@ private: /// Use a Pixel Buffer Object to download the previous texture and then upload it to the new one /// using the new format. OGLBuffer copy_pbo; + + std::array last_color_buffers; }; } // namespace OpenGL