From 09000da701bb8f87ca8d8b73672170d636aab644 Mon Sep 17 00:00:00 2001 From: wheremyfoodat Date: Wed, 21 Sep 2022 03:45:33 +0300 Subject: [PATCH] [GPU/GSP] Get our first command list --- include/emulator.hpp | 2 +- include/gpu.hpp | 4 +++- include/services/gsp_gpu.hpp | 5 +++-- src/core/services/gsp_gpu.cpp | 16 ++++++++++++++-- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/emulator.hpp b/include/emulator.hpp index a3821d7f..193ea536 100644 --- a/include/emulator.hpp +++ b/include/emulator.hpp @@ -30,7 +30,7 @@ class Emulator { public: Emulator() : window(sf::VideoMode(width, height), "Alber", sf::Style::Default, sf::ContextSettings(0, 0, 0, 4, 3)), - kernel(cpu, memory, gpu), cpu(memory, kernel) { + kernel(cpu, memory, gpu), cpu(memory, kernel), gpu(memory) { reset(); window.setActive(true); } diff --git a/include/gpu.hpp b/include/gpu.hpp index c62ff991..e01a4d1d 100644 --- a/include/gpu.hpp +++ b/include/gpu.hpp @@ -1,10 +1,12 @@ #pragma once #include "helpers.hpp" +#include "memory.hpp" class GPU { + Memory& mem; public: - GPU() {} + GPU(Memory& mem) : mem(mem) {} void clearBuffer(u32 startAddress, u32 endAddress, u32 value, u32 control); void reset(); }; \ No newline at end of file diff --git a/include/services/gsp_gpu.hpp b/include/services/gsp_gpu.hpp index e4b2eb35..42e88d8d 100644 --- a/include/services/gsp_gpu.hpp +++ b/include/services/gsp_gpu.hpp @@ -26,7 +26,7 @@ class GPUService { // This is the PID of that process u32 privilegedProcess; - void processCommands(); + void processCommandBuffer(); // Service commands void acquireRight(u32 messagePointer); @@ -37,7 +37,8 @@ class GPUService { void writeHwRegs(u32 messagePointer); void writeHwRegsWithMask(u32 messagePointer); - // GPU commands processed via TriggerCmdReqQueue + // GSP commands processed via TriggerCmdReqQueue + void processCommandList(u32* cmd); void memoryFill(u32* cmd); public: diff --git a/src/core/services/gsp_gpu.cpp b/src/core/services/gsp_gpu.cpp index 9d5d9ace..c7b31810 100644 --- a/src/core/services/gsp_gpu.cpp +++ b/src/core/services/gsp_gpu.cpp @@ -16,6 +16,7 @@ namespace ServiceCommands { // Commands written to shared memory and processed by TriggerCmdReqQueue namespace GPUCommands { enum : u32 { + ProcessCommandList = 1, MemoryFill = 2 }; } @@ -186,14 +187,14 @@ void GPUService::setLCDForceBlack(u32 messagePointer) { } void GPUService::triggerCmdReqQueue(u32 messagePointer) { - processCommands(); + processCommandBuffer(); mem.write32(messagePointer + 4, Result::Success); } #include #include using namespace std::chrono_literals; -void GPUService::processCommands() { +void GPUService::processCommandBuffer() { if (sharedMem == nullptr) [[unlikely]] { // Shared memory hasn't been set up yet return; } @@ -211,6 +212,7 @@ void GPUService::processCommands() { while (commandsLeft != 0) { u32 cmdID = cmd[0] & 0xff; switch (cmdID) { + case GPUCommands::ProcessCommandList: processCommandList(cmd); break; case GPUCommands::MemoryFill: memoryFill(cmd); break; default: Helpers::panic("GSP::GPU::ProcessCommands: Unknown cmd ID %d", cmdID); } @@ -243,4 +245,14 @@ void GPUService::memoryFill(u32* cmd) { if (start1 != 0) { gpu.clearBuffer(start1, end1, value1, control1); } +} + +// Actually send command list (aka display list) to GPU +void GPUService::processCommandList(u32* cmd) { + u32 address = cmd[1]; // Buffer address + u32 size = cmd[2]; // Buffer size + bool updateGas = cmd[3] == 1; // Update gas additive blend results (0 = don't update, 1 = update) + bool flushBuffer = cmd[7] == 1; // Flush buffer (0 = don't flush, 1 = flush) + + Helpers::panic("GPU::GSP::processCommandList. Address: %08X, size: %08X", address, size); } \ No newline at end of file