From 17b08a25fabe70e72e3662a57defe7084555b115 Mon Sep 17 00:00:00 2001 From: Sky Date: Thu, 6 Jul 2023 11:18:14 -0700 Subject: [PATCH] [GPU] Converted Depth/Color Surfaces to a ring buffer Additionally made the surface cache search hit for any address that lies in the surface. This should allow multiple races to be done in Mario Kart and fixes the intro video. --- include/renderer_gl/renderer_gl.hpp | 4 ++-- include/renderer_gl/surface_cache.hpp | 2 +- include/renderer_gl/surfaces.hpp | 10 +++++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/include/renderer_gl/renderer_gl.hpp b/include/renderer_gl/renderer_gl.hpp index 3ede19ff..8258c4c7 100644 --- a/include/renderer_gl/renderer_gl.hpp +++ b/include/renderer_gl/renderer_gl.hpp @@ -43,8 +43,8 @@ class Renderer { float oldDepthOffset = 0.0; bool oldDepthmapEnable = false; - SurfaceCache depthBufferCache; - SurfaceCache colourBufferCache; + SurfaceCache depthBufferCache; + SurfaceCache colourBufferCache; SurfaceCache textureCache; OpenGL::uvec2 fbSize; // The size of the framebuffer (ie both the colour and depth buffer)' diff --git a/include/renderer_gl/surface_cache.hpp b/include/renderer_gl/surface_cache.hpp index fb0a469d..e12befeb 100644 --- a/include/renderer_gl/surface_cache.hpp +++ b/include/renderer_gl/surface_cache.hpp @@ -46,7 +46,7 @@ public: OptionalRef findFromAddress(u32 address) { for (auto& e : buffer) { - if (e.location == address && e.valid) + if (e.location <= address && e.location+e.sizeInBytes() > address && e.valid) return e; } diff --git a/include/renderer_gl/surfaces.hpp b/include/renderer_gl/surfaces.hpp index 7ff36c6d..e5458aae 100644 --- a/include/renderer_gl/surfaces.hpp +++ b/include/renderer_gl/surfaces.hpp @@ -60,8 +60,10 @@ struct ColourBuffer { void free() { valid = false; - if (texture.exists() || fbo.exists()) - Helpers::panic("Make this buffer free itself"); + if (texture.exists() || fbo.exists()){ + texture.free(); + fbo.free(); + } } bool matches(ColourBuffer& other) { @@ -128,8 +130,10 @@ struct DepthBuffer { } void free() { + if(texture.exists()){ + texture.free(); + } valid = false; - printf("Make this depth buffer free itself\n"); } bool matches(DepthBuffer& other) {