anv: Remove anv_image::surface_type
authorChad Versace <chad.versace@intel.com>
Thu, 10 Dec 2015 00:59:02 +0000 (16:59 -0800)
committerChad Versace <chad.versace@intel.com>
Mon, 14 Dec 2015 18:46:27 +0000 (10:46 -0800)
When building RENDER_SURFACE_STATE, the driver set
SurfaceType = anv_image::surface_type, which was calculated during
anv_image_init(). This was bad because the value of
anv_image::surface_type was taken from a gen-specific header,
gen8_pack.h, even though the anv_image structure is used for all gens.

Replace anv_image::surface_type with a gen-specific lookup function,
anv_surftype(), defined in gen${x}_state.c.

The lookup function contains some useful asserts that caught some nasty
bugs in anv meta, which were fixed in the previous commit.

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

index ffc7ae8cae6ac3c3563b558265467a37cc9acb81..3b3751ad1e188da37c427067169fa4f3a76c45fc 100644 (file)
  */
 #include "gen8_pack.h"
 
-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,
-};
-
 /**
  * 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.
@@ -203,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)
@@ -219,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;
index 3b5a4be835593e5302be7e2911bb5e62d3fd7f61..07854d3e3579dddc64870171bd40925d9209e8c2 100644 (file)
@@ -1429,8 +1429,6 @@ struct anv_image {
    struct anv_bo *bo;
    VkDeviceSize offset;
 
-   uint8_t surface_type; /**< RENDER_SURFACE_STATE.SurfaceType */
-
    bool needs_nonrt_surface_state:1;
    bool needs_color_rt_surface_state:1;
    bool needs_storage_surface_state:1;
index 3206f77b8313be24409515d77b813264706cda27..321dc3f0f5d93bdee0326efe8f73cc54602d32c5 100644 (file)
 #include "gen7_pack.h"
 #include "gen75_pack.h"
 
+static const uint8_t
+anv_surftype(const struct anv_image *image, VkImageViewType view_type)
+{
+   switch (view_type) {
+   default:
+      unreachable("bad VkImageViewType");
+   case VK_IMAGE_VIEW_TYPE_1D:
+   case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
+      assert(image->type == VK_IMAGE_TYPE_1D);
+      return SURFTYPE_1D;
+   case VK_IMAGE_VIEW_TYPE_CUBE:
+   case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
+      anv_finishme("%s:%s: cube images", __FILE__, __func__);
+      /* fallthrough */
+   case VK_IMAGE_VIEW_TYPE_2D:
+   case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
+      assert(image->type == VK_IMAGE_TYPE_2D);
+      return SURFTYPE_2D;
+   case VK_IMAGE_VIEW_TYPE_3D:
+      assert(image->type == VK_IMAGE_TYPE_3D);
+      return SURFTYPE_3D;
+   }
+}
+
 GENX_FUNC(GEN7, GEN75) void
 genX(fill_buffer_surface_state)(void *state, const struct anv_format *format,
                                 uint32_t offset, uint32_t range,
@@ -242,7 +266,7 @@ genX(image_view_init)(struct anv_image_view *iview,
       isl_surf_get_image_alignment_sa(&surface->isl);
 
    struct GENX(RENDER_SURFACE_STATE) surface_state = {
-      .SurfaceType = image->surface_type,
+      .SurfaceType = anv_surftype(image, pCreateInfo->viewType),
       .SurfaceArray = image->array_size > 1,
       .SurfaceFormat = format->surface_format,
       .SurfaceVerticalAlignment = anv_valign[image_align_sa.height],
index ac1f17f48f915a86c050f58f4c8a0751b768d370..0937677e8e4d1f5468e00b475ea5912399ad0115 100644 (file)
 #include "gen8_pack.h"
 #include "gen9_pack.h"
 
+static const uint8_t
+anv_surftype(const struct anv_image *image, VkImageViewType view_type)
+{
+   switch (view_type) {
+   default:
+      unreachable("bad VkImageViewType");
+   case VK_IMAGE_VIEW_TYPE_1D:
+   case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
+      assert(image->type == VK_IMAGE_TYPE_1D);
+      return SURFTYPE_1D;
+   case VK_IMAGE_VIEW_TYPE_CUBE:
+   case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
+      anv_finishme("%s:%s: cube images", __FILE__, __func__);
+      /* fallthrough */
+   case VK_IMAGE_VIEW_TYPE_2D:
+   case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
+      assert(image->type == VK_IMAGE_TYPE_2D);
+      return SURFTYPE_2D;
+   case VK_IMAGE_VIEW_TYPE_3D:
+      assert(image->type == VK_IMAGE_TYPE_3D);
+      return SURFTYPE_3D;
+   }
+}
+
 void
 genX(fill_buffer_surface_state)(void *state, const struct anv_format *format,
                                 uint32_t offset, uint32_t range, uint32_t stride)
@@ -222,7 +246,7 @@ genX(image_view_init)(struct anv_image_view *iview,
    get_halign_valign(&surface->isl, &halign, &valign);
 
    struct GENX(RENDER_SURFACE_STATE) surface_state = {
-      .SurfaceType = image->surface_type,
+      .SurfaceType = anv_surftype(image, pCreateInfo->viewType),
       .SurfaceArray = image->array_size > 1,
       .SurfaceFormat = format_info->surface_format,
       .SurfaceVerticalAlignment = valign,