[PICA] Shader uploads

This commit is contained in:
wheremyfoodat 2022-09-22 03:46:19 +03:00
parent 36a30da78d
commit 5993dc4759
11 changed files with 105 additions and 9 deletions

View file

@ -2,10 +2,12 @@
#include <array>
#include "helpers.hpp"
#include "memory.hpp"
#include "PICA/shader_unit.hpp"
class GPU {
Memory& mem;
static constexpr u32 regNum = 0x300;
ShaderUnit shaderUnit;
std::array<u32, regNum> regs; // GPU internal registers
public:

16
include/PICA/regs.hpp Normal file
View file

@ -0,0 +1,16 @@
#pragma once
namespace PICAInternalRegs {
enum : u32 {
VertexShaderTransferEnd = 0x2BF,
VertexShaderTransferIndex = 0x2CB,
VertexShaderData0 = 0x2CC,
VertexShaderData1 = 0x2CD,
VertexShaderData2 = 0x2CE,
VertexShaderData3 = 0x2CF,
VertexShaderData4 = 0x2D0,
VertexShaderData5 = 0x2D1,
VertexShaderData6 = 0x2D2,
VertexShaderData7 = 0x2D3,
};
}

41
include/PICA/shader.hpp Normal file
View file

@ -0,0 +1,41 @@
#pragma once
#include <algorithm>
#include <array>
#include <cstring>
#include "helpers.hpp"
class PICAShader {
int bufferIndex; // Index of the next instruction to overwrite
public:
std::array<u32, 512> loadedShader; // Currently loaded & active shader
std::array<u32, 512> bufferedShader; // Shader to be transferred when the SH_CODETRANSFER_END reg gets written to
u32 boolUniform;
std::array<u32, 4> intUniforms;
std::array<u32, 8> floatUniforms;
void reset() {
loadedShader.fill(0);
bufferedShader.fill(0);
intUniforms.fill(0);
floatUniforms.fill(0);
boolUniform = 0;
bufferIndex = 0;
}
void finalize() {
std::memcpy(&loadedShader[0], &bufferedShader[0], 512 * sizeof(u32));
}
void setBufferIndex(u32 offset) {
if (offset != 0) Helpers::panic("Is this register 9 or 11 bit?");
bufferIndex = (offset >> 2) & 511;
}
void uploadWord(u32 word) {
bufferedShader[bufferIndex++] = word;
bufferIndex &= 511;
}
};

View file

@ -0,0 +1,11 @@
#pragma once
#include "PICA/shader.hpp"
class ShaderUnit {
public:
PICAShader vs; // Vertex shader
PICAShader gs; // Geometry shader
void reset();
};

View file

@ -4,9 +4,9 @@
#include <fstream>
#include "cpu.hpp"
#include "gpu.hpp"
#include "memory.hpp"
#include "opengl.hpp"
#include "PICA/gpu.hpp"
#include "SFML/Window.hpp"
#include "SFML/Graphics.hpp"

View file

@ -1,6 +1,6 @@
#pragma once
#include <cstring>
#include "gpu.hpp"
#include "PICA/gpu.hpp"
#include "helpers.hpp"
#include "kernel_types.hpp"
#include "memory.hpp"