4778d4cd47185918cbd415b1d637a50afe47bbbd
[mesa.git] / src / libre-soc / vulkan / libresoc_image.c
1
2 /*
3 * Copyright © 2016 Red Hat.
4 * Copyright © 2016 Bas Nieuwenhuizen
5 *
6 * based in part on anv driver which is:
7 * Copyright © 2015 Intel Corporation
8 *
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:
15 *
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
18 * Software.
19 *
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
26 * IN THE SOFTWARE.
27 */
28
29 #include "vk_util.h"
30 #include "libresoc_private.h"
31
32
33 VkResult
34 libresoc_image_create(VkDevice _device,
35 const struct libresoc_image_create_info *create_info,
36 const VkAllocationCallbacks* alloc,
37 VkImage *pImage)
38 {
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);
43
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;
46
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);
54
55 image = vk_zalloc2(&device->vk.alloc, alloc, image_struct_size, 8,
56 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
57 if (!image)
58 return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
59
60 vk_object_base_init(&device->vk, &image->base, VK_OBJECT_TYPE_IMAGE);
61
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);
71
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;
77
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;
84 // else
85 // image->queue_family_mask |= 1u << pCreateInfo->pQueueFamilyIndices[i];
86 // }
87
88 // const VkExternalMemoryImageCreateInfo *external_info =
89 // vk_find_struct_const(pCreateInfo->pNext,
90 // EXTERNAL_MEMORY_IMAGE_CREATE_INFO) ;
91
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;
95 // }
96
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);
100 // }
101
102 // bool delay_layout = external_info &&
103 // (external_info->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID);
104
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;
109 // }
110
111 // ASSERTED VkResult result = libresoc_image_create_layout(device, *create_info, image);
112 // assert(result == VK_SUCCESS);
113
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;
118
119 // image->bo = device->ws->buffer_create(device->ws, image->size, image->alignment,
120 // 0, RADEON_FLAG_VIRTUAL, LIBRESOC_BO_PRIORITY_VIRTUAL);
121 // if (!image->bo) {
122 // libresoc_destroy_image(device, alloc, image);
123 // return vk_error(device->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY);
124 // }
125 // }
126
127 *pImage = libresoc_image_to_handle(image);
128
129 return VK_SUCCESS;
130 }
131
132
133 VkResult
134 libresoc_CreateImage(VkDevice device,
135 const VkImageCreateInfo *pCreateInfo,
136 const VkAllocationCallbacks *pAllocator,
137 VkImage *pImage)
138 {
139
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;
143
144 return libresoc_image_create(device,
145 &(struct libresoc_image_create_info) {
146 .vk_info = pCreateInfo,
147 .scanout = scanout,
148 },
149 pAllocator,
150 pImage);
151 }
152 void libresoc_GetImageSubresourceLayout(
153 VkDevice _device,
154 VkImage _image,
155 const VkImageSubresource* pSubresource,
156 VkSubresourceLayout* pLayout)
157 {
158 //TODO: stub
159 }
160
161 VkResult
162 libresoc_CreateImageView(VkDevice _device,
163 const VkImageViewCreateInfo *pCreateInfo,
164 const VkAllocationCallbacks *pAllocator,
165 VkImageView *pView)
166 {
167 //TODO: stub
168 return VK_SUCCESS;
169 // LIBRESOC_FROM_HANDLE(libresoc_device, device, _device);
170 // struct libresoc_image_view *view;
171
172 // view = vk_alloc2(&device->vk.alloc, pAllocator, sizeof(*view), 8,
173 // VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
174 // if (view == NULL)
175 // return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
176
177 // vk_object_base_init(&device->vk, &view->base,
178 // VK_OBJECT_TYPE_IMAGE_VIEW);
179
180 // libresoc_image_view_init(view, device, pCreateInfo, NULL);
181
182 // *pView = libresoc_image_view_to_handle(view);
183
184 // return VK_SUCCESS;
185 }
186 void
187 libresoc_DestroyImage(VkDevice _device, VkImage _image,
188 const VkAllocationCallbacks *pAllocator)
189 {
190
191 }
192
193 void
194 libresoc_DestroyImageView(VkDevice _device, VkImageView _iview,
195 const VkAllocationCallbacks *pAllocator)
196 {}