vk: Move anv_color_attachment_view_init() to gen8_state.c
authorKristian Høgsberg Kristensen <kristian.h.kristensen@intel.com>
Thu, 20 Aug 2015 05:19:21 +0000 (22:19 -0700)
committerKristian Høgsberg Kristensen <kristian.h.kristensen@intel.com>
Mon, 24 Aug 2015 20:45:40 +0000 (13:45 -0700)
I'd prefer to move anv_CreateAttachmentView() as well, but it's a little
too much generic code to just duplicate for each gen.  For now, we'll
add a anv_color_attachment_view_init() to dispatch to the gen specific
implementation, which we then call from anv_CreateAttachmentView().

Signed-off-by: Kristian Høgsberg Kristensen <kristian.h.kristensen@intel.com>
src/vulkan/anv_image.c
src/vulkan/anv_private.h
src/vulkan/gen8_state.c

index 04fab514582b0bae8bfc7a3a34b0c26345aa93ff..51f2cf5244c85ecef25c1f13fd69850c26e4100c 100644 (file)
@@ -450,101 +450,6 @@ anv_DestroyImageView(VkDevice _device, VkImageView _iview)
    return VK_SUCCESS;
 }
 
-void
-anv_color_attachment_view_init(struct anv_color_attachment_view *aview,
-                               struct anv_device *device,
-                               const VkAttachmentViewCreateInfo* pCreateInfo,
-                               struct anv_cmd_buffer *cmd_buffer)
-{
-   ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image);
-   struct anv_surface_view *view = &aview->view;
-   struct anv_surface *surface = &image->primary_surface;
-
-   aview->base.attachment_type = ANV_ATTACHMENT_VIEW_TYPE_COLOR;
-
-   anv_assert(pCreateInfo->arraySize > 0);
-   anv_assert(pCreateInfo->mipLevel < image->levels);
-   anv_assert(pCreateInfo->baseArraySlice + pCreateInfo->arraySize <= image->array_size);
-
-   view->bo = image->bo;
-   view->offset = image->offset + surface->offset;
-   view->format = anv_format_for_vk_format(pCreateInfo->format);
-
-   aview->base.extent = (VkExtent3D) {
-      .width = anv_minify(image->extent.width, pCreateInfo->mipLevel),
-      .height = anv_minify(image->extent.height, pCreateInfo->mipLevel),
-      .depth = anv_minify(image->extent.depth, pCreateInfo->mipLevel),
-   };
-
-   uint32_t depth = 1;
-   if (pCreateInfo->arraySize > 1) {
-      depth = pCreateInfo->arraySize;
-   } else if (image->extent.depth > 1) {
-      depth = image->extent.depth;
-   }
-
-   if (cmd_buffer) {
-      view->surface_state =
-         anv_state_stream_alloc(&cmd_buffer->surface_state_stream, 64, 64);
-   } else {
-      view->surface_state =
-         anv_state_pool_alloc(&device->surface_state_pool, 64, 64);
-   }
-
-   struct GEN8_RENDER_SURFACE_STATE surface_state = {
-      .SurfaceType = SURFTYPE_2D,
-      .SurfaceArray = image->array_size > 1,
-      .SurfaceFormat = view->format->surface_format,
-      .SurfaceVerticalAlignment = anv_valign[surface->v_align],
-      .SurfaceHorizontalAlignment = anv_halign[surface->h_align],
-      .TileMode = surface->tile_mode,
-      .VerticalLineStride = 0,
-      .VerticalLineStrideOffset = 0,
-      .SamplerL2BypassModeDisable = true,
-      .RenderCacheReadWriteMode = WriteOnlyCache,
-      .MemoryObjectControlState = GEN8_MOCS,
-
-      /* The driver sets BaseMipLevel in SAMPLER_STATE, not here in
-       * RENDER_SURFACE_STATE. The Broadwell PRM says "it is illegal to have
-       * both Base Mip Level fields nonzero".
-       */
-      .BaseMipLevel = 0.0,
-
-      .SurfaceQPitch = surface->qpitch >> 2,
-      .Height = image->extent.height - 1,
-      .Width = image->extent.width - 1,
-      .Depth = depth - 1,
-      .SurfacePitch = surface->stride - 1,
-      .MinimumArrayElement = pCreateInfo->baseArraySlice,
-      .NumberofMultisamples = MULTISAMPLECOUNT_1,
-      .XOffset = 0,
-      .YOffset = 0,
-
-      /* For render target surfaces, the hardware interprets field MIPCount/LOD as
-       * LOD. The Broadwell PRM says:
-       *
-       *    MIPCountLOD defines the LOD that will be rendered into.
-       *    SurfaceMinLOD is ignored.
-       */
-      .SurfaceMinLOD = 0,
-      .MIPCountLOD = pCreateInfo->mipLevel,
-
-      .AuxiliarySurfaceMode = AUX_NONE,
-      .RedClearColor = 0,
-      .GreenClearColor = 0,
-      .BlueClearColor = 0,
-      .AlphaClearColor = 0,
-      .ShaderChannelSelectRed = SCS_RED,
-      .ShaderChannelSelectGreen = SCS_GREEN,
-      .ShaderChannelSelectBlue = SCS_BLUE,
-      .ShaderChannelSelectAlpha = SCS_ALPHA,
-      .ResourceMinLOD = 0.0,
-      .SurfaceBaseAddress = { NULL, view->offset },
-   };
-
-   GEN8_RENDER_SURFACE_STATE_pack(NULL, view->surface_state.map, &surface_state);
-}
-
 static void
 anv_depth_stencil_view_init(struct anv_depth_stencil_view *view,
                             const VkAttachmentViewCreateInfo *pCreateInfo)
@@ -572,6 +477,21 @@ anv_depth_stencil_view_init(struct anv_depth_stencil_view *view,
    view->stencil_qpitch = 0; /* FINISHME: QPitch */
 }
 
+void
+anv_color_attachment_view_init(struct anv_color_attachment_view *aview,
+                               struct anv_device *device,
+                               const VkAttachmentViewCreateInfo* pCreateInfo,
+                               struct anv_cmd_buffer *cmd_buffer)
+{
+   switch (device->info.gen) {
+   case 8:
+      gen8_color_attachment_view_init(aview, device, pCreateInfo, cmd_buffer);
+      break;
+   default:
+      unreachable("unsupported gen\n");
+   }
+}
+
 VkResult
 anv_CreateAttachmentView(VkDevice _device,
                          const VkAttachmentViewCreateInfo *pCreateInfo,
index 234cb6ebdc38211345c756139fe2974c97a3ed73..58480aca818c630fcb7f2c79fa54218b732dabb8 100644 (file)
@@ -1067,6 +1067,11 @@ void anv_color_attachment_view_init(struct anv_color_attachment_view *view,
                                     const VkAttachmentViewCreateInfo* pCreateInfo,
                                     struct anv_cmd_buffer *cmd_buffer);
 
+void gen8_color_attachment_view_init(struct anv_color_attachment_view *aview,
+                                     struct anv_device *device,
+                                     const VkAttachmentViewCreateInfo* pCreateInfo,
+                                     struct anv_cmd_buffer *cmd_buffer);
+
 VkResult anv_buffer_view_create(struct anv_device *device,
                                 const VkBufferViewCreateInfo *pCreateInfo,
                                 struct anv_buffer_view **view_out);
index fb013cbf3a437c1e572841551a5b796c8b53dcf7..a22610c99e091d6dc1a6cd7113b2e07625f23ffe 100644 (file)
@@ -296,6 +296,103 @@ gen8_CreateImageView(VkDevice _device,
    return VK_SUCCESS;
 }
 
+void
+gen8_color_attachment_view_init(struct anv_color_attachment_view *aview,
+                                struct anv_device *device,
+                                const VkAttachmentViewCreateInfo* pCreateInfo,
+                                struct anv_cmd_buffer *cmd_buffer)
+{
+   ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image);
+   struct anv_surface_view *view = &aview->view;
+   struct anv_surface *surface = &image->primary_surface;
+   const struct anv_format *format_info =
+      anv_format_for_vk_format(pCreateInfo->format);
+
+   aview->base.attachment_type = ANV_ATTACHMENT_VIEW_TYPE_COLOR;
+
+   anv_assert(pCreateInfo->arraySize > 0);
+   anv_assert(pCreateInfo->mipLevel < image->levels);
+   anv_assert(pCreateInfo->baseArraySlice + pCreateInfo->arraySize <= image->array_size);
+
+   view->bo = image->bo;
+   view->offset = image->offset + surface->offset;
+   view->format = anv_format_for_vk_format(pCreateInfo->format);
+
+   aview->base.extent = (VkExtent3D) {
+      .width = anv_minify(image->extent.width, pCreateInfo->mipLevel),
+      .height = anv_minify(image->extent.height, pCreateInfo->mipLevel),
+      .depth = anv_minify(image->extent.depth, pCreateInfo->mipLevel),
+   };
+
+   uint32_t depth = 1;
+   if (pCreateInfo->arraySize > 1) {
+      depth = pCreateInfo->arraySize;
+   } else if (image->extent.depth > 1) {
+      depth = image->extent.depth;
+   }
+
+   if (cmd_buffer) {
+      view->surface_state =
+         anv_state_stream_alloc(&cmd_buffer->surface_state_stream, 64, 64);
+   } else {
+      view->surface_state =
+         anv_state_pool_alloc(&device->surface_state_pool, 64, 64);
+   }
+
+   struct GEN8_RENDER_SURFACE_STATE surface_state = {
+      .SurfaceType = SURFTYPE_2D,
+      .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,
+      .VerticalLineStride = 0,
+      .VerticalLineStrideOffset = 0,
+      .SamplerL2BypassModeDisable = true,
+      .RenderCacheReadWriteMode = WriteOnlyCache,
+      .MemoryObjectControlState = GEN8_MOCS,
+
+      /* The driver sets BaseMipLevel in SAMPLER_STATE, not here in
+       * RENDER_SURFACE_STATE. The Broadwell PRM says "it is illegal to have
+       * both Base Mip Level fields nonzero".
+       */
+      .BaseMipLevel = 0.0,
+
+      .SurfaceQPitch = surface->qpitch >> 2,
+      .Height = image->extent.height - 1,
+      .Width = image->extent.width - 1,
+      .Depth = depth - 1,
+      .SurfacePitch = surface->stride - 1,
+      .MinimumArrayElement = pCreateInfo->baseArraySlice,
+      .NumberofMultisamples = MULTISAMPLECOUNT_1,
+      .XOffset = 0,
+      .YOffset = 0,
+
+      /* For render target surfaces, the hardware interprets field MIPCount/LOD as
+       * LOD. The Broadwell PRM says:
+       *
+       *    MIPCountLOD defines the LOD that will be rendered into.
+       *    SurfaceMinLOD is ignored.
+       */
+      .SurfaceMinLOD = 0,
+      .MIPCountLOD = pCreateInfo->mipLevel,
+
+      .AuxiliarySurfaceMode = AUX_NONE,
+      .RedClearColor = 0,
+      .GreenClearColor = 0,
+      .BlueClearColor = 0,
+      .AlphaClearColor = 0,
+      .ShaderChannelSelectRed = SCS_RED,
+      .ShaderChannelSelectGreen = SCS_GREEN,
+      .ShaderChannelSelectBlue = SCS_BLUE,
+      .ShaderChannelSelectAlpha = SCS_ALPHA,
+      .ResourceMinLOD = 0.0,
+      .SurfaceBaseAddress = { NULL, view->offset },
+   };
+
+   GEN8_RENDER_SURFACE_STATE_pack(NULL, view->surface_state.map, &surface_state);
+}
+
 VkResult gen8_CreateSampler(
     VkDevice                                    _device,
     const VkSamplerCreateInfo*                  pCreateInfo,