CiTrace: Clean up initialization method.

This commit is contained in:
Tony Wasserka 2015-07-12 03:20:19 +02:00
parent dc8295298e
commit 29abb11e8f
3 changed files with 61 additions and 79 deletions

View File

@ -12,6 +12,8 @@
#include <QPushButton>
#include <QSpinBox>
#include <boost/range/algorithm/copy.hpp>
#include "core/hw/gpu.h"
#include "core/hw/lcd.h"
@ -76,15 +78,19 @@ void GraphicsTracingWidget::StartRecording() {
for (unsigned comp = 0; comp < 3; ++comp)
vs_float_uniforms[4 * i + comp] = nihstro::to_float24(Pica::g_state.vs.uniforms.f[i][comp].ToFloat32());
auto recorder = new CiTrace::Recorder((u32*)&GPU::g_regs, sizeof(GPU::g_regs) / sizeof(u32),
(u32*)&LCD::g_regs, sizeof(LCD::g_regs) / sizeof(u32),
(u32*)&Pica::g_state.regs, sizeof(Pica::g_state.regs) / sizeof(u32),
default_attributes.data(), default_attributes.size(),
shader_binary.data(), shader_binary.size(),
swizzle_data.data(), swizzle_data.size(),
vs_float_uniforms.data(), vs_float_uniforms.size(),
nullptr, 0, nullptr, 0, nullptr, 0 // Geometry shader is not implemented yet, so submit dummy data for now
);
CiTrace::Recorder::InitialState state;
std::copy_n((u32*)&GPU::g_regs, sizeof(GPU::g_regs) / sizeof(u32), std::back_inserter(state.gpu_registers));
std::copy_n((u32*)&LCD::g_regs, sizeof(LCD::g_regs) / sizeof(u32), std::back_inserter(state.lcd_registers));
std::copy_n((u32*)&Pica::g_state.regs, sizeof(Pica::g_state.regs) / sizeof(u32), std::back_inserter(state.pica_registers));
boost::copy(default_attributes, std::back_inserter(state.default_attributes));
boost::copy(shader_binary, std::back_inserter(state.vs_program_binary));
boost::copy(swizzle_data, std::back_inserter(state.vs_swizzle_data));
boost::copy(vs_float_uniforms, std::back_inserter(state.vs_float_uniforms));
//boost::copy(TODO: Not implemented, std::back_inserter(state.gs_program_binary));
//boost::copy(TODO: Not implemented, std::back_inserter(state.gs_swizzle_data));
//boost::copy(TODO: Not implemented, std::back_inserter(state.gs_float_uniforms));
auto recorder = new CiTrace::Recorder(state);
context->recorder = std::shared_ptr<CiTrace::Recorder>(recorder);
emit SetStartTracingButtonEnabled(false);

View File

@ -12,26 +12,7 @@
namespace CiTrace {
Recorder::Recorder(u32* gpu_registers, u32 gpu_registers_size,
u32* lcd_registers, u32 lcd_registers_size,
u32* pica_registers, u32 pica_registers_size,
u32* default_attributes, u32 default_attributes_size,
u32* vs_program_binary, u32 vs_program_binary_size,
u32* vs_swizzle_data, u32 vs_swizzle_data_size,
u32* vs_float_uniforms, u32 vs_float_uniforms_size,
u32* gs_program_binary, u32 gs_program_binary_size,
u32* gs_swizzle_data, u32 gs_swizzle_data_size,
u32* gs_float_uniforms, u32 gs_float_uniforms_size)
: gpu_registers(gpu_registers, gpu_registers + gpu_registers_size),
lcd_registers(lcd_registers, lcd_registers + lcd_registers_size),
pica_registers(pica_registers, pica_registers + pica_registers_size),
default_attributes(default_attributes, default_attributes + default_attributes_size),
vs_program_binary(vs_program_binary, vs_program_binary + vs_program_binary_size),
vs_swizzle_data(vs_swizzle_data, vs_swizzle_data + vs_swizzle_data_size),
vs_float_uniforms(vs_float_uniforms, vs_float_uniforms + vs_float_uniforms_size),
gs_program_binary(gs_program_binary, gs_program_binary + gs_program_binary_size),
gs_swizzle_data(gs_swizzle_data, gs_swizzle_data + gs_swizzle_data_size),
gs_float_uniforms(gs_float_uniforms, gs_float_uniforms + gs_float_uniforms_size) {
Recorder::Recorder(const InitialState& initial_state) : initial_state(initial_state) {
}
@ -45,16 +26,16 @@ void Recorder::Finish(const std::string& filename) {
// Calculate file offsets
auto& initial = header.initial_state_offsets;
initial.gpu_registers_size = gpu_registers.size();
initial.lcd_registers_size = lcd_registers.size();
initial.pica_registers_size = pica_registers.size();
initial.default_attributes_size = default_attributes.size();
initial.vs_program_binary_size = vs_program_binary.size();
initial.vs_swizzle_data_size = vs_swizzle_data.size();
initial.vs_float_uniforms_size = vs_float_uniforms.size();
initial.gs_program_binary_size = gs_program_binary.size();
initial.gs_swizzle_data_size = gs_swizzle_data.size();
initial.gs_float_uniforms_size = gs_float_uniforms.size();
initial.gpu_registers_size = initial_state.gpu_registers.size();
initial.lcd_registers_size = initial_state.lcd_registers.size();
initial.pica_registers_size = initial_state.pica_registers.size();
initial.default_attributes_size = initial_state.default_attributes.size();
initial.vs_program_binary_size = initial_state.vs_program_binary.size();
initial.vs_swizzle_data_size = initial_state.vs_swizzle_data.size();
initial.vs_float_uniforms_size = initial_state.vs_float_uniforms.size();
initial.gs_program_binary_size = initial_state.gs_program_binary.size();
initial.gs_swizzle_data_size = initial_state.gs_swizzle_data.size();
initial.gs_float_uniforms_size = initial_state.gs_float_uniforms.size();
header.stream_size = stream.size();
initial.gpu_registers = sizeof(header);
@ -98,44 +79,44 @@ void Recorder::Finish(const std::string& filename) {
throw "Failed to write header";
// Write initial state
written = file.WriteArray(gpu_registers.data(), gpu_registers.size());
if (written != gpu_registers.size() || file.Tell() != initial.lcd_registers)
written = file.WriteArray(initial_state.gpu_registers.data(), initial_state.gpu_registers.size());
if (written != initial_state.gpu_registers.size() || file.Tell() != initial.lcd_registers)
throw "Failed to write GPU registers";
written = file.WriteArray(lcd_registers.data(), lcd_registers.size());
if (written != lcd_registers.size() || file.Tell() != initial.pica_registers)
written = file.WriteArray(initial_state.lcd_registers.data(), initial_state.lcd_registers.size());
if (written != initial_state.lcd_registers.size() || file.Tell() != initial.pica_registers)
throw "Failed to write LCD registers";
written = file.WriteArray(pica_registers.data(), pica_registers.size());
if (written != pica_registers.size() || file.Tell() != initial.default_attributes)
written = file.WriteArray(initial_state.pica_registers.data(), initial_state.pica_registers.size());
if (written != initial_state.pica_registers.size() || file.Tell() != initial.default_attributes)
throw "Failed to write Pica registers";
written = file.WriteArray(default_attributes.data(), default_attributes.size());
if (written != default_attributes.size() || file.Tell() != initial.vs_program_binary)
written = file.WriteArray(initial_state.default_attributes.data(), initial_state.default_attributes.size());
if (written != initial_state.default_attributes.size() || file.Tell() != initial.vs_program_binary)
throw "Failed to write default vertex attributes";
written = file.WriteArray(vs_program_binary.data(), vs_program_binary.size());
if (written != vs_program_binary.size() || file.Tell() != initial.vs_swizzle_data)
written = file.WriteArray(initial_state.vs_program_binary.data(), initial_state.vs_program_binary.size());
if (written != initial_state.vs_program_binary.size() || file.Tell() != initial.vs_swizzle_data)
throw "Failed to write vertex shader program binary";
written = file.WriteArray(vs_swizzle_data.data(), vs_swizzle_data.size());
if (written != vs_swizzle_data.size() || file.Tell() != initial.vs_float_uniforms)
written = file.WriteArray(initial_state.vs_swizzle_data.data(), initial_state.vs_swizzle_data.size());
if (written != initial_state.vs_swizzle_data.size() || file.Tell() != initial.vs_float_uniforms)
throw "Failed to write vertex shader swizzle data";
written = file.WriteArray(vs_float_uniforms.data(), vs_float_uniforms.size());
if (written != vs_float_uniforms.size() || file.Tell() != initial.gs_program_binary)
written = file.WriteArray(initial_state.vs_float_uniforms.data(), initial_state.vs_float_uniforms.size());
if (written != initial_state.vs_float_uniforms.size() || file.Tell() != initial.gs_program_binary)
throw "Failed to write vertex shader float uniforms";
written = file.WriteArray(gs_program_binary.data(), gs_program_binary.size());
if (written != gs_program_binary.size() || file.Tell() != initial.gs_swizzle_data)
written = file.WriteArray(initial_state.gs_program_binary.data(), initial_state.gs_program_binary.size());
if (written != initial_state.gs_program_binary.size() || file.Tell() != initial.gs_swizzle_data)
throw "Failed to write geomtry shader program binary";
written = file.WriteArray(gs_swizzle_data.data(), gs_swizzle_data.size());
if (written != gs_swizzle_data.size() || file.Tell() != initial.gs_float_uniforms)
written = file.WriteArray(initial_state.gs_swizzle_data.data(), initial_state.gs_swizzle_data.size());
if (written != initial_state.gs_swizzle_data.size() || file.Tell() != initial.gs_float_uniforms)
throw "Failed to write geometry shader swizzle data";
written = file.WriteArray(gs_float_uniforms.data(), gs_float_uniforms.size());
if (written != gs_float_uniforms.size() || file.Tell() != initial.gs_float_uniforms + sizeof(u32) * initial.gs_float_uniforms_size)
written = file.WriteArray(initial_state.gs_float_uniforms.data(), initial_state.gs_float_uniforms.size());
if (written != initial_state.gs_float_uniforms.size() || file.Tell() != initial.gs_float_uniforms + sizeof(u32) * initial.gs_float_uniforms_size)
throw "Failed to write geometry shader float uniforms";
// Iterate through stream elements, write "extra data"

View File

@ -17,21 +17,25 @@ namespace CiTrace {
class Recorder {
public:
struct InitialState {
std::vector<u32> gpu_registers;
std::vector<u32> lcd_registers;
std::vector<u32> pica_registers;
std::vector<u32> default_attributes;
std::vector<u32> vs_program_binary;
std::vector<u32> vs_swizzle_data;
std::vector<u32> vs_float_uniforms;
std::vector<u32> gs_program_binary;
std::vector<u32> gs_swizzle_data;
std::vector<u32> gs_float_uniforms;
};
/**
* Recorder constructor
* @param default_attributes Pointer to an array of 32-bit-aligned 24-bit floating point values.
* @param vs_float_uniforms Pointer to an array of 32-bit-aligned 24-bit floating point values.
*/
Recorder(u32* gpu_registers, u32 gpu_registers_size,
u32* lcd_registers, u32 lcd_registers_size,
u32* pica_registers, u32 pica_registers_size,
u32* default_attributes, u32 default_attributes_size,
u32* vs_program_binary, u32 vs_program_binary_size,
u32* vs_swizzle_data, u32 vs_swizzle_data_size,
u32* vs_float_uniforms, u32 vs_float_uniforms_size,
u32* gs_program_binary, u32 gs_program_binary_size,
u32* gs_swizzle_data, u32 gs_swizzle_data_size,
u32* gs_float_uniforms, u32 gs_float_uniforms_size);
Recorder(const InitialState& initial_state);
/// Finish recording of this Citrace and save it using the given filename.
void Finish(const std::string& filename);
@ -55,16 +59,7 @@ public:
private:
// Initial state of recording start
std::vector<u32> gpu_registers;
std::vector<u32> lcd_registers;
std::vector<u32> pica_registers;
std::vector<u32> default_attributes;
std::vector<u32> vs_program_binary;
std::vector<u32> vs_swizzle_data;
std::vector<u32> vs_float_uniforms;
std::vector<u32> gs_program_binary;
std::vector<u32> gs_swizzle_data;
std::vector<u32> gs_float_uniforms;
InitialState initial_state;
// Command stream
struct StreamElement {