<p dir="ltr">Thanks for cleaning this up.  Series is</p>
<p dir="ltr">Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br>
Cc: "12.0" <<a href="mailto:mesa-stable@lists.freedesktop.org">mesa-stable@lists.freedesktop.org</a>><br>
</p>
<div class="gmail_quote">On Jun 10, 2016 8:02 PM, "Nanley Chery" <<a href="mailto:nanleychery@gmail.com">nanleychery@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;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. Asserts<br>
of pCreateInfo members are moved to the earliest points at which they<br>
should not be NULL.<br>
<br>
This fixes a segfault seen in the McNopper demo, VKTS_Example09.<br>
<br>
v3 (Jason Ekstrand):<br>
   - Fix disabled rasterization check<br>
   - Revert opaque detection of color attachment usage<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 | 70 ++++++++++++++++++++++++++++-------------<br>
 1 file changed, 48 insertions(+), 22 deletions(-)<br>
<br>
diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c<br>
index ae03787..60b7c6b 100644<br>
--- a/src/intel/vulkan/anv_pipeline.c<br>
+++ b/src/intel/vulkan/anv_pipeline.c<br>
@@ -979,18 +979,27 @@ 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>
-   }<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 (!pCreateInfo->pRasterizationState->rasterizerDiscardEnable) {<br>
+      assert(pCreateInfo->pViewportState);<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>
+      }<br>
<br>
-   dynamic->scissor.count = pCreateInfo->pViewportState->scissorCount;<br>
-   if (states & (1 << VK_DYNAMIC_STATE_SCISSOR)) {<br>
-      typed_memcpy(dynamic->scissor.scissors,<br>
-                   pCreateInfo->pViewportState->pScissors,<br>
-                   pCreateInfo->pViewportState->scissorCount);<br>
+      dynamic->scissor.count = pCreateInfo->pViewportState->scissorCount;<br>
+      if (states & (1 << VK_DYNAMIC_STATE_SCISSOR)) {<br>
+         typed_memcpy(dynamic->scissor.scissors,<br>
+                     pCreateInfo->pViewportState->pScissors,<br>
+                     pCreateInfo->pViewportState->scissorCount);<br>
+      }<br>
    }<br>
<br>
    if (states & (1 << VK_DYNAMIC_STATE_LINE_WIDTH)) {<br>
@@ -1008,10 +1017,27 @@ 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>
+   bool uses_color_att = false;<br>
+   for (unsigned i = 0; i < subpass->color_count; ++i) {<br>
+      if (subpass->color_attachments[i] != VK_ATTACHMENT_UNUSED) {<br>
+         uses_color_att = true;<br>
+         break;<br>
+      }<br>
+   }<br>
+<br>
+   if (uses_color_att &&<br>
+       !pCreateInfo->pRasterizationState->rasterizerDiscardEnable) {<br>
       assert(pCreateInfo->pColorBlendState);<br>
-      typed_memcpy(dynamic->blend_constants,<br>
-                   pCreateInfo->pColorBlendState->blendConstants, 4);<br>
+<br>
+      if (states & (1 << VK_DYNAMIC_STATE_BLEND_CONSTANTS))<br>
+         typed_memcpy(dynamic->blend_constants,<br>
+                     pCreateInfo->pColorBlendState->blendConstants, 4);<br>
    }<br>
<br>
    /* If there is no depthstencil attachment, then don't read<br>
@@ -1020,14 +1046,17 @@ 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 (!pCreateInfo->pRasterizationState->rasterizerDiscardEnable &&<br>
+       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 +1064,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 +1071,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 +1078,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>
--<br>
2.8.3<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</blockquote></div>