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 "VkPipelineLayout.hpp"
21 PipelineLayout::PipelineLayout(const VkPipelineLayoutCreateInfo* pCreateInfo, void* mem)
22 : setLayoutCount(pCreateInfo->setLayoutCount), pushConstantRangeCount(pCreateInfo->pushConstantRangeCount)
24 char* hostMem = reinterpret_cast<char*>(mem);
26 size_t setLayoutsSize = pCreateInfo->setLayoutCount * sizeof(DescriptorSetLayout*);
27 setLayouts = reinterpret_cast<DescriptorSetLayout**>(hostMem);
28 memcpy(setLayouts, pCreateInfo->pSetLayouts, setLayoutsSize); // Assumes Cast(VkDescriptorSetLayout) is nothing but a cast
29 hostMem += setLayoutsSize;
31 size_t pushConstantRangesSize = pCreateInfo->pushConstantRangeCount * sizeof(VkPushConstantRange);
32 pushConstantRanges = reinterpret_cast<VkPushConstantRange*>(hostMem);
33 memcpy(pushConstantRanges, pCreateInfo->pPushConstantRanges, pushConstantRangesSize);
36 void PipelineLayout::destroy(const VkAllocationCallbacks* pAllocator)
38 vk::deallocate(setLayouts, pAllocator); // pushConstantRanges are in the same allocation
41 size_t PipelineLayout::ComputeRequiredAllocationSize(const VkPipelineLayoutCreateInfo* pCreateInfo)
43 return (pCreateInfo->setLayoutCount * sizeof(DescriptorSetLayout*)) +
44 (pCreateInfo->pushConstantRangeCount * sizeof(VkPushConstantRange));
47 size_t PipelineLayout::getNumDescriptorSets() const
49 return setLayoutCount;
52 size_t PipelineLayout::getBindingOffset(size_t descriptorSet, size_t binding) const
54 ASSERT(descriptorSet < setLayoutCount);
55 return setLayouts[descriptorSet]->getBindingOffset(binding);