Skip to content

Commit

Permalink
Using less common symbol names for mem operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinnegatamante committed Nov 13, 2020
1 parent 2b4409b commit ab6ae28
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 38 deletions.
4 changes: 2 additions & 2 deletions source/framebuffers.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ void glDeleteFramebuffers(GLsizei n, GLuint *framebuffers) {
fb->target = NULL;
}
if (fb->depth_buffer_addr) {
mempool_free(fb->depth_buffer_addr, fb->depth_buffer_mem_type);
mempool_free(fb->stencil_buffer_addr, fb->stencil_buffer_mem_type);
vgl_mem_free(fb->depth_buffer_addr, fb->depth_buffer_mem_type);
vgl_mem_free(fb->stencil_buffer_addr, fb->stencil_buffer_mem_type);
fb->depth_buffer_addr = NULL;
fb->stencil_buffer_addr = NULL;
}
Expand Down
14 changes: 7 additions & 7 deletions source/gxm.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ void initGxmContext(void) {

void termGxmContext(void) {
// Deallocating ring buffers
mempool_free(vdm_ring_buffer_addr, VGL_MEM_VRAM);
mempool_free(vertex_ring_buffer_addr, VGL_MEM_VRAM);
mempool_free(fragment_ring_buffer_addr, VGL_MEM_VRAM);
vgl_mem_free(vdm_ring_buffer_addr, VGL_MEM_VRAM);
vgl_mem_free(vertex_ring_buffer_addr, VGL_MEM_VRAM);
vgl_mem_free(fragment_ring_buffer_addr, VGL_MEM_VRAM);
gpu_fragment_usse_free_mapped(fragment_usse_ring_buffer_addr);

// Destroying sceGxm context
Expand Down Expand Up @@ -272,7 +272,7 @@ void termDisplayColorSurfaces(void) {
int i;
for (i = 0; i < DISPLAY_BUFFER_COUNT; i++) {
if (!system_app_mode)
mempool_free(gxm_color_surfaces_addr[i], VGL_MEM_VRAM);
vgl_mem_free(gxm_color_surfaces_addr[i], VGL_MEM_VRAM);
sceGxmSyncObjectDestroy(gxm_sync_objects[i]);
}
}
Expand Down Expand Up @@ -311,8 +311,8 @@ void initDepthStencilSurfaces(void) {

void termDepthStencilSurfaces(void) {
// Deallocating depth and stencil surfaces memblocks
mempool_free(gxm_depth_surface_addr, VGL_MEM_VRAM);
mempool_free(gxm_stencil_surface_addr, VGL_MEM_VRAM);
vgl_mem_free(gxm_depth_surface_addr, VGL_MEM_VRAM);
vgl_mem_free(gxm_stencil_surface_addr, VGL_MEM_VRAM);
}

void startShaderPatcher(void) {
Expand Down Expand Up @@ -366,7 +366,7 @@ void stopShaderPatcher(void) {
sceGxmShaderPatcherDestroy(gxm_shader_patcher);

// Freeing shader patcher buffers
mempool_free(gxm_shader_patcher_buffer_addr, VGL_MEM_VRAM);
vgl_mem_free(gxm_shader_patcher_buffer_addr, VGL_MEM_VRAM);
gpu_vertex_usse_free_mapped(gxm_shader_patcher_vertex_usse_addr);
gpu_fragment_usse_free_mapped(gxm_shader_patcher_fragment_usse_addr);
}
Expand Down
14 changes: 7 additions & 7 deletions source/utils/gpu_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,18 @@ void swizzle_compressed_texture(uint8_t *dst, uint8_t *src, int w, int h, int is

void *gpu_alloc_mapped(size_t size, vglMemType *type) {
// Allocating requested memblock
void *res = mempool_alloc(size, *type);
void *res = vgl_mem_alloc(size, *type);

// Requested memory type finished, using other one
if (res == NULL) {
*type = *type == VGL_MEM_VRAM ? VGL_MEM_RAM : VGL_MEM_VRAM;
res = mempool_alloc(size, *type);
res = vgl_mem_alloc(size, *type);
}

// Even the other one failed, using our last resort
if (res == NULL) {
*type = VGL_MEM_SLOW;
res = mempool_alloc(size, *type);
res = vgl_mem_alloc(size, *type);
}

if (res == NULL && use_extra_mem) {
Expand Down Expand Up @@ -144,7 +144,7 @@ void gpu_vertex_usse_free_mapped(void *addr) {
sceGxmUnmapVertexUsseMemory(addr);

// Deallocating memblock
mempool_free(addr, vert_usse_type);
vgl_mem_free(addr, vert_usse_type);
}

void *gpu_fragment_usse_alloc_mapped(size_t size, unsigned int *usse_offset) {
Expand All @@ -164,7 +164,7 @@ void gpu_fragment_usse_free_mapped(void *addr) {
sceGxmUnmapFragmentUsseMemory(addr);

// Deallocating memblock
mempool_free(addr, frag_usse_type);
vgl_mem_free(addr, frag_usse_type);
}

void *gpu_pool_malloc(unsigned int size) {
Expand Down Expand Up @@ -267,7 +267,7 @@ palette *gpu_alloc_palette(const void *data, uint32_t w, uint32_t bpe) {
void gpu_free_texture(texture *tex) {
// Deallocating texture
if (tex->data != NULL)
mempool_free(tex->data, tex->mtype);
vgl_mem_free(tex->data, tex->mtype);

// Invalidating texture object
tex->valid = 0;
Expand Down Expand Up @@ -537,6 +537,6 @@ void gpu_free_palette(palette *pal) {
// Deallocating palette memblock and object
if (pal == NULL)
return;
mempool_free(pal->data, pal->type);
vgl_mem_free(pal->data, pal->type);
free(pal);
}
10 changes: 4 additions & 6 deletions source/utils/mem_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ void mem_term(void) {
}
}

int mem_init(size_t size_ram, size_t size_cdram, size_t size_phycont) {
void vgl_mem_init(size_t size_ram, size_t size_cdram, size_t size_phycont) {
if (mempool_addr[0] != NULL)
mem_term();

Expand Down Expand Up @@ -297,25 +297,23 @@ int mem_init(size_t size_ram, size_t size_cdram, size_t size_phycont) {
heap_extend(VGL_MEM_RAM, mempool_addr[1], mempool_size[1]);
if (size_phycont)
heap_extend(VGL_MEM_SLOW, mempool_addr[2], mempool_size[2]);

return 1;
}

void mempool_free(void *ptr, vglMemType type) {
void vgl_mem_free(void *ptr, vglMemType type) {
if (type == VGL_MEM_EXTERNAL)
free(ptr);
else
heap_free(ptr); // type is already stored in heap for alloc'd blocks
}

void *mempool_alloc(size_t size, vglMemType type) {
void *vgl_mem_alloc(size_t size, vglMemType type) {
void *res = NULL;
if (size <= tm_free[type])
res = heap_alloc(type, size, MEM_ALIGNMENT);
return res;
}

// Returns currently free space on mempool
size_t mempool_get_free_space(vglMemType type) {
size_t vgl_mem_get_free_space(vglMemType type) {
return tm_free[type];
}
10 changes: 5 additions & 5 deletions source/utils/mem_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
#ifndef _MEM_UTILS_H_
#define _MEM_UTILS_H_

int mem_init(size_t size_ram, size_t size_cdram, size_t size_phycont); // Initialize mempools
void mem_term(void); // Terminate both CDRAM and RAM mempools
size_t mempool_get_free_space(vglMemType type); // Return free space in bytes for a mempool
void *mempool_alloc(size_t size, vglMemType type); // Allocate a memory block on a mempool
void mempool_free(void *ptr, vglMemType type); // Free a memory block on a mempool
void vgl_mem_init(size_t size_ram, size_t size_cdram, size_t size_phycont); // Initialize internal mempools
void vgl_mem_term(void); // Terminate internal mempools
size_t vgl_mem_get_free_space(vglMemType type); // Return free space in bytes for a mempool
void *vgl_mem_alloc(size_t size, vglMemType type); // Allocate a memory block on a mempool
void vgl_mem_free(void *ptr, vglMemType type); // Free a memory block on a mempool

#endif
22 changes: 11 additions & 11 deletions source/vitaGL.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ void vglInitWithCustomSizes(uint32_t gpu_pool_size, int width, int height, int r
// Initializing sceGxm
initGxm();

// Initializing memory heap for CDRAM and RAM memory
mem_init(ram_pool_size, cdram_pool_size, phycont_pool_size);
// Initializing memory heaps for CDRAM and RAM memory (both standard and physically contiguous)
vgl_mem_init(ram_pool_size, cdram_pool_size, phycont_pool_size);

// Initializing sceGxm context
initGxmContext();
Expand Down Expand Up @@ -737,10 +737,10 @@ void vglEnd(void) {
waitRenderingDone();

// Deallocating default vertices buffers
mempool_free(clear_vertices, VGL_MEM_RAM);
mempool_free(depth_vertices, VGL_MEM_RAM);
mempool_free(depth_clear_indices, VGL_MEM_RAM);
mempool_free(scissor_test_vertices, VGL_MEM_RAM);
vgl_mem_free(clear_vertices, VGL_MEM_RAM);
vgl_mem_free(depth_vertices, VGL_MEM_RAM);
vgl_mem_free(depth_clear_indices, VGL_MEM_RAM);
vgl_mem_free(scissor_test_vertices, VGL_MEM_RAM);

// Releasing shader programs from sceGxmShaderPatcher
sceGxmShaderPatcherReleaseFragmentProgram(gxm_shader_patcher, scissor_test_fragment_program);
Expand Down Expand Up @@ -837,7 +837,7 @@ void glDeleteBuffers(GLsizei n, const GLuint *gl_buffers) {
uint8_t idx = gl_buffers[j] - BUFFERS_ADDR;
buffers[idx] = gl_buffers[j];
if (gpu_buffers[idx].ptr != NULL) {
mempool_free(gpu_buffers[idx].ptr, VGL_MEM_VRAM);
vgl_mem_free(gpu_buffers[idx].ptr, VGL_MEM_VRAM);
gpu_buffers[idx].ptr = NULL;
gpu_buffers[idx].size = 0;
}
Expand Down Expand Up @@ -871,7 +871,7 @@ void glBufferData(GLenum target, GLsizei size, const GLvoid *data, GLenum usage)

// Free buffer if already existing.
if (gpu_buffers[idx].ptr != NULL)
mempool_free(gpu_buffers[idx].ptr, type);
vgl_mem_free(gpu_buffers[idx].ptr, type);

gpu_buffers[idx].ptr = gpu_alloc_mapped(size, &type);
gpu_buffers[idx].size = size;
Expand Down Expand Up @@ -2223,17 +2223,17 @@ void vglDrawObjects(GLenum mode, GLsizei count, GLboolean implicit_wvp) {
size_t vglMemFree(vglMemType type) {
if (type >= VGL_MEM_TYPE_COUNT)
return 0;
return mempool_get_free_space(type);
return vgl_mem_get_free_space(type);
}

void *vglAlloc(uint32_t size, vglMemType type) {
if (type >= VGL_MEM_TYPE_COUNT)
return NULL;
return mempool_alloc(size, type);
return vgl_mem_alloc(size, type);
}

void vglFree(void *addr) {
mempool_free(addr, VGL_MEM_RAM); // Type is discarded so we just pass a random one
vgl_mem_free(addr, VGL_MEM_RAM); // Type is discarded so we just pass a random one
}

void vglUseExtraMem(GLboolean use) {
Expand Down

0 comments on commit ab6ae28

Please sign in to comment.