anv/image_view: Separate vulkan and isl formats
authorJason Ekstrand <jason.ekstrand@intel.com>
Fri, 1 Jan 2016 22:09:17 +0000 (14:09 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Tue, 5 Jan 2016 00:08:05 +0000 (16:08 -0800)
Previously, anv_image_view had a anv_format pointer that we used for
everything.  This commit replaces that pointer with a VkFormat enum copied
from the API and an isl_format.  In order to implement RGB formats, we have
to use a different isl_format for the actual surface state than the obvious
one from the VkFormat.  Separating the two helps us keep things streight.

src/vulkan/anv_cmd_buffer.c
src/vulkan/anv_image.c
src/vulkan/anv_meta_clear.c
src/vulkan/anv_private.h
src/vulkan/gen7_cmd_buffer.c
src/vulkan/gen7_state.c
src/vulkan/gen8_cmd_buffer.c
src/vulkan/gen8_state.c

index 2f19c75e7ccdb1623c92692cb848e7020f276f23..49bb298a1884a84469fcee08fb9ef073e5ae66b6 100644 (file)
@@ -1075,7 +1075,8 @@ anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer *cmd_buffer)
    const struct anv_image_view *iview =
       fb->attachments[subpass->depth_stencil_attachment];
 
-   assert(anv_format_is_depth_or_stencil(iview->format));
+   assert(iview->aspect_mask & (VK_IMAGE_ASPECT_DEPTH_BIT |
+                                VK_IMAGE_ASPECT_STENCIL_BIT));
 
    return iview;
 }
index 5bee5a236e8cbb5d8ae22568088637e8fddbd37b..bd550890596a06a94e7d2809e4488bd87626a6ca 100644 (file)
@@ -210,6 +210,7 @@ anv_image_create(VkDevice _device,
    image->levels = pCreateInfo->mipLevels;
    image->array_size = pCreateInfo->arrayLayers;
    image->usage = anv_image_get_full_usage(pCreateInfo);
+   image->tiling = pCreateInfo->tiling;
 
    if (image->usage & VK_IMAGE_USAGE_SAMPLED_BIT) {
       image->needs_nonrt_surface_state = true;
@@ -440,7 +441,9 @@ anv_image_view_init(struct anv_image_view *iview,
    iview->offset = image->offset + surface->offset;
 
    iview->aspect_mask = pCreateInfo->subresourceRange.aspectMask;
-   iview->format = anv_format_for_vk_format(pCreateInfo->format);
+   iview->vk_format = pCreateInfo->format;
+   iview->format = anv_get_isl_format(pCreateInfo->format, iview->aspect_mask,
+                                      image->tiling);
 
    iview->extent = (VkExtent3D) {
       .width = anv_minify(image->extent.width, range->baseMipLevel),
index 17a40cd6be601b6ddc3b6d0554fad32e57c7b7e7..6873c4e8e6b2a8bf3537a775327e1539736c5294 100644 (file)
@@ -759,7 +759,7 @@ void anv_CmdClearColorImage(
                   .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
                   .attachmentCount = 1,
                   .pAttachments = &(VkAttachmentDescription) {
-                     .format = iview.format->vk_format,
+                     .format = iview.vk_format,
                      .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
                      .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
                      .initialLayout = VK_IMAGE_LAYOUT_GENERAL,
index 76c47de594a109854c93bf17c8e1652e00624d88..8667b45cfc0bb7295323e10386269e3d25d61a47 100644 (file)
@@ -1453,6 +1453,7 @@ struct anv_image {
    uint32_t levels;
    uint32_t array_size;
    VkImageUsageFlags usage; /**< Superset of VkImageCreateInfo::usage. */
+   VkImageTiling tiling; /** VkImageCreateInfo::tiling */
 
    VkDeviceSize size;
    uint32_t alignment;
@@ -1489,11 +1490,12 @@ struct anv_image {
 
 struct anv_image_view {
    const struct anv_image *image; /**< VkImageViewCreateInfo::image */
-   const struct anv_format *format; /**< VkImageViewCreateInfo::format */
    struct anv_bo *bo;
    uint32_t offset; /**< Offset into bo. */
 
    VkImageAspectFlags aspect_mask;
+   VkFormat vk_format;
+   enum isl_format format;
    VkExtent3D extent; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
 
    /** RENDER_SURFACE_STATE when using image as a color render target. */
index feed3611805cea50e3f1d81e8e5ab51496e08b2e..fa9cb8fa9146a30facbe6ee341ab29cfc80128b3 100644 (file)
@@ -459,7 +459,7 @@ cmd_buffer_flush_state(struct anv_cmd_buffer *cmd_buffer)
          anv_cmd_buffer_get_depth_stencil_view(cmd_buffer);
 
       struct GEN7_DEPTH_STENCIL_STATE depth_stencil = {
-         .StencilBufferWriteEnable = iview && iview->format->has_stencil,
+         .StencilBufferWriteEnable = iview && (iview->aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT),
 
          .StencilTestMask =
             cmd_buffer->state.dynamic.stencil_compare_mask.front & 0xff,
@@ -698,17 +698,22 @@ cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
    const struct anv_image_view *iview =
       anv_cmd_buffer_get_depth_stencil_view(cmd_buffer);
    const struct anv_image *image = iview ? iview->image : NULL;
-   const bool has_depth = iview && iview->format->depth_format;
-   const bool has_stencil = iview && iview->format->has_stencil;
+
+   /* XXX: isl needs to grow depth format support */
+   const struct anv_format *anv_format =
+      iview ? anv_format_for_vk_format(iview->vk_format) : NULL;
+
+   const bool has_depth = iview && anv_format->depth_format;
+   const bool has_stencil = iview && anv_format->has_stencil;
 
    /* Emit 3DSTATE_DEPTH_BUFFER */
    if (has_depth) {
       anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_DEPTH_BUFFER),
          .SurfaceType = SURFTYPE_2D,
-         .DepthWriteEnable = iview->format->depth_format,
+         .DepthWriteEnable = true,
          .StencilWriteEnable = has_stencil,
          .HierarchicalDepthBufferEnable = false,
-         .SurfaceFormat = iview->format->depth_format,
+         .SurfaceFormat = anv_format->depth_format,
          .SurfacePitch = image->depth_surface.isl.row_pitch - 1,
          .SurfaceBaseAddress = {
             .bo = image->bo,
index fe2967c7ef4ca244178553f39fdb23724801808e..a7940ca9e2f58d1c40b6a208d36d53bd73f5ebf0 100644 (file)
@@ -214,7 +214,7 @@ genX(image_view_init)(struct anv_image_view *iview,
    struct GENX(RENDER_SURFACE_STATE) surface_state = {
       .SurfaceType = anv_surftype(image, pCreateInfo->viewType, false),
       .SurfaceArray = image->array_size > 1,
-      .SurfaceFormat = iview->format->surface_format,
+      .SurfaceFormat = iview->format,
       .SurfaceVerticalAlignment = anv_valign[image_align_sa.height],
       .SurfaceHorizontalAlignment = anv_halign[image_align_sa.width],
 
@@ -310,8 +310,7 @@ genX(image_view_init)(struct anv_image_view *iview,
          anv_surftype(image, pCreateInfo->viewType, true),
 
       surface_state.SurfaceFormat =
-         isl_lower_storage_image_format(&device->isl_dev,
-                                        iview->format->surface_format);
+         isl_lower_storage_image_format(&device->isl_dev, iview->format);
 
       surface_state.SurfaceMinLOD = range->baseMipLevel;
       surface_state.MIPCountLOD = MAX2(range->levelCount, 1) - 1;
index 9614da705e7f118a6964265581be115e2a81c373..965a9c14317602be87b5ec297d0bbb2a45aed112 100644 (file)
@@ -695,8 +695,13 @@ cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
    const struct anv_image_view *iview =
       anv_cmd_buffer_get_depth_stencil_view(cmd_buffer);
    const struct anv_image *image = iview ? iview->image : NULL;
-   const bool has_depth = iview && iview->format->depth_format;
-   const bool has_stencil = iview && iview->format->has_stencil;
+
+   /* XXX: isl needs to grow depth format support */
+   const struct anv_format *anv_format =
+      iview ? anv_format_for_vk_format(iview->vk_format) : NULL;
+
+   const bool has_depth = iview && anv_format->depth_format;
+   const bool has_stencil = iview && anv_format->has_stencil;
 
    /* FIXME: Implement the PMA stall W/A */
    /* FIXME: Width and Height are wrong */
@@ -705,10 +710,10 @@ cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
    if (has_depth) {
       anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_DEPTH_BUFFER),
          .SurfaceType = SURFTYPE_2D,
-         .DepthWriteEnable = iview->format->depth_format,
+         .DepthWriteEnable = anv_format->depth_format,
          .StencilWriteEnable = has_stencil,
          .HierarchicalDepthBufferEnable = false,
-         .SurfaceFormat = iview->format->depth_format,
+         .SurfaceFormat = anv_format->depth_format,
          .SurfacePitch = image->depth_surface.isl.row_pitch - 1,
          .SurfaceBaseAddress = {
             .bo = image->bo,
index 5562a252a21999a2c5945ec13857a24181fcae7a..a24eb1924937b75bd5c3cba0c5358ff23e8b16a5 100644 (file)
@@ -194,7 +194,7 @@ genX(image_view_init)(struct anv_image_view *iview,
    struct GENX(RENDER_SURFACE_STATE) surface_state = {
       .SurfaceType = anv_surftype(image, pCreateInfo->viewType, false),
       .SurfaceArray = image->array_size > 1,
-      .SurfaceFormat = iview->format->surface_format,
+      .SurfaceFormat = iview->format,
       .SurfaceVerticalAlignment = valign,
       .SurfaceHorizontalAlignment = halign,
       .TileMode = isl_to_gen_tiling[surface->isl.tiling],
@@ -285,8 +285,7 @@ genX(image_view_init)(struct anv_image_view *iview,
          anv_surftype(image, pCreateInfo->viewType, true),
 
       surface_state.SurfaceFormat =
-         isl_lower_storage_image_format(&device->isl_dev,
-                                        iview->format->surface_format);
+         isl_lower_storage_image_format(&device->isl_dev, iview->format);
 
       surface_state.SurfaceMinLOD = range->baseMipLevel;
       surface_state.MIPCountLOD = MAX2(range->levelCount, 1) - 1;