vk: Add anv_image::usage
authorChad Versace <chad.versace@intel.com>
Wed, 7 Oct 2015 01:17:09 +0000 (18:17 -0700)
committerChad Versace <chad.versace@intel.com>
Wed, 7 Oct 2015 04:22:18 +0000 (21:22 -0700)
It's a copy of VkImageCreateInfo::usage. Will be used for the
VkAttachmentView/VkImageView merge.

src/vulkan/anv_image.c
src/vulkan/anv_private.h
src/vulkan/gen7_state.c
src/vulkan/gen8_state.c

index 29a442daa43b56e7ee037b4eefa0a912bb3fca3c..b95cadca9e71cdc534d6e3a01f609168eee18057 100644 (file)
@@ -304,8 +304,21 @@ anv_image_create(VkDevice _device,
    image->format = anv_format_for_vk_format(pCreateInfo->format);
    image->levels = pCreateInfo->mipLevels;
    image->array_size = pCreateInfo->arraySize;
+   image->usage = pCreateInfo->usage;
    image->surf_type = surf_type;
 
+   if (pCreateInfo->usage & VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT) {
+      /* Meta will transfer from the image by binding it as a texture. */
+      image->usage |= VK_IMAGE_USAGE_SAMPLED_BIT;
+   }
+
+   if (pCreateInfo->usage & VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT) {
+      /* Meta will transfer to the image by binding it as a color attachment,
+       * even if the image format is not a color format.
+       */
+      image->usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
+   }
+
    if (likely(anv_format_is_color(image->format))) {
       r = anv_image_make_surface(create_info, image->format,
                                  &image->size, &image->alignment,
@@ -458,6 +471,11 @@ anv_image_view_init(struct anv_image_view *iview,
                     const VkImageViewCreateInfo* pCreateInfo,
                     struct anv_cmd_buffer *cmd_buffer)
 {
+   ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image);
+
+   assert(image->usage & (VK_IMAGE_USAGE_SAMPLED_BIT |
+                          VK_IMAGE_USAGE_STORAGE_BIT));
+
    switch (device->info.gen) {
    case 7:
       gen7_image_view_init(iview, device, pCreateInfo, cmd_buffer);
@@ -506,6 +524,8 @@ anv_depth_stencil_view_init(struct anv_image_view *iview,
 {
    ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image);
 
+   assert(image->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_BIT);
+
    iview->image = image;
    iview->format = anv_format_for_vk_format(pCreateInfo->format);
 
@@ -565,6 +585,10 @@ anv_color_attachment_view_init(struct anv_image_view *iview,
                                const VkAttachmentViewCreateInfo* pCreateInfo,
                                struct anv_cmd_buffer *cmd_buffer)
 {
+   ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image);
+
+   assert(image->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
+
    switch (device->info.gen) {
    case 7:
       gen7_color_attachment_view_init(iview, device, pCreateInfo, cmd_buffer);
index 3326625ebb30c62767e23b17a98ec75c062804ad..06ab1dc65a6c6aff9e5f0ca07f8eb88edc9749b6 100644 (file)
@@ -1202,6 +1202,7 @@ struct anv_image {
    VkExtent3D extent;
    uint32_t levels;
    uint32_t array_size;
+   VkImageUsageFlags usage; /**< VkImageCreateInfo::usage */
 
    VkDeviceSize size;
    uint32_t alignment;
index d7a4b10c6e869a4c55804fb68fdba666ab38e5c0..5829d03d3e3e7d285cc29e4c1b6ebe7ab2110513 100644 (file)
@@ -369,6 +369,7 @@ gen7_color_attachment_view_init(struct anv_image_view *iview,
    struct anv_surface *surface =
       anv_image_get_surface_for_color_attachment(image);
 
+   assert(image->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
    anv_assert(pCreateInfo->arraySize > 0);
    anv_assert(pCreateInfo->mipLevel < image->levels);
    anv_assert(pCreateInfo->baseArraySlice + pCreateInfo->arraySize <= image->array_size);
index e836613db4240f067bc214da7dead3c8e7c3824c..3c479e1c23ee31f3137a0f4e88741d769d2bb2c0 100644 (file)
@@ -295,6 +295,7 @@ gen8_color_attachment_view_init(struct anv_image_view *iview,
    uint32_t depth = 1; /* RENDER_SURFACE_STATE::Depth */
    uint32_t rt_view_extent = 1; /* RENDER_SURFACE_STATE::RenderTargetViewExtent */
 
+   assert(image->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
    anv_assert(pCreateInfo->arraySize > 0);
    anv_assert(pCreateInfo->mipLevel < image->levels);
    anv_assert(pCreateInfo->baseArraySlice + pCreateInfo->arraySize <= image->array_size);