From 7901f8796018e67df73ae23131763bb6b4e0ea2e Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 16 Dec 2021 23:00:17 +0900 Subject: [PATCH] [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). --- include/QF/Vulkan/qf_vid.h | 5 +++- libs/video/renderer/vulkan/vkparse.c | 30 ++++++++++++++++++- libs/video/renderer/vulkan/vkparse.h | 6 ++-- libs/video/renderer/vulkan/vkparse.plist | 14 +++++++++ libs/video/renderer/vulkan/vulkan_alias.c | 4 +-- libs/video/renderer/vulkan/vulkan_bsp.c | 10 +++---- libs/video/renderer/vulkan/vulkan_compose.c | 2 +- libs/video/renderer/vulkan/vulkan_draw.c | 2 +- libs/video/renderer/vulkan/vulkan_lighting.c | 2 +- libs/video/renderer/vulkan/vulkan_sprite.c | 4 +-- .../video/renderer/vulkan/vulkan_vid_common.c | 22 ++++++++++++-- 11 files changed, 83 insertions(+), 18 deletions(-) diff --git a/include/QF/Vulkan/qf_vid.h b/include/QF/Vulkan/qf_vid.h index 1a94898a3..f729c2b65 100644 --- a/include/QF/Vulkan/qf_vid.h +++ b/include/QF/Vulkan/qf_vid.h @@ -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, diff --git a/libs/video/renderer/vulkan/vkparse.c b/libs/video/renderer/vulkan/vkparse.c index b9db14277..51ef1136f 100644 --- a/libs/video/renderer/vulkan/vkparse.c +++ b/libs/video/renderer/vulkan/vkparse.c @@ -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; diff --git a/libs/video/renderer/vulkan/vkparse.h b/libs/video/renderer/vulkan/vkparse.h index 6e2ef92b2..6f2ea6357 100644 --- a/libs/video/renderer/vulkan/vkparse.h +++ b/libs/video/renderer/vulkan/vkparse.h @@ -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, diff --git a/libs/video/renderer/vulkan/vkparse.plist b/libs/video/renderer/vulkan/vkparse.plist index 6f5efa6d3..23577cb79 100644 --- a/libs/video/renderer/vulkan/vkparse.plist +++ b/libs/video/renderer/vulkan/vkparse.plist @@ -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; diff --git a/libs/video/renderer/vulkan/vulkan_alias.c b/libs/video/renderer/vulkan/vulkan_alias.c index 848748a23..d40ea4562 100644 --- a/libs/video/renderer/vulkan/vulkan_alias.c +++ b/libs/video/renderer/vulkan/vulkan_alias.c @@ -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"); diff --git a/libs/video/renderer/vulkan/vulkan_bsp.c b/libs/video/renderer/vulkan/vulkan_bsp.c index 3c63c1fb8..db0877881 100644 --- a/libs/video/renderer/vulkan/vulkan_bsp.c +++ b/libs/video/renderer/vulkan/vulkan_bsp.c @@ -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"); diff --git a/libs/video/renderer/vulkan/vulkan_compose.c b/libs/video/renderer/vulkan/vulkan_compose.c index b188cae95..161012ae0 100644 --- a/libs/video/renderer/vulkan/vulkan_compose.c +++ b/libs/video/renderer/vulkan/vulkan_compose.c @@ -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); diff --git a/libs/video/renderer/vulkan/vulkan_draw.c b/libs/video/renderer/vulkan/vulkan_draw.c index 6c5824d26..f64c6515e 100644 --- a/libs/video/renderer/vulkan/vulkan_draw.c +++ b/libs/video/renderer/vulkan/vulkan_draw.c @@ -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"); diff --git a/libs/video/renderer/vulkan/vulkan_lighting.c b/libs/video/renderer/vulkan/vulkan_lighting.c index 5e62e9f31..5fd4c9dfb 100644 --- a/libs/video/renderer/vulkan/vulkan_lighting.c +++ b/libs/video/renderer/vulkan/vulkan_lighting.c @@ -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"); diff --git a/libs/video/renderer/vulkan/vulkan_sprite.c b/libs/video/renderer/vulkan/vulkan_sprite.c index ce4dcc599..53a7d2efe 100644 --- a/libs/video/renderer/vulkan/vulkan_sprite.c +++ b/libs/video/renderer/vulkan/vulkan_sprite.c @@ -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"); diff --git a/libs/video/renderer/vulkan/vulkan_vid_common.c b/libs/video/renderer/vulkan/vulkan_vid_common.c index de553fde0..2e1f57c2b 100644 --- a/libs/video/renderer/vulkan/vulkan_vid_common.c +++ b/libs/video/renderer/vulkan/vulkan_vid_common.c @@ -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;