[vulkan] Use the descriptor set manager

This cleans up a lot of ugly code that I always thought was rather dumb.
This commit is contained in:
Bill Currie 2023-06-24 21:42:46 +09:00
parent 6ce42fd347
commit b9bb841744
29 changed files with 274 additions and 490 deletions

View file

@ -368,11 +368,6 @@ typedef struct bspctx_s {
VkSampler sampler;
VkDeviceMemory texture_memory;
VkPipeline depth;
VkPipeline gbuf;
VkPipeline skysheet;
VkPipeline skybox;
VkPipeline turb;
size_t vertex_buffer_size;
size_t index_buffer_size;
VkBuffer vertex_buffer;
@ -392,6 +387,7 @@ void Vulkan_RegisterTextures (model_t **models, int num_models,
void Vulkan_BuildDisplayLists (model_t **models, int num_models,
struct vulkan_ctx_s *ctx);
void Vulkan_Bsp_Init (struct vulkan_ctx_s *ctx);
void Vulkan_Bsp_Setup (struct vulkan_ctx_s *ctx);
void Vulkan_Bsp_Shutdown (struct vulkan_ctx_s *ctx);
///@}

View file

@ -53,6 +53,7 @@ typedef struct composectx_s {
struct vulkan_ctx_s;
void Vulkan_Compose_Init (struct vulkan_ctx_s *ctx);
void Vulkan_Compose_Setup (struct vulkan_ctx_s *ctx);
void Vulkan_Compose_Shutdown (struct vulkan_ctx_s *ctx);
#endif//__QF_Vulkan_qf_compose_h

View file

@ -30,14 +30,7 @@
#include "QF/screen.h"
typedef enum {
QFV_draw2d,
QFV_drawNumPasses
} QFV_DrawSubpass;
struct vulkan_ctx_s;
struct qfv_renderframe_s;
struct qpic_s;
struct font_s;
struct draw_charbuffer_s;
@ -45,6 +38,7 @@ struct draw_charbuffer_s;
void Vulkan_Draw_CharBuffer (int x, int y, struct draw_charbuffer_s *buffer,
struct vulkan_ctx_s *ctx);
void Vulkan_Draw_Init (struct vulkan_ctx_s *ctx);
void Vulkan_Draw_Setup (struct vulkan_ctx_s *ctx);
void Vulkan_Draw_Shutdown (struct vulkan_ctx_s *ctx);
void Vulkan_Draw_Character (int x, int y, unsigned ch,
struct vulkan_ctx_s *ctx);

View file

@ -90,8 +90,7 @@ typedef struct iqmindset_s
typedef struct iqmctx_s {
iqm_frameset_t frames;
VkSampler sampler;
VkDescriptorPool bones_pool;
VkDescriptorSetLayout bones_setLayout;
struct qfv_dsmanager_s *dsmanager;
} iqmctx_t;
struct vulkan_ctx_s;

View file

@ -95,7 +95,6 @@ typedef struct light_renderer_set_s
typedef struct lightingctx_s {
lightingframeset_t frames;
VkPipeline pipeline;
VkPipelineLayout layout;
VkSampler sampler;
VkDeviceMemory light_memory;
struct qfv_resource_s *shadow_resources;
@ -114,6 +113,7 @@ typedef struct lightingctx_s {
struct vulkan_ctx_s;
void Vulkan_Lighting_Init (struct vulkan_ctx_s *ctx);
void Vulkan_Lighting_Setup (struct vulkan_ctx_s *ctx);
void Vulkan_Lighting_Shutdown (struct vulkan_ctx_s *ctx);
void Vulkan_LoadLights (struct scene_s *scene, struct vulkan_ctx_s *ctx);

View file

@ -36,15 +36,13 @@
#include "QF/Vulkan/image.h"
#include "QF/simd/types.h"
typedef struct qfv_matrix_buffer_s {
typedef __attribute__((aligned(64))) struct qfv_matrix_buffer_s {
// projection and view matrices (model is push constant)
mat4f_t Projection3d;
mat4f_t View[6];
mat4f_t Sky;
mat4f_t Projection2d;
vec2f_t ScreenSize;
vec2f_t pad; //FIXME shouldn't need this (for gpu align)
vec4f_t pad2[3];
} qfv_matrix_buffer_t;
typedef struct matrixframe_s {
@ -56,22 +54,20 @@ typedef struct matrixframeset_s
DARRAY_TYPE (matrixframe_t) matrixframeset_t;
typedef struct matrixctx_s {
matrixframeset_t frames;
VkDeviceMemory memory;
qfv_matrix_buffer_t matrices;
int dirty;
struct qfv_stagebuf_s *stage;
VkDescriptorPool pool;
VkDescriptorSetLayout setLayout;
vec4f_t sky_rotation[2];
vec4f_t sky_velocity;
vec4f_t sky_fix;
double sky_time;
int dirty;
matrixframeset_t frames;
struct qfv_resource_s *resource;
struct qfv_stagebuf_s *stage;
} matrixctx_t;
struct vulkan_ctx_s;
struct qfv_renderframe_s;
void Vulkan_CalcViewMatrix (struct vulkan_ctx_s *ctx);
void Vulkan_SetViewMatrices (struct vulkan_ctx_s *ctx, mat4f_t views[],
@ -80,6 +76,7 @@ void Vulkan_SetSkyMatrix (struct vulkan_ctx_s *ctx, mat4f_t sky);
void Vulkan_SetSkyMatrix (struct vulkan_ctx_s *ctx, mat4f_t sky);
void Vulkan_Matrix_Init (struct vulkan_ctx_s *ctx);
void Vulkan_Matrix_Setup (struct vulkan_ctx_s *ctx);
void Vulkan_Matrix_Shutdown (struct vulkan_ctx_s *ctx);
VkDescriptorSet Vulkan_Matrix_Descriptors (struct vulkan_ctx_s *ctx, int frame)
__attribute__((pure));

View file

@ -52,6 +52,7 @@ typedef struct outputctx_s {
struct vulkan_ctx_s;
void Vulkan_Output_Init (struct vulkan_ctx_s *ctx);
void Vulkan_Output_Setup (struct vulkan_ctx_s *ctx);
void Vulkan_Output_Shutdown (struct vulkan_ctx_s *ctx);
void Vulkan_Output_SetInput (struct vulkan_ctx_s *ctx, VkImageView input);

View file

@ -30,12 +30,6 @@ typedef struct qfv_particle_system_s {
uint32_t firstInstance; // always 0
} qfv_particle_system_t;
typedef enum {
QFV_particleTranslucent,
QFV_particleNumPasses
} QFV_ParticleSubpass;
typedef struct particleframe_s {
VkEvent physicsEvent;
VkEvent updateEvent;
@ -57,17 +51,14 @@ typedef struct particlectx_s {
struct qfv_resource_s *resources;
struct qfv_stagebuf_s *stage;
VkDescriptorPool pool;
VkDescriptorSetLayout setLayout;
psystem_t *psystem;
} particlectx_t;
struct cvar_s;
struct vulkan_ctx_s;
struct psystem_s *Vulkan_ParticleSystem (struct vulkan_ctx_s *ctx);
void Vulkan_Particles_Init (struct vulkan_ctx_s *ctx);
void Vulkan_Particles_Setup (struct vulkan_ctx_s *ctx);
void Vulkan_Particles_Shutdown (struct vulkan_ctx_s *ctx);
#endif//__QF_Vulkan_qf_particles_h

View file

@ -63,8 +63,6 @@ typedef struct scnframeset_s
typedef struct scenectx_s {
struct qfv_resource_s *entities;
scnframeset_t frames;
VkDescriptorPool pool;
VkDescriptorSetLayout setLayout;
int max_entities;
} scenectx_t;
@ -72,6 +70,7 @@ struct vulkan_ctx_s;
struct entity_s;
void Vulkan_Scene_Init (struct vulkan_ctx_s *ctx);
void Vulkan_Scene_Setup (struct vulkan_ctx_s *ctx);
void Vulkan_Scene_Shutdown (struct vulkan_ctx_s *ctx);
int Vulkan_Scene_MaxEntities (struct vulkan_ctx_s *ctx) __attribute__((pure));
VkDescriptorSet Vulkan_Scene_Descriptors (struct vulkan_ctx_s *ctx) __attribute__((pure));

View file

@ -59,8 +59,7 @@ typedef enum {
} QFV_SpriteSubpass;
typedef struct spritectx_s {
VkDescriptorPool pool;
VkDescriptorSetLayout setLayout;
struct qfv_dsmanager_s *dsmanager;
unsigned maxImages;
VkSampler sampler;
} spritectx_t;

View file

@ -11,8 +11,7 @@ typedef struct qfv_tex_s {
} qfv_tex_t;
typedef struct texturectx_s {
VkDescriptorPool pool;
VkDescriptorSetLayout setLayout;
struct qfv_dsmanager_s *dsmanager;
} texturectx_t;
void Vulkan_ExpandPalette (byte *dst, const byte *src, const byte *palette,
@ -30,6 +29,7 @@ void Vulkan_UpdateTex (struct vulkan_ctx_s *ctx, qfv_tex_t *tex, tex_t *src,
int x, int y, int layer, int mip);
void Vulkan_UnloadTex (struct vulkan_ctx_s *ctx, qfv_tex_t *tex);
void Vulkan_Texture_Init (struct vulkan_ctx_s *ctx);
void Vulkan_Texture_Setup (struct vulkan_ctx_s *ctx);
void Vulkan_Texture_Shutdown (struct vulkan_ctx_s *ctx);
VkDescriptorSet Vulkan_CreateCombinedImageSampler (struct vulkan_ctx_s *ctx,
VkImageView view,

View file

@ -29,17 +29,15 @@ typedef struct translucentframeset_s
typedef struct translucentctx_s {
translucentframeset_t frames;
struct qfv_resource_s *resources;
int maxFragments;
VkDescriptorPool pool;
VkDescriptorSetLayout setLayout;
} translucentctx_t;
struct vulkan_ctx_s;
void Vulkan_Translucent_Init (struct vulkan_ctx_s *ctx);
void Vulkan_Translucent_Setup (struct vulkan_ctx_s *ctx);
void Vulkan_Translucent_Shutdown (struct vulkan_ctx_s *ctx);
VkDescriptorSet Vulkan_Translucent_Descriptors (struct vulkan_ctx_s *ctx,
int frame)__attribute__((pure));

View file

@ -80,17 +80,7 @@ struct qfv_output_s;
void Vulkan_ConfigOutput (struct vulkan_ctx_s *ctx,
struct qfv_output_s *output);
VkPipeline Vulkan_CreateComputePipeline (struct vulkan_ctx_s *ctx,
const char *name);
VkPipeline Vulkan_CreateGraphicsPipeline (struct vulkan_ctx_s *ctx,
const char *name);
VkDescriptorPool Vulkan_CreateDescriptorPool (struct vulkan_ctx_s *ctx,
const char *name);
VkPipelineLayout Vulkan_CreatePipelineLayout (struct vulkan_ctx_s *ctx,
const char *name);
VkSampler Vulkan_CreateSampler (struct vulkan_ctx_s *ctx, const char *name);
VkDescriptorSetLayout Vulkan_CreateDescriptorSetLayout(struct vulkan_ctx_s*ctx,
const char *name);
struct entity_s;
void Vulkan_BeginEntityLabel (struct vulkan_ctx_s *ctx, VkCommandBuffer cmd,

View file

@ -409,6 +409,10 @@ void QFV_Render_AddTasks (struct vulkan_ctx_s *ctx, exprsym_t *task_sys);
void QFV_CreateFramebuffer (struct vulkan_ctx_s *ctx, qfv_renderpass_t *rp);
struct qfv_dsmanager_s *
QFV_Render_DSManager (struct vulkan_ctx_s *ctx,
const char *setName) __attribute__((pure));
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));

View file

@ -94,7 +94,6 @@ vulkan_R_Init (void)
Vulkan_CreateStagingBuffers (vulkan_ctx);
Vulkan_Texture_Init (vulkan_ctx);
Vulkan_Palette_Init (vulkan_ctx, vid.palette);
Vulkan_CreateSwapchain (vulkan_ctx);
Vulkan_CreateCapture (vulkan_ctx);
@ -116,6 +115,18 @@ vulkan_R_Init (void)
QFV_LoadRenderInfo (vulkan_ctx);
QFV_BuildRender (vulkan_ctx);
Vulkan_Texture_Setup (vulkan_ctx);
Vulkan_Palette_Init (vulkan_ctx, vid.palette);
Vulkan_Bsp_Setup (vulkan_ctx);
Vulkan_Matrix_Setup (vulkan_ctx);
Vulkan_Scene_Setup (vulkan_ctx);
Vulkan_Output_Setup (vulkan_ctx);
Vulkan_Compose_Setup (vulkan_ctx);
Vulkan_Draw_Setup (vulkan_ctx);
Vulkan_Particles_Setup (vulkan_ctx);
Vulkan_Translucent_Setup (vulkan_ctx);
Vulkan_Lighting_Setup (vulkan_ctx);
Skin_Init ();
SCR_Init ();

View file

@ -560,3 +560,16 @@ QFV_GetStep (const exprval_t *param, qfv_job_t *job)
}
return *(qfv_step_t **)stepref->value;
}
qfv_dsmanager_t *
QFV_Render_DSManager (struct vulkan_ctx_s *ctx, const char *setName)
{
auto job = ctx->render_context->job;
for (uint32_t i = 0; i < job->num_dsmanagers; i++) {
auto ds = job->dsmanager[i];
if (!strcmp (ds->name, setName)) {
return ds;
}
}
return 0;
}

View file

@ -2021,96 +2021,6 @@ void Vulkan_Script_SetOutput (vulkan_ctx_t *ctx, qfv_output_t *output)
sctx->output = *output;
}
VkPipeline
Vulkan_CreateComputePipeline (vulkan_ctx_t *ctx, const char *name)
{
scriptctx_t *sctx = ctx->script_context;
plitem_t *item = qfv_load_pipeline (ctx, "pipelines");
if (!(item = PL_ObjectForKey (item, name))) {
Sys_Printf ("error loading pipeline %s\n", name);
return 0;
} else {
Sys_MaskPrintf (SYS_vulkan_parse, "Found pipeline def %s\n", name);
}
VkPipeline pipeline = QFV_ParseComputePipeline (ctx, item,
sctx->pipelineDef);
QFV_duSetObjectName (ctx->device, VK_OBJECT_TYPE_PIPELINE, pipeline,
va (ctx->va_ctx, "pipeline:%s", name));
return pipeline;
}
VkPipeline
Vulkan_CreateGraphicsPipeline (vulkan_ctx_t *ctx, const char *name)
{
scriptctx_t *sctx = ctx->script_context;
plitem_t *item = qfv_load_pipeline (ctx, "pipelines");
if (!(item = PL_ObjectForKey (item, name))) {
Sys_Printf ("error loading pipeline %s\n", name);
return 0;
} else {
Sys_MaskPrintf (SYS_vulkan_parse, "Found pipeline def %s\n", name);
}
VkPipeline pipeline = QFV_ParseGraphicsPipeline (ctx, item,
sctx->pipelineDef);
QFV_duSetObjectName (ctx->device, VK_OBJECT_TYPE_PIPELINE, pipeline,
va (ctx->va_ctx, "pipeline:%s", name));
return pipeline;
}
VkDescriptorPool
Vulkan_CreateDescriptorPool (vulkan_ctx_t *ctx, const char *name)
{
scriptctx_t *sctx = ctx->script_context;
hashtab_t *tab = sctx->descriptorPools;
const char *path;
path = va (ctx->va_ctx, "$"QFV_PROPERTIES".descriptorPools.%s", name);
__auto_type pool = (VkDescriptorPool) QFV_GetHandle (tab, path);
if (pool) {
return pool;
}
plitem_t *item = qfv_load_pipeline (ctx, "descriptorPools");
if (!(item = PL_ObjectForKey (item, name))) {
Sys_Printf ("error loading descriptor pool %s\n", name);
return 0;
} else {
Sys_MaskPrintf (SYS_vulkan_parse, "Found descriptor pool def %s\n",
name);
}
pool = QFV_ParseDescriptorPool (ctx, item, sctx->pipelineDef);
QFV_AddHandle (tab, path, (uint64_t) pool);
QFV_duSetObjectName (ctx->device, VK_OBJECT_TYPE_DESCRIPTOR_POOL, pool,
va (ctx->va_ctx, "descriptor_pool:%s", name));
return pool;
}
VkPipelineLayout
Vulkan_CreatePipelineLayout (vulkan_ctx_t *ctx, const char *name)
{
scriptctx_t *sctx = ctx->script_context;
hashtab_t *tab = sctx->pipelineLayouts;
const char *path;
path = va (ctx->va_ctx, "$"QFV_PROPERTIES".pipelineLayouts.%s", name);
__auto_type layout = (VkPipelineLayout) QFV_GetHandle (tab, path);
if (layout) {
return layout;
}
plitem_t *item = qfv_load_pipeline (ctx, "pipelineLayouts");
if (!(item = PL_ObjectForKey (item, name))) {
Sys_Printf ("error loading pipeline layout %s\n", name);
return 0;
} else {
Sys_MaskPrintf (SYS_vulkan_parse, "Found pipeline layout def %s\n",
name);
}
layout = QFV_ParsePipelineLayout (ctx, item, sctx->pipelineDef);
QFV_AddHandle (tab, path, (uint64_t) layout);
QFV_duSetObjectName (ctx->device, VK_OBJECT_TYPE_PIPELINE_LAYOUT, layout,
va (ctx->va_ctx, "pipeline_layout:%s", name));
return layout;
}
VkSampler
Vulkan_CreateSampler (vulkan_ctx_t *ctx, const char *name)
{
@ -2137,33 +2047,6 @@ Vulkan_CreateSampler (vulkan_ctx_t *ctx, const char *name)
return sampler;
}
VkDescriptorSetLayout
Vulkan_CreateDescriptorSetLayout(vulkan_ctx_t *ctx, const char *name)
{
scriptctx_t *sctx = ctx->script_context;
hashtab_t *tab = sctx->setLayouts;
const char *path;
path = va (ctx->va_ctx, "$"QFV_PROPERTIES".setLayouts.%s", name);
__auto_type set = (VkDescriptorSetLayout) QFV_GetHandle (tab, path);
if (set) {
return set;
}
plitem_t *item = qfv_load_pipeline (ctx, "setLayouts");
if (!(item = PL_ObjectForKey (item, name))) {
Sys_Printf ("error loading descriptor set %s\n", name);
return 0;
} else {
Sys_MaskPrintf (SYS_vulkan_parse, "Found descriptor set def %s\n",
name);
}
set = QFV_ParseDescriptorSetLayout (ctx, item, sctx->pipelineDef);
QFV_AddHandle (tab, path, (uint64_t) set);
QFV_duSetObjectName (ctx->device, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT,
set, va (ctx->va_ctx, "descriptor_set:%s", name));
return set;
}
exprtab_t *
QFV_CreateSymtab (plitem_t *dict, const char *properties,
const char **extra_items, exprsym_t *extra_syms,

View file

@ -1439,14 +1439,21 @@ static exprsym_t bsp_task_syms[] = {
void
Vulkan_Bsp_Init (vulkan_ctx_t *ctx)
{
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
qfvPushDebug (ctx, "bsp init");
QFV_Render_AddTasks (ctx, bsp_task_syms);
bspctx_t *bctx = calloc (1, sizeof (bspctx_t));
ctx->bsp_context = bctx;
}
void
Vulkan_Bsp_Setup (vulkan_ctx_t *ctx)
{
qfvPushDebug (ctx, "bsp init");
auto device = ctx->device;
auto dfunc = device->funcs;
auto bctx = ctx->bsp_context;
bctx->light_scrap = QFV_CreateScrap (device, "lightmap_atlas", 2048,
tex_frgba, ctx->staging);
@ -1540,12 +1547,6 @@ Vulkan_Bsp_Shutdown (struct vulkan_ctx_s *ctx)
free (bframe->cmdSet.a);
}
dfunc->vkDestroyPipeline (device->dev, bctx->depth, 0);
dfunc->vkDestroyPipeline (device->dev, bctx->gbuf, 0);
dfunc->vkDestroyPipeline (device->dev, bctx->skybox, 0);
dfunc->vkDestroyPipeline (device->dev, bctx->skysheet, 0);
dfunc->vkDestroyPipeline (device->dev, bctx->turb, 0);
DARRAY_CLEAR (&bctx->registered_textures);
for (int i = 0; i < bctx->main_pass.num_queues; i++) {
DARRAY_CLEAR (&bctx->main_pass.draw_queues[i]);

View file

@ -49,6 +49,7 @@
#include "QF/Vulkan/debug.h"
#include "QF/Vulkan/descriptor.h"
#include "QF/Vulkan/device.h"
#include "QF/Vulkan/dsmanager.h"
#include "QF/Vulkan/image.h"
#include "QF/Vulkan/instance.h"
#include "QF/Vulkan/render.h"
@ -106,13 +107,18 @@ static exprsym_t compose_task_syms[] = {
void
Vulkan_Compose_Init (vulkan_ctx_t *ctx)
{
qfv_device_t *device = ctx->device;
qfvPushDebug (ctx, "compose init");
QFV_Render_AddTasks (ctx, compose_task_syms);
composectx_t *cctx = calloc (1, sizeof (composectx_t));
ctx->compose_context = cctx;
}
void
Vulkan_Compose_Setup (vulkan_ctx_t *ctx)
{
qfvPushDebug (ctx, "compose init");
auto cctx = ctx->compose_context;
auto rctx = ctx->render_context;
size_t frames = rctx->frames.size;
@ -120,16 +126,7 @@ Vulkan_Compose_Init (vulkan_ctx_t *ctx)
DARRAY_RESIZE (&cctx->frames, frames);
cctx->frames.grow = 0;
__auto_type attach = QFV_AllocDescriptorSetLayoutSet (frames, alloca);
for (size_t i = 0; i < frames; i++) {
attach->a[i] = Vulkan_CreateDescriptorSetLayout (ctx,
"compose_attach");
}
__auto_type attach_pool = Vulkan_CreateDescriptorPool (ctx,
"compose_attach_pool");
__auto_type attach_set = QFV_AllocateDescriptorSet (device, attach_pool,
attach);
auto dsmanager = QFV_Render_DSManager (ctx, "compose_attach");
for (size_t i = 0; i < frames; i++) {
__auto_type cframe = &cctx->frames.a[i];
@ -137,12 +134,11 @@ Vulkan_Compose_Init (vulkan_ctx_t *ctx)
cframe->imageInfo[j] = base_image_info;
cframe->imageInfo[j].sampler = 0;
cframe->descriptors[j] = base_image_write;
cframe->descriptors[j].dstSet = attach_set->a[i];
cframe->descriptors[j].dstSet = QFV_DSManager_AllocSet (dsmanager);
cframe->descriptors[j].dstBinding = j;
cframe->descriptors[j].pImageInfo = &cframe->imageInfo[j];
}
}
free (attach_set);
qfvPopDebug (ctx);
}

View file

@ -60,6 +60,7 @@
#include "QF/Vulkan/debug.h"
#include "QF/Vulkan/descriptor.h"
#include "QF/Vulkan/device.h"
#include "QF/Vulkan/dsmanager.h"
#include "QF/Vulkan/image.h"
#include "QF/Vulkan/instance.h"
#include "QF/Vulkan/render.h"
@ -123,13 +124,11 @@ typedef struct cachepic_s {
// core pic atlas + static verts
#define CORE_DESC 0
// FIXME must match pool size in pl_quake_def.plist descriptorPools.quad_pool
// should do some reflection
// FIXME make dynamic
#define MAX_DESCIPTORS 64
typedef struct descpool_s {
VkDescriptorSet sets[MAX_DESCIPTORS];
VkDescriptorPool pool;
struct drawctx_s *dctx;
uint32_t users[MAX_DESCIPTORS];// picdata_t.descid
int in_use;
@ -149,7 +148,6 @@ typedef struct drawframe_s {
descbatchset_t quad_batch;
quadqueue_t quad_insts;
linequeue_t line_verts;
qfv_cmdbufferset_t cmdSet;
descpool_t dyn_descs;
} drawframe_t;
@ -190,6 +188,7 @@ typedef struct drawctx_s {
memsuper_t *pic_memsuper;
memsuper_t *string_memsuper;
hashtab_t *pic_cache;
qfv_dsmanager_t *dsmanager;
qfv_resource_t *draw_resource;
qfv_resobj_t *index_object;
qfv_resobj_t *svertex_objects;
@ -198,12 +197,6 @@ typedef struct drawctx_s {
qfv_resobj_t *lvertex_objects;
uint32_t svertex_index;
uint32_t svertex_max;
VkPipeline quad_pipeline;
VkPipeline line_pipeline;
VkPipelineLayout lines_layout;
VkPipelineLayout quad_layout;
VkDescriptorSetLayout quad_data_set_layout;
VkDescriptorPool quad_pool;
VkDescriptorSet core_quad_set;
drawframeset_t frames;
drawfontset_t fonts;
@ -228,10 +221,12 @@ static int
get_dyn_descriptor (descpool_t *pool, qpic_t *pic, VkBufferView buffer_view,
vulkan_ctx_t *ctx)
{
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
auto device = ctx->device;
auto dfunc = device->funcs;
auto dctx = ctx->draw_context;
auto pd = (picdata_t *) pic->data;
uint32_t id = pd->descid;
for (int i = 0; i < pool->in_use; i++) {
if (pool->users[i] == id) {
return ~i;
@ -243,11 +238,7 @@ get_dyn_descriptor (descpool_t *pool, qpic_t *pic, VkBufferView buffer_view,
int descid = pool->in_use++;
pool->users[descid] = id;
if (!pool->sets[descid]) {
auto layout = QFV_AllocDescriptorSetLayoutSet (1, alloca);
layout->a[0] = pool->dctx->quad_data_set_layout;
auto set = QFV_AllocateDescriptorSet (device, pool->pool, layout);
pool->sets[descid] = set->a[0];;
free (set);//FIXME allocation
pool->sets[descid] = QFV_DSManager_AllocSet (dctx->dsmanager);
}
VkWriteDescriptorSet write[] = {
{ VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, 0,
@ -716,11 +707,7 @@ load_lmp (const char *path, vulkan_ctx_t *ctx)
&imageBarriers[qfv_LT_TransferDst_to_ShaderReadOnly]);
QFV_PacketSubmit (packet);
__auto_type layouts = QFV_AllocDescriptorSetLayoutSet (1, alloca);
layouts->a[0] = Vulkan_CreateDescriptorSetLayout (ctx, "quad_data_set");
__auto_type pool = Vulkan_CreateDescriptorPool (ctx, "quad_pool");
__auto_type cache_sets = QFV_AllocateDescriptorSet (device, pool, layouts);
font->set = cache_sets->a[0];
font->set = QFV_DSManager_AllocSet (dctx->dsmanager);;
VkDescriptorImageInfo imageInfo = {
dctx->pic_sampler,
cache_iview->image_view.view,
@ -737,7 +724,6 @@ load_lmp (const char *path, vulkan_ctx_t *ctx)
0, 0, &dctx->svertex_objects[1].buffer_view.view },
};
dfunc->vkUpdateDescriptorSets (device->dev, 2, write, 0, 0);
free (cache_sets);
qpic_t *pic;
pic = cmemalloc (dctx->pic_memsuper,
@ -779,9 +765,8 @@ Vulkan_Draw_UncachePic (const char *path, vulkan_ctx_t *ctx)
void
Vulkan_Draw_Shutdown (vulkan_ctx_t *ctx)
{
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
drawctx_t *dctx = ctx->draw_context;
auto device = ctx->device;
auto dctx = ctx->draw_context;
QFV_DestroyResource (device, &dctx->draw_resource[0]);
QFV_DestroyResource (device, &dctx->draw_resource[1]);
@ -792,8 +777,6 @@ Vulkan_Draw_Shutdown (vulkan_ctx_t *ctx)
}
}
dfunc->vkDestroyPipeline (device->dev, dctx->quad_pipeline, 0);
dfunc->vkDestroyPipeline (device->dev, dctx->line_pipeline, 0);
Hash_DelTable (dctx->pic_cache);
delete_memsuper (dctx->pic_memsuper);
delete_memsuper (dctx->string_memsuper);
@ -870,12 +853,15 @@ load_white_pic (vulkan_ctx_t *ctx)
}
static void
draw_quads (vulkan_ctx_t *ctx, VkCommandBuffer cmd)
draw_quads (qfv_taskctx_t *taskctx)
{
auto ctx = taskctx->ctx;
auto device = ctx->device;
auto dfunc = device->funcs;
auto dctx = ctx->draw_context;
auto dframe = &dctx->frames.a[ctx->curFrame];
auto layout = taskctx->pipeline->layout;
auto cmd = taskctx->cmd;
VkBuffer instance_buffer = dframe->instance_buffer;
VkDeviceSize offsets[] = {0};
@ -895,7 +881,6 @@ draw_quads (vulkan_ctx_t *ctx, VkCommandBuffer cmd)
fontid < 0 ? dframe->dyn_descs.sets[~fontid]
: dctx->fonts.a[fontid].set,
};
VkPipelineLayout layout = dctx->quad_layout;
dfunc->vkCmdBindDescriptorSets (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
layout, 0, 2, set, 0, 0);
@ -906,12 +891,15 @@ draw_quads (vulkan_ctx_t *ctx, VkCommandBuffer cmd)
}
static void
draw_lines (vulkan_ctx_t *ctx, VkCommandBuffer cmd)
draw_lines (qfv_taskctx_t *taskctx)
{
auto ctx = taskctx->ctx;
auto device = ctx->device;
auto dfunc = device->funcs;
auto dctx = ctx->draw_context;
auto dframe = &dctx->frames.a[ctx->curFrame];
auto layout = taskctx->pipeline->layout;
auto cmd = taskctx->cmd;
VkBuffer line_buffer = dframe->line_buffer;
VkDeviceSize offsets[] = {0};
@ -919,7 +907,6 @@ draw_lines (vulkan_ctx_t *ctx, VkCommandBuffer cmd)
VkDescriptorSet set[1] = {
Vulkan_Matrix_Descriptors (ctx, ctx->curFrame),
};
VkPipelineLayout layout = dctx->lines_layout;
dfunc->vkCmdBindDescriptorSets (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
layout, 0, 1, set, 0, 0);
dfunc->vkCmdDraw (cmd, dframe->line_verts.count * VERTS_PER_LINE,
@ -962,7 +949,7 @@ slice_draw (const exprval_t **params, exprval_t *result, exprctx_t *ectx)
#undef a
dfunc->vkFlushMappedMemoryRanges (device->dev, 2, ranges);
draw_quads (ctx, taskctx->cmd);
draw_quads (taskctx);
dframe->quad_insts.count = 0;
dframe->dvertex_index = 0;
@ -995,7 +982,7 @@ line_draw (const exprval_t **params, exprval_t *result, exprctx_t *ectx)
#undef a
dfunc->vkFlushMappedMemoryRanges (device->dev, 1, ranges);
draw_lines (ctx, taskctx->cmd);
draw_lines (taskctx);
dframe->line_verts.count = 0;
}
@ -1046,13 +1033,20 @@ Vulkan_Draw_Init (vulkan_ctx_t *ctx)
{
QFV_Render_AddTasks (ctx, draw_task_syms);
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
qfvPushDebug (ctx, "draw init");
drawctx_t *dctx = calloc (1, sizeof (drawctx_t));
ctx->draw_context = dctx;
}
void
Vulkan_Draw_Setup (vulkan_ctx_t *ctx)
{
qfvPushDebug (ctx, "draw init");
auto device = ctx->device;
auto dfunc = device->funcs;
auto dctx = ctx->draw_context;
dctx->dsmanager = QFV_Render_DSManager (ctx, "quad_data_set");
auto rctx = ctx->render_context;
size_t frames = rctx->frames.size;
@ -1089,17 +1083,7 @@ Vulkan_Draw_Init (vulkan_ctx_t *ctx)
flush_draw_scrap (ctx);
dctx->lines_layout = Vulkan_CreatePipelineLayout (ctx, "lines_layout");
dctx->quad_layout = Vulkan_CreatePipelineLayout (ctx, "quad_layout");
__auto_type sl = Vulkan_CreateDescriptorSetLayout (ctx, "quad_data_set");
dctx->quad_data_set_layout = sl;
dctx->quad_pool = Vulkan_CreateDescriptorPool (ctx, "quad_pool");
// core set + dynamic sets
__auto_type layouts = QFV_AllocDescriptorSetLayoutSet (1 + frames, alloca);
for (size_t i = 0; i < layouts->size; i++) {
layouts->a[i] = dctx->quad_data_set_layout;
}
VkDescriptorImageInfo imageInfo = {
dctx->pic_sampler,
@ -1107,17 +1091,11 @@ Vulkan_Draw_Init (vulkan_ctx_t *ctx)
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
};
__auto_type pool = dctx->quad_pool;
__auto_type sets = QFV_AllocateDescriptorSet (device, pool, layouts);
for (size_t i = 1; i < sets->size; i++) {
__auto_type frame = &dctx->frames.a[i - 1];
frame->dyn_descs = (descpool_t) {};
//FIXME returns same pool every time
frame->dyn_descs.pool = Vulkan_CreateDescriptorPool (ctx, "quad_pool");
frame->dyn_descs.dctx = dctx;
for (size_t i = 0; i < frames; i++) {
__auto_type frame = &dctx->frames.a[i];
frame->dyn_descs = (descpool_t) { .dctx = dctx };
}
dctx->core_quad_set = sets->a[0];
free (sets);
dctx->core_quad_set = QFV_DSManager_AllocSet (dctx->dsmanager);
VkWriteDescriptorSet write[] = {
{ VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, 0,
@ -1133,13 +1111,6 @@ Vulkan_Draw_Init (vulkan_ctx_t *ctx)
DARRAY_APPEND (&dctx->fonts, (drawfont_t) { .set = dctx->core_quad_set });
for (size_t i = 0; i < frames; i++) {
__auto_type dframe = &dctx->frames.a[i];
DARRAY_INIT (&dframe->cmdSet, QFV_drawNumPasses);
DARRAY_RESIZE (&dframe->cmdSet, QFV_drawNumPasses);
dframe->cmdSet.grow = 0;
}
qfvPopDebug (ctx);
}
@ -1701,11 +1672,7 @@ Vulkan_Draw_AddFont (font_t *rfont, vulkan_ctx_t *ctx)
&imageBarriers[qfv_LT_TransferDst_to_ShaderReadOnly]);
QFV_PacketSubmit (packet);
__auto_type layouts = QFV_AllocDescriptorSetLayoutSet (1, alloca);
layouts->a[0] = Vulkan_CreateDescriptorSetLayout (ctx, "quad_data_set");
__auto_type pool = Vulkan_CreateDescriptorPool (ctx, "quad_pool");
__auto_type glyph_sets = QFV_AllocateDescriptorSet (device, pool, layouts);
font->set = glyph_sets->a[0];
font->set = QFV_DSManager_AllocSet (dctx->dsmanager);;
VkDescriptorImageInfo imageInfo = {
dctx->glyph_sampler,
glyph_iview->image_view.view,
@ -1722,7 +1689,6 @@ Vulkan_Draw_AddFont (font_t *rfont, vulkan_ctx_t *ctx)
0, 0, &glyph_bview->buffer_view.view },
};
dfunc->vkUpdateDescriptorSets (device->dev, 2, write, 0, 0);
free (glyph_sets);
return fontid;
}

View file

@ -45,6 +45,7 @@
#include "QF/Vulkan/debug.h"
#include "QF/Vulkan/descriptor.h"
#include "QF/Vulkan/device.h"
#include "QF/Vulkan/dsmanager.h"
#include "QF/Vulkan/instance.h"
#include "QF/Vulkan/resource.h"
#include "QF/Vulkan/render.h"
@ -123,26 +124,23 @@ Vulkan_IQMAddBones (vulkan_ctx_t *ctx, iqm_t *iqm)
{
qfvPushDebug (ctx, "Vulkan_IQMAddBones");
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
iqmctx_t *ictx = ctx->iqm_context;
__auto_type mesh = (qfv_iqm_t *) iqm->extra_data;
int num_sets = ictx->frames.size;
auto device = ctx->device;
auto dfunc = device->funcs;
auto ictx = ctx->iqm_context;
auto mesh = (qfv_iqm_t *) iqm->extra_data;
int num_sets = ictx->frames.size;
//FIXME kinda dumb
__auto_type layouts = QFV_AllocDescriptorSetLayoutSet (num_sets, alloca);
for (size_t i = 0; i < layouts->size; i++) {
layouts->a[i] = ictx->bones_setLayout;
if (!ictx->dsmanager) {
ictx->dsmanager = QFV_Render_DSManager (ctx, "bone_set");
}
__auto_type sets = QFV_AllocateDescriptorSet (device, ictx->bones_pool,
layouts);
for (size_t i = 0; i < sets->size; i++) {
mesh->bones_descriptors[i] = sets->a[i];
for (int i = 0; i < num_sets; i++) {
auto set = QFV_DSManager_AllocSet (ictx->dsmanager);
mesh->bones_descriptors[i] = set;
}
free (sets);
VkDescriptorBufferInfo bufferInfo[num_sets];
size_t bones_size = iqm->num_joints * 3 * sizeof (vec4f_t);
size_t bones_size = sizeof (vec4f_t[iqm->num_joints * 3]);
for (int i = 0; i < num_sets; i++) {
bufferInfo[i].buffer = mesh->bones_buffer;
bufferInfo[i].offset = i * bones_size;
@ -162,14 +160,13 @@ Vulkan_IQMAddBones (vulkan_ctx_t *ctx, iqm_t *iqm)
void
Vulkan_IQMRemoveBones (vulkan_ctx_t *ctx, iqm_t *iqm)
{
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
iqmctx_t *ictx = ctx->iqm_context;
__auto_type mesh = (qfv_iqm_t *) iqm->extra_data;
int num_sets = ictx->frames.size;
auto ictx = ctx->iqm_context;
auto mesh = (qfv_iqm_t *) iqm->extra_data;
int num_sets = ictx->frames.size;
dfunc->vkFreeDescriptorSets (device->dev, ictx->bones_pool, num_sets,
mesh->bones_descriptors);
for (int i = 0; i < num_sets; i++) {
QFV_DSManager_FreeSet (ictx->dsmanager, mesh->bones_descriptors[i]);
}
}
void
@ -318,9 +315,6 @@ Vulkan_IQM_Init (vulkan_ctx_t *ctx)
ictx->sampler = Vulkan_CreateSampler (ctx, "alias_sampler");
ictx->bones_pool = Vulkan_CreateDescriptorPool (ctx, "bone_pool");
ictx->bones_setLayout = Vulkan_CreateDescriptorSetLayout (ctx, "bone_set");
qfvPopDebug (ctx);
}

View file

@ -62,6 +62,7 @@
#include "QF/Vulkan/debug.h"
#include "QF/Vulkan/descriptor.h"
#include "QF/Vulkan/device.h"
#include "QF/Vulkan/dsmanager.h"
#include "QF/Vulkan/image.h"
#include "QF/Vulkan/instance.h"
#include "QF/Vulkan/projection.h"
@ -252,6 +253,7 @@ lights_draw (const exprval_t **params, exprval_t *result, exprctx_t *ectx)
auto dfunc = device->funcs;
auto lctx = ctx->lighting_context;
auto cmd = taskctx->cmd;
auto layout = taskctx->pipeline->layout;
if (!lctx->scene) {
return;
@ -279,7 +281,7 @@ lights_draw (const exprval_t **params, exprval_t *result, exprctx_t *ectx)
lframe->shadowWrite.dstSet,
};
dfunc->vkCmdBindDescriptorSets (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
lctx->layout, 0, 3, sets, 0, 0);
layout, 0, 3, sets, 0, 0);
dfunc->vkCmdDraw (cmd, 3, 1, 0, 0);
}
@ -296,16 +298,20 @@ static exprsym_t lighting_task_syms[] = {
void
Vulkan_Lighting_Init (vulkan_ctx_t *ctx)
{
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
lightingctx_t *lctx = calloc (1, sizeof (lightingctx_t));
ctx->lighting_context = lctx;
qfvPushDebug (ctx, "lighting init");
QFV_Render_AddTasks (ctx, lighting_task_syms);
}
// lighting_context initialized in Vulkan_Lighting_CreateRenderPasses
void
Vulkan_Lighting_Setup (vulkan_ctx_t *ctx)
{
qfvPushDebug (ctx, "lighting init");
auto device = ctx->device;
auto dfunc = device->funcs;
auto lctx = ctx->lighting_context;
Vulkan_Script_SetOutput (ctx,
&(qfv_output_t) { .format = VK_FORMAT_X8_D24_UNORM_PACK32 });
@ -329,7 +335,6 @@ Vulkan_Lighting_Init (vulkan_ctx_t *ctx)
DARRAY_RESIZE (&lctx->frames, frames);
lctx->frames.grow = 0;
lctx->layout = Vulkan_CreatePipelineLayout (ctx, "lighting_layout");
lctx->sampler = Vulkan_CreateSampler (ctx, "shadow_sampler");
__auto_type lbuffers = QFV_AllocBufferSet (frames, alloca);
@ -352,42 +357,21 @@ Vulkan_Lighting_Init (vulkan_ctx_t *ctx)
lctx->light_memory, "memory:lighting");
__auto_type attach = QFV_AllocDescriptorSetLayoutSet (frames, alloca);
__auto_type lights = QFV_AllocDescriptorSetLayoutSet (frames, alloca);
__auto_type shadow = QFV_AllocDescriptorSetLayoutSet (frames, alloca);
for (size_t i = 0; i < frames; i++) {
attach->a[i] = Vulkan_CreateDescriptorSetLayout (ctx,
"lighting_attach");
lights->a[i] = Vulkan_CreateDescriptorSetLayout (ctx,
"lighting_lights");
shadow->a[i] = Vulkan_CreateDescriptorSetLayout (ctx,
"lighting_shadow");
}
__auto_type attach_pool = Vulkan_CreateDescriptorPool (ctx,
"lighting_attach_pool");
__auto_type lights_pool = Vulkan_CreateDescriptorPool (ctx,
"lighting_lights_pool");
__auto_type shadow_pool = Vulkan_CreateDescriptorPool (ctx,
"lighting_shadow_pool");
__auto_type attach_set = QFV_AllocateDescriptorSet (device, attach_pool,
attach);
__auto_type lights_set = QFV_AllocateDescriptorSet (device, lights_pool,
lights);
__auto_type shadow_set = QFV_AllocateDescriptorSet (device, shadow_pool,
shadow);
auto attach_mgr = QFV_Render_DSManager (ctx, "lighting_attach");
auto lights_mgr = QFV_Render_DSManager (ctx, "lighting_lights");
auto shadow_mgr = QFV_Render_DSManager (ctx, "lighting_shadow");
VkDeviceSize light_offset = 0;
for (size_t i = 0; i < frames; i++) {
__auto_type lframe = &lctx->frames.a[i];
QFV_duSetObjectName (device, VK_OBJECT_TYPE_DESCRIPTOR_SET,
attach_set->a[i],
auto attach = QFV_DSManager_AllocSet (attach_mgr);
auto lights = QFV_DSManager_AllocSet (lights_mgr);
auto shadow = QFV_DSManager_AllocSet (shadow_mgr);
QFV_duSetObjectName (device, VK_OBJECT_TYPE_DESCRIPTOR_SET, attach,
va (ctx->va_ctx, "lighting:attach_set:%zd", i));
QFV_duSetObjectName (device, VK_OBJECT_TYPE_DESCRIPTOR_SET,
lights_set->a[i],
QFV_duSetObjectName (device, VK_OBJECT_TYPE_DESCRIPTOR_SET, lights,
va (ctx->va_ctx, "lighting:lights_set:%zd", i));
QFV_duSetObjectName (device, VK_OBJECT_TYPE_DESCRIPTOR_SET,
shadow_set->a[i],
QFV_duSetObjectName (device, VK_OBJECT_TYPE_DESCRIPTOR_SET, shadow,
va (ctx->va_ctx, "lighting:shadow_set:%zd", i));
lframe->light_buffer = lbuffers->a[i];
@ -398,7 +382,7 @@ Vulkan_Lighting_Init (vulkan_ctx_t *ctx)
for (int j = 0; j < LIGHTING_BUFFER_INFOS; j++) {
lframe->bufferInfo[j] = base_buffer_info;
lframe->bufferWrite[j] = base_buffer_write;
lframe->bufferWrite[j].dstSet = lights_set->a[i];
lframe->bufferWrite[j].dstSet = lights;
lframe->bufferWrite[j].dstBinding = j;
lframe->bufferWrite[j].pBufferInfo = &lframe->bufferInfo[j];
}
@ -406,7 +390,7 @@ Vulkan_Lighting_Init (vulkan_ctx_t *ctx)
lframe->attachInfo[j] = base_image_info;
lframe->attachInfo[j].sampler = 0;
lframe->attachWrite[j] = base_attachment_write;
lframe->attachWrite[j].dstSet = attach_set->a[i];
lframe->attachWrite[j].dstSet = attach;
lframe->attachWrite[j].dstBinding = j;
lframe->attachWrite[j].pImageInfo = &lframe->attachInfo[j];
}
@ -416,14 +400,11 @@ Vulkan_Lighting_Init (vulkan_ctx_t *ctx)
lframe->shadowInfo[j].imageView = ctx->default_black->view;
}
lframe->shadowWrite = base_image_write;
lframe->shadowWrite.dstSet = shadow_set->a[i];
lframe->shadowWrite.dstSet = shadow;
lframe->shadowWrite.dstBinding = 0;
lframe->shadowWrite.descriptorCount = LIGHTING_SHADOW_INFOS;
lframe->shadowWrite.pImageInfo = lframe->shadowInfo;
}
free (shadow_set);
free (attach_set);
free (lights_set);
qfvPopDebug (ctx);
}

View file

@ -48,9 +48,11 @@
#include "QF/Vulkan/debug.h"
#include "QF/Vulkan/descriptor.h"
#include "QF/Vulkan/device.h"
#include "QF/Vulkan/dsmanager.h"
#include "QF/Vulkan/instance.h"
#include "QF/Vulkan/projection.h"
#include "QF/Vulkan/render.h"
#include "QF/Vulkan/resource.h"
#include "QF/Vulkan/staging.h"
#include "r_internal.h"
@ -231,57 +233,53 @@ void
Vulkan_Matrix_Init (vulkan_ctx_t *ctx)
{
QFV_Render_AddTasks (ctx, matrix_task_syms);
matrixctx_t *mctx = calloc (1, sizeof (matrixctx_t));
ctx->matrix_context = mctx;
}
void
Vulkan_Matrix_Setup (vulkan_ctx_t *ctx)
{
qfvPushDebug (ctx, "matrix init");
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
matrixctx_t *mctx = calloc (1, sizeof (matrixctx_t));
ctx->matrix_context = mctx;
auto mctx = ctx->matrix_context;
auto rctx = ctx->render_context;
size_t frames = rctx->frames.size;
DARRAY_INIT (&mctx->frames, frames);
DARRAY_RESIZE (&mctx->frames, frames);
mctx->frames.grow = 0;
//__auto_type cmdBuffers = QFV_AllocCommandBufferSet (frames, alloca);
//QFV_AllocateCommandBuffers (device, ctx->cmdpool, 1, cmdBuffers);
mctx->pool = Vulkan_CreateDescriptorPool (ctx, "matrix_pool");
mctx->setLayout = Vulkan_CreateDescriptorSetLayout (ctx, "matrix_set");
__auto_type layouts = QFV_AllocDescriptorSetLayoutSet (frames, alloca);
for (size_t i = 0; i < layouts->size; i++) {
layouts->a[i] = mctx->setLayout;
}
mctx->resource = malloc (sizeof (qfv_resource_t)
+ sizeof (qfv_resobj_t[frames])); // buffers
auto buffers = (qfv_resobj_t *) &mctx->resource[1];
*mctx->resource = (qfv_resource_t) {
.name = "matrix",
.va_ctx = ctx->va_ctx,
.memory_properties = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
.num_objects = frames,
.objects = buffers,
};
for (size_t i = 0; i < frames; i++) {
__auto_type mframe = &mctx->frames.a[i];
//mframe->cmd = cmdBuffers->a[i];
mframe->buffer = QFV_CreateBuffer (device, sizeof (qfv_matrix_buffer_t),
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
| VK_BUFFER_USAGE_TRANSFER_DST_BIT);
QFV_duSetObjectName (device, VK_OBJECT_TYPE_BUFFER,
mframe->buffer, va (ctx->va_ctx,
"buffer:matrices:%zd", i));
buffers[i] = (qfv_resobj_t) {
.name = va (ctx->va_ctx, "%zd", i),
.type = qfv_res_buffer,
.buffer = {
.size = sizeof (qfv_matrix_buffer_t),
.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
| VK_BUFFER_USAGE_TRANSFER_DST_BIT,
},
};
}
QFV_CreateResource (device, mctx->resource);
VkMemoryRequirements req;
//offset = (offset + req.alignment - 1) & ~(req.alignment - 1);
dfunc->vkGetBufferMemoryRequirements (device->dev,
mctx->frames.a[0].buffer, &req);
mctx->memory = QFV_AllocBufferMemory (device, mctx->frames.a[0].buffer,
VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
frames * req.size, 0);
QFV_duSetObjectName (device, VK_OBJECT_TYPE_DEVICE_MEMORY,
mctx->memory, "memory:matrices");
__auto_type sets = QFV_AllocateDescriptorSet (device, mctx->pool, layouts);
auto dsmanager = QFV_Render_DSManager (ctx, "matrix_set");
for (size_t i = 0; i < frames; i++) {
__auto_type mframe = &mctx->frames.a[i];
QFV_BindBufferMemory (device, mframe->buffer, mctx->memory,
i * req.size);
mframe->descriptors = sets->a[i];
auto mframe = &mctx->frames.a[i];
mframe->buffer = buffers[i].buffer.buffer;
mframe->descriptors = QFV_DSManager_AllocSet (dsmanager);
VkDescriptorBufferInfo bufferInfo = {
mframe->buffer, 0, VK_WHOLE_SIZE
};
@ -293,7 +291,6 @@ Vulkan_Matrix_Init (vulkan_ctx_t *ctx)
};
dfunc->vkUpdateDescriptorSets (device->dev, 1, write, 0, 0);
}
free (sets);
mctx->sky_fix = (vec4f_t) { 0, 0, 1, 1 } * sqrtf (0.5);
mctx->sky_rotation[0] = (vec4f_t) { 0, 0, 0, 1};
@ -322,24 +319,18 @@ void
Vulkan_Matrix_Shutdown (vulkan_ctx_t *ctx)
{
qfvPushDebug (ctx, "matrix shutdown");
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
__auto_type mctx = ctx->matrix_context;
auto device = ctx->device;
auto mctx = ctx->matrix_context;
QFV_DestroyStagingBuffer (mctx->stage);
QFV_DestroyResource (device, mctx->resource);
for (size_t i = 0; i < mctx->frames.size; i++) {
__auto_type mframe = &mctx->frames.a[i];
dfunc->vkDestroyBuffer (device->dev, mframe->buffer, 0);
}
dfunc->vkFreeMemory (device->dev, mctx->memory, 0);
qfvPopDebug (ctx);
}
VkDescriptorSet
Vulkan_Matrix_Descriptors (vulkan_ctx_t *ctx, int frame)
{
__auto_type mctx = ctx->matrix_context;
auto mctx = ctx->matrix_context;
return mctx->frames.a[frame].descriptors;
}

View file

@ -51,6 +51,7 @@
#include "QF/Vulkan/debug.h"
#include "QF/Vulkan/descriptor.h"
#include "QF/Vulkan/device.h"
#include "QF/Vulkan/dsmanager.h"
#include "QF/Vulkan/image.h"
#include "QF/Vulkan/instance.h"
#include "QF/Vulkan/render.h"
@ -238,46 +239,41 @@ static exprsym_t output_task_syms[] = {
void
Vulkan_Output_Init (vulkan_ctx_t *ctx)
{
qfv_device_t *device = ctx->device;
outputctx_t *octx = calloc (1, sizeof (outputctx_t));
ctx->output_context = octx;
qfvPushDebug (ctx, "output init");
QFV_Render_AddTasks (ctx, output_task_syms);
__auto_type pld = ctx->script_context->pipelineDef;//FIXME
ctx->script_context->pipelineDef = Vulkan_GetConfig (ctx, "qf_output");
qfvPushDebug (ctx, "output init");
octx->sampler = Vulkan_CreateSampler (ctx, "linear");
ctx->script_context->pipelineDef = pld;
qfvPopDebug (ctx);
}
void
Vulkan_Output_Setup (vulkan_ctx_t *ctx)
{
qfvPushDebug (ctx, "output init");
auto octx = ctx->output_context;
auto rctx = ctx->render_context;
size_t frames = rctx->frames.size;
DARRAY_INIT (&octx->frames, frames);
DARRAY_RESIZE (&octx->frames, frames);
octx->frames.grow = 0;
__auto_type pld = ctx->script_context->pipelineDef;//FIXME
ctx->script_context->pipelineDef = Vulkan_GetConfig (ctx, "qf_output");
octx->sampler = Vulkan_CreateSampler (ctx, "linear");
__auto_type layouts = QFV_AllocDescriptorSetLayoutSet (frames, alloca);
layouts->a[0] = Vulkan_CreateDescriptorSetLayout (ctx, "output_set");
for (size_t i = 0; i < frames; i++) {
layouts->a[i] = layouts->a[0];
}
__auto_type pool = Vulkan_CreateDescriptorPool (ctx, "output_pool");
__auto_type sets = QFV_AllocateDescriptorSet (device, pool, layouts);
__auto_type cmdSet = QFV_AllocCommandBufferSet (1, alloca);
auto dsmanager = QFV_Render_DSManager (ctx, "output_set");
for (size_t i = 0; i < frames; i++) {
__auto_type oframe = &octx->frames.a[i];
auto oframe = &octx->frames.a[i];
oframe->input = 0;
oframe->set = sets->a[i];
QFV_AllocateCommandBuffers (device, ctx->cmdpool, 1, cmdSet);
oframe->set = QFV_DSManager_AllocSet (dsmanager);
}
ctx->script_context->pipelineDef = pld;
free (sets);
qfvPopDebug (ctx);
}

View file

@ -46,6 +46,7 @@
#include "QF/Vulkan/debug.h"
#include "QF/Vulkan/descriptor.h"
#include "QF/Vulkan/device.h"
#include "QF/Vulkan/dsmanager.h"
#include "QF/Vulkan/instance.h"
#include "QF/Vulkan/render.h"
#include "QF/Vulkan/resource.h"
@ -423,36 +424,35 @@ static exprsym_t particles_task_syms[] = {
void
Vulkan_Particles_Init (vulkan_ctx_t *ctx)
{
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
qfvPushDebug (ctx, "particles init");
QFV_Render_AddTasks (ctx, particles_task_syms);
particlectx_t *pctx = calloc (1, sizeof (particlectx_t));
ctx->particle_context = pctx;
pctx->psystem = &r_psystem;
}
void
Vulkan_Particles_Setup (vulkan_ctx_t *ctx)
{
qfvPushDebug (ctx, "particles init");
auto device = ctx->device;
auto dfunc = device->funcs;
auto pctx = ctx->particle_context;
size_t frames = ctx->render_context->frames.size;
DARRAY_INIT (&pctx->frames, frames);
DARRAY_RESIZE (&pctx->frames, frames);
pctx->frames.grow = 0;
pctx->pool = Vulkan_CreateDescriptorPool (ctx, "particle_pool");
pctx->setLayout = Vulkan_CreateDescriptorSetLayout (ctx, "particle_set");
__auto_type layouts = QFV_AllocDescriptorSetLayoutSet (3 * frames, alloca);
for (size_t i = 0; i < layouts->size; i++) {
layouts->a[i] = pctx->setLayout;
}
__auto_type sets = QFV_AllocateDescriptorSet (device, pctx->pool, layouts);
auto dsmanager = QFV_Render_DSManager (ctx, "particle_set");
for (size_t i = 0; i < frames; i++) {
__auto_type pframe = &pctx->frames.a[i];
pframe->curDescriptors = sets->a[i * 3 + 0];
pframe->inDescriptors = sets->a[i * 3 + 1];
pframe->newDescriptors = sets->a[i * 3 + 2];
pframe->curDescriptors = QFV_DSManager_AllocSet (dsmanager);
pframe->inDescriptors = QFV_DSManager_AllocSet (dsmanager);
pframe->newDescriptors = QFV_DSManager_AllocSet (dsmanager);
VkEventCreateInfo event = { VK_STRUCTURE_TYPE_EVENT_CREATE_INFO };
dfunc->vkCreateEvent (device->dev, &event, 0, &pframe->physicsEvent);
@ -464,7 +464,6 @@ Vulkan_Particles_Init (vulkan_ctx_t *ctx)
pframe->updateEvent,
va (ctx->va_ctx, "event:particle:update:%zd", i));
}
free (sets);
create_buffers (ctx);
qfvPopDebug (ctx);
}

View file

@ -43,6 +43,7 @@
#include "QF/Vulkan/debug.h"
#include "QF/Vulkan/descriptor.h"
#include "QF/Vulkan/device.h"
#include "QF/Vulkan/dsmanager.h"
#include "QF/Vulkan/instance.h"
#include "QF/Vulkan/render.h"
#include "QF/Vulkan/resource.h"
@ -133,16 +134,22 @@ static VkWriteDescriptorSet base_buffer_write = {
void
Vulkan_Scene_Init (vulkan_ctx_t *ctx)
{
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
qfvPushDebug (ctx, "scene init");
scenectx_t *sctx = calloc (1, sizeof (scenectx_t)
+ sizeof (qfv_resource_t)
+ sizeof (qfv_resobj_t));
ctx->scene_context = sctx;
sctx->max_entities = qfv_max_entities;
}
void
Vulkan_Scene_Setup (vulkan_ctx_t *ctx)
{
qfvPushDebug (ctx, "scene init");
auto device = ctx->device;
auto dfunc = device->funcs;
auto sctx = ctx->scene_context;
auto rctx = ctx->render_context;
size_t frames = rctx->frames.size;
@ -169,13 +176,7 @@ Vulkan_Scene_Init (vulkan_ctx_t *ctx)
QFV_CreateResource (device, sctx->entities);
sctx->pool = Vulkan_CreateDescriptorPool (ctx, "entity_pool");
sctx->setLayout = Vulkan_CreateDescriptorSetLayout (ctx, "entity_set");
__auto_type layouts = QFV_AllocDescriptorSetLayoutSet (frames, alloca);
for (size_t i = 0; i < layouts->size; i++) {
layouts->a[i] = sctx->setLayout;
}
__auto_type sets = QFV_AllocateDescriptorSet (device, sctx->pool, layouts);
auto dsmanager = QFV_Render_DSManager (ctx, "entity_set");
entdata_t *entdata;
dfunc->vkMapMemory (device->dev, sctx->entities->memory, 0, VK_WHOLE_SIZE,
@ -186,7 +187,7 @@ Vulkan_Scene_Init (vulkan_ctx_t *ctx)
for (size_t i = 0; i < frames; i++) {
__auto_type sframe = &sctx->frames.a[i];
sframe->descriptors = sets->a[i];
sframe->descriptors = QFV_DSManager_AllocSet (dsmanager);;
VkDescriptorBufferInfo bufferInfo = {
buffer, i * entdata_size, entdata_size
};
@ -202,7 +203,6 @@ Vulkan_Scene_Init (vulkan_ctx_t *ctx)
};
sframe->pooled_entities = set_new ();
}
free (sets);
qfvPopDebug (ctx);
}

View file

@ -61,6 +61,7 @@
#include "QF/Vulkan/debug.h"
#include "QF/Vulkan/descriptor.h"
#include "QF/Vulkan/device.h"
#include "QF/Vulkan/dsmanager.h"
#include "QF/Vulkan/instance.h"
#include "QF/Vulkan/render.h"
@ -116,14 +117,10 @@ Vulkan_Sprite_DescriptorSet (vulkan_ctx_t *ctx, qfv_sprite_t *sprite)
qfv_devfuncs_t *dfunc = device->funcs;
spritectx_t *sctx = ctx->sprite_context;
//FIXME kinda dumb
__auto_type layouts = QFV_AllocDescriptorSetLayoutSet (1, alloca);
for (size_t i = 0; i < layouts->size; i++) {
layouts->a[i] = sctx->setLayout;
if (!sctx->dsmanager) {
sctx->dsmanager = QFV_Render_DSManager (ctx, "sprite_set");
}
__auto_type sets = QFV_AllocateDescriptorSet (device, sctx->pool, layouts);
sprite->descriptors = sets->a[0];
free (sets);
sprite->descriptors = QFV_DSManager_AllocSet (sctx->dsmanager);
VkDescriptorBufferInfo bufferInfo[1];
bufferInfo[0] = base_buffer_info;
@ -145,14 +142,10 @@ Vulkan_Sprite_DescriptorSet (vulkan_ctx_t *ctx, qfv_sprite_t *sprite)
}
void
Vulkan_Sprint_FreeDescriptors (vulkan_ctx_t *ctx, qfv_sprite_t *sprite)
Vulkan_Sprite_FreeDescriptors (vulkan_ctx_t *ctx, qfv_sprite_t *sprite)
{
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
spritectx_t *sctx = ctx->sprite_context;
dfunc->vkFreeDescriptorSets (device->dev, sctx->pool, 1,
&sprite->descriptors);
QFV_DSManager_FreeSet (sctx->dsmanager, sprite->descriptors);
}
static void
@ -229,9 +222,6 @@ Vulkan_Sprite_Init (vulkan_ctx_t *ctx)
sctx->sampler = Vulkan_CreateSampler (ctx, "sprite_sampler");
sctx->pool = Vulkan_CreateDescriptorPool (ctx, "sprite_pool");
sctx->setLayout = Vulkan_CreateDescriptorSetLayout (ctx, "sprite_set");
qfvPopDebug (ctx);
}

View file

@ -44,8 +44,10 @@
#include "QF/Vulkan/debug.h"
#include "QF/Vulkan/descriptor.h"
#include "QF/Vulkan/device.h"
#include "QF/Vulkan/dsmanager.h"
#include "QF/Vulkan/image.h"
#include "QF/Vulkan/instance.h"
#include "QF/Vulkan/render.h"
#include "QF/Vulkan/staging.h"
#include "vid_vulkan.h"
@ -508,13 +510,18 @@ static tex_t default_magenta_tex = {
void
Vulkan_Texture_Init (vulkan_ctx_t *ctx)
{
qfvPushDebug (ctx, "texture init");
texturectx_t *tctx = calloc (1, sizeof (texturectx_t));
ctx->texture_context = tctx;
}
tctx->pool = Vulkan_CreateDescriptorPool (ctx, "texture_pool");
tctx->setLayout = Vulkan_CreateDescriptorSetLayout (ctx, "texture_set");
void
Vulkan_Texture_Setup (vulkan_ctx_t *ctx)
{
qfvPushDebug (ctx, "texture init");
auto tctx = ctx->texture_context;
tctx->dsmanager = QFV_Render_DSManager (ctx, "texture_set");
ctx->default_black = Vulkan_LoadTex (ctx, &default_black_tex, 1,
"default_black");
@ -560,18 +567,11 @@ Vulkan_CreateCombinedImageSampler (vulkan_ctx_t *ctx, VkImageView view,
{
qfvPushDebug (ctx, "Vulkan_CreateCombinedImageSampler");
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
texturectx_t *tctx = ctx->texture_context;
auto device = ctx->device;
auto dfunc = device->funcs;
auto tctx = ctx->texture_context;
//FIXME kinda dumb
__auto_type layouts = QFV_AllocDescriptorSetLayoutSet (1, alloca);
for (size_t i = 0; i < layouts->size; i++) {
layouts->a[i] = tctx->setLayout;
}
__auto_type sets = QFV_AllocateDescriptorSet (device, tctx->pool, layouts);
VkDescriptorSet descriptor = sets->a[0];
free (sets);
auto descriptor = QFV_DSManager_AllocSet (tctx->dsmanager);
VkDescriptorImageInfo imageInfo[1];
imageInfo[0] = base_image_info;
@ -599,9 +599,7 @@ Vulkan_CreateTextureDescriptor (vulkan_ctx_t *ctx, qfv_tex_t *tex,
void
Vulkan_FreeTexture (vulkan_ctx_t *ctx, VkDescriptorSet texture)
{
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
texturectx_t *tctx = ctx->texture_context;
auto tctx = ctx->texture_context;
dfunc->vkFreeDescriptorSets (device->dev, tctx->pool, 1, &texture);
QFV_DSManager_FreeSet (tctx->dsmanager, texture);
}

View file

@ -50,6 +50,7 @@
#include "QF/Vulkan/debug.h"
#include "QF/Vulkan/descriptor.h"
#include "QF/Vulkan/device.h"
#include "QF/Vulkan/dsmanager.h"
#include "QF/Vulkan/image.h"
#include "QF/Vulkan/instance.h"
#include "QF/Vulkan/render.h"
@ -128,16 +129,18 @@ static exprsym_t translucent_task_syms[] = {
void
Vulkan_Translucent_Init (vulkan_ctx_t *ctx)
{
if (ctx->translucent_context) {//FIXME
return;
}
qfv_device_t *device = ctx->device;
qfvPushDebug (ctx, "translucent init");
QFV_Render_AddTasks (ctx, translucent_task_syms);
translucentctx_t *tctx = calloc (1, sizeof (translucentctx_t));
ctx->translucent_context = tctx;
}
void
Vulkan_Translucent_Setup (vulkan_ctx_t *ctx)
{
qfvPushDebug (ctx, "translucent init");
auto tctx = ctx->translucent_context;
auto rctx = ctx->render_context;
size_t frames = rctx->frames.size;
@ -147,19 +150,12 @@ Vulkan_Translucent_Init (vulkan_ctx_t *ctx)
tctx->maxFragments = vulkan_oit_fragments * 1024 * 1024;
__auto_type setLayout = QFV_AllocDescriptorSetLayoutSet (frames, alloca);
for (size_t i = 0; i < frames; i++) {
setLayout->a[i] = Vulkan_CreateDescriptorSetLayout (ctx, "oit_set");
}
__auto_type pool = Vulkan_CreateDescriptorPool (ctx, "oit_pool");
__auto_type sets = QFV_AllocateDescriptorSet (device, pool, setLayout);
auto dsmanager = QFV_Render_DSManager (ctx, "oit_set");
for (size_t i = 0; i < frames; i++) {
tctx->frames.a[i] = (translucentframe_t) {
.descriptors = sets->a[i],
.descriptors = QFV_DSManager_AllocSet (dsmanager),
};
}
free (sets);
Vulkan_Translucent_CreateBuffers (ctx, ctx->swapchain->extent);//FIXME
qfvPopDebug (ctx);
}