1
0
Fork 0
forked from suyu/suyu

Merge pull request #2349 from lioncash/surface

yuzu/debugger/graphics/graphics_surface: General cleanup
This commit is contained in:
bunnei 2019-04-05 23:33:45 -04:00 committed by GitHub
commit d9ee5b874c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,6 +7,7 @@
#include <QDebug> #include <QDebug>
#include <QFileDialog> #include <QFileDialog>
#include <QLabel> #include <QLabel>
#include <QMessageBox>
#include <QMouseEvent> #include <QMouseEvent>
#include <QPushButton> #include <QPushButton>
#include <QScrollArea> #include <QScrollArea>
@ -95,50 +96,91 @@ GraphicsSurfaceWidget::GraphicsSurfaceWidget(std::shared_ptr<Tegra::DebugContext
surface_picker_y_control = new QSpinBox; surface_picker_y_control = new QSpinBox;
surface_picker_y_control->setRange(0, max_dimension - 1); surface_picker_y_control->setRange(0, max_dimension - 1);
surface_format_control = new QComboBox; // clang-format off
// Color formats sorted by Maxwell texture format index // Color formats sorted by Maxwell texture format index
surface_format_control->addItem(tr("None")); const QStringList surface_formats{
surface_format_control->addItem(tr("Unknown")); tr("None"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("R32_G32_B32_A32"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("R32_G32_B32"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("R16_G16_B16_A16"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("R32_G32"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("R32_B24G8"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("ETC2_RGB"),
surface_format_control->addItem(tr("A8R8G8B8")); QStringLiteral("X8B8G8R8"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("A8R8G8B8"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("A2B10G10R10"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("ETC2_RGB_PTA"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("ETC2_RGBA"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("R16_G16"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("G8R24"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("G24R8"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("R32"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("BC6H_SF16"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("BC6H_UF16"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("A4B4G4R4"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("A5B5G5R1"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("A1B5G5R5"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("B5G6R5"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("B6G5R5"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("BC7U"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("G8R8"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("EAC"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("EACX2"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("R16"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("Y8_VIDEO"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("R8"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("G4R4"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("R1"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("E5B9G9R9_SHAREDEXP"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("BF10GF11RF11"),
surface_format_control->addItem(tr("Unknown")); QStringLiteral("G8B8G8R8"),
surface_format_control->addItem(tr("DXT1")); QStringLiteral("B8G8R8G8"),
surface_format_control->addItem(tr("DXT23")); QStringLiteral("DXT1"),
surface_format_control->addItem(tr("DXT45")); QStringLiteral("DXT23"),
surface_format_control->addItem(tr("DXN1")); QStringLiteral("DXT45"),
surface_format_control->addItem(tr("DXN2")); QStringLiteral("DXN1"),
QStringLiteral("DXN2"),
QStringLiteral("Z24S8"),
QStringLiteral("X8Z24"),
QStringLiteral("S8Z24"),
QStringLiteral("X4V4Z24__COV4R4V"),
QStringLiteral("X4V4Z24__COV8R8V"),
QStringLiteral("V8Z24__COV4R12V"),
QStringLiteral("ZF32"),
QStringLiteral("ZF32_X24S8"),
QStringLiteral("X8Z24_X20V4S8__COV4R4V"),
QStringLiteral("X8Z24_X20V4S8__COV8R8V"),
QStringLiteral("ZF32_X20V4X8__COV4R4V"),
QStringLiteral("ZF32_X20V4X8__COV8R8V"),
QStringLiteral("ZF32_X20V4S8__COV4R4V"),
QStringLiteral("ZF32_X20V4S8__COV8R8V"),
QStringLiteral("X8Z24_X16V8S8__COV4R12V"),
QStringLiteral("ZF32_X16V8X8__COV4R12V"),
QStringLiteral("ZF32_X16V8S8__COV4R12V"),
QStringLiteral("Z16"),
QStringLiteral("V8Z24__COV8R24V"),
QStringLiteral("X8Z24_X16V8S8__COV8R24V"),
QStringLiteral("ZF32_X16V8X8__COV8R24V"),
QStringLiteral("ZF32_X16V8S8__COV8R24V"),
QStringLiteral("ASTC_2D_4X4"),
QStringLiteral("ASTC_2D_5X5"),
QStringLiteral("ASTC_2D_6X6"),
QStringLiteral("ASTC_2D_8X8"),
QStringLiteral("ASTC_2D_10X10"),
QStringLiteral("ASTC_2D_12X12"),
QStringLiteral("ASTC_2D_5X4"),
QStringLiteral("ASTC_2D_6X5"),
QStringLiteral("ASTC_2D_8X6"),
QStringLiteral("ASTC_2D_10X8"),
QStringLiteral("ASTC_2D_12X10"),
QStringLiteral("ASTC_2D_8X5"),
QStringLiteral("ASTC_2D_10X5"),
QStringLiteral("ASTC_2D_10X6"),
};
// clang-format on
surface_format_control = new QComboBox;
surface_format_control->addItems(surface_formats);
surface_info_label = new QLabel(); surface_info_label = new QLabel();
surface_info_label->setWordWrap(true); surface_info_label->setWordWrap(true);
@ -157,22 +199,20 @@ GraphicsSurfaceWidget::GraphicsSurfaceWidget(std::shared_ptr<Tegra::DebugContext
// Connections // Connections
connect(this, &GraphicsSurfaceWidget::Update, this, &GraphicsSurfaceWidget::OnUpdate); connect(this, &GraphicsSurfaceWidget::Update, this, &GraphicsSurfaceWidget::OnUpdate);
connect(surface_source_list, connect(surface_source_list, qOverload<int>(&QComboBox::currentIndexChanged), this,
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&GraphicsSurfaceWidget::OnSurfaceSourceChanged); &GraphicsSurfaceWidget::OnSurfaceSourceChanged);
connect(surface_address_control, &CSpinBox::ValueChanged, this, connect(surface_address_control, &CSpinBox::ValueChanged, this,
&GraphicsSurfaceWidget::OnSurfaceAddressChanged); &GraphicsSurfaceWidget::OnSurfaceAddressChanged);
connect(surface_width_control, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), connect(surface_width_control, qOverload<int>(&QSpinBox::valueChanged), this,
this, &GraphicsSurfaceWidget::OnSurfaceWidthChanged); &GraphicsSurfaceWidget::OnSurfaceWidthChanged);
connect(surface_height_control, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), connect(surface_height_control, qOverload<int>(&QSpinBox::valueChanged), this,
this, &GraphicsSurfaceWidget::OnSurfaceHeightChanged); &GraphicsSurfaceWidget::OnSurfaceHeightChanged);
connect(surface_format_control, connect(surface_format_control, qOverload<int>(&QComboBox::currentIndexChanged), this,
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&GraphicsSurfaceWidget::OnSurfaceFormatChanged); &GraphicsSurfaceWidget::OnSurfaceFormatChanged);
connect(surface_picker_x_control, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), connect(surface_picker_x_control, qOverload<int>(&QSpinBox::valueChanged), this,
this, &GraphicsSurfaceWidget::OnSurfacePickerXChanged); &GraphicsSurfaceWidget::OnSurfacePickerXChanged);
connect(surface_picker_y_control, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), connect(surface_picker_y_control, qOverload<int>(&QSpinBox::valueChanged), this,
this, &GraphicsSurfaceWidget::OnSurfacePickerYChanged); &GraphicsSurfaceWidget::OnSurfacePickerYChanged);
connect(save_surface, &QPushButton::clicked, this, &GraphicsSurfaceWidget::SaveSurface); connect(save_surface, &QPushButton::clicked, this, &GraphicsSurfaceWidget::SaveSurface);
auto main_widget = new QWidget; auto main_widget = new QWidget;
@ -420,40 +460,56 @@ void GraphicsSurfaceWidget::OnUpdate() {
} }
void GraphicsSurfaceWidget::SaveSurface() { void GraphicsSurfaceWidget::SaveSurface() {
QString png_filter = tr("Portable Network Graphic (*.png)"); const QString png_filter = tr("Portable Network Graphic (*.png)");
QString bin_filter = tr("Binary data (*.bin)"); const QString bin_filter = tr("Binary data (*.bin)");
QString selectedFilter; QString selected_filter;
QString filename = QFileDialog::getSaveFileName( const QString filename = QFileDialog::getSaveFileName(
this, tr("Save Surface"), this, tr("Save Surface"),
QString("texture-0x%1.png").arg(QString::number(surface_address, 16)), QStringLiteral("texture-0x%1.png").arg(QString::number(surface_address, 16)),
QString("%1;;%2").arg(png_filter, bin_filter), &selectedFilter); QStringLiteral("%1;;%2").arg(png_filter, bin_filter), &selected_filter);
if (filename.isEmpty()) { if (filename.isEmpty()) {
// If the user canceled the dialog, don't save anything. // If the user canceled the dialog, don't save anything.
return; return;
} }
if (selectedFilter == png_filter) { if (selected_filter == png_filter) {
const QPixmap* pixmap = surface_picture_label->pixmap(); const QPixmap* const pixmap = surface_picture_label->pixmap();
ASSERT_MSG(pixmap != nullptr, "No pixmap set"); ASSERT_MSG(pixmap != nullptr, "No pixmap set");
QFile file(filename); QFile file{filename};
file.open(QIODevice::WriteOnly); if (!file.open(QIODevice::WriteOnly)) {
if (pixmap) QMessageBox::warning(this, tr("Error"), tr("Failed to open file '%1'").arg(filename));
pixmap->save(&file, "PNG"); return;
} else if (selectedFilter == bin_filter) { }
auto& gpu = Core::System::GetInstance().GPU();
std::optional<VAddr> address = gpu.MemoryManager().GpuToCpuAddress(surface_address);
const u8* buffer = Memory::GetPointer(*address); if (!pixmap->save(&file, "PNG")) {
QMessageBox::warning(this, tr("Error"),
tr("Failed to save surface data to file '%1'").arg(filename));
}
} else if (selected_filter == bin_filter) {
auto& gpu = Core::System::GetInstance().GPU();
const std::optional<VAddr> address = gpu.MemoryManager().GpuToCpuAddress(surface_address);
const u8* const buffer = Memory::GetPointer(*address);
ASSERT_MSG(buffer != nullptr, "Memory not accessible"); ASSERT_MSG(buffer != nullptr, "Memory not accessible");
QFile file(filename); QFile file{filename};
file.open(QIODevice::WriteOnly); if (!file.open(QIODevice::WriteOnly)) {
int size = surface_width * surface_height * Tegra::Texture::BytesPerPixel(surface_format); QMessageBox::warning(this, tr("Error"), tr("Failed to open file '%1'").arg(filename));
QByteArray data(reinterpret_cast<const char*>(buffer), size); return;
file.write(data); }
const int size =
surface_width * surface_height * Tegra::Texture::BytesPerPixel(surface_format);
const QByteArray data(reinterpret_cast<const char*>(buffer), size);
if (file.write(data) != data.size()) {
QMessageBox::warning(
this, tr("Error"),
tr("Failed to completely write surface data to file. The saved data will "
"likely be corrupt."));
}
} else { } else {
UNREACHABLE_MSG("Unhandled filter selected"); UNREACHABLE_MSG("Unhandled filter selected");
} }