[vulkan] Add support for compute shaders

This needed changing Vulkan_CreatePipeline to
Vulkan_CreateGraphicsPipeline for consistency (and parsing the
difference from a plist seemed... not worth thinking about).
This commit is contained in:
Bill Currie 2021-12-16 23:00:17 +09:00
parent 93f806ccfb
commit 7901f87960
11 changed files with 83 additions and 18 deletions

View file

@ -69,7 +69,10 @@ void Vulkan_Init_Common (struct vulkan_ctx_s *ctx);
void Vulkan_Shutdown_Common (struct vulkan_ctx_s *ctx);
void Vulkan_CreateStagingBuffers (struct vulkan_ctx_s *ctx);
VkPipeline Vulkan_CreatePipeline (struct vulkan_ctx_s *ctx, const char *name);
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,

View file

@ -1142,7 +1142,35 @@ QFV_ParseRenderPass (vulkan_ctx_t *ctx, plitem_t *plist, plitem_t *properties)
}
VkPipeline
QFV_ParsePipeline (vulkan_ctx_t *ctx, plitem_t *plist, plitem_t *properties)
QFV_ParseComputePipeline (vulkan_ctx_t *ctx, plitem_t *plist,
plitem_t *properties)
{
memsuper_t *memsuper = new_memsuper ();
qfv_device_t *device = ctx->device;
__auto_type cInfo = QFV_AllocComputePipelineCreateInfoSet (1, alloca);
memset (&cInfo->a[0], 0, sizeof (cInfo->a[0]));
if (!parse_object (ctx, memsuper, plist, parse_VkComputePipelineCreateInfo,
&cInfo->a[0], properties)) {
delete_memsuper (memsuper);
return 0;
}
qfvPushDebug (ctx, va (ctx->va_ctx,
"QFV_ParseComputePipeline: %d", PL_Line (plist)));
__auto_type plSet = QFV_CreateComputePipelines (device, 0, cInfo);
qfvPopDebug (ctx);
VkPipeline pipeline = plSet->a[0];
free (plSet);
delete_memsuper (memsuper);
return pipeline;
}
VkPipeline
QFV_ParseGraphicsPipeline (vulkan_ctx_t *ctx, plitem_t *plist,
plitem_t *properties)
{
memsuper_t *memsuper = new_memsuper ();
qfv_device_t *device = ctx->device;

View file

@ -36,8 +36,10 @@ void QFV_AddHandle (struct hashtab_s *tab, const char *name, uint64_t handle);
VkRenderPass QFV_ParseRenderPass (vulkan_ctx_t *ctx, plitem_t *plist,
plitem_t *properties);
VkPipeline QFV_ParsePipeline (vulkan_ctx_t *ctx, plitem_t *plist,
plitem_t *properties);
VkPipeline QFV_ParseComputePipeline (vulkan_ctx_t *ctx, plitem_t *plist,
plitem_t *properties);
VkPipeline QFV_ParseGraphicsPipeline (vulkan_ctx_t *ctx, plitem_t *plist,
plitem_t *properties);
VkDescriptorPool QFV_ParseDescriptorPool (vulkan_ctx_t *ctx, plitem_t *plist,
plitem_t *properties);
VkDescriptorSetLayout QFV_ParseDescriptorSetLayout (vulkan_ctx_t *ctx,

View file

@ -19,6 +19,7 @@
VkPushConstantRange,
VkPipelineLayoutCreateInfo,
VkGraphicsPipelineCreateInfo,
VkComputePipelineCreateInfo,
VkDescriptorPoolCreateInfo,
VkSamplerCreateInfo,
VkImageCreateInfo,
@ -294,6 +295,19 @@
};
basePipelineIndex = auto;
};
VkComputePipelineCreateInfo = {
flags = auto;
stage = auto;
layout = {
type = (custom, QFString, parse_VkPipelineLayout);
fields = (layout);
};
basePipelineHandle = {
type = (custom, QFString, parse_BasePipeline);
fields = (basePipelineHandle);
};
basePipelineIndex = auto;
};
VkImageCreateInfo = {
flags = auto;
imageType = auto;

View file

@ -353,8 +353,8 @@ Vulkan_Alias_Init (vulkan_ctx_t *ctx)
DARRAY_RESIZE (&actx->frames, frames);
actx->frames.grow = 0;
actx->depth = Vulkan_CreatePipeline (ctx, "alias_depth");
actx->gbuf = Vulkan_CreatePipeline (ctx, "alias_gbuf");
actx->depth = Vulkan_CreateGraphicsPipeline (ctx, "alias_depth");
actx->gbuf = Vulkan_CreateGraphicsPipeline (ctx, "alias_gbuf");
actx->layout = Vulkan_CreatePipelineLayout (ctx, "alias_layout");
actx->sampler = Vulkan_CreateSampler (ctx, "alias_sampler");

View file

@ -1402,11 +1402,11 @@ Vulkan_Bsp_Init (vulkan_ctx_t *ctx)
DARRAY_RESIZE (&bctx->frames, frames);
bctx->frames.grow = 0;
bctx->depth = Vulkan_CreatePipeline (ctx, "bsp_depth");
bctx->gbuf = Vulkan_CreatePipeline (ctx, "bsp_gbuf");
bctx->skybox = Vulkan_CreatePipeline (ctx, "bsp_skybox");
bctx->skysheet = Vulkan_CreatePipeline (ctx, "bsp_skysheet");
bctx->turb = Vulkan_CreatePipeline (ctx, "bsp_turb");
bctx->depth = Vulkan_CreateGraphicsPipeline (ctx, "bsp_depth");
bctx->gbuf = Vulkan_CreateGraphicsPipeline (ctx, "bsp_gbuf");
bctx->skybox = Vulkan_CreateGraphicsPipeline (ctx, "bsp_skybox");
bctx->skysheet = Vulkan_CreateGraphicsPipeline (ctx, "bsp_skysheet");
bctx->turb = Vulkan_CreateGraphicsPipeline (ctx, "bsp_turb");
bctx->layout = Vulkan_CreatePipelineLayout (ctx, "quakebsp_layout");
bctx->sampler = Vulkan_CreateSampler (ctx, "quakebsp_sampler");

View file

@ -138,7 +138,7 @@ Vulkan_Compose_Init (vulkan_ctx_t *ctx)
DARRAY_RESIZE (&cctx->frames, frames);
cctx->frames.grow = 0;
cctx->pipeline = Vulkan_CreatePipeline (ctx, "compose");
cctx->pipeline = Vulkan_CreateGraphicsPipeline (ctx, "compose");
cctx->layout = Vulkan_CreatePipelineLayout (ctx, "compose_layout");
__auto_type cmdSet = QFV_AllocCommandBufferSet (1, alloca);

View file

@ -396,7 +396,7 @@ Vulkan_Draw_Init (vulkan_ctx_t *ctx)
flush_draw_scrap (ctx);
dctx->pipeline = Vulkan_CreatePipeline (ctx, "twod");
dctx->pipeline = Vulkan_CreateGraphicsPipeline (ctx, "twod");
dctx->layout = Vulkan_CreatePipelineLayout (ctx, "twod_layout");

View file

@ -316,7 +316,7 @@ Vulkan_Lighting_Init (vulkan_ctx_t *ctx)
DARRAY_RESIZE (&lctx->frames, frames);
lctx->frames.grow = 0;
lctx->pipeline = Vulkan_CreatePipeline (ctx, "lighting");
lctx->pipeline = Vulkan_CreateGraphicsPipeline (ctx, "lighting");
lctx->layout = Vulkan_CreatePipelineLayout (ctx, "lighting_layout");
lctx->sampler = Vulkan_CreateSampler (ctx, "shadow_sampler");

View file

@ -297,8 +297,8 @@ Vulkan_Sprite_Init (vulkan_ctx_t *ctx)
DARRAY_RESIZE (&sctx->frames, frames);
sctx->frames.grow = 0;
sctx->depth = Vulkan_CreatePipeline (ctx, "sprite_depth");
sctx->gbuf = Vulkan_CreatePipeline (ctx, "sprite_gbuf");
sctx->depth = Vulkan_CreateGraphicsPipeline (ctx, "sprite_depth");
sctx->gbuf = Vulkan_CreateGraphicsPipeline (ctx, "sprite_gbuf");
sctx->layout = Vulkan_CreatePipelineLayout (ctx, "sprite_layout");
sctx->sampler = Vulkan_CreateSampler (ctx, "sprite_sampler");

View file

@ -551,7 +551,7 @@ Vulkan_DestroyRenderPasses (vulkan_ctx_t *ctx)
}
VkPipeline
Vulkan_CreatePipeline (vulkan_ctx_t *ctx, const char *name)
Vulkan_CreateComputePipeline (vulkan_ctx_t *ctx, const char *name)
{
plitem_t *item = qfv_load_pipeline (ctx, "pipelines");
if (!(item = PL_ObjectForKey (item, name))) {
@ -560,7 +560,25 @@ Vulkan_CreatePipeline (vulkan_ctx_t *ctx, const char *name)
} else {
Sys_MaskPrintf (SYS_vulkan_parse, "Found pipeline def %s\n", name);
}
VkPipeline pipeline = QFV_ParsePipeline (ctx, item, ctx->pipelineDef);
VkPipeline pipeline = QFV_ParseComputePipeline (ctx, item,
ctx->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)
{
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,
ctx->pipelineDef);
QFV_duSetObjectName (ctx->device, VK_OBJECT_TYPE_PIPELINE, pipeline,
va (ctx->va_ctx, "pipeline:%s", name));
return pipeline;