mirror of
https://github.com/yuzu-mirror/yuzu.git
synced 2024-11-19 03:17:34 +01:00
82c2601555
Reimplement the buffer cache using cached bindings and page level granularity for modification tracking. This also drops the usage of shared pointers and virtual functions from the cache. - Bindings are cached, allowing to skip work when the game changes few bits between draws. - OpenGL Assembly shaders no longer copy when a region has been modified from the GPU to emulate constant buffers, instead GL_EXT_memory_object is used to alias sub-buffers within the same allocation. - OpenGL Assembly shaders stream constant buffer data using glProgramBufferParametersIuivNV, from NV_parameter_buffer_object. In theory this should save one hash table resolve inside the driver compared to glBufferSubData. - A new OpenGL stream buffer is implemented based on fences for drivers that are not Nvidia's proprietary, due to their low performance on partial glBufferSubData calls synchronized with 3D rendering (that some games use a lot). - Most optimizations are shared between APIs now, allowing Vulkan to cache more bindings than before, skipping unnecesarry work. This commit adds the necessary infrastructure to use Vulkan object from OpenGL. Overall, it improves performance and fixes some bugs present on the old cache. There are still some edge cases hit by some games that harm performance on some vendors, this are planned to be fixed in later commits.
71 lines
2.6 KiB
C++
71 lines
2.6 KiB
C++
// Copyright 2019 yuzu Emulator Project
|
|
// Licensed under GPLv2 or any later version
|
|
// Refer to the license.txt file included.
|
|
|
|
#include <array>
|
|
#include <cstddef>
|
|
|
|
#include "common/common_types.h"
|
|
#include "video_core/dirty_flags.h"
|
|
|
|
#define OFF(field_name) MAXWELL3D_REG_INDEX(field_name)
|
|
#define NUM(field_name) (sizeof(::Tegra::Engines::Maxwell3D::Regs::field_name) / (sizeof(u32)))
|
|
|
|
namespace VideoCommon::Dirty {
|
|
namespace {
|
|
using Tegra::Engines::Maxwell3D;
|
|
|
|
void SetupDirtyVertexBuffers(Maxwell3D::DirtyState::Tables& tables) {
|
|
static constexpr std::size_t num_array = 3;
|
|
for (std::size_t i = 0; i < Maxwell3D::Regs::NumVertexArrays; ++i) {
|
|
const std::size_t array_offset = OFF(vertex_array) + i * NUM(vertex_array[0]);
|
|
const std::size_t limit_offset = OFF(vertex_array_limit) + i * NUM(vertex_array_limit[0]);
|
|
|
|
FillBlock(tables, array_offset, num_array, VertexBuffer0 + i, VertexBuffers);
|
|
FillBlock(tables, limit_offset, NUM(vertex_array_limit), VertexBuffer0 + i, VertexBuffers);
|
|
}
|
|
}
|
|
|
|
void SetupIndexBuffer(Maxwell3D::DirtyState::Tables& tables) {
|
|
FillBlock(tables[0], OFF(index_array), NUM(index_array), IndexBuffer);
|
|
}
|
|
|
|
void SetupDirtyDescriptors(Maxwell3D::DirtyState::Tables& tables) {
|
|
FillBlock(tables[0], OFF(tic), NUM(tic), Descriptors);
|
|
FillBlock(tables[0], OFF(tsc), NUM(tsc), Descriptors);
|
|
}
|
|
|
|
void SetupDirtyRenderTargets(Maxwell3D::DirtyState::Tables& tables) {
|
|
static constexpr std::size_t num_per_rt = NUM(rt[0]);
|
|
static constexpr std::size_t begin = OFF(rt);
|
|
static constexpr std::size_t num = num_per_rt * Maxwell3D::Regs::NumRenderTargets;
|
|
for (std::size_t rt = 0; rt < Maxwell3D::Regs::NumRenderTargets; ++rt) {
|
|
FillBlock(tables[0], begin + rt * num_per_rt, num_per_rt, ColorBuffer0 + rt);
|
|
}
|
|
FillBlock(tables[1], begin, num, RenderTargets);
|
|
FillBlock(tables[0], OFF(render_area), NUM(render_area), RenderTargets);
|
|
|
|
tables[0][OFF(rt_control)] = RenderTargets;
|
|
tables[1][OFF(rt_control)] = RenderTargetControl;
|
|
|
|
static constexpr std::array zeta_flags{ZetaBuffer, RenderTargets};
|
|
for (std::size_t i = 0; i < std::size(zeta_flags); ++i) {
|
|
const u8 flag = zeta_flags[i];
|
|
auto& table = tables[i];
|
|
table[OFF(zeta_enable)] = flag;
|
|
table[OFF(zeta_width)] = flag;
|
|
table[OFF(zeta_height)] = flag;
|
|
FillBlock(table, OFF(zeta), NUM(zeta), flag);
|
|
}
|
|
}
|
|
} // Anonymous namespace
|
|
|
|
void SetupDirtyFlags(Maxwell3D::DirtyState::Tables& tables) {
|
|
SetupDirtyVertexBuffers(tables);
|
|
SetupIndexBuffer(tables);
|
|
SetupDirtyDescriptors(tables);
|
|
SetupDirtyRenderTargets(tables);
|
|
}
|
|
|
|
} // namespace VideoCommon::Dirty
|