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->info.width = pCreateInfo->extent.width;
64 // image->info.height = pCreateInfo->extent.height;
65 // image->info.depth = pCreateInfo->extent.depth;
66 // image->info.samples = pCreateInfo->samples;
67 // image->info.storage_samples = pCreateInfo->samples;
68 // image->info.array_size = pCreateInfo->arrayLayers;
69 // image->info.levels = pCreateInfo->mipLevels;
70 // image->info.num_channels = vk_format_get_nr_components(format);
72 //image->vk_format = format;
73 image
->tiling
= pCreateInfo
->tiling
;
74 image
->usage
= pCreateInfo
->usage
;
75 image
->flags
= pCreateInfo
->flags
;
76 //image->plane_count = plane_count;
78 image
->exclusive
= pCreateInfo
->sharingMode
== VK_SHARING_MODE_EXCLUSIVE
;
79 // if (pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT) {
80 // for (uint32_t i = 0; i < pCreateInfo->queueFamilyIndexCount; ++i)
81 // if (pCreateInfo->pQueueFamilyIndices[i] == VK_QUEUE_FAMILY_EXTERNAL ||
82 // pCreateInfo->pQueueFamilyIndices[i] == VK_QUEUE_FAMILY_FOREIGN_EXT)
83 // image->queue_family_mask |= (1u << LIBRESOC_MAX_QUEUE_FAMILIES) - 1u;
85 // image->queue_family_mask |= 1u << pCreateInfo->pQueueFamilyIndices[i];
88 // const VkExternalMemoryImageCreateInfo *external_info =
89 // vk_find_struct_const(pCreateInfo->pNext,
90 // EXTERNAL_MEMORY_IMAGE_CREATE_INFO) ;
92 // image->shareable = external_info;
93 // if (!vk_format_is_depth_or_stencil(format) && !image->shareable) {
94 // image->info.surf_index = &device->image_mrt_offset_counter;
97 // for (unsigned plane = 0; plane < image->plane_count; ++plane) {
98 // image->planes[plane].surface.flags =
99 // libresoc_get_surface_flags(device, image, plane, pCreateInfo, format);
102 // bool delay_layout = external_info &&
103 // (external_info->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID);
105 // if (delay_layout) {
106 // *pImage = libresoc_image_to_handle(image);
107 // assert (!(image->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT));
108 // return VK_SUCCESS;
111 // ASSERTED VkResult result = libresoc_image_create_layout(device, *create_info, image);
112 // assert(result == VK_SUCCESS);
114 // if (image->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) {
115 // image->alignment = MAX2(image->alignment, 4096);
116 // image->size = align64(image->size, image->alignment);
117 // image->offset = 0;
119 // image->bo = device->ws->buffer_create(device->ws, image->size, image->alignment,
120 // 0, RADEON_FLAG_VIRTUAL, LIBRESOC_BO_PRIORITY_VIRTUAL);
122 // libresoc_destroy_image(device, alloc, image);
123 // return vk_error(device->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY);
127 *pImage
= libresoc_image_to_handle(image
);
134 libresoc_CreateImage(VkDevice device
,
135 const VkImageCreateInfo
*pCreateInfo
,
136 const VkAllocationCallbacks
*pAllocator
,
140 const struct wsi_image_create_info
*wsi_info
=
141 vk_find_struct_const(pCreateInfo
->pNext
, WSI_IMAGE_CREATE_INFO_MESA
);
142 bool scanout
= wsi_info
&& wsi_info
->scanout
;
144 return libresoc_image_create(device
,
145 &(struct libresoc_image_create_info
) {
146 .vk_info
= pCreateInfo
,
152 void libresoc_GetImageSubresourceLayout(
155 const VkImageSubresource
* pSubresource
,
156 VkSubresourceLayout
* pLayout
)