Merge branch 'master' into bottom-screen

This commit is contained in:
wheremyfoodat 2023-06-17 02:19:30 +03:00
commit 7b859ad602
11 changed files with 107 additions and 69 deletions

View file

@ -1,5 +1,7 @@
#pragma once
#include <span>
#include "dynarmic/interface/A32/a32.h"
#include "dynarmic/interface/A32/config.h"
#include "dynarmic/interface/exclusive_monitor.h"
@ -132,17 +134,11 @@ public:
return jit->Regs()[index];
}
std::array<u32, 16>& regs() {
return jit->Regs();
}
std::span<u32, 16> regs() { return jit->Regs(); }
// Get reference to array of FPRs. This array consists of the FPRs as single precision values
// Hence why its base type is u32
// Note: Dynarmic keeps 64 VFP registers as VFPv3 extends the VFP register set to 64 registers.
// However the 3DS ARM11 is an ARMv6k processor with VFPv2, so only the first 32 registers are actually used
std::array<u32, 64>& fprs() {
return jit->ExtRegs();
}
// Get reference to array of FPRs. This array consists of the FPRs as single precision values
// Hence why its base type is u32
std::span<u32, 32> fprs() { return std::span(jit->ExtRegs()).first<32>(); }
void setCPSR(u32 value) {
jit->SetCpsr(value);

View file

@ -2,10 +2,12 @@
#include <array>
#include <cassert>
#include <limits>
#include <span>
#include <string>
#include <vector>
#include "kernel_types.hpp"
#include "helpers.hpp"
#include "kernel_types.hpp"
#include "logger.hpp"
#include "memory.hpp"
#include "resource_limits.hpp"
@ -14,7 +16,7 @@
class CPU;
class Kernel {
std::array<u32, 16>& regs;
std::span<u32, 16> regs;
CPU& cpu;
Memory& mem;

View file

@ -30,6 +30,19 @@
#include "gl3w.h"
// Check if we have C++20. If yes, we can add C++20 std::span support
#ifdef _MSVC_LANG // MSVC does not properly define __cplusplus without a compiler flag...
#if _MSVC_LANG >= 202002L
#define OPENGL_HAVE_CPP20
#endif
#elif __cplusplus >= 202002L
#define OPENGL_HAVE_CPP20
#endif // MSVC_LANG
#ifdef OPENGL_HAVE_CPP20
#include <span>
#endif
// Uncomment the following define if you want GL objects to automatically free themselves when their lifetime ends
// #define OPENGL_DESTRUCTORS
@ -389,17 +402,30 @@ namespace OpenGL {
void free() { glDeleteBuffers(1, &m_handle); }
// Reallocates the buffer on every call. Prefer the sub version if possible.
template <typename VertType>
void bufferVerts(VertType* vertices, int vertCount, GLenum usage = GL_DYNAMIC_DRAW) {
glBufferData(GL_ARRAY_BUFFER, sizeof(VertType) * vertCount, vertices, usage);
}
template <typename VertType>
void bufferVerts(VertType* vertices, int vertCount, GLenum usage = GL_DYNAMIC_DRAW) {
glBufferData(GL_ARRAY_BUFFER, sizeof(VertType) * vertCount, vertices, usage);
}
// Only use if you used createFixedSize
template <typename VertType>
void bufferVertsSub(VertType* vertices, int vertCount, GLintptr offset = 0) {
glBufferSubData(GL_ARRAY_BUFFER, offset, sizeof(VertType) * vertCount, vertices);
}
};
// Only use if you used createFixedSize
template <typename VertType>
void bufferVertsSub(VertType* vertices, int vertCount, GLintptr offset = 0) {
glBufferSubData(GL_ARRAY_BUFFER, offset, sizeof(VertType) * vertCount, vertices);
}
// If C++20 is available, add overloads that take std::span instead of raw pointers
#ifdef OPENGL_HAVE_CPP20
template <typename VertType>
void bufferVerts(std::span<const VertType> vertices, GLenum usage = GL_DYNAMIC_DRAW) {
glBufferData(GL_ARRAY_BUFFER, sizeof(VertType) * vertices.size(), vertices.data(), usage);
}
template <typename VertType>
void bufferVertsSub(std::span<const VertType> vertices, GLintptr offset = 0) {
glBufferSubData(GL_ARRAY_BUFFER, offset, sizeof(VertType) * vertices.size(), vertices.data());
}
#endif
};
enum DepthFunc {
Never = GL_NEVER, // Depth test never passes

View file

@ -1,5 +1,7 @@
#pragma once
#include <array>
#include <span>
#include "helpers.hpp"
#include "logger.hpp"
#include "opengl.hpp"
@ -24,7 +26,7 @@ class Renderer {
OpenGL::VertexBuffer vbo;
GLint alphaControlLoc = -1;
GLint texUnitConfigLoc = -1;
// Depth configuration uniform locations
GLint depthOffsetLoc = -1;
GLint depthScaleLoc = -1;
@ -41,11 +43,11 @@ class Renderer {
SurfaceCache<ColourBuffer, 10> colourBufferCache;
SurfaceCache<Texture, 256> textureCache;
OpenGL::uvec2 fbSize; // The size of the framebuffer (ie both the colour and depth buffer)'
OpenGL::uvec2 fbSize; // The size of the framebuffer (ie both the colour and depth buffer)'
u32 colourBufferLoc; // Location in 3DS VRAM for the colour buffer
ColourBuffer::Formats colourBufferFormat; // Format of the colours stored in the colour buffer
u32 colourBufferLoc; // Location in 3DS VRAM for the colour buffer
ColourBuffer::Formats colourBufferFormat; // Format of the colours stored in the colour buffer
// Same for the depth/stencil buffer
u32 depthBufferLoc;
DepthBuffer::Formats depthBufferFormat;
@ -54,7 +56,7 @@ class Renderer {
OpenGL::VertexArray dummyVAO;
OpenGL::VertexBuffer dummyVBO;
static constexpr u32 regNum = 0x300; // Number of internal PICA registers
static constexpr u32 regNum = 0x300; // Number of internal PICA registers
const std::array<u32, regNum>& regs;
OpenGL::Texture screenTexture;
@ -67,16 +69,16 @@ class Renderer {
void setupBlending();
void bindDepthBuffer();
public:
public:
Renderer(GPU& gpu, const std::array<u32, regNum>& internalRegs) : gpu(gpu), regs(internalRegs) {}
void reset();
void display(); // Display the 3DS screen contents to the window
void initGraphicsContext(); // Initialize graphics context
void getGraphicsContext(); // Set up graphics context for rendering
void clearBuffer(u32 startAddress, u32 endAddress, u32 value, u32 control); // Clear a GPU buffer in VRAM
void displayTransfer(u32 inputAddr, u32 outputAddr, u32 inputSize, u32 outputSize, u32 flags); // Perform display transfer
void drawVertices(OpenGL::Primitives primType, Vertex* vertices, u32 count); // Draw the given vertices
void display(); // Display the 3DS screen contents to the window
void initGraphicsContext(); // Initialize graphics context
void getGraphicsContext(); // Set up graphics context for rendering
void clearBuffer(u32 startAddress, u32 endAddress, u32 value, u32 control); // Clear a GPU buffer in VRAM
void displayTransfer(u32 inputAddr, u32 outputAddr, u32 inputSize, u32 outputSize, u32 flags); // Perform display transfer
void drawVertices(OpenGL::Primitives primType, std::span<const Vertex> vertices); // Draw the given vertices
void setFBSize(u32 width, u32 height) {
fbSize.x() = width;

View file

@ -1,6 +1,8 @@
#pragma once
#include <array>
#include <optional>
#include <span>
#include "kernel_types.hpp"
#include "logger.hpp"
#include "memory.hpp"
@ -14,16 +16,16 @@
#include "services/cfg.hpp"
#include "services/dlp_srvr.hpp"
#include "services/dsp.hpp"
#include "services/hid.hpp"
#include "services/frd.hpp"
#include "services/fs.hpp"
#include "services/gsp_gpu.hpp"
#include "services/gsp_lcd.hpp"
#include "services/hid.hpp"
#include "services/ldr_ro.hpp"
#include "services/mic.hpp"
#include "services/ndm.hpp"
#include "services/nfc.hpp"
#include "services/nim.hpp"
#include "services/ndm.hpp"
#include "services/ptm.hpp"
#include "services/y2r.hpp"
@ -31,7 +33,7 @@
class Kernel;
class ServiceManager {
std::array<u32, 16>& regs;
std::span<u32, 16> regs;
Memory& mem;
Kernel& kernel;
@ -69,8 +71,8 @@ class ServiceManager {
void registerClient(u32 messagePointer);
void subscribe(u32 messagePointer);
public:
ServiceManager(std::array<u32, 16>& regs, Memory& mem, GPU& gpu, u32& currentPID, Kernel& kernel);
public:
ServiceManager(std::span<u32, 16> regs, Memory& mem, GPU& gpu, u32& currentPID, Kernel& kernel);
void reset();
void initializeFS() { fs.initializeFilesystem(); }
void handleSyncRequest(u32 messagePointer);