video_core: Refactor GPU interface (#7272)

* video_core: Refactor GPU interface

* citra_qt: Better debug widget lifetime
This commit is contained in:
GPUCode 2023-12-28 12:46:57 +02:00 committed by GitHub
parent 602f4f60d8
commit 2bb7f89c30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
167 changed files with 4172 additions and 4866 deletions

View file

@ -22,9 +22,9 @@
#include "input_common/main.h"
#include "input_common/motion_emu.h"
#include "video_core/custom_textures/custom_tex_manager.h"
#include "video_core/gpu.h"
#include "video_core/renderer_base.h"
#include "video_core/renderer_software/renderer_software.h"
#include "video_core/video_core.h"
#ifdef HAS_OPENGL
#include <glad/glad.h>
@ -73,7 +73,7 @@ void EmuThread::run() {
emit LoadProgress(VideoCore::LoadCallbackStage::Prepare, 0, 0);
system.Renderer().Rasterizer()->LoadDiskResources(
system.GPU().Renderer().Rasterizer()->LoadDiskResources(
stop_run, [this](VideoCore::LoadCallbackStage stage, std::size_t value, std::size_t total) {
emit LoadProgress(stage, value, total);
});
@ -284,9 +284,7 @@ public:
}
context->MakeCurrent();
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
if (VideoCore::g_renderer) {
VideoCore::g_renderer->TryPresent(100, is_secondary);
}
system.GPU().Renderer().TryPresent(100, is_secondary);
context->SwapBuffers();
glFinish();
}
@ -367,7 +365,7 @@ struct SoftwareRenderWidget : public RenderWidget {
}
QImage LoadFramebuffer(VideoCore::ScreenId screen_id) {
const auto& renderer = static_cast<SwRenderer::RendererSoftware&>(system.Renderer());
const auto& renderer = static_cast<SwRenderer::RendererSoftware&>(system.GPU().Renderer());
const auto& info = renderer.Screen(screen_id);
const int width = static_cast<int>(info.width);
const int height = static_cast<int>(info.height);
@ -678,13 +676,14 @@ void GRenderWindow::ReleaseRenderTarget() {
}
void GRenderWindow::CaptureScreenshot(u32 res_scale, const QString& screenshot_path) {
auto& renderer = system.GPU().Renderer();
if (res_scale == 0) {
res_scale = system.Renderer().GetResolutionScaleFactor();
res_scale = renderer.GetResolutionScaleFactor();
}
const auto layout{Layout::FrameLayoutFromResolutionScale(res_scale, is_secondary)};
screenshot_image = QImage(QSize(layout.width, layout.height), QImage::Format_RGB32);
system.Renderer().RequestScreenshot(
renderer.RequestScreenshot(
screenshot_image.bits(),
[this, screenshot_path](bool invert_y) {
const std::string std_screenshot_path = screenshot_path.toStdString();

View file

@ -20,7 +20,6 @@ ConfigureGraphics::ConfigureGraphics(std::span<const QString> physical_devices,
ui->physical_device_combo->addItem(name);
}
ui->toggle_vsync_new->setEnabled(!is_powered_on);
ui->graphics_api_combo->setEnabled(!is_powered_on);
ui->physical_device_combo->setEnabled(!is_powered_on);
ui->toggle_async_shaders->setEnabled(!is_powered_on);

View file

@ -5,8 +5,8 @@
#include <QListView>
#include "citra_qt/debugger/graphics/graphics.h"
#include "citra_qt/util/util.h"
extern GraphicsDebugger g_debugger;
#include "core/core.h"
#include "video_core/gpu.h"
GPUCommandStreamItemModel::GPUCommandStreamItemModel(QObject* parent)
: QAbstractListModel(parent), command_count(0) {
@ -19,19 +19,19 @@ int GPUCommandStreamItemModel::rowCount([[maybe_unused]] const QModelIndex& pare
}
QVariant GPUCommandStreamItemModel::data(const QModelIndex& index, int role) const {
if (!index.isValid())
if (!index.isValid() || !GetDebugger())
return QVariant();
int command_index = index.row();
const Service::GSP::Command& command = GetDebugger()->ReadGXCommandHistory(command_index);
if (role == Qt::DisplayRole) {
std::map<Service::GSP::CommandId, const char*> command_names = {
{Service::GSP::CommandId::REQUEST_DMA, "REQUEST_DMA"},
{Service::GSP::CommandId::SUBMIT_GPU_CMDLIST, "SUBMIT_GPU_CMDLIST"},
{Service::GSP::CommandId::SET_MEMORY_FILL, "SET_MEMORY_FILL"},
{Service::GSP::CommandId::SET_DISPLAY_TRANSFER, "SET_DISPLAY_TRANSFER"},
{Service::GSP::CommandId::SET_TEXTURE_COPY, "SET_TEXTURE_COPY"},
{Service::GSP::CommandId::CACHE_FLUSH, "CACHE_FLUSH"},
{Service::GSP::CommandId::RequestDma, "REQUEST_DMA"},
{Service::GSP::CommandId::SubmitCmdList, "SUBMIT_GPU_CMDLIST"},
{Service::GSP::CommandId::MemoryFill, "SET_MEMORY_FILL"},
{Service::GSP::CommandId::DisplayTransfer, "SET_DISPLAY_TRANSFER"},
{Service::GSP::CommandId::TextureCopy, "SET_TEXTURE_COPY"},
{Service::GSP::CommandId::CacheFlush, "CACHE_FLUSH"},
};
const u32* command_data = reinterpret_cast<const u32*>(&command);
QString str = QStringLiteral("%1 %2 %3 %4 %5 %6 %7 %8 %9")
@ -63,8 +63,8 @@ void GPUCommandStreamItemModel::OnGXCommandFinishedInternal(int total_command_co
emit dataChanged(index(prev_command_count, 0), index(total_command_count - 1, 0));
}
GPUCommandStreamWidget::GPUCommandStreamWidget(QWidget* parent)
: QDockWidget(tr("Graphics Debugger"), parent), model(this) {
GPUCommandStreamWidget::GPUCommandStreamWidget(Core::System& system_, QWidget* parent)
: QDockWidget(tr("Graphics Debugger"), parent), system{system_}, model(this) {
setObjectName(QStringLiteral("GraphicsDebugger"));
auto* command_list = new QListView;
@ -74,12 +74,26 @@ GPUCommandStreamWidget::GPUCommandStreamWidget(QWidget* parent)
setWidget(command_list);
}
void GPUCommandStreamWidget::Register() {
auto& debugger = system.GPU().Debugger();
debugger.RegisterObserver(&model);
}
void GPUCommandStreamWidget::Unregister() {
auto& debugger = system.GPU().Debugger();
debugger.UnregisterObserver(&model);
}
void GPUCommandStreamWidget::showEvent(QShowEvent* event) {
g_debugger.RegisterObserver(&model);
if (system.IsPoweredOn()) {
Register();
}
QDockWidget::showEvent(event);
}
void GPUCommandStreamWidget::hideEvent(QHideEvent* event) {
g_debugger.UnregisterObserver(&model);
if (system.IsPoweredOn()) {
Unregister();
}
QDockWidget::hideEvent(event);
}

View file

@ -8,8 +8,12 @@
#include <QDockWidget>
#include "video_core/gpu_debugger.h"
namespace Core {
class System;
}
class GPUCommandStreamItemModel : public QAbstractListModel,
public GraphicsDebugger::DebuggerObserver {
public VideoCore::GraphicsDebugger::DebuggerObserver {
Q_OBJECT
public:
@ -35,12 +39,16 @@ class GPUCommandStreamWidget : public QDockWidget {
Q_OBJECT
public:
GPUCommandStreamWidget(QWidget* parent = nullptr);
GPUCommandStreamWidget(Core::System& system, QWidget* parent = nullptr);
void Register();
void Unregister();
protected:
void showEvent(QShowEvent* event) override;
void hideEvent(QHideEvent* event) override;
private:
Core::System& system;
GPUCommandStreamItemModel model;
};

View file

@ -18,7 +18,8 @@ BreakPointObserverDock::BreakPointObserverDock(std::shared_ptr<Pica::DebugContex
&BreakPointObserverDock::OnBreakPointHit, Qt::BlockingQueuedConnection);
}
void BreakPointObserverDock::OnPicaBreakPointHit(Pica::DebugContext::Event event, void* data) {
void BreakPointObserverDock::OnPicaBreakPointHit(Pica::DebugContext::Event event,
const void* data) {
emit BreakPointHit(event, data);
}

View file

@ -20,14 +20,14 @@ public:
BreakPointObserverDock(std::shared_ptr<Pica::DebugContext> debug_context, const QString& title,
QWidget* parent = nullptr);
void OnPicaBreakPointHit(Pica::DebugContext::Event event, void* data) override;
void OnPicaBreakPointHit(Pica::DebugContext::Event event, const void* data) override;
void OnPicaResume() override;
signals:
void Resumed();
void BreakPointHit(Pica::DebugContext::Event event, void* data);
void BreakPointHit(Pica::DebugContext::Event event, const void* data);
private:
virtual void OnBreakPointHit(Pica::DebugContext::Event event, void* data) = 0;
virtual void OnBreakPointHit(Pica::DebugContext::Event event, const void* data) = 0;
virtual void OnResumed() = 0;
};

View file

@ -191,12 +191,12 @@ GraphicsBreakPointsWidget::GraphicsBreakPointsWidget(
setWidget(main_widget);
}
void GraphicsBreakPointsWidget::OnPicaBreakPointHit(Event event, void* data) {
void GraphicsBreakPointsWidget::OnPicaBreakPointHit(Event event, const void* data) {
// Process in GUI thread
emit BreakPointHit(event, data);
}
void GraphicsBreakPointsWidget::OnBreakPointHit(Pica::DebugContext::Event event, void* data) {
void GraphicsBreakPointsWidget::OnBreakPointHit(Pica::DebugContext::Event event, const void* data) {
status_text->setText(tr("Emulation halted at breakpoint"));
resume_button->setEnabled(true);
}

View file

@ -23,16 +23,16 @@ public:
explicit GraphicsBreakPointsWidget(std::shared_ptr<Pica::DebugContext> debug_context,
QWidget* parent = nullptr);
void OnPicaBreakPointHit(Pica::DebugContext::Event event, void* data) override;
void OnPicaBreakPointHit(Pica::DebugContext::Event event, const void* data) override;
void OnPicaResume() override;
signals:
void Resumed();
void BreakPointHit(Pica::DebugContext::Event event, void* data);
void BreakPointHit(Pica::DebugContext::Event event, const void* data);
void BreakPointsChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
private:
void OnBreakPointHit(Pica::DebugContext::Event event, void* data);
void OnBreakPointHit(Pica::DebugContext::Event event, const void* data);
void OnItemDoubleClicked(const QModelIndex&);
void OnResumeRequested();
void OnResumed();

View file

@ -19,8 +19,8 @@
#include "core/core.h"
#include "core/memory.h"
#include "video_core/debug_utils/debug_utils.h"
#include "video_core/pica_state.h"
#include "video_core/regs.h"
#include "video_core/gpu.h"
#include "video_core/pica/pica_core.h"
#include "video_core/texture/texture_decode.h"
namespace {
@ -73,7 +73,7 @@ QVariant GPUCommandListModel::data(const QModelIndex& index, int role) const {
if (role == Qt::DisplayRole) {
switch (index.column()) {
case 0:
return QString::fromLatin1(Pica::Regs::GetRegisterName(write.cmd_id));
return QString::fromLatin1(Pica::RegsInternal::GetRegisterName(write.cmd_id));
case 1:
return QStringLiteral("%1").arg(write.cmd_id, 3, 16, QLatin1Char('0'));
case 2:
@ -119,8 +119,7 @@ void GPUCommandListModel::OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace&
}
#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::g_state.regs.reg_name)) / 4)
(cmd_id >= PICA_REG_INDEX(reg_name) && cmd_id <= PICA_REG_INDEX(reg_name))
void GPUCommandListWidget::OnCommandDoubleClicked(const QModelIndex& index) {
const unsigned int command_id =
@ -147,13 +146,13 @@ void GPUCommandListWidget::OnCommandDoubleClicked(const QModelIndex& index) {
void GPUCommandListWidget::SetCommandInfo(const QModelIndex& index) {
QWidget* new_info_widget = nullptr;
const unsigned int command_id =
const u32 command_id =
list_widget->model()->data(index, GPUCommandListModel::CommandIdRole).toUInt();
if (COMMAND_IN_RANGE(command_id, texturing.texture0) ||
COMMAND_IN_RANGE(command_id, texturing.texture1) ||
COMMAND_IN_RANGE(command_id, texturing.texture2)) {
unsigned texture_index;
u32 texture_index;
if (COMMAND_IN_RANGE(command_id, texturing.texture0)) {
texture_index = 0;
} else if (COMMAND_IN_RANGE(command_id, texturing.texture1)) {
@ -162,7 +161,8 @@ void GPUCommandListWidget::SetCommandInfo(const QModelIndex& index) {
texture_index = 2;
}
const auto texture = Pica::g_state.regs.texturing.GetTextures()[texture_index];
auto& pica = system.GPU().PicaCore();
const auto texture = pica.regs.internal.texturing.GetTextures()[texture_index];
const auto config = texture.config;
const auto format = texture.format;

View file

@ -15,10 +15,10 @@
#include "citra_qt/debugger/graphics/graphics_surface.h"
#include "citra_qt/util/spinbox.h"
#include "common/color.h"
#include "core/core.h"
#include "core/memory.h"
#include "video_core/pica_state.h"
#include "video_core/regs_framebuffer.h"
#include "video_core/regs_texturing.h"
#include "video_core/gpu.h"
#include "video_core/pica/pica_core.h"
#include "video_core/texture/texture_decode.h"
#include "video_core/utils.h"
@ -49,10 +49,10 @@ void SurfacePicture::mouseMoveEvent(QMouseEvent* event) {
mousePressEvent(event);
}
GraphicsSurfaceWidget::GraphicsSurfaceWidget(Memory::MemorySystem& memory_,
GraphicsSurfaceWidget::GraphicsSurfaceWidget(Core::System& system_,
std::shared_ptr<Pica::DebugContext> debug_context,
QWidget* parent)
: BreakPointObserverDock(debug_context, tr("Pica Surface Viewer"), parent), memory{memory_},
: BreakPointObserverDock(debug_context, tr("Pica Surface Viewer"), parent), system{system_},
surface_source(Source::ColorBuffer) {
setObjectName(QStringLiteral("PicaSurface"));
@ -214,7 +214,7 @@ GraphicsSurfaceWidget::GraphicsSurfaceWidget(Memory::MemorySystem& memory_,
}
}
void GraphicsSurfaceWidget::OnBreakPointHit(Pica::DebugContext::Event event, void* data) {
void GraphicsSurfaceWidget::OnBreakPointHit(Pica::DebugContext::Event event, const void* data) {
emit Update();
widget()->setEnabled(true);
}
@ -289,7 +289,7 @@ void GraphicsSurfaceWidget::Pick(int x, int y) {
return;
}
const u8* buffer = memory.GetPhysicalPointer(surface_address);
const u8* buffer = system.Memory().GetPhysicalPointer(surface_address);
if (!buffer) {
surface_info_label->setText(tr("(unable to access pixel data)"));
surface_info_label->setAlignment(Qt::AlignCenter);
@ -410,13 +410,13 @@ void GraphicsSurfaceWidget::Pick(int x, int y) {
void GraphicsSurfaceWidget::OnUpdate() {
QPixmap pixmap;
const auto& regs = system.GPU().PicaCore().regs.internal;
switch (surface_source) {
case Source::ColorBuffer: {
// TODO: Store a reference to the registers in the debug context instead of accessing them
// directly...
const auto& framebuffer = Pica::g_state.regs.framebuffer.framebuffer;
const auto& framebuffer = regs.framebuffer.framebuffer;
surface_address = framebuffer.GetColorBufferPhysicalAddress();
surface_width = framebuffer.GetWidth();
surface_height = framebuffer.GetHeight();
@ -451,8 +451,7 @@ void GraphicsSurfaceWidget::OnUpdate() {
}
case Source::DepthBuffer: {
const auto& framebuffer = Pica::g_state.regs.framebuffer.framebuffer;
const auto& framebuffer = regs.framebuffer.framebuffer;
surface_address = framebuffer.GetDepthBufferPhysicalAddress();
surface_width = framebuffer.GetWidth();
surface_height = framebuffer.GetHeight();
@ -479,8 +478,7 @@ void GraphicsSurfaceWidget::OnUpdate() {
}
case Source::StencilBuffer: {
const auto& framebuffer = Pica::g_state.regs.framebuffer.framebuffer;
const auto& framebuffer = regs.framebuffer.framebuffer;
surface_address = framebuffer.GetDepthBufferPhysicalAddress();
surface_width = framebuffer.GetWidth();
surface_height = framebuffer.GetHeight();
@ -513,7 +511,7 @@ void GraphicsSurfaceWidget::OnUpdate() {
break;
}
const auto texture = Pica::g_state.regs.texturing.GetTextures()[texture_index];
const auto texture = regs.texturing.GetTextures()[texture_index];
auto info = Pica::Texture::TextureInfo::FromPicaRegister(texture.config, texture.format);
surface_address = info.physical_address;
@ -545,7 +543,7 @@ void GraphicsSurfaceWidget::OnUpdate() {
// TODO: Implement a good way to visualize alpha components!
QImage decoded_image(surface_width, surface_height, QImage::Format_ARGB32);
const u8* buffer = memory.GetPhysicalPointer(surface_address);
const u8* buffer = system.Memory().GetPhysicalPointer(surface_address);
if (!buffer) {
surface_picture_label->hide();
@ -681,7 +679,7 @@ void GraphicsSurfaceWidget::SaveSurface() {
tr("Failed to save surface data to file '%1'").arg(filename));
}
} else if (selected_filter == bin_filter) {
const u8* const buffer = memory.GetPhysicalPointer(surface_address);
const u8* const buffer = system.Memory().GetPhysicalPointer(surface_address);
ASSERT_MSG(buffer, "Memory not accessible");
QFile file{filename};

View file

@ -14,8 +14,8 @@ class CSpinBox;
class GraphicsSurfaceWidget;
namespace Memory {
class MemorySystem;
namespace Core {
class System;
}
class SurfacePicture : public QLabel {
@ -76,7 +76,7 @@ class GraphicsSurfaceWidget : public BreakPointObserverDock {
static unsigned int NibblesPerPixel(Format format);
public:
explicit GraphicsSurfaceWidget(Memory::MemorySystem& memory,
explicit GraphicsSurfaceWidget(Core::System& system,
std::shared_ptr<Pica::DebugContext> debug_context,
QWidget* parent = nullptr);
void Pick(int x, int y);
@ -95,12 +95,12 @@ signals:
void Update();
private:
void OnBreakPointHit(Pica::DebugContext::Event event, void* data) override;
void OnBreakPointHit(Pica::DebugContext::Event event, const void* data) override;
void OnResumed() override;
void SaveSurface();
Memory::MemorySystem& memory;
Core::System& system;
QComboBox* surface_source_list;
CSpinBox* surface_address_control;
QSpinBox* surface_width_control;

View file

@ -14,14 +14,15 @@
#include <nihstro/float24.h>
#include "citra_qt/debugger/graphics/graphics_tracing.h"
#include "common/common_types.h"
#include "core/hw/gpu.h"
#include "core/hw/lcd.h"
#include "core/core.h"
#include "core/tracer/recorder.h"
#include "video_core/pica_state.h"
#include "video_core/gpu.h"
#include "video_core/pica/pica_core.h"
GraphicsTracingWidget::GraphicsTracingWidget(std::shared_ptr<Pica::DebugContext> debug_context,
GraphicsTracingWidget::GraphicsTracingWidget(Core::System& system_,
std::shared_ptr<Pica::DebugContext> debug_context,
QWidget* parent)
: BreakPointObserverDock(debug_context, tr("CiTrace Recorder"), parent) {
: BreakPointObserverDock(debug_context, tr("CiTrace Recorder"), parent), system{system_} {
setObjectName(QStringLiteral("CiTracing"));
@ -61,45 +62,46 @@ void GraphicsTracingWidget::StartRecording() {
if (!context)
return;
auto shader_binary = Pica::g_state.vs.program_code;
auto swizzle_data = Pica::g_state.vs.swizzle_data;
auto& pica = system.GPU().PicaCore();
auto shader_binary = pica.vs_setup.program_code;
auto swizzle_data = pica.vs_setup.swizzle_data;
// Encode floating point numbers to 24-bit values
// TODO: Drop this explicit conversion once we store float24 values bit-correctly internally.
std::array<u32, 4 * 16> default_attributes;
for (unsigned i = 0; i < 16; ++i) {
for (unsigned comp = 0; comp < 3; ++comp) {
default_attributes[4 * i + comp] = nihstro::to_float24(
Pica::g_state.input_default_attributes.attr[i][comp].ToFloat32());
for (u32 i = 0; i < 16; ++i) {
for (u32 comp = 0; comp < 3; ++comp) {
default_attributes[4 * i + comp] =
nihstro::to_float24(pica.input_default_attributes[i][comp].ToFloat32());
}
}
std::array<u32, 4 * 96> vs_float_uniforms;
for (unsigned i = 0; i < 96; ++i)
for (unsigned comp = 0; comp < 3; ++comp)
for (u32 i = 0; i < 96; ++i) {
for (u32 comp = 0; comp < 3; ++comp) {
vs_float_uniforms[4 * i + comp] =
nihstro::to_float24(Pica::g_state.vs.uniforms.f[i][comp].ToFloat32());
nihstro::to_float24(pica.vs_setup.uniforms.f[i][comp].ToFloat32());
}
}
CiTrace::Recorder::InitialState state;
std::copy_n((u32*)&GPU::g_regs, sizeof(GPU::g_regs) / sizeof(u32),
std::back_inserter(state.gpu_registers));
std::copy_n((u32*)&LCD::g_regs, sizeof(LCD::g_regs) / sizeof(u32),
std::back_inserter(state.lcd_registers));
std::copy_n((u32*)&Pica::g_state.regs, sizeof(Pica::g_state.regs) / sizeof(u32),
std::back_inserter(state.pica_registers));
std::copy(default_attributes.begin(), default_attributes.end(),
std::back_inserter(state.default_attributes));
std::copy(shader_binary.begin(), shader_binary.end(),
std::back_inserter(state.vs_program_binary));
std::copy(swizzle_data.begin(), swizzle_data.end(), std::back_inserter(state.vs_swizzle_data));
std::copy(vs_float_uniforms.begin(), vs_float_uniforms.end(),
std::back_inserter(state.vs_float_uniforms));
// boost::copy(TODO: Not implemented, std::back_inserter(state.gs_program_binary));
// boost::copy(TODO: Not implemented, std::back_inserter(state.gs_swizzle_data));
// boost::copy(TODO: Not implemented, std::back_inserter(state.gs_float_uniforms));
auto recorder = new CiTrace::Recorder(state);
context->recorder = std::shared_ptr<CiTrace::Recorder>(recorder);
const auto copy = [&](std::vector<u32>& dest, auto& data) {
dest.resize(sizeof(data));
std::memcpy(dest.data(), std::addressof(data), sizeof(data));
};
copy(state.pica_registers, pica.regs);
copy(state.lcd_registers, pica.regs_lcd);
copy(state.default_attributes, default_attributes);
copy(state.vs_program_binary, shader_binary);
copy(state.vs_swizzle_data, swizzle_data);
copy(state.vs_float_uniforms, vs_float_uniforms);
// copy(TODO: Not implemented, std::back_inserter(state.gs_program_binary));
// copy(TODO: Not implemented, std::back_inserter(state.gs_swizzle_data));
// copy(TODO: Not implemented, std::back_inserter(state.gs_float_uniforms));
context->recorder = std::make_shared<CiTrace::Recorder>(state);
emit SetStartTracingButtonEnabled(false);
emit SetStopTracingButtonEnabled(true);
@ -139,7 +141,7 @@ void GraphicsTracingWidget::AbortRecording() {
emit SetStartTracingButtonEnabled(true);
}
void GraphicsTracingWidget::OnBreakPointHit(Pica::DebugContext::Event event, void* data) {
void GraphicsTracingWidget::OnBreakPointHit(Pica::DebugContext::Event event, const void* data) {
widget()->setEnabled(true);
}

View file

@ -6,13 +6,18 @@
#include "citra_qt/debugger/graphics/graphics_breakpoint_observer.h"
namespace Core {
class System;
}
class EmuThread;
class GraphicsTracingWidget : public BreakPointObserverDock {
Q_OBJECT
public:
explicit GraphicsTracingWidget(std::shared_ptr<Pica::DebugContext> debug_context,
explicit GraphicsTracingWidget(Core::System& system,
std::shared_ptr<Pica::DebugContext> debug_context,
QWidget* parent = nullptr);
void OnEmulationStarting(EmuThread* emu_thread);
@ -23,11 +28,14 @@ private slots:
void StopRecording();
void AbortRecording();
void OnBreakPointHit(Pica::DebugContext::Event event, void* data) override;
void OnBreakPointHit(Pica::DebugContext::Event event, const void* data) override;
void OnResumed() override;
signals:
void SetStartTracingButtonEnabled(bool enable);
void SetStopTracingButtonEnabled(bool enable);
void SetAbortTracingButtonEnabled(bool enable);
private:
Core::System& system;
};

View file

@ -16,9 +16,9 @@
#include <QTreeView>
#include "citra_qt/debugger/graphics/graphics_vertex_shader.h"
#include "citra_qt/util/util.h"
#include "video_core/pica_state.h"
#include "video_core/shader/debug_data.h"
#include "video_core/shader/shader.h"
#include "core/core.h"
#include "video_core/gpu.h"
#include "video_core/pica/pica_core.h"
#include "video_core/shader/shader_interpreter.h"
using nihstro::Instruction;
@ -352,16 +352,14 @@ void GraphicsVertexShaderWidget::DumpShader() {
return;
}
auto& setup = Pica::g_state.vs;
auto& config = Pica::g_state.regs.vs;
Pica::DebugUtils::DumpShader(filename.toStdString(), config, setup,
Pica::g_state.regs.rasterizer.vs_output_attributes);
auto& pica = system.GPU().PicaCore();
Pica::DebugUtils::DumpShader(filename.toStdString(), pica.regs.internal.vs, pica.vs_setup,
pica.regs.internal.rasterizer.vs_output_attributes);
}
GraphicsVertexShaderWidget::GraphicsVertexShaderWidget(
std::shared_ptr<Pica::DebugContext> debug_context, QWidget* parent)
: BreakPointObserverDock(debug_context, tr("Pica Vertex Shader"), parent) {
Core::System& system_, std::shared_ptr<Pica::DebugContext> debug_context, QWidget* parent)
: BreakPointObserverDock(debug_context, tr("Pica Vertex Shader"), parent), system{system_} {
setObjectName(QStringLiteral("PicaVertexShader"));
// Clear input vertex data so that it contains valid float values in case a debug shader
@ -472,7 +470,8 @@ GraphicsVertexShaderWidget::GraphicsVertexShaderWidget(
widget()->setEnabled(false);
}
void GraphicsVertexShaderWidget::OnBreakPointHit(Pica::DebugContext::Event event, void* data) {
void GraphicsVertexShaderWidget::OnBreakPointHit(Pica::DebugContext::Event event,
const void* data) {
if (event == Pica::DebugContext::Event::VertexShaderInvocation) {
Reload(true, data);
} else {
@ -482,7 +481,7 @@ void GraphicsVertexShaderWidget::OnBreakPointHit(Pica::DebugContext::Event event
widget()->setEnabled(true);
}
void GraphicsVertexShaderWidget::Reload(bool replace_vertex_data, void* vertex_data) {
void GraphicsVertexShaderWidget::Reload(bool replace_vertex_data, const void* vertex_data) {
model->beginResetModel();
if (replace_vertex_data) {
@ -491,7 +490,7 @@ void GraphicsVertexShaderWidget::Reload(bool replace_vertex_data, void* vertex_d
for (unsigned attr = 0; attr < 16; ++attr) {
for (unsigned comp = 0; comp < 4; ++comp) {
input_data[4 * attr + comp]->setText(
QStringLiteral("%1").arg(input_vertex.attr[attr][comp].ToFloat32()));
QStringLiteral("%1").arg(input_vertex[attr][comp].ToFloat32()));
}
}
breakpoint_warning->hide();
@ -508,28 +507,27 @@ void GraphicsVertexShaderWidget::Reload(bool replace_vertex_data, void* vertex_d
// Reload shader code
info.Clear();
auto& shader_setup = Pica::g_state.vs;
auto& shader_config = Pica::g_state.regs.vs;
for (auto instr : shader_setup.program_code)
auto& pica = system.GPU().PicaCore();
for (auto instr : pica.vs_setup.program_code)
info.code.push_back({instr});
int num_attributes = shader_config.max_input_attribute_index + 1;
int num_attributes = pica.regs.internal.vs.max_input_attribute_index + 1;
for (auto pattern : shader_setup.swizzle_data) {
for (auto pattern : pica.vs_setup.swizzle_data) {
const nihstro::SwizzleInfo swizzle_info = {.pattern = nihstro::SwizzlePattern{pattern}};
info.swizzle_info.push_back(swizzle_info);
}
u32 entry_point = Pica::g_state.regs.vs.main_offset;
u32 entry_point = pica.regs.internal.vs.main_offset;
info.labels.insert({entry_point, "main"});
// Generate debug information
Pica::Shader::InterpreterEngine shader_engine;
shader_engine.SetupBatch(shader_setup, entry_point);
debug_data = shader_engine.ProduceDebugInfo(shader_setup, input_vertex, shader_config);
shader_engine.SetupBatch(pica.vs_setup, entry_point);
debug_data = shader_engine.ProduceDebugInfo(pica.vs_setup, input_vertex, pica.regs.internal.vs);
// Reload widget state
for (int attr = 0; attr < num_attributes; ++attr) {
unsigned source_attr = shader_config.GetRegisterForAttribute(attr);
unsigned source_attr = pica.regs.internal.vs.GetRegisterForAttribute(attr);
input_data_mapping[attr]->setText(QStringLiteral("-> v%1").arg(source_attr));
input_data_container[attr]->setVisible(true);
}
@ -551,7 +549,7 @@ void GraphicsVertexShaderWidget::OnResumed() {
void GraphicsVertexShaderWidget::OnInputAttributeChanged(int index) {
const f32 value = input_data[index]->text().toFloat();
input_vertex.attr[index / 4][index % 4] = Pica::f24::FromFloat32(value);
input_vertex[index / 4][index % 4] = Pica::f24::FromFloat32(value);
// Re-execute shader with updated value
Reload();
}

View file

@ -8,8 +8,12 @@
#include <QTreeView>
#include <nihstro/parser_shbin.h>
#include "citra_qt/debugger/graphics/graphics_breakpoint_observer.h"
#include "video_core/pica/output_vertex.h"
#include "video_core/shader/debug_data.h"
#include "video_core/shader/shader.h"
namespace Core {
class System;
}
class QLabel;
class QSpinBox;
@ -40,11 +44,12 @@ class GraphicsVertexShaderWidget : public BreakPointObserverDock {
using Event = Pica::DebugContext::Event;
public:
GraphicsVertexShaderWidget(std::shared_ptr<Pica::DebugContext> debug_context,
GraphicsVertexShaderWidget(Core::System& system,
std::shared_ptr<Pica::DebugContext> debug_context,
QWidget* parent = nullptr);
private slots:
void OnBreakPointHit(Pica::DebugContext::Event event, void* data) override;
void OnBreakPointHit(Pica::DebugContext::Event event, const void* data) override;
void OnResumed() override;
void OnInputAttributeChanged(int index);
@ -60,9 +65,10 @@ private slots:
* specify that no valid vertex data can be retrieved currently. Only used if
* replace_vertex_data is true.
*/
void Reload(bool replace_vertex_data = false, void* vertex_data = nullptr);
void Reload(bool replace_vertex_data = false, const void* vertex_data = nullptr);
private:
Core::System& system;
QLabel* instruction_description;
QTreeView* binary_list;
GraphicsVertexShaderModel* model;
@ -83,7 +89,7 @@ private:
nihstro::ShaderInfo info;
Pica::Shader::DebugData<true> debug_data;
Pica::Shader::AttributeBuffer input_vertex;
Pica::AttributeBuffer input_vertex;
friend class GraphicsVertexShaderModel;
};

View file

@ -74,7 +74,6 @@
#include "common/logging/backend.h"
#include "common/logging/log.h"
#include "common/memory_detect.h"
#include "common/microprofile.h"
#include "common/scm_rev.h"
#include "common/scope_exit.h"
#if CITRA_ARCH(x86_64)
@ -96,8 +95,8 @@
#include "input_common/main.h"
#include "network/network_settings.h"
#include "ui_main.h"
#include "video_core/gpu.h"
#include "video_core/renderer_base.h"
#include "video_core/video_core.h"
#ifdef __APPLE__
#include "common/apple_authorization.h"
@ -458,7 +457,7 @@ void GMainWindow::InitializeDebugWidgets() {
connect(this, &GMainWindow::EmulationStopping, registersWidget,
&RegistersWidget::OnEmulationStopping);
graphicsWidget = new GPUCommandStreamWidget(this);
graphicsWidget = new GPUCommandStreamWidget(system, this);
addDockWidget(Qt::RightDockWidgetArea, graphicsWidget);
graphicsWidget->hide();
debug_menu->addAction(graphicsWidget->toggleViewAction());
@ -473,12 +472,13 @@ void GMainWindow::InitializeDebugWidgets() {
graphicsBreakpointsWidget->hide();
debug_menu->addAction(graphicsBreakpointsWidget->toggleViewAction());
graphicsVertexShaderWidget = new GraphicsVertexShaderWidget(Pica::g_debug_context, this);
graphicsVertexShaderWidget =
new GraphicsVertexShaderWidget(system, Pica::g_debug_context, this);
addDockWidget(Qt::RightDockWidgetArea, graphicsVertexShaderWidget);
graphicsVertexShaderWidget->hide();
debug_menu->addAction(graphicsVertexShaderWidget->toggleViewAction());
graphicsTracingWidget = new GraphicsTracingWidget(Pica::g_debug_context, this);
graphicsTracingWidget = new GraphicsTracingWidget(system, Pica::g_debug_context, this);
addDockWidget(Qt::RightDockWidgetArea, graphicsTracingWidget);
graphicsTracingWidget->hide();
debug_menu->addAction(graphicsTracingWidget->toggleViewAction());
@ -1237,6 +1237,11 @@ void GMainWindow::BootGame(const QString& filename) {
video_dumping_path.clear();
}
// Register debug widgets
if (graphicsWidget->isVisible()) {
graphicsWidget->Register();
}
// Create and start the emulation thread
emu_thread = std::make_unique<EmuThread>(system, *render_window);
emit EmulationStarting(emu_thread.get());
@ -1315,6 +1320,11 @@ void GMainWindow::ShutdownGame() {
// TODO(bunnei): This function is not thread safe, but it's being used as if it were
Pica::g_debug_context->ClearBreakpoints();
// Unregister debug widgets
if (graphicsWidget->isVisible()) {
graphicsWidget->Unregister();
}
// Frame advancing must be cancelled in order to release the emu thread from waiting
system.frame_limiter.SetFrameAdvancing(false);
@ -2214,7 +2224,7 @@ void GMainWindow::OnToggleFilterBar() {
void GMainWindow::OnCreateGraphicsSurfaceViewer() {
auto graphicsSurfaceViewerWidget =
new GraphicsSurfaceWidget(system.Memory(), Pica::g_debug_context, this);
new GraphicsSurfaceWidget(system, Pica::g_debug_context, this);
addDockWidget(Qt::RightDockWidgetArea, graphicsSurfaceViewerWidget);
// TODO: Maybe graphicsSurfaceViewerWidget->setFloating(true);
graphicsSurfaceViewerWidget->show();
@ -2434,10 +2444,10 @@ void GMainWindow::OnStartVideoDumping() {
}
void GMainWindow::StartVideoDumping(const QString& path) {
Layout::FramebufferLayout layout{
Layout::FrameLayoutFromResolutionScale(VideoCore::g_renderer->GetResolutionScaleFactor())};
auto& renderer = system.GPU().Renderer();
const auto layout{Layout::FrameLayoutFromResolutionScale(renderer.GetResolutionScaleFactor())};
auto dumper = std::make_shared<VideoDumper::FFmpegBackend>();
auto dumper = std::make_shared<VideoDumper::FFmpegBackend>(renderer);
if (dumper->StartDumping(path.toStdString(), layout)) {
system.RegisterVideoDumper(dumper);
} else {