[vulkan] Add job tasks to be run on new scene

I think has been one of the biggest roadblocks to breaking free of
quake, so having dual render paths and thus the different new scene load
sequence has proven to be unexpected helpful. There's a lot more to be
done to make the render graph actually usable by anyone but me, but just
making scene load configurable frees up a lot. I think there needs to be
renderer startup/shutdown configuration too, but this seems to be enough
for now.
This commit is contained in:
Bill Currie 2024-01-21 13:36:17 +09:00
parent fea08de4cb
commit 60cb5a922a
9 changed files with 137 additions and 16 deletions

View file

@ -273,6 +273,9 @@ typedef struct qfv_jobinfo_s {
uint32_t num_dslayouts;
qfv_descriptorsetlayoutinfo_t *dslayouts;
uint32_t newscene_num_tasks;
qfv_taskinfo_t *newscene_tasks;
} qfv_jobinfo_t;
typedef struct qfv_samplercreateinfo_s {
@ -400,6 +403,9 @@ typedef struct qfv_step_s {
typedef struct qfv_job_s {
qfv_label_t label;
uint32_t newscene_task_count;
qfv_taskinfo_t *newscene_tasks;
uint32_t num_renderpasses;
uint32_t num_pipelines;
uint32_t num_layouts;
@ -480,6 +486,9 @@ qfv_step_t *QFV_GetStep (const exprval_t *param, qfv_job_t *job);
qfv_step_t *QFV_FindStep (const char *step, qfv_job_t *job) __attribute__((pure));
struct qfv_resobj_s *QFV_FindResource (const char *name, qfv_renderpass_t *rp) __attribute__((pure));
struct scene_s;
void QFV_Render_NewScene (struct scene_s *scene, struct vulkan_ctx_s *ctx);
struct imui_ctx_s;
void QFV_Render_UI (struct vulkan_ctx_s *ctx, struct imui_ctx_s *imui_ctx);
void QFV_Render_Menu (struct vulkan_ctx_s *ctx, struct imui_ctx_s *imui_ctx);

View file

@ -838,3 +838,19 @@ QFV_Render_Sampler (vulkan_ctx_t *ctx, const char *name)
printf ("sampler %s not found\n", name);
return 0;
}
void
QFV_Render_NewScene (struct scene_s *scene, vulkan_ctx_t *ctx)
{
auto rctx = ctx->render_context;
auto frame = &rctx->frames.a[ctx->curFrame];
auto job = rctx->job;
qfv_taskctx_t taskctx = {
.ctx = ctx,
.frame = frame,
.data = scene,
};
run_tasks (job->newscene_task_count, job->newscene_tasks, &taskctx);
}

View file

@ -223,6 +223,7 @@ count_stuff (qfv_jobinfo_t *jobinfo, objcount_t *counts)
for (uint32_t i = 0; i < jobinfo->num_steps; i++) {
count_step_stuff (&jobinfo->steps[i], counts);
}
counts->num_tasks += jobinfo->newscene_num_tasks;
}
static qfv_imageinfo_t * __attribute__((pure))
@ -817,6 +818,19 @@ make_label (const char *name, vec4f_t color)
return label;
}
static void
init_tasks (uint32_t *task_count, qfv_taskinfo_t **tasks,
uint32_t num_tasks, qfv_taskinfo_t *intasks,
jobptr_t *jp, objstate_t *s)
{
*task_count = num_tasks;
*tasks = &jp->tasks[s->inds.num_tasks];
for (uint32_t i = 0; i < num_tasks; i++) {
(*tasks)[i] = intasks[i];
}
s->inds.num_tasks += num_tasks;
}
static void
init_pipeline (qfv_pipeline_t *pl, qfv_pipelineinfo_t *plinfo,
jobptr_t *jp, objstate_t *s, int is_compute)
@ -830,19 +844,15 @@ init_pipeline (qfv_pipeline_t *pl, qfv_pipelineinfo_t *plinfo,
.pipeline = is_compute ? s->ptr.cpl[s->inds.num_comp_pipelines]
: s->ptr.gpl[s->inds.num_graph_pipelines],
.layout = li->layout,
.task_count = plinfo->num_tasks,
.tasks = &jp->tasks[s->inds.num_tasks],
.num_indices = li->num_sets,
.ds_indices = &jp->ds_indices[s->inds.num_ds_indices],
};
s->inds.num_tasks += plinfo->num_tasks;
init_tasks (&pl->task_count, &pl->tasks, plinfo->num_tasks, plinfo->tasks,
jp, s);
s->inds.num_ds_indices += li->num_sets;
for (uint32_t i = 0; i < pl->num_indices; i++) {
pl->ds_indices[i] = find_ds_index (&li->sets[i], s);
}
for (uint32_t i = 0; i < pl->task_count; i++) {
pl->tasks[i] = plinfo->tasks[i];
}
}
static void
@ -942,13 +952,9 @@ init_process (qfv_process_t *proc, qfv_processinfo_t *pinfo,
{
*proc = (qfv_process_t) {
.label = make_label (pinfo->name, pinfo->color),
.tasks = &jp->tasks[s->inds.num_tasks],
.task_count = pinfo->num_tasks,
};
s->inds.num_tasks += pinfo->num_tasks;
for (uint32_t i = 0; i < proc->task_count; i++) {
proc->tasks[i] = pinfo->tasks[i];
}
init_tasks (&proc->task_count, &proc->tasks, pinfo->num_tasks, pinfo->tasks,
jp, s);
}
static void
@ -1066,6 +1072,10 @@ init_job (vulkan_ctx_t *ctx, objcount_t *counts, objstate_t s)
auto layoutInfo = &jobinfo->dslayouts[i];
job->dsmanager[i] = QFV_DSManager_Create (layoutInfo, 16, ctx);
}
init_tasks (&job->newscene_task_count, &job->newscene_tasks,
jobinfo->newscene_num_tasks, jobinfo->newscene_tasks,
&jp, &s);
}
static void

View file

@ -2668,3 +2668,8 @@ steps = {
};
};
};
newscene_tasks = (
{ func = bsp_register_textures; },
{ func = bsp_build_display_lists; },
{ func = lighting_load_lights; },
);

View file

@ -1533,3 +1533,8 @@ steps = {
};
};
};
newscene_tasks = (
{ func = bsp_register_textures; },
{ func = bsp_build_lightmaps; },
{ func = bsp_build_display_lists; },
);

View file

@ -621,6 +621,11 @@ parse = {
size = num_dslayouts;
values = dslayouts;
};
newscene_tasks = {
type = (array, qfv_taskinfo_t);
size = newscene_num_tasks;
values = newscene_tasks;
};
plitem = ignore;
};
qfv_samplercreateinfo_s = {

View file

@ -1387,6 +1387,42 @@ bsp_visit_world (const exprval_t **params, exprval_t *result, exprctx_t *ectx)
bsp_flush (ctx);
}
static void
bsp_build_lightmaps (const exprval_t **params, exprval_t *result,
exprctx_t *ectx)
{
qfZoneNamed (zone, true);
auto taskctx = (qfv_taskctx_t *) ectx;
auto ctx = taskctx->ctx;
auto scene = (scene_t *) taskctx->data;
Vulkan_BuildLightmaps (scene->models, scene->num_models, ctx);
}
static void
bsp_build_display_lists (const exprval_t **params, exprval_t *result,
exprctx_t *ectx)
{
qfZoneNamed (zone, true);
auto taskctx = (qfv_taskctx_t *) ectx;
auto ctx = taskctx->ctx;
auto scene = (scene_t *) taskctx->data;
Vulkan_BuildDisplayLists (scene->models, scene->num_models, ctx);
}
static void
bsp_register_textures (const exprval_t **params, exprval_t *result,
exprctx_t *ectx)
{
qfZoneNamed (zone, true);
auto taskctx = (qfv_taskctx_t *) ectx;
auto ctx = taskctx->ctx;
auto scene = (scene_t *) taskctx->data;
Vulkan_RegisterTextures (scene->models, scene->num_models, ctx);
}
static exprenum_t bsp_pass_enum;
static exprtype_t bsp_pass_type = {
.name = "bsp_pass",
@ -1461,10 +1497,28 @@ static exprfunc_t bsp_draw_queue_func[] = {
{ 0, 3, bsp_draw_queue_params, bsp_draw_queue },
{}
};
static exprfunc_t bsp_build_lightmaps_func[] = {
{ .func = bsp_build_lightmaps },
{}
};
static exprfunc_t bsp_build_display_lists_func[] = {
{ .func = bsp_build_display_lists },
{}
};
static exprfunc_t bsp_register_textures_func[] = {
{ .func = bsp_register_textures },
{}
};
static exprsym_t bsp_task_syms[] = {
{ "bsp_reset_queues", &cexpr_function, bsp_reset_queues_func },
{ "bsp_visit_world", &cexpr_function, bsp_visit_world_func },
{ "bsp_draw_queue", &cexpr_function, bsp_draw_queue_func },
{ "bsp_build_lightmaps", &cexpr_function, bsp_build_lightmaps_func },
{ "bsp_build_display_lists", &cexpr_function,
bsp_build_display_lists_func },
{ "bsp_register_textures", &cexpr_function, bsp_register_textures_func },
{}
};

View file

@ -1330,6 +1330,18 @@ lighting_draw_lights (const exprval_t **params, exprval_t *result,
dfunc->vkCmdDraw (cmd, 3, 1, 0, 0);
}
static void
lighting_load_lights (const exprval_t **params, exprval_t *result,
exprctx_t *ectx)
{
qfZoneNamed (zone, true);
auto taskctx = (qfv_taskctx_t *) ectx;
auto ctx = taskctx->ctx;
auto scene = (scene_t *) taskctx->data;
Vulkan_LoadLights (scene, ctx);
}
static exprenum_t lighting_stage_enum;
static exprtype_t lighting_stage_type = {
.name = "lighting_stage",
@ -1430,6 +1442,11 @@ static exprfunc_t lighting_draw_shadow_maps_func[] = {
.param_types = stepref_param },
{}
};
static exprfunc_t lighting_load_lights_func[] = {
{ .func = lighting_load_lights },
{}
};
static exprsym_t lighting_task_syms[] = {
{ "lighting_update_lights", &cexpr_function, lighting_update_lights_func },
{ "lighting_update_descriptors", &cexpr_function,
@ -1445,6 +1462,8 @@ static exprsym_t lighting_task_syms[] = {
{ "lighting_setup_shadow", &cexpr_function, lighting_setup_shadow_func },
{ "lighting_draw_shadow_maps", &cexpr_function,
lighting_draw_shadow_maps_func },
{ "lighting_load_lights", &cexpr_function, lighting_load_lights_func },
{}
};

View file

@ -281,8 +281,6 @@ Vulkan_NewScene (scene_t *scene, vulkan_ctx_t *ctx)
EntQueue_Clear (r_ent_queue);
R_ClearParticles ();
Vulkan_RegisterTextures (scene->models, scene->num_models, ctx);
Vulkan_BuildLightmaps (scene->models, scene->num_models, ctx);
Vulkan_BuildDisplayLists (scene->models, scene->num_models, ctx);
//Vulkan_LoadLights (scene, ctx);
QFV_Render_NewScene (scene, ctx);
}