GSP_GPU: move used_thread_ids into the class

This commit is contained in:
Weiyi Wang 2019-06-23 14:07:14 -04:00
parent bb776e25a9
commit 8251de44cf
4 changed files with 31 additions and 12 deletions

View File

@ -72,7 +72,7 @@ public:
protected: protected:
/// Creates the storage for the session data of the service. /// Creates the storage for the session data of the service.
virtual std::unique_ptr<SessionDataBase> MakeSessionData() const = 0; virtual std::unique_ptr<SessionDataBase> MakeSessionData() = 0;
/// Returns the session data associated with the server session. /// Returns the session data associated with the server session.
template <typename T> template <typename T>

View File

@ -50,12 +50,6 @@ constexpr ResultCode ERR_REGS_INVALID_SIZE(ErrorDescription::InvalidSize, ErrorM
ErrorSummary::InvalidArgument, ErrorSummary::InvalidArgument,
ErrorLevel::Usage); // 0xE0E02BEC ErrorLevel::Usage); // 0xE0E02BEC
/// Maximum number of threads that can be registered at the same time in the GSP module.
constexpr u32 MaxGSPThreads = 4;
/// Thread ids currently in use by the sessions connected to the GSPGPU service.
static std::array<bool, MaxGSPThreads> used_thread_ids = {false, false, false, false};
static PAddr VirtualToPhysicalAddress(VAddr addr) { static PAddr VirtualToPhysicalAddress(VAddr addr) {
if (addr == 0) { if (addr == 0) {
return 0; return 0;
@ -79,7 +73,7 @@ static PAddr VirtualToPhysicalAddress(VAddr addr) {
return addr | 0x80000000; return addr | 0x80000000;
} }
static u32 GetUnusedThreadId() { u32 GSP_GPU::GetUnusedThreadId() {
for (u32 id = 0; id < MaxGSPThreads; ++id) { for (u32 id = 0; id < MaxGSPThreads; ++id) {
if (!used_thread_ids[id]) if (!used_thread_ids[id])
return id; return id;
@ -821,17 +815,25 @@ GSP_GPU::GSP_GPU(Core::System& system) : ServiceFramework("gsp::Gpu", 2), system
first_initialization = true; first_initialization = true;
}; };
std::unique_ptr<Kernel::SessionRequestHandler::SessionDataBase> GSP_GPU::MakeSessionData() {
return std::make_unique<SessionData>(this);
}
SessionData::SessionData() { SessionData::SessionData() {
UNREACHABLE();
}
SessionData::SessionData(GSP_GPU* gsp) : gsp(gsp) {
// Assign a new thread id to this session when it connects. Note: In the real GSP service this // Assign a new thread id to this session when it connects. Note: In the real GSP service this
// is done through a real thread (svcCreateThread) but we have to simulate it since our HLE // is done through a real thread (svcCreateThread) but we have to simulate it since our HLE
// services don't have threads. // services don't have threads.
thread_id = GetUnusedThreadId(); thread_id = gsp->GetUnusedThreadId();
used_thread_ids[thread_id] = true; gsp->used_thread_ids[thread_id] = true;
} }
SessionData::~SessionData() { SessionData::~SessionData() {
// Free the thread id slot so that other sessions can use it. // Free the thread id slot so that other sessions can use it.
used_thread_ids[thread_id] = false; gsp->used_thread_ids[thread_id] = false;
} }
} // namespace Service::GSP } // namespace Service::GSP

View File

@ -183,10 +183,15 @@ struct CommandBuffer {
}; };
static_assert(sizeof(CommandBuffer) == 0x200, "CommandBuffer struct has incorrect size"); static_assert(sizeof(CommandBuffer) == 0x200, "CommandBuffer struct has incorrect size");
class GSP_GPU;
struct SessionData : public Kernel::SessionRequestHandler::SessionDataBase { struct SessionData : public Kernel::SessionRequestHandler::SessionDataBase {
SessionData(); SessionData();
SessionData(GSP_GPU* gsp);
~SessionData(); ~SessionData();
GSP_GPU* gsp;
/// Event triggered when GSP interrupt has been signalled /// Event triggered when GSP interrupt has been signalled
std::shared_ptr<Kernel::Event> interrupt_event; std::shared_ptr<Kernel::Event> interrupt_event;
/// Thread index into interrupt relay queue /// Thread index into interrupt relay queue
@ -404,6 +409,10 @@ private:
/// Returns the session data for the specified registered thread id, or nullptr if not found. /// Returns the session data for the specified registered thread id, or nullptr if not found.
SessionData* FindRegisteredThreadData(u32 thread_id); SessionData* FindRegisteredThreadData(u32 thread_id);
u32 GetUnusedThreadId();
std::unique_ptr<Kernel::SessionRequestHandler::SessionDataBase> MakeSessionData() override;
Core::System& system; Core::System& system;
/// GSP shared memory /// GSP shared memory
@ -413,6 +422,14 @@ private:
int active_thread_id = -1; int active_thread_id = -1;
bool first_initialization = true; bool first_initialization = true;
/// Maximum number of threads that can be registered at the same time in the GSP module.
static constexpr u32 MaxGSPThreads = 4;
/// Thread ids currently in use by the sessions connected to the GSPGPU service.
std::array<bool, MaxGSPThreads> used_thread_ids = {false, false, false, false};
friend class SessionData;
}; };
ResultCode SetBufferSwap(u32 screen_id, const FrameBufferInfo& info); ResultCode SetBufferSwap(u32 screen_id, const FrameBufferInfo& info);

View File

@ -156,7 +156,7 @@ protected:
RegisterHandlersBase(functions, n); RegisterHandlersBase(functions, n);
} }
std::unique_ptr<SessionDataBase> MakeSessionData() const override { std::unique_ptr<SessionDataBase> MakeSessionData() override {
return std::make_unique<SessionData>(); return std::make_unique<SessionData>();
} }