diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | src/core/hle/service/gsp_gpu.cpp | 2 | ||||
| -rw-r--r-- | src/core/hw/gpu.cpp | 17 | ||||
| -rw-r--r-- | src/core/hw/lcd.cpp | 10 | ||||
| -rw-r--r-- | src/core/tracer/recorder.cpp | 198 | ||||
| -rw-r--r-- | src/core/tracer/recorder.h | 92 | ||||
| -rw-r--r-- | src/core/tracer/tracer.h | 98 |
7 files changed, 419 insertions, 1 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 9b004440c..5066eb258 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -115,6 +115,7 @@ set(SRCS | |||
| 115 | loader/elf.cpp | 115 | loader/elf.cpp |
| 116 | loader/loader.cpp | 116 | loader/loader.cpp |
| 117 | loader/ncch.cpp | 117 | loader/ncch.cpp |
| 118 | tracer/recorder.cpp | ||
| 118 | mem_map.cpp | 119 | mem_map.cpp |
| 119 | memory.cpp | 120 | memory.cpp |
| 120 | settings.cpp | 121 | settings.cpp |
| @@ -243,6 +244,8 @@ set(HEADERS | |||
| 243 | loader/elf.h | 244 | loader/elf.h |
| 244 | loader/loader.h | 245 | loader/loader.h |
| 245 | loader/ncch.h | 246 | loader/ncch.h |
| 247 | tracer/recorder.h | ||
| 248 | tracer/tracer.h | ||
| 246 | mem_map.h | 249 | mem_map.h |
| 247 | memory.h | 250 | memory.h |
| 248 | memory_setup.h | 251 | memory_setup.h |
diff --git a/src/core/hle/service/gsp_gpu.cpp b/src/core/hle/service/gsp_gpu.cpp index f175085e8..3910d0227 100644 --- a/src/core/hle/service/gsp_gpu.cpp +++ b/src/core/hle/service/gsp_gpu.cpp | |||
| @@ -349,7 +349,7 @@ void SignalInterrupt(InterruptId interrupt_id) { | |||
| 349 | /// Executes the next GSP command | 349 | /// Executes the next GSP command |
| 350 | static void ExecuteCommand(const Command& command, u32 thread_id) { | 350 | static void ExecuteCommand(const Command& command, u32 thread_id) { |
| 351 | // Utility function to convert register ID to address | 351 | // Utility function to convert register ID to address |
| 352 | auto WriteGPURegister = [](u32 id, u32 data) { | 352 | static auto WriteGPURegister = [](u32 id, u32 data) { |
| 353 | GPU::Write<u32>(0x1EF00000 + 4 * id, data); | 353 | GPU::Write<u32>(0x1EF00000 + 4 * id, data); |
| 354 | }; | 354 | }; |
| 355 | 355 | ||
diff --git a/src/core/hw/gpu.cpp b/src/core/hw/gpu.cpp index 796493378..a3a7d128f 100644 --- a/src/core/hw/gpu.cpp +++ b/src/core/hw/gpu.cpp | |||
| @@ -21,12 +21,17 @@ | |||
| 21 | #include "core/hw/hw.h" | 21 | #include "core/hw/hw.h" |
| 22 | #include "core/hw/gpu.h" | 22 | #include "core/hw/gpu.h" |
| 23 | 23 | ||
| 24 | #include "core/tracer/recorder.h" | ||
| 25 | |||
| 24 | #include "video_core/command_processor.h" | 26 | #include "video_core/command_processor.h" |
| 25 | #include "video_core/hwrasterizer_base.h" | 27 | #include "video_core/hwrasterizer_base.h" |
| 26 | #include "video_core/renderer_base.h" | 28 | #include "video_core/renderer_base.h" |
| 27 | #include "video_core/utils.h" | 29 | #include "video_core/utils.h" |
| 28 | #include "video_core/video_core.h" | 30 | #include "video_core/video_core.h" |
| 29 | 31 | ||
| 32 | #include "video_core/debug_utils/debug_utils.h" | ||
| 33 | |||
| 34 | |||
| 30 | namespace GPU { | 35 | namespace GPU { |
| 31 | 36 | ||
| 32 | Regs g_regs; | 37 | Regs g_regs; |
| @@ -289,6 +294,11 @@ inline void Write(u32 addr, const T data) { | |||
| 289 | if (config.trigger & 1) | 294 | if (config.trigger & 1) |
| 290 | { | 295 | { |
| 291 | u32* buffer = (u32*)Memory::GetPhysicalPointer(config.GetPhysicalAddress()); | 296 | u32* buffer = (u32*)Memory::GetPhysicalPointer(config.GetPhysicalAddress()); |
| 297 | |||
| 298 | if (Pica::g_debug_context && Pica::g_debug_context->recorder) { | ||
| 299 | Pica::g_debug_context->recorder->MemoryAccessed((u8*)buffer, config.size * sizeof(u32), config.GetPhysicalAddress()); | ||
| 300 | } | ||
| 301 | |||
| 292 | Pica::CommandProcessor::ProcessCommandList(buffer, config.size); | 302 | Pica::CommandProcessor::ProcessCommandList(buffer, config.size); |
| 293 | 303 | ||
| 294 | g_regs.command_processor_config.trigger = 0; | 304 | g_regs.command_processor_config.trigger = 0; |
| @@ -299,6 +309,13 @@ inline void Write(u32 addr, const T data) { | |||
| 299 | default: | 309 | default: |
| 300 | break; | 310 | break; |
| 301 | } | 311 | } |
| 312 | |||
| 313 | // Notify tracer about the register write | ||
| 314 | // This is happening *after* handling the write to make sure we properly catch all memory reads. | ||
| 315 | if (Pica::g_debug_context && Pica::g_debug_context->recorder) { | ||
| 316 | // addr + GPU VBase - IO VBase + IO PBase | ||
| 317 | Pica::g_debug_context->recorder->RegisterWritten<T>(addr + 0x1EF00000 - 0x1EC00000 + 0x10100000, data); | ||
| 318 | } | ||
| 302 | } | 319 | } |
| 303 | 320 | ||
| 304 | // Explicitly instantiate template functions because we aren't defining this in the header: | 321 | // Explicitly instantiate template functions because we aren't defining this in the header: |
diff --git a/src/core/hw/lcd.cpp b/src/core/hw/lcd.cpp index cdb757a18..6f93709e3 100644 --- a/src/core/hw/lcd.cpp +++ b/src/core/hw/lcd.cpp | |||
| @@ -10,6 +10,9 @@ | |||
| 10 | #include "core/hw/hw.h" | 10 | #include "core/hw/hw.h" |
| 11 | #include "core/hw/lcd.h" | 11 | #include "core/hw/lcd.h" |
| 12 | 12 | ||
| 13 | #include "core/tracer/recorder.h" | ||
| 14 | #include "video_core/debug_utils/debug_utils.h" | ||
| 15 | |||
| 13 | namespace LCD { | 16 | namespace LCD { |
| 14 | 17 | ||
| 15 | Regs g_regs; | 18 | Regs g_regs; |
| @@ -40,6 +43,13 @@ inline void Write(u32 addr, const T data) { | |||
| 40 | } | 43 | } |
| 41 | 44 | ||
| 42 | g_regs[index] = static_cast<u32>(data); | 45 | g_regs[index] = static_cast<u32>(data); |
| 46 | |||
| 47 | // Notify tracer about the register write | ||
| 48 | // This is happening *after* handling the write to make sure we properly catch all memory reads. | ||
| 49 | if (Pica::g_debug_context && Pica::g_debug_context->recorder) { | ||
| 50 | // addr + GPU VBase - IO VBase + IO PBase | ||
| 51 | Pica::g_debug_context->recorder->RegisterWritten<T>(addr + HW::VADDR_LCD - 0x1EC00000 + 0x10100000, data); | ||
| 52 | } | ||
| 43 | } | 53 | } |
| 44 | 54 | ||
| 45 | // Explicitly instantiate template functions because we aren't defining this in the header: | 55 | // Explicitly instantiate template functions because we aren't defining this in the header: |
diff --git a/src/core/tracer/recorder.cpp b/src/core/tracer/recorder.cpp new file mode 100644 index 000000000..73ebdd388 --- /dev/null +++ b/src/core/tracer/recorder.cpp | |||
| @@ -0,0 +1,198 @@ | |||
| 1 | // Copyright 2015 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <cstring> | ||
| 6 | |||
| 7 | #include "common/assert.h" | ||
| 8 | #include "common/file_util.h" | ||
| 9 | #include "common/logging/log.h" | ||
| 10 | |||
| 11 | #include "recorder.h" | ||
| 12 | |||
| 13 | namespace CiTrace { | ||
| 14 | |||
| 15 | Recorder::Recorder(u32* gpu_registers, u32 gpu_registers_size, | ||
| 16 | u32* lcd_registers, u32 lcd_registers_size, | ||
| 17 | u32* pica_registers, u32 pica_registers_size, | ||
| 18 | u32* vs_program_binary, u32 vs_program_binary_size, | ||
| 19 | u32* vs_swizzle_data, u32 vs_swizzle_data_size, | ||
| 20 | u32* vs_float_uniforms, u32 vs_float_uniforms_size, | ||
| 21 | u32* gs_program_binary, u32 gs_program_binary_size, | ||
| 22 | u32* gs_swizzle_data, u32 gs_swizzle_data_size, | ||
| 23 | u32* gs_float_uniforms, u32 gs_float_uniforms_size) | ||
| 24 | : gpu_registers(gpu_registers, gpu_registers + gpu_registers_size), | ||
| 25 | lcd_registers(lcd_registers, lcd_registers + lcd_registers_size), | ||
| 26 | pica_registers(pica_registers, pica_registers + pica_registers_size), | ||
| 27 | vs_program_binary(vs_program_binary, vs_program_binary + vs_program_binary_size), | ||
| 28 | vs_swizzle_data(vs_swizzle_data, vs_swizzle_data + vs_swizzle_data_size), | ||
| 29 | vs_float_uniforms(vs_float_uniforms, vs_float_uniforms + vs_float_uniforms_size), | ||
| 30 | gs_program_binary(gs_program_binary, gs_program_binary + gs_program_binary_size), | ||
| 31 | gs_swizzle_data(gs_swizzle_data, gs_swizzle_data + gs_swizzle_data_size), | ||
| 32 | gs_float_uniforms(gs_float_uniforms, gs_float_uniforms + gs_float_uniforms_size) { | ||
| 33 | |||
| 34 | } | ||
| 35 | |||
| 36 | void Recorder::Finish(const std::string& filename) { | ||
| 37 | // Setup CiTrace header | ||
| 38 | CTHeader header; | ||
| 39 | std::memcpy(header.magic, CTHeader::ExpectedMagicWord(), 4); | ||
| 40 | header.version = CTHeader::ExpectedVersion(); | ||
| 41 | header.header_size = sizeof(CTHeader); | ||
| 42 | |||
| 43 | // Calculate file offsets | ||
| 44 | auto& initial = header.initial_state_offsets; | ||
| 45 | |||
| 46 | initial.gpu_registers_size = gpu_registers.size(); | ||
| 47 | initial.lcd_registers_size = lcd_registers.size(); | ||
| 48 | initial.pica_registers_size = pica_registers.size(); | ||
| 49 | initial.vs_program_binary_size = vs_program_binary.size(); | ||
| 50 | initial.vs_swizzle_data_size = vs_swizzle_data.size(); | ||
| 51 | initial.vs_float_uniforms_size = vs_float_uniforms.size(); | ||
| 52 | initial.gs_program_binary_size = gs_program_binary.size(); | ||
| 53 | initial.gs_swizzle_data_size = gs_swizzle_data.size(); | ||
| 54 | initial.gs_float_uniforms_size = gs_float_uniforms.size(); | ||
| 55 | header.stream_size = stream.size(); | ||
| 56 | |||
| 57 | initial.gpu_registers = sizeof(header); | ||
| 58 | initial.lcd_registers = initial.gpu_registers + initial.gpu_registers_size * sizeof(u32); | ||
| 59 | initial.pica_registers = initial.lcd_registers + initial.lcd_registers_size * sizeof(u32);; | ||
| 60 | initial.vs_program_binary = initial.pica_registers + initial.pica_registers_size * sizeof(u32); | ||
| 61 | initial.vs_swizzle_data = initial.vs_program_binary + initial.vs_program_binary_size * sizeof(u32); | ||
| 62 | initial.vs_float_uniforms = initial.vs_swizzle_data + initial.vs_swizzle_data_size * sizeof(u32); | ||
| 63 | initial.gs_program_binary = initial.vs_float_uniforms + initial.vs_float_uniforms_size * sizeof(u32); | ||
| 64 | initial.gs_swizzle_data = initial.gs_program_binary + initial.gs_program_binary_size * sizeof(u32); | ||
| 65 | initial.gs_float_uniforms = initial.gs_swizzle_data + initial.gs_swizzle_data_size * sizeof(u32); | ||
| 66 | header.stream_offset = initial.gs_float_uniforms + initial.gs_float_uniforms_size * sizeof(u32); | ||
| 67 | |||
| 68 | // Iterate through stream elements, update relevant stream element data | ||
| 69 | for (auto& stream_element : stream) { | ||
| 70 | switch (stream_element.data.type) { | ||
| 71 | case MemoryLoad: | ||
| 72 | { | ||
| 73 | auto& file_offset = memory_regions[stream_element.hash]; | ||
| 74 | if (!stream_element.uses_existing_data) { | ||
| 75 | file_offset = header.stream_offset; | ||
| 76 | } | ||
| 77 | stream_element.data.memory_load.file_offset = file_offset; | ||
| 78 | break; | ||
| 79 | } | ||
| 80 | |||
| 81 | default: | ||
| 82 | // Other commands don't use any extra data | ||
| 83 | DEBUG_ASSERT(stream_element.extra_data.size() == 0); | ||
| 84 | break; | ||
| 85 | } | ||
| 86 | header.stream_offset += stream_element.extra_data.size(); | ||
| 87 | } | ||
| 88 | |||
| 89 | try { | ||
| 90 | // Open file and write header | ||
| 91 | FileUtil::IOFile file(filename, "wb"); | ||
| 92 | size_t written = file.WriteObject(header); | ||
| 93 | if (written != 1 || file.Tell() != initial.gpu_registers) | ||
| 94 | throw "Failed to write header"; | ||
| 95 | |||
| 96 | // Write initial state | ||
| 97 | written = file.WriteArray(gpu_registers.data(), gpu_registers.size()); | ||
| 98 | if (written != gpu_registers.size() || file.Tell() != initial.lcd_registers) | ||
| 99 | throw "Failed to write GPU registers"; | ||
| 100 | |||
| 101 | written = file.WriteArray(lcd_registers.data(), lcd_registers.size()); | ||
| 102 | if (written != lcd_registers.size() || file.Tell() != initial.pica_registers) | ||
| 103 | throw "Failed to write LCD registers"; | ||
| 104 | |||
| 105 | written = file.WriteArray(pica_registers.data(), pica_registers.size()); | ||
| 106 | if (written != pica_registers.size() || file.Tell() != initial.vs_program_binary) | ||
| 107 | throw "Failed to write Pica registers"; | ||
| 108 | |||
| 109 | written = file.WriteArray(vs_program_binary.data(), vs_program_binary.size()); | ||
| 110 | if (written != vs_program_binary.size() || file.Tell() != initial.vs_swizzle_data) | ||
| 111 | throw "Failed to write vertex shader program binary"; | ||
| 112 | |||
| 113 | written = file.WriteArray(vs_swizzle_data.data(), vs_swizzle_data.size()); | ||
| 114 | if (written != vs_swizzle_data.size() || file.Tell() != initial.vs_float_uniforms) | ||
| 115 | throw "Failed to write vertex shader swizzle data"; | ||
| 116 | |||
| 117 | written = file.WriteArray(vs_float_uniforms.data(), vs_float_uniforms.size()); | ||
| 118 | if (written != vs_float_uniforms.size() || file.Tell() != initial.gs_program_binary) | ||
| 119 | throw "Failed to write vertex shader float uniforms"; | ||
| 120 | |||
| 121 | written = file.WriteArray(gs_program_binary.data(), gs_program_binary.size()); | ||
| 122 | if (written != gs_program_binary.size() || file.Tell() != initial.gs_swizzle_data) | ||
| 123 | throw "Failed to write geomtry shader program binary"; | ||
| 124 | |||
| 125 | written = file.WriteArray(gs_swizzle_data.data(), gs_swizzle_data.size()); | ||
| 126 | if (written != gs_swizzle_data.size() || file.Tell() != initial.gs_float_uniforms) | ||
| 127 | throw "Failed to write geometry shader swizzle data"; | ||
| 128 | |||
| 129 | written = file.WriteArray(gs_float_uniforms.data(), gs_float_uniforms.size()); | ||
| 130 | if (written != gs_float_uniforms.size() || file.Tell() != initial.gs_float_uniforms + sizeof(u32) * initial.gs_float_uniforms_size) | ||
| 131 | throw "Failed to write geometry shader float uniforms"; | ||
| 132 | |||
| 133 | // Iterate through stream elements, write "extra data" | ||
| 134 | for (const auto& stream_element : stream) { | ||
| 135 | if (stream_element.extra_data.size() == 0) | ||
| 136 | continue; | ||
| 137 | |||
| 138 | written = file.WriteBytes(stream_element.extra_data.data(), stream_element.extra_data.size()); | ||
| 139 | if (written != stream_element.extra_data.size()) | ||
| 140 | throw "Failed to write extra data"; | ||
| 141 | } | ||
| 142 | |||
| 143 | if (file.Tell() != header.stream_offset) | ||
| 144 | throw "Unexpected end of extra data"; | ||
| 145 | |||
| 146 | // Write actual stream elements | ||
| 147 | for (const auto& stream_element : stream) { | ||
| 148 | if (1 != file.WriteObject(stream_element.data)) | ||
| 149 | throw "Failed to write stream element"; | ||
| 150 | } | ||
| 151 | } catch(const char* str) { | ||
| 152 | LOG_ERROR(HW_GPU, "Writing CiTrace file failed: %s", str); | ||
| 153 | } | ||
| 154 | } | ||
| 155 | |||
| 156 | void Recorder::FrameFinished() { | ||
| 157 | stream.push_back( { FrameMarker } ); | ||
| 158 | } | ||
| 159 | |||
| 160 | void Recorder::MemoryAccessed(const u8* data, u32 size, u32 physical_address) { | ||
| 161 | StreamElement element = { MemoryLoad }; | ||
| 162 | element.data.memory_load.size = size; | ||
| 163 | element.data.memory_load.physical_address = physical_address; | ||
| 164 | |||
| 165 | // Compute hash over given memory region to check if the contents are already stored internally | ||
| 166 | boost::crc_32_type result; | ||
| 167 | result.process_bytes(data, size); | ||
| 168 | element.hash = result.checksum(); | ||
| 169 | |||
| 170 | element.uses_existing_data = (memory_regions.find(element.hash) != memory_regions.end()); | ||
| 171 | if (!element.uses_existing_data) { | ||
| 172 | element.extra_data.resize(size); | ||
| 173 | memcpy(element.extra_data.data(), data, size); | ||
| 174 | memory_regions.insert({element.hash, 0}); // file offset will be initialized in Finish() | ||
| 175 | } | ||
| 176 | |||
| 177 | stream.push_back(element); | ||
| 178 | } | ||
| 179 | |||
| 180 | template<typename T> | ||
| 181 | void Recorder::RegisterWritten(u32 physical_address, T value) { | ||
| 182 | StreamElement element = { RegisterWrite }; | ||
| 183 | element.data.register_write.size = (sizeof(T) == 1) ? CTRegisterWrite::SIZE_8 | ||
| 184 | : (sizeof(T) == 2) ? CTRegisterWrite::SIZE_16 | ||
| 185 | : (sizeof(T) == 4) ? CTRegisterWrite::SIZE_32 | ||
| 186 | : CTRegisterWrite::SIZE_64; | ||
| 187 | element.data.register_write.physical_address = physical_address; | ||
| 188 | element.data.register_write.value = value; | ||
| 189 | |||
| 190 | stream.push_back(element); | ||
| 191 | } | ||
| 192 | |||
| 193 | template void Recorder::RegisterWritten(u32,u8); | ||
| 194 | template void Recorder::RegisterWritten(u32,u16); | ||
| 195 | template void Recorder::RegisterWritten(u32,u32); | ||
| 196 | template void Recorder::RegisterWritten(u32,u64); | ||
| 197 | |||
| 198 | } | ||
diff --git a/src/core/tracer/recorder.h b/src/core/tracer/recorder.h new file mode 100644 index 000000000..8fec0a971 --- /dev/null +++ b/src/core/tracer/recorder.h | |||
| @@ -0,0 +1,92 @@ | |||
| 1 | // Copyright 2015 Citra 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 <unordered_map> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include <boost/crc.hpp> | ||
| 11 | |||
| 12 | #include "common/common_types.h" | ||
| 13 | |||
| 14 | #include "tracer.h" | ||
| 15 | |||
| 16 | namespace CiTrace { | ||
| 17 | |||
| 18 | class Recorder { | ||
| 19 | public: | ||
| 20 | /** | ||
| 21 | * Recorder constructor | ||
| 22 | * @param vs_float_uniforms Pointer to an array of 32-bit-aligned 24-bit floating point values. | ||
| 23 | */ | ||
| 24 | Recorder(u32* gpu_registers, u32 gpu_registers_size, | ||
| 25 | u32* lcd_registers, u32 lcd_registers_size, | ||
| 26 | u32* pica_registers, u32 pica_registers_size, | ||
| 27 | u32* vs_program_binary, u32 vs_program_binary_size, | ||
| 28 | u32* vs_swizzle_data, u32 vs_swizzle_data_size, | ||
| 29 | u32* vs_float_uniforms, u32 vs_float_uniforms_size, | ||
| 30 | u32* gs_program_binary, u32 gs_program_binary_size, | ||
| 31 | u32* gs_swizzle_data, u32 gs_swizzle_data_size, | ||
| 32 | u32* gs_float_uniforms, u32 gs_float_uniforms_size); | ||
| 33 | |||
| 34 | /// Finish recording of this Citrace and save it using the given filename. | ||
| 35 | void Finish(const std::string& filename); | ||
| 36 | |||
| 37 | /// Mark end of a frame | ||
| 38 | void FrameFinished(); | ||
| 39 | |||
| 40 | /** | ||
| 41 | * Store a copy of the given memory range in the recording. | ||
| 42 | * @note Use this whenever the GPU is about to access a particular memory region. | ||
| 43 | * @note The implementation will make sure to minimize redundant memory updates. | ||
| 44 | */ | ||
| 45 | void MemoryAccessed(const u8* data, u32 size, u32 physical_address); | ||
| 46 | |||
| 47 | /** | ||
| 48 | * Record a register write. | ||
| 49 | * @note Use this whenever a GPU-related MMIO register has been written to. | ||
| 50 | */ | ||
| 51 | template<typename T> | ||
| 52 | void RegisterWritten(u32 physical_address, T value); | ||
| 53 | |||
| 54 | private: | ||
| 55 | // Initial state of recording start | ||
| 56 | std::vector<u32> gpu_registers; | ||
| 57 | std::vector<u32> lcd_registers; | ||
| 58 | std::vector<u32> pica_registers; | ||
| 59 | std::vector<u32> vs_program_binary; | ||
| 60 | std::vector<u32> vs_swizzle_data; | ||
| 61 | std::vector<u32> vs_float_uniforms; | ||
| 62 | std::vector<u32> gs_program_binary; | ||
| 63 | std::vector<u32> gs_swizzle_data; | ||
| 64 | std::vector<u32> gs_float_uniforms; | ||
| 65 | |||
| 66 | // Command stream | ||
| 67 | struct StreamElement { | ||
| 68 | CTStreamElement data; | ||
| 69 | |||
| 70 | /** | ||
| 71 | * Extra data to store along "core" data. | ||
| 72 | * This is e.g. used for data used in MemoryUpdates. | ||
| 73 | */ | ||
| 74 | std::vector<u8> extra_data; | ||
| 75 | |||
| 76 | /// Optional CRC hash (e.g. for hashing memory regions) | ||
| 77 | boost::crc_32_type::value_type hash; | ||
| 78 | |||
| 79 | /// If true, refer to data already written to the output file instead of extra_data | ||
| 80 | bool uses_existing_data; | ||
| 81 | }; | ||
| 82 | |||
| 83 | std::vector<StreamElement> stream; | ||
| 84 | |||
| 85 | /** | ||
| 86 | * Internal cache which maps hashes of memory contents to file offsets at which those memory | ||
| 87 | * contents are stored. | ||
| 88 | */ | ||
| 89 | std::unordered_map<boost::crc_32_type::value_type /*hash*/, u32 /*file_offset*/> memory_regions; | ||
| 90 | }; | ||
| 91 | |||
| 92 | } // namespace | ||
diff --git a/src/core/tracer/tracer.h b/src/core/tracer/tracer.h new file mode 100644 index 000000000..1545d7439 --- /dev/null +++ b/src/core/tracer/tracer.h | |||
| @@ -0,0 +1,98 @@ | |||
| 1 | // Copyright 2015 Citra 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 <cstdint> | ||
| 8 | |||
| 9 | namespace CiTrace { | ||
| 10 | |||
| 11 | // NOTE: Things are stored in little-endian | ||
| 12 | |||
| 13 | #pragma pack(1) | ||
| 14 | |||
| 15 | struct CTHeader { | ||
| 16 | static const char* ExpectedMagicWord() { | ||
| 17 | return "CiTr"; | ||
| 18 | } | ||
| 19 | |||
| 20 | static uint32_t ExpectedVersion() { | ||
| 21 | return 1; | ||
| 22 | } | ||
| 23 | |||
| 24 | char magic[4]; | ||
| 25 | uint32_t version; | ||
| 26 | uint32_t header_size; | ||
| 27 | |||
| 28 | struct { | ||
| 29 | // NOTE: Register range sizes are technically hardware-constants, but the actual limits | ||
| 30 | // aren't known. Hence we store the presumed limits along the offsets. | ||
| 31 | // Sizes are given in uint32_t units. | ||
| 32 | uint32_t gpu_registers; | ||
| 33 | uint32_t gpu_registers_size; | ||
| 34 | uint32_t lcd_registers; | ||
| 35 | uint32_t lcd_registers_size; | ||
| 36 | uint32_t pica_registers; | ||
| 37 | uint32_t pica_registers_size; | ||
| 38 | uint32_t vs_program_binary; | ||
| 39 | uint32_t vs_program_binary_size; | ||
| 40 | uint32_t vs_swizzle_data; | ||
| 41 | uint32_t vs_swizzle_data_size; | ||
| 42 | uint32_t vs_float_uniforms; | ||
| 43 | uint32_t vs_float_uniforms_size; | ||
| 44 | uint32_t gs_program_binary; | ||
| 45 | uint32_t gs_program_binary_size; | ||
| 46 | uint32_t gs_swizzle_data; | ||
| 47 | uint32_t gs_swizzle_data_size; | ||
| 48 | uint32_t gs_float_uniforms; | ||
| 49 | uint32_t gs_float_uniforms_size; | ||
| 50 | |||
| 51 | // Other things we might want to store here: | ||
| 52 | // - Initial framebuffer data, maybe even a full copy of FCRAM/VRAM | ||
| 53 | // - Default vertex attributes | ||
| 54 | } initial_state_offsets; | ||
| 55 | |||
| 56 | uint32_t stream_offset; | ||
| 57 | uint32_t stream_size; | ||
| 58 | }; | ||
| 59 | |||
| 60 | enum CTStreamElementType : uint32_t { | ||
| 61 | FrameMarker = 0xE1, | ||
| 62 | MemoryLoad = 0xE2, | ||
| 63 | RegisterWrite = 0xE3, | ||
| 64 | }; | ||
| 65 | |||
| 66 | struct CTMemoryLoad { | ||
| 67 | uint32_t file_offset; | ||
| 68 | uint32_t size; | ||
| 69 | uint32_t physical_address; | ||
| 70 | uint32_t pad; | ||
| 71 | }; | ||
| 72 | |||
| 73 | struct CTRegisterWrite { | ||
| 74 | uint32_t physical_address; | ||
| 75 | |||
| 76 | enum : uint32_t { | ||
| 77 | SIZE_8 = 0xD1, | ||
| 78 | SIZE_16 = 0xD2, | ||
| 79 | SIZE_32 = 0xD3, | ||
| 80 | SIZE_64 = 0xD4 | ||
| 81 | } size; | ||
| 82 | |||
| 83 | // TODO: Make it clearer which bits of this member are used for sizes other than 32 bits | ||
| 84 | uint64_t value; | ||
| 85 | }; | ||
| 86 | |||
| 87 | struct CTStreamElement { | ||
| 88 | CTStreamElementType type; | ||
| 89 | |||
| 90 | union { | ||
| 91 | CTMemoryLoad memory_load; | ||
| 92 | CTRegisterWrite register_write; | ||
| 93 | }; | ||
| 94 | }; | ||
| 95 | |||
| 96 | #pragma pack() | ||
| 97 | |||
| 98 | } | ||