OSDN Git Service

Implement indirect draws
[android-x86/external-swiftshader.git] / src / Vulkan / VkPipelineLayout.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 "VkPipelineLayout.hpp"
16 #include <cstring>
17
18 namespace vk
19 {
20
21 PipelineLayout::PipelineLayout(const VkPipelineLayoutCreateInfo* pCreateInfo, void* mem)
22         : setLayoutCount(pCreateInfo->setLayoutCount), pushConstantRangeCount(pCreateInfo->pushConstantRangeCount)
23 {
24         char* hostMem = reinterpret_cast<char*>(mem);
25
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;
30
31         size_t pushConstantRangesSize = pCreateInfo->pushConstantRangeCount * sizeof(VkPushConstantRange);
32         pushConstantRanges = reinterpret_cast<VkPushConstantRange*>(hostMem);
33         memcpy(pushConstantRanges, pCreateInfo->pPushConstantRanges, pushConstantRangesSize);
34 }
35
36 void PipelineLayout::destroy(const VkAllocationCallbacks* pAllocator)
37 {
38         vk::deallocate(setLayouts, pAllocator); // pushConstantRanges are in the same allocation
39 }
40
41 size_t PipelineLayout::ComputeRequiredAllocationSize(const VkPipelineLayoutCreateInfo* pCreateInfo)
42 {
43         return (pCreateInfo->setLayoutCount * sizeof(DescriptorSetLayout*)) +
44                (pCreateInfo->pushConstantRangeCount * sizeof(VkPushConstantRange));
45 }
46
47 size_t PipelineLayout::getNumDescriptorSets() const
48 {
49         return setLayoutCount;
50 }
51
52 size_t PipelineLayout::getBindingOffset(size_t descriptorSet, size_t binding) const
53 {
54         ASSERT(descriptorSet < setLayoutCount);
55         return setLayouts[descriptorSet]->getBindingOffset(binding);
56 }
57
58 } // namespace vk