mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-08 07:05:40 +12:00
[PICA] Start implementing shader interpreter
This commit is contained in:
parent
4b3c7955dd
commit
057aa57422
5 changed files with 32 additions and 6 deletions
|
@ -54,7 +54,9 @@ set(SERVICE_SOURCE_FILES src/core/services/service_manager.cpp src/core/services
|
||||||
src/core/services/fs.cpp src/core/services/gsp_gpu.cpp src/core/services/gsp_lcd.cpp
|
src/core/services/fs.cpp src/core/services/gsp_gpu.cpp src/core/services/gsp_lcd.cpp
|
||||||
src/core/services/ndm.cpp
|
src/core/services/ndm.cpp
|
||||||
)
|
)
|
||||||
set(PICA_SOURCE_FILES src/core/PICA/gpu.cpp src/core/PICA/regs.cpp src/core/PICA/shader_unit.cpp)
|
set(PICA_SOURCE_FILES src/core/PICA/gpu.cpp src/core/PICA/regs.cpp src/core/PICA/shader_unit.cpp
|
||||||
|
src/core/PICA/shader_interpreter.cpp
|
||||||
|
)
|
||||||
|
|
||||||
set(HEADER_FILES include/emulator.hpp include/helpers.hpp include/opengl.hpp include/termcolor.hpp
|
set(HEADER_FILES include/emulator.hpp include/helpers.hpp include/opengl.hpp include/termcolor.hpp
|
||||||
include/cpu.hpp include/cpu_dynarmic.hpp include/memory.hpp include/kernel/kernel.hpp
|
include/cpu.hpp include/cpu_dynarmic.hpp include/memory.hpp include/kernel/kernel.hpp
|
||||||
|
|
|
@ -10,12 +10,13 @@ enum class ShaderType {
|
||||||
Vertex, Geometry
|
Vertex, Geometry
|
||||||
};
|
};
|
||||||
|
|
||||||
template <ShaderType type>
|
|
||||||
class PICAShader {
|
class PICAShader {
|
||||||
int bufferIndex; // Index of the next instruction to overwrite
|
|
||||||
using f24 = Floats::f24;
|
using f24 = Floats::f24;
|
||||||
using vec4f = OpenGL::Vector<f24, 4>;
|
using vec4f = OpenGL::Vector<f24, 4>;
|
||||||
|
|
||||||
|
int bufferIndex; // Index of the next instruction to overwrite for shader uploads
|
||||||
|
ShaderType type;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::array<u32, 512> loadedShader; // Currently loaded & active shader
|
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
|
std::array<u32, 512> bufferedShader; // Shader to be transferred when the SH_CODETRANSFER_END reg gets written to
|
||||||
|
@ -28,6 +29,8 @@ public:
|
||||||
std::array<vec4f, 16> attributes; // Attributes past to the shader
|
std::array<vec4f, 16> attributes; // Attributes past to the shader
|
||||||
std::array<vec4f, 16> outputs;
|
std::array<vec4f, 16> outputs;
|
||||||
|
|
||||||
|
PICAShader(ShaderType type) : type(type) {}
|
||||||
|
|
||||||
void reset() {
|
void reset() {
|
||||||
loadedShader.fill(0);
|
loadedShader.fill(0);
|
||||||
bufferedShader.fill(0);
|
bufferedShader.fill(0);
|
||||||
|
@ -55,4 +58,6 @@ public:
|
||||||
bufferedShader[bufferIndex++] = word;
|
bufferedShader[bufferIndex++] = word;
|
||||||
bufferIndex &= 511;
|
bufferIndex &= 511;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void run();
|
||||||
};
|
};
|
|
@ -4,8 +4,9 @@
|
||||||
class ShaderUnit {
|
class ShaderUnit {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PICAShader<ShaderType::Vertex> vs; // Vertex shader
|
PICAShader vs; // Vertex shader
|
||||||
PICAShader<ShaderType::Geometry> gs; // Geometry shader
|
PICAShader gs; // Geometry shader
|
||||||
|
|
||||||
|
ShaderUnit() : vs(ShaderType::Vertex), gs(ShaderType::Geometry) {}
|
||||||
void reset();
|
void reset();
|
||||||
};
|
};
|
|
@ -71,7 +71,9 @@ void GPU::drawArrays() {
|
||||||
for (int attrCount = 0; attrCount < totalAttribCount; attrCount++) {
|
for (int attrCount = 0; attrCount < totalAttribCount; attrCount++) {
|
||||||
// Check if attribute is fixed or not
|
// Check if attribute is fixed or not
|
||||||
if (fixedAttribMask & (1 << attrCount)) { // Fixed attribute
|
if (fixedAttribMask & (1 << attrCount)) { // Fixed attribute
|
||||||
|
vec4f& fixedAttr = shaderUnit.vs.fixedAttributes[attrCount]; // TODO: Is this how it works?
|
||||||
|
vec4f& inputAttr = shaderUnit.vs.attributes[attrCount];
|
||||||
|
std::memcpy(&inputAttr, &fixedAttr, sizeof(vec4f)); // Copy fixed attr to input attr
|
||||||
} else { // Non-fixed attribute
|
} else { // Non-fixed attribute
|
||||||
auto& attr = attributeInfo[attrCount]; // Get information for this attribute
|
auto& attr = attributeInfo[attrCount]; // Get information for this attribute
|
||||||
u64 attrCfg = attr.getConfigFull(); // Get config1 | (config2 << 32)
|
u64 attrCfg = attr.getConfigFull(); // Get config1 | (config2 << 32)
|
||||||
|
@ -113,5 +115,7 @@ void GPU::drawArrays() {
|
||||||
printf("Attribute %d, type: %d, component count: %d\n", attrCount, attribType, componentCount);
|
printf("Attribute %d, type: %d, component count: %d\n", attrCount, attribType, componentCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shaderUnit.vs.run(); // Run vertex shader for vertex
|
||||||
}
|
}
|
||||||
}
|
}
|
14
src/core/PICA/shader_interpreter.cpp
Normal file
14
src/core/PICA/shader_interpreter.cpp
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#include "PICA/shader.hpp"
|
||||||
|
|
||||||
|
void PICAShader::run() {
|
||||||
|
u32 pc = 0; // Program counter
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
const u32 instruction = loadedShader[pc++];
|
||||||
|
const u32 opcode = instruction >> 26; // Top 6 bits are the opcode
|
||||||
|
|
||||||
|
switch (opcode) {
|
||||||
|
default:Helpers::panic("Unimplemented PICA instruction %08X (Opcode = %02X)", instruction, opcode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue