From f82410e6335b02603c7a6fc0fc63894b6a820a5b Mon Sep 17 00:00:00 2001
From: Tony Wasserka <NeoBrainX@gmail.com>
Date: Sun, 18 May 2014 21:18:38 +0200
Subject: [PATCH] Further refine GPU command list debugging.

---
 src/citra_qt/debugger/graphics_cmdlists.cpp | 14 ++++++++++----
 src/video_core/gpu_debugger.h               |  1 +
 src/video_core/pica.h                       | 16 ++++++++++++++++
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/src/citra_qt/debugger/graphics_cmdlists.cpp b/src/citra_qt/debugger/graphics_cmdlists.cpp
index d07645e78..195197ef5 100644
--- a/src/citra_qt/debugger/graphics_cmdlists.cpp
+++ b/src/citra_qt/debugger/graphics_cmdlists.cpp
@@ -53,7 +53,7 @@ int GPUCommandListModel::rowCount(const QModelIndex& parent) const
 
 int GPUCommandListModel::columnCount(const QModelIndex& parent) const
 {
-    return 1;
+    return 2;
 }
 
 QVariant GPUCommandListModel::data(const QModelIndex& index, int role) const
@@ -68,7 +68,7 @@ QVariant GPUCommandListModel::data(const QModelIndex& index, int role) const
         const GraphicsDebugger::PicaCommandList& cmdlist = command_lists[item->index].second;
         u32 address = command_lists[item->index].first;
 
-        if (role == Qt::DisplayRole)
+        if (role == Qt::DisplayRole && index.column() == 0)
         {
             return QVariant(QString("0x%1 bytes at 0x%2").arg(cmdlist.size(), 0, 16).arg(address, 8, 16, QLatin1Char('0')));
         }
@@ -78,11 +78,17 @@ QVariant GPUCommandListModel::data(const QModelIndex& index, int role) const
         // index refers to a specific command
         const GraphicsDebugger::PicaCommandList& cmdlist = command_lists[item->parent->index].second;
         const GraphicsDebugger::PicaCommand& cmd = cmdlist[item->index];
+        const Pica::CommandHeader& header = cmd.GetHeader();
 
         if (role == Qt::DisplayRole) {
             QString content;
-            for (int j = 0; j < cmd.size(); ++j)
-                content.append(QString("%1 ").arg(cmd[j], 8, 16, QLatin1Char('0')));
+            if (index.column() == 0) {
+                content = Pica::command_names[header.cmd_id];
+                content.append(" ");
+            } else if (index.column() == 1) {
+                for (int j = 0; j < cmd.size(); ++j)
+                    content.append(QString("%1 ").arg(cmd[j], 8, 16, QLatin1Char('0')));
+            }
 
             return QVariant(content);
         }
diff --git a/src/video_core/gpu_debugger.h b/src/video_core/gpu_debugger.h
index 5ece0a8b7..6a1e04244 100644
--- a/src/video_core/gpu_debugger.h
+++ b/src/video_core/gpu_debugger.h
@@ -100,6 +100,7 @@ public:
             auto& cmd = cmdlist.back();
 
             size_t size = 2 + header.extra_data_length;
+            size = (size + 1) / 2 * 2; // align to 8 bytes
             cmd.reserve(size);
             std::copy(parse_pointer, parse_pointer + size, std::back_inserter(cmd));
 
diff --git a/src/video_core/pica.h b/src/video_core/pica.h
index 8ebe0dc3c..7cbc45f98 100644
--- a/src/video_core/pica.h
+++ b/src/video_core/pica.h
@@ -4,6 +4,9 @@
 
 #pragma once
 
+#include <initializer_list>
+#include <map>
+
 #include "common/bit_field.h"
 #include "common/common_types.h"
 
@@ -34,4 +37,17 @@ union CommandHeader {
     BitField<31,  1, u32> group_commands;
 };
 
+static std::map<CommandId, const char*> command_names = {
+    {CommandId::ViewportSizeX, "ViewportSizeX" },
+    {CommandId::ViewportInvSizeX, "ViewportInvSizeX" },
+    {CommandId::ViewportSizeY, "ViewportSizeY" },
+    {CommandId::ViewportInvSizeY, "ViewportInvSizeY" },
+    {CommandId::ViewportCorner, "ViewportCorner" },
+    {CommandId::DepthBufferFormat, "DepthBufferFormat" },
+    {CommandId::ColorBufferFormat, "ColorBufferFormat" },
+    {CommandId::DepthBufferAddress, "DepthBufferAddress" },
+    {CommandId::ColorBufferAddress, "ColorBufferAddress" },
+    {CommandId::ColorBufferSize, "ColorBufferSize" },
+};
+
 }