Merge pull request #2008 from ReinUsesLisp/dirty-framebuffers

gl_rasterizer_cache: Use dirty flags for framebuffers
This commit is contained in:
bunnei 2019-01-20 14:06:26 -05:00 committed by GitHub
commit 197d0d9d24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 78 additions and 8 deletions

View File

@ -135,6 +135,25 @@ void Maxwell3D::CallMethod(const GPU::MethodCall& method_call) {
if (regs.reg_array[method_call.method] != method_call.argument) { if (regs.reg_array[method_call.method] != method_call.argument) {
regs.reg_array[method_call.method] = method_call.argument; regs.reg_array[method_call.method] = method_call.argument;
// Color buffers
constexpr u32 first_rt_reg = MAXWELL3D_REG_INDEX(rt);
constexpr u32 registers_per_rt = sizeof(regs.rt[0]) / sizeof(u32);
if (method_call.method >= first_rt_reg &&
method_call.method < first_rt_reg + registers_per_rt * Regs::NumRenderTargets) {
const std::size_t rt_index = (method_call.method - first_rt_reg) / registers_per_rt;
dirty_flags.color_buffer |= 1u << static_cast<u32>(rt_index);
}
// Zeta buffer
constexpr u32 registers_in_zeta = sizeof(regs.zeta) / sizeof(u32);
if (method_call.method == MAXWELL3D_REG_INDEX(zeta_enable) ||
method_call.method == MAXWELL3D_REG_INDEX(zeta_width) ||
method_call.method == MAXWELL3D_REG_INDEX(zeta_height) ||
(method_call.method >= MAXWELL3D_REG_INDEX(zeta) &&
method_call.method < MAXWELL3D_REG_INDEX(zeta) + registers_in_zeta)) {
dirty_flags.zeta_buffer = true;
}
// Shader // Shader
constexpr u32 shader_registers_count = constexpr u32 shader_registers_count =
sizeof(regs.shader_config[0]) * Regs::MaxShaderProgram / sizeof(u32); sizeof(regs.shader_config[0]) * Regs::MaxShaderProgram / sizeof(u32);

View File

@ -1089,12 +1089,17 @@ public:
MemoryManager& memory_manager; MemoryManager& memory_manager;
struct DirtyFlags { struct DirtyFlags {
u8 color_buffer = 0xFF;
bool zeta_buffer = true;
bool shaders = true; bool shaders = true;
bool vertex_attrib_format = true; bool vertex_attrib_format = true;
u32 vertex_array = 0xFFFFFFFF; u32 vertex_array = 0xFFFFFFFF;
void OnMemoryWrite() { void OnMemoryWrite() {
color_buffer = 0xFF;
zeta_buffer = true;
shaders = true; shaders = true;
vertex_array = 0xFFFFFFFF; vertex_array = 0xFFFFFFFF;
} }

View File

@ -490,7 +490,19 @@ void RasterizerOpenGL::ConfigureFramebuffers(OpenGLState& current_state, bool us
bool using_depth_fb, bool preserve_contents, bool using_depth_fb, bool preserve_contents,
std::optional<std::size_t> single_color_target) { std::optional<std::size_t> single_color_target) {
MICROPROFILE_SCOPE(OpenGL_Framebuffer); MICROPROFILE_SCOPE(OpenGL_Framebuffer);
const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; const auto& gpu = Core::System::GetInstance().GPU().Maxwell3D();
const auto& regs = gpu.regs;
const FramebufferConfigState fb_config_state{using_color_fb, using_depth_fb, preserve_contents,
single_color_target};
if (fb_config_state == current_framebuffer_config_state && gpu.dirty_flags.color_buffer == 0 &&
!gpu.dirty_flags.zeta_buffer) {
// Only skip if the previous ConfigureFramebuffers call was from the same kind (multiple or
// single color targets). This is done because the guest registers may not change but the
// host framebuffer may contain different attachments
return;
}
current_framebuffer_config_state = fb_config_state;
Surface depth_surface; Surface depth_surface;
if (using_depth_fb) { if (using_depth_fb) {

View File

@ -99,6 +99,23 @@ private:
float max_anisotropic = 1.0f; float max_anisotropic = 1.0f;
}; };
struct FramebufferConfigState {
bool using_color_fb{};
bool using_depth_fb{};
bool preserve_contents{};
std::optional<std::size_t> single_color_target;
bool operator==(const FramebufferConfigState& rhs) const {
return std::tie(using_color_fb, using_depth_fb, preserve_contents,
single_color_target) == std::tie(rhs.using_color_fb, rhs.using_depth_fb,
rhs.preserve_contents,
rhs.single_color_target);
}
bool operator!=(const FramebufferConfigState& rhs) const {
return !operator==(rhs);
}
};
/** /**
* Configures the color and depth framebuffer states. * Configures the color and depth framebuffer states.
* @param use_color_fb If true, configure color framebuffers. * @param use_color_fb If true, configure color framebuffers.
@ -203,6 +220,7 @@ private:
vertex_array_cache; vertex_array_cache;
std::map<FramebufferCacheKey, OGLFramebuffer> framebuffer_cache; std::map<FramebufferCacheKey, OGLFramebuffer> framebuffer_cache;
FramebufferConfigState current_framebuffer_config_state;
std::array<SamplerInfo, Tegra::Engines::Maxwell3D::Regs::NumTextureSamplers> texture_samplers; std::array<SamplerInfo, Tegra::Engines::Maxwell3D::Regs::NumTextureSamplers> texture_samplers;

View File

@ -919,9 +919,16 @@ Surface RasterizerCacheOpenGL::GetTextureSurface(const Tegra::Texture::FullTextu
} }
Surface RasterizerCacheOpenGL::GetDepthBufferSurface(bool preserve_contents) { Surface RasterizerCacheOpenGL::GetDepthBufferSurface(bool preserve_contents) {
const auto& regs{Core::System::GetInstance().GPU().Maxwell3D().regs}; auto& gpu{Core::System::GetInstance().GPU().Maxwell3D()};
const auto& regs{gpu.regs};
if (!gpu.dirty_flags.zeta_buffer) {
return last_depth_buffer;
}
gpu.dirty_flags.zeta_buffer = false;
if (!regs.zeta.Address() || !regs.zeta_enable) { if (!regs.zeta.Address() || !regs.zeta_enable) {
return {}; return last_depth_buffer = {};
} }
SurfaceParams depth_params{SurfaceParams::CreateForDepthBuffer( SurfaceParams depth_params{SurfaceParams::CreateForDepthBuffer(
@ -929,25 +936,31 @@ Surface RasterizerCacheOpenGL::GetDepthBufferSurface(bool preserve_contents) {
regs.zeta.memory_layout.block_width, regs.zeta.memory_layout.block_height, regs.zeta.memory_layout.block_width, regs.zeta.memory_layout.block_height,
regs.zeta.memory_layout.block_depth, regs.zeta.memory_layout.type)}; regs.zeta.memory_layout.block_depth, regs.zeta.memory_layout.type)};
return GetSurface(depth_params, preserve_contents); return last_depth_buffer = GetSurface(depth_params, preserve_contents);
} }
Surface RasterizerCacheOpenGL::GetColorBufferSurface(std::size_t index, bool preserve_contents) { Surface RasterizerCacheOpenGL::GetColorBufferSurface(std::size_t index, bool preserve_contents) {
const auto& regs{Core::System::GetInstance().GPU().Maxwell3D().regs}; auto& gpu{Core::System::GetInstance().GPU().Maxwell3D()};
const auto& regs{gpu.regs};
if ((gpu.dirty_flags.color_buffer & (1u << static_cast<u32>(index))) == 0) {
return last_color_buffers[index];
}
gpu.dirty_flags.color_buffer &= ~(1u << static_cast<u32>(index));
ASSERT(index < Tegra::Engines::Maxwell3D::Regs::NumRenderTargets); ASSERT(index < Tegra::Engines::Maxwell3D::Regs::NumRenderTargets);
if (index >= regs.rt_control.count) { if (index >= regs.rt_control.count) {
return {}; return last_color_buffers[index] = {};
} }
if (regs.rt[index].Address() == 0 || regs.rt[index].format == Tegra::RenderTargetFormat::NONE) { if (regs.rt[index].Address() == 0 || regs.rt[index].format == Tegra::RenderTargetFormat::NONE) {
return {}; return last_color_buffers[index] = {};
} }
const SurfaceParams color_params{SurfaceParams::CreateForFramebuffer(index)}; const SurfaceParams color_params{SurfaceParams::CreateForFramebuffer(index)};
return GetSurface(color_params, preserve_contents); return last_color_buffers[index] = GetSurface(color_params, preserve_contents);
} }
void RasterizerCacheOpenGL::LoadSurface(const Surface& surface) { void RasterizerCacheOpenGL::LoadSurface(const Surface& surface) {

View File

@ -396,6 +396,9 @@ private:
/// Use a Pixel Buffer Object to download the previous texture and then upload it to the new one /// Use a Pixel Buffer Object to download the previous texture and then upload it to the new one
/// using the new format. /// using the new format.
OGLBuffer copy_pbo; OGLBuffer copy_pbo;
std::array<Surface, Tegra::Engines::Maxwell3D::Regs::NumRenderTargets> last_color_buffers;
Surface last_depth_buffer;
}; };
} // namespace OpenGL } // namespace OpenGL