turnip: preliminary support for tu_image_view_init
authorChia-I Wu <olvaffe@gmail.com>
Thu, 10 Jan 2019 19:58:07 +0000 (11:58 -0800)
committerChia-I Wu <olvaffe@gmail.com>
Mon, 11 Mar 2019 17:01:41 +0000 (10:01 -0700)
src/freedreno/vulkan/tu_image.c
src/freedreno/vulkan/tu_private.h

index 9a6930b0a9a41f304239d401fcc9ee6df0304a5d..af90b1ff310911e11ec29cb9d3b98b1e23afb483 100644 (file)
@@ -154,6 +154,8 @@ tu_image_create(VkDevice _device,
    image->usage = pCreateInfo->usage;
    image->flags = pCreateInfo->flags;
    image->extent = pCreateInfo->extent;
+   image->level_count = pCreateInfo->mipLevels;
+   image->layer_count = pCreateInfo->arrayLayers;
 
    image->exclusive = pCreateInfo->sharingMode == VK_SHARING_MODE_EXCLUSIVE;
    if (pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT) {
@@ -184,6 +186,41 @@ tu_image_view_init(struct tu_image_view *iview,
                    struct tu_device *device,
                    const VkImageViewCreateInfo *pCreateInfo)
 {
+   TU_FROM_HANDLE(tu_image, image, pCreateInfo->image);
+   const VkImageSubresourceRange *range = &pCreateInfo->subresourceRange;
+
+   switch (image->type) {
+   case VK_IMAGE_TYPE_1D:
+   case VK_IMAGE_TYPE_2D:
+      assert(range->baseArrayLayer + tu_get_layerCount(image, range) <=
+             image->layer_count);
+      break;
+   case VK_IMAGE_TYPE_3D:
+      assert(range->baseArrayLayer + tu_get_layerCount(image, range) <=
+             tu_minify(image->extent.depth, range->baseMipLevel));
+      break;
+   default:
+      unreachable("bad VkImageType");
+   }
+
+   iview->image = image;
+   iview->type = pCreateInfo->viewType;
+   iview->vk_format = pCreateInfo->format;
+   iview->aspect_mask = pCreateInfo->subresourceRange.aspectMask;
+
+   if (iview->aspect_mask == VK_IMAGE_ASPECT_STENCIL_BIT) {
+      iview->vk_format = vk_format_stencil_only(iview->vk_format);
+   } else if (iview->aspect_mask == VK_IMAGE_ASPECT_DEPTH_BIT) {
+      iview->vk_format = vk_format_depth_only(iview->vk_format);
+   }
+
+   // should we minify?
+   iview->extent = image->extent;
+
+   iview->base_layer = range->baseArrayLayer;
+   iview->layer_count = tu_get_layerCount(image, range);
+   iview->base_mip = range->baseMipLevel;
+   iview->level_count = tu_get_levelCount(image, range);
 }
 
 unsigned
index 4f593c9978fd4a5d320ea2e1448939193fed60be..5c4e9e814dfe6dfdbb0c7db6b0fd7d92d2c33ead 100644 (file)
@@ -941,6 +941,8 @@ struct tu_image
    VkImageTiling tiling;     /** VkImageCreateInfo::tiling */
    VkImageCreateFlags flags; /** VkImageCreateInfo::flags */
    VkExtent3D extent;
+   uint32_t level_count;
+   uint32_t layer_count;
 
    VkDeviceSize size;
    uint32_t alignment;
@@ -971,14 +973,18 @@ static inline uint32_t
 tu_get_layerCount(const struct tu_image *image,
                   const VkImageSubresourceRange *range)
 {
-   abort();
+   return range->layerCount == VK_REMAINING_ARRAY_LAYERS
+             ? image->layer_count - range->baseArrayLayer
+             : range->layerCount;
 }
 
 static inline uint32_t
 tu_get_levelCount(const struct tu_image *image,
                   const VkImageSubresourceRange *range)
 {
-   abort();
+   return range->levelCount == VK_REMAINING_MIP_LEVELS
+             ? image->level_count - range->baseMipLevel
+             : range->levelCount;
 }
 
 struct tu_image_view