diff options
| author | 2014-07-22 19:20:57 -0400 | |
|---|---|---|
| committer | 2014-07-22 19:20:57 -0400 | |
| commit | daa924b906ff3a6f54d00c5d19874c2f839af0a3 (patch) | |
| tree | 127b4998ece87140690b7e74853215522d57ecaa /src/core/hle | |
| parent | Merge pull request #32 from yuriks/master (diff) | |
| parent | Use uniform formatting when printing hexadecimal numbers. (diff) | |
| download | yuzu-daa924b906ff3a6f54d00c5d19874c2f839af0a3.tar.gz yuzu-daa924b906ff3a6f54d00c5d19874c2f839af0a3.tar.xz yuzu-daa924b906ff3a6f54d00c5d19874c2f839af0a3.zip | |
Merge pull request #31 from neobrain/gpu_framebuffer
GPU framebuffer emulation improvements
Diffstat (limited to 'src/core/hle')
| -rw-r--r-- | src/core/hle/config_mem.h | 6 | ||||
| -rw-r--r-- | src/core/hle/service/gsp.cpp | 143 | ||||
| -rw-r--r-- | src/core/hle/service/gsp.h | 60 |
3 files changed, 153 insertions, 56 deletions
diff --git a/src/core/hle/config_mem.h b/src/core/hle/config_mem.h index da396a3e6..fa01b5cdb 100644 --- a/src/core/hle/config_mem.h +++ b/src/core/hle/config_mem.h | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | 1 | // Copyright 2014 Citra Emulator Project |
| 2 | // Licensed under GPLv2 | 2 | // Licensed under GPLv2 |
| 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 | 6 | ||
| 7 | // Configuration memory stores various hardware/kernel configuration settings. This memory page is | 7 | // Configuration memory stores various hardware/kernel configuration settings. This memory page is |
| 8 | // read-only for ARM11 processes. I'm guessing this would normally be written to by the firmware/ | 8 | // read-only for ARM11 processes. I'm guessing this would normally be written to by the firmware/ |
| 9 | // bootrom. Because we're not emulating this, and essentially just "stubbing" the functionality, I'm | 9 | // bootrom. Because we're not emulating this, and essentially just "stubbing" the functionality, I'm |
| 10 | // putting this as a subset of HLE for now. | 10 | // putting this as a subset of HLE for now. |
| @@ -16,6 +16,6 @@ | |||
| 16 | namespace ConfigMem { | 16 | namespace ConfigMem { |
| 17 | 17 | ||
| 18 | template <typename T> | 18 | template <typename T> |
| 19 | inline void Read(T &var, const u32 addr); | 19 | void Read(T &var, const u32 addr); |
| 20 | 20 | ||
| 21 | } // namespace | 21 | } // namespace |
diff --git a/src/core/hle/service/gsp.cpp b/src/core/hle/service/gsp.cpp index 1fdbdf342..b20203e27 100644 --- a/src/core/hle/service/gsp.cpp +++ b/src/core/hle/service/gsp.cpp | |||
| @@ -47,11 +47,6 @@ Handle g_shared_memory = 0; | |||
| 47 | 47 | ||
| 48 | u32 g_thread_id = 0; | 48 | u32 g_thread_id = 0; |
| 49 | 49 | ||
| 50 | enum { | ||
| 51 | REG_FRAMEBUFFER_1 = 0x00400468, | ||
| 52 | REG_FRAMEBUFFER_2 = 0x00400494, | ||
| 53 | }; | ||
| 54 | |||
| 55 | /// Gets a pointer to the start (header) of a command buffer in GSP shared memory | 50 | /// Gets a pointer to the start (header) of a command buffer in GSP shared memory |
| 56 | static inline u8* GX_GetCmdBufferPointer(u32 thread_id, u32 offset=0) { | 51 | static inline u8* GX_GetCmdBufferPointer(u32 thread_id, u32 offset=0) { |
| 57 | return Kernel::GetSharedMemoryPointer(g_shared_memory, 0x800 + (thread_id * 0x200) + offset); | 52 | return Kernel::GetSharedMemoryPointer(g_shared_memory, 0x800 + (thread_id * 0x200) + offset); |
| @@ -67,38 +62,62 @@ void GX_FinishCommand(u32 thread_id) { | |||
| 67 | // TODO: Increment header->index? | 62 | // TODO: Increment header->index? |
| 68 | } | 63 | } |
| 69 | 64 | ||
| 65 | /// Write a GSP GPU hardware register | ||
| 66 | void WriteHWRegs(Service::Interface* self) { | ||
| 67 | u32* cmd_buff = Service::GetCommandBuffer(); | ||
| 68 | u32 reg_addr = cmd_buff[1]; | ||
| 69 | u32 size = cmd_buff[2]; | ||
| 70 | |||
| 71 | // TODO: Return proper error codes | ||
| 72 | if (reg_addr + size >= 0x420000) { | ||
| 73 | ERROR_LOG(GPU, "Write address out of range! (address=0x%08x, size=0x%08x)", reg_addr, size); | ||
| 74 | return; | ||
| 75 | } | ||
| 76 | |||
| 77 | // size should be word-aligned | ||
| 78 | if ((size % 4) != 0) { | ||
| 79 | ERROR_LOG(GPU, "Invalid size 0x%08x", size); | ||
| 80 | return; | ||
| 81 | } | ||
| 82 | |||
| 83 | u32* src = (u32*)Memory::GetPointer(cmd_buff[0x4]); | ||
| 84 | |||
| 85 | while (size > 0) { | ||
| 86 | GPU::Write<u32>(reg_addr + 0x1EB00000, *src); | ||
| 87 | |||
| 88 | size -= 4; | ||
| 89 | ++src; | ||
| 90 | reg_addr += 4; | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 70 | /// Read a GSP GPU hardware register | 94 | /// Read a GSP GPU hardware register |
| 71 | void ReadHWRegs(Service::Interface* self) { | 95 | void ReadHWRegs(Service::Interface* self) { |
| 72 | static const u32 framebuffer_1[] = {GPU::PADDR_VRAM_TOP_LEFT_FRAME1, GPU::PADDR_VRAM_TOP_RIGHT_FRAME1}; | ||
| 73 | static const u32 framebuffer_2[] = {GPU::PADDR_VRAM_TOP_LEFT_FRAME2, GPU::PADDR_VRAM_TOP_RIGHT_FRAME2}; | ||
| 74 | |||
| 75 | u32* cmd_buff = Service::GetCommandBuffer(); | 96 | u32* cmd_buff = Service::GetCommandBuffer(); |
| 76 | u32 reg_addr = cmd_buff[1]; | 97 | u32 reg_addr = cmd_buff[1]; |
| 77 | u32 size = cmd_buff[2]; | 98 | u32 size = cmd_buff[2]; |
| 78 | u32* dst = (u32*)Memory::GetPointer(cmd_buff[0x41]); | ||
| 79 | 99 | ||
| 80 | switch (reg_addr) { | 100 | // TODO: Return proper error codes |
| 101 | if (reg_addr + size >= 0x420000) { | ||
| 102 | ERROR_LOG(GPU, "Read address out of range! (address=0x%08x, size=0x%08x)", reg_addr, size); | ||
| 103 | return; | ||
| 104 | } | ||
| 81 | 105 | ||
| 82 | // NOTE: Calling SetFramebufferLocation here is a hack... Not sure the correct way yet to set | 106 | // size should be word-aligned |
| 83 | // whether the framebuffers should be in VRAM or GSP heap, but from what I understand, if the | 107 | if ((size % 4) != 0) { |
| 84 | // user application is reading from either of these registers, then its going to be in VRAM. | 108 | ERROR_LOG(GPU, "Invalid size 0x%08x", size); |
| 109 | return; | ||
| 110 | } | ||
| 85 | 111 | ||
| 86 | // Top framebuffer 1 addresses | 112 | u32* dst = (u32*)Memory::GetPointer(cmd_buff[0x41]); |
| 87 | case REG_FRAMEBUFFER_1: | ||
| 88 | GPU::SetFramebufferLocation(GPU::FRAMEBUFFER_LOCATION_VRAM); | ||
| 89 | memcpy(dst, framebuffer_1, size); | ||
| 90 | break; | ||
| 91 | 113 | ||
| 92 | // Top framebuffer 2 addresses | 114 | while (size > 0) { |
| 93 | case REG_FRAMEBUFFER_2: | 115 | GPU::Read<u32>(*dst, reg_addr + 0x1EB00000); |
| 94 | GPU::SetFramebufferLocation(GPU::FRAMEBUFFER_LOCATION_VRAM); | ||
| 95 | memcpy(dst, framebuffer_2, size); | ||
| 96 | break; | ||
| 97 | 116 | ||
| 98 | default: | 117 | size -= 4; |
| 99 | ERROR_LOG(GSP, "unknown register read at address %08X", reg_addr); | 118 | ++dst; |
| 119 | reg_addr += 4; | ||
| 100 | } | 120 | } |
| 101 | |||
| 102 | } | 121 | } |
| 103 | 122 | ||
| 104 | /** | 123 | /** |
| @@ -120,8 +139,8 @@ void RegisterInterruptRelayQueue(Service::Interface* self) { | |||
| 120 | 139 | ||
| 121 | Kernel::SetEventLocked(g_event, false); | 140 | Kernel::SetEventLocked(g_event, false); |
| 122 | 141 | ||
| 123 | // Hack - This function will permanently set the state of the GSP event such that GPU command | 142 | // Hack - This function will permanently set the state of the GSP event such that GPU command |
| 124 | // synchronization barriers always passthrough. Correct solution would be to set this after the | 143 | // synchronization barriers always passthrough. Correct solution would be to set this after the |
| 125 | // GPU as processed all queued up commands, but due to the emulator being single-threaded they | 144 | // GPU as processed all queued up commands, but due to the emulator being single-threaded they |
| 126 | // will always be ready. | 145 | // will always be ready. |
| 127 | Kernel::SetPermanentLock(g_event, true); | 146 | Kernel::SetPermanentLock(g_event, true); |
| @@ -134,52 +153,92 @@ void RegisterInterruptRelayQueue(Service::Interface* self) { | |||
| 134 | 153 | ||
| 135 | /// This triggers handling of the GX command written to the command buffer in shared memory. | 154 | /// This triggers handling of the GX command written to the command buffer in shared memory. |
| 136 | void TriggerCmdReqQueue(Service::Interface* self) { | 155 | void TriggerCmdReqQueue(Service::Interface* self) { |
| 156 | |||
| 157 | // Utility function to convert register ID to address | ||
| 158 | auto WriteGPURegister = [](u32 id, u32 data) { | ||
| 159 | GPU::Write<u32>(0x1EF00000 + 4 * id, data); | ||
| 160 | }; | ||
| 161 | |||
| 137 | GX_CmdBufferHeader* header = (GX_CmdBufferHeader*)GX_GetCmdBufferPointer(g_thread_id); | 162 | GX_CmdBufferHeader* header = (GX_CmdBufferHeader*)GX_GetCmdBufferPointer(g_thread_id); |
| 138 | u32* cmd_buff = (u32*)GX_GetCmdBufferPointer(g_thread_id, 0x20 + (header->index * 0x20)); | 163 | auto& command = *(const GXCommand*)GX_GetCmdBufferPointer(g_thread_id, 0x20 + (header->index * 0x20)); |
| 139 | 164 | ||
| 140 | switch (static_cast<GXCommandId>(cmd_buff[0])) { | 165 | switch (command.id) { |
| 141 | 166 | ||
| 142 | // GX request DMA - typically used for copying memory from GSP heap to VRAM | 167 | // GX request DMA - typically used for copying memory from GSP heap to VRAM |
| 143 | case GXCommandId::REQUEST_DMA: | 168 | case GXCommandId::REQUEST_DMA: |
| 144 | memcpy(Memory::GetPointer(cmd_buff[2]), Memory::GetPointer(cmd_buff[1]), cmd_buff[3]); | 169 | memcpy(Memory::GetPointer(command.dma_request.dest_address), |
| 170 | Memory::GetPointer(command.dma_request.source_address), | ||
| 171 | command.dma_request.size); | ||
| 145 | break; | 172 | break; |
| 146 | 173 | ||
| 174 | // ctrulib homebrew sends all relevant command list data with this command, | ||
| 175 | // hence we do all "interesting" stuff here and do nothing in SET_COMMAND_LIST_FIRST. | ||
| 176 | // TODO: This will need some rework in the future. | ||
| 147 | case GXCommandId::SET_COMMAND_LIST_LAST: | 177 | case GXCommandId::SET_COMMAND_LIST_LAST: |
| 148 | GPU::Write<u32>(GPU::Registers::CommandListAddress, cmd_buff[1] >> 3); | 178 | { |
| 149 | GPU::Write<u32>(GPU::Registers::CommandListSize, cmd_buff[2] >> 3); | 179 | auto& params = command.set_command_list_last; |
| 150 | GPU::Write<u32>(GPU::Registers::ProcessCommandList, 1); // TODO: Not sure if we are supposed to always write this | 180 | WriteGPURegister(GPU::Regs::CommandProcessor + 2, params.address >> 3); |
| 181 | WriteGPURegister(GPU::Regs::CommandProcessor, params.size >> 3); | ||
| 182 | WriteGPURegister(GPU::Regs::CommandProcessor + 4, 1); // TODO: Not sure if we are supposed to always write this .. seems to trigger processing though | ||
| 151 | 183 | ||
| 152 | // TODO: Move this to GPU | 184 | // TODO: Move this to GPU |
| 153 | // TODO: Not sure what units the size is measured in | 185 | // TODO: Not sure what units the size is measured in |
| 154 | g_debugger.CommandListCalled(cmd_buff[1], (u32*)Memory::GetPointer(cmd_buff[1]), cmd_buff[2]); | 186 | g_debugger.CommandListCalled(params.address, |
| 187 | (u32*)Memory::GetPointer(params.address), | ||
| 188 | params.size); | ||
| 155 | break; | 189 | break; |
| 190 | } | ||
| 156 | 191 | ||
| 192 | // It's assumed that the two "blocks" behave equivalently. | ||
| 193 | // Presumably this is done simply to allow two memory fills to run in parallel. | ||
| 157 | case GXCommandId::SET_MEMORY_FILL: | 194 | case GXCommandId::SET_MEMORY_FILL: |
| 195 | { | ||
| 196 | auto& params = command.memory_fill; | ||
| 197 | WriteGPURegister(GPU::Regs::MemoryFill, params.start1 >> 3); | ||
| 198 | WriteGPURegister(GPU::Regs::MemoryFill + 1, params.end1 >> 3); | ||
| 199 | WriteGPURegister(GPU::Regs::MemoryFill + 2, params.end1 - params.start1); | ||
| 200 | WriteGPURegister(GPU::Regs::MemoryFill + 3, params.value1); | ||
| 201 | |||
| 202 | WriteGPURegister(GPU::Regs::MemoryFill + 4, params.start2 >> 3); | ||
| 203 | WriteGPURegister(GPU::Regs::MemoryFill + 5, params.end2 >> 3); | ||
| 204 | WriteGPURegister(GPU::Regs::MemoryFill + 6, params.end2 - params.start2); | ||
| 205 | WriteGPURegister(GPU::Regs::MemoryFill + 7, params.value2); | ||
| 158 | break; | 206 | break; |
| 207 | } | ||
| 159 | 208 | ||
| 209 | // TODO: Check if texture copies are implemented correctly.. | ||
| 160 | case GXCommandId::SET_DISPLAY_TRANSFER: | 210 | case GXCommandId::SET_DISPLAY_TRANSFER: |
| 161 | break; | ||
| 162 | |||
| 163 | case GXCommandId::SET_TEXTURE_COPY: | 211 | case GXCommandId::SET_TEXTURE_COPY: |
| 212 | { | ||
| 213 | auto& params = command.image_copy; | ||
| 214 | WriteGPURegister(GPU::Regs::DisplayTransfer, params.in_buffer_address >> 3); | ||
| 215 | WriteGPURegister(GPU::Regs::DisplayTransfer + 1, params.out_buffer_address >> 3); | ||
| 216 | WriteGPURegister(GPU::Regs::DisplayTransfer + 3, params.in_buffer_size); | ||
| 217 | WriteGPURegister(GPU::Regs::DisplayTransfer + 2, params.out_buffer_size); | ||
| 218 | WriteGPURegister(GPU::Regs::DisplayTransfer + 4, params.flags); | ||
| 219 | |||
| 220 | // TODO: Should this only be ORed with 1 for texture copies? | ||
| 221 | // trigger transfer | ||
| 222 | WriteGPURegister(GPU::Regs::DisplayTransfer + 6, 1); | ||
| 164 | break; | 223 | break; |
| 224 | } | ||
| 165 | 225 | ||
| 226 | // TODO: Figure out what exactly SET_COMMAND_LIST_FIRST and SET_COMMAND_LIST_LAST | ||
| 227 | // are supposed to do. | ||
| 166 | case GXCommandId::SET_COMMAND_LIST_FIRST: | 228 | case GXCommandId::SET_COMMAND_LIST_FIRST: |
| 167 | { | 229 | { |
| 168 | //u32* buf0_data = (u32*)Memory::GetPointer(cmd_buff[1]); | ||
| 169 | //u32* buf1_data = (u32*)Memory::GetPointer(cmd_buff[3]); | ||
| 170 | //u32* buf2_data = (u32*)Memory::GetPointer(cmd_buff[5]); | ||
| 171 | break; | 230 | break; |
| 172 | } | 231 | } |
| 173 | 232 | ||
| 174 | default: | 233 | default: |
| 175 | ERROR_LOG(GSP, "unknown command 0x%08X", cmd_buff[0]); | 234 | ERROR_LOG(GSP, "unknown command 0x%08X", (int)command.id.Value()); |
| 176 | } | 235 | } |
| 177 | 236 | ||
| 178 | GX_FinishCommand(g_thread_id); | 237 | GX_FinishCommand(g_thread_id); |
| 179 | } | 238 | } |
| 180 | 239 | ||
| 181 | const Interface::FunctionInfo FunctionTable[] = { | 240 | const Interface::FunctionInfo FunctionTable[] = { |
| 182 | {0x00010082, nullptr, "WriteHWRegs"}, | 241 | {0x00010082, WriteHWRegs, "WriteHWRegs"}, |
| 183 | {0x00020084, nullptr, "WriteHWRegsWithMask"}, | 242 | {0x00020084, nullptr, "WriteHWRegsWithMask"}, |
| 184 | {0x00030082, nullptr, "WriteHWRegRepeat"}, | 243 | {0x00030082, nullptr, "WriteHWRegRepeat"}, |
| 185 | {0x00040080, ReadHWRegs, "ReadHWRegs"}, | 244 | {0x00040080, ReadHWRegs, "ReadHWRegs"}, |
diff --git a/src/core/hle/service/gsp.h b/src/core/hle/service/gsp.h index 214de140f..a83cb4846 100644 --- a/src/core/hle/service/gsp.h +++ b/src/core/hle/service/gsp.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "common/bit_field.h" | ||
| 7 | #include "core/hle/service/service.h" | 8 | #include "core/hle/service/service.h" |
| 8 | 9 | ||
| 9 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 10 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| @@ -12,21 +13,58 @@ | |||
| 12 | namespace GSP_GPU { | 13 | namespace GSP_GPU { |
| 13 | 14 | ||
| 14 | enum class GXCommandId : u32 { | 15 | enum class GXCommandId : u32 { |
| 15 | REQUEST_DMA = 0x00000000, | 16 | REQUEST_DMA = 0x00, |
| 16 | SET_COMMAND_LIST_LAST = 0x00000001, | 17 | SET_COMMAND_LIST_LAST = 0x01, |
| 17 | SET_MEMORY_FILL = 0x00000002, // TODO: Confirm? (lictru uses 0x01000102) | 18 | |
| 18 | SET_DISPLAY_TRANSFER = 0x00000003, | 19 | // Fills a given memory range with a particular value |
| 19 | SET_TEXTURE_COPY = 0x00000004, | 20 | SET_MEMORY_FILL = 0x02, |
| 20 | SET_COMMAND_LIST_FIRST = 0x00000005, | 21 | |
| 22 | // Copies an image and optionally performs color-conversion or scaling. | ||
| 23 | // This is highly similar to the GameCube's EFB copy feature | ||
| 24 | SET_DISPLAY_TRANSFER = 0x03, | ||
| 25 | |||
| 26 | // Conceptionally similar to SET_DISPLAY_TRANSFER and presumable uses the same hardware path | ||
| 27 | SET_TEXTURE_COPY = 0x04, | ||
| 28 | |||
| 29 | SET_COMMAND_LIST_FIRST = 0x05, | ||
| 21 | }; | 30 | }; |
| 22 | 31 | ||
| 23 | union GXCommand { | 32 | struct GXCommand { |
| 24 | struct { | 33 | BitField<0, 8, GXCommandId> id; |
| 25 | GXCommandId id; | ||
| 26 | }; | ||
| 27 | 34 | ||
| 28 | u32 data[0x20]; | 35 | union { |
| 36 | struct { | ||
| 37 | u32 source_address; | ||
| 38 | u32 dest_address; | ||
| 39 | u32 size; | ||
| 40 | } dma_request; | ||
| 41 | |||
| 42 | struct { | ||
| 43 | u32 address; | ||
| 44 | u32 size; | ||
| 45 | } set_command_list_last; | ||
| 46 | |||
| 47 | struct { | ||
| 48 | u32 start1; | ||
| 49 | u32 value1; | ||
| 50 | u32 end1; | ||
| 51 | u32 start2; | ||
| 52 | u32 value2; | ||
| 53 | u32 end2; | ||
| 54 | } memory_fill; | ||
| 55 | |||
| 56 | struct { | ||
| 57 | u32 in_buffer_address; | ||
| 58 | u32 out_buffer_address; | ||
| 59 | u32 in_buffer_size; | ||
| 60 | u32 out_buffer_size; | ||
| 61 | u32 flags; | ||
| 62 | } image_copy; | ||
| 63 | |||
| 64 | u8 raw_data[0x1C]; | ||
| 65 | }; | ||
| 29 | }; | 66 | }; |
| 67 | static_assert(sizeof(GXCommand) == 0x20, "GXCommand struct has incorrect size"); | ||
| 30 | 68 | ||
| 31 | /// Interface to "srv:" service | 69 | /// Interface to "srv:" service |
| 32 | class Interface : public Service::Interface { | 70 | class Interface : public Service::Interface { |