1 | // Copyright 2018 The SwiftShader Authors. All Rights Reserved. |
2 | // |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | // you may not use this file except in compliance with the License. |
5 | // You may obtain a copy of the License at |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // Unless required by applicable law or agreed to in writing, software |
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | // See the License for the specific language governing permissions and |
13 | // limitations under the License. |
14 | |
15 | #include "VkDescriptorUpdateTemplate.hpp" |
16 | #include "VkDescriptorSet.hpp" |
17 | #include "VkDescriptorSetLayout.hpp" |
18 | #include <cstring> |
19 | |
20 | namespace vk |
21 | { |
22 | DescriptorUpdateTemplate::DescriptorUpdateTemplate(const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo, void* mem) : |
23 | descriptorUpdateEntryCount(pCreateInfo->descriptorUpdateEntryCount), |
24 | descriptorUpdateEntries(reinterpret_cast<VkDescriptorUpdateTemplateEntry*>(mem)), |
25 | descriptorSetLayout(vk::Cast(pCreateInfo->descriptorSetLayout)) |
26 | { |
27 | for(uint32_t i = 0; i < descriptorUpdateEntryCount; i++) |
28 | { |
29 | descriptorUpdateEntries[i] = pCreateInfo->pDescriptorUpdateEntries[i]; |
30 | } |
31 | } |
32 | |
33 | size_t DescriptorUpdateTemplate::ComputeRequiredAllocationSize(const VkDescriptorUpdateTemplateCreateInfo* info) |
34 | { |
35 | return info->descriptorUpdateEntryCount * sizeof(VkDescriptorUpdateTemplateEntry); |
36 | } |
37 | |
38 | void DescriptorUpdateTemplate::updateDescriptorSet(Device* device, VkDescriptorSet vkDescriptorSet, const void* pData) |
39 | { |
40 | |
41 | DescriptorSet* descriptorSet = vk::Cast(vkDescriptorSet); |
42 | |
43 | for(uint32_t i = 0; i < descriptorUpdateEntryCount; i++) |
44 | { |
45 | DescriptorSetLayout::WriteDescriptorSet(device, descriptorSet, descriptorUpdateEntries[i], |
46 | reinterpret_cast<char const *>(pData)); |
47 | } |
48 | } |
49 | } |