2014-05-18 02:04:55 +05:30
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 11:08:14 +05:30
|
|
|
// Licensed under GPLv2 or any later version
|
2014-05-18 02:04:55 +05:30
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <functional>
|
|
|
|
#include <vector>
|
|
|
|
|
2014-10-29 08:38:37 +05:30
|
|
|
#include "core/hle/service/gsp_gpu.h"
|
2014-07-26 18:12:46 +05:30
|
|
|
|
2014-05-18 02:04:55 +05:30
|
|
|
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)
|
|
|
|
{
|
2014-07-23 08:56:28 +05:30
|
|
|
const GSP_GPU::Command& cmd = observed->ReadGXCommandHistory(total_command_count-1);
|
2014-12-06 07:23:49 +05:30
|
|
|
LOG_TRACE(Debug_GPU, "Received command: id=%x", (int)cmd.id.Value());
|
2014-05-18 02:04:55 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-06-12 00:52:26 +05:30
|
|
|
const GraphicsDebugger* GetDebugger() const
|
2014-05-18 02:04:55 +05:30
|
|
|
{
|
|
|
|
return observed;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
GraphicsDebugger* observed;
|
|
|
|
|
|
|
|
friend class GraphicsDebugger;
|
|
|
|
};
|
|
|
|
|
|
|
|
void GXCommandProcessed(u8* command_data)
|
|
|
|
{
|
2014-06-25 00:57:18 +05:30
|
|
|
if (observers.empty())
|
|
|
|
return;
|
|
|
|
|
2015-02-18 04:12:28 +05:30
|
|
|
gx_command_history.emplace_back();
|
|
|
|
GSP_GPU::Command& cmd = gx_command_history.back();
|
2014-05-18 02:04:55 +05:30
|
|
|
|
2014-07-23 08:56:28 +05:30
|
|
|
memcpy(&cmd, command_data, sizeof(GSP_GPU::Command));
|
2014-05-18 02:04:55 +05:30
|
|
|
|
|
|
|
ForEachObserver([this](DebuggerObserver* observer) {
|
2015-02-02 02:01:21 +05:30
|
|
|
observer->GXCommandProcessed(static_cast<int>(this->gx_command_history.size()));
|
2014-05-18 02:04:55 +05:30
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2014-07-23 08:56:28 +05:30
|
|
|
const GSP_GPU::Command& ReadGXCommandHistory(int index) const
|
2014-05-18 02:04:55 +05:30
|
|
|
{
|
|
|
|
// 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)
|
|
|
|
{
|
2014-12-19 05:12:24 +05:30
|
|
|
observers.erase(std::remove(observers.begin(), observers.end(), observer), observers.end());
|
2014-05-18 02:04:55 +05:30
|
|
|
observer->observed = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void ForEachObserver(std::function<void (DebuggerObserver*)> func)
|
|
|
|
{
|
|
|
|
std::for_each(observers.begin(),observers.end(), func);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<DebuggerObserver*> observers;
|
|
|
|
|
2014-07-23 08:56:28 +05:30
|
|
|
std::vector<GSP_GPU::Command> gx_command_history;
|
2014-05-18 02:04:55 +05:30
|
|
|
};
|