summaryrefslogtreecommitdiff
path: root/src/video_core/gpu_debugger.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core/gpu_debugger.h')
-rw-r--r--src/video_core/gpu_debugger.h41
1 files changed, 15 insertions, 26 deletions
diff --git a/src/video_core/gpu_debugger.h b/src/video_core/gpu_debugger.h
index a3aab216c..3c6636d66 100644
--- a/src/video_core/gpu_debugger.h
+++ b/src/video_core/gpu_debugger.h
@@ -7,20 +7,16 @@
7#include <algorithm> 7#include <algorithm>
8#include <functional> 8#include <functional>
9#include <vector> 9#include <vector>
10
11#include "core/hle/service/gsp_gpu.h" 10#include "core/hle/service/gsp_gpu.h"
12 11
13class GraphicsDebugger 12class GraphicsDebugger {
14{
15public: 13public:
16 // Base class for all objects which need to be notified about GPU events 14 // Base class for all objects which need to be notified about GPU events
17 class DebuggerObserver 15 class DebuggerObserver {
18 {
19 public: 16 public:
20 DebuggerObserver() : observed(nullptr) { } 17 DebuggerObserver() : observed(nullptr) {}
21 18
22 virtual ~DebuggerObserver() 19 virtual ~DebuggerObserver() {
23 {
24 if (observed) 20 if (observed)
25 observed->UnregisterObserver(this); 21 observed->UnregisterObserver(this);
26 } 22 }
@@ -31,15 +27,13 @@ public:
31 * @param total_command_count Total number of commands in the GX history 27 * @param total_command_count Total number of commands in the GX history
32 * @note All methods in this class are called from the GSP thread 28 * @note All methods in this class are called from the GSP thread
33 */ 29 */
34 virtual void GXCommandProcessed(int total_command_count) 30 virtual void GXCommandProcessed(int total_command_count) {
35 { 31 const GSP_GPU::Command& cmd = observed->ReadGXCommandHistory(total_command_count - 1);
36 const GSP_GPU::Command& cmd = observed->ReadGXCommandHistory(total_command_count-1);
37 LOG_TRACE(Debug_GPU, "Received command: id=%x", (int)cmd.id.Value()); 32 LOG_TRACE(Debug_GPU, "Received command: id=%x", (int)cmd.id.Value());
38 } 33 }
39 34
40 protected: 35 protected:
41 const GraphicsDebugger* GetDebugger() const 36 const GraphicsDebugger* GetDebugger() const {
42 {
43 return observed; 37 return observed;
44 } 38 }
45 39
@@ -49,8 +43,7 @@ public:
49 friend class GraphicsDebugger; 43 friend class GraphicsDebugger;
50 }; 44 };
51 45
52 void GXCommandProcessed(u8* command_data) 46 void GXCommandProcessed(u8* command_data) {
53 {
54 if (observers.empty()) 47 if (observers.empty())
55 return; 48 return;
56 49
@@ -60,33 +53,29 @@ public:
60 memcpy(&cmd, command_data, sizeof(GSP_GPU::Command)); 53 memcpy(&cmd, command_data, sizeof(GSP_GPU::Command));
61 54
62 ForEachObserver([this](DebuggerObserver* observer) { 55 ForEachObserver([this](DebuggerObserver* observer) {
63 observer->GXCommandProcessed(static_cast<int>(this->gx_command_history.size())); 56 observer->GXCommandProcessed(static_cast<int>(this->gx_command_history.size()));
64 } ); 57 });
65 } 58 }
66 59
67 const GSP_GPU::Command& ReadGXCommandHistory(int index) const 60 const GSP_GPU::Command& ReadGXCommandHistory(int index) const {
68 {
69 // TODO: Is this thread-safe? 61 // TODO: Is this thread-safe?
70 return gx_command_history[index]; 62 return gx_command_history[index];
71 } 63 }
72 64
73 void RegisterObserver(DebuggerObserver* observer) 65 void RegisterObserver(DebuggerObserver* observer) {
74 {
75 // TODO: Check for duplicates 66 // TODO: Check for duplicates
76 observers.push_back(observer); 67 observers.push_back(observer);
77 observer->observed = this; 68 observer->observed = this;
78 } 69 }
79 70
80 void UnregisterObserver(DebuggerObserver* observer) 71 void UnregisterObserver(DebuggerObserver* observer) {
81 {
82 observers.erase(std::remove(observers.begin(), observers.end(), observer), observers.end()); 72 observers.erase(std::remove(observers.begin(), observers.end(), observer), observers.end());
83 observer->observed = nullptr; 73 observer->observed = nullptr;
84 } 74 }
85 75
86private: 76private:
87 void ForEachObserver(std::function<void (DebuggerObserver*)> func) 77 void ForEachObserver(std::function<void(DebuggerObserver*)> func) {
88 { 78 std::for_each(observers.begin(), observers.end(), func);
89 std::for_each(observers.begin(),observers.end(), func);
90 } 79 }
91 80
92 std::vector<DebuggerObserver*> observers; 81 std::vector<DebuggerObserver*> observers;