vk/image: Factor view creation out into separate *_init functions
authorJason Ekstrand <jason.ekstrand@intel.com>
Tue, 19 May 2015 03:42:03 +0000 (20:42 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Tue, 19 May 2015 03:57:43 +0000 (20:57 -0700)
The *_init functions work basically the same as the Vulkan entrypoints
except that they act on an already-created view and take an optional
command buffer option.  If a command buffer is given, the surface state is
allocated out of the command buffer's state stream.

src/vulkan/image.c
src/vulkan/private.h

index d5e74dc6594b0e9953f055bcfbf3a8c75873a70a..cf658e969da05962fc92e4ba7aabd063e6c3f115 100644 (file)
@@ -111,10 +111,14 @@ VkResult anv_GetImageSubresourceInfo(
 
 static struct anv_state
 create_surface_state(struct anv_device *device,
-                     struct anv_image *image, const struct anv_format *format)
+                     struct anv_image *image, const struct anv_format *format,
+                     struct anv_cmd_buffer *cmd_buffer)
 {
-   struct anv_state state =
-      anv_state_pool_alloc(&device->surface_state_pool, 64, 64);
+   struct anv_state state;
+   if (cmd_buffer)
+      state = anv_state_stream_alloc(&cmd_buffer->surface_state_stream, 64, 64);
+   else
+      state = anv_state_pool_alloc(&device->surface_state_pool, 64, 64);
 
    struct GEN8_RENDER_SURFACE_STATE surface_state = {
       .SurfaceType = SURFTYPE_2D,
@@ -159,6 +163,26 @@ create_surface_state(struct anv_device *device,
    return state;
 }
 
+void
+anv_image_view_init(struct anv_surface_view *view,
+                    struct anv_device *device,
+                    const VkImageViewCreateInfo* pCreateInfo,
+                    struct anv_cmd_buffer *cmd_buffer)
+{
+   struct anv_image *image = (struct anv_image *) pCreateInfo->image;
+   const struct anv_format *format =
+      anv_format_for_vk_format(pCreateInfo->format);
+
+   view->bo = image->bo;
+   view->offset = image->offset;
+   view->surface_state = create_surface_state(device, image, format,
+                                              cmd_buffer);
+   view->format = pCreateInfo->format;
+
+   /* TODO: Miplevels */
+   view->extent = image->extent;
+}
+
 VkResult anv_CreateImageView(
     VkDevice                                    _device,
     const VkImageViewCreateInfo*                pCreateInfo,
@@ -166,9 +190,6 @@ VkResult anv_CreateImageView(
 {
    struct anv_device *device = (struct anv_device *) _device;
    struct anv_surface_view *view;
-   struct anv_image *image = (struct anv_image *) pCreateInfo->image;
-   const struct anv_format *format =
-      anv_format_for_vk_format(pCreateInfo->format);
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO);
 
@@ -177,19 +198,31 @@ VkResult anv_CreateImageView(
    if (view == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
-   view->bo = image->bo;
-   view->offset = image->offset;
-   view->surface_state = create_surface_state(device, image, format);
-   view->format = pCreateInfo->format;
-
-   /* TODO: Miplevels */
-   view->extent = image->extent;
+   anv_image_view_init(view, device, pCreateInfo, NULL);
 
    *pView = (VkImageView) view;
 
    return VK_SUCCESS;
 }
 
+void
+anv_color_attachment_view_init(struct anv_surface_view *view,
+                               struct anv_device *device,
+                               const VkColorAttachmentViewCreateInfo* pCreateInfo,
+                               struct anv_cmd_buffer *cmd_buffer)
+{
+   struct anv_image *image = (struct anv_image *) pCreateInfo->image;
+   const struct anv_format *format =
+      anv_format_for_vk_format(pCreateInfo->format);
+
+   view->bo = image->bo;
+   view->offset = image->offset;
+   view->surface_state = create_surface_state(device, image, format,
+                                              cmd_buffer);
+   view->extent = image->extent;
+   view->format = pCreateInfo->format;
+}
+
 VkResult anv_CreateColorAttachmentView(
     VkDevice                                    _device,
     const VkColorAttachmentViewCreateInfo*      pCreateInfo,
@@ -197,9 +230,6 @@ VkResult anv_CreateColorAttachmentView(
 {
    struct anv_device *device = (struct anv_device *) _device;
    struct anv_surface_view *view;
-   struct anv_image *image = (struct anv_image *) pCreateInfo->image;
-   const struct anv_format *format =
-      anv_format_for_vk_format(pCreateInfo->format);
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_COLOR_ATTACHMENT_VIEW_CREATE_INFO);
 
@@ -208,11 +238,7 @@ VkResult anv_CreateColorAttachmentView(
    if (view == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
-   view->bo = image->bo;
-   view->offset = image->offset;
-   view->surface_state = create_surface_state(device, image, format);
-   view->extent = image->extent;
-   view->format = pCreateInfo->format;
+   anv_color_attachment_view_init(view, device, pCreateInfo, NULL);
 
    *pView = (VkColorAttachmentView) view;
 
index 13be1b9479105d50b96774cb037becaf749787d9..7e935962742fc08f42ee9d9a1ad1e0ed3d74d91f 100644 (file)
@@ -671,6 +671,16 @@ struct anv_surface_view {
    VkFormat                                     format;
 };
 
+void anv_image_view_init(struct anv_surface_view *view,
+                         struct anv_device *device,
+                         const VkImageViewCreateInfo* pCreateInfo,
+                         struct anv_cmd_buffer *cmd_buffer);
+
+void anv_color_attachment_view_init(struct anv_surface_view *view,
+                                    struct anv_device *device,
+                                    const VkColorAttachmentViewCreateInfo* pCreateInfo,
+                                    struct anv_cmd_buffer *cmd_buffer);
+
 struct anv_sampler {
    uint32_t state[4];
 };