2014-05-18 11:52:22 -04:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2014-08-24 08:39:52 -04:00
|
|
|
#include <QLabel>
|
2014-08-14 13:21:55 -04:00
|
|
|
#include <QListView>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QVBoxLayout>
|
2014-05-18 13:59:36 -04:00
|
|
|
#include <QTreeView>
|
2014-05-18 11:52:22 -04:00
|
|
|
|
2014-08-14 13:21:55 -04:00
|
|
|
#include "graphics_cmdlists.hxx"
|
2014-05-18 13:59:36 -04:00
|
|
|
|
2014-08-24 08:39:52 -04:00
|
|
|
#include "video_core/pica.h"
|
|
|
|
#include "video_core/math.h"
|
|
|
|
|
|
|
|
#include "video_core/debug_utils/debug_utils.h"
|
|
|
|
|
|
|
|
class TextureInfoWidget : public QWidget {
|
|
|
|
public:
|
|
|
|
TextureInfoWidget(u8* src, const Pica::DebugUtils::TextureInfo& info, QWidget* parent = nullptr) : QWidget(parent) {
|
|
|
|
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) {
|
|
|
|
Math::Vec4<u8> color = Pica::DebugUtils::LookupTexture(src, x, y, info);
|
|
|
|
decoded_image.setPixel(x, y, qRgba(color.r(), color.g(), color.b(), color.a()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QLabel* image_widget = new QLabel;
|
|
|
|
QPixmap image_pixmap = QPixmap::fromImage(decoded_image);
|
|
|
|
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-14 13:21:55 -04:00
|
|
|
GPUCommandListModel::GPUCommandListModel(QObject* parent) : QAbstractListModel(parent)
|
2014-05-18 13:59:36 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-05-18 11:52:22 -04:00
|
|
|
int GPUCommandListModel::rowCount(const QModelIndex& parent) const
|
|
|
|
{
|
2014-08-14 13:21:55 -04:00
|
|
|
return pica_trace.writes.size();
|
2014-05-18 13:59:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int GPUCommandListModel::columnCount(const QModelIndex& parent) const
|
|
|
|
{
|
2014-05-18 15:18:38 -04:00
|
|
|
return 2;
|
2014-05-18 11:52:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant GPUCommandListModel::data(const QModelIndex& index, int role) const
|
|
|
|
{
|
|
|
|
if (!index.isValid())
|
|
|
|
return QVariant();
|
|
|
|
|
2014-08-14 13:21:55 -04: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) {
|
|
|
|
content = QString::fromLatin1(Pica::Regs::GetCommandName(cmd.cmd_id).c_str());
|
|
|
|
content.append(" ");
|
|
|
|
} else if (index.column() == 1) {
|
|
|
|
content.append(QString("%1 ").arg(cmd.hex, 8, 16, QLatin1Char('0')));
|
|
|
|
content.append(QString("%1 ").arg(val, 8, 16, QLatin1Char('0')));
|
2014-05-18 11:52:22 -04:00
|
|
|
}
|
2014-08-14 13:21:55 -04:00
|
|
|
|
|
|
|
return QVariant(content);
|
2014-08-24 08:39:52 -04:00
|
|
|
} else if (role == CommandIdRole) {
|
|
|
|
return QVariant::fromValue<int>(cmd.cmd_id.Value());
|
2014-05-18 11:52:22 -04:00
|
|
|
}
|
2014-05-18 13:59:36 -04:00
|
|
|
|
2014-05-18 11:52:22 -04:00
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2014-10-26 06:40:12 -04:00
|
|
|
QVariant GPUCommandListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
|
|
|
switch(role) {
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
{
|
|
|
|
if (section == 0) {
|
|
|
|
return tr("Command Name");
|
|
|
|
} else if (section == 1) {
|
|
|
|
return tr("Data");
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2014-08-14 13:21:55 -04:00
|
|
|
void GPUCommandListModel::OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace& trace)
|
2014-05-18 11:52:22 -04:00
|
|
|
{
|
2014-08-14 13:21:55 -04:00
|
|
|
beginResetModel();
|
|
|
|
|
|
|
|
pica_trace = trace;
|
|
|
|
|
|
|
|
endResetModel();
|
2014-05-18 11:52:22 -04:00
|
|
|
}
|
|
|
|
|
2014-08-24 08:39:52 -04:00
|
|
|
void GPUCommandListWidget::SetCommandInfo(const QModelIndex& index)
|
|
|
|
{
|
|
|
|
QWidget* new_info_widget;
|
|
|
|
|
|
|
|
#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)
|
|
|
|
const int command_id = list_widget->model()->data(index, GPUCommandListModel::CommandIdRole).toInt();
|
|
|
|
if (COMMAND_IN_RANGE(command_id, texture0)) {
|
|
|
|
u8* src = Memory::GetPointer(Pica::registers.texture0.GetPhysicalAddress());
|
|
|
|
Pica::DebugUtils::TextureInfo info;
|
|
|
|
info.width = Pica::registers.texture0.width;
|
|
|
|
info.height = Pica::registers.texture0.height;
|
|
|
|
info.stride = 3 * Pica::registers.texture0.width;
|
|
|
|
info.format = Pica::registers.texture0_format;
|
|
|
|
new_info_widget = new TextureInfoWidget(src, info);
|
|
|
|
} else {
|
|
|
|
new_info_widget = new QWidget;
|
|
|
|
}
|
|
|
|
#undef COMMAND_IN_RANGE
|
|
|
|
|
|
|
|
widget()->layout()->removeWidget(command_info_widget);
|
|
|
|
delete command_info_widget;
|
|
|
|
widget()->layout()->addWidget(new_info_widget);
|
|
|
|
command_info_widget = new_info_widget;
|
|
|
|
}
|
2014-05-18 11:52:22 -04:00
|
|
|
|
2014-08-14 13:21:55 -04:00
|
|
|
GPUCommandListWidget::GPUCommandListWidget(QWidget* parent) : QDockWidget(tr("Pica Command List"), parent)
|
2014-05-18 11:52:22 -04:00
|
|
|
{
|
2014-08-24 08:39:52 -04:00
|
|
|
setObjectName("Pica Command List");
|
2014-08-14 13:21:55 -04:00
|
|
|
GPUCommandListModel* model = new GPUCommandListModel(this);
|
2014-05-18 11:52:22 -04:00
|
|
|
|
2014-08-14 13:21:55 -04:00
|
|
|
QWidget* main_widget = new QWidget;
|
2014-05-18 13:59:36 -04:00
|
|
|
|
2014-08-24 08:39:52 -04:00
|
|
|
list_widget = new QTreeView;
|
2014-08-14 13:21:55 -04:00
|
|
|
list_widget->setModel(model);
|
|
|
|
list_widget->setFont(QFont("monospace"));
|
|
|
|
list_widget->setRootIsDecorated(false);
|
2014-05-18 13:59:36 -04:00
|
|
|
|
2014-08-24 08:39:52 -04:00
|
|
|
connect(list_widget->selectionModel(), SIGNAL(currentChanged(const QModelIndex&,const QModelIndex&)),
|
|
|
|
this, SLOT(SetCommandInfo(const QModelIndex&)));
|
|
|
|
|
|
|
|
|
2014-10-26 06:40:12 -04:00
|
|
|
toggle_tracing = new QPushButton(tr("Start Tracing"));
|
2014-05-18 13:59:36 -04:00
|
|
|
|
2014-08-14 13:21:55 -04: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 11:52:22 -04:00
|
|
|
|
2014-08-24 08:39:52 -04:00
|
|
|
command_info_widget = new QWidget;
|
|
|
|
|
2014-08-14 13:21:55 -04:00
|
|
|
QVBoxLayout* main_layout = new QVBoxLayout;
|
|
|
|
main_layout->addWidget(list_widget);
|
|
|
|
main_layout->addWidget(toggle_tracing);
|
2014-08-24 08:39:52 -04:00
|
|
|
main_layout->addWidget(command_info_widget);
|
2014-08-14 13:21:55 -04:00
|
|
|
main_widget->setLayout(main_layout);
|
|
|
|
|
|
|
|
setWidget(main_widget);
|
2014-05-18 11:52:22 -04:00
|
|
|
}
|
|
|
|
|
2014-08-14 13:21:55 -04:00
|
|
|
void GPUCommandListWidget::OnToggleTracing()
|
2014-05-18 11:52:22 -04:00
|
|
|
{
|
2014-08-14 13:21:55 -04:00
|
|
|
if (!Pica::DebugUtils::IsPicaTracing()) {
|
|
|
|
Pica::DebugUtils::StartPicaTracing();
|
2014-10-26 06:40:12 -04:00
|
|
|
toggle_tracing->setText(tr("Stop Tracing"));
|
2014-08-14 13:21:55 -04:00
|
|
|
} else {
|
|
|
|
pica_trace = Pica::DebugUtils::FinishPicaTracing();
|
|
|
|
emit TracingFinished(*pica_trace);
|
2014-10-26 06:40:12 -04:00
|
|
|
toggle_tracing->setText(tr("Start Tracing"));
|
2014-08-14 13:21:55 -04:00
|
|
|
}
|
2014-05-18 11:52:22 -04:00
|
|
|
}
|