diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 72 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.h | 4 |
2 files changed, 34 insertions, 42 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 291ef737d..6441e2586 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -36,7 +36,7 @@ static bool IsPassThroughTevStage(const Pica::Regs::TevStageConfig& stage) { | |||
| 36 | stage.GetAlphaMultiplier() == 1); | 36 | stage.GetAlphaMultiplier() == 1); |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | RasterizerOpenGL::RasterizerOpenGL() : last_fb_color_addr(0), last_fb_depth_addr(0) { } | 39 | RasterizerOpenGL::RasterizerOpenGL() : cached_fb_color_addr(0), cached_fb_depth_addr(0) { } |
| 40 | RasterizerOpenGL::~RasterizerOpenGL() { } | 40 | RasterizerOpenGL::~RasterizerOpenGL() { } |
| 41 | 41 | ||
| 42 | void RasterizerOpenGL::InitObjects() { | 42 | void RasterizerOpenGL::InitObjects() { |
| @@ -169,16 +169,14 @@ void RasterizerOpenGL::DrawTriangles() { | |||
| 169 | // Flush the resource cache at the current depth and color framebuffer addresses for render-to-texture | 169 | // Flush the resource cache at the current depth and color framebuffer addresses for render-to-texture |
| 170 | const auto& regs = Pica::g_state.regs; | 170 | const auto& regs = Pica::g_state.regs; |
| 171 | 171 | ||
| 172 | PAddr cur_fb_color_addr = regs.framebuffer.GetColorBufferPhysicalAddress(); | 172 | u32 cached_fb_color_size = Pica::Regs::BytesPerColorPixel(fb_color_texture.format) |
| 173 | u32 cur_fb_color_size = Pica::Regs::BytesPerColorPixel(regs.framebuffer.color_format) | 173 | * fb_color_texture.width * fb_color_texture.height; |
| 174 | * regs.framebuffer.GetWidth() * regs.framebuffer.GetHeight(); | ||
| 175 | 174 | ||
| 176 | PAddr cur_fb_depth_addr = regs.framebuffer.GetDepthBufferPhysicalAddress(); | 175 | u32 cached_fb_depth_size = Pica::Regs::BytesPerDepthPixel(fb_depth_texture.format) |
| 177 | u32 cur_fb_depth_size = Pica::Regs::BytesPerDepthPixel(regs.framebuffer.depth_format) | 176 | * fb_depth_texture.width * fb_depth_texture.height; |
| 178 | * regs.framebuffer.GetWidth() * regs.framebuffer.GetHeight(); | ||
| 179 | 177 | ||
| 180 | res_cache.InvalidateInRange(cur_fb_color_addr, cur_fb_color_size, true); | 178 | res_cache.InvalidateInRange(cached_fb_color_addr, cached_fb_color_size, true); |
| 181 | res_cache.InvalidateInRange(cur_fb_depth_addr, cur_fb_depth_size, true); | 179 | res_cache.InvalidateInRange(cached_fb_depth_addr, cached_fb_depth_size, true); |
| 182 | } | 180 | } |
| 183 | 181 | ||
| 184 | void RasterizerOpenGL::FlushFramebuffer() { | 182 | void RasterizerOpenGL::FlushFramebuffer() { |
| @@ -291,38 +289,34 @@ void RasterizerOpenGL::NotifyPicaRegisterChanged(u32 id) { | |||
| 291 | void RasterizerOpenGL::FlushRegion(PAddr addr, u32 size) { | 289 | void RasterizerOpenGL::FlushRegion(PAddr addr, u32 size) { |
| 292 | const auto& regs = Pica::g_state.regs; | 290 | const auto& regs = Pica::g_state.regs; |
| 293 | 291 | ||
| 294 | PAddr cur_fb_color_addr = regs.framebuffer.GetColorBufferPhysicalAddress(); | 292 | u32 cached_fb_color_size = Pica::Regs::BytesPerColorPixel(fb_color_texture.format) |
| 295 | u32 cur_fb_color_size = Pica::Regs::BytesPerColorPixel(regs.framebuffer.color_format) | 293 | * fb_color_texture.width * fb_color_texture.height; |
| 296 | * regs.framebuffer.GetWidth() * regs.framebuffer.GetHeight(); | ||
| 297 | 294 | ||
| 298 | PAddr cur_fb_depth_addr = regs.framebuffer.GetDepthBufferPhysicalAddress(); | 295 | u32 cached_fb_depth_size = Pica::Regs::BytesPerDepthPixel(fb_depth_texture.format) |
| 299 | u32 cur_fb_depth_size = Pica::Regs::BytesPerDepthPixel(regs.framebuffer.depth_format) | 296 | * fb_depth_texture.width * fb_depth_texture.height; |
| 300 | * regs.framebuffer.GetWidth() * regs.framebuffer.GetHeight(); | ||
| 301 | 297 | ||
| 302 | // If source memory region overlaps 3DS framebuffers, commit them before the copy happens | 298 | // If source memory region overlaps 3DS framebuffers, commit them before the copy happens |
| 303 | if (MathUtil::IntervalsIntersect(addr, size, cur_fb_color_addr, cur_fb_color_size)) | 299 | if (MathUtil::IntervalsIntersect(addr, size, cached_fb_color_addr, cached_fb_color_size)) |
| 304 | CommitColorBuffer(); | 300 | CommitColorBuffer(); |
| 305 | 301 | ||
| 306 | if (MathUtil::IntervalsIntersect(addr, size, cur_fb_depth_addr, cur_fb_depth_size)) | 302 | if (MathUtil::IntervalsIntersect(addr, size, cached_fb_depth_addr, cached_fb_depth_size)) |
| 307 | CommitDepthBuffer(); | 303 | CommitDepthBuffer(); |
| 308 | } | 304 | } |
| 309 | 305 | ||
| 310 | void RasterizerOpenGL::InvalidateRegion(PAddr addr, u32 size) { | 306 | void RasterizerOpenGL::InvalidateRegion(PAddr addr, u32 size) { |
| 311 | const auto& regs = Pica::g_state.regs; | 307 | const auto& regs = Pica::g_state.regs; |
| 312 | 308 | ||
| 313 | PAddr cur_fb_color_addr = regs.framebuffer.GetColorBufferPhysicalAddress(); | 309 | u32 cached_fb_color_size = Pica::Regs::BytesPerColorPixel(fb_color_texture.format) |
| 314 | u32 cur_fb_color_size = Pica::Regs::BytesPerColorPixel(regs.framebuffer.color_format) | 310 | * fb_color_texture.width * fb_color_texture.height; |
| 315 | * regs.framebuffer.GetWidth() * regs.framebuffer.GetHeight(); | ||
| 316 | 311 | ||
| 317 | PAddr cur_fb_depth_addr = regs.framebuffer.GetDepthBufferPhysicalAddress(); | 312 | u32 cached_fb_depth_size = Pica::Regs::BytesPerDepthPixel(fb_depth_texture.format) |
| 318 | u32 cur_fb_depth_size = Pica::Regs::BytesPerDepthPixel(regs.framebuffer.depth_format) | 313 | * fb_depth_texture.width * fb_depth_texture.height; |
| 319 | * regs.framebuffer.GetWidth() * regs.framebuffer.GetHeight(); | ||
| 320 | 314 | ||
| 321 | // If modified memory region overlaps 3DS framebuffers, reload their contents into OpenGL | 315 | // If modified memory region overlaps 3DS framebuffers, reload their contents into OpenGL |
| 322 | if (MathUtil::IntervalsIntersect(addr, size, cur_fb_color_addr, cur_fb_color_size)) | 316 | if (MathUtil::IntervalsIntersect(addr, size, cached_fb_color_addr, cached_fb_color_size)) |
| 323 | ReloadColorBuffer(); | 317 | ReloadColorBuffer(); |
| 324 | 318 | ||
| 325 | if (MathUtil::IntervalsIntersect(addr, size, cur_fb_depth_addr, cur_fb_depth_size)) | 319 | if (MathUtil::IntervalsIntersect(addr, size, cached_fb_depth_addr, cached_fb_depth_size)) |
| 326 | ReloadDepthBuffer(); | 320 | ReloadDepthBuffer(); |
| 327 | 321 | ||
| 328 | // Notify cache of flush in case the region touches a cached resource | 322 | // Notify cache of flush in case the region touches a cached resource |
| @@ -514,10 +508,10 @@ void RasterizerOpenGL::SetShader() { | |||
| 514 | void RasterizerOpenGL::SyncFramebuffer() { | 508 | void RasterizerOpenGL::SyncFramebuffer() { |
| 515 | const auto& regs = Pica::g_state.regs; | 509 | const auto& regs = Pica::g_state.regs; |
| 516 | 510 | ||
| 517 | PAddr cur_fb_color_addr = regs.framebuffer.GetColorBufferPhysicalAddress(); | 511 | PAddr new_fb_color_addr = regs.framebuffer.GetColorBufferPhysicalAddress(); |
| 518 | Pica::Regs::ColorFormat new_fb_color_format = regs.framebuffer.color_format; | 512 | Pica::Regs::ColorFormat new_fb_color_format = regs.framebuffer.color_format; |
| 519 | 513 | ||
| 520 | PAddr cur_fb_depth_addr = regs.framebuffer.GetDepthBufferPhysicalAddress(); | 514 | PAddr new_fb_depth_addr = regs.framebuffer.GetDepthBufferPhysicalAddress(); |
| 521 | Pica::Regs::DepthFormat new_fb_depth_format = regs.framebuffer.depth_format; | 515 | Pica::Regs::DepthFormat new_fb_depth_format = regs.framebuffer.depth_format; |
| 522 | 516 | ||
| 523 | bool fb_size_changed = fb_color_texture.width != static_cast<GLsizei>(regs.framebuffer.GetWidth()) || | 517 | bool fb_size_changed = fb_color_texture.width != static_cast<GLsizei>(regs.framebuffer.GetWidth()) || |
| @@ -529,10 +523,10 @@ void RasterizerOpenGL::SyncFramebuffer() { | |||
| 529 | bool depth_fb_prop_changed = fb_depth_texture.format != new_fb_depth_format || | 523 | bool depth_fb_prop_changed = fb_depth_texture.format != new_fb_depth_format || |
| 530 | fb_size_changed; | 524 | fb_size_changed; |
| 531 | 525 | ||
| 532 | bool color_fb_modified = last_fb_color_addr != cur_fb_color_addr || | 526 | bool color_fb_modified = cached_fb_color_addr != new_fb_color_addr || |
| 533 | color_fb_prop_changed; | 527 | color_fb_prop_changed; |
| 534 | 528 | ||
| 535 | bool depth_fb_modified = last_fb_depth_addr != cur_fb_depth_addr || | 529 | bool depth_fb_modified = cached_fb_depth_addr != new_fb_depth_addr || |
| 536 | depth_fb_prop_changed; | 530 | depth_fb_prop_changed; |
| 537 | 531 | ||
| 538 | // Commit if framebuffer modified in any way | 532 | // Commit if framebuffer modified in any way |
| @@ -572,13 +566,13 @@ void RasterizerOpenGL::SyncFramebuffer() { | |||
| 572 | 566 | ||
| 573 | // Load buffer data again if fb modified in any way | 567 | // Load buffer data again if fb modified in any way |
| 574 | if (color_fb_modified) { | 568 | if (color_fb_modified) { |
| 575 | last_fb_color_addr = cur_fb_color_addr; | 569 | cached_fb_color_addr = new_fb_color_addr; |
| 576 | 570 | ||
| 577 | ReloadColorBuffer(); | 571 | ReloadColorBuffer(); |
| 578 | } | 572 | } |
| 579 | 573 | ||
| 580 | if (depth_fb_modified) { | 574 | if (depth_fb_modified) { |
| 581 | last_fb_depth_addr = cur_fb_depth_addr; | 575 | cached_fb_depth_addr = new_fb_depth_addr; |
| 582 | 576 | ||
| 583 | ReloadDepthBuffer(); | 577 | ReloadDepthBuffer(); |
| 584 | } | 578 | } |
| @@ -723,7 +717,7 @@ void RasterizerOpenGL::SyncDrawState() { | |||
| 723 | MICROPROFILE_DEFINE(OpenGL_FramebufferReload, "OpenGL", "FB Reload", MP_RGB(70, 70, 200)); | 717 | MICROPROFILE_DEFINE(OpenGL_FramebufferReload, "OpenGL", "FB Reload", MP_RGB(70, 70, 200)); |
| 724 | 718 | ||
| 725 | void RasterizerOpenGL::ReloadColorBuffer() { | 719 | void RasterizerOpenGL::ReloadColorBuffer() { |
| 726 | u8* color_buffer = Memory::GetPhysicalPointer(Pica::g_state.regs.framebuffer.GetColorBufferPhysicalAddress()); | 720 | u8* color_buffer = Memory::GetPhysicalPointer(cached_fb_color_addr); |
| 727 | 721 | ||
| 728 | if (color_buffer == nullptr) | 722 | if (color_buffer == nullptr) |
| 729 | return; | 723 | return; |
| @@ -758,13 +752,11 @@ void RasterizerOpenGL::ReloadColorBuffer() { | |||
| 758 | } | 752 | } |
| 759 | 753 | ||
| 760 | void RasterizerOpenGL::ReloadDepthBuffer() { | 754 | void RasterizerOpenGL::ReloadDepthBuffer() { |
| 761 | PAddr depth_buffer_addr = Pica::g_state.regs.framebuffer.GetDepthBufferPhysicalAddress(); | 755 | if (cached_fb_depth_addr == 0) |
| 762 | |||
| 763 | if (depth_buffer_addr == 0) | ||
| 764 | return; | 756 | return; |
| 765 | 757 | ||
| 766 | // TODO: Appears to work, but double-check endianness of depth values and order of depth-stencil | 758 | // TODO: Appears to work, but double-check endianness of depth values and order of depth-stencil |
| 767 | u8* depth_buffer = Memory::GetPhysicalPointer(depth_buffer_addr); | 759 | u8* depth_buffer = Memory::GetPhysicalPointer(cached_fb_depth_addr); |
| 768 | 760 | ||
| 769 | if (depth_buffer == nullptr) | 761 | if (depth_buffer == nullptr) |
| 770 | return; | 762 | return; |
| @@ -827,8 +819,8 @@ Common::Profiling::TimingCategory buffer_commit_category("Framebuffer Commit"); | |||
| 827 | MICROPROFILE_DEFINE(OpenGL_FramebufferCommit, "OpenGL", "FB Commit", MP_RGB(70, 70, 200)); | 819 | MICROPROFILE_DEFINE(OpenGL_FramebufferCommit, "OpenGL", "FB Commit", MP_RGB(70, 70, 200)); |
| 828 | 820 | ||
| 829 | void RasterizerOpenGL::CommitColorBuffer() { | 821 | void RasterizerOpenGL::CommitColorBuffer() { |
| 830 | if (last_fb_color_addr != 0) { | 822 | if (cached_fb_color_addr != 0) { |
| 831 | u8* color_buffer = Memory::GetPhysicalPointer(last_fb_color_addr); | 823 | u8* color_buffer = Memory::GetPhysicalPointer(cached_fb_color_addr); |
| 832 | 824 | ||
| 833 | if (color_buffer != nullptr) { | 825 | if (color_buffer != nullptr) { |
| 834 | Common::Profiling::ScopeTimer timer(buffer_commit_category); | 826 | Common::Profiling::ScopeTimer timer(buffer_commit_category); |
| @@ -863,9 +855,9 @@ void RasterizerOpenGL::CommitColorBuffer() { | |||
| 863 | } | 855 | } |
| 864 | 856 | ||
| 865 | void RasterizerOpenGL::CommitDepthBuffer() { | 857 | void RasterizerOpenGL::CommitDepthBuffer() { |
| 866 | if (last_fb_depth_addr != 0) { | 858 | if (cached_fb_depth_addr != 0) { |
| 867 | // TODO: Output seems correct visually, but doesn't quite match sw renderer output. One of them is wrong. | 859 | // TODO: Output seems correct visually, but doesn't quite match sw renderer output. One of them is wrong. |
| 868 | u8* depth_buffer = Memory::GetPhysicalPointer(last_fb_depth_addr); | 860 | u8* depth_buffer = Memory::GetPhysicalPointer(cached_fb_depth_addr); |
| 869 | 861 | ||
| 870 | if (depth_buffer != nullptr) { | 862 | if (depth_buffer != nullptr) { |
| 871 | Common::Profiling::ScopeTimer timer(buffer_commit_category); | 863 | Common::Profiling::ScopeTimer timer(buffer_commit_category); |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index c8a2d8f16..569beaa5c 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h | |||
| @@ -278,8 +278,8 @@ private: | |||
| 278 | 278 | ||
| 279 | OpenGLState state; | 279 | OpenGLState state; |
| 280 | 280 | ||
| 281 | PAddr last_fb_color_addr; | 281 | PAddr cached_fb_color_addr; |
| 282 | PAddr last_fb_depth_addr; | 282 | PAddr cached_fb_depth_addr; |
| 283 | 283 | ||
| 284 | // Hardware rasterizer | 284 | // Hardware rasterizer |
| 285 | std::array<SamplerInfo, 3> texture_samplers; | 285 | std::array<SamplerInfo, 3> texture_samplers; |