From ba02d564f8a0b0167b96f247b6ad9d2bde05b6c8 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Sun, 15 Sep 2019 11:48:54 -0400 Subject: Video Core: initial Implementation of InstanceDraw Packaging --- src/video_core/engines/maxwell_3d.cpp | 74 +++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'src/video_core/engines/maxwell_3d.cpp') diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp index c7a3c85a0..48fc1a9e1 100644 --- a/src/video_core/engines/maxwell_3d.cpp +++ b/src/video_core/engines/maxwell_3d.cpp @@ -92,6 +92,10 @@ void Maxwell3D::InitializeRegisterDefaults() { // Some games (like Super Mario Odyssey) assume that SRGB is enabled. regs.framebuffer_srgb = 1; + mme_inline[MAXWELL3D_REG_INDEX(draw.vertex_end_gl)] = true; + mme_inline[MAXWELL3D_REG_INDEX(draw.vertex_begin_gl)] = true; + mme_inline[MAXWELL3D_REG_INDEX(vertex_buffer.count)] = true; + mme_inline[MAXWELL3D_REG_INDEX(index_array.count)] = true; } #define DIRTY_REGS_POS(field_name) (offsetof(Maxwell3D::DirtyRegs, field_name)) @@ -416,6 +420,76 @@ void Maxwell3D::CallMethod(const GPU::MethodCall& method_call) { } } +void Maxwell3D::CallMethodFromMME(const GPU::MethodCall& method_call) { + const u32 method = method_call.method; + if (mme_inline[method]) { + regs.reg_array[method] = method_call.argument; + if (method == MAXWELL3D_REG_INDEX(vertex_buffer.count) || + method == MAXWELL3D_REG_INDEX(index_array.count)) { + MMMEDrawMode expected_mode = method == MAXWELL3D_REG_INDEX(vertex_buffer.count) + ? MMMEDrawMode::Array + : MMMEDrawMode::Indexed; + u32 count = method_call.argument; + while (true) { + if (mme_draw.current_mode == MMMEDrawMode::Undefined) { + mme_draw.current_mode = expected_mode; + mme_draw.current_count = count; + mme_draw.instance_count = 1; + break; + } else { + if (mme_draw.current_mode == expected_mode && count == mme_draw.current_count) { + mme_draw.instance_count++; + break; + } else { + FlushMMEInlineDraw(); + } + } + } + } + } else { + if (mme_draw.current_mode != MMMEDrawMode::Undefined) { + FlushMMEInlineDraw(); + } + CallMethod(method_call); + } +} + +void Maxwell3D::FlushMMEInlineDraw() { + LOG_DEBUG(HW_GPU, "called, topology={}, count={}", static_cast(regs.draw.topology.Value()), + regs.vertex_buffer.count); + ASSERT_MSG(!(regs.index_array.count && regs.vertex_buffer.count), "Both indexed and direct?"); + + auto debug_context = system.GetGPUDebugContext(); + + if (debug_context) { + debug_context->OnEvent(Tegra::DebugContext::Event::IncomingPrimitiveBatch, nullptr); + } + + // Both instance configuration registers can not be set at the same time. + ASSERT_MSG(!regs.draw.instance_next || !regs.draw.instance_cont, + "Illegal combination of instancing parameters"); + + const bool is_indexed = mme_draw.current_mode == MMMEDrawMode::Indexed; + rasterizer.AccelerateDrawMultiBatch(is_indexed); + + if (debug_context) { + debug_context->OnEvent(Tegra::DebugContext::Event::FinishedPrimitiveBatch, nullptr); + } + + // TODO(bunnei): Below, we reset vertex count so that we can use these registers to determine if + // the game is trying to draw indexed or direct mode. This needs to be verified on HW still - + // it's possible that it is incorrect and that there is some other register used to specify the + // drawing mode. + if (is_indexed) { + regs.index_array.count = 0; + } else { + regs.vertex_buffer.count = 0; + } + mme_draw.current_mode = MMMEDrawMode::Undefined; + mme_draw.current_count = 0; + mme_draw.instance_count = 0; +} + void Maxwell3D::ProcessMacroUpload(u32 data) { ASSERT_MSG(regs.macros.upload_address < macro_memory.size(), "upload_address exceeded macro_memory size!"); -- cgit v1.2.3 From 7606da5611b5626790e99b4387e033eaea20c2cb Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Sun, 15 Sep 2019 14:25:07 -0400 Subject: VideoCore: Corrections to the MME Inliner and removal of hacky instance management. --- src/video_core/engines/maxwell_3d.cpp | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'src/video_core/engines/maxwell_3d.cpp') diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp index 48fc1a9e1..d1f63a5eb 100644 --- a/src/video_core/engines/maxwell_3d.cpp +++ b/src/video_core/engines/maxwell_3d.cpp @@ -260,6 +260,9 @@ void Maxwell3D::CallMacroMethod(u32 method, std::size_t num_parameters, const u3 // Execute the current macro. macro_interpreter.Execute(macro_positions[entry], num_parameters, parameters); + if (mme_draw.current_mode != MMMEDrawMode::Undefined) { + FlushMMEInlineDraw(); + } } void Maxwell3D::CallMethod(const GPU::MethodCall& method_call) { @@ -426,25 +429,37 @@ void Maxwell3D::CallMethodFromMME(const GPU::MethodCall& method_call) { regs.reg_array[method] = method_call.argument; if (method == MAXWELL3D_REG_INDEX(vertex_buffer.count) || method == MAXWELL3D_REG_INDEX(index_array.count)) { - MMMEDrawMode expected_mode = method == MAXWELL3D_REG_INDEX(vertex_buffer.count) - ? MMMEDrawMode::Array - : MMMEDrawMode::Indexed; - u32 count = method_call.argument; + const MMMEDrawMode expected_mode = method == MAXWELL3D_REG_INDEX(vertex_buffer.count) + ? MMMEDrawMode::Array + : MMMEDrawMode::Indexed; + const u32 count = method_call.argument; while (true) { if (mme_draw.current_mode == MMMEDrawMode::Undefined) { - mme_draw.current_mode = expected_mode; - mme_draw.current_count = count; - mme_draw.instance_count = 1; + if (mme_draw.gl_begin_consume) { + mme_draw.current_mode = expected_mode; + mme_draw.current_count = count; + mme_draw.instance_count = 1; + mme_draw.gl_begin_consume = false; + mme_draw.gl_end_count = 0; + } break; } else { - if (mme_draw.current_mode == expected_mode && count == mme_draw.current_count) { + if (mme_draw.current_mode == expected_mode && count == mme_draw.current_count && + mme_draw.instance_mode && mme_draw.gl_begin_consume) { mme_draw.instance_count++; + mme_draw.gl_begin_consume = false; break; } else { FlushMMEInlineDraw(); } } } + } else if (method == MAXWELL3D_REG_INDEX(draw.vertex_begin_gl)) { + mme_draw.instance_mode = + (regs.draw.instance_next != 0) || (regs.draw.instance_cont != 0); + mme_draw.gl_begin_consume = true; + } else { + mme_draw.gl_end_count++; } } else { if (mme_draw.current_mode != MMMEDrawMode::Undefined) { @@ -458,6 +473,7 @@ void Maxwell3D::FlushMMEInlineDraw() { LOG_DEBUG(HW_GPU, "called, topology={}, count={}", static_cast(regs.draw.topology.Value()), regs.vertex_buffer.count); ASSERT_MSG(!(regs.index_array.count && regs.vertex_buffer.count), "Both indexed and direct?"); + ASSERT(mme_draw.instance_count == mme_draw.gl_end_count); auto debug_context = system.GetGPUDebugContext(); @@ -488,6 +504,9 @@ void Maxwell3D::FlushMMEInlineDraw() { mme_draw.current_mode = MMMEDrawMode::Undefined; mme_draw.current_count = 0; mme_draw.instance_count = 0; + mme_draw.instance_mode = false; + mme_draw.gl_begin_consume = false; + mme_draw.gl_end_count = 0; } void Maxwell3D::ProcessMacroUpload(u32 data) { -- cgit v1.2.3 From 7761e44d186deff278e51814bdec0c25e8e1a09c Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Thu, 19 Sep 2019 11:41:07 -0400 Subject: Rasterizer: Refactor and simplify DrawBatch Interface. --- src/video_core/engines/maxwell_3d.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/video_core/engines/maxwell_3d.cpp') diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp index d1f63a5eb..b8f071bc0 100644 --- a/src/video_core/engines/maxwell_3d.cpp +++ b/src/video_core/engines/maxwell_3d.cpp @@ -486,7 +486,7 @@ void Maxwell3D::FlushMMEInlineDraw() { "Illegal combination of instancing parameters"); const bool is_indexed = mme_draw.current_mode == MMMEDrawMode::Indexed; - rasterizer.AccelerateDrawMultiBatch(is_indexed); + rasterizer.DrawMultiBatch(is_indexed); if (debug_context) { debug_context->OnEvent(Tegra::DebugContext::Event::FinishedPrimitiveBatch, nullptr); @@ -657,7 +657,7 @@ void Maxwell3D::DrawArrays() { } const bool is_indexed{regs.index_array.count && !regs.vertex_buffer.count}; - rasterizer.AccelerateDrawBatch(is_indexed); + rasterizer.DrawBatch(is_indexed); if (debug_context) { debug_context->OnEvent(Tegra::DebugContext::Event::FinishedPrimitiveBatch, nullptr); -- cgit v1.2.3 From 68f5aff64f231e77fed726b91619061e308b7b2d Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Sun, 22 Sep 2019 07:23:13 -0400 Subject: Maxwell3D: Corrections and refactors to MME instance refactor --- src/video_core/engines/maxwell_3d.cpp | 69 +++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 31 deletions(-) (limited to 'src/video_core/engines/maxwell_3d.cpp') diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp index b8f071bc0..e9c15beff 100644 --- a/src/video_core/engines/maxwell_3d.cpp +++ b/src/video_core/engines/maxwell_3d.cpp @@ -260,7 +260,7 @@ void Maxwell3D::CallMacroMethod(u32 method, std::size_t num_parameters, const u3 // Execute the current macro. macro_interpreter.Execute(macro_positions[entry], num_parameters, parameters); - if (mme_draw.current_mode != MMMEDrawMode::Undefined) { + if (mme_draw.current_mode != MMEDrawMode::Undefined) { FlushMMEInlineDraw(); } } @@ -423,37 +423,40 @@ void Maxwell3D::CallMethod(const GPU::MethodCall& method_call) { } } +void Maxwell3D::StepInstance(const MMEDrawMode expected_mode, const u32 count) { + if (mme_draw.current_mode == MMEDrawMode::Undefined) { + if (mme_draw.gl_begin_consume) { + mme_draw.current_mode = expected_mode; + mme_draw.current_count = count; + mme_draw.instance_count = 1; + mme_draw.gl_begin_consume = false; + mme_draw.gl_end_count = 0; + } + return; + } else { + if (mme_draw.current_mode == expected_mode && count == mme_draw.current_count && + mme_draw.instance_mode && mme_draw.gl_begin_consume) { + mme_draw.instance_count++; + mme_draw.gl_begin_consume = false; + return; + } else { + FlushMMEInlineDraw(); + } + } + // Tail call in case it needs to retry. + StepInstance(expected_mode, count); +} + void Maxwell3D::CallMethodFromMME(const GPU::MethodCall& method_call) { const u32 method = method_call.method; if (mme_inline[method]) { regs.reg_array[method] = method_call.argument; if (method == MAXWELL3D_REG_INDEX(vertex_buffer.count) || method == MAXWELL3D_REG_INDEX(index_array.count)) { - const MMMEDrawMode expected_mode = method == MAXWELL3D_REG_INDEX(vertex_buffer.count) - ? MMMEDrawMode::Array - : MMMEDrawMode::Indexed; - const u32 count = method_call.argument; - while (true) { - if (mme_draw.current_mode == MMMEDrawMode::Undefined) { - if (mme_draw.gl_begin_consume) { - mme_draw.current_mode = expected_mode; - mme_draw.current_count = count; - mme_draw.instance_count = 1; - mme_draw.gl_begin_consume = false; - mme_draw.gl_end_count = 0; - } - break; - } else { - if (mme_draw.current_mode == expected_mode && count == mme_draw.current_count && - mme_draw.instance_mode && mme_draw.gl_begin_consume) { - mme_draw.instance_count++; - mme_draw.gl_begin_consume = false; - break; - } else { - FlushMMEInlineDraw(); - } - } - } + const MMEDrawMode expected_mode = method == MAXWELL3D_REG_INDEX(vertex_buffer.count) + ? MMEDrawMode::Array + : MMEDrawMode::Indexed; + StepInstance(expected_mode, method_call.argument); } else if (method == MAXWELL3D_REG_INDEX(draw.vertex_begin_gl)) { mme_draw.instance_mode = (regs.draw.instance_next != 0) || (regs.draw.instance_cont != 0); @@ -462,7 +465,7 @@ void Maxwell3D::CallMethodFromMME(const GPU::MethodCall& method_call) { mme_draw.gl_end_count++; } } else { - if (mme_draw.current_mode != MMMEDrawMode::Undefined) { + if (mme_draw.current_mode != MMEDrawMode::Undefined) { FlushMMEInlineDraw(); } CallMethod(method_call); @@ -485,8 +488,10 @@ void Maxwell3D::FlushMMEInlineDraw() { ASSERT_MSG(!regs.draw.instance_next || !regs.draw.instance_cont, "Illegal combination of instancing parameters"); - const bool is_indexed = mme_draw.current_mode == MMMEDrawMode::Indexed; - rasterizer.DrawMultiBatch(is_indexed); + const bool is_indexed = mme_draw.current_mode == MMEDrawMode::Indexed; + if (ShouldExecute()) { + rasterizer.DrawMultiBatch(is_indexed); + } if (debug_context) { debug_context->OnEvent(Tegra::DebugContext::Event::FinishedPrimitiveBatch, nullptr); @@ -501,7 +506,7 @@ void Maxwell3D::FlushMMEInlineDraw() { } else { regs.vertex_buffer.count = 0; } - mme_draw.current_mode = MMMEDrawMode::Undefined; + mme_draw.current_mode = MMEDrawMode::Undefined; mme_draw.current_count = 0; mme_draw.instance_count = 0; mme_draw.instance_mode = false; @@ -657,7 +662,9 @@ void Maxwell3D::DrawArrays() { } const bool is_indexed{regs.index_array.count && !regs.vertex_buffer.count}; - rasterizer.DrawBatch(is_indexed); + if (ShouldExecute()) { + rasterizer.DrawBatch(is_indexed); + } if (debug_context) { debug_context->OnEvent(Tegra::DebugContext::Event::FinishedPrimitiveBatch, nullptr); -- cgit v1.2.3