anv: Add initial support for cube maps
[mesa.git] / src / vulkan / anv_image.c
index 09993180e7ec2431e441e909bdd61b1234344776..dcad2affb2c497cd10dfab9680c05c5eed2ea9bf 100644 (file)
  */
 #include "gen8_pack.h"
 
-static const uint8_t anv_halign[] = {
-    [4] = HALIGN4,
-    [8] = HALIGN8,
-    [16] = HALIGN16,
-};
-
-static const uint8_t anv_valign[] = {
-    [4] = VALIGN4,
-    [8] = VALIGN8,
-    [16] = VALIGN16,
-};
-
-static const uint8_t anv_surf_type_from_image_type[] = {
-   [VK_IMAGE_TYPE_1D] = SURFTYPE_1D,
-   [VK_IMAGE_TYPE_2D] = SURFTYPE_2D,
-   [VK_IMAGE_TYPE_3D] = SURFTYPE_3D,
-};
-
-static const struct anv_image_view_info
-anv_image_view_info_table[] = {
-   #define INFO(s, ...) { .surface_type = s, __VA_ARGS__ }
-   [VK_IMAGE_VIEW_TYPE_1D]          = INFO(SURFTYPE_1D),
-   [VK_IMAGE_VIEW_TYPE_2D]          = INFO(SURFTYPE_2D),
-   [VK_IMAGE_VIEW_TYPE_3D]          = INFO(SURFTYPE_3D),
-   [VK_IMAGE_VIEW_TYPE_CUBE]        = INFO(SURFTYPE_CUBE,                  .is_cube = 1),
-   [VK_IMAGE_VIEW_TYPE_1D_ARRAY]    = INFO(SURFTYPE_1D,     .is_array = 1),
-   [VK_IMAGE_VIEW_TYPE_2D_ARRAY]    = INFO(SURFTYPE_2D,     .is_array = 1),
-   [VK_IMAGE_VIEW_TYPE_CUBE_ARRAY]  = INFO(SURFTYPE_CUBE,   .is_array = 1, .is_cube = 1),
-   #undef INFO
-};
-
-struct anv_image_view_info
-anv_image_view_info_for_vk_image_view_type(VkImageViewType type)
-{
-   return anv_image_view_info_table[type];
-}
-
 /**
  * The \a format argument is required and overrides any format found in struct
  * anv_image_create_info. Exactly one bit must be set in \a aspect.
@@ -234,10 +197,6 @@ anv_image_create(VkDevice _device,
    anv_assert(pCreateInfo->extent.height > 0);
    anv_assert(pCreateInfo->extent.depth > 0);
 
-   /* TODO(chadv): How should we validate inputs? */
-   const uint8_t surf_type =
-      anv_surf_type_from_image_type[pCreateInfo->imageType];
-
    image = anv_alloc2(&device->alloc, alloc, sizeof(*image), 8,
                       VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (!image)
@@ -250,7 +209,6 @@ anv_image_create(VkDevice _device,
    image->levels = pCreateInfo->mipLevels;
    image->array_size = pCreateInfo->arrayLayers;
    image->usage = anv_image_get_full_usage(pCreateInfo);
-   image->surface_type = surf_type;
 
    if (image->usage & VK_IMAGE_USAGE_SAMPLED_BIT) {
       image->needs_nonrt_surface_state = true;
@@ -374,7 +332,6 @@ anv_validate_CreateImageView(VkDevice _device,
 {
    ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image);
    const VkImageSubresourceRange *subresource;
-   const struct anv_image_view_info *view_info;
    const struct anv_format *view_format_info;
 
    /* Validate structure type before dereferencing it. */
@@ -385,7 +342,6 @@ anv_validate_CreateImageView(VkDevice _device,
    /* Validate viewType is in range before using it. */
    assert(pCreateInfo->viewType >= VK_IMAGE_VIEW_TYPE_BEGIN_RANGE);
    assert(pCreateInfo->viewType <= VK_IMAGE_VIEW_TYPE_END_RANGE);
-   view_info = &anv_image_view_info_table[pCreateInfo->viewType];
 
    /* Validate format is in range before using it. */
    assert(pCreateInfo->format >= VK_FORMAT_BEGIN_RANGE);
@@ -412,11 +368,6 @@ anv_validate_CreateImageView(VkDevice _device,
    assert(subresource->baseArrayLayer + subresource->layerCount <= image->array_size);
    assert(pView);
 
-   if (view_info->is_cube) {
-      assert(subresource->baseArrayLayer % 6 == 0);
-      assert(subresource->layerCount % 6 == 0);
-   }
-
    const VkImageAspectFlags ds_flags = VK_IMAGE_ASPECT_DEPTH_BIT
                                      | VK_IMAGE_ASPECT_STENCIL_BIT;
 
@@ -544,6 +495,52 @@ anv_DestroyImageView(VkDevice _device, VkImageView _iview,
    anv_free2(&device->alloc, pAllocator, iview);
 }
 
+VkResult
+anv_CreateBufferView(VkDevice _device,
+                     const VkBufferViewCreateInfo *pCreateInfo,
+                     const VkAllocationCallbacks *pAllocator,
+                     VkBufferView *pView)
+{
+   ANV_FROM_HANDLE(anv_device, device, _device);
+   ANV_FROM_HANDLE(anv_buffer, buffer, pCreateInfo->buffer);
+   struct anv_buffer_view *view;
+
+   /* TODO: Storage texel buffers */
+
+   view = anv_alloc2(&device->alloc, pAllocator, sizeof(*view), 8,
+                     VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+   if (!view)
+      return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
+
+   view->bo = buffer->bo;
+   view->offset = buffer->offset + pCreateInfo->offset;
+
+   view->surface_state =
+      anv_state_pool_alloc(&device->surface_state_pool, 64, 64);
+
+   const struct anv_format *format =
+      anv_format_for_vk_format(pCreateInfo->format);
+
+   anv_fill_buffer_surface_state(device, view->surface_state.map, format,
+                                 view->offset, pCreateInfo->range,
+                                 format->isl_layout->bpb / 8);
+
+   *pView = anv_buffer_view_to_handle(view);
+
+   return VK_SUCCESS;
+}
+
+void
+anv_DestroyBufferView(VkDevice _device, VkBufferView bufferView,
+                      const VkAllocationCallbacks *pAllocator)
+{
+   ANV_FROM_HANDLE(anv_device, device, _device);
+   ANV_FROM_HANDLE(anv_buffer_view, view, bufferView);
+
+   anv_state_pool_free(&device->surface_state_pool, view->surface_state);
+   anv_free2(&device->alloc, pAllocator, view);
+}
+
 struct anv_surface *
 anv_image_get_surface_for_aspect_mask(struct anv_image *image, VkImageAspectFlags aspect_mask)
 {
@@ -592,3 +589,12 @@ anv_image_get_surface_for_aspect_mask(struct anv_image *image, VkImageAspectFlag
        return NULL;
    }
 }
+
+void
+anv_image_view_fill_image_param(struct anv_device *device,
+                                struct anv_image_view *view,
+                                struct brw_image_param *param)
+{
+   memset(param, 0, sizeof *param);
+   anv_finishme("Actually fill out brw_image_param");
+}