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.
This commit is contained in:
Chad Versace 2015-12-09 16:59:02 -08:00
parent f0d11d5a81
commit ee57062e1e
4 changed files with 50 additions and 15 deletions

View file

@ -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;

View 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;

View file

@ -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],

View file

@ -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,