From c34da106edb3e5a6d519c7afe91f52c2abd2f901 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Thu, 28 Nov 2019 21:04:57 -0300 Subject: gl_rasterizer: Re-enable framebuffer cache for clear buffers --- src/video_core/renderer_opengl/gl_rasterizer.cpp | 41 ++++++++---------------- 1 file changed, 13 insertions(+), 28 deletions(-) (limited to 'src/video_core/renderer_opengl/gl_rasterizer.cpp') diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index a568a4343..18c122228 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -93,7 +93,6 @@ RasterizerOpenGL::RasterizerOpenGL(Core::System& system, Core::Frontend::EmuWind shader_program_manager = std::make_unique(); state.draw.shader_program = 0; state.Apply(); - clear_framebuffer.Create(); LOG_DEBUG(Render_OpenGL, "Sync fixed function OpenGL state here"); CheckExtensions(); @@ -405,46 +404,32 @@ void RasterizerOpenGL::ConfigureFramebuffers() { void RasterizerOpenGL::ConfigureClearFramebuffer(OpenGLState& current_state, bool using_color_fb, bool using_depth_fb, bool using_stencil_fb) { + using VideoCore::Surface::SurfaceType; + auto& gpu = system.GPU().Maxwell3D(); const auto& regs = gpu.regs; texture_cache.GuardRenderTargets(true); - View color_surface{}; + View color_surface; if (using_color_fb) { color_surface = texture_cache.GetColorBufferSurface(regs.clear_buffers.RT, false); } - View depth_surface{}; + View depth_surface; if (using_depth_fb || using_stencil_fb) { depth_surface = texture_cache.GetDepthBufferSurface(false); } texture_cache.GuardRenderTargets(false); - current_state.draw.draw_framebuffer = clear_framebuffer.handle; - current_state.ApplyFramebufferState(); + FramebufferCacheKey key; + key.colors_count = color_surface ? 1 : 0; + key.colors[0] = color_surface; + key.color_attachments[0] = GL_COLOR_ATTACHMENT0; + key.zeta = depth_surface; + key.stencil_enable = depth_surface && depth_surface->GetSurfaceParams().type == + VideoCore::Surface::SurfaceType::DepthStencil; - if (color_surface) { - color_surface->Attach(GL_COLOR_ATTACHMENT0, GL_DRAW_FRAMEBUFFER); - } else { - glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); - } - - if (depth_surface) { - const auto& params = depth_surface->GetSurfaceParams(); - switch (params.type) { - case VideoCore::Surface::SurfaceType::Depth: - depth_surface->Attach(GL_DEPTH_ATTACHMENT, GL_DRAW_FRAMEBUFFER); - glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0); - break; - case VideoCore::Surface::SurfaceType::DepthStencil: - depth_surface->Attach(GL_DEPTH_STENCIL_ATTACHMENT, GL_DRAW_FRAMEBUFFER); - break; - default: - UNIMPLEMENTED(); - } - } else { - glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, - 0); - } + current_state.draw.draw_framebuffer = framebuffer_cache.GetFramebuffer(key); + current_state.ApplyFramebufferState(); } void RasterizerOpenGL::Clear() { -- cgit v1.2.3 From fb6cf12a17daf1f452d9c542e22c9252bbfb5c76 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Thu, 28 Nov 2019 22:59:09 -0300 Subject: gl_framebuffer_cache: Optimize framebuffer key Pack color attachment enumerations into a single u32. To determine the number of buffers, the highest color attachment with a shared pointer that doesn't point to null is used. --- src/video_core/renderer_opengl/gl_rasterizer.cpp | 30 ++++++++++-------------- 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'src/video_core/renderer_opengl/gl_rasterizer.cpp') diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 18c122228..9eef7fcd2 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -372,33 +372,31 @@ void RasterizerOpenGL::ConfigureFramebuffers() { UNIMPLEMENTED_IF(regs.rt_separate_frag_data == 0); // Bind the framebuffer surfaces - FramebufferCacheKey fbkey; - for (std::size_t index = 0; index < Maxwell::NumRenderTargets; ++index) { + FramebufferCacheKey key; + const auto colors_count = static_cast(regs.rt_control.count); + for (std::size_t index = 0; index < colors_count; ++index) { View color_surface{texture_cache.GetColorBufferSurface(index, true)}; - - 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); + if (!color_surface) { + continue; } + // 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] = std::move(color_surface); + key.SetAttachment(index, regs.rt_control.GetMap(index)); + key.colors[index] = std::move(color_surface); } - fbkey.colors_count = static_cast(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.stencil_enable = depth_surface->GetSurfaceParams().type == SurfaceType::DepthStencil; - fbkey.zeta = std::move(depth_surface); + key.zeta = std::move(depth_surface); } texture_cache.GuardRenderTargets(false); - state.draw.draw_framebuffer = framebuffer_cache.GetFramebuffer(fbkey); + state.draw.draw_framebuffer = framebuffer_cache.GetFramebuffer(key); SyncViewport(state); } @@ -421,12 +419,8 @@ void RasterizerOpenGL::ConfigureClearFramebuffer(OpenGLState& current_state, boo texture_cache.GuardRenderTargets(false); FramebufferCacheKey key; - key.colors_count = color_surface ? 1 : 0; key.colors[0] = color_surface; - key.color_attachments[0] = GL_COLOR_ATTACHMENT0; key.zeta = depth_surface; - key.stencil_enable = depth_surface && depth_surface->GetSurfaceParams().type == - VideoCore::Surface::SurfaceType::DepthStencil; current_state.draw.draw_framebuffer = framebuffer_cache.GetFramebuffer(key); current_state.ApplyFramebufferState(); -- cgit v1.2.3