• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2017 Intel Corporation
3  * Copyright © 2022 Collabora, Ltd
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 "vk_descriptor_update_template.h"
26 
27 #include "vk_common_entrypoints.h"
28 #include "vk_device.h"
29 #include "vk_log.h"
30 
31 VKAPI_ATTR VkResult VKAPI_CALL
vk_common_CreateDescriptorUpdateTemplate(VkDevice _device,const VkDescriptorUpdateTemplateCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDescriptorUpdateTemplate * pDescriptorUpdateTemplate)32 vk_common_CreateDescriptorUpdateTemplate(VkDevice _device,
33    const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
34    const VkAllocationCallbacks *pAllocator,
35    VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate)
36 {
37    VK_FROM_HANDLE(vk_device, device, _device);
38    struct vk_descriptor_update_template *template;
39 
40    uint32_t entry_count = 0;
41    for (uint32_t i = 0; i < pCreateInfo->descriptorUpdateEntryCount; i++) {
42       if (pCreateInfo->pDescriptorUpdateEntries[i].descriptorCount > 0)
43          entry_count++;
44    }
45 
46    size_t size = sizeof(*template) + entry_count * sizeof(template->entries[0]);
47    template = vk_object_alloc(device, pAllocator, size,
48                               VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE);
49    if (template == NULL)
50       return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
51 
52    template->type = pCreateInfo->templateType;
53    template->bind_point = pCreateInfo->pipelineBindPoint;
54 
55    if (template->type == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET)
56       template->set = pCreateInfo->set;
57 
58    uint32_t entry_idx = 0;
59    template->entry_count = entry_count;
60    for (uint32_t i = 0; i < pCreateInfo->descriptorUpdateEntryCount; i++) {
61       const VkDescriptorUpdateTemplateEntry *pEntry =
62          &pCreateInfo->pDescriptorUpdateEntries[i];
63 
64       if (pEntry->descriptorCount == 0)
65          continue;
66 
67       template->entries[entry_idx++] = (struct vk_descriptor_template_entry) {
68          .type = pEntry->descriptorType,
69          .binding = pEntry->dstBinding,
70          .array_element = pEntry->dstArrayElement,
71          .array_count = pEntry->descriptorCount,
72          .offset = pEntry->offset,
73          .stride = pEntry->stride,
74       };
75    }
76    assert(entry_idx == entry_count);
77 
78    *pDescriptorUpdateTemplate =
79       vk_descriptor_update_template_to_handle(template);
80 
81    return VK_SUCCESS;
82 }
83 
84 VKAPI_ATTR void VKAPI_CALL
vk_common_DestroyDescriptorUpdateTemplate(VkDevice _device,VkDescriptorUpdateTemplate descriptorUpdateTemplate,const VkAllocationCallbacks * pAllocator)85 vk_common_DestroyDescriptorUpdateTemplate(VkDevice _device,
86    VkDescriptorUpdateTemplate descriptorUpdateTemplate,
87    const VkAllocationCallbacks *pAllocator)
88 {
89    VK_FROM_HANDLE(vk_device, device, _device);
90    VK_FROM_HANDLE(vk_descriptor_update_template, template,
91                   descriptorUpdateTemplate);
92 
93    if (!template)
94       return;
95 
96    vk_object_free(device, pAllocator, template);
97 }
98