[vulkan] Remove elements_t type

This was one of the biggest reasons I had trouble understanding the bsp
display list code, but it turns out it was for dealing with GLES's
16-bit limit on vertex indices. Since vulkan uses 32-bit indices,
there's no need for the extra layer of indirection. I'm pretty sure it
was that lack of understanding that prevented me from removing it when I
first converted the glsl bsp code to vulkan (ie, that 16-bit indices
were the only reason for elements_t).

It's hard to tell whether the change makes much difference to
performance, though it seems it might (noisy stats even over 50 timedemo
loops) and the better data localization indicate it should at least be
just as good if not better. However, the reason for the change is
simplifying the data structures so I can make bsp rendering thread-safe
in preparation for rendering shadow maps.
This commit is contained in:
Bill Currie 2022-05-14 00:09:42 +09:00
parent beb05f28ff
commit 765b61d133
2 changed files with 16 additions and 40 deletions

View File

@ -54,17 +54,11 @@ typedef struct bspvert_s {
quat_t tlst; quat_t tlst;
} bspvert_t; } bspvert_t;
typedef struct elements_s {
struct elements_s *_next;
struct elements_s *next;
uint32_t first_index;
uint32_t index_count;
} elements_t;
typedef struct elechain_s { typedef struct elechain_s {
struct elechain_s *_next; struct elechain_s *_next;
struct elechain_s *next; struct elechain_s *next;
elements_t *elements; uint32_t first_index;
uint32_t index_count;
vec_t *transform; vec_t *transform;
float *color; float *color;
} elechain_t; } elechain_t;
@ -120,9 +114,6 @@ typedef struct bspctx_s {
elechain_t *elechains; elechain_t *elechains;
elechain_t **elechains_tail; elechain_t **elechains_tail;
elechain_t *free_elechains; elechain_t *free_elechains;
elements_t *elementss;
elements_t **elementss_tail;
elements_t *free_elementss;
instsurf_t *instsurfs; instsurf_t *instsurfs;
instsurf_t **instsurfs_tail; instsurf_t **instsurfs_tail;
instsurf_t *free_instsurfs; instsurf_t *free_instsurfs;

View File

@ -162,7 +162,6 @@ release_##name##s (bspctx_t *bctx) \
} }
GET_RELEASE (elechain_t, elechain) GET_RELEASE (elechain_t, elechain)
GET_RELEASE (elements_t, elements)
GET_RELEASE (instsurf_t, static_instsurf) GET_RELEASE (instsurf_t, static_instsurf)
GET_RELEASE (instsurf_t, instsurf) GET_RELEASE (instsurf_t, instsurf)
@ -216,7 +215,6 @@ clear_texture_chains (bspctx_t *bctx)
} }
clear_tex_chain (r_notexture_mip->render); clear_tex_chain (r_notexture_mip->render);
release_elechains (bctx); release_elechains (bctx);
release_elementss (bctx);
release_instsurfs (bctx); release_instsurfs (bctx);
} }
@ -225,7 +223,6 @@ Vulkan_ClearElements (vulkan_ctx_t *ctx)
{ {
bspctx_t *bctx = ctx->bsp_context; bspctx_t *bctx = ctx->bsp_context;
release_elechains (bctx); release_elechains (bctx);
release_elementss (bctx);
} }
static inline void static inline void
@ -307,7 +304,8 @@ add_elechain (vulktex_t *tex, bspctx_t *bctx)
elechain_t *ec; elechain_t *ec;
ec = get_elechain (bctx); ec = get_elechain (bctx);
ec->elements = get_elements (bctx); ec->first_index = 0;
ec->index_count = 0;
ec->transform = 0; ec->transform = 0;
ec->color = 0; ec->color = 0;
*tex->elechain_tail = ec; *tex->elechain_tail = ec;
@ -793,7 +791,6 @@ draw_elechain (elechain_t *ec, VkPipelineLayout layout, qfv_device_t *device,
VkCommandBuffer cmd) VkCommandBuffer cmd)
{ {
qfv_devfuncs_t *dfunc = device->funcs; qfv_devfuncs_t *dfunc = device->funcs;
elements_t *el;
if (ec->transform) { if (ec->transform) {
push_transform (ec->transform, layout, device, cmd); push_transform (ec->transform, layout, device, cmd);
@ -801,10 +798,8 @@ draw_elechain (elechain_t *ec, VkPipelineLayout layout, qfv_device_t *device,
//FIXME should cache current transform //FIXME should cache current transform
push_transform (identity, layout, device, cmd); push_transform (identity, layout, device, cmd);
} }
for (el = ec->elements; el; el = el->next) { if (ec->index_count) {
if (!el->index_count) dfunc->vkCmdDrawIndexed (cmd, ec->index_count, 1, ec->first_index,
continue;
dfunc->vkCmdDrawIndexed (cmd, el->index_count, 1, el->first_index,
0, 0); 0, 0);
} }
} }
@ -812,13 +807,10 @@ draw_elechain (elechain_t *ec, VkPipelineLayout layout, qfv_device_t *device,
static void static void
reset_elechain (elechain_t *ec) reset_elechain (elechain_t *ec)
{ {
elements_t *el; ec->first_index = 0;
ec->index_count = 0;
}
for (el = ec->elements; el; el = el->next) {
el->first_index = 0;
el->index_count = 0;
}
}
static void static void
bsp_begin_subpass (QFV_BspSubpass subpass, VkPipeline pipeline, bsp_begin_subpass (QFV_BspSubpass subpass, VkPipeline pipeline,
@ -975,8 +967,7 @@ sky_end (vulkan_ctx_t *ctx)
} }
static inline void static inline void
add_surf_elements (vulktex_t *tex, instsurf_t *is, add_surf_elements (vulktex_t *tex, instsurf_t *is, elechain_t **ec,
elechain_t **ec, elements_t **el,
bspctx_t *bctx, bspframe_t *bframe) bspctx_t *bctx, bspframe_t *bframe)
{ {
bsppoly_t *poly = (bsppoly_t *) is->surface->polys; bsppoly_t *poly = (bsppoly_t *) is->surface->polys;
@ -985,19 +976,17 @@ add_surf_elements (vulktex_t *tex, instsurf_t *is,
(*ec) = add_elechain (tex, bctx); (*ec) = add_elechain (tex, bctx);
(*ec)->transform = is->transform; (*ec)->transform = is->transform;
(*ec)->color = is->color; (*ec)->color = is->color;
(*el) = (*ec)->elements; (*ec)->first_index = bframe->index_count;
(*el)->first_index = bframe->index_count;
} }
if (is->transform != (*ec)->transform || is->color != (*ec)->color) { if (is->transform != (*ec)->transform || is->color != (*ec)->color) {
(*ec) = add_elechain (tex, bctx); (*ec) = add_elechain (tex, bctx);
(*ec)->transform = is->transform; (*ec)->transform = is->transform;
(*ec)->color = is->color; (*ec)->color = is->color;
(*el) = (*ec)->elements; (*ec)->first_index = bframe->index_count;
(*el)->first_index = bframe->index_count;
} }
memcpy (bframe->index_data + bframe->index_count, memcpy (bframe->index_data + bframe->index_count,
poly->indices, poly->count * sizeof (poly->indices[0])); poly->indices, poly->count * sizeof (poly->indices[0]));
(*el)->index_count += poly->count; (*ec)->index_count += poly->count;
bframe->index_count += poly->count; bframe->index_count += poly->count;
} }
@ -1006,12 +995,11 @@ build_tex_elechain (vulktex_t *tex, bspctx_t *bctx, bspframe_t *bframe)
{ {
instsurf_t *is; instsurf_t *is;
elechain_t *ec = 0; elechain_t *ec = 0;
elements_t *el = 0;
for (is = tex->tex_chain; is; is = is->tex_chain) { for (is = tex->tex_chain; is; is = is->tex_chain) {
// emit the polygon indices for the surface to the texture's // emit the polygon indices for the surface to the texture's
// element chain // element chain
add_surf_elements (tex, is, &ec, &el, bctx, bframe); add_surf_elements (tex, is, &ec, bctx, bframe);
} }
} }
@ -1117,7 +1105,6 @@ Vulkan_DrawWaterSurfaces (qfv_renderframe_t *rFrame)
instsurf_t *is; instsurf_t *is;
vulktex_t *tex = 0; vulktex_t *tex = 0;
elechain_t *ec = 0; elechain_t *ec = 0;
elements_t *el = 0;
if (!bctx->waterchain) if (!bctx->waterchain)
return; return;
@ -1146,7 +1133,7 @@ Vulkan_DrawWaterSurfaces (qfv_renderframe_t *rFrame)
} }
// emit the polygon indices for the surface to the texture's // emit the polygon indices for the surface to the texture's
// element chain // element chain
add_surf_elements (tex, is, &ec, &el, bctx, bframe); add_surf_elements (tex, is, &ec, bctx, bframe);
} }
if (tex) { if (tex) {
bind_texture (tex, 1, bctx->layout, dfunc, bind_texture (tex, 1, bctx->layout, dfunc,
@ -1176,7 +1163,6 @@ Vulkan_DrawSky (qfv_renderframe_t *rFrame)
instsurf_t *is; instsurf_t *is;
vulktex_t *tex = 0; vulktex_t *tex = 0;
elechain_t *ec = 0; elechain_t *ec = 0;
elements_t *el = 0;
if (!bctx->sky_chain) if (!bctx->sky_chain)
return; return;
@ -1208,7 +1194,7 @@ Vulkan_DrawSky (qfv_renderframe_t *rFrame)
} }
// emit the polygon indices for the surface to the texture's // emit the polygon indices for the surface to the texture's
// element chain // element chain
add_surf_elements (tex, is, &ec, &el, bctx, bframe); add_surf_elements (tex, is, &ec, bctx, bframe);
} }
if (tex) { if (tex) {
bind_texture (tex, 1, bctx->layout, dfunc, bind_texture (tex, 1, bctx->layout, dfunc,
@ -1350,7 +1336,6 @@ Vulkan_Bsp_Init (vulkan_ctx_t *ctx)
bctx->sky_chain_tail = &bctx->sky_chain; bctx->sky_chain_tail = &bctx->sky_chain;
bctx->static_instsurfs_tail = &bctx->static_instsurfs; bctx->static_instsurfs_tail = &bctx->static_instsurfs;
bctx->elechains_tail = &bctx->elechains; bctx->elechains_tail = &bctx->elechains;
bctx->elementss_tail = &bctx->elementss;
bctx->instsurfs_tail = &bctx->instsurfs; bctx->instsurfs_tail = &bctx->instsurfs;
bctx->light_scrap = QFV_CreateScrap (device, "lightmap_atlas", 2048, bctx->light_scrap = QFV_CreateScrap (device, "lightmap_atlas", 2048,