diff options
Diffstat (limited to 'src/video_core')
| -rw-r--r-- | src/video_core/engines/maxwell_3d.cpp | 19 | ||||
| -rw-r--r-- | src/video_core/engines/maxwell_3d.h | 5 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 14 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.h | 18 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | 27 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer_cache.h | 3 |
6 files changed, 78 insertions, 8 deletions
diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp index 0ed7bc5d8..d64a5080b 100644 --- a/src/video_core/engines/maxwell_3d.cpp +++ b/src/video_core/engines/maxwell_3d.cpp | |||
| @@ -135,6 +135,25 @@ void Maxwell3D::CallMethod(const GPU::MethodCall& method_call) { | |||
| 135 | 135 | ||
| 136 | if (regs.reg_array[method_call.method] != method_call.argument) { | 136 | if (regs.reg_array[method_call.method] != method_call.argument) { |
| 137 | regs.reg_array[method_call.method] = method_call.argument; | 137 | regs.reg_array[method_call.method] = method_call.argument; |
| 138 | // Color buffers | ||
| 139 | constexpr u32 first_rt_reg = MAXWELL3D_REG_INDEX(rt); | ||
| 140 | constexpr u32 registers_per_rt = sizeof(regs.rt[0]) / sizeof(u32); | ||
| 141 | if (method_call.method >= first_rt_reg && | ||
| 142 | method_call.method < first_rt_reg + registers_per_rt * Regs::NumRenderTargets) { | ||
| 143 | const std::size_t rt_index = (method_call.method - first_rt_reg) / registers_per_rt; | ||
| 144 | dirty_flags.color_buffer |= 1u << static_cast<u32>(rt_index); | ||
| 145 | } | ||
| 146 | |||
| 147 | // Zeta buffer | ||
| 148 | constexpr u32 registers_in_zeta = sizeof(regs.zeta) / sizeof(u32); | ||
| 149 | if (method_call.method == MAXWELL3D_REG_INDEX(zeta_enable) || | ||
| 150 | method_call.method == MAXWELL3D_REG_INDEX(zeta_width) || | ||
| 151 | method_call.method == MAXWELL3D_REG_INDEX(zeta_height) || | ||
| 152 | (method_call.method >= MAXWELL3D_REG_INDEX(zeta) && | ||
| 153 | method_call.method < MAXWELL3D_REG_INDEX(zeta) + registers_in_zeta)) { | ||
| 154 | dirty_flags.zeta_buffer = true; | ||
| 155 | } | ||
| 156 | |||
| 138 | // Shader | 157 | // Shader |
| 139 | constexpr u32 shader_registers_count = | 158 | constexpr u32 shader_registers_count = |
| 140 | sizeof(regs.shader_config[0]) * Regs::MaxShaderProgram / sizeof(u32); | 159 | 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 d50e5a126..1f76aa670 100644 --- a/src/video_core/engines/maxwell_3d.h +++ b/src/video_core/engines/maxwell_3d.h | |||
| @@ -1089,12 +1089,17 @@ public: | |||
| 1089 | MemoryManager& memory_manager; | 1089 | MemoryManager& memory_manager; |
| 1090 | 1090 | ||
| 1091 | struct DirtyFlags { | 1091 | struct DirtyFlags { |
| 1092 | u8 color_buffer = 0xFF; | ||
| 1093 | bool zeta_buffer = true; | ||
| 1094 | |||
| 1092 | bool shaders = true; | 1095 | bool shaders = true; |
| 1093 | 1096 | ||
| 1094 | bool vertex_attrib_format = true; | 1097 | bool vertex_attrib_format = true; |
| 1095 | u32 vertex_array = 0xFFFFFFFF; | 1098 | u32 vertex_array = 0xFFFFFFFF; |
| 1096 | 1099 | ||
| 1097 | void OnMemoryWrite() { | 1100 | void OnMemoryWrite() { |
| 1101 | color_buffer = 0xFF; | ||
| 1102 | zeta_buffer = true; | ||
| 1098 | shaders = true; | 1103 | shaders = true; |
| 1099 | vertex_array = 0xFFFFFFFF; | 1104 | vertex_array = 0xFFFFFFFF; |
| 1100 | } | 1105 | } |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 0c2a3265b..2bf086902 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -490,7 +490,19 @@ void RasterizerOpenGL::ConfigureFramebuffers(OpenGLState& current_state, bool us | |||
| 490 | bool using_depth_fb, bool preserve_contents, | 490 | bool using_depth_fb, bool preserve_contents, |
| 491 | std::optional<std::size_t> single_color_target) { | 491 | std::optional<std::size_t> single_color_target) { |
| 492 | MICROPROFILE_SCOPE(OpenGL_Framebuffer); | 492 | MICROPROFILE_SCOPE(OpenGL_Framebuffer); |
| 493 | const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; | 493 | const auto& gpu = Core::System::GetInstance().GPU().Maxwell3D(); |
| 494 | const auto& regs = gpu.regs; | ||
| 495 | |||
| 496 | const FramebufferConfigState fb_config_state{using_color_fb, using_depth_fb, preserve_contents, | ||
| 497 | single_color_target}; | ||
| 498 | if (fb_config_state == current_framebuffer_config_state && gpu.dirty_flags.color_buffer == 0 && | ||
| 499 | !gpu.dirty_flags.zeta_buffer) { | ||
| 500 | // Only skip if the previous ConfigureFramebuffers call was from the same kind (multiple or | ||
| 501 | // single color targets). This is done because the guest registers may not change but the | ||
| 502 | // host framebuffer may contain different attachments | ||
| 503 | return; | ||
| 504 | } | ||
| 505 | current_framebuffer_config_state = fb_config_state; | ||
| 494 | 506 | ||
| 495 | Surface depth_surface; | 507 | Surface depth_surface; |
| 496 | if (using_depth_fb) { | 508 | if (using_depth_fb) { |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index fe230083f..21c51f874 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h | |||
| @@ -99,6 +99,23 @@ private: | |||
| 99 | float max_anisotropic = 1.0f; | 99 | float max_anisotropic = 1.0f; |
| 100 | }; | 100 | }; |
| 101 | 101 | ||
| 102 | struct FramebufferConfigState { | ||
| 103 | bool using_color_fb{}; | ||
| 104 | bool using_depth_fb{}; | ||
| 105 | bool preserve_contents{}; | ||
| 106 | std::optional<std::size_t> single_color_target; | ||
| 107 | |||
| 108 | bool operator==(const FramebufferConfigState& rhs) const { | ||
| 109 | return std::tie(using_color_fb, using_depth_fb, preserve_contents, | ||
| 110 | single_color_target) == std::tie(rhs.using_color_fb, rhs.using_depth_fb, | ||
| 111 | rhs.preserve_contents, | ||
| 112 | rhs.single_color_target); | ||
| 113 | } | ||
| 114 | bool operator!=(const FramebufferConfigState& rhs) const { | ||
| 115 | return !operator==(rhs); | ||
| 116 | } | ||
| 117 | }; | ||
| 118 | |||
| 102 | /** | 119 | /** |
| 103 | * Configures the color and depth framebuffer states. | 120 | * Configures the color and depth framebuffer states. |
| 104 | * @param use_color_fb If true, configure color framebuffers. | 121 | * @param use_color_fb If true, configure color framebuffers. |
| @@ -203,6 +220,7 @@ private: | |||
| 203 | vertex_array_cache; | 220 | vertex_array_cache; |
| 204 | 221 | ||
| 205 | std::map<FramebufferCacheKey, OGLFramebuffer> framebuffer_cache; | 222 | std::map<FramebufferCacheKey, OGLFramebuffer> framebuffer_cache; |
| 223 | FramebufferConfigState current_framebuffer_config_state; | ||
| 206 | 224 | ||
| 207 | std::array<SamplerInfo, Tegra::Engines::Maxwell3D::Regs::NumTextureSamplers> texture_samplers; | 225 | std::array<SamplerInfo, Tegra::Engines::Maxwell3D::Regs::NumTextureSamplers> texture_samplers; |
| 208 | 226 | ||
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index bff0c65cd..a05b8b936 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | |||
| @@ -919,9 +919,16 @@ Surface RasterizerCacheOpenGL::GetTextureSurface(const Tegra::Texture::FullTextu | |||
| 919 | } | 919 | } |
| 920 | 920 | ||
| 921 | Surface RasterizerCacheOpenGL::GetDepthBufferSurface(bool preserve_contents) { | 921 | Surface RasterizerCacheOpenGL::GetDepthBufferSurface(bool preserve_contents) { |
| 922 | const auto& regs{Core::System::GetInstance().GPU().Maxwell3D().regs}; | 922 | auto& gpu{Core::System::GetInstance().GPU().Maxwell3D()}; |
| 923 | const auto& regs{gpu.regs}; | ||
| 924 | |||
| 925 | if (!gpu.dirty_flags.zeta_buffer) { | ||
| 926 | return last_depth_buffer; | ||
| 927 | } | ||
| 928 | gpu.dirty_flags.zeta_buffer = false; | ||
| 929 | |||
| 923 | if (!regs.zeta.Address() || !regs.zeta_enable) { | 930 | if (!regs.zeta.Address() || !regs.zeta_enable) { |
| 924 | return {}; | 931 | return last_depth_buffer = {}; |
| 925 | } | 932 | } |
| 926 | 933 | ||
| 927 | SurfaceParams depth_params{SurfaceParams::CreateForDepthBuffer( | 934 | SurfaceParams depth_params{SurfaceParams::CreateForDepthBuffer( |
| @@ -929,25 +936,31 @@ Surface RasterizerCacheOpenGL::GetDepthBufferSurface(bool preserve_contents) { | |||
| 929 | regs.zeta.memory_layout.block_width, regs.zeta.memory_layout.block_height, | 936 | regs.zeta.memory_layout.block_width, regs.zeta.memory_layout.block_height, |
| 930 | regs.zeta.memory_layout.block_depth, regs.zeta.memory_layout.type)}; | 937 | regs.zeta.memory_layout.block_depth, regs.zeta.memory_layout.type)}; |
| 931 | 938 | ||
| 932 | return GetSurface(depth_params, preserve_contents); | 939 | return last_depth_buffer = GetSurface(depth_params, preserve_contents); |
| 933 | } | 940 | } |
| 934 | 941 | ||
| 935 | Surface RasterizerCacheOpenGL::GetColorBufferSurface(std::size_t index, bool preserve_contents) { | 942 | Surface RasterizerCacheOpenGL::GetColorBufferSurface(std::size_t index, bool preserve_contents) { |
| 936 | const auto& regs{Core::System::GetInstance().GPU().Maxwell3D().regs}; | 943 | auto& gpu{Core::System::GetInstance().GPU().Maxwell3D()}; |
| 944 | const auto& regs{gpu.regs}; | ||
| 945 | |||
| 946 | if ((gpu.dirty_flags.color_buffer & (1u << static_cast<u32>(index))) == 0) { | ||
| 947 | return last_color_buffers[index]; | ||
| 948 | } | ||
| 949 | gpu.dirty_flags.color_buffer &= ~(1u << static_cast<u32>(index)); | ||
| 937 | 950 | ||
| 938 | ASSERT(index < Tegra::Engines::Maxwell3D::Regs::NumRenderTargets); | 951 | ASSERT(index < Tegra::Engines::Maxwell3D::Regs::NumRenderTargets); |
| 939 | 952 | ||
| 940 | if (index >= regs.rt_control.count) { | 953 | if (index >= regs.rt_control.count) { |
| 941 | return {}; | 954 | return last_color_buffers[index] = {}; |
| 942 | } | 955 | } |
| 943 | 956 | ||
| 944 | if (regs.rt[index].Address() == 0 || regs.rt[index].format == Tegra::RenderTargetFormat::NONE) { | 957 | if (regs.rt[index].Address() == 0 || regs.rt[index].format == Tegra::RenderTargetFormat::NONE) { |
| 945 | return {}; | 958 | return last_color_buffers[index] = {}; |
| 946 | } | 959 | } |
| 947 | 960 | ||
| 948 | const SurfaceParams color_params{SurfaceParams::CreateForFramebuffer(index)}; | 961 | const SurfaceParams color_params{SurfaceParams::CreateForFramebuffer(index)}; |
| 949 | 962 | ||
| 950 | return GetSurface(color_params, preserve_contents); | 963 | return last_color_buffers[index] = GetSurface(color_params, preserve_contents); |
| 951 | } | 964 | } |
| 952 | 965 | ||
| 953 | void RasterizerCacheOpenGL::LoadSurface(const Surface& surface) { | 966 | 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 7223700c4..37611c4fc 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.h +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.h | |||
| @@ -396,6 +396,9 @@ private: | |||
| 396 | /// Use a Pixel Buffer Object to download the previous texture and then upload it to the new one | 396 | /// Use a Pixel Buffer Object to download the previous texture and then upload it to the new one |
| 397 | /// using the new format. | 397 | /// using the new format. |
| 398 | OGLBuffer copy_pbo; | 398 | OGLBuffer copy_pbo; |
| 399 | |||
| 400 | std::array<Surface, Tegra::Engines::Maxwell3D::Regs::NumRenderTargets> last_color_buffers; | ||
| 401 | Surface last_depth_buffer; | ||
| 399 | }; | 402 | }; |
| 400 | 403 | ||
| 401 | } // namespace OpenGL | 404 | } // namespace OpenGL |