OSDN Git Service

Implement indirect draws
[android-x86/external-swiftshader.git] / src / Vulkan / VkDescriptorUpdateTemplate.cpp
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 "VkDescriptorSetLayout.hpp"
17 #include <cstring>
18
19 namespace vk
20 {
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
25         {\r
26                 for(uint32_t i = 0; i < descriptorUpdateEntryCount; i++)\r
27                 {\r
28                         descriptorUpdateEntries[i] = pCreateInfo->pDescriptorUpdateEntries[i];\r
29                 }\r
30         }\r
31 \r
32         size_t DescriptorUpdateTemplate::ComputeRequiredAllocationSize(const VkDescriptorUpdateTemplateCreateInfo* info)\r
33         {\r
34                 return info->descriptorUpdateEntryCount * sizeof(VkDescriptorUpdateTemplateEntry);\r
35         }\r
36 \r
37         void DescriptorUpdateTemplate::updateDescriptorSet(VkDescriptorSet descriptorSet, const void* pData)\r
38         {
39                 for(uint32_t i = 0; i < descriptorUpdateEntryCount; i++)
40                 {
41                         for(uint32_t j = 0; j < descriptorUpdateEntries[i].descriptorCount; j++)
42                         {
43                                 const char *memToRead = (const char *)pData + descriptorUpdateEntries[i].offset + j * descriptorUpdateEntries[i].stride;
44                                 size_t typeSize = 0;
45                                 uint8_t* memToWrite = descriptorSetLayout->getOffsetPointer(
46                                         descriptorSet, descriptorUpdateEntries[i].dstBinding, descriptorUpdateEntries[i].dstArrayElement, 1, &typeSize);
47                                 memcpy(memToWrite, memToRead, typeSize);
48                         }
49                 }\r
50         }
51 }