vk: Assert on use of uninitialized surface state
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.
diff --git a/src/vulkan/anv_cmd_buffer.c b/src/vulkan/anv_cmd_buffer.c
index 5507400..d146f9a 100644
--- a/src/vulkan/anv_cmd_buffer.c
+++ b/src/vulkan/anv_cmd_buffer.c
@@ -657,6 +657,7 @@
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 @@
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 @@
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;
diff --git a/src/vulkan/gen7_state.c b/src/vulkan/gen7_state.c
index 257cb35..88598ce 100644
--- a/src/vulkan/gen7_state.c
+++ b/src/vulkan/gen7_state.c
@@ -251,6 +251,8 @@
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 @@
&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(RENDER_SURFACE_STATE_pack)(NULL, iview->storage_surface_state.map,
&surface_state);
+ } else {
+ iview->storage_surface_state.alloc_size = 0;
}
}
diff --git a/src/vulkan/gen8_state.c b/src/vulkan/gen8_state.c
index c29d100..13b7e11 100644
--- a/src/vulkan/gen8_state.c
+++ b/src/vulkan/gen8_state.c
@@ -310,6 +310,8 @@
&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 @@
&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(RENDER_SURFACE_STATE_pack)(NULL, iview->storage_surface_state.map,
&surface_state);
+ } else {
+ iview->storage_surface_state.alloc_size = 0;
}
}