From b12a31a10d99cf06fa6e3b2a098b7af69dec41a6 Mon Sep 17 00:00:00 2001 From: Cloudwalk Date: Wed, 21 Jul 2021 14:49:35 -0400 Subject: [PATCH] model_shared: Avoid using R_FrameData_Alloc when building sorted surfaces list Works around an issue where the r_framedatasize cvar would grow to a ridiculous size over time. To be investigated further... --- gl_rmain.c | 1 + model_shared.c | 12 ++++++------ model_shared.h | 3 +++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/gl_rmain.c b/gl_rmain.c index e5516ded..d164550d 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -247,6 +247,7 @@ cvar_t r_glsl_saturation_redcompensate = {CF_CLIENT | CF_ARCHIVE, "r_glsl_satura cvar_t r_glsl_vertextextureblend_usebothalphas = {CF_CLIENT | CF_ARCHIVE, "r_glsl_vertextextureblend_usebothalphas", "0", "use both alpha layers on vertex blended surfaces, each alpha layer sets amount of 'blend leak' on another layer, requires mod_q3shader_force_terrain_alphaflag on."}; +// FIXME: This cvar would grow to a ridiculous size after several launches and clean exits when used during surface sorting. cvar_t r_framedatasize = {CF_CLIENT | CF_ARCHIVE, "r_framedatasize", "0.5", "size of renderer data cache used during one frame (for skeletal animation caching, light processing, etc)"}; cvar_t r_buffermegs[R_BUFFERDATA_COUNT] = { diff --git a/model_shared.c b/model_shared.c index e7d3228d..8e707337 100644 --- a/model_shared.c +++ b/model_shared.c @@ -2936,7 +2936,7 @@ void Mod_MakeSortedSurfaces(model_t *mod) if(cls.state == ca_dedicated) return; - info = (Mod_MakeSortedSurfaces_qsortsurface_t*)R_FrameData_Alloc(mod->num_surfaces * sizeof(*info)); + info = (Mod_MakeSortedSurfaces_qsortsurface_t*)Mem_Alloc(loadmodel->mempool, mod->num_surfaces * sizeof(*info)); if (!mod->modelsurfaces_sorted) mod->modelsurfaces_sorted = (int *) Mem_Alloc(loadmodel->mempool, mod->num_surfaces * sizeof(*mod->modelsurfaces_sorted)); // the goal is to sort by submodel (can't change which submodel a surface belongs to), and then by effects and textures @@ -2952,6 +2952,7 @@ void Mod_MakeSortedSurfaces(model_t *mod) qsort(info + mod->brush.submodels[k]->submodelsurfaces_start, (size_t)mod->brush.submodels[k]->submodelsurfaces_end - mod->brush.submodels[k]->submodelsurfaces_start, sizeof(*info), Mod_MakeSortedSurfaces_qsortfunc); for (j = 0; j < mod->num_surfaces; j++) mod->modelsurfaces_sorted[j] = info[j].surfaceindex; + Mem_Free(info); } void Mod_BuildVBOs(void) @@ -4645,25 +4646,24 @@ static void Mod_Mesh_MakeSortedSurfaces(model_t *mod) { int i, j; texture_t *tex; - unsigned char* included = (unsigned char *)R_FrameData_Alloc(mod->num_surfaces * sizeof(unsigned char)); // build the sorted surfaces list properly to reduce material setup // this is easy because we're just sorting on texture and don't care about the order of textures mod->submodelsurfaces_start = 0; mod->submodelsurfaces_end = 0; for (i = 0; i < mod->num_surfaces; i++) - included[i] = 0; + mod->data_surfaces[i].included = false; for (i = 0; i < mod->num_surfaces; i++) { - if (included[i]) + if (mod->data_surfaces[i].included) continue; tex = mod->data_surfaces[i].texture; // j = i is intentional for (j = i; j < mod->num_surfaces; j++) { - if (!included[j] && mod->data_surfaces[j].texture == tex) + if (!mod->data_surfaces[j].included && mod->data_surfaces[j].texture == tex) { - included[j] = 1; + mod->data_surfaces[j].included = 1; mod->modelsurfaces_sorted[mod->submodelsurfaces_end++] = j; } } diff --git a/model_shared.h b/model_shared.h index 072d61f9..cf5e02dc 100644 --- a/model_shared.h +++ b/model_shared.h @@ -404,6 +404,9 @@ typedef struct msurface_s int num_firstcollisiontriangle; // q3bsp only int num_collisiontriangles; // number of triangles (if surface has collisions enabled) int num_collisionvertices; // number of vertices referenced by collision triangles (if surface has collisions enabled) + + // used by Mod_Mesh_Finalize when building sortedmodelsurfaces + qbool included; } msurface_t; -- 2.39.2