From 37861326ce38192b14f152740cb7b47e27fe8b68 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 5 Jun 2020 21:05:19 -0400 Subject: [PATCH 1/3] gsp_gpu: Mark GetUnusedThreadId() as const This doesn't modify class state. --- src/core/hle/service/gsp/gsp_gpu.cpp | 2 +- src/core/hle/service/gsp/gsp_gpu.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/hle/service/gsp/gsp_gpu.cpp b/src/core/hle/service/gsp/gsp_gpu.cpp index 5a41f5ca0..3b32b47d0 100644 --- a/src/core/hle/service/gsp/gsp_gpu.cpp +++ b/src/core/hle/service/gsp/gsp_gpu.cpp @@ -78,7 +78,7 @@ static PAddr VirtualToPhysicalAddress(VAddr addr) { return addr | 0x80000000; } -u32 GSP_GPU::GetUnusedThreadId() { +u32 GSP_GPU::GetUnusedThreadId() const { for (u32 id = 0; id < MaxGSPThreads; ++id) { if (!used_thread_ids[id]) return id; diff --git a/src/core/hle/service/gsp/gsp_gpu.h b/src/core/hle/service/gsp/gsp_gpu.h index c8914ef72..4d961634a 100644 --- a/src/core/hle/service/gsp/gsp_gpu.h +++ b/src/core/hle/service/gsp/gsp_gpu.h @@ -424,7 +424,7 @@ private: /// Returns the session data for the specified registered thread id, or nullptr if not found. SessionData* FindRegisteredThreadData(u32 thread_id); - u32 GetUnusedThreadId(); + u32 GetUnusedThreadId() const; std::unique_ptr MakeSessionData() override; From a17027783f133c2679b32b3179b0b79d49b3ad43 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 5 Jun 2020 21:09:16 -0400 Subject: [PATCH 2/3] gsp_gpu: Resolve sign conversion warnings Resolves numerous warnings about signed/unsigned conversion warnings. --- src/core/hle/service/gsp/gsp_gpu.cpp | 16 +++++++++------- src/core/hle/service/gsp/gsp_gpu.h | 6 +++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/core/hle/service/gsp/gsp_gpu.cpp b/src/core/hle/service/gsp/gsp_gpu.cpp index 3b32b47d0..cde0d7e83 100644 --- a/src/core/hle/service/gsp/gsp_gpu.cpp +++ b/src/core/hle/service/gsp/gsp_gpu.cpp @@ -109,9 +109,10 @@ static inline InterruptRelayQueue* GetInterruptRelayQueue( } void GSP_GPU::ClientDisconnected(std::shared_ptr server_session) { - SessionData* session_data = GetSessionData(server_session); - if (active_thread_id == session_data->thread_id) + const SessionData* session_data = GetSessionData(server_session); + if (active_thread_id == session_data->thread_id) { ReleaseRight(session_data); + } SessionRequestHandler::ClientDisconnected(server_session); } @@ -470,8 +471,9 @@ void GSP_GPU::SignalInterrupt(InterruptId interrupt_id) { } // For normal interrupts, don't do anything if no process has acquired the GPU right. - if (active_thread_id == -1) + if (active_thread_id == UINT32_MAX) { return; + } SignalInterruptForThread(interrupt_id, active_thread_id); } @@ -712,23 +714,23 @@ void GSP_GPU::AcquireRight(Kernel::HLERequestContext& ctx) { } // TODO(Subv): This case should put the caller thread to sleep until the right is released. - ASSERT_MSG(active_thread_id == -1, "GPU right has already been acquired"); + ASSERT_MSG(active_thread_id == UINT32_MAX, "GPU right has already been acquired"); active_thread_id = session_data->thread_id; rb.Push(RESULT_SUCCESS); } -void GSP_GPU::ReleaseRight(SessionData* session_data) { +void GSP_GPU::ReleaseRight(const SessionData* session_data) { ASSERT_MSG(active_thread_id == session_data->thread_id, "Wrong thread tried to release GPU right"); - active_thread_id = -1; + active_thread_id = UINT32_MAX; } void GSP_GPU::ReleaseRight(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp(ctx, 0x17, 0, 0); - SessionData* session_data = GetSessionData(ctx.Session()); + const SessionData* session_data = GetSessionData(ctx.Session()); ReleaseRight(session_data); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); diff --git a/src/core/hle/service/gsp/gsp_gpu.h b/src/core/hle/service/gsp/gsp_gpu.h index 4d961634a..0a8517c8c 100644 --- a/src/core/hle/service/gsp/gsp_gpu.h +++ b/src/core/hle/service/gsp/gsp_gpu.h @@ -379,7 +379,7 @@ private: * Releases rights to the GPU. * Will fail if the session_data doesn't have the GPU right */ - void ReleaseRight(SessionData* session_data); + void ReleaseRight(const SessionData* session_data); /** * GSP_GPU::ImportDisplayCaptureInfo service function @@ -433,8 +433,8 @@ private: /// GSP shared memory std::shared_ptr shared_memory; - /// Thread id that currently has GPU rights or -1 if none. - int active_thread_id = -1; + /// Thread id that currently has GPU rights or UINT32_MAX if none. + u32 active_thread_id = UINT32_MAX; bool first_initialization = true; From 0cc6eb3134f652eb8f9b70e8f3c09bfc3aac5383 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 5 Jun 2020 21:12:35 -0400 Subject: [PATCH 3/3] gsp_gpu: Mark REGS_BEGIN as constexpr Same behavior, but more consistent with the already constexpr file-scope variables. --- src/core/hle/service/gsp/gsp_gpu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/hle/service/gsp/gsp_gpu.cpp b/src/core/hle/service/gsp/gsp_gpu.cpp index cde0d7e83..4a778a231 100644 --- a/src/core/hle/service/gsp/gsp_gpu.cpp +++ b/src/core/hle/service/gsp/gsp_gpu.cpp @@ -32,7 +32,7 @@ GraphicsDebugger g_debugger; namespace Service::GSP { // Beginning address of HW regs -const u32 REGS_BEGIN = 0x1EB00000; +constexpr u32 REGS_BEGIN = 0x1EB00000; namespace ErrCodes { enum {