Add GSP::GPU::AcquireRight

This commit is contained in:
wheremyfoodat 2022-09-18 17:30:26 +03:00
parent a56b67f3ba
commit 68698ae7a7
6 changed files with 49 additions and 8 deletions

View file

@ -74,7 +74,8 @@ class Kernel {
void outputDebugString();
public:
Kernel(std::array<u32, 16>& regs, Memory& mem) : regs(regs), mem(mem), handleCounter(0), serviceManager(regs, mem) {
Kernel(std::array<u32, 16>& regs, Memory& mem)
: regs(regs), mem(mem), handleCounter(0), serviceManager(regs, mem, currentProcess) {
objects.reserve(512); // Make room for a few objects to avoid further memory allocs later
portHandles.reserve(32);
}

View file

@ -331,6 +331,17 @@ namespace OpenGL {
}
};
enum DepthFunc {
Never = GL_NEVER, // Depth test never passes
Always = GL_ALWAYS, // Depth test always passes
Equal = GL_EQUAL, // Depth test passes if frag z == depth buffer z
NotEqual = GL_NOTEQUAL, // Depth test passes if frag z != depth buffer z
Less = GL_LESS, // Depth test passes if frag z < depth buffer z
Lequal = GL_LEQUAL, // Depth test passes if frag z <= depth buffer z
Greater = GL_GREATER, // Depth test passes if frag z > depth buffer z
Gequal = GL_GEQUAL, // Depth test passes if frag z >= depth buffer z
};
static void setClearColor(float val) { glClearColor(val, val, val, val); }
static void setClearColor(float r, float g, float b, float a) { glClearColor(r, g, b, a); }
static void setClearDepth(float depth) { glClearDepthf(depth); }
@ -359,6 +370,8 @@ namespace OpenGL {
static void enableStencil() { glEnable(GL_STENCIL_TEST); }
static void disableStencil() { glDisable(GL_STENCIL_TEST); }
static void setDepthFunc(DepthFunc func) { glDepthFunc(static_cast<GLenum>(func)); }
enum Primitives {
Triangle = GL_TRIANGLES,
Triangles = Triangle,

View file

@ -6,11 +6,17 @@
class GPUService {
Handle handle = KernelHandles::GPU;
Memory& mem;
u32& currentPID; // Process ID of the current process
// At any point in time only 1 process has privileges to use rendering functions
// This is the PID of that process
u32 privilegedProcess;
// Service commands
void acquireRight(u32 messagePointer);
public:
GPUService(Memory& mem) : mem(mem) {}
GPUService(Memory& mem, u32& currentPID) : mem(mem), currentPID(currentPID) {}
void reset();
void handleSyncRequest(u32 messagePointer);
};

View file

@ -23,7 +23,7 @@ class ServiceManager {
void registerClient(u32 messagePointer);
public:
ServiceManager(std::array<u32, 16>& regs, Memory& mem);
ServiceManager(std::array<u32, 16>& regs, Memory& mem, u32& currentPID);
void reset();
void handleSyncRequest(u32 messagePointer);

View file

@ -2,6 +2,7 @@
namespace GPUCommands {
enum : u32 {
AcquireRight = 0x00160042
};
}
@ -11,11 +12,32 @@ namespace Result {
};
}
void GPUService::reset() {}
void GPUService::reset() {
privilegedProcess = 0xFFFFFFFF; // Set the privileged process to an invalid handle
}
void GPUService::handleSyncRequest(u32 messagePointer) {
const u32 command = mem.read32(messagePointer);
switch (command) {
default: Helpers::panic("GPU service requested. Command: %08X\n", command);
case GPUCommands::AcquireRight: acquireRight(messagePointer); break;
; default: Helpers::panic("GPU service requested. Command: %08X\n", command);
}
}
void GPUService::acquireRight(u32 messagePointer) {
const u32 flag = mem.read32(messagePointer + 4);
const u32 pid = mem.read32(messagePointer + 12);
printf("GSP::GPU::acquireRight (flag = %d, pid = %X)\n", flag, pid);
if (flag != 0) {
Helpers::panic("GSP::GPU::acquireRight with flag != 0 needs to perform additional initialization");
}
if (pid == KernelHandles::CurrentProcess) {
privilegedProcess = currentPID;
} else {
privilegedProcess = pid;
}
mem.write32(messagePointer + 4, Result::Success);
}

View file

@ -1,8 +1,7 @@
#include "services/service_manager.hpp"
ServiceManager::ServiceManager(std::array<u32, 16>& regs, Memory& mem) : regs(regs), mem(mem),
apt(mem), hid(mem), fs(mem),
gsp_gpu(mem), gsp_lcd(mem) {}
ServiceManager::ServiceManager(std::array<u32, 16>& regs, Memory& mem, u32& currentPID)
: regs(regs), mem(mem), apt(mem), hid(mem), fs(mem), gsp_gpu(mem, currentPID), gsp_lcd(mem) {}
void ServiceManager::reset() {
apt.reset();