<div dir="ltr"><br><div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 10, 2016 at 4:12 PM, Nanley Chery <span dir="ltr"><<a href="mailto:nanleychery@gmail.com" target="_blank">nanleychery@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">From: Nanley Chery <<a href="mailto:nanley.g.chery@intel.com">nanley.g.chery@intel.com</a>><br>
<br>
Add guards to prevent dereferencing NULL dynamic pipeline state.<br>
<br>
This fixes a segfault seen in the McNopper demo, VKTS_Example09.<br>
<br>
Signed-off-by: Nanley Chery <<a href="mailto:nanley.g.chery@intel.com">nanley.g.chery@intel.com</a>><br>
Cc: "12.0" <<a href="mailto:mesa-stable@lists.freedesktop.org">mesa-stable@lists.freedesktop.org</a>><br>
---<br>
src/intel/vulkan/anv_pipeline.c | 51 ++++++++++++++++++++++++++++++-----------<br>
1 file changed, 37 insertions(+), 14 deletions(-)<br>
<br>
diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c<br>
index d5a3a21..4ce13eb 100644<br>
--- a/src/intel/vulkan/anv_pipeline.c<br>
+++ b/src/intel/vulkan/anv_pipeline.c<br>
@@ -979,11 +979,28 @@ copy_non_dynamic_state(struct anv_pipeline *pipeline,<br>
<br>
struct anv_dynamic_state *dynamic = &pipeline->dynamic_state;<br>
<br>
- dynamic->viewport.count = pCreateInfo->pViewportState->viewportCount;<br>
- if (states & (1 << VK_DYNAMIC_STATE_VIEWPORT)) {<br>
- typed_memcpy(dynamic->viewport.viewports,<br>
- pCreateInfo->pViewportState->pViewports,<br>
- pCreateInfo->pViewportState->viewportCount);<br>
+ bool fs_used = pipeline->active_stages & VK_SHADER_STAGE_FRAGMENT_BIT;<br>
+ bool color_att_used = false;<br>
+ for (unsigned i = 0; i < subpass->color_count; ++i) {<br>
+ if (subpass->color_attachments[i] != VK_ATTACHMENT_UNUSED) {<br>
+ color_att_used = true;<br>
+ break;<br>
+ }<br>
+ }<br>
+<br>
+ /* Section 9.2 of the Vulkan 1.0.15 spec says:<br>
+ *<br>
+ * pViewportState is [...] NULL if the pipeline<br>
+ * has rasterization disabled.<br>
+ */<br>
+ if (fs_used) {<br></blockquote><div><br></div><div>fs_used is not equivalent to rasterization being disabled. The only think I know of that can actually cause rasterization to be disabled is if you set rasterizerDiscardEnable. If you don't have a fragment shader they still get rastierized, but it's depth-only.<br><br></div><div>--Jason<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ assert(pCreateInfo->pViewportState);<br>
+ dynamic->viewport.count = pCreateInfo->pViewportState->viewportCount;<br>
+ if (states & (1 << VK_DYNAMIC_STATE_VIEWPORT)) {<br>
+ typed_memcpy(dynamic->viewport.viewports,<br>
+ pCreateInfo->pViewportState->pViewports,<br>
+ pCreateInfo->pViewportState->viewportCount);<br>
+ }<br>
}<br>
<br>
dynamic->scissor.count = pCreateInfo->pViewportState->scissorCount;<br>
@@ -1008,7 +1025,14 @@ copy_non_dynamic_state(struct anv_pipeline *pipeline,<br>
pCreateInfo->pRasterizationState->depthBiasSlopeFactor;<br>
}<br>
<br>
- if (states & (1 << VK_DYNAMIC_STATE_BLEND_CONSTANTS)) {<br>
+ /* Section 9.2 of the Vulkan 1.0.15 spec says:<br>
+ *<br>
+ * pColorBlendState is [...] NULL if the pipeline has rasterization<br>
+ * disabled or if the subpass of the render pass the pipeline is<br>
+ * created against does not use any color attachments.<br>
+ */<br>
+ if (fs_used && color_att_used &&<br>
+ states & (1 << VK_DYNAMIC_STATE_BLEND_CONSTANTS)) {<br>
assert(pCreateInfo->pColorBlendState);<br>
typed_memcpy(dynamic->blend_constants,<br>
pCreateInfo->pColorBlendState->blendConstants, 4);<br>
@@ -1020,14 +1044,16 @@ copy_non_dynamic_state(struct anv_pipeline *pipeline,<br>
* no need to override the depthstencil defaults in<br>
* anv_pipeline::dynamic_state when there is no depthstencil attachment.<br>
*<br>
- * From the Vulkan spec (20 Oct 2015, git-aa308cb):<br>
+ * Section 9.2 of the Vulkan 1.0.15 spec says:<br>
*<br>
- * pDepthStencilState [...] may only be NULL if renderPass and subpass<br>
- * specify a subpass that has no depth/stencil attachment.<br>
+ * pDepthStencilState is [...] NULL if the pipeline has rasterization<br>
+ * disabled or if the subpass of the render pass the pipeline is created<br>
+ * against does not use a depth/stencil attachment.<br>
*/<br>
- if (subpass->depth_stencil_attachment != VK_ATTACHMENT_UNUSED) {<br>
+ if (fs_used && subpass->depth_stencil_attachment != VK_ATTACHMENT_UNUSED) {<br>
+ assert(pCreateInfo->pDepthStencilState);<br>
+<br>
if (states & (1 << VK_DYNAMIC_STATE_DEPTH_BOUNDS)) {<br>
- assert(pCreateInfo->pDepthStencilState);<br>
dynamic->depth_bounds.min =<br>
pCreateInfo->pDepthStencilState->minDepthBounds;<br>
dynamic->depth_bounds.max =<br>
@@ -1035,7 +1061,6 @@ copy_non_dynamic_state(struct anv_pipeline *pipeline,<br>
}<br>
<br>
if (states & (1 << VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK)) {<br>
- assert(pCreateInfo->pDepthStencilState);<br>
dynamic->stencil_compare_mask.front =<br>
pCreateInfo->pDepthStencilState->front.compareMask;<br>
dynamic->stencil_compare_mask.back =<br>
@@ -1043,7 +1068,6 @@ copy_non_dynamic_state(struct anv_pipeline *pipeline,<br>
}<br>
<br>
if (states & (1 << VK_DYNAMIC_STATE_STENCIL_WRITE_MASK)) {<br>
- assert(pCreateInfo->pDepthStencilState);<br>
dynamic->stencil_write_mask.front =<br>
pCreateInfo->pDepthStencilState->front.writeMask;<br>
dynamic->stencil_write_mask.back =<br>
@@ -1051,7 +1075,6 @@ copy_non_dynamic_state(struct anv_pipeline *pipeline,<br>
}<br>
<br>
if (states & (1 << VK_DYNAMIC_STATE_STENCIL_REFERENCE)) {<br>
- assert(pCreateInfo->pDepthStencilState);<br>
dynamic->stencil_reference.front =<br>
pCreateInfo->pDepthStencilState->front.reference;<br>
dynamic->stencil_reference.back =<br>
<span class=""><font color="#888888">--<br>
2.8.3<br>
<br>
</font></span></blockquote></div><br></div></div></div>