1 // Copyright 2018 The SwiftShader Authors. All Rights Reserved.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 #include "VkDescriptorUpdateTemplate.hpp"
16 #include "VkDescriptorSetLayout.hpp"
21 DescriptorUpdateTemplate::DescriptorUpdateTemplate(const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo, void* mem) :
\r
22 descriptorUpdateEntryCount(pCreateInfo->descriptorUpdateEntryCount),
\r
23 descriptorUpdateEntries(reinterpret_cast<VkDescriptorUpdateTemplateEntry*>(mem)),
\r
24 descriptorSetLayout(Cast(pCreateInfo->descriptorSetLayout))
\r
26 for(uint32_t i = 0; i < descriptorUpdateEntryCount; i++)
\r
28 descriptorUpdateEntries[i] = pCreateInfo->pDescriptorUpdateEntries[i];
\r
32 size_t DescriptorUpdateTemplate::ComputeRequiredAllocationSize(const VkDescriptorUpdateTemplateCreateInfo* info)
\r
34 return info->descriptorUpdateEntryCount * sizeof(VkDescriptorUpdateTemplateEntry);
\r
37 void DescriptorUpdateTemplate::updateDescriptorSet(VkDescriptorSet descriptorSet, const void* pData)
\r
39 for(uint32_t i = 0; i < descriptorUpdateEntryCount; i++)
41 for(uint32_t j = 0; j < descriptorUpdateEntries[i].descriptorCount; j++)
43 const char *memToRead = (const char *)pData + descriptorUpdateEntries[i].offset + j * descriptorUpdateEntries[i].stride;
45 uint8_t* memToWrite = descriptorSetLayout->getOffsetPointer(
46 descriptorSet, descriptorUpdateEntries[i].dstBinding, descriptorUpdateEntries[i].dstArrayElement, 1, &typeSize);
47 memcpy(memToWrite, memToRead, typeSize);