forked from suyu/suyu
Merge pull request #1654 from degasus/dirty_flags
gl_rasterizer: Skip VAO binding if the state is clean.
This commit is contained in:
commit
8ea6261547
4 changed files with 37 additions and 7 deletions
|
@ -108,8 +108,16 @@ void Maxwell3D::WriteReg(u32 method, u32 value, u32 remaining_params) {
|
||||||
debug_context->OnEvent(Tegra::DebugContext::Event::MaxwellCommandLoaded, nullptr);
|
debug_context->OnEvent(Tegra::DebugContext::Event::MaxwellCommandLoaded, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u32 old = regs.reg_array[method];
|
||||||
regs.reg_array[method] = value;
|
regs.reg_array[method] = value;
|
||||||
|
|
||||||
|
if (value != old) {
|
||||||
|
if (method >= MAXWELL3D_REG_INDEX(vertex_attrib_format) &&
|
||||||
|
method < MAXWELL3D_REG_INDEX(vertex_attrib_format) + regs.vertex_attrib_format.size()) {
|
||||||
|
dirty_flags.vertex_attrib_format = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case MAXWELL3D_REG_INDEX(macros.data): {
|
case MAXWELL3D_REG_INDEX(macros.data): {
|
||||||
ProcessMacroUpload(value);
|
ProcessMacroUpload(value);
|
||||||
|
|
|
@ -1004,6 +1004,12 @@ public:
|
||||||
State state{};
|
State state{};
|
||||||
MemoryManager& memory_manager;
|
MemoryManager& memory_manager;
|
||||||
|
|
||||||
|
struct DirtyFlags {
|
||||||
|
bool vertex_attrib_format = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
DirtyFlags dirty_flags;
|
||||||
|
|
||||||
/// Reads a register value located at the input method address
|
/// Reads a register value located at the input method address
|
||||||
u32 GetRegisterValue(u32 method) const;
|
u32 GetRegisterValue(u32 method) const;
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,8 @@ using Maxwell = Tegra::Engines::Maxwell3D::Regs;
|
||||||
using PixelFormat = VideoCore::Surface::PixelFormat;
|
using PixelFormat = VideoCore::Surface::PixelFormat;
|
||||||
using SurfaceType = VideoCore::Surface::SurfaceType;
|
using SurfaceType = VideoCore::Surface::SurfaceType;
|
||||||
|
|
||||||
MICROPROFILE_DEFINE(OpenGL_VAO, "OpenGL", "Vertex Array Setup", MP_RGB(128, 128, 192));
|
MICROPROFILE_DEFINE(OpenGL_VAO, "OpenGL", "Vertex Format Setup", MP_RGB(128, 128, 192));
|
||||||
|
MICROPROFILE_DEFINE(OpenGL_VB, "OpenGL", "Vertex Buffer Setup", MP_RGB(128, 128, 192));
|
||||||
MICROPROFILE_DEFINE(OpenGL_Shader, "OpenGL", "Shader Setup", MP_RGB(128, 128, 192));
|
MICROPROFILE_DEFINE(OpenGL_Shader, "OpenGL", "Shader Setup", MP_RGB(128, 128, 192));
|
||||||
MICROPROFILE_DEFINE(OpenGL_UBO, "OpenGL", "Const Buffer Setup", MP_RGB(128, 128, 192));
|
MICROPROFILE_DEFINE(OpenGL_UBO, "OpenGL", "Const Buffer Setup", MP_RGB(128, 128, 192));
|
||||||
MICROPROFILE_DEFINE(OpenGL_Index, "OpenGL", "Index Buffer Setup", MP_RGB(128, 128, 192));
|
MICROPROFILE_DEFINE(OpenGL_Index, "OpenGL", "Index Buffer Setup", MP_RGB(128, 128, 192));
|
||||||
|
@ -122,11 +123,16 @@ RasterizerOpenGL::RasterizerOpenGL(Core::Frontend::EmuWindow& window, ScreenInfo
|
||||||
|
|
||||||
RasterizerOpenGL::~RasterizerOpenGL() {}
|
RasterizerOpenGL::~RasterizerOpenGL() {}
|
||||||
|
|
||||||
void RasterizerOpenGL::SetupVertexArrays() {
|
void RasterizerOpenGL::SetupVertexFormat() {
|
||||||
MICROPROFILE_SCOPE(OpenGL_VAO);
|
auto& gpu = Core::System::GetInstance().GPU().Maxwell3D();
|
||||||
const auto& gpu = Core::System::GetInstance().GPU().Maxwell3D();
|
|
||||||
const auto& regs = gpu.regs;
|
const auto& regs = gpu.regs;
|
||||||
|
|
||||||
|
if (!gpu.dirty_flags.vertex_attrib_format)
|
||||||
|
return;
|
||||||
|
gpu.dirty_flags.vertex_attrib_format = false;
|
||||||
|
|
||||||
|
MICROPROFILE_SCOPE(OpenGL_VAO);
|
||||||
|
|
||||||
auto [iter, is_cache_miss] = vertex_array_cache.try_emplace(regs.vertex_attrib_format);
|
auto [iter, is_cache_miss] = vertex_array_cache.try_emplace(regs.vertex_attrib_format);
|
||||||
auto& VAO = iter->second;
|
auto& VAO = iter->second;
|
||||||
|
|
||||||
|
@ -175,8 +181,13 @@ void RasterizerOpenGL::SetupVertexArrays() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state.draw.vertex_array = VAO.handle;
|
state.draw.vertex_array = VAO.handle;
|
||||||
state.draw.vertex_buffer = buffer_cache.GetHandle();
|
|
||||||
state.Apply();
|
state.Apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RasterizerOpenGL::SetupVertexBuffer() {
|
||||||
|
MICROPROFILE_SCOPE(OpenGL_VB);
|
||||||
|
const auto& gpu = Core::System::GetInstance().GPU().Maxwell3D();
|
||||||
|
const auto& regs = gpu.regs;
|
||||||
|
|
||||||
// Upload all guest vertex arrays sequentially to our buffer
|
// Upload all guest vertex arrays sequentially to our buffer
|
||||||
for (u32 index = 0; index < Maxwell::NumVertexArrays; ++index) {
|
for (u32 index = 0; index < Maxwell::NumVertexArrays; ++index) {
|
||||||
|
@ -203,6 +214,9 @@ void RasterizerOpenGL::SetupVertexArrays() {
|
||||||
glVertexBindingDivisor(index, 0);
|
glVertexBindingDivisor(index, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implicit set by glBindVertexBuffer. Stupid glstate handling...
|
||||||
|
state.draw.vertex_buffer = buffer_cache.GetHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawParameters RasterizerOpenGL::SetupDraw() {
|
DrawParameters RasterizerOpenGL::SetupDraw() {
|
||||||
|
@ -620,7 +634,8 @@ void RasterizerOpenGL::DrawArrays() {
|
||||||
|
|
||||||
buffer_cache.Map(buffer_size);
|
buffer_cache.Map(buffer_size);
|
||||||
|
|
||||||
SetupVertexArrays();
|
SetupVertexFormat();
|
||||||
|
SetupVertexBuffer();
|
||||||
DrawParameters params = SetupDraw();
|
DrawParameters params = SetupDraw();
|
||||||
SetupShaders(params.primitive_mode);
|
SetupShaders(params.primitive_mode);
|
||||||
|
|
||||||
|
|
|
@ -207,7 +207,8 @@ private:
|
||||||
|
|
||||||
std::size_t CalculateIndexBufferSize() const;
|
std::size_t CalculateIndexBufferSize() const;
|
||||||
|
|
||||||
void SetupVertexArrays();
|
void SetupVertexFormat();
|
||||||
|
void SetupVertexBuffer();
|
||||||
|
|
||||||
DrawParameters SetupDraw();
|
DrawParameters SetupDraw();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue