vk: Don't duplicate anv_depth_stencil_view's surface data
authorChad Versace <chad.versace@intel.com>
Fri, 28 Aug 2015 14:52:19 +0000 (07:52 -0700)
committerChad Versace <chad.versace@intel.com>
Fri, 28 Aug 2015 14:52:19 +0000 (07:52 -0700)
In anv_depth_stencil_view, replace the members
    bo
    depth_offset
    depth_stride
    depth_format
    depth_qpitch
    stencil_offset
    stencil_stride
    stencil_qpitch
with the single member
    const struct anv_image *image

The removed members duplicated data in anv_image::depth_surface and
anv_image::stencil_surface.

src/vulkan/anv_image.c
src/vulkan/anv_private.h
src/vulkan/gen7_cmd_buffer.c
src/vulkan/gen8_cmd_buffer.c

index 6ab541e5bce894935062cd6841d51ac5adc54311..242de52f639c95e625ef7d07875415048e5aa8f8 100644 (file)
@@ -468,35 +468,15 @@ anv_depth_stencil_view_init(struct anv_depth_stencil_view *view,
    view->base.attachment_type = ANV_ATTACHMENT_VIEW_TYPE_DEPTH_STENCIL;
 
    /* XXX: We don't handle any of these */
-   assert(anv_format_is_depth_or_stencil(image->format));
    anv_assert(pCreateInfo->mipLevel == 0);
    anv_assert(pCreateInfo->baseArraySlice == 0);
    anv_assert(pCreateInfo->arraySize == 1);
 
-   view->bo = image->bo;
-
+   view->image = image;
    view->format = anv_format_for_vk_format(pCreateInfo->format);
-   assert(anv_format_is_depth_or_stencil(view->format));
-
-   if (view->format->depth_format) {
-      view->depth_stride = image->depth_surface.stride;
-      view->depth_offset = image->offset + image->depth_surface.offset;
-      view->depth_qpitch = 0; /* FINISHME: QPitch */
-   } else {
-      view->depth_stride = 0;
-      view->depth_offset = 0;
-      view->depth_qpitch = 0;
-   }
 
-   if (view->format->has_stencil) {
-      view->stencil_stride = image->stencil_surface.stride;
-      view->stencil_offset = image->offset + image->stencil_surface.offset;
-      view->stencil_qpitch = 0; /* FINISHME: QPitch */
-   } else {
-      view->stencil_stride = 0;
-      view->stencil_offset = 0;
-      view->stencil_qpitch = 0;
-   }
+   assert(anv_format_is_depth_or_stencil(image->format));
+   assert(anv_format_is_depth_or_stencil(view->format));
 }
 
 struct anv_surface *
index 594b4fedc6c91742d84f28e57342031ae1c61e49..5cbc67b7c2ca96f0241df28ce73344cce0cd0df4 100644 (file)
@@ -1119,18 +1119,8 @@ struct anv_color_attachment_view {
 
 struct anv_depth_stencil_view {
    struct anv_attachment_view base;
+   const struct anv_image *image; /**< VkAttachmentViewCreateInfo::image */
    const struct anv_format *format; /**< VkAttachmentViewCreateInfo::format */
-
-   struct anv_bo *bo;
-
-   uint32_t depth_offset; /**< Offset into bo. */
-   uint32_t depth_stride; /**< 3DSTATE_DEPTH_BUFFER.SurfacePitch */
-   uint32_t depth_format; /**< 3DSTATE_DEPTH_BUFFER.SurfaceFormat */
-   uint16_t depth_qpitch; /**< 3DSTATE_DEPTH_BUFFER.SurfaceQPitch */
-
-   uint32_t stencil_offset; /**< Offset into bo. */
-   uint32_t stencil_stride; /**< 3DSTATE_STENCIL_BUFFER.SurfacePitch */
-   uint16_t stencil_qpitch; /**< 3DSTATE_STENCIL_BUFFER.SurfaceQPitch */
 };
 
 struct anv_image_create_info {
index c157155cd99281fe2bb16b564ca1a1193bbc4f1e..84b733ca45823513798ddf21b9f9fe8aaa3ed8fc 100644 (file)
@@ -539,6 +539,7 @@ gen7_cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
       view = (const struct anv_depth_stencil_view *)aview;
    }
 
+   const struct anv_image *image = view ? view->image : NULL;
    const bool has_depth = view && view->format->depth_format;
    const bool has_stencil = view && view->format->has_stencil;
 
@@ -550,8 +551,11 @@ gen7_cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
          .StencilWriteEnable = has_stencil,
          .HierarchicalDepthBufferEnable = false,
          .SurfaceFormat = view->format->depth_format,
-         .SurfacePitch = view->depth_stride - 1,
-         .SurfaceBaseAddress = { view->bo,  view->depth_offset },
+         .SurfacePitch = image->depth_surface.stride - 1,
+         .SurfaceBaseAddress = {
+            .bo = image->bo,
+            .offset = image->depth_surface.offset,
+         },
          .Height = fb->height - 1,
          .Width = fb->width - 1,
          .LOD = 0,
@@ -589,8 +593,11 @@ gen7_cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
    if (has_stencil) {
       anv_batch_emit(&cmd_buffer->batch, GEN7_3DSTATE_STENCIL_BUFFER,
          .StencilBufferObjectControlState = GEN7_MOCS,
-         .SurfacePitch = view->stencil_stride - 1,
-         .SurfaceBaseAddress = { view->bo, view->stencil_offset });
+         .SurfacePitch = image->stencil_surface.stride - 1,
+         .SurfaceBaseAddress = {
+            .bo = image->bo,
+            .offset = image->offset + image->stencil_surface.offset,
+         });
    } else {
       anv_batch_emit(&cmd_buffer->batch, GEN7_3DSTATE_STENCIL_BUFFER);
    }
index 0ec0f666ae098d159b621e31ebb004e064148f7b..5aa78528f5c6f62bf3bd9d5a6e8b98c3a0d32ab0 100644 (file)
@@ -469,6 +469,7 @@ gen8_cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
       view = (const struct anv_depth_stencil_view *)aview;
    }
 
+   const struct anv_image *image = view ? view->image : NULL;
    const bool has_depth = view && view->format->depth_format;
    const bool has_stencil = view && view->format->has_stencil;
 
@@ -483,8 +484,11 @@ gen8_cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
          .StencilWriteEnable = has_stencil,
          .HierarchicalDepthBufferEnable = false,
          .SurfaceFormat = view->format->depth_format,
-         .SurfacePitch = view->depth_stride - 1,
-         .SurfaceBaseAddress = { view->bo,  view->depth_offset },
+         .SurfacePitch = image->depth_surface.stride - 1,
+         .SurfaceBaseAddress = {
+            .bo = image->bo,
+            .offset = image->depth_surface.offset,
+         },
          .Height = fb->height - 1,
          .Width = fb->width - 1,
          .LOD = 0,
@@ -492,7 +496,7 @@ gen8_cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
          .MinimumArrayElement = 0,
          .DepthBufferObjectControlState = GEN8_MOCS,
          .RenderTargetViewExtent = 1 - 1,
-         .SurfaceQPitch = view->depth_qpitch >> 2);
+         .SurfaceQPitch = image->depth_surface.qpitch >> 2);
    } else {
       /* Even when no depth buffer is present, the hardware requires that
        * 3DSTATE_DEPTH_BUFFER be programmed correctly. The Broadwell PRM says:
@@ -524,9 +528,12 @@ gen8_cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
       anv_batch_emit(&cmd_buffer->batch, GEN8_3DSTATE_STENCIL_BUFFER,
          .StencilBufferEnable = true,
          .StencilBufferObjectControlState = GEN8_MOCS,
-         .SurfacePitch = view->stencil_stride - 1,
-         .SurfaceBaseAddress = { view->bo, view->stencil_offset },
-         .SurfaceQPitch = view->stencil_qpitch >> 2);
+         .SurfacePitch = image->stencil_surface.stride - 1,
+         .SurfaceBaseAddress = {
+            .bo = image->bo,
+            .offset = image->offset + image->stencil_surface.offset,
+         },
+         .SurfaceQPitch = image->stencil_surface.stride >> 2);
    } else {
       anv_batch_emit(&cmd_buffer->batch, GEN8_3DSTATE_STENCIL_BUFFER);
    }