[model] Move visframe out of msurface_t

One more step towards BSP thread-safety. This one brought with it a very
noticeable speed boost (ie, not lost in the noise) thanks to the face
visframes being in tightly packed groups instead of 128 bytes apart,
though the sw render's boost is lost in the noise (but it's very
fill-rate limited).
This commit is contained in:
Bill Currie 2022-05-22 16:31:24 +09:00
parent d40769c21d
commit c8472755d1
13 changed files with 36 additions and 23 deletions

View file

@ -139,7 +139,8 @@ typedef struct glpoly_s {
#define MAX_DLIGHTS 128
typedef struct msurface_s {
int visframe; // should be drawn when node is crossed
int _visframe; // should be drawn when node is crossed/
// no longer used, see r_face_visframes
int flags;
plane_t *plane;

View file

@ -75,9 +75,10 @@ struct animation_s;
void R_DrawAliasModel (struct entity_s *e);
void R_MarkLeaves (struct mleaf_s *viewleaf, int *node_visframes,
int *leaf_visframes);
int *leaf_visframes, int *face_visframes);
extern int *r_node_visframes;
extern int *r_leaf_visframes;
extern int *r_face_visframes;
void GL_SetPalette (void *data, const byte *palette);
void GLSL_SetPalette (void *data, const byte *palette);

View file

@ -173,7 +173,7 @@ gl_R_NewScene (scene_t *scene)
brush->leafs[i].efrags = NULL;
// Force a vis update
R_MarkLeaves (0, 0, 0);
R_MarkLeaves (0, 0, 0, 0);
R_ClearParticles ();

View file

@ -612,9 +612,10 @@ visit_node (glbspctx_t *bctx, mnode_t *node, int side)
side = (~side + 1) & SURF_PLANEBACK;
// draw stuff
if ((c = node->numsurfaces)) {
surf = bctx->brush->surfaces + node->firstsurface;
for (; c; c--, surf++) {
if (surf->visframe != r_visframecount)
int surf_id = node->firstsurface;
surf = bctx->brush->surfaces + surf_id;
for (; c; c--, surf++, surf_id++) {
if (r_face_visframes[surf_id] != r_visframecount)
continue;
// side is either 0 or SURF_PLANEBACK

View file

@ -753,9 +753,10 @@ visit_node (glslbspctx_t *bctx, mnode_t *node, int side)
// chain any visible surfaces on the node that face the camera.
// not all nodes have any surfaces to draw (purely a split plane)
if ((c = node->numsurfaces)) {
surf = bctx->brush->surfaces + node->firstsurface;
for (; c; c--, surf++) {
if (surf->visframe != r_visframecount)
int surf_id = node->firstsurface;
surf = bctx->brush->surfaces + surf_id;
for (; c; c--, surf++, surf_id++) {
if (r_face_visframes[surf_id] != r_visframecount)
continue;
// side is either 0 or SURF_PLANEBACK

View file

@ -199,7 +199,7 @@ glsl_R_NewScene (scene_t *scene)
r_refdef.worldmodel = scene->worldmodel;
// Force a vis update
R_MarkLeaves (0, 0, 0);
R_MarkLeaves (0, 0, 0, 0);
R_ClearParticles ();
glsl_R_RegisterTextures (scene->models, scene->num_models);

View file

@ -47,7 +47,8 @@ static mleaf_t *r_oldviewleaf;
static set_t *solid;
void
R_MarkLeaves (mleaf_t *viewleaf, int *node_visframes, int *leaf_visframes)
R_MarkLeaves (mleaf_t *viewleaf, int *node_visframes, int *leaf_visframes,
int *face_visframes)
{
set_t *vis;
int c;
@ -80,7 +81,7 @@ R_MarkLeaves (mleaf_t *viewleaf, int *node_visframes, int *leaf_visframes)
if ((c = leaf->nummarksurfaces)) {
mark = brush->marksurfaces + leaf->firstmarksurface;
do {
(*mark)->visframe = r_visframecount;
face_visframes[*mark - brush->surfaces] = r_visframecount;
mark++;
} while (--c);
}

View file

@ -305,7 +305,8 @@ R_MarkLights (vec4f_t lightorigin, dlight_t *light, int lightnum,
msurface_t **msurf = brush->marksurfaces + leaf->firstmarksurface;
for (m = 0; m < leaf->nummarksurfaces; m++) {
msurface_t *surf = *msurf++;
if (surf->visframe != r_visframecount)
int surf_id = surf - brush->surfaces;
if (r_face_visframes[surf_id] != r_visframecount)
continue;
mark_surfaces (surf, lightorigin, light, lightnum);
}

View file

@ -63,6 +63,7 @@ byte *draw_chars; // 8*8 graphic characters FIXME location
qboolean r_cache_thrash; // set if surface cache is thrashing
int *r_node_visframes; //FIXME per renderer
int *r_leaf_visframes; //FIXME per renderer
int *r_face_visframes; //FIXME per renderer
qboolean scr_skipupdate;
static qboolean scr_initialized;// ready to draw
@ -284,7 +285,8 @@ SCR_UpdateScreen (transform_t *camera, double realtime, SCR_Func *scr_funcs)
warp_buffer = r_funcs->create_frame_buffer (r_data->vid->width,
r_data->vid->height);
}
R_MarkLeaves (scr_scene->viewleaf, r_node_visframes, r_leaf_visframes);
R_MarkLeaves (scr_scene->viewleaf, r_node_visframes, r_leaf_visframes,
r_face_visframes);
}
R_PushDlights (vec3_origin);
@ -516,9 +518,12 @@ SCR_NewScene (scene_t *scene)
scr_scene = scene;
if (scene) {
mod_brush_t *brush = &scr_scene->worldmodel->brush;
int size = (brush->numnodes + brush->modleafs) * sizeof (int);
int count = brush->numnodes + brush->modleafs
+ brush->numsurfaces;
int size = count * sizeof (int);
r_node_visframes = Hunk_AllocName (0, size, "visframes");
r_leaf_visframes = r_node_visframes + brush->numnodes;
r_face_visframes = r_leaf_visframes + brush->modleafs;
r_funcs->set_fov (tan_fov_x, tan_fov_y);
r_funcs->R_NewScene (scene);
} else {

View file

@ -384,9 +384,10 @@ visit_node (swbspctx_t *bctx, mnode_t *node, int side, int clipflags)
side = (~side + 1) & SURF_PLANEBACK;
// draw stuff
if ((c = node->numsurfaces)) {
surf = brush->surfaces + node->firstsurface;
for (; c; c--, surf++) {
if (surf->visframe != r_visframecount)
int surf_id = node->firstsurface;
surf = brush->surfaces + surf_id;
for (; c; c--, surf++, surf_id++) {
if (r_face_visframes[surf_id] != r_visframecount)
continue;
// side is either 0 or SURF_PLANEBACK

View file

@ -167,7 +167,7 @@ R_NewScene (scene_t *scene)
R_InitSky (brush->skytexture);
// Force a vis update
R_MarkLeaves (0, 0, 0);
R_MarkLeaves (0, 0, 0, 0);
R_ClearParticles ();

View file

@ -665,9 +665,10 @@ visit_node (mod_brush_t *brush, mnode_t *node, int side, vulkan_ctx_t *ctx)
// chain any visible surfaces on the node that face the camera.
// not all nodes have any surfaces to draw (purely a split plane)
if ((c = node->numsurfaces)) {
surf = brush->surfaces + node->firstsurface;
for (; c; c--, surf++) {
if (surf->visframe != r_visframecount)
int surf_id = node->firstsurface;
surf = brush->surfaces + surf_id;
for (; c; c--, surf++, surf_id++) {
if (r_face_visframes[surf_id] != r_visframecount)
continue;
// side is either 0 or SURF_PLANEBACK

View file

@ -142,7 +142,7 @@ Vulkan_NewScene (scene_t *scene, vulkan_ctx_t *ctx)
r_refdef.worldmodel = scene->worldmodel;
// Force a vis update
R_MarkLeaves (0, 0, 0);
R_MarkLeaves (0, 0, 0, 0);
R_ClearParticles ();
Vulkan_RegisterTextures (scene->models, scene->num_models, ctx);