3 * Copyright © 2016 Red Hat.
4 * Copyright © 2016 Bas Nieuwenhuizen
6 * based in part on anv driver which is:
7 * Copyright © 2015 Intel Corporation
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice (including the next
17 * paragraph) shall be included in all copies or substantial portions of the
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30 #include "libresoc_private.h"
34 libresoc_image_create(VkDevice _device
,
35 const struct libresoc_image_create_info
*create_info
,
36 const VkAllocationCallbacks
* alloc
,
39 LIBRESOC_FROM_HANDLE(libresoc_device
, device
, _device
);
40 const VkImageCreateInfo
*pCreateInfo
= create_info
->vk_info
;
41 struct libresoc_image
*image
= NULL
;
42 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
);
44 // const unsigned plane_count = vk_format_get_plane_count(format);
45 // const size_t image_struct_size = sizeof(*image) + sizeof(struct libresoc_image_plane) * plane_count;
47 const size_t image_struct_size
= sizeof(*image
);
48 // libresoc_assert(pCreateInfo->mipLevels > 0);
49 // libresoc_assert(pCreateInfo->arrayLayers > 0);
50 // libresoc_assert(pCreateInfo->samples > 0);
51 // libresoc_assert(pCreateInfo->extent.width > 0);
52 // libresoc_assert(pCreateInfo->extent.height > 0);
53 // libresoc_assert(pCreateInfo->extent.depth > 0);
55 image
= vk_zalloc2(&device
->vk
.alloc
, alloc
, image_struct_size
, 8,
56 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
58 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
60 vk_object_base_init(&device
->vk
, &image
->base
, VK_OBJECT_TYPE_IMAGE
);
62 image
->type
= pCreateInfo
->imageType
;
63 image
->size
= pCreateInfo
->extent
.width
* pCreateInfo
->extent
.height
* 4;
64 image
->width
= pCreateInfo
->extent
.width
;
65 image
->height
= pCreateInfo
->extent
.height
;
66 // image->info.depth = pCreateInfo->extent.depth;
67 // image->info.samples = pCreateInfo->samples;
68 // image->info.storage_samples = pCreateInfo->samples;
69 // image->info.array_size = pCreateInfo->arrayLayers;
70 // image->info.levels = pCreateInfo->mipLevels;
71 // image->info.num_channels = vk_format_get_nr_components(format);
73 //image->vk_format = format;
74 image
->tiling
= pCreateInfo
->tiling
;
75 image
->usage
= pCreateInfo
->usage
;
76 image
->flags
= pCreateInfo
->flags
;
77 //image->plane_count = plane_count;
79 image
->exclusive
= pCreateInfo
->sharingMode
== VK_SHARING_MODE_EXCLUSIVE
;
80 // if (pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT) {
81 // for (uint32_t i = 0; i < pCreateInfo->queueFamilyIndexCount; ++i)
82 // if (pCreateInfo->pQueueFamilyIndices[i] == VK_QUEUE_FAMILY_EXTERNAL ||
83 // pCreateInfo->pQueueFamilyIndices[i] == VK_QUEUE_FAMILY_FOREIGN_EXT)
84 // image->queue_family_mask |= (1u << LIBRESOC_MAX_QUEUE_FAMILIES) - 1u;
86 // image->queue_family_mask |= 1u << pCreateInfo->pQueueFamilyIndices[i];
89 // const VkExternalMemoryImageCreateInfo *external_info =
90 // vk_find_struct_const(pCreateInfo->pNext,
91 // EXTERNAL_MEMORY_IMAGE_CREATE_INFO) ;
93 // image->shareable = external_info;
94 // if (!vk_format_is_depth_or_stencil(format) && !image->shareable) {
95 // image->info.surf_index = &device->image_mrt_offset_counter;
98 // for (unsigned plane = 0; plane < image->plane_count; ++plane) {
99 // image->planes[plane].surface.flags =
100 // libresoc_get_surface_flags(device, image, plane, pCreateInfo, format);
103 // bool delay_layout = external_info &&
104 // (external_info->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID);
106 // if (delay_layout) {
107 // *pImage = libresoc_image_to_handle(image);
108 // assert (!(image->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT));
109 // return VK_SUCCESS;
112 // ASSERTED VkResult result = libresoc_image_create_layout(device, *create_info, image);
113 // assert(result == VK_SUCCESS);
115 // if (image->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) {
116 // image->alignment = MAX2(image->alignment, 4096);
117 // image->size = align64(image->size, image->alignment);
118 // image->offset = 0;
120 // image->bo = device->ws->buffer_create(device->ws, image->size, image->alignment,
121 // 0, RADEON_FLAG_VIRTUAL, LIBRESOC_BO_PRIORITY_VIRTUAL);
123 // libresoc_destroy_image(device, alloc, image);
124 // return vk_error(device->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY);
128 *pImage
= libresoc_image_to_handle(image
);
135 libresoc_CreateImage(VkDevice device
,
136 const VkImageCreateInfo
*pCreateInfo
,
137 const VkAllocationCallbacks
*pAllocator
,
141 const struct wsi_image_create_info
*wsi_info
=
142 vk_find_struct_const(pCreateInfo
->pNext
, WSI_IMAGE_CREATE_INFO_MESA
);
143 bool scanout
= wsi_info
&& wsi_info
->scanout
;
145 return libresoc_image_create(device
,
146 &(struct libresoc_image_create_info
) {
147 .vk_info
= pCreateInfo
,
153 void libresoc_GetImageSubresourceLayout(
156 const VkImageSubresource
* pSubresource
,
157 VkSubresourceLayout
* pLayout
)
159 LIBRESOC_FROM_HANDLE(libresoc_image
, image
, _image
);
161 pLayout
->size
= image
->size
;
162 pLayout
->rowPitch
= image
->width
;
166 libresoc_CreateImageView(VkDevice _device
,
167 const VkImageViewCreateInfo
*pCreateInfo
,
168 const VkAllocationCallbacks
*pAllocator
,
173 // LIBRESOC_FROM_HANDLE(libresoc_device, device, _device);
174 // struct libresoc_image_view *view;
176 // view = vk_alloc2(&device->vk.alloc, pAllocator, sizeof(*view), 8,
177 // VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
179 // return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
181 // vk_object_base_init(&device->vk, &view->base,
182 // VK_OBJECT_TYPE_IMAGE_VIEW);
184 // libresoc_image_view_init(view, device, pCreateInfo, NULL);
186 // *pView = libresoc_image_view_to_handle(view);
188 // return VK_SUCCESS;
191 libresoc_DestroyImage(VkDevice _device
, VkImage _image
,
192 const VkAllocationCallbacks
*pAllocator
)
198 libresoc_DestroyImageView(VkDevice _device
, VkImageView _iview
,
199 const VkAllocationCallbacks
*pAllocator
)