anv: Fix parsing of load ops in VkAttachmentDescription
authorChad Versace <chad.versace@intel.com>
Thu, 29 Oct 2015 17:59:55 +0000 (10:59 -0700)
committerChad Versace <chad.versace@intel.com>
Thu, 29 Oct 2015 17:59:55 +0000 (10:59 -0700)
My original understanding of VkAttachmentDescription::loadOp,
stencilLoadOp was incorrect. Below are all possible combinations:

  VkFormat       | loadOp=clear   stencilLoadOp=clear
  ---------------+---------------------------
  color          | clear-color    ignored
  depth-only     | clear-depth    ignored
  stencil-only   | ignored        clear-stencil
  depth-stencil  | clear-depth    clear-stencil

src/vulkan/anv_device.c
src/vulkan/anv_meta.c

index d450b2b4e872f92b1d4082579a83be2c22e80877..05e723fe60d6ee0b382c7c1865c71efe5abf8fa3 100644 (file)
@@ -1894,15 +1894,21 @@ VkResult anv_CreateRenderPass(
       // att->store_op = pCreateInfo->pAttachments[i].storeOp;
       // att->stencil_store_op = pCreateInfo->pAttachments[i].stencilStoreOp;
 
-      if (att->load_op == VK_ATTACHMENT_LOAD_OP_CLEAR) {
-         if (anv_format_is_color(att->format)) {
+      if (anv_format_is_color(att->format)) {
+         if (att->load_op == VK_ATTACHMENT_LOAD_OP_CLEAR) {
             ++pass->num_color_clear_attachments;
-         } else if (att->format->depth_format) {
+         }
+      } else {
+         if (att->format->depth_format &&
+             att->load_op == VK_ATTACHMENT_LOAD_OP_CLEAR) {
             pass->has_depth_clear_attachment = true;
          }
-      } else if (att->stencil_load_op == VK_ATTACHMENT_LOAD_OP_CLEAR) {
-         assert(att->format->has_stencil);
-         pass->has_stencil_clear_attachment = true;
+
+         if (att->format->has_stencil &&
+             att->stencil_load_op == VK_ATTACHMENT_LOAD_OP_CLEAR) {
+            assert(att->format->has_stencil);
+            pass->has_stencil_clear_attachment = true;
+         }
       }
    }
 
index 8bfab1f8323c3d8482aadcffd3b2334be2d8cb82..cc605197f9b12074dd6db2ba95d9e02dc86c6c32 100644 (file)
@@ -446,8 +446,8 @@ anv_cmd_buffer_clear_attachments(struct anv_cmd_buffer *cmd_buffer,
    for (uint32_t i = 0; i < pass->attachment_count; i++) {
       const struct anv_render_pass_attachment *att = &pass->attachments[i];
 
-      if (att->load_op == VK_ATTACHMENT_LOAD_OP_CLEAR) {
-         if (anv_format_is_color(att->format)) {
+      if (anv_format_is_color(att->format)) {
+         if (att->load_op == VK_ATTACHMENT_LOAD_OP_CLEAR) {
             instance_data[layer] = (struct clear_instance_data) {
                .vue_header = {
                   .RTAIndex = i,
@@ -458,14 +458,19 @@ anv_cmd_buffer_clear_attachments(struct anv_cmd_buffer *cmd_buffer,
             };
             color_attachments[layer] = i;
             layer++;
-         } else if (att->format->depth_format) {
+         }
+      } else {
+         if (att->format->depth_format &&
+             att->load_op == VK_ATTACHMENT_LOAD_OP_CLEAR) {
             assert(ds_attachment == VK_ATTACHMENT_UNUSED);
             ds_attachment = i;
             ds_clear_value = clear_values[ds_attachment].depthStencil;
          }
-      } else if (att->stencil_load_op == VK_ATTACHMENT_LOAD_OP_CLEAR) {
-         assert(att->format->has_stencil);
-         anv_finishme("stencil clear");
+
+         if (att->format->has_stencil &&
+             att->stencil_load_op == VK_ATTACHMENT_LOAD_OP_CLEAR) {
+            anv_finishme("stencil clear");
+         }
       }
    }