From 4a9336f584d4078f218ff0ac812f4da5c586f858 Mon Sep 17 00:00:00 2001 From: Hayden K <819028+mrneo240@users.noreply.github.com> Date: Mon, 8 Apr 2019 09:36:33 -0400 Subject: [PATCH] fix all the previous crap. holy hell --- GL/draw.c | 20 ++++++++++---------- GL/error.c | 2 +- GL/flush.c | 33 +++++++-------------------------- GL/immediate.c | 5 ----- GL/profiler.c | 19 ++++--------------- GL/profiler.h | 18 +++--------------- GL/texture.c | 10 ++++------ containers/aligned_vector.c | 15 ++------------- containers/named_array.c | 12 +++++------- include/gl.h | 5 ++--- include/glkos.h | 4 ---- 11 files changed, 38 insertions(+), 105 deletions(-) diff --git a/GL/draw.c b/GL/draw.c index 0a66e45..b266912 100644 --- a/GL/draw.c +++ b/GL/draw.c @@ -1065,7 +1065,7 @@ static void submitVertices(GLenum mode, GLsizei first, GLuint count, GLenum type glActiveTextureARB(activeTexture); - PROFILER_PUSH(__func__); + profiler_push(__func__); /* Polygons are treated as triangle fans, the only time this would be a * problem is if we supported glPolygonMode(..., GL_LINE) but we don't. @@ -1103,19 +1103,19 @@ static void submitVertices(GLenum mode, GLsizei first, GLuint count, GLenum type /* Make room for the vertices and header */ aligned_vector_extend(&target->output->vector, target->count + 1); - PROFILER_CHECKPOINT("allocate"); + profiler_checkpoint("allocate"); generate(target, mode, first, count, (GLubyte*) indices, type, doTexture, doMultitexture, doLighting); - PROFILER_CHECKPOINT("generate"); + profiler_checkpoint("generate"); light(target); - PROFILER_CHECKPOINT("light"); + profiler_checkpoint("light"); transform(target); - PROFILER_CHECKPOINT("transform"); + profiler_checkpoint("transform"); if(_glIsClippingEnabled()) { #if DEBUG_CLIPPING @@ -1150,15 +1150,15 @@ static void submitVertices(GLenum mode, GLsizei first, GLuint count, GLenum type } - PROFILER_CHECKPOINT("clip"); + profiler_checkpoint("clip"); divide(target); - PROFILER_CHECKPOINT("divide"); + profiler_checkpoint("divide"); push(_glSubmissionTargetHeader(target), _glSubmissionTargetStart(target), target->count, target->output, 0); - PROFILER_CHECKPOINT("push"); + profiler_checkpoint("push"); /* Now, if multitexturing is enabled, we want to send exactly the same vertices again, except: - We want to enable blending, and send them to the TR list @@ -1169,7 +1169,7 @@ static void submitVertices(GLenum mode, GLsizei first, GLuint count, GLenum type if(!doMultitexture) { /* Multitexture actively disabled */ - PROFILER_POP(); + profiler_pop(); return; } @@ -1298,7 +1298,7 @@ void APIENTRY glDisableClientState(GLenum cap) { (ENABLED_VERTEX_ATTRIBUTES &= ~UV_ENABLED_FLAG); break; default: - _glKosThrowError(GL_INVALID_ENUM, __func__); + _glKosThrowError(GL_INVALID_ENUM, __func__); } } diff --git a/GL/error.c b/GL/error.c index d4b73c4..49732e5 100644 --- a/GL/error.c +++ b/GL/error.c @@ -57,7 +57,7 @@ void _glKosPrintError() { } fprintf(stderr, "GL ERROR: %s when calling %s\n", _glErrorEnumAsString(last_error), error_function); - _glKosResetError(); + _glKosResetError(); } GLenum glGetError(void) { diff --git a/GL/flush.c b/GL/flush.c index 45a3bc2..6c68fe7 100644 --- a/GL/flush.c +++ b/GL/flush.c @@ -120,14 +120,13 @@ void APIENTRY glKosInit() { } #define QACRTA ((((unsigned int)0x10000000)>>26)<<2)&0x1c -static int frame_count = 0; void APIENTRY glKosSwapBuffers() { - - + static int frame_count = 0; + TRACE(); - PROFILER_PUSH(__func__); + profiler_push(__func__); pvr_wait_ready(); @@ -152,29 +151,11 @@ void APIENTRY glKosSwapBuffers() { aligned_vector_clear(&PT_LIST.vector); aligned_vector_clear(&TR_LIST.vector); - PROFILER_CHECKPOINT("scene"); - PROFILER_POP(); + profiler_checkpoint("scene"); + profiler_pop(); -#if PROFILER_COMPILE - if(++frame_count > 49) { - PROFILER_PRINT_STATS(); + if(frame_count++ > 100) { + profiler_print_stats(); frame_count = 0; } -#endif -} - - -void APIENTRY glKosReserveOPList(unsigned int elements){ - aligned_vector_reserve(&OP_LIST.vector, elements); - aligned_vector_reserve((AlignedVector*)_glKosINTERNALGetVertices(), elements/3); -} - -void APIENTRY glKosReservePTList(unsigned int elements){ - aligned_vector_reserve(&PT_LIST.vector, elements); - aligned_vector_reserve((AlignedVector*)_glKosINTERNALGetVertices(), elements/3); -} - -void APIENTRY glKosReserveTRList(unsigned int elements){ - aligned_vector_reserve(&TR_LIST.vector, elements); - aligned_vector_reserve((AlignedVector*)_glKosINTERNALGetVertices(), elements/3); } diff --git a/GL/immediate.c b/GL/immediate.c index a9b3185..77b1919 100644 --- a/GL/immediate.c +++ b/GL/immediate.c @@ -296,8 +296,3 @@ void APIENTRY glRecti(GLint x1, GLint y1, GLint x2, GLint y2) { void APIENTRY glRectiv(const GLint *v1, const GLint *v2) { return glRectfv((const GLfloat *)v1, (const GLfloat *)v2); } - - -AlignedVector* APIENTRY _glKosINTERNALGetVertices(){ - return &VERTICES; -} \ No newline at end of file diff --git a/GL/profiler.c b/GL/profiler.c index 5cc9eaa..968bc9f 100644 --- a/GL/profiler.c +++ b/GL/profiler.c @@ -1,16 +1,11 @@ - #include #include #include #include #include "profiler.h" -#include "private.h" -#if PROFILER_COMPILE #include "../containers/aligned_vector.h" -#ifdef PROFILER_COMPILE - #define MAX_PATH 256 typedef struct { @@ -29,7 +24,7 @@ typedef struct { static RootProfiler* root = NULL; -static char PROFILER_ENABLED = PROFILER_COMPILE; +static char PROFILER_ENABLED = 0; void profiler_enable() { PROFILER_ENABLED = 1; @@ -131,24 +126,18 @@ void profiler_pop() { aligned_vector_resize(&root->stack, root->stack.size - 1); } -#include + void profiler_print_stats() { if(!PROFILER_ENABLED) return; - fprintf(stderr, "%-40s%-20s%-20s%-20s%-20s\n", "Path", "Time(ms)", "Average", "Total", "Calls"); - float total_ms = 0; - float fps = 0; + fprintf(stderr, "%-60s%-20s%-20s%-20s\n", "Path", "Average", "Total", "Calls"); + uint16_t i = 0; for(; i < root->results.size; ++i) { ProfilerResult* result = aligned_vector_at(&root->results, i); float ms = ((float) result->total_time_us) / 1000.0f; float avg = ms / (float) result->total_calls; - total_ms += ms; fprintf(stderr, "%-60s%-20f%-20f%" PRIu64 "\n", result->name, (double)avg, (double)ms, result->total_calls); } - total_ms/=((ProfilerResult*)aligned_vector_at(&root->results, i-1))->total_calls; - fps = 1000/total_ms; - fprintf(stderr, "%-10s%-10f%-10s%-10f\n", "Time(ms)", total_ms, "FPS", fps); } -#endif diff --git a/GL/profiler.h b/GL/profiler.h index 69c307d..acaf8bf 100644 --- a/GL/profiler.h +++ b/GL/profiler.h @@ -2,15 +2,6 @@ #include -#define PROFILER_COMPILE 0 -#if PROFILER_COMPILE -#define PROFILER_PUSH(S) profiler_push(S) -#define PROFILER_CHECKPOINT(P) profiler_checkpoint(P) -#define PROFILER_POP() profiler_pop() -#define PROFILER_PRINT_STATS() profiler_print_stats() -void profiler_enable(); -void profiler_disable(); - typedef struct { char name[64]; uint64_t start_time_in_us; @@ -22,9 +13,6 @@ void profiler_checkpoint(const char* name); void profiler_pop(); void profiler_print_stats(); -#else -#define PROFILER_PUSH(S) -#define PROFILER_CHECKPOINT(P) -#define PROFILER_POP() -#define PROFILER_PRINT_STATS() -#endif + +void profiler_enable(); +void profiler_disable(); diff --git a/GL/texture.c b/GL/texture.c index b7db324..7b3e2ed 100644 --- a/GL/texture.c +++ b/GL/texture.c @@ -36,9 +36,6 @@ static GLenum INTERNAL_PALETTE_FORMAT = GL_RGBA4; static TexturePalette* _initTexturePalette() { TexturePalette* palette = (TexturePalette*) malloc(sizeof(TexturePalette)); assert(palette); - - //memset(palette, 0x0, sizeof(TexturePalette)); - sq_clr(palette, (sizeof(TexturePalette) & 0xfffffffc) + 4); memset(palette, 0x0, sizeof(TexturePalette)); palette->bank = -1; @@ -402,7 +399,7 @@ void APIENTRY glBindTexture(GLenum target, GLuint texture) { } } -void APIENTRY glTexEnvi(GLenum target, GLenum pname, GLenum param) { +void APIENTRY glTexEnvi(GLenum target, GLenum pname, GLint param) { TRACE(); GLint target_values [] = {GL_TEXTURE_ENV, 0}; @@ -832,11 +829,12 @@ GLboolean _glIsMipmapComplete(const TextureObject* obj) { } #define TWIDTAB(x) ( (x&1)|((x&2)<<1)|((x&4)<<2)|((x&8)<<3)|((x&16)<<4)| \ - ((x&32)<<5)|((x&64)<<6)|((x&128)<<7)|((x&256)<<8)|((x&512)<<9) ) -#define TWIDOUT(x, y) ( TWIDTAB((y)) | (TWIDTAB((x)) << 1) ) + ((x&32)<<5)|((x&64)<<6)|((x&128)<<7)|((x&256)<<8)|((x&512)<<9) ) +#define TWIDOUT(x, y) ( TWIDTAB((y)) | (TWIDTAB((x)) << 1) ) #define MIN(a, b) ( (a)<(b)? (a):(b) ) + void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *data) { diff --git a/containers/aligned_vector.c b/containers/aligned_vector.c index 1b19224..55ddc7e 100644 --- a/containers/aligned_vector.c +++ b/containers/aligned_vector.c @@ -41,8 +41,7 @@ void aligned_vector_reserve(AlignedVector* vector, unsigned int element_count) { if(element_count <= vector->capacity) { return; } - element_count = ((element_count+_VECTOR_ALIGN_COUNT) & ~_VECTOR_ALIGN_COUNT); - + unsigned int original_byte_size = vector->size * vector->element_size; /* We overallocate so that we don't make small allocations during push backs */ @@ -55,14 +54,7 @@ void aligned_vector_reserve(AlignedVector* vector, unsigned int element_count) { assert(vector->data); if(original_data) { - if( !(*vector->data % 32) && !(*original_data % 32)){ - if (original_byte_size % 4) - original_byte_size = (original_byte_size & 0xfffffffc) + 4; - sq_cpy(vector->data, original_data, original_byte_size); - } else { - memcpy(vector->data, original_data, original_byte_size); - } - + memcpy(vector->data, original_data, original_byte_size); free(original_data); } @@ -83,7 +75,6 @@ void* aligned_vector_push_back(AlignedVector* vector, const void* objs, unsigned /* Copy the objects in */ memcpy(dest, objs, vector->element_size * count); - //sq_cpy(dest, objs, ((vector->element_size * count) & 0xfffffffc) + 4); return dest; } @@ -141,8 +132,6 @@ void aligned_vector_shrink_to_fit(AlignedVector* vector) { if(original_data) { memcpy(vector->data, original_data, new_byte_size); - //sq_cpy(vector->data, original_data, ((new_byte_size) & 0xfffffffc) + 4); - free(original_data); } diff --git a/containers/named_array.c b/containers/named_array.c index 87b68c8..2e82d27 100644 --- a/containers/named_array.c +++ b/containers/named_array.c @@ -46,7 +46,7 @@ void named_array_init(NamedArray* array, unsigned int element_size, unsigned int char named_array_used(NamedArray* array, unsigned int id) { unsigned int i = id / 8; unsigned int j = id % 8; - + unsigned char v = array->used_markers[i] & (unsigned char) (1 << j); return !!(v); } @@ -60,9 +60,7 @@ void* named_array_alloc(NamedArray* array, unsigned int* new_id) { array->used_markers[i] |= (unsigned char) 1 << j; *new_id = id; unsigned char* ptr = &array->elements[id * array->element_size]; - - //memset(ptr, 0, array->element_size); - sq_clr(ptr, (array->element_size & 0xfffffffc) + 4); + memset(ptr, 0, array->element_size); return ptr; } } @@ -75,7 +73,8 @@ void* named_array_reserve(NamedArray* array, unsigned int id) { if(!named_array_used(array, id)) { unsigned int j = (id % 8); unsigned int i = id / 8; - + + assert(!named_array_used(array, id)); array->used_markers[i] |= (unsigned char) 1 << j; assert__(named_array_used(array, id)) { @@ -85,8 +84,7 @@ void* named_array_reserve(NamedArray* array, unsigned int id) { assert(named_array_used(array, id)); unsigned char* ptr = &array->elements[id * array->element_size]; - //memset(ptr, 0, array->element_size); - sq_clr(ptr, (array->element_size & 0xfffffffc) + 4); + memset(ptr, 0, array->element_size); return ptr; } diff --git a/include/gl.h b/include/gl.h index 9cf4099..2937fe8 100644 --- a/include/gl.h +++ b/include/gl.h @@ -485,9 +485,8 @@ GLAPI void APIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor); /* Texturing */ GLAPI void APIENTRY glTexParameteri(GLenum target, GLenum pname, GLint param); -GLAPI void APIENTRY glTexEnvi(GLenum target, GLenum pname, GLenum param); -#define glTexEnvf(target, pname, param) glTexEnvi(target, pname, param) -//GLAPI void APIENTRY glTexEnvf(GLenum target, GLenum pname, GLenum param); +GLAPI void APIENTRY glTexEnvi(GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glTexEnvf(GLenum target, GLenum pname, GLfloat param); GLAPI GLboolean APIENTRY glIsTexture(GLuint texture); GLAPI void APIENTRY glGenTextures(GLsizei n, GLuint *textures); diff --git a/include/glkos.h b/include/glkos.h index 1e794c6..f99607c 100644 --- a/include/glkos.h +++ b/include/glkos.h @@ -96,9 +96,5 @@ GLAPI void APIENTRY glKOS_INTERNAL_SetMipmapBias(GLubyte level); /* Pass to glTexParameteri to set the shared bank */ #define GL_SHARED_TEXTURE_BANK_KOS 0xEF00 -GLAPI void APIENTRY glKosReserveOPList(unsigned int elements); -GLAPI void APIENTRY glKosReservePTList(unsigned int elements); -GLAPI void APIENTRY glKosReserveTRList(unsigned int elements); - __END_DECLS