summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Subv2018-07-03 22:32:59 -0500
committerGravatar Subv2018-07-03 22:32:59 -0500
commit5a9df3c6753e66519acaa13685abb89231e45ade (patch)
tree8f567cbd7f15670e34f2191ee0848f859c32b6ff
parentMerge pull request #609 from Subv/clear_buffers (diff)
downloadyuzu-5a9df3c6753e66519acaa13685abb89231e45ade.tar.gz
yuzu-5a9df3c6753e66519acaa13685abb89231e45ade.tar.xz
yuzu-5a9df3c6753e66519acaa13685abb89231e45ade.zip
GPU: Only configure the used framebuffers during clear.
Don't try to configure the color buffer if it is not being cleared, it may not be completely valid at this point.
Diffstat (limited to '')
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp20
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.h2
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer_cache.cpp34
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer_cache.h9
4 files changed, 48 insertions, 17 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 43dbf4da9..e516eb1ad 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -297,7 +297,8 @@ bool RasterizerOpenGL::AccelerateDrawBatch(bool is_indexed) {
297 return true; 297 return true;
298} 298}
299 299
300std::pair<Surface, Surface> RasterizerOpenGL::ConfigureFramebuffers() { 300std::pair<Surface, Surface> RasterizerOpenGL::ConfigureFramebuffers(bool using_color_fb,
301 bool using_depth_fb) {
301 const auto& regs = Core::System().GetInstance().GPU().Maxwell3D().regs; 302 const auto& regs = Core::System().GetInstance().GPU().Maxwell3D().regs;
302 303
303 // Sync the depth test state before configuring the framebuffer surfaces. 304 // Sync the depth test state before configuring the framebuffer surfaces.
@@ -306,9 +307,6 @@ std::pair<Surface, Surface> RasterizerOpenGL::ConfigureFramebuffers() {
306 // TODO(bunnei): Implement this 307 // TODO(bunnei): Implement this
307 const bool has_stencil = false; 308 const bool has_stencil = false;
308 309
309 const bool using_color_fb = true;
310 const bool using_depth_fb = regs.zeta.Address() != 0;
311
312 const MathUtil::Rectangle<s32> viewport_rect{regs.viewport_transform[0].GetRect()}; 310 const MathUtil::Rectangle<s32> viewport_rect{regs.viewport_transform[0].GetRect()};
313 311
314 const bool write_color_fb = 312 const bool write_color_fb =
@@ -358,18 +356,25 @@ std::pair<Surface, Surface> RasterizerOpenGL::ConfigureFramebuffers() {
358void RasterizerOpenGL::Clear() { 356void RasterizerOpenGL::Clear() {
359 const auto& regs = Core::System().GetInstance().GPU().Maxwell3D().regs; 357 const auto& regs = Core::System().GetInstance().GPU().Maxwell3D().regs;
360 358
359 bool use_color_fb = false;
360 bool use_depth_fb = false;
361
361 GLbitfield clear_mask = 0; 362 GLbitfield clear_mask = 0;
362 if (regs.clear_buffers.R && regs.clear_buffers.G && regs.clear_buffers.B && 363 if (regs.clear_buffers.R && regs.clear_buffers.G && regs.clear_buffers.B &&
363 regs.clear_buffers.A) { 364 regs.clear_buffers.A) {
364 clear_mask |= GL_COLOR_BUFFER_BIT; 365 clear_mask |= GL_COLOR_BUFFER_BIT;
366 use_color_fb = true;
365 } 367 }
366 if (regs.clear_buffers.Z) 368 if (regs.clear_buffers.Z) {
367 clear_mask |= GL_DEPTH_BUFFER_BIT; 369 clear_mask |= GL_DEPTH_BUFFER_BIT;
370 use_depth_fb = true;
371 }
368 372
369 if (clear_mask == 0) 373 if (clear_mask == 0)
370 return; 374 return;
371 375
372 auto [dirty_color_surface, dirty_depth_surface] = ConfigureFramebuffers(); 376 auto [dirty_color_surface, dirty_depth_surface] =
377 ConfigureFramebuffers(use_color_fb, use_depth_fb);
373 378
374 // TODO(Subv): Support clearing only partial colors. 379 // TODO(Subv): Support clearing only partial colors.
375 glClearColor(regs.clear_color[0], regs.clear_color[1], regs.clear_color[2], 380 glClearColor(regs.clear_color[0], regs.clear_color[1], regs.clear_color[2],
@@ -394,7 +399,8 @@ void RasterizerOpenGL::DrawArrays() {
394 MICROPROFILE_SCOPE(OpenGL_Drawing); 399 MICROPROFILE_SCOPE(OpenGL_Drawing);
395 const auto& regs = Core::System().GetInstance().GPU().Maxwell3D().regs; 400 const auto& regs = Core::System().GetInstance().GPU().Maxwell3D().regs;
396 401
397 auto [dirty_color_surface, dirty_depth_surface] = ConfigureFramebuffers(); 402 auto [dirty_color_surface, dirty_depth_surface] =
403 ConfigureFramebuffers(true, regs.zeta.Address() != 0);
398 404
399 SyncBlendState(); 405 SyncBlendState();
400 SyncCullMode(); 406 SyncCullMode();
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h
index 7738f40b1..c406142e4 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer.h
@@ -85,7 +85,7 @@ private:
85 85
86 /// Configures the color and depth framebuffer states and returns the dirty <Color, Depth> 86 /// Configures the color and depth framebuffer states and returns the dirty <Color, Depth>
87 /// surfaces if writing was enabled. 87 /// surfaces if writing was enabled.
88 std::pair<Surface, Surface> ConfigureFramebuffers(); 88 std::pair<Surface, Surface> ConfigureFramebuffers(bool using_color_fb, bool using_depth_fb);
89 89
90 /// Binds the framebuffer color and depth surface 90 /// Binds the framebuffer color and depth surface
91 void BindFramebufferSurfaces(const Surface& color_surface, const Surface& depth_surface, 91 void BindFramebufferSurfaces(const Surface& color_surface, const Surface& depth_surface,
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
index 3a00d9383..50469c05c 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
@@ -65,6 +65,25 @@ struct FormatTuple {
65 return params; 65 return params;
66} 66}
67 67
68/*static*/ SurfaceParams SurfaceParams::CreateForDepthBuffer(
69 const Tegra::Engines::Maxwell3D::Regs::RenderTargetConfig& config, Tegra::GPUVAddr zeta_address,
70 Tegra::DepthFormat format) {
71
72 SurfaceParams params{};
73 params.addr = zeta_address;
74 params.is_tiled = true;
75 params.block_height = Tegra::Texture::TICEntry::DefaultBlockHeight;
76 params.pixel_format = PixelFormatFromDepthFormat(format);
77 params.component_type = ComponentTypeFromDepthFormat(format);
78 params.type = GetFormatType(params.pixel_format);
79 params.size_in_bytes = params.SizeInBytes();
80 params.width = config.width;
81 params.height = config.height;
82 params.unaligned_height = config.height;
83 params.size_in_bytes = params.SizeInBytes();
84 return params;
85}
86
68static constexpr std::array<FormatTuple, SurfaceParams::MaxPixelFormat> tex_format_tuples = {{ 87static constexpr std::array<FormatTuple, SurfaceParams::MaxPixelFormat> tex_format_tuples = {{
69 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, ComponentType::UNorm, false}, // ABGR8 88 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, ComponentType::UNorm, false}, // ABGR8
70 {GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV, ComponentType::UNorm, false}, // B5G6R5 89 {GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV, ComponentType::UNorm, false}, // B5G6R5
@@ -461,15 +480,16 @@ SurfaceSurfaceRect_Tuple RasterizerCacheOpenGL::GetFramebufferSurfaces(
461 LOG_WARNING(Render_OpenGL, "hard-coded for render target 0!"); 480 LOG_WARNING(Render_OpenGL, "hard-coded for render target 0!");
462 481
463 // get color and depth surfaces 482 // get color and depth surfaces
464 const SurfaceParams color_params{SurfaceParams::CreateForFramebuffer(regs.rt[0])}; 483 SurfaceParams color_params{};
465 SurfaceParams depth_params{color_params}; 484 SurfaceParams depth_params{};
485
486 if (using_color_fb) {
487 color_params = SurfaceParams::CreateForFramebuffer(regs.rt[0]);
488 }
466 489
467 if (using_depth_fb) { 490 if (using_depth_fb) {
468 depth_params.addr = regs.zeta.Address(); 491 depth_params =
469 depth_params.pixel_format = SurfaceParams::PixelFormatFromDepthFormat(regs.zeta.format); 492 SurfaceParams::CreateForDepthBuffer(regs.rt[0], regs.zeta.Address(), regs.zeta.format);
470 depth_params.component_type = SurfaceParams::ComponentTypeFromDepthFormat(regs.zeta.format);
471 depth_params.type = SurfaceParams::GetFormatType(depth_params.pixel_format);
472 depth_params.size_in_bytes = depth_params.SizeInBytes();
473 } 493 }
474 494
475 MathUtil::Rectangle<u32> color_rect{}; 495 MathUtil::Rectangle<u32> color_rect{};
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.h b/src/video_core/renderer_opengl/gl_rasterizer_cache.h
index 7aaf371bd..8005a81b8 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer_cache.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.h
@@ -326,13 +326,18 @@ struct SurfaceParams {
326 return addr <= (region_addr + region_size) && region_addr <= (addr + size_in_bytes); 326 return addr <= (region_addr + region_size) && region_addr <= (addr + size_in_bytes);
327 } 327 }
328 328
329 /// Creates SurfaceParams from a texture configation 329 /// Creates SurfaceParams from a texture configuration
330 static SurfaceParams CreateForTexture(const Tegra::Texture::FullTextureInfo& config); 330 static SurfaceParams CreateForTexture(const Tegra::Texture::FullTextureInfo& config);
331 331
332 /// Creates SurfaceParams from a framebuffer configation 332 /// Creates SurfaceParams from a framebuffer configuration
333 static SurfaceParams CreateForFramebuffer( 333 static SurfaceParams CreateForFramebuffer(
334 const Tegra::Engines::Maxwell3D::Regs::RenderTargetConfig& config); 334 const Tegra::Engines::Maxwell3D::Regs::RenderTargetConfig& config);
335 335
336 /// Creates SurfaceParams for a depth buffer configuration
337 static SurfaceParams CreateForDepthBuffer(
338 const Tegra::Engines::Maxwell3D::Regs::RenderTargetConfig& config,
339 Tegra::GPUVAddr zeta_address, Tegra::DepthFormat format);
340
336 Tegra::GPUVAddr addr; 341 Tegra::GPUVAddr addr;
337 bool is_tiled; 342 bool is_tiled;
338 u32 block_height; 343 u32 block_height;