summaryrefslogtreecommitdiff
path: root/src/core/hle/service/gsp.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2014-07-23 00:10:37 -0400
committerGravatar bunnei2014-08-06 18:19:56 -0400
commitcad2f21985e2bfc7bed3dfa766bb3aa9ceba0d29 (patch)
tree62611042058172a517abfb1155601a844b564937 /src/core/hle/service/gsp.cpp
parentGSP: Added reinitialization of other state objects. (diff)
downloadyuzu-cad2f21985e2bfc7bed3dfa766bb3aa9ceba0d29.tar.gz
yuzu-cad2f21985e2bfc7bed3dfa766bb3aa9ceba0d29.tar.xz
yuzu-cad2f21985e2bfc7bed3dfa766bb3aa9ceba0d29.zip
GSP: Cleaned up command buffer decoding.
GSP: Cleaned up code and added additional comments. GSP: Removed unnecessary TODO comment. GSP: Changed u32 iterators in TriggerCmdReqQueue to unsigned.
Diffstat (limited to 'src/core/hle/service/gsp.cpp')
-rw-r--r--src/core/hle/service/gsp.cpp84
1 files changed, 42 insertions, 42 deletions
diff --git a/src/core/hle/service/gsp.cpp b/src/core/hle/service/gsp.cpp
index 1b74f4889..e241b31c8 100644
--- a/src/core/hle/service/gsp.cpp
+++ b/src/core/hle/service/gsp.cpp
@@ -23,21 +23,23 @@ GraphicsDebugger g_debugger;
23 23
24namespace GSP_GPU { 24namespace GSP_GPU {
25 25
26Handle g_event = 0; 26Handle g_interrupt_event = 0; ///< Handle to event triggered when GSP interrupt has been signalled
27Handle g_shared_memory = 0; 27Handle g_shared_memory = 0; ///< Handle to GSP shared memorys
28u32 g_thread_id = 1; ///< Thread index into interrupt relay queue, 1 is arbitrary
28 29
29u32 g_thread_id = 1; 30/// Gets a pointer to a thread command buffer in GSP shared memory
31static inline u8* GetCommandBuffer(u32 thread_id) {
32 if (0 == g_shared_memory)
33 return nullptr;
30 34
31/// Gets a pointer to the start (header) of a command buffer in GSP shared memory 35 return Kernel::GetSharedMemoryPointer(g_shared_memory,
32static inline u8* GetCmdBufferPointer(u32 thread_id, u32 offset=0) { 36 0x800 + (thread_id * sizeof(CommandBuffer)));
33 if (0 == g_shared_memory) return nullptr;
34
35 return Kernel::GetSharedMemoryPointer(g_shared_memory, 0x800 + (thread_id * 0x200) + offset);
36} 37}
37 38
38/// Gets a pointer to the start (header) of a command buffer in GSP shared memory 39/// Gets a pointer to the interrupt relay queue for a given thread index
39static inline InterruptQueue* GetInterruptQueue(u32 thread_id) { 40static inline InterruptRelayQueue* GetInterruptRelayQueue(u32 thread_id) {
40 return (InterruptQueue*)Kernel::GetSharedMemoryPointer(g_shared_memory, sizeof(InterruptQueue) * thread_id); 41 return (InterruptRelayQueue*)Kernel::GetSharedMemoryPointer(g_shared_memory,
42 sizeof(InterruptRelayQueue) * thread_id);
41} 43}
42 44
43/// Write a GSP GPU hardware register 45/// Write a GSP GPU hardware register
@@ -111,15 +113,15 @@ void ReadHWRegs(Service::Interface* self) {
111void RegisterInterruptRelayQueue(Service::Interface* self) { 113void RegisterInterruptRelayQueue(Service::Interface* self) {
112 u32* cmd_buff = Service::GetCommandBuffer(); 114 u32* cmd_buff = Service::GetCommandBuffer();
113 u32 flags = cmd_buff[1]; 115 u32 flags = cmd_buff[1];
114 g_event = cmd_buff[3]; 116 g_interrupt_event = cmd_buff[3];
115 g_shared_memory = Kernel::CreateSharedMemory("GSPSharedMem"); 117 g_shared_memory = Kernel::CreateSharedMemory("GSPSharedMem");
116 118
117 _assert_msg_(GSP, (g_event != 0), "handle is not valid!"); 119 _assert_msg_(GSP, (g_interrupt_event != 0), "handle is not valid!");
118 120
119 cmd_buff[2] = g_thread_id++; // ThreadID 121 cmd_buff[2] = g_thread_id++; // ThreadID
120 cmd_buff[4] = g_shared_memory; // GSP shared memory 122 cmd_buff[4] = g_shared_memory; // GSP shared memory
121 123
122 Kernel::SignalEvent(GSP_GPU::g_event); // TODO(bunnei): Is this correct? 124 Kernel::SignalEvent(g_interrupt_event); // TODO(bunnei): Is this correct?
123} 125}
124 126
125/** 127/**
@@ -127,7 +129,7 @@ void RegisterInterruptRelayQueue(Service::Interface* self) {
127 * @param interrupt_id ID of interrupt that is being signalled 129 * @param interrupt_id ID of interrupt that is being signalled
128 */ 130 */
129void SignalInterrupt(InterruptId interrupt_id) { 131void SignalInterrupt(InterruptId interrupt_id) {
130 if (0 == GSP_GPU::g_event) { 132 if (0 == g_interrupt_event) {
131 WARN_LOG(GSP, "cannot synchronize until GSP event has been created!"); 133 WARN_LOG(GSP, "cannot synchronize until GSP event has been created!");
132 return; 134 return;
133 } 135 }
@@ -136,34 +138,26 @@ void SignalInterrupt(InterruptId interrupt_id) {
136 return; 138 return;
137 } 139 }
138 for (int thread_id = 0; thread_id < 0x4; ++thread_id) { 140 for (int thread_id = 0; thread_id < 0x4; ++thread_id) {
139 InterruptQueue* interrupt_queue = GetInterruptQueue(thread_id); 141 InterruptRelayQueue* interrupt_relay_queue = GetInterruptRelayQueue(thread_id);
140 interrupt_queue->number_interrupts = interrupt_queue->number_interrupts + 1; 142 interrupt_relay_queue->number_interrupts = interrupt_relay_queue->number_interrupts + 1;
141 143
142 u8 next = interrupt_queue->index; 144 u8 next = interrupt_relay_queue->index;
143 next += interrupt_queue->number_interrupts; 145 next += interrupt_relay_queue->number_interrupts;
144 next = next % 0x34; 146 next = next % 0x34; // 0x34 is the number of interrupt slots
145 147
146 interrupt_queue->slot[next] = interrupt_id; 148 interrupt_relay_queue->slot[next] = interrupt_id;
147 interrupt_queue->error_code = 0x0; // No error 149 interrupt_relay_queue->error_code = 0x0; // No error
148 } 150 }
149 Kernel::SignalEvent(GSP_GPU::g_event); 151 Kernel::SignalEvent(g_interrupt_event);
150} 152}
151 153
152/// Executes the next GSP command 154/// Executes the next GSP command
153void ExecuteCommand(u32 thread_id, u32 command_index) { 155void ExecuteCommand(const Command& command) {
154
155 // Utility function to convert register ID to address 156 // Utility function to convert register ID to address
156 auto WriteGPURegister = [](u32 id, u32 data) { 157 auto WriteGPURegister = [](u32 id, u32 data) {
157 GPU::Write<u32>(0x1EF00000 + 4 * id, data); 158 GPU::Write<u32>(0x1EF00000 + 4 * id, data);
158 }; 159 };
159 160
160 CmdBufferHeader* header = (CmdBufferHeader*)GetCmdBufferPointer(thread_id);
161 auto& command = *(const Command*)GetCmdBufferPointer(thread_id, (command_index + 1) * 0x20);
162
163 g_debugger.GXCommandProcessed(GetCmdBufferPointer(thread_id, 0x20 + (header->index * 0x20)));
164
165 NOTICE_LOG(GSP, "decoding command 0x%08X", (int)command.id.Value());
166
167 switch (command.id) { 161 switch (command.id) {
168 162
169 // GX request DMA - typically used for copying memory from GSP heap to VRAM 163 // GX request DMA - typically used for copying memory from GSP heap to VRAM
@@ -181,7 +175,9 @@ void ExecuteCommand(u32 thread_id, u32 command_index) {
181 auto& params = command.set_command_list_last; 175 auto& params = command.set_command_list_last;
182 WriteGPURegister(GPU::Regs::CommandProcessor + 2, params.address >> 3); 176 WriteGPURegister(GPU::Regs::CommandProcessor + 2, params.address >> 3);
183 WriteGPURegister(GPU::Regs::CommandProcessor, params.size >> 3); 177 WriteGPURegister(GPU::Regs::CommandProcessor, params.size >> 3);
184 WriteGPURegister(GPU::Regs::CommandProcessor + 4, 1); // TODO: Not sure if we are supposed to always write this .. seems to trigger processing though 178
179 // TODO: Not sure if we are supposed to always write this .. seems to trigger processing though
180 WriteGPURegister(GPU::Regs::CommandProcessor + 4, 1);
185 181
186 // TODO: Move this to GPU 182 // TODO: Move this to GPU
187 // TODO: Not sure what units the size is measured in 183 // TODO: Not sure what units the size is measured in
@@ -246,20 +242,24 @@ void ExecuteCommand(u32 thread_id, u32 command_index) {
246 default: 242 default:
247 ERROR_LOG(GSP, "unknown command 0x%08X", (int)command.id.Value()); 243 ERROR_LOG(GSP, "unknown command 0x%08X", (int)command.id.Value());
248 } 244 }
249
250 header->number_commands = header->number_commands - 1; // Indicates that command has completed
251} 245}
252 246
253/// This triggers handling of the GX command written to the command buffer in shared memory. 247/// This triggers handling of the GX command written to the command buffer in shared memory.
254void TriggerCmdReqQueue(Service::Interface* self) { 248void TriggerCmdReqQueue(Service::Interface* self) {
255 249
256 // Iterate through each thread's command queue... 250 // Iterate through each thread's command queue...
257 for (u32 thread_id = 0; thread_id < 0x4; ++thread_id) { 251 for (unsigned thread_id = 0; thread_id < 0x4; ++thread_id) {
258 CmdBufferHeader* header = (CmdBufferHeader*)GetCmdBufferPointer(thread_id); 252 CommandBuffer* command_buffer = (CommandBuffer*)GetCommandBuffer(thread_id);
259 253
260 // Iterate through each command... 254 // Iterate through each command...
261 for (u32 command_index = 0; command_index < header->number_commands; ++command_index) { 255 for (unsigned i = 0; i < command_buffer->number_commands; ++i) {
262 ExecuteCommand(thread_id, command_index); 256 g_debugger.GXCommandProcessed((u8*)&command_buffer->commands[i]);
257
258 // Decode and execute command
259 ExecuteCommand(command_buffer->commands[i]);
260
261 // Indicates that command has completed
262 command_buffer->number_commands = command_buffer->number_commands - 1;
263 } 263 }
264 } 264 }
265} 265}
@@ -303,7 +303,7 @@ const Interface::FunctionInfo FunctionTable[] = {
303Interface::Interface() { 303Interface::Interface() {
304 Register(FunctionTable, ARRAY_SIZE(FunctionTable)); 304 Register(FunctionTable, ARRAY_SIZE(FunctionTable));
305 305
306 g_event = 0; 306 g_interrupt_event = 0;
307 g_shared_memory = 0; 307 g_shared_memory = 0;
308 g_thread_id = 1; 308 g_thread_id = 1;
309} 309}