diff options
Diffstat (limited to 'src/video_core/macro/macro.h')
| -rw-r--r-- | src/video_core/macro/macro.h | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/src/video_core/macro/macro.h b/src/video_core/macro/macro.h new file mode 100644 index 000000000..28ca243d1 --- /dev/null +++ b/src/video_core/macro/macro.h | |||
| @@ -0,0 +1,128 @@ | |||
| 1 | // Copyright 2020 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <memory> | ||
| 8 | #include <unordered_map> | ||
| 9 | #include <vector> | ||
| 10 | #include "common/bit_field.h" | ||
| 11 | #include "common/common_types.h" | ||
| 12 | |||
| 13 | namespace Tegra { | ||
| 14 | namespace Engines { | ||
| 15 | class Maxwell3D; | ||
| 16 | } | ||
| 17 | namespace Macro { | ||
| 18 | constexpr std::size_t NUM_MACRO_REGISTERS = 8; | ||
| 19 | enum class Operation : u32 { | ||
| 20 | ALU = 0, | ||
| 21 | AddImmediate = 1, | ||
| 22 | ExtractInsert = 2, | ||
| 23 | ExtractShiftLeftImmediate = 3, | ||
| 24 | ExtractShiftLeftRegister = 4, | ||
| 25 | Read = 5, | ||
| 26 | Unused = 6, // This operation doesn't seem to be a valid encoding. | ||
| 27 | Branch = 7, | ||
| 28 | }; | ||
| 29 | |||
| 30 | enum class ALUOperation : u32 { | ||
| 31 | Add = 0, | ||
| 32 | AddWithCarry = 1, | ||
| 33 | Subtract = 2, | ||
| 34 | SubtractWithBorrow = 3, | ||
| 35 | // Operations 4-7 don't seem to be valid encodings. | ||
| 36 | Xor = 8, | ||
| 37 | Or = 9, | ||
| 38 | And = 10, | ||
| 39 | AndNot = 11, | ||
| 40 | Nand = 12 | ||
| 41 | }; | ||
| 42 | |||
| 43 | enum class ResultOperation : u32 { | ||
| 44 | IgnoreAndFetch = 0, | ||
| 45 | Move = 1, | ||
| 46 | MoveAndSetMethod = 2, | ||
| 47 | FetchAndSend = 3, | ||
| 48 | MoveAndSend = 4, | ||
| 49 | FetchAndSetMethod = 5, | ||
| 50 | MoveAndSetMethodFetchAndSend = 6, | ||
| 51 | MoveAndSetMethodSend = 7 | ||
| 52 | }; | ||
| 53 | |||
| 54 | enum class BranchCondition : u32 { | ||
| 55 | Zero = 0, | ||
| 56 | NotZero = 1, | ||
| 57 | }; | ||
| 58 | |||
| 59 | union Opcode { | ||
| 60 | u32 raw; | ||
| 61 | BitField<0, 3, Operation> operation; | ||
| 62 | BitField<4, 3, ResultOperation> result_operation; | ||
| 63 | BitField<4, 1, BranchCondition> branch_condition; | ||
| 64 | // If set on a branch, then the branch doesn't have a delay slot. | ||
| 65 | BitField<5, 1, u32> branch_annul; | ||
| 66 | BitField<7, 1, u32> is_exit; | ||
| 67 | BitField<8, 3, u32> dst; | ||
| 68 | BitField<11, 3, u32> src_a; | ||
| 69 | BitField<14, 3, u32> src_b; | ||
| 70 | // The signed immediate overlaps the second source operand and the alu operation. | ||
| 71 | BitField<14, 18, s32> immediate; | ||
| 72 | |||
| 73 | BitField<17, 5, ALUOperation> alu_operation; | ||
| 74 | |||
| 75 | // Bitfield instructions data | ||
| 76 | BitField<17, 5, u32> bf_src_bit; | ||
| 77 | BitField<22, 5, u32> bf_size; | ||
| 78 | BitField<27, 5, u32> bf_dst_bit; | ||
| 79 | |||
| 80 | u32 GetBitfieldMask() const { | ||
| 81 | return (1 << bf_size) - 1; | ||
| 82 | } | ||
| 83 | |||
| 84 | s32 GetBranchTarget() const { | ||
| 85 | return static_cast<s32>(immediate * sizeof(u32)); | ||
| 86 | } | ||
| 87 | }; | ||
| 88 | |||
| 89 | union MethodAddress { | ||
| 90 | u32 raw; | ||
| 91 | BitField<0, 12, u32> address; | ||
| 92 | BitField<12, 6, u32> increment; | ||
| 93 | }; | ||
| 94 | |||
| 95 | } // namespace Macro | ||
| 96 | |||
| 97 | class CachedMacro { | ||
| 98 | public: | ||
| 99 | virtual ~CachedMacro() = default; | ||
| 100 | /** | ||
| 101 | * Executes the macro code with the specified input parameters. | ||
| 102 | * @param code The macro byte code to execute | ||
| 103 | * @param parameters The parameters of the macro | ||
| 104 | */ | ||
| 105 | virtual void Execute(std::vector<u32>& parameters, u32 method) = 0; | ||
| 106 | }; | ||
| 107 | |||
| 108 | class MacroEngine { | ||
| 109 | public: | ||
| 110 | virtual ~MacroEngine() = default; | ||
| 111 | |||
| 112 | // Store the uploaded macro code to compile them when they're called. | ||
| 113 | void AddCode(u32 method, u32 data); | ||
| 114 | |||
| 115 | // Compiles the macro if its not in the cache, and executes the compiled macro | ||
| 116 | void Execute(u32 method, std::vector<u32> parameters); | ||
| 117 | |||
| 118 | protected: | ||
| 119 | virtual std::unique_ptr<CachedMacro> Compile(const std::vector<u32>& code) = 0; | ||
| 120 | |||
| 121 | private: | ||
| 122 | std::unordered_map<u32, std::unique_ptr<CachedMacro>> macro_cache; | ||
| 123 | std::unordered_map<u32, std::vector<u32>> uploaded_macro_code; | ||
| 124 | }; | ||
| 125 | |||
| 126 | std::unique_ptr<MacroEngine> GetMacroEngine(Engines::Maxwell3D& maxwell3d); | ||
| 127 | |||
| 128 | } // namespace Tegra | ||