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