diff options
author | Tony Wasserka <NeoBrainX@gmail.com> | 2014-05-17 22:34:55 +0200 |
---|---|---|
committer | bunnei <ericbunnie@gmail.com> | 2014-06-12 06:10:48 -0400 |
commit | 31666632caf9e5f0eea8d8d839e7120e38be97f9 (patch) | |
tree | a4cd919f52ff5ee64b3337c1cb3f7c01dd330ef9 /src/video_core/gpu_debugger.h | |
parent | 82d32603593cbec12499c5f0bfcbe61d2cac5629 (diff) |
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 00000000..ace9de95 --- /dev/null +++ b/src/video_core/gpu_debugger.h @@ -0,0 +1,97 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +#include <algorithm> +#include <functional> +#include <vector> + +#include "common/log.h" + +#include "core/hle/service/gsp.h" + + +class GraphicsDebugger +{ +public: + // Base class for all objects which need to be notified about GPU events + class DebuggerObserver + { + public: + DebuggerObserver() : observed(nullptr) { } + + virtual ~DebuggerObserver() + { + if (observed) + observed->UnregisterObserver(this); + } + + /** + * Called when a GX command has been processed and is ready for being + * read via GraphicsDebugger::ReadGXCommandHistory. + * @param total_command_count Total number of commands in the GX history + * @note All methods in this class are called from the GSP thread + */ + virtual void GXCommandProcessed(int total_command_count) + { + const GSP_GPU::GXCommand& cmd = observed->ReadGXCommandHistory(total_command_count-1); + ERROR_LOG(GSP, "Received command: id=%x", cmd.id); + } + + protected: + GraphicsDebugger* GetDebugger() + { + return observed; + } + + private: + GraphicsDebugger* observed; + bool in_destruction; + + friend class GraphicsDebugger; + }; + + void GXCommandProcessed(u8* command_data) + { + gx_command_history.push_back(GSP_GPU::GXCommand()); + GSP_GPU::GXCommand& cmd = gx_command_history[gx_command_history.size()-1]; + + const int cmd_length = sizeof(GSP_GPU::GXCommand); + memcpy(cmd.data, command_data, cmd_length); + + ForEachObserver([this](DebuggerObserver* observer) { + observer->GXCommandProcessed(this->gx_command_history.size()); + } ); + } + + const GSP_GPU::GXCommand& ReadGXCommandHistory(int index) const + { + // TODO: Is this thread-safe? + return gx_command_history[index]; + } + + void RegisterObserver(DebuggerObserver* observer) + { + // TODO: Check for duplicates + observers.push_back(observer); + observer->observed = this; + } + + void UnregisterObserver(DebuggerObserver* observer) + { + std::remove(observers.begin(), observers.end(), observer); + observer->observed = nullptr; + } + +private: + void ForEachObserver(std::function<void (DebuggerObserver*)> func) + { + std::for_each(observers.begin(),observers.end(), func); + } + + std::vector<DebuggerObserver*> observers; + + std::vector<GSP_GPU::GXCommand> gx_command_history; +}; |