anv/pass: Avoid accessing attachment array out of bounds
authorNanley Chery <nanley.g.chery@intel.com>
Mon, 27 Feb 2017 18:23:33 +0000 (10:23 -0800)
committerNanley Chery <nanley.g.chery@intel.com>
Thu, 2 Mar 2017 21:17:54 +0000 (13:17 -0800)
Cc: <mesa-stable@lists.freedesktop.org>
Signed-off-by: Nanley Chery <nanley.g.chery@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/intel/vulkan/anv_pass.c

index 2df18260d3a2ee62e9e0530d57c36c9f1e84d4fe..a8b24703bcfbbe623167fdb22a85a7f41956cdae 100644 (file)
@@ -116,13 +116,15 @@ VkResult anv_CreateRenderPass(
          for (uint32_t j = 0; j < desc->inputAttachmentCount; j++) {
             uint32_t a = desc->pInputAttachments[j].attachment;
             subpass->input_attachments[j] = a;
-            pass->attachments[a].usage |= VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
-            pass->attachments[a].subpass_usage[i] |= ANV_SUBPASS_USAGE_INPUT;
-            pass->attachments[a].last_subpass_idx = i;
+            if (a != VK_ATTACHMENT_UNUSED) {
+               pass->attachments[a].usage |= VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
+               pass->attachments[a].subpass_usage[i] |= ANV_SUBPASS_USAGE_INPUT;
+               pass->attachments[a].last_subpass_idx = i;
 
-            if (desc->pDepthStencilAttachment &&
-                a == desc->pDepthStencilAttachment->attachment)
-               subpass->has_ds_self_dep = true;
+               if (desc->pDepthStencilAttachment &&
+                   a == desc->pDepthStencilAttachment->attachment)
+                  subpass->has_ds_self_dep = true;
+            }
          }
       }
 
@@ -133,9 +135,11 @@ VkResult anv_CreateRenderPass(
          for (uint32_t j = 0; j < desc->colorAttachmentCount; j++) {
             uint32_t a = desc->pColorAttachments[j].attachment;
             subpass->color_attachments[j] = a;
-            pass->attachments[a].usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
-            pass->attachments[a].subpass_usage[i] |= ANV_SUBPASS_USAGE_DRAW;
-            pass->attachments[a].last_subpass_idx = i;
+            if (a != VK_ATTACHMENT_UNUSED) {
+               pass->attachments[a].usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
+               pass->attachments[a].subpass_usage[i] |= ANV_SUBPASS_USAGE_DRAW;
+               pass->attachments[a].last_subpass_idx = i;
+            }
          }
       }