From ad175d054bfb2fb3cd11b3018deb2d5a8ceb5803 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 18 Feb 2020 22:38:01 +0900 Subject: [PATCH] Sanitize pipelines wow, talk about doing things the wrong way. I guess that's the problem with following a book targeted for C++: you get all that safety-goat nonsense. --- include/QF/Vulkan/pipeline.h | 164 +++-------- libs/video/renderer/vulkan/pipeline.c | 403 ++------------------------ 2 files changed, 68 insertions(+), 499 deletions(-) diff --git a/include/QF/Vulkan/pipeline.h b/include/QF/Vulkan/pipeline.h index 2120e2317..f77585217 100644 --- a/include/QF/Vulkan/pipeline.h +++ b/include/QF/Vulkan/pipeline.h @@ -3,23 +3,11 @@ #include "QF/darray.h" -typedef struct qfv_shadermodule_s { - struct qfv_device_s *device; - VkShaderModule module; -} qfv_shadermodule_t; +typedef struct qfv_pipelineshaderstateset_s + DARRAY_TYPE (VkPipelineShaderStageCreateInfo) qfv_pipelineshaderstateset_s; -typedef struct qfv_shaderstageparams_s { - VkShaderStageFlagBits stageFlags; - qfv_shadermodule_t *module; - const char *entryPointName; - const VkSpecializationInfo *specializationInfo; -} qfv_shaderstageparams_t; - -typedef struct qfv_shaderstageparamsset_s - DARRAY_TYPE (qfv_shaderstageparams_t) qfv_shaderstageparamsset_t; - -#define QFV_AllocShaderParamsSet(num, allocator) \ - DARRAY_ALLOCFIXED (qfv_shaderstageparamsset_t, num, allocator) +#define QFV_AllocPipelineShaderStageSet(num, allocator) \ + DARRAY_ALLOCFIXED (qfv_pipelineshaderstateset_s, num, allocator) typedef struct qfv_vertexinputbindingset_s DARRAY_TYPE (VkVertexInputBindingDescription) qfv_vertexinputbindingset_t; @@ -48,21 +36,15 @@ typedef struct qfv_pipelinetessellation_s { uint32_t patchControlPoints; } qfv_pipelinetessellation_t; -typedef struct qfv_viewportset_s { - uint32_t numViewports; - VkViewport viewports[]; -} qfv_viewportset_t; +typedef struct qfv_viewportset_s DARRAY_TYPE (VkViewport) qfv_viewportset_t; #define QFV_AllocViewportSet(num, allocator) \ - allocator (field_offset (qfv_viewportset_t, viewports[num])) + DARRAY_ALLOCFIXED (qfv_viewportset_t, num, allocator) -typedef struct qfv_scissorsset_s { - uint32_t numScissors; - VkRect2D scissors[]; -} qfv_scissorsset_t; +typedef struct qfv_scissorsset_s DARRAY_TYPE (VkRect2D) qfv_scissorsset_t; #define QFV_AllocScissorsSet(num, allocator) \ - allocator (field_offset (qfv_scissorsset_t, scissors[num])) + DARRAY_ALLOCFIXED (qfv_scissorsset_t, num, allocator) typedef struct qfv_viewportinfo_s { qfv_viewportset_t *viewportset; @@ -103,139 +85,73 @@ typedef struct qfv_pipelinedepthandstencil_s { float maxDepthBounds; } qfv_pipelinedepthandstencil_t; -typedef struct qfv_blendattachmentset_s { - uint32_t numAttachments; - VkPipelineColorBlendAttachmentState attachments[]; -} qfv_blendattachmentset_t; +typedef struct qfv_blendattachmentset_s + DARRAY_TYPE (VkPipelineColorBlendAttachmentState) qfv_blendattachmentset_t; #define QFV_AllocBlendAttachmentSet(num, allocator) \ - allocator (field_offset (qfv_blendattachmentset_t, attachments[num])) + DARRAY_ALLOCFIXED (qfv_blendattachmentset_t, num, allocator) -typedef struct qfv_pipelineblend_s { - VkBool32 logicOpEnable; - VkLogicOp logicOp; - qfv_blendattachmentset_t *blendAttachments; - float blendConstants[4]; -} qfv_pipelineblend_t; - -typedef struct qfv_dynamicstateset_s { - uint32_t numStates; - VkDynamicState states[]; -} qfv_dynamicstateset_t; +typedef struct qfv_dynamicstateset_s + DARRAY_TYPE (VkDynamicState) qfv_dynamicstateset_t; #define QFV_AllocDynamicStateSet(num, allocator) \ - allocator (field_offset (qfv_dynamicstateset_t, states[num])) + DARRAY_ALLOCFIXED (qfv_dynamicstateset_t, num, allocator) -typedef struct qfv_pushconstantrangeset_s { - uint32_t numRanges; - VkPushConstantRange ranges[]; -} qfv_pushconstantrangeset_t; +typedef struct qfv_pushconstantrangeset_s + DARRAY_TYPE (VkPushConstantRange) qfv_pushconstantrangeset_t; #define QFV_AllocPushConstantRangeSet(num, allocator) \ - allocator (field_offset (qfv_pushconstantrangeset_t, ranges[num])) + DARRAY_ALLOCFIXED (qfv_pushconstantrangeset_t, num, allocator) -typedef struct qfv_pipelinelayout_s { - struct qfv_device_s *device; - VkPipelineLayout layout; -} qfv_pipelinelayout_t; - -typedef struct qfv_pipeline_s { - struct qfv_device_s *device; - VkPipeline pipeline; -} qfv_pipeline_t; - -typedef struct qfv_pipelineset_s { - uint32_t numPipelines; - qfv_pipeline_t *pipelines[]; -} qfv_pipelineset_t; +typedef struct qfv_pipelineset_s DARRAY_TYPE (VkPipeline) qfv_pipelineset_t; #define QFV_AllocPipelineSet(num, allocator) \ - allocator (field_offset (qfv_pipelineset_t, pipelines[num])) + DARRAY_ALLOCFIXED (qfv_pipelineset_t, num, allocator) -typedef struct qfv_graphicspipelinecreateinfo_s { - VkPipelineCreateFlags flags; - qfv_shaderstageparamsset_t *stages; - qfv_vertexinputstate_t *vertexState; - qfv_pipelineinputassembly_t *inputAssemblyState; - qfv_pipelinetessellation_t *tessellationState; - qfv_viewportinfo_t *viewportState; - qfv_pipelinerasterization_t *rasterizationState; - qfv_pipelinemultisample_t *multisampleState; - qfv_pipelinedepthandstencil_t *depthStencilState; - qfv_pipelineblend_t *colorBlendState; - qfv_dynamicstateset_t *dynamicState; - qfv_pipelinelayout_t *layout; - VkRenderPass renderPass; - uint32_t subpass; - qfv_pipeline_t *basePipeline; - int32_t basePipelineIndex; -} qfv_graphicspipelinecreateinfo_t; - -typedef struct qfv_graphicspipelinecreateinfoset_s { - uint32_t numPipelines; - qfv_graphicspipelinecreateinfo_t *pipelines[]; -} qfv_graphicspipelinecreateinfoset_t; +typedef struct qfv_graphicspipelinecreateinfoset_s + DARRAY_TYPE (VkGraphicsPipelineCreateInfo) + qfv_graphicspipelinecreateinfoset_t; #define QFV_AllocGraphicsPipelineCreateInfoSet(num, allocator) \ - allocator (field_offset (qfv_graphicspipelinecreateinfoset_t, \ - pipelines[num])) + DARRAY_ALLOCFIXED (qfv_graphicspipelinecreateinfoset_t, num, allocator) -typedef struct qfv_computepipelinecreateinfo_s { - VkPipelineCreateFlags flags; - qfv_shaderstageparams_t *stage; - qfv_pipelinelayout_t *layout; - qfv_pipeline_t *basePipeline; - int32_t basePipelineIndex; -} qfv_computepipelinecreateinfo_t; - -typedef struct qfv_computepipelinecreateinfoset_s { - uint32_t numPipelines; - qfv_computepipelinecreateinfo_t *pipelines[]; -} qfv_computepipelinecreateinfoset_t; +typedef struct qfv_computepipelinecreateinfoset_s + DARRAY_TYPE (VkComputePipelineCreateInfo) + qfv_computepipelinecreateinfoset_t; #define QFV_AllocComputePipelineCreateInfoSet(num, allocator) \ - allocator (field_offset (qfv_computepipelinecreateinfoset_t, \ - pipelines[num])) + DARRAY_ALLOCFIXED (qfv_computepipelinecreateinfoset_t, num, allocator) -typedef struct qfv_pipelinecache_s { - struct qfv_device_s *device; - VkPipelineCache cache; -} qfv_pipelinecache_t; - -typedef struct qfv_pipelinecacheset_s { - uint32_t numCaches; - qfv_pipelinecache_t *caches[]; -} qfv_pipelinecacheset_t; +typedef struct qfv_pipelinecacheset_s + DARRAY_TYPE (VkPipelineCache) qfv_pipelinecacheset_t; #define QFV_AllocPipelineCacheSet(num, allocator) \ - allocator (field_offset (qfv_pipelinecacheset_t, caches[num])) + DARRAY_ALLOCFIXED (qfv_pipelinecacheset_t, num, allocator) -qfv_shadermodule_t *QFV_CreateShaderModule (struct qfv_device_s *device, +VkShaderModule QFV_CreateShaderModule (struct qfv_device_s *device, size_t size, const uint32_t *code); -void QFV_DestroyShaderModule (qfv_shadermodule_t *module); struct dstring_s; -qfv_pipelinecache_t *QFV_CreatePipelineCache (struct qfv_device_s *device, - struct dstring_s *cacheData); -struct dstring_s *QFV_GetPipelineCacheData (qfv_pipelinecache_t *cache); -void QFV_MergePipelineCaches (qfv_pipelinecache_t *targetCache, +VkPipelineCache QFV_CreatePipelineCache (struct qfv_device_s *device, + struct dstring_s *cacheData); +struct dstring_s *QFV_GetPipelineCacheData (struct qfv_device_s *device, + VkPipelineCache cache); +void QFV_MergePipelineCaches (struct qfv_device_s *device, + VkPipelineCache targetCache, qfv_pipelinecacheset_t *sourceCaches); -void QFV_DestroyPipelineCache (qfv_pipelinecache_t *cache); struct qfv_descriptorsetlayoutset_s; -qfv_pipelinelayout_t * +VkPipelineLayout QFV_CreatePipelineLayout (struct qfv_device_s *device, struct qfv_descriptorsetlayoutset_s *layouts, qfv_pushconstantrangeset_t *pushConstants); -void QFV_DestroyPipelineLayout (qfv_pipelinelayout_t *layout); qfv_pipelineset_t * QFV_CreateGraphicsPipelines (struct qfv_device_s *device, - qfv_pipelinecache_t *cache, + VkPipelineCache cache, qfv_graphicspipelinecreateinfoset_t *gpciSet); qfv_pipelineset_t * QFV_CreateComputePipelines (struct qfv_device_s *device, - qfv_pipelinecache_t *cache, + VkPipelineCache cache, qfv_computepipelinecreateinfoset_t *cpciSet); -void QFV_DestroyPipeline (qfv_pipeline_t *pipeline); #endif//__QF_Vulkan_pipeline_h diff --git a/libs/video/renderer/vulkan/pipeline.c b/libs/video/renderer/vulkan/pipeline.c index 18babb115..119fbf303 100644 --- a/libs/video/renderer/vulkan/pipeline.c +++ b/libs/video/renderer/vulkan/pipeline.c @@ -64,7 +64,7 @@ #include "util.h" -qfv_shadermodule_t * +VkShaderModule QFV_CreateShaderModule (qfv_device_t *device, size_t size, const uint32_t *code) { @@ -76,24 +76,12 @@ QFV_CreateShaderModule (qfv_device_t *device, size, code, }; - qfv_shadermodule_t *module = malloc (sizeof (*module)); - module->device = device; - dfunc->vkCreateShaderModule (dev, &createInfo, 0, &module->module); + VkShaderModule module; + dfunc->vkCreateShaderModule (dev, &createInfo, 0, &module); return module; } -void -QFV_DestroyShaderModule (qfv_shadermodule_t *module) -{ - qfv_device_t *device = module->device; - VkDevice dev = device->dev; - qfv_devfuncs_t *dfunc = device->funcs; - - dfunc->vkDestroyShaderModule (dev, module->module, 0); - free (module); -} - -qfv_pipelinecache_t * +VkPipelineCache QFV_CreatePipelineCache (qfv_device_t *device, dstring_t *cacheData) { VkDevice dev = device->dev; @@ -104,55 +92,38 @@ QFV_CreatePipelineCache (qfv_device_t *device, dstring_t *cacheData) cacheData->size, cacheData->str, }; - qfv_pipelinecache_t *cache = malloc (sizeof (*cache)); - cache->device = device; - dfunc->vkCreatePipelineCache (dev, &createInfo, 0, &cache->cache); + VkPipelineCache cache; + dfunc->vkCreatePipelineCache (dev, &createInfo, 0, &cache); return cache; } dstring_t * -QFV_GetPipelineCacheData (qfv_pipelinecache_t *cache) +QFV_GetPipelineCacheData (qfv_device_t *device, VkPipelineCache cache) { - qfv_device_t *device = cache->device; VkDevice dev = device->dev; qfv_devfuncs_t *dfunc = device->funcs; dstring_t *cacheData = dstring_new (); - dfunc->vkGetPipelineCacheData (dev, cache->cache, &cacheData->size, 0); + dfunc->vkGetPipelineCacheData (dev, cache, &cacheData->size, 0); dstring_adjust (cacheData); - dfunc->vkGetPipelineCacheData (dev, cache->cache, &cacheData->size, - cacheData->str); + dfunc->vkGetPipelineCacheData (dev, cache, + &cacheData->size, cacheData->str); return cacheData; } void -QFV_MergePipelineCaches (qfv_pipelinecache_t *targetCache, +QFV_MergePipelineCaches (qfv_device_t *device, + VkPipelineCache targetCache, qfv_pipelinecacheset_t *sourceCaches) { - qfv_device_t *device = targetCache->device; VkDevice dev = device->dev; qfv_devfuncs_t *dfunc = device->funcs; - VkPipelineCache *srcCaches = alloca (sourceCaches->numCaches - * sizeof (*srcCaches)); - for (uint32_t i = 0; i < sourceCaches->numCaches; i++) { - srcCaches[i] = sourceCaches->caches[i]->cache; - } - dfunc->vkMergePipelineCaches (dev, targetCache->cache, - sourceCaches->numCaches, srcCaches); + dfunc->vkMergePipelineCaches (dev, targetCache, + sourceCaches->size, sourceCaches->a); } -void -QFV_DestroyPipelineCache (qfv_pipelinecache_t *cache) -{ - qfv_device_t *device = cache->device; - VkDevice dev = device->dev; - qfv_devfuncs_t *dfunc = device->funcs; - - dfunc->vkDestroyPipelineCache (dev, cache->cache, 0); -} - -qfv_pipelinelayout_t * +VkPipelineLayout QFV_CreatePipelineLayout (qfv_device_t *device, qfv_descriptorsetlayoutset_t *layouts, qfv_pushconstantrangeset_t *pushConstants) @@ -163,357 +134,39 @@ QFV_CreatePipelineLayout (qfv_device_t *device, VkPipelineLayoutCreateInfo createInfo = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, 0, 0, layouts->size, layouts->a, - pushConstants->numRanges, pushConstants->ranges, + pushConstants->size, pushConstants->a, }; - qfv_pipelinelayout_t *layout = malloc (sizeof (layout)); - layout->device = device; - dfunc->vkCreatePipelineLayout (dev, &createInfo, 0, &layout->layout); + VkPipelineLayout layout; + dfunc->vkCreatePipelineLayout (dev, &createInfo, 0, &layout); return layout; } -void -QFV_DestroyPipelineLayout (qfv_pipelinelayout_t *layout) -{ - qfv_device_t *device = layout->device; - VkDevice dev = device->dev; - qfv_devfuncs_t *dfunc = device->funcs; - - dfunc->vkDestroyPipelineLayout (dev, layout->layout, 0); - free (layout); -} - -static VkPipelineShaderStageCreateInfo -shaderStageCI (qfv_shaderstageparams_t params) -{ - VkPipelineShaderStageCreateInfo createInfo = { - VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, 0, 0, - params.stageFlags, params.module->module, - params.entryPointName, params.specializationInfo, - }; - return createInfo; -} - -static VkPipelineVertexInputStateCreateInfo -vertexInputSCI (qfv_vertexinputstate_t vertexState) -{ - VkPipelineVertexInputStateCreateInfo createInfo = { - VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, 0, 0, - vertexState.bindings->size, - vertexState.bindings->a, - vertexState.attributes->size, - vertexState.attributes->a, - }; - return createInfo; -} - -static VkPipelineInputAssemblyStateCreateInfo -inputAssemblySCI (qfv_pipelineinputassembly_t inputAssemblyState) -{ - VkPipelineInputAssemblyStateCreateInfo createInfo = { - VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, 0, 0, - inputAssemblyState.topology, - inputAssemblyState.primativeRestartEnable, - }; - return createInfo; -} - -static VkPipelineTessellationStateCreateInfo -tessellationSCI (qfv_pipelinetessellation_t tessellationState) -{ - VkPipelineTessellationStateCreateInfo createInfo = { - VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, 0, 0, - tessellationState.patchControlPoints - }; - return createInfo; -} - -static VkPipelineViewportStateCreateInfo -viewportSCI (qfv_viewportinfo_t viewportState) -{ - VkPipelineViewportStateCreateInfo createInfo = { - VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, 0, 0, - viewportState.viewportset->numViewports, - viewportState.viewportset->viewports, - viewportState.scissorsset->numScissors, - viewportState.scissorsset->scissors, - }; - return createInfo; -} - -static VkPipelineRasterizationStateCreateInfo -rasterizationSCI (qfv_pipelinerasterization_t rasterizationState) -{ - VkPipelineRasterizationStateCreateInfo createInfo = { - VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, 0, 0, - rasterizationState.depthClampEnable, - rasterizationState.rasterizerDiscardEnable, - rasterizationState.polygonMode, - rasterizationState.cullMode, - rasterizationState.frontFace, - rasterizationState.depthBiasEnable, - rasterizationState.depthBiasConstantFactor, - rasterizationState.depthBiasClamp, - rasterizationState.depthBiasSlopeFactor, - rasterizationState.lineWidth, - }; - return createInfo; -} - -static VkPipelineMultisampleStateCreateInfo -multisampleSCI (qfv_pipelinemultisample_t multisampleState) -{ - VkPipelineMultisampleStateCreateInfo createInfo = { - VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, 0, 0, - multisampleState.rasterizationSamples, - multisampleState.sampleShadingEnable, - multisampleState.minSampleShading, - multisampleState.sampleMask, - multisampleState.alphaToCoverageEnable, - multisampleState.alphaToOneEnable, - }; - return createInfo; -} - -static VkPipelineDepthStencilStateCreateInfo -depthStencilSCI (qfv_pipelinedepthandstencil_t depthStencilState) -{ - VkPipelineDepthStencilStateCreateInfo createInfo = { - VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, 0, 0, - depthStencilState.depthTestEnable, - depthStencilState.depthWriteEnable, - depthStencilState.depthCompareOp, - depthStencilState.depthBoundsTestEnable, - depthStencilState.stencilTestEnable, - depthStencilState.front, - depthStencilState.back, - depthStencilState.minDepthBounds, - depthStencilState.maxDepthBounds, - }; - return createInfo; -} - -static VkPipelineColorBlendStateCreateInfo -colorBlendSCI (qfv_pipelineblend_t colorBlendState) -{ - VkPipelineColorBlendStateCreateInfo createInfo = { - VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, 0, 0, - colorBlendState.logicOpEnable, - colorBlendState.logicOp, - colorBlendState.blendAttachments->numAttachments, - colorBlendState.blendAttachments->attachments, - { - colorBlendState.blendConstants[0], - colorBlendState.blendConstants[1], - colorBlendState.blendConstants[2], - colorBlendState.blendConstants[3], - }, - }; - return createInfo; -} - -static VkPipelineDynamicStateCreateInfo -dynamicSCI (qfv_dynamicstateset_t *dynamicState) -{ - VkPipelineDynamicStateCreateInfo createInfo = { - VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, 0, 0, - dynamicState->numStates, dynamicState->states, - }; - return createInfo; -} - qfv_pipelineset_t * QFV_CreateGraphicsPipelines (qfv_device_t *device, - qfv_pipelinecache_t *cache, + VkPipelineCache cache, qfv_graphicspipelinecreateinfoset_t *gpciSet) { VkDevice dev = device->dev; qfv_devfuncs_t *dfunc = device->funcs; - uint32_t numPipelines = gpciSet->numPipelines; - uint32_t stageCount = 0; - for (uint32_t i = 0; i < numPipelines; i++) { - stageCount += gpciSet->pipelines[i]->stages->size; - } + __auto_type pipelines = QFV_AllocPipelineSet (gpciSet->size, malloc); + dfunc->vkCreateGraphicsPipelines (dev, cache, gpciSet->size, gpciSet->a, 0, + pipelines->a); - size_t blockSize = numPipelines - * (sizeof (VkGraphicsPipelineCreateInfo) - + sizeof (VkPipelineVertexInputStateCreateInfo) - + sizeof (VkPipelineInputAssemblyStateCreateInfo) - + sizeof (VkPipelineTessellationStateCreateInfo) - + sizeof (VkPipelineViewportStateCreateInfo) - + sizeof (VkPipelineRasterizationStateCreateInfo) - + sizeof (VkPipelineMultisampleStateCreateInfo) - + sizeof (VkPipelineDepthStencilStateCreateInfo) - + sizeof (VkPipelineColorBlendStateCreateInfo) - + sizeof (VkPipelineDynamicStateCreateInfo)) - + stageCount * sizeof (VkPipelineShaderStageCreateInfo); - VkGraphicsPipelineCreateInfo *pipelineInfos = malloc (blockSize); - - pipelineInfos->pStages = (void *)(pipelineInfos + numPipelines); - pipelineInfos->pVertexInputState - = (void *)(pipelineInfos->pStages + stageCount); - pipelineInfos->pInputAssemblyState - = (void *)(pipelineInfos->pVertexInputState + numPipelines); - pipelineInfos->pTessellationState - = (void *)(pipelineInfos->pInputAssemblyState + numPipelines); - pipelineInfos->pViewportState - = (void *)(pipelineInfos->pTessellationState + numPipelines); - pipelineInfos->pRasterizationState - = (void *)(pipelineInfos->pViewportState + numPipelines); - pipelineInfos->pMultisampleState - = (void *)(pipelineInfos->pRasterizationState + numPipelines); - pipelineInfos->pDepthStencilState - = (void *)(pipelineInfos->pMultisampleState + numPipelines); - pipelineInfos->pColorBlendState - = (void *)(pipelineInfos->pDepthStencilState + numPipelines); - pipelineInfos->pDynamicState - = (void *)(pipelineInfos->pColorBlendState + numPipelines); - for (uint32_t i = 1; i < gpciSet->numPipelines; i++) { - pipelineInfos[i].pStages = pipelineInfos[i - 1].pStages - + gpciSet->pipelines[i - 1]->stages->size; - pipelineInfos[i].pVertexInputState - = pipelineInfos[i - 1].pVertexInputState + 1; - pipelineInfos[i].pInputAssemblyState - = pipelineInfos[i - 1].pInputAssemblyState + 1; - pipelineInfos[i].pTessellationState - = pipelineInfos[i - 1].pTessellationState + 1; - pipelineInfos[i].pViewportState - = pipelineInfos[i - 1].pViewportState + 1; - pipelineInfos[i].pRasterizationState - = pipelineInfos[i - 1].pRasterizationState + 1; - pipelineInfos[i].pMultisampleState - = pipelineInfos[i - 1].pMultisampleState + 1; - pipelineInfos[i].pDepthStencilState - = pipelineInfos[i - 1].pDepthStencilState + 1; - pipelineInfos[i].pColorBlendState - = pipelineInfos[i - 1].pColorBlendState + 1; - pipelineInfos[i].pDynamicState - = pipelineInfos[i - 1].pDynamicState + 1; - } - for (uint32_t i = 0; i < gpciSet->numPipelines; i++) { - VkGraphicsPipelineCreateInfo *gci = pipelineInfos + i; - qfv_graphicspipelinecreateinfo_t *ci = gpciSet->pipelines[i]; - gci->sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; - gci->pNext = 0; - gci->flags = ci->flags; - gci->stageCount = ci->stages->size; - for (uint32_t j = 0; j < gci->stageCount; j++) { - ((VkPipelineShaderStageCreateInfo *)gci->pStages)[i] = shaderStageCI (ci->stages->a[j]); - } - if (ci->vertexState) { - *(VkPipelineVertexInputStateCreateInfo *)gci->pVertexInputState = vertexInputSCI (*ci->vertexState); - } else { - gci->pVertexInputState = 0; - } - if (ci->inputAssemblyState) { - *(VkPipelineInputAssemblyStateCreateInfo *)gci->pInputAssemblyState = inputAssemblySCI (*ci->inputAssemblyState); - } else { - gci->pInputAssemblyState = 0; - } - if (ci->tessellationState) { - *(VkPipelineTessellationStateCreateInfo *)gci->pTessellationState = tessellationSCI (*ci->tessellationState); - } else { - gci->pTessellationState = 0; - } - if (ci->viewportState) { - *(VkPipelineViewportStateCreateInfo *)gci->pViewportState = viewportSCI (*ci->viewportState); - } else { - gci->pViewportState = 0; - } - if (ci->rasterizationState) { - *(VkPipelineRasterizationStateCreateInfo *)gci->pRasterizationState = rasterizationSCI (*ci->rasterizationState); - } else { - gci->pRasterizationState = 0; - } - if (ci->multisampleState) { - *(VkPipelineMultisampleStateCreateInfo *)gci->pMultisampleState = multisampleSCI (*ci->multisampleState); - } else { - gci->pMultisampleState = 0; - } - if (ci->depthStencilState) { - *(VkPipelineDepthStencilStateCreateInfo *)gci->pDepthStencilState = depthStencilSCI (*ci->depthStencilState); - } else { - gci->pDepthStencilState = 0; - } - if (ci->colorBlendState) { - *(VkPipelineColorBlendStateCreateInfo *)gci->pColorBlendState = colorBlendSCI (*ci->colorBlendState); - } else { - gci->pColorBlendState = 0; - } - if (ci->dynamicState) { - *(VkPipelineDynamicStateCreateInfo *)gci->pDynamicState = dynamicSCI (ci->dynamicState); - } else { - gci->pDynamicState = 0; - } - gci->layout = ci->layout->layout; - gci->renderPass = ci->renderPass; - gci->subpass = ci->subpass; - gci->basePipelineHandle = ci->basePipeline->pipeline; - gci->basePipelineIndex = ci->basePipelineIndex; - } - - VkPipeline *pipelines = alloca (numPipelines * sizeof (pipelines)); - dfunc->vkCreateGraphicsPipelines (dev, cache->cache, - numPipelines, pipelineInfos, 0, - pipelines); - - qfv_pipelineset_t *pipelineset = QFV_AllocPipelineSet (numPipelines, malloc); - pipelineset->numPipelines = numPipelines; - for (uint32_t i = 0; i < numPipelines; i++) { - pipelineset->pipelines[i] = malloc (sizeof (qfv_pipeline_t)); - pipelineset->pipelines[i]->device = device; - pipelineset->pipelines[i]->pipeline = pipelines[i]; - } - return pipelineset; + return pipelines; } qfv_pipelineset_t * QFV_CreateComputePipelines (qfv_device_t *device, - qfv_pipelinecache_t *cache, + VkPipelineCache cache, qfv_computepipelinecreateinfoset_t *cpciSet) { VkDevice dev = device->dev; qfv_devfuncs_t *dfunc = device->funcs; - uint32_t numPipelines = cpciSet->numPipelines; - - size_t blockSize = numPipelines * (sizeof (VkComputePipelineCreateInfo)); - VkComputePipelineCreateInfo *pipelineInfos = malloc (blockSize); - - for (uint32_t i = 0; i < cpciSet->numPipelines; i++) { - VkComputePipelineCreateInfo *cci = pipelineInfos + i; - qfv_computepipelinecreateinfo_t *ci = cpciSet->pipelines[i]; - cci->sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO; - cci->pNext = 0; - cci->flags = ci->flags; - cci->stage = shaderStageCI (*ci->stage); - cci->layout = ci->layout->layout; - cci->basePipelineHandle = ci->basePipeline->pipeline; - cci->basePipelineIndex = ci->basePipelineIndex; - } - - VkPipeline *pipelines = alloca (numPipelines * sizeof (pipelines)); - dfunc->vkCreateComputePipelines (dev, cache->cache, - numPipelines, pipelineInfos, 0, - pipelines); - - qfv_pipelineset_t *pipelineset = QFV_AllocPipelineSet (numPipelines, malloc); - pipelineset->numPipelines = numPipelines; - for (uint32_t i = 0; i < numPipelines; i++) { - pipelineset->pipelines[i] = malloc (sizeof (qfv_pipeline_t)); - pipelineset->pipelines[i]->device = device; - pipelineset->pipelines[i]->pipeline = pipelines[i]; - } - return pipelineset; -} - -void -QFV_DestroyPipeline (qfv_pipeline_t *pipeline) -{ - qfv_device_t *device = pipeline->device; - VkDevice dev = device->dev; - qfv_devfuncs_t *dfunc = device->funcs; - - dfunc->vkDestroyPipeline (dev, pipeline->pipeline, 0); + __auto_type pipelines = QFV_AllocPipelineSet (cpciSet->size, malloc); + dfunc->vkCreateComputePipelines (dev, cache, cpciSet->size, cpciSet->a, 0, + pipelines->a); + return pipelines; }