From 00d82ca6edeb70334e40f12fdd8018e64d04ac11 Mon Sep 17 00:00:00 2001 From: wheremyfoodat Date: Thu, 22 Sep 2022 04:03:55 +0300 Subject: [PATCH] [PICA] Implement drawArrays, get our first triangle data --- include/PICA/gpu.hpp | 2 ++ include/PICA/regs.hpp | 6 ++++++ src/core/PICA/gpu.cpp | 8 ++++++++ src/core/PICA/regs.cpp | 5 +++++ 4 files changed, 21 insertions(+) diff --git a/include/PICA/gpu.hpp b/include/PICA/gpu.hpp index 2b99880d..9b2129f1 100644 --- a/include/PICA/gpu.hpp +++ b/include/PICA/gpu.hpp @@ -10,6 +10,8 @@ class GPU { ShaderUnit shaderUnit; std::array regs; // GPU internal registers + void drawArrays(); + public: GPU(Memory& mem) : mem(mem) {} void clearBuffer(u32 startAddress, u32 endAddress, u32 value, u32 control); diff --git a/include/PICA/regs.hpp b/include/PICA/regs.hpp index 61d2f33c..afcaa5e5 100644 --- a/include/PICA/regs.hpp +++ b/include/PICA/regs.hpp @@ -2,6 +2,12 @@ namespace PICAInternalRegs { enum : u32 { + // Draw command regs + VertexCountReg = 0x228, + VertexOffsetReg = 0x22A, + SignalDrawArrays = 0x22E, + + // Vertex shader registers VertexShaderTransferEnd = 0x2BF, VertexShaderTransferIndex = 0x2CB, VertexShaderData0 = 0x2CC, diff --git a/src/core/PICA/gpu.cpp b/src/core/PICA/gpu.cpp index a9e74b2e..1abbf5a5 100644 --- a/src/core/PICA/gpu.cpp +++ b/src/core/PICA/gpu.cpp @@ -1,4 +1,5 @@ #include "PICA/gpu.hpp" +#include "PICA/regs.hpp" #include void GPU::reset() { @@ -9,4 +10,11 @@ void GPU::reset() { void GPU::clearBuffer(u32 startAddress, u32 endAddress, u32 value, u32 control) { printf("GPU: Clear buffer\nStart: %08X End: %08X\nValue: %08X Control: %08X\n", startAddress, endAddress, value, control); +} + +void GPU::drawArrays() { + const u32 vertexCount = regs[PICAInternalRegs::VertexCountReg]; + const u32 vertexOffset = regs[PICAInternalRegs::VertexOffsetReg]; + + printf("PICA::DrawArrays(vertex count = %d, vertexOffset = %d)\n", vertexCount, vertexOffset); } \ No newline at end of file diff --git a/src/core/PICA/regs.cpp b/src/core/PICA/regs.cpp index 9d37df4d..649e2584 100644 --- a/src/core/PICA/regs.cpp +++ b/src/core/PICA/regs.cpp @@ -34,10 +34,15 @@ void GPU::writeInternalReg(u32 index, u32 value, u32 mask) { u32 currentValue = regs[index]; u32 newValue = (currentValue & ~mask) | (value & mask); // Only overwrite the bits specified by "mask" + regs[index] = newValue; // TODO: Figure out if things like the shader index use the unmasked value or the masked one // We currently use the unmasked value like Citra does switch (index) { + case SignalDrawArrays: + if (value != 0) drawArrays(); + break; + case VertexShaderTransferEnd: if (value != 0) shaderUnit.vs.finalize(); break;