rasterizer_cache: Refactor to support in-order flushing.

This commit is contained in:
bunnei 2018-10-16 16:51:53 -04:00
parent 0e59291310
commit 91602de7f2
6 changed files with 116 additions and 63 deletions

View file

@ -15,17 +15,17 @@
namespace OpenGL {
struct CachedBufferEntry final {
VAddr GetAddr() const {
struct CachedBufferEntry final : public RasterizerCacheObject {
VAddr GetAddr() const override {
return addr;
}
std::size_t GetSizeInBytes() const {
std::size_t GetSizeInBytes() const override {
return size;
}
// We do not have to flush this cache as things in it are never modified by us.
void Flush() {}
void Flush() override {}
VAddr addr;
std::size_t size;

View file

@ -428,7 +428,7 @@ void RasterizerOpenGL::ConfigureFramebuffers(bool using_color_fb, bool using_dep
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.
color_surface->MarkAsDirty();
color_surface->MarkAsModified(true, res_cache);
}
glFramebufferTexture2D(
@ -445,7 +445,7 @@ void RasterizerOpenGL::ConfigureFramebuffers(bool using_color_fb, bool using_dep
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.
color_surface->MarkAsDirty();
color_surface->MarkAsModified(true, res_cache);
}
buffers[index] = GL_COLOR_ATTACHMENT0 + regs.rt_control.GetMap(index);
@ -469,7 +469,7 @@ void RasterizerOpenGL::ConfigureFramebuffers(bool using_color_fb, bool using_dep
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.
depth_surface->MarkAsDirty();
depth_surface->MarkAsModified(true, res_cache);
if (regs.stencil_enable) {
// Attach both depth and stencil
@ -642,9 +642,6 @@ void RasterizerOpenGL::FlushRegion(VAddr addr, u64 size) {
// Only flush if use_accurate_framebuffers is enabled, as it incurs a performance hit
res_cache.FlushRegion(addr, size);
}
shader_cache.FlushRegion(addr, size);
buffer_cache.FlushRegion(addr, size);
}
void RasterizerOpenGL::InvalidateRegion(VAddr addr, u64 size) {

View file

@ -905,8 +905,6 @@ void CachedSurface::LoadGLBuffer() {
}
ConvertFormatAsNeeded_LoadGLBuffer(gl_buffer, params.pixel_format, params.width, params.height);
dirty = false;
}
MICROPROFILE_DEFINE(OpenGL_SurfaceFlush, "OpenGL", "Surface Flush", MP_RGB(128, 192, 64));
@ -1111,6 +1109,7 @@ Surface RasterizerCacheOpenGL::GetColorBufferSurface(std::size_t index, bool pre
void RasterizerCacheOpenGL::LoadSurface(const Surface& surface) {
surface->LoadGLBuffer();
surface->UploadGLTexture(read_framebuffer.handle, draw_framebuffer.handle);
surface->MarkAsModified(false, *this);
}
Surface RasterizerCacheOpenGL::GetSurface(const SurfaceParams& params, bool preserve_contents) {

View file

@ -819,28 +819,20 @@ struct hash<SurfaceReserveKey> {
namespace OpenGL {
class CachedSurface final {
class CachedSurface final : public RasterizerCacheObject {
public:
CachedSurface(const SurfaceParams& params);
VAddr GetAddr() const {
VAddr GetAddr() const override {
return params.addr;
}
std::size_t GetSizeInBytes() const {
std::size_t GetSizeInBytes() const override {
return cached_size_in_bytes;
}
void Flush() {
// There is no need to flush the surface if it hasn't been modified by us.
if (!dirty)
return;
void Flush() override {
FlushGLBuffer();
dirty = false;
}
void MarkAsDirty() {
dirty = true;
}
const OGLTexture& Texture() const {
@ -868,7 +860,6 @@ private:
SurfaceParams params;
GLenum gl_target;
std::size_t cached_size_in_bytes;
bool dirty = false;
};
class RasterizerCacheOpenGL final : public RasterizerCache<Surface> {

View file

@ -19,22 +19,20 @@ class CachedShader;
using Shader = std::shared_ptr<CachedShader>;
using Maxwell = Tegra::Engines::Maxwell3D::Regs;
class CachedShader final {
class CachedShader final : public RasterizerCacheObject {
public:
CachedShader(VAddr addr, Maxwell::ShaderProgram program_type);
/// Gets the address of the shader in guest memory, required for cache management
VAddr GetAddr() const {
VAddr GetAddr() const override {
return addr;
}
/// Gets the size of the shader in guest memory, required for cache management
std::size_t GetSizeInBytes() const {
std::size_t GetSizeInBytes() const override {
return GLShader::MAX_PROGRAM_CODE_LENGTH * sizeof(u64);
}
// We do not have to flush this cache as things in it are never modified by us.
void Flush() {}
void Flush() override {}
/// Gets the shader entries for the shader
const GLShader::ShaderEntries& GetShaderEntries() const {