summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/core/hle/service/gsp.cpp84
-rw-r--r--src/core/hle/service/gsp.h46
2 files changed, 69 insertions, 61 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}
diff --git a/src/core/hle/service/gsp.h b/src/core/hle/service/gsp.h
index 66b99e94a..fccebef7e 100644
--- a/src/core/hle/service/gsp.h
+++ b/src/core/hle/service/gsp.h
@@ -41,8 +41,8 @@ enum class CommandId : u32 {
41 SET_COMMAND_LIST_FIRST = 0x05, 41 SET_COMMAND_LIST_FIRST = 0x05,
42}; 42};
43 43
44/// GSP thread interrupt queue header 44/// GSP thread interrupt relay queue
45struct InterruptQueue { 45struct InterruptRelayQueue {
46 union { 46 union {
47 u32 hex; 47 u32 hex;
48 48
@@ -61,23 +61,8 @@ struct InterruptQueue {
61 61
62 InterruptId slot[0x34]; ///< Interrupt ID slots 62 InterruptId slot[0x34]; ///< Interrupt ID slots
63}; 63};
64static_assert(sizeof(InterruptQueue) == 0x40, "InterruptQueue struct has incorrect size"); 64static_assert(sizeof(InterruptRelayQueue) == 0x40,
65 65 "InterruptRelayQueue struct has incorrect size");
66/// GSP shared memory GX command buffer header
67union CmdBufferHeader {
68 u32 hex;
69
70 // Current command index. This index is updated by GSP module after loading the command data,
71 // right before the command is processed. When this index is updated by GSP module, the total
72 // commands field is decreased by one as well.
73 BitField<0,8,u32> index;
74
75 // Total commands to process, must not be value 0 when GSP module handles commands. This must be
76 // <=15 when writing a command to shared memory. This is incremented by the application when
77 // writing a command to shared memory, after increasing this value TriggerCmdReqQueue is only
78 // used if this field is value 1.
79 BitField<8,8,u32> number_commands;
80};
81 66
82/// GSP command 67/// GSP command
83struct Command { 68struct Command {
@@ -117,6 +102,29 @@ struct Command {
117}; 102};
118static_assert(sizeof(Command) == 0x20, "Command struct has incorrect size"); 103static_assert(sizeof(Command) == 0x20, "Command struct has incorrect size");
119 104
105/// GSP shared memory GX command buffer header
106struct CommandBuffer {
107 union {
108 u32 hex;
109
110 // Current command index. This index is updated by GSP module after loading the command
111 // data, right before the command is processed. When this index is updated by GSP module,
112 // the total commands field is decreased by one as well.
113 BitField<0,8,u32> index;
114
115 // Total commands to process, must not be value 0 when GSP module handles commands. This
116 // must be <=15 when writing a command to shared memory. This is incremented by the
117 // application when writing a command to shared memory, after increasing this value
118 // TriggerCmdReqQueue is only used if this field is value 1.
119 BitField<8,8,u32> number_commands;
120 };
121
122 u32 unk[7];
123
124 Command commands[0xF];
125};
126static_assert(sizeof(CommandBuffer) == 0x200, "CommandBuffer struct has incorrect size");
127
120/// Interface to "srv:" service 128/// Interface to "srv:" service
121class Interface : public Service::Interface { 129class Interface : public Service::Interface {
122public: 130public: