From 114d6b2f97eb62c7d8c958ebb391b70b026130f9 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 17 Dec 2016 01:21:16 -0800 Subject: VideoCore/Shader: Split interpreter and JIT into separate ShaderEngines --- src/video_core/shader/shader_interpreter.cpp | 39 ++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'src/video_core/shader/shader_interpreter.cpp') diff --git a/src/video_core/shader/shader_interpreter.cpp b/src/video_core/shader/shader_interpreter.cpp index 20fb9754b..8e2b8c548 100644 --- a/src/video_core/shader/shader_interpreter.cpp +++ b/src/video_core/shader/shader_interpreter.cpp @@ -7,10 +7,12 @@ #include #include #include +#include #include #include "common/assert.h" #include "common/common_types.h" #include "common/logging/log.h" +#include "common/microprofile.h" #include "common/vector_math.h" #include "video_core/pica_state.h" #include "video_core/pica_types.h" @@ -37,8 +39,8 @@ struct CallStackElement { }; template -void RunInterpreter(const ShaderSetup& setup, UnitState& state, DebugData& debug_data, - unsigned offset) { +static void RunInterpreter(const ShaderSetup& setup, UnitState& state, DebugData& debug_data, + unsigned offset) { // TODO: Is there a maximal size for this? boost::container::static_vector call_stack; u32 program_counter = offset; @@ -647,9 +649,36 @@ void RunInterpreter(const ShaderSetup& setup, UnitState& state, DebugData } } -// Explicit instantiation -template void RunInterpreter(const ShaderSetup&, UnitState&, DebugData&, unsigned offset); -template void RunInterpreter(const ShaderSetup&, UnitState&, DebugData&, unsigned offset); +void InterpreterEngine::SetupBatch(const ShaderSetup* setup_) { + setup = setup_; +} + +MICROPROFILE_DECLARE(GPU_Shader); + +void InterpreterEngine::Run(UnitState& state, unsigned int entry_point) const { + ASSERT(setup != nullptr); + ASSERT(entry_point < 1024); + + MICROPROFILE_SCOPE(GPU_Shader); + + DebugData dummy_debug_data; + RunInterpreter(*setup, state, dummy_debug_data, entry_point); +} + +DebugData InterpreterEngine::ProduceDebugInfo(const InputVertex& input, int num_attributes, + unsigned int entry_point) const { + ASSERT(setup != nullptr); + ASSERT(entry_point < 1024); + + UnitState state; + DebugData debug_data; + + // Setup input register table + boost::fill(state.registers.input, Math::Vec4::AssignToAll(float24::Zero())); + state.LoadInputVertex(input, num_attributes); + RunInterpreter(*setup, state, debug_data, entry_point); + return debug_data; +} } // namespace -- cgit v1.2.3 From 1a2acc3baae01b9469ee97333c2ec4d58c8a0b91 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 17 Dec 2016 02:33:43 -0800 Subject: Shader: Don't read ShaderSetup from global state --- src/video_core/shader/shader_interpreter.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/video_core/shader/shader_interpreter.cpp') diff --git a/src/video_core/shader/shader_interpreter.cpp b/src/video_core/shader/shader_interpreter.cpp index 8e2b8c548..d1f11142d 100644 --- a/src/video_core/shader/shader_interpreter.cpp +++ b/src/video_core/shader/shader_interpreter.cpp @@ -75,9 +75,9 @@ static void RunInterpreter(const ShaderSetup& setup, UnitState& state, DebugData } }; - const auto& uniforms = g_state.vs.uniforms; - const auto& swizzle_data = g_state.vs.swizzle_data; - const auto& program_code = g_state.vs.program_code; + const auto& uniforms = setup.uniforms; + const auto& swizzle_data = setup.swizzle_data; + const auto& program_code = setup.program_code; // Placeholder for invalid inputs static float24 dummy_vec4_float24[4]; -- cgit v1.2.3 From 9ea5eacf919c8c257f8c5fda65e5fac2b6adee07 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 17 Dec 2016 14:09:02 -0800 Subject: Shader: Initialize conditional_code in interpreter This doesn't belong in LoadInputVertex because it also happens for non-VS invocations. Since it's not used by the JIT it seems adequate to initialize it in the interpreter which is the only thing that cares about them. --- src/video_core/shader/shader_interpreter.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/video_core/shader/shader_interpreter.cpp') diff --git a/src/video_core/shader/shader_interpreter.cpp b/src/video_core/shader/shader_interpreter.cpp index d1f11142d..ecc227089 100644 --- a/src/video_core/shader/shader_interpreter.cpp +++ b/src/video_core/shader/shader_interpreter.cpp @@ -45,6 +45,9 @@ static void RunInterpreter(const ShaderSetup& setup, UnitState& state, DebugData boost::container::static_vector call_stack; u32 program_counter = offset; + state.conditional_code[0] = false; + state.conditional_code[1] = false; + auto call = [&program_counter, &call_stack](u32 offset, u32 num_instructions, u32 return_offset, u8 repeat_count, u8 loop_increment) { // -1 to make sure when incrementing the PC we end up at the correct offset -- cgit v1.2.3 From 6fa3687afc97685101f9ee5c65cf98f505980695 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 17 Dec 2016 14:38:03 -0800 Subject: Shader: Remove OutputRegisters struct --- src/video_core/shader/shader_interpreter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/video_core/shader/shader_interpreter.cpp') diff --git a/src/video_core/shader/shader_interpreter.cpp b/src/video_core/shader/shader_interpreter.cpp index ecc227089..a6197c10a 100644 --- a/src/video_core/shader/shader_interpreter.cpp +++ b/src/video_core/shader/shader_interpreter.cpp @@ -175,7 +175,7 @@ static void RunInterpreter(const ShaderSetup& setup, UnitState& state, DebugData float24* dest = (instr.common.dest.Value() < 0x10) - ? &state.output_registers.value[instr.common.dest.Value().GetIndex()][0] + ? &state.registers.output[instr.common.dest.Value().GetIndex()][0] : (instr.common.dest.Value() < 0x20) ? &state.registers.temporary[instr.common.dest.Value().GetIndex()][0] : dummy_vec4_float24; @@ -518,7 +518,7 @@ static void RunInterpreter(const ShaderSetup& setup, UnitState& state, DebugData float24* dest = (instr.mad.dest.Value() < 0x10) - ? &state.output_registers.value[instr.mad.dest.Value().GetIndex()][0] + ? &state.registers.output[instr.mad.dest.Value().GetIndex()][0] : (instr.mad.dest.Value() < 0x20) ? &state.registers.temporary[instr.mad.dest.Value().GetIndex()][0] : dummy_vec4_float24; -- cgit v1.2.3 From 0f642741451e3f75c2f1d64ae9beccaf1437f12c Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 17 Dec 2016 16:06:04 -0800 Subject: VideoCore/Shader: Move per-batch ShaderEngine state into ShaderSetup --- src/video_core/shader/shader_interpreter.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/video_core/shader/shader_interpreter.cpp') diff --git a/src/video_core/shader/shader_interpreter.cpp b/src/video_core/shader/shader_interpreter.cpp index a6197c10a..e44abbf1d 100644 --- a/src/video_core/shader/shader_interpreter.cpp +++ b/src/video_core/shader/shader_interpreter.cpp @@ -652,25 +652,23 @@ static void RunInterpreter(const ShaderSetup& setup, UnitState& state, DebugData } } -void InterpreterEngine::SetupBatch(const ShaderSetup* setup_) { - setup = setup_; -} +void InterpreterEngine::SetupBatch(ShaderSetup& setup) {} MICROPROFILE_DECLARE(GPU_Shader); -void InterpreterEngine::Run(UnitState& state, unsigned int entry_point) const { - ASSERT(setup != nullptr); +void InterpreterEngine::Run(const ShaderSetup& setup, UnitState& state, + unsigned int entry_point) const { ASSERT(entry_point < 1024); MICROPROFILE_SCOPE(GPU_Shader); DebugData dummy_debug_data; - RunInterpreter(*setup, state, dummy_debug_data, entry_point); + RunInterpreter(setup, state, dummy_debug_data, entry_point); } -DebugData InterpreterEngine::ProduceDebugInfo(const InputVertex& input, int num_attributes, +DebugData InterpreterEngine::ProduceDebugInfo(const ShaderSetup& setup, + const InputVertex& input, int num_attributes, unsigned int entry_point) const { - ASSERT(setup != nullptr); ASSERT(entry_point < 1024); UnitState state; @@ -679,7 +677,7 @@ DebugData InterpreterEngine::ProduceDebugInfo(const InputVertex& input, in // Setup input register table boost::fill(state.registers.input, Math::Vec4::AssignToAll(float24::Zero())); state.LoadInputVertex(input, num_attributes); - RunInterpreter(*setup, state, debug_data, entry_point); + RunInterpreter(setup, state, debug_data, entry_point); return debug_data; } -- cgit v1.2.3 From 0e9081b97348c65029c96697443acb0dbbc58756 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 17 Dec 2016 16:16:02 -0800 Subject: VideoCore/Shader: Move entry_point to SetupBatch --- src/video_core/shader/shader_interpreter.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/video_core/shader/shader_interpreter.cpp') diff --git a/src/video_core/shader/shader_interpreter.cpp b/src/video_core/shader/shader_interpreter.cpp index e44abbf1d..c0c89b857 100644 --- a/src/video_core/shader/shader_interpreter.cpp +++ b/src/video_core/shader/shader_interpreter.cpp @@ -652,32 +652,31 @@ static void RunInterpreter(const ShaderSetup& setup, UnitState& state, DebugData } } -void InterpreterEngine::SetupBatch(ShaderSetup& setup) {} +void InterpreterEngine::SetupBatch(ShaderSetup& setup, unsigned int entry_point) { + ASSERT(entry_point < 1024); + setup.engine_data.entry_point = entry_point; +} MICROPROFILE_DECLARE(GPU_Shader); -void InterpreterEngine::Run(const ShaderSetup& setup, UnitState& state, - unsigned int entry_point) const { - ASSERT(entry_point < 1024); +void InterpreterEngine::Run(const ShaderSetup& setup, UnitState& state) const { MICROPROFILE_SCOPE(GPU_Shader); DebugData dummy_debug_data; - RunInterpreter(setup, state, dummy_debug_data, entry_point); + RunInterpreter(setup, state, dummy_debug_data, setup.engine_data.entry_point); } DebugData InterpreterEngine::ProduceDebugInfo(const ShaderSetup& setup, - const InputVertex& input, int num_attributes, - unsigned int entry_point) const { - ASSERT(entry_point < 1024); - + const InputVertex& input, + int num_attributes) const { UnitState state; DebugData debug_data; // Setup input register table boost::fill(state.registers.input, Math::Vec4::AssignToAll(float24::Zero())); state.LoadInputVertex(input, num_attributes); - RunInterpreter(setup, state, debug_data, entry_point); + RunInterpreter(setup, state, debug_data, setup.engine_data.entry_point); return debug_data; } -- cgit v1.2.3