vk: Assert on use of uninitialized surface state
authorKristian Høgsberg Kristensen <kristian.h.kristensen@intel.com>
Sat, 9 Jan 2016 07:43:20 +0000 (23:43 -0800)
committerKristian Høgsberg Kristensen <kristian.h.kristensen@intel.com>
Sat, 9 Jan 2016 07:51:11 +0000 (23:51 -0800)
This exposes a case where we want to anv_CmdCopyBufferToImage() on an
image that wasn't created with VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT and
end up using uninitialized color_rt_surface_state from the meta image
view.

src/vulkan/anv_cmd_buffer.c
src/vulkan/gen7_state.c
src/vulkan/gen8_state.c

index 5507400c84a2b3a3e957cd7d2b625c5cef34521d..d146f9ac46795ef9225e276c03d7fe04ec541716 100644 (file)
@@ -657,6 +657,7 @@ anv_cmd_buffer_emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
       const struct anv_image_view *iview =
          fb->attachments[subpass->color_attachments[a]];
 
+      assert(iview->color_rt_surface_state.alloc_size);
       bt_map[a] = iview->color_rt_surface_state.offset + state_offset;
       add_surface_state_reloc(cmd_buffer, iview->color_rt_surface_state,
                               iview->bo, iview->offset);
@@ -716,12 +717,14 @@ anv_cmd_buffer_emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
       case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
       case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
          surface_state = desc->image_view->nonrt_surface_state;
+         assert(surface_state.alloc_size);
          bo = desc->image_view->bo;
          bo_offset = desc->image_view->offset;
          break;
 
       case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: {
          surface_state = desc->image_view->storage_surface_state;
+         assert(surface_state.alloc_size);
          bo = desc->image_view->bo;
          bo_offset = desc->image_view->offset;
 
@@ -740,12 +743,14 @@ anv_cmd_buffer_emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
       case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
       case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
          surface_state = desc->buffer_view->surface_state;
+         assert(surface_state.alloc_size);
          bo = desc->buffer_view->bo;
          bo_offset = desc->buffer_view->offset;
          break;
 
       case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
          surface_state = desc->buffer_view->storage_surface_state;
+         assert(surface_state.alloc_size);
          bo = desc->buffer_view->bo;
          bo_offset = desc->buffer_view->offset;
 
index 257cb35aca901746a9195e0901a1a19dc8bb55bf..88598cea18e5943ccafc9e9176ab717fb558520b 100644 (file)
@@ -251,6 +251,8 @@ genX(image_view_init)(struct anv_image_view *iview,
 
       if (!device->info.has_llc)
          anv_state_clflush(iview->nonrt_surface_state);
+   } else {
+      iview->nonrt_surface_state.alloc_size = 0;
    }
 
    if (image->needs_color_rt_surface_state) {
@@ -271,6 +273,8 @@ genX(image_view_init)(struct anv_image_view *iview,
                                       &surface_state);
       if (!device->info.has_llc)
          anv_state_clflush(iview->color_rt_surface_state);
+   } else {
+      iview->color_rt_surface_state.alloc_size = 0;
    }
 
    if (image->needs_storage_surface_state) {
@@ -287,5 +291,7 @@ genX(image_view_init)(struct anv_image_view *iview,
 
       GENX(RENDER_SURFACE_STATE_pack)(NULL, iview->storage_surface_state.map,
                                       &surface_state);
+   } else {
+      iview->storage_surface_state.alloc_size = 0;
    }
 }
index c29d100f9f556e7e0d3f1ac1cab292bfdb55c55e..13b7e1149d98d25d5acc003c9905d72514368348 100644 (file)
@@ -310,6 +310,8 @@ genX(image_view_init)(struct anv_image_view *iview,
                                       &surface_state);
       if (!device->info.has_llc)
          anv_state_clflush(iview->nonrt_surface_state);
+   } else {
+      iview->nonrt_surface_state.alloc_size = 0;
    }
 
    if (image->needs_color_rt_surface_state) {
@@ -329,6 +331,8 @@ genX(image_view_init)(struct anv_image_view *iview,
                                       &surface_state);
       if (!device->info.has_llc)
          anv_state_clflush(iview->color_rt_surface_state);
+   } else {
+      iview->color_rt_surface_state.alloc_size = 0;
    }
 
    if (image->needs_storage_surface_state) {
@@ -346,6 +350,8 @@ genX(image_view_init)(struct anv_image_view *iview,
 
       GENX(RENDER_SURFACE_STATE_pack)(NULL, iview->storage_surface_state.map,
                                       &surface_state);
+   } else {
+      iview->storage_surface_state.alloc_size = 0;
    }
 }