Maxwell3D: Corrections and refactors to MME instance refactor

This commit is contained in:
Fernando Sahmkow 2019-09-22 07:23:13 -04:00
parent 433e764bb0
commit 68f5aff64f
4 changed files with 46 additions and 44 deletions

View file

@ -260,7 +260,7 @@ void Maxwell3D::CallMacroMethod(u32 method, std::size_t num_parameters, const u3
// Execute the current macro. // Execute the current macro.
macro_interpreter.Execute(macro_positions[entry], num_parameters, parameters); macro_interpreter.Execute(macro_positions[entry], num_parameters, parameters);
if (mme_draw.current_mode != MMMEDrawMode::Undefined) { if (mme_draw.current_mode != MMEDrawMode::Undefined) {
FlushMMEInlineDraw(); FlushMMEInlineDraw();
} }
} }
@ -423,18 +423,8 @@ void Maxwell3D::CallMethod(const GPU::MethodCall& method_call) {
} }
} }
void Maxwell3D::CallMethodFromMME(const GPU::MethodCall& method_call) { void Maxwell3D::StepInstance(const MMEDrawMode expected_mode, const u32 count) {
const u32 method = method_call.method; if (mme_draw.current_mode == MMEDrawMode::Undefined) {
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) { if (mme_draw.gl_begin_consume) {
mme_draw.current_mode = expected_mode; mme_draw.current_mode = expected_mode;
mme_draw.current_count = count; mme_draw.current_count = count;
@ -442,18 +432,31 @@ void Maxwell3D::CallMethodFromMME(const GPU::MethodCall& method_call) {
mme_draw.gl_begin_consume = false; mme_draw.gl_begin_consume = false;
mme_draw.gl_end_count = 0; mme_draw.gl_end_count = 0;
} }
break; return;
} else { } 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_mode && mme_draw.gl_begin_consume) {
mme_draw.instance_count++; mme_draw.instance_count++;
mme_draw.gl_begin_consume = false; mme_draw.gl_begin_consume = false;
break; return;
} else { } else {
FlushMMEInlineDraw(); 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 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)) { } else if (method == MAXWELL3D_REG_INDEX(draw.vertex_begin_gl)) {
mme_draw.instance_mode = mme_draw.instance_mode =
(regs.draw.instance_next != 0) || (regs.draw.instance_cont != 0); (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++; mme_draw.gl_end_count++;
} }
} else { } else {
if (mme_draw.current_mode != MMMEDrawMode::Undefined) { if (mme_draw.current_mode != MMEDrawMode::Undefined) {
FlushMMEInlineDraw(); FlushMMEInlineDraw();
} }
CallMethod(method_call); CallMethod(method_call);
@ -485,8 +488,10 @@ void Maxwell3D::FlushMMEInlineDraw() {
ASSERT_MSG(!regs.draw.instance_next || !regs.draw.instance_cont, ASSERT_MSG(!regs.draw.instance_next || !regs.draw.instance_cont,
"Illegal combination of instancing parameters"); "Illegal combination of instancing parameters");
const bool is_indexed = mme_draw.current_mode == MMMEDrawMode::Indexed; const bool is_indexed = mme_draw.current_mode == MMEDrawMode::Indexed;
if (ShouldExecute()) {
rasterizer.DrawMultiBatch(is_indexed); rasterizer.DrawMultiBatch(is_indexed);
}
if (debug_context) { if (debug_context) {
debug_context->OnEvent(Tegra::DebugContext::Event::FinishedPrimitiveBatch, nullptr); debug_context->OnEvent(Tegra::DebugContext::Event::FinishedPrimitiveBatch, nullptr);
@ -501,7 +506,7 @@ void Maxwell3D::FlushMMEInlineDraw() {
} else { } else {
regs.vertex_buffer.count = 0; regs.vertex_buffer.count = 0;
} }
mme_draw.current_mode = MMMEDrawMode::Undefined; mme_draw.current_mode = MMEDrawMode::Undefined;
mme_draw.current_count = 0; mme_draw.current_count = 0;
mme_draw.instance_count = 0; mme_draw.instance_count = 0;
mme_draw.instance_mode = false; mme_draw.instance_mode = false;
@ -657,7 +662,9 @@ void Maxwell3D::DrawArrays() {
} }
const bool is_indexed{regs.index_array.count && !regs.vertex_buffer.count}; const bool is_indexed{regs.index_array.count && !regs.vertex_buffer.count};
if (ShouldExecute()) {
rasterizer.DrawBatch(is_indexed); rasterizer.DrawBatch(is_indexed);
}
if (debug_context) { if (debug_context) {
debug_context->OnEvent(Tegra::DebugContext::Event::FinishedPrimitiveBatch, nullptr); debug_context->OnEvent(Tegra::DebugContext::Event::FinishedPrimitiveBatch, nullptr);

View file

@ -1269,14 +1269,14 @@ public:
return execute_on; return execute_on;
} }
enum class MMMEDrawMode : u32 { enum class MMEDrawMode : u32 {
Undefined, Undefined,
Array, Array,
Indexed, Indexed,
}; };
struct MMEDrawState { struct MMEDrawState {
MMMEDrawMode current_mode{MMMEDrawMode::Undefined}; MMEDrawMode current_mode{MMEDrawMode::Undefined};
u32 current_count{}; u32 current_count{};
u32 instance_count{}; u32 instance_count{};
bool instance_mode{}; bool instance_mode{};
@ -1369,6 +1369,9 @@ private:
/// Handles a write to the VERTEX_END_GL register, triggering a draw. /// Handles a write to the VERTEX_END_GL register, triggering a draw.
void DrawArrays(); void DrawArrays();
// Handles a instance drawcall from MME
void StepInstance(MMEDrawMode expected_mode, u32 count);
}; };
#define ASSERT_REG_POSITION(field_name, position) \ #define ASSERT_REG_POSITION(field_name, position) \

View file

@ -31,7 +31,7 @@ public:
/// Draw the current batch of vertex arrays /// Draw the current batch of vertex arrays
virtual bool DrawBatch(bool is_indexed) = 0; virtual bool DrawBatch(bool is_indexed) = 0;
/// Draw the current batch of multiple instasnces of vertex arrays /// Draw the current batch of multiple instances of vertex arrays
virtual bool DrawMultiBatch(bool is_indexed) = 0; virtual bool DrawMultiBatch(bool is_indexed) = 0;
/// Clear the current framebuffer /// Clear the current framebuffer

View file

@ -749,13 +749,9 @@ bool RasterizerOpenGL::DrawBatch(bool is_indexed) {
MICROPROFILE_SCOPE(OpenGL_Drawing); MICROPROFILE_SCOPE(OpenGL_Drawing);
auto& maxwell3d = system.GPU().Maxwell3D();
if (!maxwell3d.ShouldExecute()) {
return false;
}
DrawPrelude(); DrawPrelude();
auto& maxwell3d = system.GPU().Maxwell3D();
const auto& regs = maxwell3d.regs; const auto& regs = maxwell3d.regs;
const auto current_instance = maxwell3d.state.current_instance; const auto current_instance = maxwell3d.state.current_instance;
DrawParams draw_call{}; DrawParams draw_call{};
@ -785,13 +781,9 @@ bool RasterizerOpenGL::DrawMultiBatch(bool is_indexed) {
MICROPROFILE_SCOPE(OpenGL_Drawing); MICROPROFILE_SCOPE(OpenGL_Drawing);
auto& maxwell3d = system.GPU().Maxwell3D();
if (!maxwell3d.ShouldExecute()) {
return false;
}
DrawPrelude(); DrawPrelude();
auto& maxwell3d = system.GPU().Maxwell3D();
const auto& regs = maxwell3d.regs; const auto& regs = maxwell3d.regs;
const auto& draw_setup = maxwell3d.mme_draw; const auto& draw_setup = maxwell3d.mme_draw;
DrawParams draw_call{}; DrawParams draw_call{};