Commit a0a80b16 by Alexis Hetu Committed by Alexis Hétu

Prevent Pipeline crashing on missing non mandatory structures

When constructing a Graphics pipeline, some structures may or may not exist, depending on what will be used by the render pass. These structures (viewportState, multisampleState, depthStencilState and colorBlendState) are now checked before being used, since it is allowed for these to be null. Bug b/118386749 Change-Id: If2759ae2554a98143b30e70624a0dc8d88c5bd43 Reviewed-on: https://swiftshader-review.googlesource.com/c/24911Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarChris Forbes <chrisforbes@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent 0eba65b1
...@@ -267,15 +267,18 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateIn ...@@ -267,15 +267,18 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateIn
context.drawType = Convert(assemblyState->topology); context.drawType = Convert(assemblyState->topology);
const VkPipelineViewportStateCreateInfo* viewportState = pCreateInfo->pViewportState; const VkPipelineViewportStateCreateInfo* viewportState = pCreateInfo->pViewportState;
if((viewportState->flags != 0) || if(viewportState)
(viewportState->viewportCount != 1) ||
(viewportState->scissorCount != 1))
{ {
UNIMPLEMENTED(); if((viewportState->flags != 0) ||
} (viewportState->viewportCount != 1) ||
(viewportState->scissorCount != 1))
{
UNIMPLEMENTED();
}
scissor = Convert(viewportState->pScissors[0]); scissor = Convert(viewportState->pScissors[0]);
viewport = viewportState->pViewports[0]; viewport = viewportState->pViewports[0];
}
const VkPipelineRasterizationStateCreateInfo* rasterizationState = pCreateInfo->pRasterizationState; const VkPipelineRasterizationStateCreateInfo* rasterizationState = pCreateInfo->pRasterizationState;
if((rasterizationState->flags != 0) || if((rasterizationState->flags != 0) ||
...@@ -291,83 +294,92 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateIn ...@@ -291,83 +294,92 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateIn
context.slopeDepthBias = (rasterizationState->depthBiasEnable ? rasterizationState->depthBiasSlopeFactor : 0.0f); context.slopeDepthBias = (rasterizationState->depthBiasEnable ? rasterizationState->depthBiasSlopeFactor : 0.0f);
const VkPipelineMultisampleStateCreateInfo* multisampleState = pCreateInfo->pMultisampleState; const VkPipelineMultisampleStateCreateInfo* multisampleState = pCreateInfo->pMultisampleState;
if((multisampleState->flags != 0) || if(multisampleState)
(multisampleState->rasterizationSamples != VK_SAMPLE_COUNT_1_BIT) ||
(multisampleState->sampleShadingEnable != 0) ||
!((multisampleState->pSampleMask == nullptr) ||
(*(multisampleState->pSampleMask) == 0xFFFFFFFFu)) ||
(multisampleState->alphaToCoverageEnable != 0) ||
(multisampleState->alphaToOneEnable != 0))
{ {
UNIMPLEMENTED(); if((multisampleState->flags != 0) ||
(multisampleState->rasterizationSamples != VK_SAMPLE_COUNT_1_BIT) ||
(multisampleState->sampleShadingEnable != 0) ||
!((multisampleState->pSampleMask == nullptr) ||
(*(multisampleState->pSampleMask) == 0xFFFFFFFFu)) ||
(multisampleState->alphaToCoverageEnable != 0) ||
(multisampleState->alphaToOneEnable != 0))
{
UNIMPLEMENTED();
}
} }
const VkPipelineDepthStencilStateCreateInfo* depthStencilState = pCreateInfo->pDepthStencilState; const VkPipelineDepthStencilStateCreateInfo* depthStencilState = pCreateInfo->pDepthStencilState;
if((depthStencilState->flags != 0) || if(depthStencilState)
(depthStencilState->depthBoundsTestEnable != 0) ||
(depthStencilState->minDepthBounds != 0.0f) ||
(depthStencilState->maxDepthBounds != 1.0f))
{ {
UNIMPLEMENTED(); if((depthStencilState->flags != 0) ||
} (depthStencilState->depthBoundsTestEnable != 0) ||
(depthStencilState->minDepthBounds != 0.0f) ||
(depthStencilState->maxDepthBounds != 1.0f))
{
UNIMPLEMENTED();
}
context.depthBufferEnable = depthStencilState->depthTestEnable; context.depthBufferEnable = depthStencilState->depthTestEnable;
context.depthWriteEnable = depthStencilState->depthWriteEnable; context.depthWriteEnable = depthStencilState->depthWriteEnable;
context.depthCompareMode = depthStencilState->depthCompareOp; context.depthCompareMode = depthStencilState->depthCompareOp;
context.stencilEnable = context.twoSidedStencil = depthStencilState->stencilTestEnable; context.stencilEnable = context.twoSidedStencil = depthStencilState->stencilTestEnable;
if(context.stencilEnable) if(context.stencilEnable)
{ {
context.stencilMask = depthStencilState->front.compareMask; context.stencilMask = depthStencilState->front.compareMask;
context.stencilCompareMode = depthStencilState->front.compareOp; context.stencilCompareMode = depthStencilState->front.compareOp;
context.stencilZFailOperation = depthStencilState->front.depthFailOp; context.stencilZFailOperation = depthStencilState->front.depthFailOp;
context.stencilFailOperation = depthStencilState->front.failOp; context.stencilFailOperation = depthStencilState->front.failOp;
context.stencilPassOperation = depthStencilState->front.passOp; context.stencilPassOperation = depthStencilState->front.passOp;
context.stencilReference = depthStencilState->front.reference; context.stencilReference = depthStencilState->front.reference;
context.stencilWriteMask = depthStencilState->front.writeMask; context.stencilWriteMask = depthStencilState->front.writeMask;
context.stencilMaskCCW = depthStencilState->back.compareMask; context.stencilMaskCCW = depthStencilState->back.compareMask;
context.stencilCompareModeCCW = depthStencilState->back.compareOp; context.stencilCompareModeCCW = depthStencilState->back.compareOp;
context.stencilZFailOperationCCW = depthStencilState->back.depthFailOp; context.stencilZFailOperationCCW = depthStencilState->back.depthFailOp;
context.stencilFailOperationCCW = depthStencilState->back.failOp; context.stencilFailOperationCCW = depthStencilState->back.failOp;
context.stencilPassOperationCCW = depthStencilState->back.passOp; context.stencilPassOperationCCW = depthStencilState->back.passOp;
context.stencilReferenceCCW = depthStencilState->back.reference; context.stencilReferenceCCW = depthStencilState->back.reference;
context.stencilWriteMaskCCW = depthStencilState->back.writeMask; context.stencilWriteMaskCCW = depthStencilState->back.writeMask;
}
} }
const VkPipelineColorBlendStateCreateInfo* colorBlendState = pCreateInfo->pColorBlendState; const VkPipelineColorBlendStateCreateInfo* colorBlendState = pCreateInfo->pColorBlendState;
if((colorBlendState->flags != 0) || if(colorBlendState)
((colorBlendState->logicOpEnable != 0) &&
(colorBlendState->attachmentCount > 1)))
{
UNIMPLEMENTED();
}
context.colorLogicOpEnabled = colorBlendState->logicOpEnable;
context.logicalOperation = colorBlendState->logicOp;
blendConstants.r = colorBlendState->blendConstants[0];
blendConstants.g = colorBlendState->blendConstants[1];
blendConstants.b = colorBlendState->blendConstants[2];
blendConstants.a = colorBlendState->blendConstants[3];
if(colorBlendState->attachmentCount == 1)
{ {
const VkPipelineColorBlendAttachmentState& attachment = colorBlendState->pAttachments[0]; if((colorBlendState->flags != 0) ||
if(attachment.colorWriteMask != (VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT)) ((colorBlendState->logicOpEnable != 0) &&
(colorBlendState->attachmentCount > 1)))
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
} }
context.alphaBlendEnable = attachment.blendEnable; context.colorLogicOpEnabled = colorBlendState->logicOpEnable;
context.separateAlphaBlendEnable = (attachment.alphaBlendOp != attachment.colorBlendOp) || context.logicalOperation = colorBlendState->logicOp;
(attachment.dstAlphaBlendFactor != attachment.dstColorBlendFactor) || blendConstants.r = colorBlendState->blendConstants[0];
(attachment.srcAlphaBlendFactor != attachment.srcColorBlendFactor); blendConstants.g = colorBlendState->blendConstants[1];
context.blendOperationStateAlpha = attachment.alphaBlendOp; blendConstants.b = colorBlendState->blendConstants[2];
context.blendOperationState = attachment.colorBlendOp; blendConstants.a = colorBlendState->blendConstants[3];
context.destBlendFactorStateAlpha = attachment.dstAlphaBlendFactor;
context.destBlendFactorState = attachment.dstColorBlendFactor; if(colorBlendState->attachmentCount == 1)
context.sourceBlendFactorStateAlpha = attachment.srcAlphaBlendFactor; {
context.sourceBlendFactorState = attachment.srcColorBlendFactor; const VkPipelineColorBlendAttachmentState& attachment = colorBlendState->pAttachments[0];
if(attachment.colorWriteMask != (VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT))
{
UNIMPLEMENTED();
}
context.alphaBlendEnable = attachment.blendEnable;
context.separateAlphaBlendEnable = (attachment.alphaBlendOp != attachment.colorBlendOp) ||
(attachment.dstAlphaBlendFactor != attachment.dstColorBlendFactor) ||
(attachment.srcAlphaBlendFactor != attachment.srcColorBlendFactor);
context.blendOperationStateAlpha = attachment.alphaBlendOp;
context.blendOperationState = attachment.colorBlendOp;
context.destBlendFactorStateAlpha = attachment.dstAlphaBlendFactor;
context.destBlendFactorState = attachment.dstColorBlendFactor;
context.sourceBlendFactorStateAlpha = attachment.srcAlphaBlendFactor;
context.sourceBlendFactorState = attachment.srcColorBlendFactor;
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment