diff options
author | ReinUsesLisp <reinuseslisp@airmail.cc> | 2019-09-17 07:36:47 +0200 |
---|---|---|
committer | ReinUsesLisp <reinuseslisp@airmail.cc> | 2019-09-17 07:50:42 +0200 |
commit | af809b491e8c6d727b973ee70e54b10bfcddbab1 (patch) | |
tree | 24c9d9fa3ccbff7febb6d515bdac9276ac4665d6 | |
parent | Merge pull request #2851 from ReinUsesLisp/srgb (diff) | |
download | yuzu-af809b491e8c6d727b973ee70e54b10bfcddbab1.tar yuzu-af809b491e8c6d727b973ee70e54b10bfcddbab1.tar.gz yuzu-af809b491e8c6d727b973ee70e54b10bfcddbab1.tar.bz2 yuzu-af809b491e8c6d727b973ee70e54b10bfcddbab1.tar.lz yuzu-af809b491e8c6d727b973ee70e54b10bfcddbab1.tar.xz yuzu-af809b491e8c6d727b973ee70e54b10bfcddbab1.tar.zst yuzu-af809b491e8c6d727b973ee70e54b10bfcddbab1.zip |
4 files changed, 33 insertions, 121 deletions
diff --git a/src/video_core/renderer_opengl/gl_framebuffer_cache.cpp b/src/video_core/renderer_opengl/gl_framebuffer_cache.cpp index 7c926bd48..a5d69d78d 100644 --- a/src/video_core/renderer_opengl/gl_framebuffer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_framebuffer_cache.cpp @@ -35,21 +35,16 @@ OGLFramebuffer FramebufferCacheOpenGL::CreateFramebuffer(const FramebufferCacheK local_state.draw.draw_framebuffer = framebuffer.handle; local_state.ApplyFramebufferState(); - if (key.is_single_buffer) { - if (key.color_attachments[0] != GL_NONE && key.colors[0]) { - key.colors[0]->Attach(key.color_attachments[0], GL_DRAW_FRAMEBUFFER); - glDrawBuffer(key.color_attachments[0]); - } else { - glDrawBuffer(GL_NONE); - } - } else { - for (std::size_t index = 0; index < Maxwell::NumRenderTargets; ++index) { - if (key.colors[index]) { - key.colors[index]->Attach(GL_COLOR_ATTACHMENT0 + static_cast<GLenum>(index), - GL_DRAW_FRAMEBUFFER); - } + for (std::size_t index = 0; index < Maxwell::NumRenderTargets; ++index) { + if (key.colors[index]) { + key.colors[index]->Attach(GL_COLOR_ATTACHMENT0 + static_cast<GLenum>(index), + GL_DRAW_FRAMEBUFFER); } + } + if (key.colors_count) { glDrawBuffers(key.colors_count, key.color_attachments.data()); + } else { + glDrawBuffer(GL_NONE); } if (key.zeta) { @@ -67,9 +62,9 @@ std::size_t FramebufferCacheKey::Hash() const { } bool FramebufferCacheKey::operator==(const FramebufferCacheKey& rhs) const { - return std::tie(is_single_buffer, stencil_enable, colors_count, color_attachments, colors, - zeta) == std::tie(rhs.is_single_buffer, rhs.stencil_enable, rhs.colors_count, - rhs.color_attachments, rhs.colors, rhs.zeta); + return std::tie(stencil_enable, colors_count, color_attachments, colors, zeta) == + std::tie(rhs.stencil_enable, rhs.colors_count, rhs.color_attachments, rhs.colors, + rhs.zeta); } } // namespace OpenGL diff --git a/src/video_core/renderer_opengl/gl_framebuffer_cache.h b/src/video_core/renderer_opengl/gl_framebuffer_cache.h index a3a996353..424344c48 100644 --- a/src/video_core/renderer_opengl/gl_framebuffer_cache.h +++ b/src/video_core/renderer_opengl/gl_framebuffer_cache.h @@ -19,7 +19,6 @@ namespace OpenGL { struct alignas(sizeof(u64)) FramebufferCacheKey { - bool is_single_buffer = false; bool stencil_enable = false; u16 colors_count = 0; diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 4dd08bccb..a2c1473db 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -445,99 +445,51 @@ void RasterizerOpenGL::LoadDiskResources(const std::atomic_bool& stop_loading, shader_cache.LoadDiskCache(stop_loading, callback); } -std::pair<bool, bool> RasterizerOpenGL::ConfigureFramebuffers( - OpenGLState& current_state, bool using_color_fb, bool using_depth_fb, bool preserve_contents, - std::optional<std::size_t> single_color_target) { +void RasterizerOpenGL::ConfigureFramebuffers() { MICROPROFILE_SCOPE(OpenGL_Framebuffer); auto& gpu = system.GPU().Maxwell3D(); - const auto& regs = gpu.regs; - - const FramebufferConfigState fb_config_state{using_color_fb, using_depth_fb, preserve_contents, - single_color_target}; - if (fb_config_state == current_framebuffer_config_state && !gpu.dirty.render_settings) { - // Only skip if the previous ConfigureFramebuffers call was from the same kind (multiple or - // single color targets). This is done because the guest registers may not change but the - // host framebuffer may contain different attachments - return current_depth_stencil_usage; + if (!gpu.dirty.render_settings) { + return; } gpu.dirty.render_settings = false; - current_framebuffer_config_state = fb_config_state; texture_cache.GuardRenderTargets(true); - View depth_surface{}; - if (using_depth_fb) { - depth_surface = texture_cache.GetDepthBufferSurface(preserve_contents); - } else { - texture_cache.SetEmptyDepthBuffer(); - } + View depth_surface = texture_cache.GetDepthBufferSurface(true); + const auto& regs = gpu.regs; + state.framebuffer_srgb.enabled = regs.framebuffer_srgb != 0; UNIMPLEMENTED_IF(regs.rt_separate_frag_data == 0); // Bind the framebuffer surfaces - current_state.framebuffer_srgb.enabled = regs.framebuffer_srgb != 0; - FramebufferCacheKey fbkey; + for (std::size_t index = 0; index < Maxwell::NumRenderTargets; ++index) { + View color_surface{texture_cache.GetColorBufferSurface(index, true)}; - if (using_color_fb) { - if (single_color_target) { - // Used when just a single color attachment is enabled, e.g. for clearing a color buffer - View color_surface{ - texture_cache.GetColorBufferSurface(*single_color_target, preserve_contents)}; - - if (color_surface) { - // Assume that a surface will be written to if it is used as a framebuffer, even if - // the shader doesn't actually write to it. - texture_cache.MarkColorBufferInUse(*single_color_target); - } - - fbkey.is_single_buffer = true; - fbkey.color_attachments[0] = - GL_COLOR_ATTACHMENT0 + static_cast<GLenum>(*single_color_target); - fbkey.colors[0] = color_surface; - for (std::size_t index = 0; index < Maxwell::NumRenderTargets; ++index) { - if (index != *single_color_target) { - texture_cache.SetEmptyColorBuffer(index); - } - } - } else { - // Multiple color attachments are enabled - for (std::size_t index = 0; index < Maxwell::NumRenderTargets; ++index) { - View color_surface{texture_cache.GetColorBufferSurface(index, preserve_contents)}; - - if (color_surface) { - // Assume that a surface will be written to if it is used as a framebuffer, even - // if the shader doesn't actually write to it. - texture_cache.MarkColorBufferInUse(index); - } - - fbkey.color_attachments[index] = - GL_COLOR_ATTACHMENT0 + regs.rt_control.GetMap(index); - fbkey.colors[index] = color_surface; - } - fbkey.is_single_buffer = false; - fbkey.colors_count = regs.rt_control.count; + if (color_surface) { + // Assume that a surface will be written to if it is used as a framebuffer, even + // if the shader doesn't actually write to it. + texture_cache.MarkColorBufferInUse(index); } - } else { - // No color attachments are enabled - leave them as zero - fbkey.is_single_buffer = true; + + fbkey.color_attachments[index] = GL_COLOR_ATTACHMENT0 + regs.rt_control.GetMap(index); + fbkey.colors[index] = std::move(color_surface); } + fbkey.colors_count = regs.rt_control.count; if (depth_surface) { // Assume that a surface will be written to if it is used as a framebuffer, even if // the shader doesn't actually write to it. texture_cache.MarkDepthBufferInUse(); - fbkey.zeta = depth_surface; fbkey.stencil_enable = depth_surface->GetSurfaceParams().type == SurfaceType::DepthStencil; + fbkey.zeta = std::move(depth_surface); } texture_cache.GuardRenderTargets(false); - current_state.draw.draw_framebuffer = framebuffer_cache.GetFramebuffer(fbkey); - SyncViewport(current_state); - - return current_depth_stencil_usage = {static_cast<bool>(depth_surface), fbkey.stencil_enable}; + state.draw.draw_framebuffer = framebuffer_cache.GetFramebuffer(fbkey); + SyncViewport(state); } void RasterizerOpenGL::ConfigureClearFramebuffer(OpenGLState& current_state, bool using_color_fb, @@ -757,7 +709,7 @@ void RasterizerOpenGL::DrawArrays() { SetupShaders(params.primitive_mode); texture_cache.GuardSamplers(false); - ConfigureFramebuffers(state); + ConfigureFramebuffers(); // Signal the buffer cache that we are not going to upload more things. const bool invalidate = buffer_cache.Unmap(); diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index eada752e0..4f5c7f864 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h @@ -77,39 +77,8 @@ public: const VideoCore::DiskResourceLoadCallback& callback) override; private: - struct FramebufferConfigState { - bool using_color_fb{}; - bool using_depth_fb{}; - bool preserve_contents{}; - std::optional<std::size_t> single_color_target; - - bool operator==(const FramebufferConfigState& rhs) const { - return std::tie(using_color_fb, using_depth_fb, preserve_contents, - single_color_target) == std::tie(rhs.using_color_fb, rhs.using_depth_fb, - rhs.preserve_contents, - rhs.single_color_target); - } - bool operator!=(const FramebufferConfigState& rhs) const { - return !operator==(rhs); - } - }; - - /** - * Configures the color and depth framebuffer states. - * - * @param current_state The current OpenGL state. - * @param using_color_fb If true, configure color framebuffers. - * @param using_depth_fb If true, configure the depth/stencil framebuffer. - * @param preserve_contents If true, tries to preserve data from a previously used - * framebuffer. - * @param single_color_target Specifies if a single color buffer target should be used. - * - * @returns If depth (first) or stencil (second) are being stored in the bound zeta texture - * (requires using_depth_fb to be true) - */ - std::pair<bool, bool> ConfigureFramebuffers( - OpenGLState& current_state, bool using_color_fb = true, bool using_depth_fb = true, - bool preserve_contents = true, std::optional<std::size_t> single_color_target = {}); + /// Configures the color and depth framebuffer states. + void ConfigureFramebuffers(); void ConfigureClearFramebuffer(OpenGLState& current_state, bool using_color_fb, bool using_depth_fb, bool using_stencil_fb); @@ -228,9 +197,6 @@ private: OGLVertexArray> vertex_array_cache; - FramebufferConfigState current_framebuffer_config_state; - std::pair<bool, bool> current_depth_stencil_usage{}; - static constexpr std::size_t STREAM_BUFFER_SIZE = 128 * 1024 * 1024; OGLBufferCache buffer_cache; |