citra-emu
/
citra
Archived
1
0
Fork 0

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:
/// 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.
template <typename T>

View File

@ -50,12 +50,6 @@ constexpr ResultCode ERR_REGS_INVALID_SIZE(ErrorDescription::InvalidSize, ErrorM
ErrorSummary::InvalidArgument,
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) {
if (addr == 0) {
return 0;
@ -79,7 +73,7 @@ static PAddr VirtualToPhysicalAddress(VAddr addr) {
return addr | 0x80000000;
}
static u32 GetUnusedThreadId() {
u32 GSP_GPU::GetUnusedThreadId() {
for (u32 id = 0; id < MaxGSPThreads; ++id) {
if (!used_thread_ids[id])
return id;
@ -821,17 +815,25 @@ GSP_GPU::GSP_GPU(Core::System& system) : ServiceFramework("gsp::Gpu", 2), system
first_initialization = true;
};
std::unique_ptr<Kernel::SessionRequestHandler::SessionDataBase> GSP_GPU::MakeSessionData() {
return std::make_unique<SessionData>(this);
}
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
// is done through a real thread (svcCreateThread) but we have to simulate it since our HLE
// services don't have threads.
thread_id = GetUnusedThreadId();
used_thread_ids[thread_id] = true;
thread_id = gsp->GetUnusedThreadId();
gsp->used_thread_ids[thread_id] = true;
}
SessionData::~SessionData() {
// 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

View File

@ -183,10 +183,15 @@ struct CommandBuffer {
};
static_assert(sizeof(CommandBuffer) == 0x200, "CommandBuffer struct has incorrect size");
class GSP_GPU;
struct SessionData : public Kernel::SessionRequestHandler::SessionDataBase {
SessionData();
SessionData(GSP_GPU* gsp);
~SessionData();
GSP_GPU* gsp;
/// Event triggered when GSP interrupt has been signalled
std::shared_ptr<Kernel::Event> interrupt_event;
/// 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.
SessionData* FindRegisteredThreadData(u32 thread_id);
u32 GetUnusedThreadId();
std::unique_ptr<Kernel::SessionRequestHandler::SessionDataBase> MakeSessionData() override;
Core::System& system;
/// GSP shared memory
@ -413,6 +422,14 @@ private:
int active_thread_id = -1;
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);

View File

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