run clang format

This commit is contained in:
olebeck 2025-06-28 03:39:00 +02:00
parent 4744142c9d
commit 7c15d4f9d8
5 changed files with 616 additions and 525 deletions

View File

@ -102,7 +102,7 @@ jobs:
- name: Configure (CMake) - name: Configure (CMake)
run: | run: |
if [ "${{ matrix.vita }}" = "true" ]; then if [ "${{ matrix.vita }}" = "true" ]; then
PRESET=--preset vita-debug PRESET="--preset vita-debug"
fi fi
${{ matrix.cmake-wrapper || '' }} cmake $PRESET -S . -B build -GNinja \ ${{ matrix.cmake-wrapper || '' }} cmake $PRESET -S . -B build -GNinja \
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \ -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \

View File

@ -1,165 +1,166 @@
#include "memory.h" #include "memory.h"
#include "utils.h" #include "utils.h"
#include <psp2/gxm.h>
#include <SDL3/SDL_stdinc.h> #include <SDL3/SDL_stdinc.h>
#include <psp2/gxm.h>
static SceUID cdramPoolUID = -1; static SceUID cdramPoolUID = -1;
static SceClibMspace cdramPool = NULL; static SceClibMspace cdramPool = NULL;
void* patcher_host_alloc(void* user_data, unsigned int size)
void *patcher_host_alloc(void *user_data, unsigned int size)
{ {
void *mem = SDL_malloc(size); void* mem = SDL_malloc(size);
(void)user_data; (void) user_data;
return mem; return mem;
} }
void patcher_host_free(void *user_data, void *mem) void patcher_host_free(void* user_data, void* mem)
{ {
(void)user_data; (void) user_data;
SDL_free(mem); SDL_free(mem);
} }
void* vita_mem_alloc( void* vita_mem_alloc(unsigned int type, size_t size, size_t alignment, int attribs, SceUID* uid)
unsigned int type, {
size_t size, void* mem;
size_t alignment,
int attribs,
SceUID *uid
) {
void *mem;
if (type == SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW) { if (type == SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW) {
size = ALIGN(size, 256 * 1024); size = ALIGN(size, 256 * 1024);
} else if (type == SCE_KERNEL_MEMBLOCK_TYPE_USER_MAIN_PHYCONT_NC_RW) { }
size = ALIGN(size, 1024 * 1024); else if (type == SCE_KERNEL_MEMBLOCK_TYPE_USER_MAIN_PHYCONT_NC_RW) {
} else { size = ALIGN(size, 1024 * 1024);
size = ALIGN(size, 4 * 1024); }
} else {
size = ALIGN(size, 4 * 1024);
}
*uid = sceKernelAllocMemBlock("gpu_mem", type, size, NULL); *uid = sceKernelAllocMemBlock("gpu_mem", type, size, NULL);
if (*uid < 0) { if (*uid < 0) {
SDL_Log("sceKernelAllocMemBlock: 0x%x", *uid); SDL_Log("sceKernelAllocMemBlock: 0x%x", *uid);
return NULL;
}
if (sceKernelGetMemBlockBase(*uid, &mem) < 0) {
return NULL;
}
if (sceGxmMapMemory(mem, size, (SceGxmMemoryAttribFlags)attribs) < 0) {
SDL_Log("sceGxmMapMemory 0x%x 0x%x %d failed", mem, size, attribs);
return NULL; return NULL;
} }
return mem; if (sceKernelGetMemBlockBase(*uid, &mem) < 0) {
return NULL;
}
if (sceGxmMapMemory(mem, size, (SceGxmMemoryAttribFlags) attribs) < 0) {
SDL_Log("sceGxmMapMemory 0x%x 0x%x %d failed", mem, size, attribs);
return NULL;
}
return mem;
} }
void vita_mem_free(SceUID uid) void vita_mem_free(SceUID uid)
{ {
void *mem = NULL; void* mem = NULL;
if (sceKernelGetMemBlockBase(uid, &mem) < 0) { if (sceKernelGetMemBlockBase(uid, &mem) < 0) {
return; return;
} }
sceGxmUnmapMemory(mem); sceGxmUnmapMemory(mem);
sceKernelFreeMemBlock(uid); sceKernelFreeMemBlock(uid);
} }
void *vita_mem_vertex_usse_alloc(unsigned int size, SceUID *uid, unsigned int *usse_offset) void* vita_mem_vertex_usse_alloc(unsigned int size, SceUID* uid, unsigned int* usse_offset)
{ {
void *mem = NULL; void* mem = NULL;
size = ALIGN(size, 4096); size = ALIGN(size, 4096);
*uid = sceKernelAllocMemBlock("vertex_usse", SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE, size, NULL); *uid = sceKernelAllocMemBlock("vertex_usse", SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE, size, NULL);
if (sceKernelGetMemBlockBase(*uid, &mem) < 0) { if (sceKernelGetMemBlockBase(*uid, &mem) < 0) {
return NULL; return NULL;
} }
if (sceGxmMapVertexUsseMemory(mem, size, usse_offset) < 0) { if (sceGxmMapVertexUsseMemory(mem, size, usse_offset) < 0) {
return NULL; return NULL;
} }
return mem; return mem;
} }
void vita_mem_vertex_usse_free(SceUID uid) void vita_mem_vertex_usse_free(SceUID uid)
{ {
void *mem = NULL; void* mem = NULL;
if (sceKernelGetMemBlockBase(uid, &mem) < 0) { if (sceKernelGetMemBlockBase(uid, &mem) < 0) {
return; return;
} }
sceGxmUnmapVertexUsseMemory(mem); sceGxmUnmapVertexUsseMemory(mem);
sceKernelFreeMemBlock(uid); sceKernelFreeMemBlock(uid);
} }
void *vita_mem_fragment_usse_alloc(unsigned int size, SceUID *uid, unsigned int *usse_offset) void* vita_mem_fragment_usse_alloc(unsigned int size, SceUID* uid, unsigned int* usse_offset)
{ {
void *mem = NULL; void* mem = NULL;
size = ALIGN(size, 4096); size = ALIGN(size, 4096);
*uid = sceKernelAllocMemBlock("fragment_usse", SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE, size, NULL); *uid = sceKernelAllocMemBlock("fragment_usse", SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE, size, NULL);
if (sceKernelGetMemBlockBase(*uid, &mem) < 0) { if (sceKernelGetMemBlockBase(*uid, &mem) < 0) {
return NULL; return NULL;
} }
if (sceGxmMapFragmentUsseMemory(mem, size, usse_offset) < 0) { if (sceGxmMapFragmentUsseMemory(mem, size, usse_offset) < 0) {
return NULL; return NULL;
} }
return mem; return mem;
} }
void vita_mem_fragment_usse_free(SceUID uid) void vita_mem_fragment_usse_free(SceUID uid)
{ {
void *mem = NULL; void* mem = NULL;
if (sceKernelGetMemBlockBase(uid, &mem) < 0) { if (sceKernelGetMemBlockBase(uid, &mem) < 0) {
return; return;
} }
sceGxmUnmapFragmentUsseMemory(mem); sceGxmUnmapFragmentUsseMemory(mem);
sceKernelFreeMemBlock(uid); sceKernelFreeMemBlock(uid);
} }
bool cdramPool_init() { bool cdramPool_init()
if(cdramPool) { {
return true; if (cdramPool) {
} return true;
int poolsize; }
int ret; int poolsize;
void* mem; int ret;
SceKernelFreeMemorySizeInfo info; void* mem;
info.size = sizeof(SceKernelFreeMemorySizeInfo); SceKernelFreeMemorySizeInfo info;
sceKernelGetFreeMemorySize(&info); info.size = sizeof(SceKernelFreeMemorySizeInfo);
sceKernelGetFreeMemorySize(&info);
poolsize = ALIGN(info.size_cdram, 256 * 1024); poolsize = ALIGN(info.size_cdram, 256 * 1024);
if (poolsize > info.size_cdram) { if (poolsize > info.size_cdram) {
poolsize = ALIGN(info.size_cdram - 256 * 1024, 256 * 1024); poolsize = ALIGN(info.size_cdram - 256 * 1024, 256 * 1024);
} }
poolsize -= 16 * 1024 * 1024; poolsize -= 16 * 1024 * 1024;
cdramPoolUID = sceKernelAllocMemBlock("gpu_cdram_pool", SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW, poolsize, NULL); cdramPoolUID = sceKernelAllocMemBlock("gpu_cdram_pool", SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW, poolsize, NULL);
if (cdramPool < 0) { if (cdramPool < 0) {
return false; return false;
} }
ret = sceKernelGetMemBlockBase(cdramPoolUID, &mem); ret = sceKernelGetMemBlockBase(cdramPoolUID, &mem);
if (ret < 0) { if (ret < 0) {
return false; return false;
} }
cdramPool = sceClibMspaceCreate(mem, poolsize); cdramPool = sceClibMspaceCreate(mem, poolsize);
if (!cdramPool) { if (!cdramPool) {
return false; return false;
} }
ret = sceGxmMapMemory(mem, poolsize, (SceGxmMemoryAttribFlags)(SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE)); ret = sceGxmMapMemory(
if (ret < 0) { mem,
return false; poolsize,
} (SceGxmMemoryAttribFlags) (SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE)
return true; );
if (ret < 0) {
return false;
}
return true;
} }
SceClibMspace cdramPool_get() { SceClibMspace cdramPool_get()
return cdramPool; {
return cdramPool;
} }

View File

@ -1,25 +1,19 @@
#pragma once #pragma once
#include <psp2/types.h>
#include <psp2/kernel/sysmem.h>
#include <psp2/kernel/clib.h>
#include <SDL3/SDL_stdinc.h> #include <SDL3/SDL_stdinc.h>
#include <psp2/kernel/clib.h>
#include <psp2/kernel/sysmem.h>
#include <psp2/types.h>
void *patcher_host_alloc(void *user_data, unsigned int size); void* patcher_host_alloc(void* user_data, unsigned int size);
void patcher_host_free(void *user_data, void *mem); void patcher_host_free(void* user_data, void* mem);
void* vita_mem_alloc( void* vita_mem_alloc(unsigned int type, size_t size, size_t alignment, int attribs, SceUID* uid);
unsigned int type,
size_t size,
size_t alignment,
int attribs,
SceUID* uid
);
void vita_mem_free(SceUID uid); void vita_mem_free(SceUID uid);
void *vita_mem_vertex_usse_alloc(unsigned int size, SceUID *uid, unsigned int *usse_offset); void* vita_mem_vertex_usse_alloc(unsigned int size, SceUID* uid, unsigned int* usse_offset);
void vita_mem_vertex_usse_free(SceUID uid); void vita_mem_vertex_usse_free(SceUID uid);
void *vita_mem_fragment_usse_alloc(unsigned int size, SceUID *uid, unsigned int *usse_offset); void* vita_mem_fragment_usse_alloc(unsigned int size, SceUID* uid, unsigned int* usse_offset);
void vita_mem_fragment_usse_free(SceUID uid); void vita_mem_fragment_usse_free(SceUID uid);
bool cdramPool_init(); bool cdramPool_init();

File diff suppressed because it is too large Load Diff

View File

@ -4,38 +4,39 @@
#include <psp2/gxm.h> #include <psp2/gxm.h>
#include <psp2/kernel/clib.h> #include <psp2/kernel/clib.h>
#define SCE_ERR(func, ...) ({ \ #define SCE_ERR(func, ...) \
sceClibPrintf(#func "\n"); \ ({ \
int __sce_err_ret_val = func(__VA_ARGS__); \ sceClibPrintf(#func "\n"); \
if (__sce_err_ret_val < 0) { \ int __sce_err_ret_val = func(__VA_ARGS__); \
sceClibPrintf(#func " error: 0x%x\n", __sce_err_ret_val); \ if (__sce_err_ret_val < 0) { \
} \ sceClibPrintf(#func " error: 0x%x\n", __sce_err_ret_val); \
__sce_err_ret_val < 0; \ } \
}) __sce_err_ret_val < 0; \
})
#define ALIGN(x, a) (((x) + ((a)-1)) & ~((a)-1)) #define ALIGN(x, a) (((x) + ((a) - 1)) & ~((a) - 1))
#define ALIGNMENT(n, a) (((a) - ((n) % (a))) % (a)) #define ALIGNMENT(n, a) (((a) - ((n) % (a))) % (a))
#define SET_UNIFORM(buffer, param, value) \
do { \
size_t __offset = sceGxmProgramParameterGetResourceIndex(param); \
void* __dst = (uint8_t*) (buffer) + (__offset * sizeof(uint32_t)); \
memcpy(__dst, reinterpret_cast<const void*>(&(value)), sizeof(value)); \
} while (0)
#define SET_UNIFORM(buffer, param, value) \ #define GET_SHADER_PARAM(var, gxp, name, ret) \
do { \ const SceGxmProgramParameter* var = sceGxmProgramFindParameterByName(gxp, name); \
size_t __offset = sceGxmProgramParameterGetResourceIndex(param); \ if (!var) { \
void* __dst = (uint8_t*)(buffer) + (__offset * sizeof(uint32_t)); \ SDL_Log("Failed to find param %s", name); \
memcpy(__dst, reinterpret_cast<const void*>(&(value)), sizeof(value)); \ return ret; \
} while (0)
#define GET_SHADER_PARAM(var, gxp, name, ret) \
const SceGxmProgramParameter* var = sceGxmProgramFindParameterByName(gxp, name); \
if(!var) { \
SDL_Log("Failed to find param %s", name); \
return ret; \
} }
static void printMatrix4x4(const float mat[4][4]) { static void printMatrix4x4(const float mat[4][4])
sceClibPrintf("mat4{\n"); {
for(int i = 0; i < 4; i++) { sceClibPrintf("mat4{\n");
sceClibPrintf("%f %f %f %f\n", mat[i][0], mat[i][1], mat[i][2], mat[i][3]); for (int i = 0; i < 4; i++) {
} sceClibPrintf("%f %f %f %f\n", mat[i][0], mat[i][1], mat[i][2], mat[i][3]);
sceClibPrintf("}\n"); }
sceClibPrintf("}\n");
} }