1 /*
2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
25 #include <stdlib.h>
26 #include <string.h>
27 #include "vk_descriptors.h"
28 #include "vk_common_entrypoints.h"
29 #include "util/macros.h"
30
31 static int
binding_compare(const void * av,const void * bv)32 binding_compare(const void* av, const void *bv)
33 {
34 const VkDescriptorSetLayoutBinding *a = (const VkDescriptorSetLayoutBinding*)av;
35 const VkDescriptorSetLayoutBinding *b = (const VkDescriptorSetLayoutBinding*)bv;
36
37 return (a->binding < b->binding) ? -1 : (a->binding > b->binding) ? 1 : 0;
38 }
39
40 VkResult
vk_create_sorted_bindings(const VkDescriptorSetLayoutBinding * bindings,unsigned count,VkDescriptorSetLayoutBinding ** sorted_bindings)41 vk_create_sorted_bindings(const VkDescriptorSetLayoutBinding *bindings, unsigned count,
42 VkDescriptorSetLayoutBinding **sorted_bindings)
43 {
44 if (!count) {
45 *sorted_bindings = NULL;
46 return VK_SUCCESS;
47 }
48
49 *sorted_bindings = malloc(count * sizeof(VkDescriptorSetLayoutBinding));
50 if (!*sorted_bindings)
51 return VK_ERROR_OUT_OF_HOST_MEMORY;
52
53 memcpy(*sorted_bindings, bindings, count * sizeof(VkDescriptorSetLayoutBinding));
54 qsort(*sorted_bindings, count, sizeof(VkDescriptorSetLayoutBinding), binding_compare);
55
56 return VK_SUCCESS;
57 }
58
59 /*
60 * For drivers that don't have mutable state in buffers, images, image views, or
61 * samplers, there's no need to save/restore anything to get the same
62 * descriptor back as long as the user uses the same GPU virtual address. In
63 * this case, the following EXT_descriptor_buffer functions are trivial.
64 */
65 VKAPI_ATTR VkResult VKAPI_CALL
vk_common_GetBufferOpaqueCaptureDescriptorDataEXT(VkDevice device,const VkBufferCaptureDescriptorDataInfoEXT * pInfo,void * pData)66 vk_common_GetBufferOpaqueCaptureDescriptorDataEXT(VkDevice device,
67 const VkBufferCaptureDescriptorDataInfoEXT *pInfo,
68 void *pData)
69 {
70 return VK_SUCCESS;
71 }
72
73 VKAPI_ATTR VkResult VKAPI_CALL
vk_common_GetImageOpaqueCaptureDescriptorDataEXT(VkDevice device,const VkImageCaptureDescriptorDataInfoEXT * pInfo,void * pData)74 vk_common_GetImageOpaqueCaptureDescriptorDataEXT(VkDevice device,
75 const VkImageCaptureDescriptorDataInfoEXT *pInfo,
76 void *pData)
77 {
78 return VK_SUCCESS;
79 }
80
81 VKAPI_ATTR VkResult VKAPI_CALL
vk_common_GetImageViewOpaqueCaptureDescriptorDataEXT(VkDevice device,const VkImageViewCaptureDescriptorDataInfoEXT * pInfo,void * pData)82 vk_common_GetImageViewOpaqueCaptureDescriptorDataEXT(VkDevice device,
83 const VkImageViewCaptureDescriptorDataInfoEXT *pInfo,
84 void *pData)
85 {
86 return VK_SUCCESS;
87 }
88
89 VKAPI_ATTR VkResult VKAPI_CALL
vk_common_GetSamplerOpaqueCaptureDescriptorDataEXT(VkDevice _device,const VkSamplerCaptureDescriptorDataInfoEXT * pInfo,void * pData)90 vk_common_GetSamplerOpaqueCaptureDescriptorDataEXT(VkDevice _device,
91 const VkSamplerCaptureDescriptorDataInfoEXT *pInfo,
92 void *pData)
93 {
94 return VK_SUCCESS;
95 }
96
97 VKAPI_ATTR VkResult VKAPI_CALL
vk_common_GetAccelerationStructureOpaqueCaptureDescriptorDataEXT(VkDevice device,const VkAccelerationStructureCaptureDescriptorDataInfoEXT * pInfo,void * pData)98 vk_common_GetAccelerationStructureOpaqueCaptureDescriptorDataEXT(VkDevice device,
99 const VkAccelerationStructureCaptureDescriptorDataInfoEXT *pInfo,
100 void *pData)
101 {
102 return VK_SUCCESS;
103 }
104