diff options
author | Danylo Piliaiev <danylo.piliaiev@globallogic.com> | 2019-03-14 12:39:13 +0200 |
---|---|---|
committer | Jason Ekstrand <jason@jlekstrand.net> | 2019-03-15 20:24:05 +0000 |
commit | b67640464532678af85f7bcdcef181dd28152b2d (patch) | |
tree | f3a8140f04ccabfbd77910d1c05d6e7a3ea6a40c | |
parent | 28ed17ea6d76b75c1265b3f570516f57da8d98f8 (diff) |
Add missing checks for existence of states during pipeline creation
Vulkan spec permits next states to be NULL in certain cases:
- pTessellationState
- pViewportState
- pMultisampleState
- pDepthStencilState
- pColorBlendState
- pDynamicState
v2: Make it backwards compatible (Jason)
Signed-off-by: Danylo Piliaiev <danylo.piliaiev@globallogic.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
-rw-r--r-- | serialize.c | 30 | ||||
-rw-r--r-- | vkpipeline_db.cpp | 9 |
2 files changed, 33 insertions, 6 deletions
diff --git a/serialize.c b/serialize.c index 14a296f..f17f4aa 100644 --- a/serialize.c +++ b/serialize.c @@ -548,10 +548,14 @@ static void serialize_viewport_state(const VkPipelineViewportStateCreateInfo *pInfo, struct blob *metadata) { + if (pInfo->sType != VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO) { + blob_write_uint32(metadata, VK_STRUCTURE_TYPE_MAX_ENUM); + return; + } + bool has_viewports = pInfo->pViewports ? true : false; bool has_scissors = pInfo->pScissors ? true : false; - assert(pInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO); blob_write_uint32(metadata, pInfo->sType); blob_write_uint32(metadata, pInfo->viewportCount); @@ -578,6 +582,10 @@ deserialize_viewport_state(struct pipeline_info *pipeline, VkPipelineViewportStateCreateInfo *pInfo = &pipeline->viewportState; pInfo->sType = blob_read_uint32(metadata); + if (pInfo->sType == VK_STRUCTURE_TYPE_MAX_ENUM) { + return true; + } + assert(pInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO); pInfo->viewportCount = blob_read_uint32(metadata); @@ -645,9 +653,13 @@ static void serialize_multisample_state(const VkPipelineMultisampleStateCreateInfo *pInfo, struct blob *metadata) { + if (pInfo->sType != VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO) { + blob_write_uint32(metadata, VK_STRUCTURE_TYPE_MAX_ENUM); + return; + } + bool has_sample_mask = pInfo->pSampleMask ? true : false; - assert(pInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO); blob_write_uint32(metadata, pInfo->sType); blob_write_uint32(metadata, pInfo->rasterizationSamples); @@ -673,6 +685,10 @@ deserialize_multisample_state(struct pipeline_info *pipeline, VkPipelineMultisampleStateCreateInfo *pInfo = &pipeline->multisampleState; pInfo->sType = blob_read_uint32(metadata); + if (pInfo->sType == VK_STRUCTURE_TYPE_MAX_ENUM) { + return true; + } + assert(pInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO); pInfo->rasterizationSamples = blob_read_uint32(metadata); @@ -697,7 +713,11 @@ static void serialize_depth_stencil_state(const VkPipelineDepthStencilStateCreateInfo *pInfo, struct blob *metadata) { - assert(pInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO); + if (pInfo->sType != VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO) { + blob_write_uint32(metadata, VK_STRUCTURE_TYPE_MAX_ENUM); + return; + } + blob_write_uint32(metadata, pInfo->sType); blob_write_uint32(metadata, pInfo->depthTestEnable); @@ -720,6 +740,10 @@ deserialize_depth_stencil_state(struct pipeline_info *pipeline, VkPipelineDepthStencilStateCreateInfo *pInfo = &pipeline->depthStencilState; pInfo->sType = blob_read_uint32(metadata); + if (pInfo->sType == VK_STRUCTURE_TYPE_MAX_ENUM) { + return true; + } + assert(pInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO); pInfo->depthTestEnable = blob_read_uint32(metadata); diff --git a/vkpipeline_db.cpp b/vkpipeline_db.cpp index 50303a5..47106ff 100644 --- a/vkpipeline_db.cpp +++ b/vkpipeline_db.cpp @@ -876,10 +876,13 @@ get_graphics_pipeline_info(const VkGraphicsPipelineCreateInfo *pCreateInfo) pipeline->inputAssemblyState = *pCreateInfo->pInputAssemblyState; if (pCreateInfo->pTessellationState) pipeline->tessellationState = *pCreateInfo->pTessellationState; - pipeline->viewportState = *pCreateInfo->pViewportState; + if (pCreateInfo->pViewportState) + pipeline->viewportState = *pCreateInfo->pViewportState; pipeline->rasterizationState = *pCreateInfo->pRasterizationState; - pipeline->multisampleState = *pCreateInfo->pMultisampleState; - pipeline->depthStencilState = *pCreateInfo->pDepthStencilState; + if (pCreateInfo->pMultisampleState) + pipeline->multisampleState = *pCreateInfo->pMultisampleState; + if (pCreateInfo->pDepthStencilState) + pipeline->depthStencilState = *pCreateInfo->pDepthStencilState; if (pCreateInfo->pColorBlendState) pipeline->colorBlendState = *pCreateInfo->pColorBlendState; if (pCreateInfo->pDynamicState) |