summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Lioncash2022-01-25 14:03:46 -0500
committerGravatar Lioncash2022-01-25 14:03:48 -0500
commit81d1a1133dad918cabc9f50948b6535b4a1e8893 (patch)
tree527d2524e2badec97e02047caf701955978b9f7c
parentvideo_core/macro_hle: Return unique_ptr directly from GetHLEProgram() (diff)
downloadyuzu-81d1a1133dad918cabc9f50948b6535b4a1e8893.tar.gz
yuzu-81d1a1133dad918cabc9f50948b6535b4a1e8893.tar.xz
yuzu-81d1a1133dad918cabc9f50948b6535b4a1e8893.zip
video_core/macro_interpreter: Move impl class to the cpp file
Keeps the implementation hidden from the intended API and lessens the header dependencies on the interpreter's header.
-rw-r--r--src/video_core/macro/macro_interpreter.cpp92
-rw-r--r--src/video_core/macro/macro_interpreter.h78
2 files changed, 86 insertions, 84 deletions
diff --git a/src/video_core/macro/macro_interpreter.cpp b/src/video_core/macro/macro_interpreter.cpp
index 8da26fd59..fba755448 100644
--- a/src/video_core/macro/macro_interpreter.cpp
+++ b/src/video_core/macro/macro_interpreter.cpp
@@ -2,6 +2,9 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <array>
6#include <optional>
7
5#include "common/assert.h" 8#include "common/assert.h"
6#include "common/logging/log.h" 9#include "common/logging/log.h"
7#include "common/microprofile.h" 10#include "common/microprofile.h"
@@ -11,16 +14,81 @@
11MICROPROFILE_DEFINE(MacroInterp, "GPU", "Execute macro interpreter", MP_RGB(128, 128, 192)); 14MICROPROFILE_DEFINE(MacroInterp, "GPU", "Execute macro interpreter", MP_RGB(128, 128, 192));
12 15
13namespace Tegra { 16namespace Tegra {
14MacroInterpreter::MacroInterpreter(Engines::Maxwell3D& maxwell3d_) 17namespace {
15 : MacroEngine{maxwell3d_}, maxwell3d{maxwell3d_} {} 18class MacroInterpreterImpl final : public CachedMacro {
19public:
20 explicit MacroInterpreterImpl(Engines::Maxwell3D& maxwell3d_, const std::vector<u32>& code_)
21 : maxwell3d{maxwell3d_}, code{code_} {}
16 22
17std::unique_ptr<CachedMacro> MacroInterpreter::Compile(const std::vector<u32>& code) { 23 void Execute(const std::vector<u32>& params, u32 method) override;
18 return std::make_unique<MacroInterpreterImpl>(maxwell3d, code); 24
19} 25private:
26 /// Resets the execution engine state, zeroing registers, etc.
27 void Reset();
28
29 /**
30 * Executes a single macro instruction located at the current program counter. Returns whether
31 * the interpreter should keep running.
32 *
33 * @param is_delay_slot Whether the current step is being executed due to a delay slot in a
34 * previous instruction.
35 */
36 bool Step(bool is_delay_slot);
37
38 /// Calculates the result of an ALU operation. src_a OP src_b;
39 u32 GetALUResult(Macro::ALUOperation operation, u32 src_a, u32 src_b);
40
41 /// Performs the result operation on the input result and stores it in the specified register
42 /// (if necessary).
43 void ProcessResult(Macro::ResultOperation operation, u32 reg, u32 result);
44
45 /// Evaluates the branch condition and returns whether the branch should be taken or not.
46 bool EvaluateBranchCondition(Macro::BranchCondition cond, u32 value) const;
47
48 /// Reads an opcode at the current program counter location.
49 Macro::Opcode GetOpcode() const;
50
51 /// Returns the specified register's value. Register 0 is hardcoded to always return 0.
52 u32 GetRegister(u32 register_id) const;
53
54 /// Sets the register to the input value.
55 void SetRegister(u32 register_id, u32 value);
56
57 /// Sets the method address to use for the next Send instruction.
58 void SetMethodAddress(u32 address);
20 59
21MacroInterpreterImpl::MacroInterpreterImpl(Engines::Maxwell3D& maxwell3d_, 60 /// Calls a GPU Engine method with the input parameter.
22 const std::vector<u32>& code_) 61 void Send(u32 value);
23 : maxwell3d{maxwell3d_}, code{code_} {} 62
63 /// Reads a GPU register located at the method address.
64 u32 Read(u32 method) const;
65
66 /// Returns the next parameter in the parameter queue.
67 u32 FetchParameter();
68
69 Engines::Maxwell3D& maxwell3d;
70
71 /// Current program counter
72 u32 pc{};
73 /// Program counter to execute at after the delay slot is executed.
74 std::optional<u32> delayed_pc;
75
76 /// General purpose macro registers.
77 std::array<u32, Macro::NUM_MACRO_REGISTERS> registers = {};
78
79 /// Method address to use for the next Send instruction.
80 Macro::MethodAddress method_address = {};
81
82 /// Input parameters of the current macro.
83 std::unique_ptr<u32[]> parameters;
84 std::size_t num_parameters = 0;
85 std::size_t parameters_capacity = 0;
86 /// Index of the next parameter that will be fetched by the 'parm' instruction.
87 u32 next_parameter_index = 0;
88
89 bool carry_flag = false;
90 const std::vector<u32>& code;
91};
24 92
25void MacroInterpreterImpl::Execute(const std::vector<u32>& params, u32 method) { 93void MacroInterpreterImpl::Execute(const std::vector<u32>& params, u32 method) {
26 MICROPROFILE_SCOPE(MacroInterp); 94 MICROPROFILE_SCOPE(MacroInterp);
@@ -283,5 +351,13 @@ u32 MacroInterpreterImpl::FetchParameter() {
283 ASSERT(next_parameter_index < num_parameters); 351 ASSERT(next_parameter_index < num_parameters);
284 return parameters[next_parameter_index++]; 352 return parameters[next_parameter_index++];
285} 353}
354} // Anonymous namespace
355
356MacroInterpreter::MacroInterpreter(Engines::Maxwell3D& maxwell3d_)
357 : MacroEngine{maxwell3d_}, maxwell3d{maxwell3d_} {}
358
359std::unique_ptr<CachedMacro> MacroInterpreter::Compile(const std::vector<u32>& code) {
360 return std::make_unique<MacroInterpreterImpl>(maxwell3d, code);
361}
286 362
287} // namespace Tegra 363} // namespace Tegra
diff --git a/src/video_core/macro/macro_interpreter.h b/src/video_core/macro/macro_interpreter.h
index d50c619ce..8a9648e46 100644
--- a/src/video_core/macro/macro_interpreter.h
+++ b/src/video_core/macro/macro_interpreter.h
@@ -3,10 +3,9 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#pragma once 5#pragma once
6#include <array> 6
7#include <optional>
8#include <vector> 7#include <vector>
9#include "common/bit_field.h" 8
10#include "common/common_types.h" 9#include "common/common_types.h"
11#include "video_core/macro/macro.h" 10#include "video_core/macro/macro.h"
12 11
@@ -26,77 +25,4 @@ private:
26 Engines::Maxwell3D& maxwell3d; 25 Engines::Maxwell3D& maxwell3d;
27}; 26};
28 27
29class MacroInterpreterImpl : public CachedMacro {
30public:
31 explicit MacroInterpreterImpl(Engines::Maxwell3D& maxwell3d_, const std::vector<u32>& code_);
32 void Execute(const std::vector<u32>& params, u32 method) override;
33
34private:
35 /// Resets the execution engine state, zeroing registers, etc.
36 void Reset();
37
38 /**
39 * Executes a single macro instruction located at the current program counter. Returns whether
40 * the interpreter should keep running.
41 *
42 * @param is_delay_slot Whether the current step is being executed due to a delay slot in a
43 * previous instruction.
44 */
45 bool Step(bool is_delay_slot);
46
47 /// Calculates the result of an ALU operation. src_a OP src_b;
48 u32 GetALUResult(Macro::ALUOperation operation, u32 src_a, u32 src_b);
49
50 /// Performs the result operation on the input result and stores it in the specified register
51 /// (if necessary).
52 void ProcessResult(Macro::ResultOperation operation, u32 reg, u32 result);
53
54 /// Evaluates the branch condition and returns whether the branch should be taken or not.
55 bool EvaluateBranchCondition(Macro::BranchCondition cond, u32 value) const;
56
57 /// Reads an opcode at the current program counter location.
58 Macro::Opcode GetOpcode() const;
59
60 /// Returns the specified register's value. Register 0 is hardcoded to always return 0.
61 u32 GetRegister(u32 register_id) const;
62
63 /// Sets the register to the input value.
64 void SetRegister(u32 register_id, u32 value);
65
66 /// Sets the method address to use for the next Send instruction.
67 void SetMethodAddress(u32 address);
68
69 /// Calls a GPU Engine method with the input parameter.
70 void Send(u32 value);
71
72 /// Reads a GPU register located at the method address.
73 u32 Read(u32 method) const;
74
75 /// Returns the next parameter in the parameter queue.
76 u32 FetchParameter();
77
78 Engines::Maxwell3D& maxwell3d;
79
80 /// Current program counter
81 u32 pc;
82 /// Program counter to execute at after the delay slot is executed.
83 std::optional<u32> delayed_pc;
84
85 /// General purpose macro registers.
86 std::array<u32, Macro::NUM_MACRO_REGISTERS> registers = {};
87
88 /// Method address to use for the next Send instruction.
89 Macro::MethodAddress method_address = {};
90
91 /// Input parameters of the current macro.
92 std::unique_ptr<u32[]> parameters;
93 std::size_t num_parameters = 0;
94 std::size_t parameters_capacity = 0;
95 /// Index of the next parameter that will be fetched by the 'parm' instruction.
96 u32 next_parameter_index = 0;
97
98 bool carry_flag = false;
99 const std::vector<u32>& code;
100};
101
102} // namespace Tegra 28} // namespace Tegra