2015-04-04 11:57:31 +01:00
|
|
|
// Copyright 2015 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2016-04-30 16:34:51 +01:00
|
|
|
#include <algorithm>
|
|
|
|
#include <array>
|
|
|
|
#include <iterator>
|
2015-04-04 11:57:31 +01:00
|
|
|
#include <memory>
|
|
|
|
|
2015-09-11 05:23:00 +01:00
|
|
|
#include <boost/range/algorithm/copy.hpp>
|
|
|
|
|
2015-04-04 11:57:31 +01:00
|
|
|
#include <QBoxLayout>
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QFileDialog>
|
2015-05-21 01:12:59 +01:00
|
|
|
#include <QMessageBox>
|
2015-04-04 11:57:31 +01:00
|
|
|
#include <QPushButton>
|
|
|
|
|
2015-09-11 05:23:00 +01:00
|
|
|
#include "citra_qt/debugger/graphics_tracing.h"
|
2015-07-12 02:20:19 +01:00
|
|
|
|
2015-08-11 22:32:39 +01:00
|
|
|
#include "common/common_types.h"
|
|
|
|
|
2015-04-04 11:57:31 +01:00
|
|
|
#include "core/hw/gpu.h"
|
2015-05-27 18:03:45 +01:00
|
|
|
#include "core/hw/lcd.h"
|
2016-04-30 16:34:51 +01:00
|
|
|
#include "core/tracer/recorder.h"
|
2015-05-27 18:03:45 +01:00
|
|
|
|
2015-04-04 11:57:31 +01:00
|
|
|
#include "nihstro/float24.h"
|
|
|
|
|
2015-09-11 05:23:00 +01:00
|
|
|
#include "video_core/pica.h"
|
2016-03-03 03:16:38 +00:00
|
|
|
#include "video_core/pica_state.h"
|
2015-04-04 11:57:31 +01:00
|
|
|
|
|
|
|
GraphicsTracingWidget::GraphicsTracingWidget(std::shared_ptr<Pica::DebugContext> debug_context,
|
|
|
|
QWidget* parent)
|
|
|
|
: BreakPointObserverDock(debug_context, tr("CiTrace Recorder"), parent) {
|
|
|
|
|
|
|
|
setObjectName("CiTracing");
|
|
|
|
|
|
|
|
QPushButton* start_recording = new QPushButton(tr("Start Recording"));
|
2016-09-18 01:38:01 +01:00
|
|
|
QPushButton* stop_recording =
|
|
|
|
new QPushButton(QIcon::fromTheme("document-save"), tr("Stop and Save"));
|
2015-04-04 11:57:31 +01:00
|
|
|
QPushButton* abort_recording = new QPushButton(tr("Abort Recording"));
|
|
|
|
|
2016-09-18 01:38:01 +01:00
|
|
|
connect(this, SIGNAL(SetStartTracingButtonEnabled(bool)), start_recording,
|
|
|
|
SLOT(setVisible(bool)));
|
|
|
|
connect(this, SIGNAL(SetStopTracingButtonEnabled(bool)), stop_recording,
|
|
|
|
SLOT(setVisible(bool)));
|
|
|
|
connect(this, SIGNAL(SetAbortTracingButtonEnabled(bool)), abort_recording,
|
|
|
|
SLOT(setVisible(bool)));
|
2015-04-04 11:57:31 +01:00
|
|
|
connect(start_recording, SIGNAL(clicked()), this, SLOT(StartRecording()));
|
|
|
|
connect(stop_recording, SIGNAL(clicked()), this, SLOT(StopRecording()));
|
|
|
|
connect(abort_recording, SIGNAL(clicked()), this, SLOT(AbortRecording()));
|
|
|
|
|
|
|
|
stop_recording->setVisible(false);
|
|
|
|
abort_recording->setVisible(false);
|
|
|
|
|
|
|
|
auto main_widget = new QWidget;
|
|
|
|
auto main_layout = new QVBoxLayout;
|
|
|
|
{
|
|
|
|
auto sub_layout = new QHBoxLayout;
|
|
|
|
sub_layout->addWidget(start_recording);
|
|
|
|
sub_layout->addWidget(stop_recording);
|
|
|
|
sub_layout->addWidget(abort_recording);
|
|
|
|
main_layout->addLayout(sub_layout);
|
|
|
|
}
|
|
|
|
main_widget->setLayout(main_layout);
|
|
|
|
setWidget(main_widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicsTracingWidget::StartRecording() {
|
|
|
|
auto context = context_weak.lock();
|
|
|
|
if (!context)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto shader_binary = Pica::g_state.vs.program_code;
|
|
|
|
auto swizzle_data = Pica::g_state.vs.swizzle_data;
|
|
|
|
|
|
|
|
// Encode floating point numbers to 24-bit values
|
|
|
|
// TODO: Drop this explicit conversion once we store float24 values bit-correctly internally.
|
2015-08-11 22:32:39 +01:00
|
|
|
std::array<u32, 4 * 16> default_attributes;
|
2015-05-21 01:51:28 +01:00
|
|
|
for (unsigned i = 0; i < 16; ++i) {
|
|
|
|
for (unsigned comp = 0; comp < 3; ++comp) {
|
2016-09-18 01:38:01 +01:00
|
|
|
default_attributes[4 * i + comp] =
|
|
|
|
nihstro::to_float24(Pica::g_state.vs_default_attributes[i][comp].ToFloat32());
|
2015-05-21 01:51:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-11 22:32:39 +01:00
|
|
|
std::array<u32, 4 * 96> vs_float_uniforms;
|
2015-04-04 11:57:31 +01:00
|
|
|
for (unsigned i = 0; i < 96; ++i)
|
|
|
|
for (unsigned comp = 0; comp < 3; ++comp)
|
2016-09-18 01:38:01 +01:00
|
|
|
vs_float_uniforms[4 * i + comp] =
|
|
|
|
nihstro::to_float24(Pica::g_state.vs.uniforms.f[i][comp].ToFloat32());
|
2015-04-04 11:57:31 +01:00
|
|
|
|
2015-07-12 02:20:19 +01:00
|
|
|
CiTrace::Recorder::InitialState state;
|
2016-09-18 01:38:01 +01:00
|
|
|
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));
|
2015-07-12 02:20:19 +01:00
|
|
|
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));
|
2016-09-18 01:38:01 +01:00
|
|
|
// 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));
|
2015-07-12 02:20:19 +01:00
|
|
|
|
|
|
|
auto recorder = new CiTrace::Recorder(state);
|
2015-04-04 11:57:31 +01:00
|
|
|
context->recorder = std::shared_ptr<CiTrace::Recorder>(recorder);
|
|
|
|
|
|
|
|
emit SetStartTracingButtonEnabled(false);
|
|
|
|
emit SetStopTracingButtonEnabled(true);
|
|
|
|
emit SetAbortTracingButtonEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicsTracingWidget::StopRecording() {
|
|
|
|
auto context = context_weak.lock();
|
|
|
|
if (!context)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QString filename = QFileDialog::getSaveFileName(this, tr("Save CiTrace"), "citrace.ctf",
|
|
|
|
tr("CiTrace File (*.ctf)"));
|
|
|
|
|
|
|
|
if (filename.isEmpty()) {
|
|
|
|
// If the user canceled the dialog, keep recording
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
context->recorder->Finish(filename.toStdString());
|
|
|
|
context->recorder = nullptr;
|
|
|
|
|
|
|
|
emit SetStopTracingButtonEnabled(false);
|
|
|
|
emit SetAbortTracingButtonEnabled(false);
|
|
|
|
emit SetStartTracingButtonEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicsTracingWidget::AbortRecording() {
|
|
|
|
auto context = context_weak.lock();
|
|
|
|
if (!context)
|
|
|
|
return;
|
|
|
|
|
|
|
|
context->recorder = nullptr;
|
|
|
|
|
|
|
|
emit SetStopTracingButtonEnabled(false);
|
|
|
|
emit SetAbortTracingButtonEnabled(false);
|
|
|
|
emit SetStartTracingButtonEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicsTracingWidget::OnBreakPointHit(Pica::DebugContext::Event event, void* data) {
|
|
|
|
widget()->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicsTracingWidget::OnResumed() {
|
|
|
|
widget()->setEnabled(false);
|
|
|
|
}
|
2015-05-21 01:12:59 +01:00
|
|
|
|
|
|
|
void GraphicsTracingWidget::OnEmulationStarting(EmuThread* emu_thread) {
|
|
|
|
// Disable tracing starting/stopping until a GPU breakpoint is reached
|
|
|
|
widget()->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicsTracingWidget::OnEmulationStopping() {
|
|
|
|
// TODO: Is it safe to access the context here?
|
|
|
|
|
|
|
|
auto context = context_weak.lock();
|
|
|
|
if (!context)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (context->recorder) {
|
2016-09-18 01:38:01 +01:00
|
|
|
auto reply =
|
|
|
|
QMessageBox::question(this, tr("CiTracing still active"),
|
|
|
|
tr("A CiTrace is still being recorded. Do you want to save it? "
|
|
|
|
"If not, all recorded data will be discarded."),
|
|
|
|
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
|
2015-05-21 01:12:59 +01:00
|
|
|
|
|
|
|
if (reply == QMessageBox::Yes) {
|
|
|
|
StopRecording();
|
|
|
|
} else {
|
|
|
|
AbortRecording();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the widget was disabled before, enable it now to allow starting
|
|
|
|
// tracing before starting the next emulation session
|
|
|
|
widget()->setEnabled(true);
|
|
|
|
}
|