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.
|
|
|
|
|
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>
|
|
|
|
#include <QVBoxLayout>
|
2014-05-18 17:59:36 +00:00
|
|
|
#include <QTreeView>
|
2014-08-24 15:23:02 +00:00
|
|
|
#include <QSpinBox>
|
|
|
|
#include <QComboBox>
|
2014-05-18 17:59:36 +00:00
|
|
|
|
2014-08-24 12:39:52 +00:00
|
|
|
#include "video_core/pica.h"
|
|
|
|
#include "video_core/math.h"
|
|
|
|
|
|
|
|
#include "video_core/debug_utils/debug_utils.h"
|
|
|
|
|
2015-01-03 23:51:14 +00:00
|
|
|
#include "graphics_cmdlists.h"
|
2014-08-24 15:23:02 +00:00
|
|
|
|
2015-01-03 23:51:14 +00:00
|
|
|
#include "util/spinbox.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:
|
|
|
|
TextureInfoWidget(u8* src, const Pica::DebugUtils::TextureInfo& info, QWidget* parent = nullptr) : QWidget(parent) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-24 15:23:02 +00:00
|
|
|
TextureInfoDockWidget::TextureInfoDockWidget(const Pica::DebugUtils::TextureInfo& info, QWidget* parent)
|
2014-12-15 20:28:45 +00:00
|
|
|
: QDockWidget(tr("Texture 0x%1").arg(info.physical_address, 8, 16, QLatin1Char('0'))),
|
2014-08-24 15:23:02 +00:00
|
|
|
info(info) {
|
|
|
|
|
|
|
|
QWidget* main_widget = new QWidget;
|
|
|
|
|
|
|
|
QLabel* image_widget = new QLabel;
|
|
|
|
|
|
|
|
connect(this, SIGNAL(UpdatePixmap(const QPixmap&)), image_widget, SLOT(setPixmap(const QPixmap&)));
|
|
|
|
|
|
|
|
CSpinBox* phys_address_spinbox = new CSpinBox;
|
|
|
|
phys_address_spinbox->SetBase(16);
|
|
|
|
phys_address_spinbox->SetRange(0, 0xFFFFFFFF);
|
|
|
|
phys_address_spinbox->SetPrefix("0x");
|
2014-12-15 20:28:45 +00:00
|
|
|
phys_address_spinbox->SetValue(info.physical_address);
|
2014-08-24 15:23:02 +00:00
|
|
|
connect(phys_address_spinbox, SIGNAL(ValueChanged(qint64)), this, SLOT(OnAddressChanged(qint64)));
|
|
|
|
|
|
|
|
QComboBox* format_choice = new QComboBox;
|
|
|
|
format_choice->addItem(tr("RGBA8"));
|
|
|
|
format_choice->addItem(tr("RGB8"));
|
|
|
|
format_choice->addItem(tr("RGBA5551"));
|
|
|
|
format_choice->addItem(tr("RGB565"));
|
|
|
|
format_choice->addItem(tr("RGBA4"));
|
2014-12-10 20:51:00 +00:00
|
|
|
format_choice->addItem(tr("IA8"));
|
|
|
|
format_choice->addItem(tr("UNK6"));
|
|
|
|
format_choice->addItem(tr("I8"));
|
|
|
|
format_choice->addItem(tr("A8"));
|
|
|
|
format_choice->addItem(tr("IA4"));
|
|
|
|
format_choice->addItem(tr("UNK10"));
|
|
|
|
format_choice->addItem(tr("A4"));
|
2014-12-31 13:48:19 +00:00
|
|
|
format_choice->addItem(tr("ETC1"));
|
|
|
|
format_choice->addItem(tr("ETC1A4"));
|
2014-08-24 15:23:02 +00:00
|
|
|
format_choice->setCurrentIndex(static_cast<int>(info.format));
|
|
|
|
connect(format_choice, SIGNAL(currentIndexChanged(int)), this, SLOT(OnFormatChanged(int)));
|
|
|
|
|
|
|
|
QSpinBox* width_spinbox = new QSpinBox;
|
|
|
|
width_spinbox->setMaximum(65535);
|
|
|
|
width_spinbox->setValue(info.width);
|
|
|
|
connect(width_spinbox, SIGNAL(valueChanged(int)), this, SLOT(OnWidthChanged(int)));
|
|
|
|
|
|
|
|
QSpinBox* height_spinbox = new QSpinBox;
|
|
|
|
height_spinbox->setMaximum(65535);
|
|
|
|
height_spinbox->setValue(info.height);
|
|
|
|
connect(height_spinbox, SIGNAL(valueChanged(int)), this, SLOT(OnHeightChanged(int)));
|
|
|
|
|
|
|
|
QSpinBox* stride_spinbox = new QSpinBox;
|
|
|
|
stride_spinbox->setMaximum(65535 * 4);
|
|
|
|
stride_spinbox->setValue(info.stride);
|
|
|
|
connect(stride_spinbox, SIGNAL(valueChanged(int)), this, SLOT(OnStrideChanged(int)));
|
|
|
|
|
|
|
|
QVBoxLayout* main_layout = new QVBoxLayout;
|
|
|
|
main_layout->addWidget(image_widget);
|
|
|
|
|
|
|
|
{
|
|
|
|
QHBoxLayout* sub_layout = new QHBoxLayout;
|
|
|
|
sub_layout->addWidget(new QLabel(tr("Source Address:")));
|
|
|
|
sub_layout->addWidget(phys_address_spinbox);
|
|
|
|
main_layout->addLayout(sub_layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
QHBoxLayout* sub_layout = new QHBoxLayout;
|
|
|
|
sub_layout->addWidget(new QLabel(tr("Format")));
|
|
|
|
sub_layout->addWidget(format_choice);
|
|
|
|
main_layout->addLayout(sub_layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
QHBoxLayout* sub_layout = new QHBoxLayout;
|
|
|
|
sub_layout->addWidget(new QLabel(tr("Width:")));
|
|
|
|
sub_layout->addWidget(width_spinbox);
|
|
|
|
sub_layout->addStretch();
|
|
|
|
sub_layout->addWidget(new QLabel(tr("Height:")));
|
|
|
|
sub_layout->addWidget(height_spinbox);
|
|
|
|
sub_layout->addStretch();
|
|
|
|
sub_layout->addWidget(new QLabel(tr("Stride:")));
|
|
|
|
sub_layout->addWidget(stride_spinbox);
|
|
|
|
main_layout->addLayout(sub_layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
main_widget->setLayout(main_layout);
|
|
|
|
|
|
|
|
emit UpdatePixmap(ReloadPixmap());
|
|
|
|
|
|
|
|
setWidget(main_widget);
|
|
|
|
}
|
|
|
|
|
2014-12-04 18:41:03 +00:00
|
|
|
void TextureInfoDockWidget::OnAddressChanged(qint64 value) {
|
2014-12-15 20:28:45 +00:00
|
|
|
info.physical_address = value;
|
2014-08-24 15:23:02 +00:00
|
|
|
emit UpdatePixmap(ReloadPixmap());
|
|
|
|
}
|
|
|
|
|
2014-12-04 18:41:03 +00:00
|
|
|
void TextureInfoDockWidget::OnFormatChanged(int value) {
|
2014-08-24 15:23:02 +00:00
|
|
|
info.format = static_cast<Pica::Regs::TextureFormat>(value);
|
|
|
|
emit UpdatePixmap(ReloadPixmap());
|
|
|
|
}
|
|
|
|
|
2014-12-04 18:41:03 +00:00
|
|
|
void TextureInfoDockWidget::OnWidthChanged(int value) {
|
2014-08-24 15:23:02 +00:00
|
|
|
info.width = value;
|
|
|
|
emit UpdatePixmap(ReloadPixmap());
|
|
|
|
}
|
|
|
|
|
2014-12-04 18:41:03 +00:00
|
|
|
void TextureInfoDockWidget::OnHeightChanged(int value) {
|
2014-08-24 15:23:02 +00:00
|
|
|
info.height = value;
|
|
|
|
emit UpdatePixmap(ReloadPixmap());
|
|
|
|
}
|
|
|
|
|
2014-12-04 18:41:03 +00:00
|
|
|
void TextureInfoDockWidget::OnStrideChanged(int value) {
|
2014-08-24 15:23:02 +00:00
|
|
|
info.stride = value;
|
|
|
|
emit UpdatePixmap(ReloadPixmap());
|
|
|
|
}
|
|
|
|
|
2014-12-04 18:41:03 +00:00
|
|
|
QPixmap TextureInfoDockWidget::ReloadPixmap() const {
|
2014-12-15 20:28:45 +00:00
|
|
|
u8* src = Memory::GetPointer(Pica::PAddrToVAddr(info.physical_address));
|
2014-08-24 15:23:02 +00:00
|
|
|
return QPixmap::fromImage(LoadTexture(src, info));
|
|
|
|
}
|
|
|
|
|
2014-12-04 18:41:03 +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 {
|
2014-08-14 17:21:55 +00:00
|
|
|
return 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 {
|
2014-05-18 19:18:38 +00:00
|
|
|
return 2;
|
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();
|
|
|
|
|
2014-08-14 17:21:55 +00:00
|
|
|
const auto& writes = pica_trace.writes;
|
|
|
|
const Pica::CommandProcessor::CommandHeader cmd{writes[index.row()].Id()};
|
|
|
|
const u32 val{writes[index.row()].Value()};
|
|
|
|
|
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
QString content;
|
|
|
|
if (index.column() == 0) {
|
2014-12-04 20:00:06 +00:00
|
|
|
QString content = QString::fromLatin1(Pica::Regs::GetCommandName(cmd.cmd_id).c_str());
|
2014-08-14 17:21:55 +00:00
|
|
|
content.append(" ");
|
2014-12-04 20:00:06 +00:00
|
|
|
return content;
|
2014-08-14 17:21:55 +00:00
|
|
|
} else if (index.column() == 1) {
|
2014-12-04 20:00:06 +00:00
|
|
|
QString content = QString("%1 ").arg(cmd.hex, 8, 16, QLatin1Char('0'));
|
2014-08-14 17:21:55 +00:00
|
|
|
content.append(QString("%1 ").arg(val, 8, 16, QLatin1Char('0')));
|
2014-12-04 20:00:06 +00:00
|
|
|
return content;
|
2014-05-18 15:52:22 +00:00
|
|
|
}
|
2014-08-24 12:39:52 +00:00
|
|
|
} else if (role == CommandIdRole) {
|
|
|
|
return QVariant::fromValue<int>(cmd.cmd_id.Value());
|
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 {
|
2014-10-26 10:40:12 +00:00
|
|
|
switch(role) {
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
{
|
|
|
|
if (section == 0) {
|
|
|
|
return tr("Command Name");
|
|
|
|
} else if (section == 1) {
|
|
|
|
return tr("Data");
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-08-24 15:23:02 +00:00
|
|
|
#define COMMAND_IN_RANGE(cmd_id, reg_name) \
|
|
|
|
(cmd_id >= PICA_REG_INDEX(reg_name) && \
|
|
|
|
cmd_id < PICA_REG_INDEX(reg_name) + sizeof(decltype(Pica::registers.reg_name)) / 4)
|
|
|
|
|
2014-12-04 18:41:03 +00:00
|
|
|
void GPUCommandListWidget::OnCommandDoubleClicked(const QModelIndex& index) {
|
2014-12-12 17:21:58 +00:00
|
|
|
const unsigned int command_id = list_widget->model()->data(index, GPUCommandListModel::CommandIdRole).toUInt();
|
2014-12-06 18:10:08 +00:00
|
|
|
if (COMMAND_IN_RANGE(command_id, texture0) ||
|
|
|
|
COMMAND_IN_RANGE(command_id, texture1) ||
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
auto config = Pica::registers.GetTextures()[index].config;
|
|
|
|
auto format = Pica::registers.GetTextures()[index].format;
|
|
|
|
auto info = Pica::DebugUtils::TextureInfo::FromPicaRegister(config, format);
|
2014-12-04 18:41:03 +00:00
|
|
|
|
|
|
|
// TODO: Instead, emit a signal here to be caught by the main window widget.
|
|
|
|
auto main_window = static_cast<QMainWindow*>(parent());
|
2014-08-24 15:23:02 +00:00
|
|
|
main_window->tabifyDockWidget(this, new TextureInfoDockWidget(info, main_window));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-04 18:41:03 +00:00
|
|
|
void GPUCommandListWidget::SetCommandInfo(const QModelIndex& index) {
|
2014-08-24 12:39:52 +00:00
|
|
|
QWidget* new_info_widget;
|
|
|
|
|
2014-12-12 17:21:58 +00:00
|
|
|
const unsigned int command_id = list_widget->model()->data(index, GPUCommandListModel::CommandIdRole).toUInt();
|
2014-12-06 18:10:08 +00:00
|
|
|
if (COMMAND_IN_RANGE(command_id, texture0) ||
|
|
|
|
COMMAND_IN_RANGE(command_id, texture1) ||
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
auto config = Pica::registers.GetTextures()[index].config;
|
|
|
|
auto format = Pica::registers.GetTextures()[index].format;
|
|
|
|
|
|
|
|
auto info = Pica::DebugUtils::TextureInfo::FromPicaRegister(config, format);
|
2014-12-10 20:51:00 +00:00
|
|
|
u8* src = Memory::GetPointer(Pica::PAddrToVAddr(config.GetPhysicalAddress()));
|
2014-08-24 12:39:52 +00:00
|
|
|
new_info_widget = new TextureInfoWidget(src, info);
|
|
|
|
} else {
|
|
|
|
new_info_widget = new QWidget;
|
|
|
|
}
|
|
|
|
|
|
|
|
widget()->layout()->removeWidget(command_info_widget);
|
|
|
|
delete command_info_widget;
|
|
|
|
widget()->layout()->addWidget(new_info_widget);
|
|
|
|
command_info_widget = new_info_widget;
|
|
|
|
}
|
2014-08-24 15:23:02 +00:00
|
|
|
#undef COMMAND_IN_RANGE
|
2014-05-18 15:52:22 +00:00
|
|
|
|
2014-12-04 18:41:03 +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);
|
|
|
|
list_widget->setFont(QFont("monospace"));
|
|
|
|
list_widget->setRootIsDecorated(false);
|
2014-05-18 17:59:36 +00:00
|
|
|
|
2014-08-24 12:39:52 +00:00
|
|
|
connect(list_widget->selectionModel(), SIGNAL(currentChanged(const QModelIndex&,const QModelIndex&)),
|
|
|
|
this, SLOT(SetCommandInfo(const QModelIndex&)));
|
2014-08-24 15:23:02 +00:00
|
|
|
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"));
|
2014-05-18 17:59:36 +00:00
|
|
|
|
2014-08-14 17:21:55 +00:00
|
|
|
connect(toggle_tracing, SIGNAL(clicked()), this, SLOT(OnToggleTracing()));
|
|
|
|
connect(this, SIGNAL(TracingFinished(const Pica::DebugUtils::PicaTrace&)),
|
|
|
|
model, SLOT(OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace&)));
|
2014-05-18 15:52:22 +00:00
|
|
|
|
2014-08-24 12:39:52 +00:00
|
|
|
command_info_widget = new QWidget;
|
|
|
|
|
2014-08-14 17:21:55 +00:00
|
|
|
QVBoxLayout* main_layout = new QVBoxLayout;
|
|
|
|
main_layout->addWidget(list_widget);
|
|
|
|
main_layout->addWidget(toggle_tracing);
|
2014-08-24 12:39:52 +00:00
|
|
|
main_layout->addWidget(command_info_widget);
|
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
|
|
|
}
|