From a5c6fb858fec1aced4c17621c3e7fb0f5c8ed883 Mon Sep 17 00:00:00 2001 From: wheremyfoodat Date: Sun, 25 Sep 2022 17:45:59 +0300 Subject: [PATCH] [PICA] Implement int uniforms --- include/PICA/regs.hpp | 5 +++++ include/PICA/shader.hpp | 12 +++++++++++- src/core/PICA/regs.cpp | 4 ++++ src/core/PICA/shader_interpreter.cpp | 2 +- src/core/PICA/shader_unit.cpp | 5 ++++- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/include/PICA/regs.hpp b/include/PICA/regs.hpp index 7707a83a..95ead4ed 100644 --- a/include/PICA/regs.hpp +++ b/include/PICA/regs.hpp @@ -50,6 +50,11 @@ namespace PICAInternalRegs { PrimitiveConfig = 0x25E, // Vertex shader registers + VertexIntUniform0 = 0x2B1, + VertexIntUniform1 = 0x2B2, + VertexIntUniform2 = 0x2B3, + VertexIntUniform3 = 0x2B4, + VertexShaderTransferEnd = 0x2BF, VertexFloatUniformIndex = 0x2C0, VertexFloatUniformData0 = 0x2C1, diff --git a/include/PICA/shader.hpp b/include/PICA/shader.hpp index 50f5d8e3..7136312f 100644 --- a/include/PICA/shader.hpp +++ b/include/PICA/shader.hpp @@ -35,6 +35,8 @@ class PICAShader { std::array operandDescriptors; std::array tempRegisters; // General purpose registers the shader can use for temp values OpenGL::Vector addrRegister; // Address register + u32 pc = 0; // Program counter: Index of the next instruction we're going to execute + u32 loopCounter; ShaderType type; @@ -102,7 +104,7 @@ public: std::array bufferedShader; // Shader to be transferred when the SH_CODETRANSFER_END reg gets written to u32 boolUniform; - std::array intUniforms; + std::array, 4> intUniforms; std::array floatUniforms; std::array fixedAttributes; // Fixed vertex attributes @@ -164,6 +166,14 @@ public: } } + void uploadIntUniform(int index, u32 word) { + auto& u = intUniforms[index]; + u.x() = word & 0xff; + u.y() = (word >> 8) & 0xff; + u.z() = (word >> 16) & 0xff; + u.w() = (word >> 24) & 0xff; + } + void run(); void reset(); }; \ No newline at end of file diff --git a/src/core/PICA/regs.cpp b/src/core/PICA/regs.cpp index cc2e6dea..3fcff134 100644 --- a/src/core/PICA/regs.cpp +++ b/src/core/PICA/regs.cpp @@ -100,6 +100,10 @@ void GPU::writeInternalReg(u32 index, u32 value, u32 mask) { shaderUnit.vs.uploadDescriptor(value); break; + case VertexIntUniform0: case VertexIntUniform1: case VertexIntUniform2: case VertexIntUniform3: + shaderUnit.vs.uploadIntUniform(index - VertexIntUniform0, value); + break; + case VertexShaderTransferEnd: if (value != 0) shaderUnit.vs.finalize(); break; diff --git a/src/core/PICA/shader_interpreter.cpp b/src/core/PICA/shader_interpreter.cpp index d4e3b534..b1b1b6d7 100644 --- a/src/core/PICA/shader_interpreter.cpp +++ b/src/core/PICA/shader_interpreter.cpp @@ -1,7 +1,7 @@ #include "PICA/shader.hpp" void PICAShader::run() { - u32 pc = 0; // Program counter + pc = 0; while (true) { const u32 instruction = loadedShader[pc++]; diff --git a/src/core/PICA/shader_unit.cpp b/src/core/PICA/shader_unit.cpp index e6f6bce7..9d2406cc 100644 --- a/src/core/PICA/shader_unit.cpp +++ b/src/core/PICA/shader_unit.cpp @@ -10,7 +10,6 @@ void PICAShader::reset() { bufferedShader.fill(0); operandDescriptors.fill(0); - intUniforms.fill(0); boolUniform = 0; bufferIndex = 0; floatUniformIndex = 0; @@ -24,6 +23,10 @@ void PICAShader::reset() { outputs.fill(zero); tempRegisters.fill(zero); + for (auto& e : intUniforms) { + e.x() = e.y() = e.z() = e.w() = 0; + } + addrRegister.x() = 0; addrRegister.y() = 0; loopCounter = 0;