anv: Use enum isl_tiling everywhere
authorChad Versace <chad.versace@intel.com>
Fri, 13 Nov 2015 18:24:57 +0000 (10:24 -0800)
committerChad Versace <chad.versace@intel.com>
Fri, 13 Nov 2015 18:44:09 +0000 (10:44 -0800)
In anv_surface and anv_image_create_info, replace member
'uint8_t tile_mode' with 'enum isl_tiling'.

As a nice side-effect, this patch also reduces bug potential because the
hardware enum values for tile modes are unstable across hardware
generations.

src/vulkan/anv_image.c
src/vulkan/anv_intel.c
src/vulkan/anv_private.h
src/vulkan/anv_wsi_wayland.c
src/vulkan/anv_wsi_x11.c
src/vulkan/gen7_state.c
src/vulkan/gen8_state.c

index ecd34e3ab5b2f364aece01ed4e1f65b3458dd978..e90257e8faaf216dc7c4cfdddeaf9ab6aa592fbd 100644 (file)
@@ -80,9 +80,6 @@ static const struct anv_surf_type_limits {
 };
 
 static const struct anv_tile_info {
-   uint32_t width;
-   uint32_t height;
-
    /**
     * Alignment for RENDER_SURFACE_STATE.SurfaceBaseAddress.
     *
@@ -96,17 +93,19 @@ static const struct anv_tile_info {
     */
    uint32_t surface_alignment;
 } anv_tile_info_table[] = {
-   [LINEAR] = {   1,  1,   64 },
-   [XMAJOR] = { 512,  8, 4096 },
-   [YMAJOR] = { 128, 32, 4096 },
-   [WMAJOR] = { 128, 32, 4096 },
+   [ISL_TILING_LINEAR]  = {   64 },
+   [ISL_TILING_X]       = { 4096 },
+   [ISL_TILING_Y]       = { 4096 },
+   [ISL_TILING_Yf]      = { 4096 },
+   [ISL_TILING_Ys]      = { 4096 },
+   [ISL_TILING_W]       = { 4096 },
 };
 
-static uint8_t
-anv_image_choose_tile_mode(const struct anv_image_create_info *anv_info)
+static enum isl_tiling
+anv_image_choose_tiling(const struct anv_image_create_info *anv_info)
 {
-   if (anv_info->force_tile_mode)
-      return anv_info->tile_mode;
+   if (anv_info->force_tiling)
+      return anv_info->tiling;
 
    /* The Sandybridge PRM says that the stencil buffer "is supported
     * only in Tile W memory".
@@ -115,16 +114,16 @@ anv_image_choose_tile_mode(const struct anv_image_create_info *anv_info)
    switch (anv_info->vk_info->tiling) {
    case VK_IMAGE_TILING_LINEAR:
       assert(anv_info->vk_info->format != VK_FORMAT_S8_UINT);
-      return LINEAR;
+      return ISL_TILING_LINEAR;
    case VK_IMAGE_TILING_OPTIMAL:
       if (unlikely(anv_info->vk_info->format == VK_FORMAT_S8_UINT)) {
-         return WMAJOR;
+         return ISL_TILING_W;
       } else {
-         return YMAJOR;
+         return ISL_TILING_Y;
       }
    default:
       assert(!"bad VKImageTiling");
-      return LINEAR;
+      return ISL_TILING_LINEAR;
    }
 }
 
@@ -134,7 +133,8 @@ anv_image_choose_tile_mode(const struct anv_image_create_info *anv_info)
  * struct anv_image_create_info.
  */
 static VkResult
-anv_image_make_surface(const struct anv_image_create_info *create_info,
+anv_image_make_surface(const struct anv_device *dev,
+                       const struct anv_image_create_info *create_info,
                        const struct anv_format *format,
                        uint64_t *inout_image_size,
                        uint32_t *inout_image_alignment,
@@ -147,15 +147,18 @@ anv_image_make_surface(const struct anv_image_create_info *create_info,
    const VkExtent3D *restrict extent = &create_info->vk_info->extent;
    const uint32_t levels = create_info->vk_info->mipLevels;
    const uint32_t array_size = create_info->vk_info->arraySize;
-   const uint8_t tile_mode = anv_image_choose_tile_mode(create_info);
+   const enum isl_tiling tiling = anv_image_choose_tiling(create_info);
 
    const struct anv_tile_info *tile_info =
-       &anv_tile_info_table[tile_mode];
+       &anv_tile_info_table[tiling];
 
    const uint32_t bs = format->isl_layout->bs;
    const uint32_t bw = format->isl_layout->bw;
    const uint32_t bh = format->isl_layout->bh;
 
+   struct isl_extent2d tile_extent;
+   isl_tiling_get_extent(&dev->isl_dev, tiling, bs, &tile_extent);
+
    const uint32_t i = MAX(4, bw); /* FINISHME: Stop hardcoding subimage alignment */
    const uint32_t j = MAX(4, bh); /* FINISHME: Stop hardcoding subimage alignment */
    assert(i == 4 || i == 8 || i == 16);
@@ -232,7 +235,7 @@ anv_image_make_surface(const struct anv_image_create_info *create_info,
     */
    assert(anv_is_aligned(qpitch, j));
 
-   uint32_t stride = align_u32(mt_width * bs / bw, tile_info->width);
+   uint32_t stride = align_u32(mt_width * bs / bw, tile_extent.width);
    if (create_info->stride > 0)
       stride = create_info->stride;
 
@@ -241,7 +244,7 @@ anv_image_make_surface(const struct anv_image_create_info *create_info,
    * Sampling Engine Surfaces >> Buffer Padding Requirements:
    */
    const uint32_t mem_rows = align_u32(mt_height / bh, 2 * bh);
-   const uint32_t size = stride * align_u32(mem_rows, tile_info->height);
+   const uint32_t size = stride * align_u32(mem_rows, tile_extent.height);
    const uint32_t offset = align_u32(*inout_image_size,
                                      tile_info->surface_alignment);
 
@@ -252,7 +255,7 @@ anv_image_make_surface(const struct anv_image_create_info *create_info,
    *out_surface = (struct anv_surface) {
       .offset = offset,
       .stride = stride,
-      .tile_mode = tile_mode,
+      .tiling = tiling,
       .qpitch = qpitch,
       .h_align = i,
       .v_align = j,
@@ -337,14 +340,14 @@ anv_image_create(VkDevice _device,
    }
 
    if (likely(anv_format_is_color(image->format))) {
-      r = anv_image_make_surface(create_info, image->format,
+      r = anv_image_make_surface(device, create_info, image->format,
                                  &image->size, &image->alignment,
                                  &image->color_surface);
       if (r != VK_SUCCESS)
          goto fail;
    } else {
       if (image->format->depth_format) {
-         r = anv_image_make_surface(create_info, image->format,
+         r = anv_image_make_surface(device, create_info, image->format,
                                     &image->size, &image->alignment,
                                     &image->depth_surface);
          if (r != VK_SUCCESS)
@@ -352,7 +355,7 @@ anv_image_create(VkDevice _device,
       }
 
       if (image->format->has_stencil) {
-         r = anv_image_make_surface(create_info, anv_format_s8_uint,
+         r = anv_image_make_surface(device, create_info, anv_format_s8_uint,
                                     &image->size, &image->alignment,
                                     &image->stencil_surface);
          if (r != VK_SUCCESS)
index f64e2dcb1e4d4c96d543ad3bd71e90eb39f6ef49..48ac183ad79b286401b775d7fd010d68f9af652e 100644 (file)
@@ -68,8 +68,8 @@ VkResult anv_CreateDmaBufImageINTEL(
 
    anv_image_create(_device,
       &(struct anv_image_create_info) {
-         .force_tile_mode = true,
-         .tile_mode = XMAJOR,
+         .force_tiling = true,
+         .tiling = ISL_TILING_X,
          .stride = pCreateInfo->strideInBytes,
          .vk_info =
       &(VkImageCreateInfo) {
index 8269c7e85094dcf425cf5452c18b21c977272412..a6728392130baa255114e50e7a181fab5b031f26 100644 (file)
@@ -1272,7 +1272,7 @@ struct anv_surface {
    uint8_t v_align; /**< RENDER_SURFACE_STATE.SurfaceVerticalAlignment */
    /** \} */
 
-   uint8_t tile_mode; /**< RENDER_SURFACE_STATE.TileMode */
+   enum isl_tiling tiling;
 };
 
 struct anv_image {
@@ -1333,8 +1333,8 @@ struct anv_image_view {
 
 struct anv_image_create_info {
    const VkImageCreateInfo *vk_info;
-   bool force_tile_mode;
-   uint8_t tile_mode;
+   bool force_tiling;
+   enum isl_tiling tiling;
    uint32_t stride;
 };
 
index d3d73b8ae2d1fd3977057175b2f400963ab33076..f32fda20c095eff58cb0a20ffc3c945fe6f46e4d 100644 (file)
@@ -547,8 +547,8 @@ wsi_wl_image_init(struct wsi_wl_swapchain *chain, struct wsi_wl_image *image)
    VkImage vk_image;
    result = anv_image_create(vk_device,
       &(struct anv_image_create_info) {
-         .force_tile_mode = true,
-         .tile_mode = XMAJOR,
+         .force_tiling = true,
+         .tiling = ISL_TILING_X,
          .stride = 0,
          .vk_info =
       &(VkImageCreateInfo) {
index 38a5e15d1a67b347a8244b58776b6f4704a24c7a..9a5e41d025a1bfddb5767df54d756ab7463243cc 100644 (file)
@@ -299,8 +299,8 @@ x11_create_swapchain(struct anv_wsi_implementation *impl,
 
       anv_image_create(anv_device_to_handle(device),
          &(struct anv_image_create_info) {
-            .force_tile_mode = true,
-            .tile_mode = XMAJOR,
+            .force_tiling = true,
+            .tiling = ISL_TILING_X,
             .stride = 0,
             .vk_info =
          &(VkImageCreateInfo) {
index 6f1cb8553e99fb247c182a1408e41ba083a9c2ba..a53b6e3faf355887eabd52eb19a390895c1ae49b 100644 (file)
@@ -219,8 +219,9 @@ gen7_image_view_init(struct anv_image_view *iview,
       /* From bspec (DevSNB, DevIVB): "Set Tile Walk to TILEWALK_XMAJOR if
        * Tiled Surface is False."
        */
-      .TiledSurface = surface->tile_mode > LINEAR,
-      .TileWalk = surface->tile_mode == YMAJOR ? TILEWALK_YMAJOR : TILEWALK_XMAJOR,
+      .TiledSurface = surface->tiling != ISL_TILING_LINEAR,
+      .TileWalk = surface->tiling == ISL_TILING_Y ?
+                  TILEWALK_YMAJOR : TILEWALK_XMAJOR,
 
       .VerticalLineStride = 0,
       .VerticalLineStrideOffset = 0,
index ce69377fd77d07ecce2ce5d74c0d8dc90975357d..22fe21db1a8db3f96c189c9262653a3887b26cfa 100644 (file)
@@ -162,13 +162,22 @@ gen8_image_view_init(struct anv_image_view *iview,
       [VK_CHANNEL_SWIZZLE_A]                    = SCS_ALPHA
    };
 
+   static const uint8_t isl_to_gen_tiling[] = {
+      [ISL_TILING_LINEAR]  = LINEAR,
+      [ISL_TILING_X]       = XMAJOR,
+      [ISL_TILING_Y]       = YMAJOR,
+      [ISL_TILING_Yf]      = YMAJOR,
+      [ISL_TILING_Ys]      = YMAJOR,
+      [ISL_TILING_W]       = WMAJOR,
+   };
+
    struct GEN8_RENDER_SURFACE_STATE surface_state = {
       .SurfaceType = image->surface_type,
       .SurfaceArray = image->array_size > 1,
       .SurfaceFormat = format_info->surface_format,
       .SurfaceVerticalAlignment = anv_valign[surface->v_align],
       .SurfaceHorizontalAlignment = anv_halign[surface->h_align],
-      .TileMode = surface->tile_mode,
+      .TileMode = isl_to_gen_tiling[surface->tiling],
       .VerticalLineStride = 0,
       .VerticalLineStrideOffset = 0,
       .SamplerL2BypassModeDisable = true,