summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Sebastian Valle2018-03-18 15:13:40 -0500
committerGravatar GitHub2018-03-18 15:13:40 -0500
commit46f9d4b4a34ab6d4b072a41de28771906a610d4a (patch)
tree1c17173b997f694dc0bd04d516a131748b4d990d /src
parentMerge pull request #245 from Subv/set_shader2 (diff)
parentGPU: Store uploaded GPU macros and keep track of the number of method paramet... (diff)
downloadyuzu-46f9d4b4a34ab6d4b072a41de28771906a610d4a.tar.gz
yuzu-46f9d4b4a34ab6d4b072a41de28771906a610d4a.tar.xz
yuzu-46f9d4b4a34ab6d4b072a41de28771906a610d4a.zip
Merge pull request #246 from Subv/gpu_macro_calls
GPU: Store uploaded GPU macros and keep track of the number of method arguments.
Diffstat (limited to 'src')
-rw-r--r--src/video_core/command_processor.cpp85
-rw-r--r--src/video_core/engines/fermi_2d.cpp1
-rw-r--r--src/video_core/engines/fermi_2d.h8
-rw-r--r--src/video_core/engines/maxwell_3d.cpp52
-rw-r--r--src/video_core/engines/maxwell_3d.h31
-rw-r--r--src/video_core/engines/maxwell_compute.cpp1
-rw-r--r--src/video_core/engines/maxwell_compute.h8
-rw-r--r--src/video_core/gpu.h13
8 files changed, 119 insertions, 80 deletions
diff --git a/src/video_core/command_processor.cpp b/src/video_core/command_processor.cpp
index 26ba8c40b..d4cdb4ab2 100644
--- a/src/video_core/command_processor.cpp
+++ b/src/video_core/command_processor.cpp
@@ -24,12 +24,37 @@ namespace Tegra {
24 24
25enum class BufferMethods { 25enum class BufferMethods {
26 BindObject = 0, 26 BindObject = 0,
27 SetGraphMacroCode = 0x45,
28 SetGraphMacroCodeArg = 0x46,
29 SetGraphMacroEntry = 0x47,
27 CountBufferMethods = 0x100, 30 CountBufferMethods = 0x100,
28}; 31};
29 32
30void GPU::WriteReg(u32 method, u32 subchannel, u32 value) { 33void GPU::WriteReg(u32 method, u32 subchannel, u32 value, u32 remaining_params) {
31 LOG_WARNING(HW_GPU, "Processing method %08X on subchannel %u value %08X", method, subchannel, 34 LOG_WARNING(HW_GPU, "Processing method %08X on subchannel %u value %08X remaining params %u",
32 value); 35 method, subchannel, value, remaining_params);
36
37 if (method == static_cast<u32>(BufferMethods::SetGraphMacroEntry)) {
38 // Prepare to upload a new macro, reset the upload counter.
39 LOG_DEBUG(HW_GPU, "Uploading GPU macro %08X", value);
40 current_macro_entry = value;
41 current_macro_code.clear();
42 return;
43 }
44
45 if (method == static_cast<u32>(BufferMethods::SetGraphMacroCodeArg)) {
46 // Append a new code word to the current macro.
47 current_macro_code.push_back(value);
48
49 // There are no more params remaining, submit the code to the 3D engine.
50 if (remaining_params == 0) {
51 maxwell_3d->SubmitMacroCode(current_macro_entry, std::move(current_macro_code));
52 current_macro_entry = InvalidGraphMacroEntry;
53 current_macro_code.clear();
54 }
55
56 return;
57 }
33 58
34 if (method == static_cast<u32>(BufferMethods::BindObject)) { 59 if (method == static_cast<u32>(BufferMethods::BindObject)) {
35 // Bind the current subchannel to the desired engine id. 60 // Bind the current subchannel to the desired engine id.
@@ -54,7 +79,7 @@ void GPU::WriteReg(u32 method, u32 subchannel, u32 value) {
54 fermi_2d->WriteReg(method, value); 79 fermi_2d->WriteReg(method, value);
55 break; 80 break;
56 case EngineID::MAXWELL_B: 81 case EngineID::MAXWELL_B:
57 maxwell_3d->WriteReg(method, value); 82 maxwell_3d->WriteReg(method, value, remaining_params);
58 break; 83 break;
59 case EngineID::MAXWELL_COMPUTE_B: 84 case EngineID::MAXWELL_COMPUTE_B:
60 maxwell_compute->WriteReg(method, value); 85 maxwell_compute->WriteReg(method, value);
@@ -64,35 +89,6 @@ void GPU::WriteReg(u32 method, u32 subchannel, u32 value) {
64 } 89 }
65} 90}
66 91
67void GPU::CallMethod(u32 method, u32 subchannel, const std::vector<u32>& parameters) {
68 LOG_WARNING(HW_GPU, "Processing method %08X on subchannel %u num params %zu", method,
69 subchannel, parameters.size());
70
71 if (method < static_cast<u32>(BufferMethods::CountBufferMethods)) {
72 // TODO(Subv): Research and implement these methods.
73 LOG_ERROR(HW_GPU, "Special buffer methods other than Bind are not implemented");
74 return;
75 }
76
77 ASSERT(bound_engines.find(subchannel) != bound_engines.end());
78
79 const EngineID engine = bound_engines[subchannel];
80
81 switch (engine) {
82 case EngineID::FERMI_TWOD_A:
83 fermi_2d->CallMethod(method, parameters);
84 break;
85 case EngineID::MAXWELL_B:
86 maxwell_3d->CallMethod(method, parameters);
87 break;
88 case EngineID::MAXWELL_COMPUTE_B:
89 maxwell_compute->CallMethod(method, parameters);
90 break;
91 default:
92 UNIMPLEMENTED();
93 }
94}
95
96void GPU::ProcessCommandList(GPUVAddr address, u32 size) { 92void GPU::ProcessCommandList(GPUVAddr address, u32 size) {
97 // TODO(Subv): PhysicalToVirtualAddress is a misnomer, it converts a GPU VAddr into an 93 // TODO(Subv): PhysicalToVirtualAddress is a misnomer, it converts a GPU VAddr into an
98 // application VAddr. 94 // application VAddr.
@@ -107,7 +103,8 @@ void GPU::ProcessCommandList(GPUVAddr address, u32 size) {
107 case SubmissionMode::Increasing: { 103 case SubmissionMode::Increasing: {
108 // Increase the method value with each argument. 104 // Increase the method value with each argument.
109 for (unsigned i = 0; i < header.arg_count; ++i) { 105 for (unsigned i = 0; i < header.arg_count; ++i) {
110 WriteReg(header.method + i, header.subchannel, Memory::Read32(current_addr)); 106 WriteReg(header.method + i, header.subchannel, Memory::Read32(current_addr),
107 header.arg_count - i - 1);
111 current_addr += sizeof(u32); 108 current_addr += sizeof(u32);
112 } 109 }
113 break; 110 break;
@@ -116,31 +113,31 @@ void GPU::ProcessCommandList(GPUVAddr address, u32 size) {
116 case SubmissionMode::NonIncreasing: { 113 case SubmissionMode::NonIncreasing: {
117 // Use the same method value for all arguments. 114 // Use the same method value for all arguments.
118 for (unsigned i = 0; i < header.arg_count; ++i) { 115 for (unsigned i = 0; i < header.arg_count; ++i) {
119 WriteReg(header.method, header.subchannel, Memory::Read32(current_addr)); 116 WriteReg(header.method, header.subchannel, Memory::Read32(current_addr),
117 header.arg_count - i - 1);
120 current_addr += sizeof(u32); 118 current_addr += sizeof(u32);
121 } 119 }
122 break; 120 break;
123 } 121 }
124 case SubmissionMode::IncreaseOnce: { 122 case SubmissionMode::IncreaseOnce: {
125 ASSERT(header.arg_count.Value() >= 1); 123 ASSERT(header.arg_count.Value() >= 1);
124
126 // Use the original method for the first argument and then the next method for all other 125 // Use the original method for the first argument and then the next method for all other
127 // arguments. 126 // arguments.
127 WriteReg(header.method, header.subchannel, Memory::Read32(current_addr),
128 header.arg_count - 1);
129 current_addr += sizeof(u32);
128 130
129 // Process this command as a method call instead of a register write. Gather 131 for (unsigned i = 1; i < header.arg_count; ++i) {
130 // all the parameters first and then pass them at once to the CallMethod function. 132 WriteReg(header.method + 1, header.subchannel, Memory::Read32(current_addr),
131 std::vector<u32> parameters(header.arg_count); 133 header.arg_count - i - 1);
132
133 for (unsigned i = 0; i < header.arg_count; ++i) {
134 parameters[i] = Memory::Read32(current_addr);
135 current_addr += sizeof(u32); 134 current_addr += sizeof(u32);
136 } 135 }
137
138 CallMethod(header.method, header.subchannel, parameters);
139 break; 136 break;
140 } 137 }
141 case SubmissionMode::Inline: { 138 case SubmissionMode::Inline: {
142 // The register value is stored in the bits 16-28 as an immediate 139 // The register value is stored in the bits 16-28 as an immediate
143 WriteReg(header.method, header.subchannel, header.inline_data); 140 WriteReg(header.method, header.subchannel, header.inline_data, 0);
144 break; 141 break;
145 } 142 }
146 default: 143 default:
diff --git a/src/video_core/engines/fermi_2d.cpp b/src/video_core/engines/fermi_2d.cpp
index 6c6162cf3..7aab163dc 100644
--- a/src/video_core/engines/fermi_2d.cpp
+++ b/src/video_core/engines/fermi_2d.cpp
@@ -8,7 +8,6 @@ namespace Tegra {
8namespace Engines { 8namespace Engines {
9 9
10void Fermi2D::WriteReg(u32 method, u32 value) {} 10void Fermi2D::WriteReg(u32 method, u32 value) {}
11void Fermi2D::CallMethod(u32 method, const std::vector<u32>& parameters) {}
12 11
13} // namespace Engines 12} // namespace Engines
14} // namespace Tegra 13} // namespace Tegra
diff --git a/src/video_core/engines/fermi_2d.h b/src/video_core/engines/fermi_2d.h
index ce8920cee..8967ddede 100644
--- a/src/video_core/engines/fermi_2d.h
+++ b/src/video_core/engines/fermi_2d.h
@@ -4,7 +4,6 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <vector>
8#include "common/common_types.h" 7#include "common/common_types.h"
9 8
10namespace Tegra { 9namespace Tegra {
@@ -17,13 +16,6 @@ public:
17 16
18 /// Write the value to the register identified by method. 17 /// Write the value to the register identified by method.
19 void WriteReg(u32 method, u32 value); 18 void WriteReg(u32 method, u32 value);
20
21 /**
22 * Handles a method call to this engine.
23 * @param method Method to call
24 * @param parameters Arguments to the method call
25 */
26 void CallMethod(u32 method, const std::vector<u32>& parameters);
27}; 19};
28 20
29} // namespace Engines 21} // namespace Engines
diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp
index db12fc702..49a138c1d 100644
--- a/src/video_core/engines/maxwell_3d.cpp
+++ b/src/video_core/engines/maxwell_3d.cpp
@@ -8,28 +8,68 @@
8namespace Tegra { 8namespace Tegra {
9namespace Engines { 9namespace Engines {
10 10
11/// First register id that is actually a Macro call.
12constexpr u32 MacroRegistersStart = 0xE00;
13
11const std::unordered_map<u32, Maxwell3D::MethodInfo> Maxwell3D::method_handlers = { 14const std::unordered_map<u32, Maxwell3D::MethodInfo> Maxwell3D::method_handlers = {
12 {0xE24, {"SetShader", 5, &Maxwell3D::SetShader}}, 15 {0xE24, {"SetShader", 5, &Maxwell3D::SetShader}},
13}; 16};
14 17
15Maxwell3D::Maxwell3D(MemoryManager& memory_manager) : memory_manager(memory_manager) {} 18Maxwell3D::Maxwell3D(MemoryManager& memory_manager) : memory_manager(memory_manager) {}
16 19
17void Maxwell3D::CallMethod(u32 method, const std::vector<u32>& parameters) { 20void Maxwell3D::SubmitMacroCode(u32 entry, std::vector<u32> code) {
21 uploaded_macros[entry * 2 + MacroRegistersStart] = std::move(code);
22}
23
24void Maxwell3D::CallMacroMethod(u32 method, const std::vector<u32>& parameters) {
18 // TODO(Subv): Write an interpreter for the macros uploaded via registers 0x45 and 0x47 25 // TODO(Subv): Write an interpreter for the macros uploaded via registers 0x45 and 0x47
26
27 // The requested macro must have been uploaded already.
28 ASSERT_MSG(uploaded_macros.find(method) != uploaded_macros.end(), "Macro %08X was not uploaded",
29 method);
30
19 auto itr = method_handlers.find(method); 31 auto itr = method_handlers.find(method);
20 if (itr == method_handlers.end()) { 32 ASSERT_MSG(itr != method_handlers.end(), "Unhandled method call %08X", method);
21 LOG_ERROR(HW_GPU, "Unhandled method call %08X", method);
22 return;
23 }
24 33
25 ASSERT(itr->second.arguments == parameters.size()); 34 ASSERT(itr->second.arguments == parameters.size());
35
26 (this->*itr->second.handler)(parameters); 36 (this->*itr->second.handler)(parameters);
37
38 // Reset the current macro and its parameters.
39 executing_macro = 0;
40 macro_params.clear();
27} 41}
28 42
29void Maxwell3D::WriteReg(u32 method, u32 value) { 43void Maxwell3D::WriteReg(u32 method, u32 value, u32 remaining_params) {
30 ASSERT_MSG(method < Regs::NUM_REGS, 44 ASSERT_MSG(method < Regs::NUM_REGS,
31 "Invalid Maxwell3D register, increase the size of the Regs structure"); 45 "Invalid Maxwell3D register, increase the size of the Regs structure");
32 46
47 // It is an error to write to a register other than the current macro's ARG register before it
48 // has finished execution.
49 if (executing_macro != 0) {
50 ASSERT(method == executing_macro + 1);
51 }
52
53 // Methods after 0xE00 are special, they're actually triggers for some microcode that was
54 // uploaded to the GPU during initialization.
55 if (method >= MacroRegistersStart) {
56 // We're trying to execute a macro
57 if (executing_macro == 0) {
58 // A macro call must begin by writing the macro method's register, not its argument.
59 ASSERT_MSG((method % 2) == 0,
60 "Can't start macro execution by writing to the ARGS register");
61 executing_macro = method;
62 }
63
64 macro_params.push_back(value);
65
66 // Call the macro when there are no more parameters in the command buffer
67 if (remaining_params == 0) {
68 CallMacroMethod(executing_macro, macro_params);
69 }
70 return;
71 }
72
33 regs.reg_array[method] = value; 73 regs.reg_array[method] = value;
34 74
35#define MAXWELL3D_REG_INDEX(field_name) (offsetof(Regs, field_name) / sizeof(u32)) 75#define MAXWELL3D_REG_INDEX(field_name) (offsetof(Regs, field_name) / sizeof(u32))
diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h
index 98137f94b..05820a21e 100644
--- a/src/video_core/engines/maxwell_3d.h
+++ b/src/video_core/engines/maxwell_3d.h
@@ -21,14 +21,10 @@ public:
21 ~Maxwell3D() = default; 21 ~Maxwell3D() = default;
22 22
23 /// Write the value to the register identified by method. 23 /// Write the value to the register identified by method.
24 void WriteReg(u32 method, u32 value); 24 void WriteReg(u32 method, u32 value, u32 remaining_params);
25 25
26 /** 26 /// Uploads the code for a GPU macro program associated with the specified entry.
27 * Handles a method call to this engine. 27 void SubmitMacroCode(u32 entry, std::vector<u32> code);
28 * @param method Method to call
29 * @param parameters Arguments to the method call
30 */
31 void CallMethod(u32 method, const std::vector<u32>& parameters);
32 28
33 /// Register structure of the Maxwell3D engine. 29 /// Register structure of the Maxwell3D engine.
34 /// TODO(Subv): This structure will need to be made bigger as more registers are discovered. 30 /// TODO(Subv): This structure will need to be made bigger as more registers are discovered.
@@ -166,7 +162,11 @@ public:
166 INSERT_PADDING_WORDS(7); 162 INSERT_PADDING_WORDS(7);
167 } cb_bind[MaxShaderStage]; 163 } cb_bind[MaxShaderStage];
168 164
169 INSERT_PADDING_WORDS(0x50A); 165 INSERT_PADDING_WORDS(0x56);
166
167 u32 tex_cb_index;
168
169 INSERT_PADDING_WORDS(0x4B3);
170 }; 170 };
171 std::array<u32, NUM_REGS> reg_array; 171 std::array<u32, NUM_REGS> reg_array;
172 }; 172 };
@@ -201,6 +201,20 @@ public:
201private: 201private:
202 MemoryManager& memory_manager; 202 MemoryManager& memory_manager;
203 203
204 std::unordered_map<u32, std::vector<u32>> uploaded_macros;
205
206 /// Macro method that is currently being executed / being fed parameters.
207 u32 executing_macro = 0;
208 /// Parameters that have been submitted to the macro call so far.
209 std::vector<u32> macro_params;
210
211 /**
212 * Call a macro on this engine.
213 * @param method Method to call
214 * @param parameters Arguments to the method call
215 */
216 void CallMacroMethod(u32 method, const std::vector<u32>& parameters);
217
204 /// Handles a write to the QUERY_GET register. 218 /// Handles a write to the QUERY_GET register.
205 void ProcessQueryGet(); 219 void ProcessQueryGet();
206 220
@@ -234,6 +248,7 @@ ASSERT_REG_POSITION(vertex_array_limit[0], 0x7C0);
234ASSERT_REG_POSITION(shader_config[0], 0x800); 248ASSERT_REG_POSITION(shader_config[0], 0x800);
235ASSERT_REG_POSITION(const_buffer, 0x8E0); 249ASSERT_REG_POSITION(const_buffer, 0x8E0);
236ASSERT_REG_POSITION(cb_bind[0], 0x904); 250ASSERT_REG_POSITION(cb_bind[0], 0x904);
251ASSERT_REG_POSITION(tex_cb_index, 0x982);
237 252
238#undef ASSERT_REG_POSITION 253#undef ASSERT_REG_POSITION
239 254
diff --git a/src/video_core/engines/maxwell_compute.cpp b/src/video_core/engines/maxwell_compute.cpp
index 3bef7fe86..e4e5f9e5e 100644
--- a/src/video_core/engines/maxwell_compute.cpp
+++ b/src/video_core/engines/maxwell_compute.cpp
@@ -8,7 +8,6 @@ namespace Tegra {
8namespace Engines { 8namespace Engines {
9 9
10void MaxwellCompute::WriteReg(u32 method, u32 value) {} 10void MaxwellCompute::WriteReg(u32 method, u32 value) {}
11void MaxwellCompute::CallMethod(u32 method, const std::vector<u32>& parameters) {}
12 11
13} // namespace Engines 12} // namespace Engines
14} // namespace Tegra 13} // namespace Tegra
diff --git a/src/video_core/engines/maxwell_compute.h b/src/video_core/engines/maxwell_compute.h
index 5fc7ed635..7262e1bcb 100644
--- a/src/video_core/engines/maxwell_compute.h
+++ b/src/video_core/engines/maxwell_compute.h
@@ -4,7 +4,6 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <vector>
8#include "common/common_types.h" 7#include "common/common_types.h"
9 8
10namespace Tegra { 9namespace Tegra {
@@ -17,13 +16,6 @@ public:
17 16
18 /// Write the value to the register identified by method. 17 /// Write the value to the register identified by method.
19 void WriteReg(u32 method, u32 value); 18 void WriteReg(u32 method, u32 value);
20
21 /**
22 * Handles a method call to this engine.
23 * @param method Method to call
24 * @param parameters Arguments to the method call
25 */
26 void CallMethod(u32 method, const std::vector<u32>& parameters);
27}; 19};
28 20
29} // namespace Engines 21} // namespace Engines
diff --git a/src/video_core/gpu.h b/src/video_core/gpu.h
index c5ec6fdef..d2e4ff52d 100644
--- a/src/video_core/gpu.h
+++ b/src/video_core/gpu.h
@@ -6,6 +6,7 @@
6 6
7#include <memory> 7#include <memory>
8#include <unordered_map> 8#include <unordered_map>
9#include <vector>
9#include "common/common_types.h" 10#include "common/common_types.h"
10#include "video_core/engines/fermi_2d.h" 11#include "video_core/engines/fermi_2d.h"
11#include "video_core/engines/maxwell_3d.h" 12#include "video_core/engines/maxwell_3d.h"
@@ -38,11 +39,10 @@ public:
38 std::unique_ptr<MemoryManager> memory_manager; 39 std::unique_ptr<MemoryManager> memory_manager;
39 40
40private: 41private:
41 /// Writes a single register in the engine bound to the specified subchannel 42 static constexpr u32 InvalidGraphMacroEntry = 0xFFFFFFFF;
42 void WriteReg(u32 method, u32 subchannel, u32 value);
43 43
44 /// Calls a method in the engine bound to the specified subchannel with the input parameters. 44 /// Writes a single register in the engine bound to the specified subchannel
45 void CallMethod(u32 method, u32 subchannel, const std::vector<u32>& parameters); 45 void WriteReg(u32 method, u32 subchannel, u32 value, u32 remaining_params);
46 46
47 /// Mapping of command subchannels to their bound engine ids. 47 /// Mapping of command subchannels to their bound engine ids.
48 std::unordered_map<u32, EngineID> bound_engines; 48 std::unordered_map<u32, EngineID> bound_engines;
@@ -53,6 +53,11 @@ private:
53 std::unique_ptr<Engines::Fermi2D> fermi_2d; 53 std::unique_ptr<Engines::Fermi2D> fermi_2d;
54 /// Compute engine 54 /// Compute engine
55 std::unique_ptr<Engines::MaxwellCompute> maxwell_compute; 55 std::unique_ptr<Engines::MaxwellCompute> maxwell_compute;
56
57 /// Entry of the macro that is currently being uploaded
58 u32 current_macro_entry = InvalidGraphMacroEntry;
59 /// Code being uploaded for the current macro
60 std::vector<u32> current_macro_code;
56}; 61};
57 62
58} // namespace Tegra 63} // namespace Tegra