lavapipe: split out pipeline struct duplication to a macro.

This just pulls a common pattern into a macro.

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7978>
This commit is contained in:
Dave Airlie
2020-12-08 09:34:14 +10:00
parent a2cf059023
commit 6a27262cc2

View File

@@ -32,6 +32,13 @@
#define SPIR_V_MAGIC_NUMBER 0x07230203 #define SPIR_V_MAGIC_NUMBER 0x07230203
#define LVP_PIPELINE_DUP(dst, src, type, count) do { \
type *temp = ralloc_array(mem_ctx, type, count); \
if (!temp) return VK_ERROR_OUT_OF_HOST_MEMORY; \
memcpy(temp, (src), sizeof(type) * count); \
dst = temp; \
} while(0)
VkResult lvp_CreateShaderModule( VkResult lvp_CreateShaderModule(
VkDevice _device, VkDevice _device,
const VkShaderModuleCreateInfo* pCreateInfo, const VkShaderModuleCreateInfo* pCreateInfo,
@@ -141,32 +148,23 @@ deep_copy_vertex_input_state(void *mem_ctx,
struct VkPipelineVertexInputStateCreateInfo *dst, struct VkPipelineVertexInputStateCreateInfo *dst,
const struct VkPipelineVertexInputStateCreateInfo *src) const struct VkPipelineVertexInputStateCreateInfo *src)
{ {
int i;
VkVertexInputBindingDescription *dst_binding_descriptions;
VkVertexInputAttributeDescription *dst_attrib_descriptions;
dst->sType = src->sType; dst->sType = src->sType;
dst->pNext = NULL; dst->pNext = NULL;
dst->flags = src->flags; dst->flags = src->flags;
dst->vertexBindingDescriptionCount = src->vertexBindingDescriptionCount; dst->vertexBindingDescriptionCount = src->vertexBindingDescriptionCount;
dst_binding_descriptions = ralloc_array(mem_ctx, VkVertexInputBindingDescription, src->vertexBindingDescriptionCount); LVP_PIPELINE_DUP(dst->pVertexBindingDescriptions,
if (!dst_binding_descriptions) src->pVertexBindingDescriptions,
return VK_ERROR_OUT_OF_HOST_MEMORY; VkVertexInputBindingDescription,
for (i = 0; i < dst->vertexBindingDescriptionCount; i++) { src->vertexBindingDescriptionCount);
memcpy(&dst_binding_descriptions[i], &src->pVertexBindingDescriptions[i], sizeof(VkVertexInputBindingDescription));
}
dst->pVertexBindingDescriptions = dst_binding_descriptions;
dst->vertexAttributeDescriptionCount = src->vertexAttributeDescriptionCount; dst->vertexAttributeDescriptionCount = src->vertexAttributeDescriptionCount;
dst_attrib_descriptions = ralloc_array(mem_ctx, VkVertexInputAttributeDescription, src->vertexAttributeDescriptionCount); LVP_PIPELINE_DUP(dst->pVertexAttributeDescriptions,
if (!dst_attrib_descriptions) src->pVertexAttributeDescriptions,
return VK_ERROR_OUT_OF_HOST_MEMORY; VkVertexInputAttributeDescription,
src->vertexAttributeDescriptionCount);
for (i = 0; i < dst->vertexAttributeDescriptionCount; i++) {
memcpy(&dst_attrib_descriptions[i], &src->pVertexAttributeDescriptions[i], sizeof(VkVertexInputAttributeDescription));
}
dst->pVertexAttributeDescriptions = dst_attrib_descriptions;
return VK_SUCCESS; return VK_SUCCESS;
} }
@@ -175,28 +173,25 @@ deep_copy_viewport_state(void *mem_ctx,
VkPipelineViewportStateCreateInfo *dst, VkPipelineViewportStateCreateInfo *dst,
const VkPipelineViewportStateCreateInfo *src) const VkPipelineViewportStateCreateInfo *src)
{ {
int i;
VkViewport *viewports;
VkRect2D *scissors;
dst->sType = src->sType; dst->sType = src->sType;
dst->pNext = src->pNext; dst->pNext = src->pNext;
dst->flags = src->flags; dst->flags = src->flags;
if (src->pViewports) { if (src->pViewports) {
viewports = ralloc_array(mem_ctx, VkViewport, src->viewportCount); LVP_PIPELINE_DUP(dst->pViewports,
for (i = 0; i < src->viewportCount; i++) src->pViewports,
memcpy(&viewports[i], &src->pViewports[i], sizeof(VkViewport)); VkViewport,
dst->pViewports = viewports; src->viewportCount);
} else } else
dst->pViewports = NULL; dst->pViewports = NULL;
dst->viewportCount = src->viewportCount; dst->viewportCount = src->viewportCount;
if (src->pScissors) { if (src->pScissors) {
scissors = ralloc_array(mem_ctx, VkRect2D, src->scissorCount); LVP_PIPELINE_DUP(dst->pScissors,
for (i = 0; i < src->scissorCount; i++) src->pScissors,
memcpy(&scissors[i], &src->pScissors[i], sizeof(VkRect2D)); VkRect2D,
dst->pScissors = scissors; src->viewportCount);
} else } else
dst->pScissors = NULL; dst->pScissors = NULL;
dst->scissorCount = src->scissorCount; dst->scissorCount = src->scissorCount;
@@ -209,17 +204,17 @@ deep_copy_color_blend_state(void *mem_ctx,
VkPipelineColorBlendStateCreateInfo *dst, VkPipelineColorBlendStateCreateInfo *dst,
const VkPipelineColorBlendStateCreateInfo *src) const VkPipelineColorBlendStateCreateInfo *src)
{ {
VkPipelineColorBlendAttachmentState *attachments;
dst->sType = src->sType; dst->sType = src->sType;
dst->pNext = src->pNext; dst->pNext = src->pNext;
dst->flags = src->flags; dst->flags = src->flags;
dst->logicOpEnable = src->logicOpEnable; dst->logicOpEnable = src->logicOpEnable;
dst->logicOp = src->logicOp; dst->logicOp = src->logicOp;
attachments = ralloc_array(mem_ctx, VkPipelineColorBlendAttachmentState, src->attachmentCount); LVP_PIPELINE_DUP(dst->pAttachments,
memcpy(attachments, src->pAttachments, src->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState)); src->pAttachments,
VkPipelineColorBlendAttachmentState,
src->attachmentCount);
dst->attachmentCount = src->attachmentCount; dst->attachmentCount = src->attachmentCount;
dst->pAttachments = attachments;
memcpy(&dst->blendConstants, &src->blendConstants, sizeof(float) * 4); memcpy(&dst->blendConstants, &src->blendConstants, sizeof(float) * 4);
@@ -231,18 +226,15 @@ deep_copy_dynamic_state(void *mem_ctx,
VkPipelineDynamicStateCreateInfo *dst, VkPipelineDynamicStateCreateInfo *dst,
const VkPipelineDynamicStateCreateInfo *src) const VkPipelineDynamicStateCreateInfo *src)
{ {
VkDynamicState *dynamic_states;
dst->sType = src->sType; dst->sType = src->sType;
dst->pNext = src->pNext; dst->pNext = src->pNext;
dst->flags = src->flags; dst->flags = src->flags;
dynamic_states = ralloc_array(mem_ctx, VkDynamicState, src->dynamicStateCount); LVP_PIPELINE_DUP(dst->pDynamicStates,
if (!dynamic_states) src->pDynamicStates,
return VK_ERROR_OUT_OF_HOST_MEMORY; VkDynamicState,
src->dynamicStateCount);
memcpy(dynamic_states, src->pDynamicStates, src->dynamicStateCount * sizeof(VkDynamicState));
dst->dynamicStateCount = src->dynamicStateCount; dst->dynamicStateCount = src->dynamicStateCount;
dst->pDynamicStates = dynamic_states;
return VK_SUCCESS; return VK_SUCCESS;
} }
@@ -255,8 +247,6 @@ deep_copy_graphics_create_info(void *mem_ctx,
VkResult result; VkResult result;
VkPipelineShaderStageCreateInfo *stages; VkPipelineShaderStageCreateInfo *stages;
VkPipelineVertexInputStateCreateInfo *vertex_input; VkPipelineVertexInputStateCreateInfo *vertex_input;
VkPipelineInputAssemblyStateCreateInfo *input_assembly;
VkPipelineRasterizationStateCreateInfo* raster_state;
dst->sType = src->sType; dst->sType = src->sType;
dst->pNext = NULL; dst->pNext = NULL;
@@ -286,23 +276,19 @@ deep_copy_graphics_create_info(void *mem_ctx,
dst->pVertexInputState = vertex_input; dst->pVertexInputState = vertex_input;
/* pInputAssemblyState */ /* pInputAssemblyState */
input_assembly = ralloc(mem_ctx, VkPipelineInputAssemblyStateCreateInfo); LVP_PIPELINE_DUP(dst->pInputAssemblyState,
if (!input_assembly) src->pInputAssemblyState,
return VK_ERROR_OUT_OF_HOST_MEMORY; VkPipelineInputAssemblyStateCreateInfo,
memcpy(input_assembly, src->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo)); 1);
dst->pInputAssemblyState = input_assembly;
/* pTessellationState */ /* pTessellationState */
if (src->pTessellationState) { if (src->pTessellationState) {
VkPipelineTessellationStateCreateInfo *tess_state; LVP_PIPELINE_DUP(dst->pTessellationState,
tess_state = ralloc(mem_ctx, VkPipelineTessellationStateCreateInfo); src->pTessellationState,
if (!tess_state) VkPipelineTessellationStateCreateInfo,
return VK_ERROR_OUT_OF_HOST_MEMORY; 1);
memcpy(tess_state, src->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
dst->pTessellationState = tess_state;
} }
/* pViewportState */ /* pViewportState */
if (src->pViewportState) { if (src->pViewportState) {
VkPipelineViewportStateCreateInfo *viewport_state; VkPipelineViewportStateCreateInfo *viewport_state;
@@ -315,11 +301,10 @@ deep_copy_graphics_create_info(void *mem_ctx,
dst->pViewportState = NULL; dst->pViewportState = NULL;
/* pRasterizationState */ /* pRasterizationState */
raster_state = ralloc(mem_ctx, VkPipelineRasterizationStateCreateInfo); LVP_PIPELINE_DUP(dst->pRasterizationState,
if (!raster_state) src->pRasterizationState,
return VK_ERROR_OUT_OF_HOST_MEMORY; VkPipelineRasterizationStateCreateInfo,
memcpy(raster_state, src->pRasterizationState, sizeof(VkPipelineRasterizationStateCreateInfo)); 1);
dst->pRasterizationState = raster_state;
/* pMultisampleState */ /* pMultisampleState */
if (src->pMultisampleState) { if (src->pMultisampleState) {
@@ -340,13 +325,10 @@ deep_copy_graphics_create_info(void *mem_ctx,
/* pDepthStencilState */ /* pDepthStencilState */
if (src->pDepthStencilState) { if (src->pDepthStencilState) {
VkPipelineDepthStencilStateCreateInfo* ds_state; LVP_PIPELINE_DUP(dst->pDepthStencilState,
src->pDepthStencilState,
ds_state = ralloc(mem_ctx, VkPipelineDepthStencilStateCreateInfo); VkPipelineDepthStencilStateCreateInfo,
if (!ds_state) 1);
return VK_ERROR_OUT_OF_HOST_MEMORY;
memcpy(ds_state, src->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
dst->pDepthStencilState = ds_state;
} else } else
dst->pDepthStencilState = NULL; dst->pDepthStencilState = NULL;