2014-05-18 17:52:22 +02:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 06:38:14 +01:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-05-18 17:52:22 +02:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2015-05-27 16:32:02 +02:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QClipboard>
|
2015-09-11 06:23:00 +02:00
|
|
|
#include <QComboBox>
|
|
|
|
#include <QHeaderView>
|
2014-08-24 14:39:52 +02:00
|
|
|
#include <QLabel>
|
2014-08-14 19:21:55 +02:00
|
|
|
#include <QListView>
|
2014-08-24 17:23:02 +02:00
|
|
|
#include <QMainWindow>
|
2014-08-14 19:21:55 +02:00
|
|
|
#include <QPushButton>
|
2014-08-24 17:23:02 +02:00
|
|
|
#include <QSpinBox>
|
2015-09-11 06:23:00 +02:00
|
|
|
#include <QTreeView>
|
|
|
|
#include <QVBoxLayout>
|
2016-09-21 08:52:38 +02:00
|
|
|
#include "citra_qt/debugger/graphics_cmdlists.h"
|
2015-09-11 06:23:00 +02:00
|
|
|
#include "citra_qt/util/spinbox.h"
|
2015-08-19 22:00:56 +02:00
|
|
|
#include "citra_qt/util/util.h"
|
2015-05-24 21:16:22 +02:00
|
|
|
#include "common/vector_math.h"
|
2016-09-18 02:38:01 +02:00
|
|
|
#include "video_core/debug_utils/debug_utils.h"
|
2015-05-24 21:16:22 +02:00
|
|
|
#include "video_core/pica.h"
|
2016-03-03 04:16:38 +01:00
|
|
|
#include "video_core/pica_state.h"
|
2014-08-24 17:23:02 +02:00
|
|
|
|
2016-12-11 01:18:02 +01:00
|
|
|
namespace {
|
2014-08-24 17:23:02 +02:00
|
|
|
QImage LoadTexture(u8* src, const Pica::DebugUtils::TextureInfo& info) {
|
|
|
|
QImage decoded_image(info.width, info.height, QImage::Format_ARGB32);
|
|
|
|
for (int y = 0; y < info.height; ++y) {
|
|
|
|
for (int x = 0; x < info.width; ++x) {
|
2014-12-06 21:52:21 +01:00
|
|
|
Math::Vec4<u8> color = Pica::DebugUtils::LookupTexture(src, x, y, info, true);
|
2014-08-24 17:23:02 +02:00
|
|
|
decoded_image.setPixel(x, y, qRgba(color.r(), color.g(), color.b(), color.a()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return decoded_image;
|
|
|
|
}
|
|
|
|
|
2014-08-24 14:39:52 +02:00
|
|
|
class TextureInfoWidget : public QWidget {
|
|
|
|
public:
|
2016-09-18 02:38:01 +02:00
|
|
|
TextureInfoWidget(u8* src, const Pica::DebugUtils::TextureInfo& info, QWidget* parent = nullptr)
|
|
|
|
: QWidget(parent) {
|
2014-08-24 14:39:52 +02:00
|
|
|
QLabel* image_widget = new QLabel;
|
2014-08-24 17:23:02 +02:00
|
|
|
QPixmap image_pixmap = QPixmap::fromImage(LoadTexture(src, info));
|
2014-08-24 14:39:52 +02:00
|
|
|
image_pixmap = image_pixmap.scaled(200, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
|
|
|
image_widget->setPixmap(image_pixmap);
|
|
|
|
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout;
|
|
|
|
layout->addWidget(image_widget);
|
|
|
|
setLayout(layout);
|
|
|
|
}
|
|
|
|
};
|
2016-12-11 01:18:02 +01:00
|
|
|
} // Anonymous namespace
|
2014-08-24 14:39:52 +02:00
|
|
|
|
2016-09-19 03:01:46 +02:00
|
|
|
GPUCommandListModel::GPUCommandListModel(QObject* parent) : QAbstractListModel(parent) {}
|
2014-05-18 19:59:36 +02:00
|
|
|
|
2014-12-04 19:41:03 +01:00
|
|
|
int GPUCommandListModel::rowCount(const QModelIndex& parent) const {
|
2015-06-28 04:27:49 +02:00
|
|
|
return static_cast<int>(pica_trace.writes.size());
|
2014-05-18 19:59:36 +02:00
|
|
|
}
|
|
|
|
|
2014-12-04 19:41:03 +01:00
|
|
|
int GPUCommandListModel::columnCount(const QModelIndex& parent) const {
|
2015-07-25 22:00:40 +02:00
|
|
|
return 4;
|
2014-05-18 17:52:22 +02:00
|
|
|
}
|
|
|
|
|
2014-12-04 19:41:03 +01:00
|
|
|
QVariant GPUCommandListModel::data(const QModelIndex& index, int role) const {
|
2014-05-18 17:52:22 +02:00
|
|
|
if (!index.isValid())
|
|
|
|
return QVariant();
|
|
|
|
|
2015-07-25 22:00:40 +02:00
|
|
|
const auto& write = pica_trace.writes[index.row()];
|
2014-08-14 19:21:55 +02:00
|
|
|
|
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
QString content;
|
2016-09-18 02:38:01 +02:00
|
|
|
switch (index.column()) {
|
2015-07-25 14:22:09 +02:00
|
|
|
case 0:
|
2015-07-25 22:00:40 +02:00
|
|
|
return QString::fromLatin1(Pica::Regs::GetCommandName(write.cmd_id).c_str());
|
2015-07-25 14:22:09 +02:00
|
|
|
case 1:
|
2015-07-25 22:00:40 +02:00
|
|
|
return QString("%1").arg(write.cmd_id, 3, 16, QLatin1Char('0'));
|
2015-07-25 14:22:09 +02:00
|
|
|
case 2:
|
2015-07-25 22:00:40 +02:00
|
|
|
return QString("%1").arg(write.mask, 4, 2, QLatin1Char('0'));
|
|
|
|
case 3:
|
|
|
|
return QString("%1").arg(write.value, 8, 16, QLatin1Char('0'));
|
2014-05-18 17:52:22 +02:00
|
|
|
}
|
2014-08-24 14:39:52 +02:00
|
|
|
} else if (role == CommandIdRole) {
|
2015-07-25 22:00:40 +02:00
|
|
|
return QVariant::fromValue<int>(write.cmd_id);
|
2014-05-18 17:52:22 +02:00
|
|
|
}
|
2014-05-18 19:59:36 +02:00
|
|
|
|
2014-05-18 17:52:22 +02:00
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2014-12-04 19:41:03 +01:00
|
|
|
QVariant GPUCommandListModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
2016-09-18 02:38:01 +02:00
|
|
|
switch (role) {
|
|
|
|
case Qt::DisplayRole: {
|
2015-07-25 14:22:09 +02:00
|
|
|
switch (section) {
|
|
|
|
case 0:
|
2014-10-26 11:40:12 +01:00
|
|
|
return tr("Command Name");
|
2015-07-25 14:22:09 +02:00
|
|
|
case 1:
|
|
|
|
return tr("Register");
|
|
|
|
case 2:
|
2015-07-25 22:00:40 +02:00
|
|
|
return tr("Mask");
|
|
|
|
case 3:
|
2015-07-25 14:22:09 +02:00
|
|
|
return tr("New Value");
|
2014-10-26 11:40:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2014-12-04 19:41:03 +01:00
|
|
|
void GPUCommandListModel::OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace& trace) {
|
2014-08-14 19:21:55 +02:00
|
|
|
beginResetModel();
|
|
|
|
|
|
|
|
pica_trace = trace;
|
|
|
|
|
|
|
|
endResetModel();
|
2014-05-18 17:52:22 +02:00
|
|
|
}
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
#define COMMAND_IN_RANGE(cmd_id, reg_name) \
|
|
|
|
(cmd_id >= PICA_REG_INDEX(reg_name) && \
|
2015-05-14 05:29:27 +02:00
|
|
|
cmd_id < PICA_REG_INDEX(reg_name) + sizeof(decltype(Pica::g_state.regs.reg_name)) / 4)
|
2014-08-24 17:23:02 +02:00
|
|
|
|
2014-12-04 19:41:03 +01:00
|
|
|
void GPUCommandListWidget::OnCommandDoubleClicked(const QModelIndex& index) {
|
2016-09-18 02:38:01 +02:00
|
|
|
const unsigned int command_id =
|
|
|
|
list_widget->model()->data(index, GPUCommandListModel::CommandIdRole).toUInt();
|
|
|
|
if (COMMAND_IN_RANGE(command_id, texture0) || COMMAND_IN_RANGE(command_id, texture1) ||
|
2014-12-06 19:10:08 +01:00
|
|
|
COMMAND_IN_RANGE(command_id, texture2)) {
|
|
|
|
|
|
|
|
unsigned index;
|
|
|
|
if (COMMAND_IN_RANGE(command_id, texture0)) {
|
|
|
|
index = 0;
|
|
|
|
} else if (COMMAND_IN_RANGE(command_id, texture1)) {
|
|
|
|
index = 1;
|
2016-04-09 18:23:15 +02:00
|
|
|
} else if (COMMAND_IN_RANGE(command_id, texture2)) {
|
2014-12-06 19:10:08 +01:00
|
|
|
index = 2;
|
2016-04-09 18:23:15 +02:00
|
|
|
} else {
|
|
|
|
UNREACHABLE_MSG("Unknown texture command");
|
2014-12-06 19:10:08 +01:00
|
|
|
}
|
2015-05-14 05:29:27 +02:00
|
|
|
auto config = Pica::g_state.regs.GetTextures()[index].config;
|
|
|
|
auto format = Pica::g_state.regs.GetTextures()[index].format;
|
2014-12-06 19:10:08 +01:00
|
|
|
auto info = Pica::DebugUtils::TextureInfo::FromPicaRegister(config, format);
|
2014-12-04 19:41:03 +01:00
|
|
|
|
2016-04-09 18:23:15 +02:00
|
|
|
// TODO: Open a surface debugger
|
2014-08-24 17:23:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-04 19:41:03 +01:00
|
|
|
void GPUCommandListWidget::SetCommandInfo(const QModelIndex& index) {
|
2015-07-26 15:03:54 +02:00
|
|
|
QWidget* new_info_widget = nullptr;
|
2014-08-24 14:39:52 +02:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
const unsigned int command_id =
|
|
|
|
list_widget->model()->data(index, GPUCommandListModel::CommandIdRole).toUInt();
|
|
|
|
if (COMMAND_IN_RANGE(command_id, texture0) || COMMAND_IN_RANGE(command_id, texture1) ||
|
2014-12-06 19:10:08 +01:00
|
|
|
COMMAND_IN_RANGE(command_id, texture2)) {
|
|
|
|
|
|
|
|
unsigned index;
|
|
|
|
if (COMMAND_IN_RANGE(command_id, texture0)) {
|
|
|
|
index = 0;
|
|
|
|
} else if (COMMAND_IN_RANGE(command_id, texture1)) {
|
|
|
|
index = 1;
|
|
|
|
} else {
|
|
|
|
index = 2;
|
|
|
|
}
|
2015-05-14 05:29:27 +02:00
|
|
|
auto config = Pica::g_state.regs.GetTextures()[index].config;
|
|
|
|
auto format = Pica::g_state.regs.GetTextures()[index].format;
|
2014-12-06 19:10:08 +01:00
|
|
|
|
|
|
|
auto info = Pica::DebugUtils::TextureInfo::FromPicaRegister(config, format);
|
2015-05-09 09:02:32 +02:00
|
|
|
u8* src = Memory::GetPhysicalPointer(config.GetPhysicalAddress());
|
2014-08-24 14:39:52 +02:00
|
|
|
new_info_widget = new TextureInfoWidget(src, info);
|
|
|
|
}
|
2015-07-26 15:03:54 +02:00
|
|
|
if (command_info_widget) {
|
|
|
|
delete command_info_widget;
|
|
|
|
command_info_widget = nullptr;
|
|
|
|
}
|
|
|
|
if (new_info_widget) {
|
|
|
|
widget()->layout()->addWidget(new_info_widget);
|
|
|
|
command_info_widget = new_info_widget;
|
|
|
|
}
|
2014-08-24 14:39:52 +02:00
|
|
|
}
|
2014-08-24 17:23:02 +02:00
|
|
|
#undef COMMAND_IN_RANGE
|
2014-05-18 17:52:22 +02:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
GPUCommandListWidget::GPUCommandListWidget(QWidget* parent)
|
|
|
|
: QDockWidget(tr("Pica Command List"), parent) {
|
2014-08-24 14:39:52 +02:00
|
|
|
setObjectName("Pica Command List");
|
2014-08-14 19:21:55 +02:00
|
|
|
GPUCommandListModel* model = new GPUCommandListModel(this);
|
2014-05-18 17:52:22 +02:00
|
|
|
|
2014-08-14 19:21:55 +02:00
|
|
|
QWidget* main_widget = new QWidget;
|
2014-05-18 19:59:36 +02:00
|
|
|
|
2014-08-24 14:39:52 +02:00
|
|
|
list_widget = new QTreeView;
|
2014-08-14 19:21:55 +02:00
|
|
|
list_widget->setModel(model);
|
2015-08-19 22:00:56 +02:00
|
|
|
list_widget->setFont(GetMonospaceFont());
|
2014-08-14 19:21:55 +02:00
|
|
|
list_widget->setRootIsDecorated(false);
|
2015-07-25 14:24:02 +02:00
|
|
|
list_widget->setUniformRowHeights(true);
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
2015-07-25 14:24:02 +02:00
|
|
|
list_widget->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
|
|
|
#else
|
|
|
|
list_widget->header()->setResizeMode(QHeaderView::ResizeToContents);
|
|
|
|
#endif
|
2014-05-18 19:59:36 +02:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
connect(list_widget->selectionModel(),
|
|
|
|
SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), this,
|
|
|
|
SLOT(SetCommandInfo(const QModelIndex&)));
|
|
|
|
connect(list_widget, SIGNAL(doubleClicked(const QModelIndex&)), this,
|
|
|
|
SLOT(OnCommandDoubleClicked(const QModelIndex&)));
|
2014-08-24 14:39:52 +02:00
|
|
|
|
2014-10-26 11:40:12 +01:00
|
|
|
toggle_tracing = new QPushButton(tr("Start Tracing"));
|
2015-05-27 16:32:02 +02:00
|
|
|
QPushButton* copy_all = new QPushButton(tr("Copy All"));
|
2014-05-18 19:59:36 +02:00
|
|
|
|
2014-08-14 19:21:55 +02:00
|
|
|
connect(toggle_tracing, SIGNAL(clicked()), this, SLOT(OnToggleTracing()));
|
2016-09-18 02:38:01 +02:00
|
|
|
connect(this, SIGNAL(TracingFinished(const Pica::DebugUtils::PicaTrace&)), model,
|
|
|
|
SLOT(OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace&)));
|
2014-05-18 17:52:22 +02:00
|
|
|
|
2015-05-27 16:32:02 +02:00
|
|
|
connect(copy_all, SIGNAL(clicked()), this, SLOT(CopyAllToClipboard()));
|
|
|
|
|
2015-07-26 15:03:54 +02:00
|
|
|
command_info_widget = nullptr;
|
2014-08-24 14:39:52 +02:00
|
|
|
|
2014-08-14 19:21:55 +02:00
|
|
|
QVBoxLayout* main_layout = new QVBoxLayout;
|
|
|
|
main_layout->addWidget(list_widget);
|
2015-05-27 16:32:02 +02:00
|
|
|
{
|
|
|
|
QHBoxLayout* sub_layout = new QHBoxLayout;
|
|
|
|
sub_layout->addWidget(toggle_tracing);
|
|
|
|
sub_layout->addWidget(copy_all);
|
|
|
|
main_layout->addLayout(sub_layout);
|
|
|
|
}
|
2014-08-14 19:21:55 +02:00
|
|
|
main_widget->setLayout(main_layout);
|
|
|
|
|
|
|
|
setWidget(main_widget);
|
2014-05-18 17:52:22 +02:00
|
|
|
}
|
|
|
|
|
2014-12-04 19:41:03 +01:00
|
|
|
void GPUCommandListWidget::OnToggleTracing() {
|
2014-08-14 19:21:55 +02:00
|
|
|
if (!Pica::DebugUtils::IsPicaTracing()) {
|
|
|
|
Pica::DebugUtils::StartPicaTracing();
|
2014-12-04 20:41:45 +01:00
|
|
|
toggle_tracing->setText(tr("Finish Tracing"));
|
2014-08-14 19:21:55 +02:00
|
|
|
} else {
|
|
|
|
pica_trace = Pica::DebugUtils::FinishPicaTracing();
|
|
|
|
emit TracingFinished(*pica_trace);
|
2014-10-26 11:40:12 +01:00
|
|
|
toggle_tracing->setText(tr("Start Tracing"));
|
2014-08-14 19:21:55 +02:00
|
|
|
}
|
2014-05-18 17:52:22 +02:00
|
|
|
}
|
2015-05-27 16:32:02 +02:00
|
|
|
|
|
|
|
void GPUCommandListWidget::CopyAllToClipboard() {
|
|
|
|
QClipboard* clipboard = QApplication::clipboard();
|
|
|
|
QString text;
|
|
|
|
|
2015-08-19 10:51:12 +02:00
|
|
|
QAbstractItemModel* model = static_cast<QAbstractItemModel*>(list_widget->model());
|
2015-05-27 16:32:02 +02:00
|
|
|
|
|
|
|
for (int row = 0; row < model->rowCount({}); ++row) {
|
|
|
|
for (int col = 0; col < model->columnCount({}); ++col) {
|
|
|
|
QModelIndex index = model->index(row, col);
|
|
|
|
text += model->data(index).value<QString>();
|
|
|
|
text += '\t';
|
|
|
|
}
|
|
|
|
text += '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
clipboard->setText(text);
|
|
|
|
}
|