diff options
| author | 2019-07-14 08:14:27 -0400 | |
|---|---|---|
| committer | 2019-07-17 17:29:52 -0400 | |
| commit | fec32fed18bd4210f00150018a05ab010091e573 (patch) | |
| tree | 81250a6801d23e54f1681e8881cabebbd1e9f01d /src | |
| parent | Maxwell3D: Implement State Dirty Flags. (diff) | |
| download | yuzu-fec32fed18bd4210f00150018a05ab010091e573.tar.gz yuzu-fec32fed18bd4210f00150018a05ab010091e573.tar.xz yuzu-fec32fed18bd4210f00150018a05ab010091e573.zip | |
GL_Rasterizer: Rework RenderTarget/DepthBuffer clearing
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/engines/maxwell_3d.cpp | 1 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 64 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.h | 5 |
3 files changed, 63 insertions, 7 deletions
diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp index cfa98f528..d499aaa8d 100644 --- a/src/video_core/engines/maxwell_3d.cpp +++ b/src/video_core/engines/maxwell_3d.cpp | |||
| @@ -568,7 +568,6 @@ void Maxwell3D::FinishCBData() { | |||
| 568 | 568 | ||
| 569 | const u32 id = cb_data_state.id; | 569 | const u32 id = cb_data_state.id; |
| 570 | memory_manager.WriteBlock(address, cb_data_state.buff[id].data(), size); | 570 | memory_manager.WriteBlock(address, cb_data_state.buff[id].data(), size); |
| 571 | dirty.ResetRenderTargets(); | ||
| 572 | 571 | ||
| 573 | cb_data_state.id = null_cb_data; | 572 | cb_data_state.id = null_cb_data; |
| 574 | cb_data_state.current = null_cb_data; | 573 | cb_data_state.current = null_cb_data; |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 76f0f98eb..4aa3d6548 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -105,6 +105,7 @@ RasterizerOpenGL::RasterizerOpenGL(Core::System& system, Core::Frontend::EmuWind | |||
| 105 | shader_program_manager = std::make_unique<GLShader::ProgramManager>(); | 105 | shader_program_manager = std::make_unique<GLShader::ProgramManager>(); |
| 106 | state.draw.shader_program = 0; | 106 | state.draw.shader_program = 0; |
| 107 | state.Apply(); | 107 | state.Apply(); |
| 108 | clear_framebuffer.Create(); | ||
| 108 | 109 | ||
| 109 | LOG_DEBUG(Render_OpenGL, "Sync fixed function OpenGL state here"); | 110 | LOG_DEBUG(Render_OpenGL, "Sync fixed function OpenGL state here"); |
| 110 | CheckExtensions(); | 111 | CheckExtensions(); |
| @@ -546,12 +547,63 @@ std::pair<bool, bool> RasterizerOpenGL::ConfigureFramebuffers( | |||
| 546 | return current_depth_stencil_usage = {static_cast<bool>(depth_surface), fbkey.stencil_enable}; | 547 | return current_depth_stencil_usage = {static_cast<bool>(depth_surface), fbkey.stencil_enable}; |
| 547 | } | 548 | } |
| 548 | 549 | ||
| 550 | void RasterizerOpenGL::ConfigureClearFramebuffer(OpenGLState& current_state, bool using_color_fb, | ||
| 551 | bool using_depth_fb, bool using_stencil_fb) { | ||
| 552 | auto& gpu = system.GPU().Maxwell3D(); | ||
| 553 | const auto& regs = gpu.regs; | ||
| 554 | |||
| 555 | texture_cache.GuardRenderTargets(true); | ||
| 556 | View color_surface{}; | ||
| 557 | if (using_color_fb) { | ||
| 558 | color_surface = texture_cache.GetColorBufferSurface(regs.clear_buffers.RT, false); | ||
| 559 | } | ||
| 560 | View depth_surface{}; | ||
| 561 | if (using_depth_fb || using_stencil_fb) { | ||
| 562 | depth_surface = texture_cache.GetDepthBufferSurface(false); | ||
| 563 | } | ||
| 564 | texture_cache.GuardRenderTargets(false); | ||
| 565 | |||
| 566 | current_state.draw.draw_framebuffer = clear_framebuffer.handle; | ||
| 567 | current_state.ApplyFramebufferState(); | ||
| 568 | |||
| 569 | if (color_surface) { | ||
| 570 | color_surface->Attach(GL_COLOR_ATTACHMENT0, GL_DRAW_FRAMEBUFFER); | ||
| 571 | } else { | ||
| 572 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); | ||
| 573 | } | ||
| 574 | |||
| 575 | if (depth_surface) { | ||
| 576 | const auto& params = depth_surface->GetSurfaceParams(); | ||
| 577 | switch (params.type) { | ||
| 578 | case VideoCore::Surface::SurfaceType::Depth: { | ||
| 579 | depth_surface->Attach(GL_DEPTH_ATTACHMENT, GL_DRAW_FRAMEBUFFER); | ||
| 580 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0); | ||
| 581 | break; | ||
| 582 | } | ||
| 583 | case VideoCore::Surface::SurfaceType::DepthStencil: { | ||
| 584 | depth_surface->Attach(GL_DEPTH_ATTACHMENT, GL_DRAW_FRAMEBUFFER); | ||
| 585 | break; | ||
| 586 | } | ||
| 587 | default: { UNIMPLEMENTED(); } | ||
| 588 | } | ||
| 589 | } else { | ||
| 590 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, | ||
| 591 | 0); | ||
| 592 | } | ||
| 593 | } | ||
| 594 | |||
| 549 | void RasterizerOpenGL::Clear() { | 595 | void RasterizerOpenGL::Clear() { |
| 550 | const auto& regs = system.GPU().Maxwell3D().regs; | 596 | const auto& regs = system.GPU().Maxwell3D().regs; |
| 551 | bool use_color{}; | 597 | bool use_color{}; |
| 552 | bool use_depth{}; | 598 | bool use_depth{}; |
| 553 | bool use_stencil{}; | 599 | bool use_stencil{}; |
| 554 | 600 | ||
| 601 | OpenGLState prev_state{OpenGLState::GetCurState()}; | ||
| 602 | SCOPE_EXIT({ | ||
| 603 | prev_state.AllDirty(); | ||
| 604 | prev_state.Apply(); | ||
| 605 | }); | ||
| 606 | |||
| 555 | OpenGLState clear_state; | 607 | OpenGLState clear_state; |
| 556 | if (regs.clear_buffers.R || regs.clear_buffers.G || regs.clear_buffers.B || | 608 | if (regs.clear_buffers.R || regs.clear_buffers.G || regs.clear_buffers.B || |
| 557 | regs.clear_buffers.A) { | 609 | regs.clear_buffers.A) { |
| @@ -608,8 +660,8 @@ void RasterizerOpenGL::Clear() { | |||
| 608 | return; | 660 | return; |
| 609 | } | 661 | } |
| 610 | 662 | ||
| 611 | const auto [clear_depth, clear_stencil] = ConfigureFramebuffers( | 663 | ConfigureClearFramebuffer(clear_state, use_color, use_depth, use_stencil); |
| 612 | clear_state, use_color, use_depth || use_stencil, false, regs.clear_buffers.RT.Value()); | 664 | SyncViewport(clear_state); |
| 613 | if (regs.clear_flags.scissor) { | 665 | if (regs.clear_flags.scissor) { |
| 614 | SyncScissorTest(clear_state); | 666 | SyncScissorTest(clear_state); |
| 615 | } | 667 | } |
| @@ -625,14 +677,14 @@ void RasterizerOpenGL::Clear() { | |||
| 625 | clear_state.ApplyFramebufferState(); | 677 | clear_state.ApplyFramebufferState(); |
| 626 | 678 | ||
| 627 | if (use_color) { | 679 | if (use_color) { |
| 628 | glClearBufferfv(GL_COLOR, regs.clear_buffers.RT, regs.clear_color); | 680 | glClearBufferfv(GL_COLOR, 0, regs.clear_color); |
| 629 | } | 681 | } |
| 630 | 682 | ||
| 631 | if (clear_depth && clear_stencil) { | 683 | if (use_depth && use_stencil) { |
| 632 | glClearBufferfi(GL_DEPTH_STENCIL, 0, regs.clear_depth, regs.clear_stencil); | 684 | glClearBufferfi(GL_DEPTH_STENCIL, 0, regs.clear_depth, regs.clear_stencil); |
| 633 | } else if (clear_depth) { | 685 | } else if (use_depth) { |
| 634 | glClearBufferfv(GL_DEPTH, 0, ®s.clear_depth); | 686 | glClearBufferfv(GL_DEPTH, 0, ®s.clear_depth); |
| 635 | } else if (clear_stencil) { | 687 | } else if (use_stencil) { |
| 636 | glClearBufferiv(GL_STENCIL, 0, ®s.clear_stencil); | 688 | glClearBufferiv(GL_STENCIL, 0, ®s.clear_stencil); |
| 637 | } | 689 | } |
| 638 | } | 690 | } |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index 1f6ce4b81..ef34d3f54 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h | |||
| @@ -108,6 +108,9 @@ private: | |||
| 108 | OpenGLState& current_state, bool using_color_fb = true, bool using_depth_fb = true, | 108 | OpenGLState& current_state, bool using_color_fb = true, bool using_depth_fb = true, |
| 109 | bool preserve_contents = true, std::optional<std::size_t> single_color_target = {}); | 109 | bool preserve_contents = true, std::optional<std::size_t> single_color_target = {}); |
| 110 | 110 | ||
| 111 | void ConfigureClearFramebuffer(OpenGLState& current_state, bool using_color_fb, | ||
| 112 | bool using_depth_fb, bool using_stencil_fb); | ||
| 113 | |||
| 111 | /// Configures the current constbuffers to use for the draw command. | 114 | /// Configures the current constbuffers to use for the draw command. |
| 112 | void SetupDrawConstBuffers(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, | 115 | void SetupDrawConstBuffers(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, |
| 113 | const Shader& shader); | 116 | const Shader& shader); |
| @@ -227,6 +230,8 @@ private: | |||
| 227 | enum class AccelDraw { Disabled, Arrays, Indexed }; | 230 | enum class AccelDraw { Disabled, Arrays, Indexed }; |
| 228 | AccelDraw accelerate_draw = AccelDraw::Disabled; | 231 | AccelDraw accelerate_draw = AccelDraw::Disabled; |
| 229 | 232 | ||
| 233 | OGLFramebuffer clear_framebuffer; | ||
| 234 | |||
| 230 | using CachedPageMap = boost::icl::interval_map<u64, int>; | 235 | using CachedPageMap = boost::icl::interval_map<u64, int>; |
| 231 | CachedPageMap cached_pages; | 236 | CachedPageMap cached_pages; |
| 232 | }; | 237 | }; |