anv: fix crash in vkCmdClearAttachments with unused attachment
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>
Mon, 15 Jul 2019 12:35:11 +0000 (15:35 +0300)
committerLionel Landwerlin <lionel.g.landwerlin@intel.com>
Mon, 15 Jul 2019 13:47:41 +0000 (16:47 +0300)
anv_render_pass_compile() turns an unused attachment into a NULL
depth_stencil_attachment pointer so check that pointer before
accessing it.

Found with updates to existing CTS tests.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Fixes: 208be8eafa30be ("anv: Make subpass::depth_stencil_attachment a pointer")
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Reviewed-by: Juan A. Suarez <jasuarez@igalia.com>
src/intel/vulkan/anv_blorp.c

index e4b1448c6cde55a355ffcbddbafdcef5c0fcbed8..5b7981bb49e806aea38ea4d08e21f8f6d1a1cc7e 100644 (file)
@@ -1158,11 +1158,11 @@ clear_depth_stencil_attachment(struct anv_cmd_buffer *cmd_buffer,
 {
    static const union isl_color_value color_value = { .u32 = { 0, } };
    const struct anv_subpass *subpass = cmd_buffer->state.subpass;
-   const uint32_t att_idx = subpass->depth_stencil_attachment->attachment;
-
-   if (att_idx == VK_ATTACHMENT_UNUSED)
+   if (!subpass->depth_stencil_attachment)
       return;
 
+   const uint32_t att_idx = subpass->depth_stencil_attachment->attachment;
+   assert(att_idx != VK_ATTACHMENT_UNUSED);
    struct anv_render_pass_attachment *pass_att =
       &cmd_buffer->state.pass->attachments[att_idx];