diff options
| author | 2014-05-17 22:34:55 +0200 | |
|---|---|---|
| committer | 2014-06-12 06:10:48 -0400 | |
| commit | 31666632caf9e5f0eea8d8d839e7120e38be97f9 (patch) | |
| tree | a4cd919f52ff5ee64b3337c1cb3f7c01dd330ef9 /src/video_core/gpu_debugger.h | |
| parent | GSP: Define more GX commands. (diff) | |
| download | yuzu-31666632caf9e5f0eea8d8d839e7120e38be97f9.tar.gz yuzu-31666632caf9e5f0eea8d8d839e7120e38be97f9.tar.xz yuzu-31666632caf9e5f0eea8d8d839e7120e38be97f9.zip | |
Add initial graphics debugger interface.
Diffstat (limited to 'src/video_core/gpu_debugger.h')
| -rw-r--r-- | src/video_core/gpu_debugger.h | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/video_core/gpu_debugger.h b/src/video_core/gpu_debugger.h new file mode 100644 index 000000000..ace9de95f --- /dev/null +++ b/src/video_core/gpu_debugger.h | |||
| @@ -0,0 +1,97 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <algorithm> | ||
| 8 | #include <functional> | ||
| 9 | #include <vector> | ||
| 10 | |||
| 11 | #include "common/log.h" | ||
| 12 | |||
| 13 | #include "core/hle/service/gsp.h" | ||
| 14 | |||
| 15 | |||
| 16 | class GraphicsDebugger | ||
| 17 | { | ||
| 18 | public: | ||
| 19 | // Base class for all objects which need to be notified about GPU events | ||
| 20 | class DebuggerObserver | ||
| 21 | { | ||
| 22 | public: | ||
| 23 | DebuggerObserver() : observed(nullptr) { } | ||
| 24 | |||
| 25 | virtual ~DebuggerObserver() | ||
| 26 | { | ||
| 27 | if (observed) | ||
| 28 | observed->UnregisterObserver(this); | ||
| 29 | } | ||
| 30 | |||
| 31 | /** | ||
| 32 | * Called when a GX command has been processed and is ready for being | ||
| 33 | * read via GraphicsDebugger::ReadGXCommandHistory. | ||
| 34 | * @param total_command_count Total number of commands in the GX history | ||
| 35 | * @note All methods in this class are called from the GSP thread | ||
| 36 | */ | ||
| 37 | virtual void GXCommandProcessed(int total_command_count) | ||
| 38 | { | ||
| 39 | const GSP_GPU::GXCommand& cmd = observed->ReadGXCommandHistory(total_command_count-1); | ||
| 40 | ERROR_LOG(GSP, "Received command: id=%x", cmd.id); | ||
| 41 | } | ||
| 42 | |||
| 43 | protected: | ||
| 44 | GraphicsDebugger* GetDebugger() | ||
| 45 | { | ||
| 46 | return observed; | ||
| 47 | } | ||
| 48 | |||
| 49 | private: | ||
| 50 | GraphicsDebugger* observed; | ||
| 51 | bool in_destruction; | ||
| 52 | |||
| 53 | friend class GraphicsDebugger; | ||
| 54 | }; | ||
| 55 | |||
| 56 | void GXCommandProcessed(u8* command_data) | ||
| 57 | { | ||
| 58 | gx_command_history.push_back(GSP_GPU::GXCommand()); | ||
| 59 | GSP_GPU::GXCommand& cmd = gx_command_history[gx_command_history.size()-1]; | ||
| 60 | |||
| 61 | const int cmd_length = sizeof(GSP_GPU::GXCommand); | ||
| 62 | memcpy(cmd.data, command_data, cmd_length); | ||
| 63 | |||
| 64 | ForEachObserver([this](DebuggerObserver* observer) { | ||
| 65 | observer->GXCommandProcessed(this->gx_command_history.size()); | ||
| 66 | } ); | ||
| 67 | } | ||
| 68 | |||
| 69 | const GSP_GPU::GXCommand& ReadGXCommandHistory(int index) const | ||
| 70 | { | ||
| 71 | // TODO: Is this thread-safe? | ||
| 72 | return gx_command_history[index]; | ||
| 73 | } | ||
| 74 | |||
| 75 | void RegisterObserver(DebuggerObserver* observer) | ||
| 76 | { | ||
| 77 | // TODO: Check for duplicates | ||
| 78 | observers.push_back(observer); | ||
| 79 | observer->observed = this; | ||
| 80 | } | ||
| 81 | |||
| 82 | void UnregisterObserver(DebuggerObserver* observer) | ||
| 83 | { | ||
| 84 | std::remove(observers.begin(), observers.end(), observer); | ||
| 85 | observer->observed = nullptr; | ||
| 86 | } | ||
| 87 | |||
| 88 | private: | ||
| 89 | void ForEachObserver(std::function<void (DebuggerObserver*)> func) | ||
| 90 | { | ||
| 91 | std::for_each(observers.begin(),observers.end(), func); | ||
| 92 | } | ||
| 93 | |||
| 94 | std::vector<DebuggerObserver*> observers; | ||
| 95 | |||
| 96 | std::vector<GSP_GPU::GXCommand> gx_command_history; | ||
| 97 | }; | ||