anv: Embed isl_surf into anv_surface
authorChad Versace <chad.versace@intel.com>
Thu, 3 Dec 2015 16:40:47 +0000 (08:40 -0800)
committerChad Versace <chad.versace@intel.com>
Thu, 3 Dec 2015 23:31:00 +0000 (15:31 -0800)
This reduces struct anv_surface to just two members: an offset and the
embedded isl_surf.

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

index 69103209022bc8e6707eae41a47eeb6bda2fbd79..f99155cad6ac20dc8efaaa0fb280edef4e7b816a 100644 (file)
@@ -147,7 +147,7 @@ anv_image_make_surface(const struct anv_device *dev,
                        const struct anv_format *format,
                        uint64_t *inout_image_size,
                        uint32_t *inout_image_alignment,
-                       struct anv_surface *out_surface)
+                       struct anv_surface *out_anv_surf)
 {
    const VkImageCreateInfo *vk_info = anv_info->vk_info;
 
@@ -157,8 +157,7 @@ anv_image_make_surface(const struct anv_device *dev,
       [VK_IMAGE_TYPE_3D] = ISL_SURF_DIM_3D,
    };
 
-   struct isl_surf isl_surf;
-   isl_surf_init(&dev->isl_dev, &isl_surf,
+   isl_surf_init(&dev->isl_dev, &out_anv_surf->isl,
       .dim = vk_to_isl_surf_dim[vk_info->imageType],
       .format = format->surface_format,
       .width = vk_info->extent.width,
@@ -172,17 +171,12 @@ anv_image_make_surface(const struct anv_device *dev,
       .usage = choose_isl_surf_usage(anv_info, format),
       .tiling_flags = choose_isl_tiling_flags(anv_info));
 
-   *out_surface = (struct anv_surface) {
-      .offset = align_u32(*inout_image_size, isl_surf.alignment),
-      .stride = isl_surf.row_pitch,
-      .tiling = isl_surf.tiling,
-      .qpitch = isl_surf_get_array_pitch_sa_rows(&isl_surf),
-      .h_align = isl_surf_get_lod_alignment_sa(&isl_surf).width,
-      .v_align = isl_surf_get_lod_alignment_sa(&isl_surf).height,
-   };
+   out_anv_surf->offset = align_u32(*inout_image_size,
+                                    out_anv_surf->isl.alignment);
 
-   *inout_image_size = out_surface->offset + isl_surf.size;
-   *inout_image_alignment = MAX(*inout_image_alignment, isl_surf.alignment);
+   *inout_image_size = out_anv_surf->offset + out_anv_surf->isl.size;
+   *inout_image_alignment = MAX(*inout_image_alignment,
+                                out_anv_surf->isl.alignment);
 
    return VK_SUCCESS;
 }
@@ -325,16 +319,9 @@ anv_surface_get_subresource_layout(struct anv_image *image,
    anv_assert(subresource->arrayLayer == 0);
 
    layout->offset = surface->offset;
-   layout->rowPitch = surface->stride;
-
-   /* Anvil's qpitch is in units of rows. Vulkan's depthPitch is in bytes. */
-   layout->depthPitch = surface->qpitch * surface->stride;
-
-   /* FINISHME: We really shouldn't be doing this calculation here */
-   if (image->array_size > 1)
-      layout->size = surface->qpitch * image->array_size;
-   else
-      layout->size = surface->stride * image->extent.height;
+   layout->rowPitch = surface->isl.row_pitch;
+   layout->depthPitch = isl_surf_get_array_pitch(&surface->isl);
+   layout->size = surface->isl.size;
 }
 
 void anv_GetImageSubresourceLayout(
index 43ebf4c11aef4d5e00c6d894496f6cf9fab86833..3fc305ba15e354f1903a3fc75016f4bba0b9301c 100644 (file)
@@ -1372,30 +1372,15 @@ struct anv_image_view_info
 anv_image_view_info_for_vk_image_view_type(VkImageViewType type);
 
 /**
- * A proxy for the color surfaces, depth surfaces, and stencil surfaces.
+ * Subsurface of an anv_image.
  */
 struct anv_surface {
+   struct isl_surf isl;
+
    /**
     * Offset from VkImage's base address, as bound by vkBindImageMemory().
     */
    uint32_t offset;
-
-   uint32_t stride; /**< RENDER_SURFACE_STATE.SurfacePitch */
-   uint16_t qpitch; /**< RENDER_SURFACE_STATE.QPitch */
-
-   /**
-    * \name Alignment of miptree images, in units of pixels.
-    *
-    * These fields contain the real alignment values, not the values to be
-    * given to the GPU.  For example, if h_align is 4, then program the GPU
-    * with HALIGN_4.
-    * \{
-    */
-   uint8_t h_align; /**< RENDER_SURFACE_STATE.SurfaceHorizontalAlignment */
-   uint8_t v_align; /**< RENDER_SURFACE_STATE.SurfaceVerticalAlignment */
-   /** \} */
-
-   enum isl_tiling tiling;
 };
 
 struct anv_image {
index 1dafcd996fec67f00cdde22bd2d0e39399c6bd90..dd5baa452a00fb87678725927ba23e358b2159ad 100644 (file)
@@ -678,7 +678,7 @@ wsi_wl_image_init(struct wsi_wl_swapchain *chain, struct wsi_wl_image *image,
 
    int ret = anv_gem_set_tiling(chain->base.device,
                                 image->memory->bo.gem_handle,
-                                surface->stride, I915_TILING_X);
+                                surface->isl.row_pitch, I915_TILING_X);
    if (ret) {
       /* FINISHME: Choose a better error. */
       result = vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY);
@@ -699,7 +699,7 @@ wsi_wl_image_init(struct wsi_wl_swapchain *chain, struct wsi_wl_image *image,
                                               chain->extent.height,
                                               chain->drm_format,
                                               surface->offset,
-                                              surface->stride,
+                                              surface->isl.row_pitch,
                                               0, 0, 0, 0 /* unused */);
    wl_display_roundtrip(chain->display->display);
    close(fd);
index d327f4316d38d82b2b9bfd3501079a8daa8d0680..15ad98c3f8b6bb779ebbdf518eaff7cf8a8ab365 100644 (file)
@@ -388,7 +388,7 @@ x11_surface_create_swapchain(struct anv_wsi_surface *wsi_surface,
                           memory_h, 0);
 
       int ret = anv_gem_set_tiling(device, memory->bo.gem_handle,
-                                   surface->stride, I915_TILING_X);
+                                   surface->isl.row_pitch, I915_TILING_X);
       if (ret) {
          /* FINISHME: Choose a better error. */
          result = vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY,
@@ -415,7 +415,7 @@ x11_surface_create_swapchain(struct anv_wsi_surface *wsi_surface,
                                              image->size,
                                              pCreateInfo->imageExtent.width,
                                              pCreateInfo->imageExtent.height,
-                                             surface->stride,
+                                             surface->isl.row_pitch,
                                              depth, bpp, fd);
 
       chain->images[i].image = image;
index dd80144270b01b267c0a374330043510630153fe..7101831080bfe303c950a9345b44094800642e53 100644 (file)
@@ -707,7 +707,7 @@ cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
          .StencilWriteEnable = has_stencil,
          .HierarchicalDepthBufferEnable = false,
          .SurfaceFormat = iview->format->depth_format,
-         .SurfacePitch = image->depth_surface.stride - 1,
+         .SurfacePitch = image->depth_surface.isl.row_pitch - 1,
          .SurfaceBaseAddress = {
             .bo = image->bo,
             .offset = image->depth_surface.offset,
@@ -758,7 +758,7 @@ cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
           *    The pitch must be set to 2x the value computed based on width,
           *    as the stencil buffer is stored with two rows interleaved.
           */
-         .SurfacePitch = 2 * image->stencil_surface.stride - 1,
+         .SurfacePitch = 2 * image->stencil_surface.isl.row_pitch - 1,
 
          .SurfaceBaseAddress = {
             .bo = image->bo,
index 5a626f75eeb0c0149a44c541f47cb8cce202e968..6dcb5bffdf1be1240642f1622149576b58ceb958 100644 (file)
@@ -238,18 +238,21 @@ genX(image_view_init)(struct anv_image_view *iview,
       depth = image->extent.depth;
    }
 
+   const struct isl_extent3d lod_align_sa =
+      isl_surf_get_lod_alignment_sa(&surface->isl);
+
    struct GENX(RENDER_SURFACE_STATE) surface_state = {
       .SurfaceType = image->surface_type,
       .SurfaceArray = image->array_size > 1,
       .SurfaceFormat = format->surface_format,
-      .SurfaceVerticalAlignment = anv_valign[surface->v_align],
-      .SurfaceHorizontalAlignment = anv_halign[surface->h_align],
+      .SurfaceVerticalAlignment = anv_valign[lod_align_sa.height],
+      .SurfaceHorizontalAlignment = anv_halign[lod_align_sa.width],
 
       /* From bspec (DevSNB, DevIVB): "Set Tile Walk to TILEWALK_XMAJOR if
        * Tiled Surface is False."
        */
-      .TiledSurface = surface->tiling != ISL_TILING_LINEAR,
-      .TileWalk = surface->tiling == ISL_TILING_Y0 ?
+      .TiledSurface = surface->isl.tiling != ISL_TILING_LINEAR,
+      .TileWalk = surface->isl.tiling == ISL_TILING_Y0 ?
                   TILEWALK_YMAJOR : TILEWALK_XMAJOR,
 
       .VerticalLineStride = 0,
@@ -260,7 +263,7 @@ genX(image_view_init)(struct anv_image_view *iview,
       .Height = image->extent.height - 1,
       .Width = image->extent.width - 1,
       .Depth = depth - 1,
-      .SurfacePitch = surface->stride - 1,
+      .SurfacePitch = surface->isl.row_pitch - 1,
       .MinimumArrayElement = range->baseArrayLayer,
       .NumberofMultisamples = MULTISAMPLECOUNT_1,
       .XOffset = 0,
index 6d0ac25b6d899459ef71c3731574b77efe5bac75..a23421102aa4fc160c052a6d31c8352dd14f1470 100644 (file)
@@ -659,7 +659,7 @@ cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
          .StencilWriteEnable = has_stencil,
          .HierarchicalDepthBufferEnable = false,
          .SurfaceFormat = iview->format->depth_format,
-         .SurfacePitch = image->depth_surface.stride - 1,
+         .SurfacePitch = image->depth_surface.isl.row_pitch - 1,
          .SurfaceBaseAddress = {
             .bo = image->bo,
             .offset = image->depth_surface.offset,
@@ -671,7 +671,7 @@ cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
          .MinimumArrayElement = 0,
          .DepthBufferObjectControlState = GENX(MOCS),
          .RenderTargetViewExtent = 1 - 1,
-         .SurfaceQPitch = image->depth_surface.qpitch >> 2);
+         .SurfaceQPitch = isl_surf_get_array_pitch_el_rows(&image->depth_surface.isl) >> 2);
    } else {
       /* Even when no depth buffer is present, the hardware requires that
        * 3DSTATE_DEPTH_BUFFER be programmed correctly. The Broadwell PRM says:
@@ -709,13 +709,13 @@ cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
           *    The pitch must be set to 2x the value computed based on width,
           *    as the stencil buffer is stored with two rows interleaved.
           */
-         .SurfacePitch = 2 * image->stencil_surface.stride - 1,
+         .SurfacePitch = 2 * image->stencil_surface.isl.row_pitch - 1,
 
          .SurfaceBaseAddress = {
             .bo = image->bo,
             .offset = image->offset + image->stencil_surface.offset,
          },
-         .SurfaceQPitch = image->stencil_surface.stride >> 2);
+         .SurfaceQPitch = isl_surf_get_array_pitch_el_rows(&image->stencil_surface.isl) >> 2);
    } else {
       anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_STENCIL_BUFFER));
    }
index f46611c629d9568554da8c63f72fe6ac2a925fe1..30478237bdd23420319a2e0d41cbdd4154386ded 100644 (file)
@@ -183,13 +183,16 @@ genX(image_view_init)(struct anv_image_view *iview,
       [ISL_TILING_W]       = WMAJOR,
    };
 
+   const struct isl_extent3d lod_align_sa =
+      isl_surf_get_lod_alignment_sa(&surface->isl);
+
    struct GENX(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 = isl_to_gen_tiling[surface->tiling],
+      .SurfaceVerticalAlignment = anv_valign[lod_align_sa.height],
+      .SurfaceHorizontalAlignment = anv_halign[lod_align_sa.width],
+      .TileMode = isl_to_gen_tiling[surface->isl.tiling],
       .VerticalLineStride = 0,
       .VerticalLineStrideOffset = 0,
       .SamplerL2BypassModeDisable = true,
@@ -202,11 +205,11 @@ genX(image_view_init)(struct anv_image_view *iview,
        */
       .BaseMipLevel = 0.0,
 
-      .SurfaceQPitch = surface->qpitch >> 2,
+      .SurfaceQPitch = isl_surf_get_array_pitch_el_rows(&surface->isl) >> 2,
       .Height = image->extent.height - 1,
       .Width = image->extent.width - 1,
       .Depth = depth - 1,
-      .SurfacePitch = surface->stride - 1,
+      .SurfacePitch = surface->isl.row_pitch - 1,
       .RenderTargetViewExtent = rt_view_extent - 1,
       .MinimumArrayElement = range->baseArrayLayer,
       .NumberofMultisamples = MULTISAMPLECOUNT_1,