From: Chad Versace Date: Thu, 10 Dec 2015 00:59:02 +0000 (-0800) Subject: anv: Remove anv_image::surface_type X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ee57062e1ec5d1d4666239c5a9c426982861f375;p=mesa.git anv: Remove anv_image::surface_type 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. --- diff --git a/src/vulkan/anv_image.c b/src/vulkan/anv_image.c index ffc7ae8cae6..3b3751ad1e1 100644 --- a/src/vulkan/anv_image.c +++ b/src/vulkan/anv_image.c @@ -34,12 +34,6 @@ */ #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; diff --git a/src/vulkan/anv_private.h b/src/vulkan/anv_private.h index 3b5a4be8355..07854d3e357 100644 --- a/src/vulkan/anv_private.h +++ b/src/vulkan/anv_private.h @@ -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; diff --git a/src/vulkan/gen7_state.c b/src/vulkan/gen7_state.c index 3206f77b831..321dc3f0f5d 100644 --- a/src/vulkan/gen7_state.c +++ b/src/vulkan/gen7_state.c @@ -32,6 +32,30 @@ #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], diff --git a/src/vulkan/gen8_state.c b/src/vulkan/gen8_state.c index ac1f17f48f9..0937677e8e4 100644 --- a/src/vulkan/gen8_state.c +++ b/src/vulkan/gen8_state.c @@ -32,6 +32,30 @@ #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,