Cleanup for #98

This commit is contained in:
wheremyfoodat 2023-07-15 04:56:43 +03:00
parent 2f45714240
commit 7b6cd90d36
10 changed files with 95 additions and 33 deletions

View file

@ -8,7 +8,7 @@
#include "PICA/float_types.hpp"
#include "PICA/regs.hpp"
#if PANDA3DS_ENABLE_OPENGL
#ifdef PANDA3DS_ENABLE_OPENGL
#include "renderer_gl/renderer_gl.hpp"
#endif
@ -20,8 +20,8 @@ GPU::GPU(Memory& mem, EmulatorConfig& config) : mem(mem), config(config) {
vram = new u8[vramSize];
mem.setVRAM(vram); // Give the bus a pointer to our VRAM
// TODO: configurable backend
#if PANDA3DS_ENABLE_OPENGL
// TODO: Configurable backend
#ifdef PANDA3DS_ENABLE_OPENGL
renderer.reset(new RendererGL(*this, regs));
#endif
}

View file

@ -134,7 +134,10 @@ void GPU::writeInternalReg(u32 index, u32 value, u32 mask) {
break;
}
case VertexFloatUniformIndex: shaderUnit.vs.setFloatUniformIndex(value); break;
case VertexFloatUniformIndex: {
shaderUnit.vs.setFloatUniformIndex(value);
break;
}
case VertexFloatUniformData0:
case VertexFloatUniformData1:
@ -143,7 +146,10 @@ void GPU::writeInternalReg(u32 index, u32 value, u32 mask) {
case VertexFloatUniformData4:
case VertexFloatUniformData5:
case VertexFloatUniformData6:
case VertexFloatUniformData7: shaderUnit.vs.uploadFloatUniform(value); break;
case VertexFloatUniformData7: {
shaderUnit.vs.uploadFloatUniform(value);
break;
}
case FixedAttribIndex:
fixedAttribCount = 0;
@ -208,7 +214,10 @@ void GPU::writeInternalReg(u32 index, u32 value, u32 mask) {
switch (primType) {
// Triangle or geometry primitive. Draw a triangle and discard all vertices
case 0:
case 3: immediateModeVertIndex = 0; break;
case 3: {
immediateModeVertIndex = 0;
break;
}
// Triangle strip. Draw triangle, discard first vertex and keep the last 2
case 1:
@ -233,7 +242,10 @@ void GPU::writeInternalReg(u32 index, u32 value, u32 mask) {
break;
case VertexShaderOpDescriptorIndex: shaderUnit.vs.setOpDescriptorIndex(value); break;
case VertexShaderOpDescriptorIndex: {
shaderUnit.vs.setOpDescriptorIndex(value);
break;
}
case VertexShaderOpDescriptorData0:
case VertexShaderOpDescriptorData1:
@ -242,14 +254,23 @@ void GPU::writeInternalReg(u32 index, u32 value, u32 mask) {
case VertexShaderOpDescriptorData4:
case VertexShaderOpDescriptorData5:
case VertexShaderOpDescriptorData6:
case VertexShaderOpDescriptorData7: shaderUnit.vs.uploadDescriptor(value); break;
case VertexShaderOpDescriptorData7: {
shaderUnit.vs.uploadDescriptor(value);
break;
}
case VertexBoolUniform: shaderUnit.vs.boolUniform = value & 0xffff; break;
case VertexBoolUniform: {
shaderUnit.vs.boolUniform = value & 0xffff;
break;
}
case VertexIntUniform0:
case VertexIntUniform1:
case VertexIntUniform2:
case VertexIntUniform3: shaderUnit.vs.uploadIntUniform(index - VertexIntUniform0, value); break;
case VertexIntUniform3: {
shaderUnit.vs.uploadIntUniform(index - VertexIntUniform0, value);
break;
}
case VertexShaderData0:
case VertexShaderData1:
@ -258,9 +279,15 @@ void GPU::writeInternalReg(u32 index, u32 value, u32 mask) {
case VertexShaderData4:
case VertexShaderData5:
case VertexShaderData6:
case VertexShaderData7: shaderUnit.vs.uploadWord(value); break;
case VertexShaderData7: {
shaderUnit.vs.uploadWord(value);
break;
}
case VertexShaderEntrypoint: shaderUnit.vs.entrypoint = value & 0xffff; break;
case VertexShaderEntrypoint: {
shaderUnit.vs.entrypoint = value & 0xffff;
break;
}
case VertexShaderTransferEnd:
if (value != 0) shaderUnit.vs.finalize();

View file

@ -20,7 +20,11 @@ void PICAShader::run() {
case ShaderOpcodes::CALLC: callc(instruction); break;
case ShaderOpcodes::CALLU: callu(instruction); break;
case ShaderOpcodes::CMP1:
case ShaderOpcodes::CMP2: cmp(instruction); break;
case ShaderOpcodes::CMP2: {
cmp(instruction);
break;
}
case ShaderOpcodes::DP3: dp3(instruction); break;
case ShaderOpcodes::DP4: dp4(instruction); break;
case ShaderOpcodes::DPHI: dphi(instruction); break;
@ -52,7 +56,10 @@ void PICAShader::run() {
case 0x34:
case 0x35:
case 0x36:
case 0x37: madi(instruction); break;
case 0x37: {
madi(instruction);
break;
}
case 0x38:
case 0x39:
@ -61,7 +68,10 @@ void PICAShader::run() {
case 0x3C:
case 0x3D:
case 0x3E:
case 0x3F: mad(instruction); break;
case 0x3F: {
mad(instruction);
break;
}
default: Helpers::panic("Unimplemented PICA instruction %08X (Opcode = %02X)", instruction, opcode);
}
@ -588,7 +598,10 @@ void PICAShader::cmp(u32 instruction) {
cmpRegister[i] = srcVec1[i] >= srcVec2[i];
break;
default: cmpRegister[i] = true; break;
default: {
cmpRegister[i] = true;
break;
}
}
}
}
@ -682,7 +695,9 @@ void PICAShader::loop(u32 instruction) {
}
void PICAShader::jmpc(u32 instruction) {
if (isCondTrue(instruction)) pc = getBits<10, 12>(instruction);
if (isCondTrue(instruction)) {
pc = getBits<10, 12>(instruction);
}
}
void PICAShader::jmpu(u32 instruction) {

View file

@ -1,5 +1,7 @@
#include "renderer_gl/renderer_gl.hpp"
#include <stb_image_write.h>
#include "PICA/float_types.hpp"
#include "PICA/gpu.hpp"
#include "PICA/regs.hpp"
@ -841,9 +843,14 @@ void RendererGL::updateLightingLUT() {
void RendererGL::drawVertices(PICA::PrimType primType, std::span<const Vertex> vertices) {
// The fourth type is meant to be "Geometry primitive". TODO: Find out what that is
static constexpr std::array<OpenGL::Primitives, 4> primTypes = {OpenGL::Triangle, OpenGL::TriangleStrip, OpenGL::TriangleFan, OpenGL::Triangle};
const auto primitiveTopology = primTypes[static_cast<usize>(primType)];
static constexpr std::array<OpenGL::Primitives, 4> primTypes = {
OpenGL::Triangle,
OpenGL::TriangleStrip,
OpenGL::TriangleFan,
OpenGL::Triangle,
};
const auto primitiveTopology = primTypes[static_cast<usize>(primType)];
gl.disableScissor();
gl.bindVBO(vbo);
gl.bindVAO(vao);
@ -1048,7 +1055,6 @@ void RendererGL::screenshot(const std::string& name) {
std::vector<uint8_t> pixels, flippedPixels;
pixels.resize(width * height * 4);
flippedPixels.resize(pixels.size());
;
OpenGL::bindScreenFramebuffer();
glReadPixels(0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, pixels.data());

View file

@ -1,8 +1,6 @@
#include "emulator.hpp"
#include <stb_image_write.h>
#if PANDA3DS_ENABLE_OPENGL
#ifdef PANDA3DS_ENABLE_OPENGL
#include <glad/gl.h>
#endif
@ -27,7 +25,7 @@ Emulator::Emulator() : kernel(cpu, memory, gpu), cpu(memory, kernel), gpu(memory
Helpers::warn("Failed to initialize SDL2 GameController: %s", SDL_GetError());
}
#if PANDA3DS_ENABLE_OPENGL
#ifdef PANDA3DS_ENABLE_OPENGL
// Request OpenGL 4.1 Core (Max available on MacOS)
// MacOS gets mad if we don't explicitly demand a core profile
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);