Add a custom extension to query and defragment texture memory

This commit is contained in:
Luke Benstead 2021-02-19 21:28:31 +00:00
parent 425a0c2af1
commit f9b7cd7985
5 changed files with 52 additions and 3 deletions

View File

@ -374,6 +374,10 @@ void _glKosThrowError(GLenum error, const char *function);
void _glKosPrintError(); void _glKosPrintError();
GLubyte _glKosHasError(); GLubyte _glKosHasError();
GLuint _glFreeTextureMemory();
GLuint _glUsedTextureMemory();
GLuint _glFreeContiguousTextureMemory();
#define PVR_VERTEX_BUF_SIZE 2560 * 256 #define PVR_VERTEX_BUF_SIZE 2560 * 256
#define MAX_TEXTURE_UNITS 2 #define MAX_TEXTURE_UNITS 2
#define MAX_LIGHTS 8 #define MAX_LIGHTS 8

View File

@ -696,6 +696,15 @@ void APIENTRY glGetIntegerv(GLenum pname, GLint *params) {
params[i] = COMPRESSED_FORMATS[i]; params[i] = COMPRESSED_FORMATS[i];
} }
} break; } break;
case GL_FREE_TEXTURE_MEMORY_KOS:
*params = _glFreeTextureMemory();
break;
case GL_USED_TEXTURE_MEMORY_KOS:
*params = _glUsedTextureMemory();
break;
case GL_FREE_CONTIGUOUS_TEXTURE_MEMORY_KOS:
*params = _glFreeContiguousTextureMemory();
break;
default: default:
_glKosThrowError(GL_INVALID_ENUM, __func__); _glKosThrowError(GL_INVALID_ENUM, __func__);
_glKosPrintError(); _glKosPrintError();
@ -715,7 +724,7 @@ const GLubyte *glGetString(GLenum name) {
return (const GLubyte*) "1.2 (partial) - GLdc 1.1"; return (const GLubyte*) "1.2 (partial) - GLdc 1.1";
case GL_EXTENSIONS: case GL_EXTENSIONS:
return (const GLubyte*) "GL_ARB_framebuffer_object, GL_ARB_multitexture, GL_ARB_texture_rg, GL_EXT_paletted_texture, GL_EXT_shared_texture_palette, GL_KOS_multiple_shared_palette, GL_ARB_vertex_array_bgra, GL_ARB_vertex_type_2_10_10_10_rev"; return (const GLubyte*) "GL_ARB_framebuffer_object, GL_ARB_multitexture, GL_ARB_texture_rg, GL_EXT_paletted_texture, GL_EXT_shared_texture_palette, GL_KOS_multiple_shared_palette, GL_ARB_vertex_array_bgra, GL_ARB_vertex_type_2_10_10_10_rev, GL_KOS_texture_memory_management";
} }
return (const GLubyte*) "GL_KOS_ERROR: ENUM Unsupported\n"; return (const GLubyte*) "GL_KOS_ERROR: ENUM Unsupported\n";

View File

@ -1065,7 +1065,7 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
active->height != height || active->height != height ||
active->color != pvr_format) { active->color != pvr_format) {
/* changed - free old texture memory */ /* changed - free old texture memory */
pvr_mem_free(active->data); yalloc_free(YALLOC_BASE, active->data);
active->data = NULL; active->data = NULL;
active->mipmap = 0; active->mipmap = 0;
active->mipmapCount = 0; active->mipmapCount = 0;
@ -1104,7 +1104,7 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
/* If we're uploading a mipmap level, we need to allocate the full amount of space */ /* If we're uploading a mipmap level, we need to allocate the full amount of space */
_glAllocateSpaceForMipmaps(active); _glAllocateSpaceForMipmaps(active);
} else { } else {
active->data = pvr_mem_malloc(active->baseDataSize); active->data = yalloc_alloc(YALLOC_BASE, active->baseDataSize);
} }
assert(active->data); assert(active->data);
@ -1544,3 +1544,31 @@ GLAPI void APIENTRY glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height
_GL_UNUSED(pixels); _GL_UNUSED(pixels);
assert(0 && "Not Implemented"); assert(0 && "Not Implemented");
} }
GLuint _glFreeTextureMemory() {
return yalloc_count_free(YALLOC_BASE);
}
GLuint _glUsedTextureMemory() {
return YALLOC_SIZE - _glFreeTextureMemory();
}
GLuint _glFreeContiguousTextureMemory() {
return yalloc_count_continuous(YALLOC_BASE);
}
GLAPI GLvoid APIENTRY glDefragmentTextureMemory_KOS(void) {
yalloc_defrag_start(YALLOC_BASE);
GLuint id;
/* Replace all texture pointers */
for(id = 0; id < MAX_TEXTURE_COUNT; id++){
if(glIsTexture(id)){
TextureObject* txr = (TextureObject*) named_array_get(&TEXTURE_OBJECTS, id);
txr->data = yalloc_defrag_address(YALLOC_BASE, txr->data);
}
}
yalloc_defrag_commit(YALLOC_BASE);
}

View File

@ -8,6 +8,7 @@
TARGET = libGLdc.a TARGET = libGLdc.a
OBJS = GL/draw.o GL/flush.o GL/framebuffer.o GL/immediate.o GL/lighting.o GL/state.o GL/texture.o GL/glu.o GL/version.h OBJS = GL/draw.o GL/flush.o GL/framebuffer.o GL/immediate.o GL/lighting.o GL/state.o GL/texture.o GL/glu.o GL/version.h
OBJS += GL/matrix.o GL/fog.o GL/error.o GL/clip.o containers/stack.o containers/named_array.o containers/aligned_vector.o GL/profiler.o OBJS += GL/matrix.o GL/fog.o GL/error.o GL/clip.o containers/stack.o containers/named_array.o containers/aligned_vector.o GL/profiler.o
OBJS += GL/yalloc/yalloc.o
SUBDIRS = SUBDIRS =

View File

@ -111,5 +111,12 @@ GLAPI void APIENTRY glKosSwapBuffers();
/* Pass to glTexParameteri to set the shared bank */ /* Pass to glTexParameteri to set the shared bank */
#define GL_SHARED_TEXTURE_BANK_KOS 0xEF00 #define GL_SHARED_TEXTURE_BANK_KOS 0xEF00
/* Memory allocation extension (GL_KOS_texture_memory_management) */
GLAPI GLvoid APIENTRY glDefragmentTextureMemory_KOS(void);
#define GL_FREE_TEXTURE_MEMORY_KOS 0xEF01
#define GL_USED_TEXTURE_MEMORY_KOS 0xEF02
#define GL_FREE_CONTIGUOUS_TEXTURE_MEMORY_KOS 0xEF03
__END_DECLS __END_DECLS