From: Jason Ekstrand Date: Tue, 19 May 2015 03:42:03 +0000 (-0700) Subject: vk/image: Factor view creation out into separate *_init functions X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4668bbb16140816138366410ec28357ab5a43a39;p=mesa.git vk/image: Factor view creation out into separate *_init functions 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. --- diff --git a/src/vulkan/image.c b/src/vulkan/image.c index d5e74dc6594..cf658e969da 100644 --- a/src/vulkan/image.c +++ b/src/vulkan/image.c @@ -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; diff --git a/src/vulkan/private.h b/src/vulkan/private.h index 13be1b94791..7e935962742 100644 --- a/src/vulkan/private.h +++ b/src/vulkan/private.h @@ -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]; };