blob: 15015fa1ba28bafbfe2bceb8b730131e92b5f0ed [file] [log] [blame]
Alexis Hetu000df8b2018-10-24 15:22:41 -04001// 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#ifndef VK_PIPELINE_LAYOUT_HPP_
16#define VK_PIPELINE_LAYOUT_HPP_
17
Antonio Maiorano42fd1592020-04-27 11:30:40 -040018#include "VkConfig.hpp"
Alexis Hetu8c1e8f12019-02-15 16:41:12 -050019#include "VkDescriptorSetLayout.hpp"
Alexis Hetu000df8b2018-10-24 15:22:41 -040020
Nicolas Capens157ba262019-12-10 17:49:14 -050021namespace vk {
Alexis Hetu000df8b2018-10-24 15:22:41 -040022
23class PipelineLayout : public Object<PipelineLayout, VkPipelineLayout>
24{
25public:
Ben Clayton2ed93ab2019-12-17 20:38:03 +000026 PipelineLayout(const VkPipelineLayoutCreateInfo *pCreateInfo, void *mem);
27 void destroy(const VkAllocationCallbacks *pAllocator);
Trevor David Black3ad285a2020-05-26 19:28:05 +000028 bool release(const VkAllocationCallbacks *pAllocator);
Alexis Hetu000df8b2018-10-24 15:22:41 -040029
Ben Clayton2ed93ab2019-12-17 20:38:03 +000030 static size_t ComputeRequiredAllocationSize(const VkPipelineLayoutCreateInfo *pCreateInfo);
Alexis Hetu000df8b2018-10-24 15:22:41 -040031
Nicolas Capensc7d5ec32020-04-22 01:11:37 -040032 size_t getDescriptorSetCount() const;
Alexis Hetu4f438a52020-06-15 16:13:51 -040033 uint32_t getBindingCount(uint32_t setNumber) const;
Ben Clayton225a1302019-04-02 12:28:22 +010034
Nicolas Capensc7d5ec32020-04-22 01:11:37 -040035 // Returns the index into the pipeline's dynamic offsets array for
Nicolas Capens026f7d02020-04-23 23:44:57 -040036 // the given descriptor set and binding number.
Nicolas Capensc7d5ec32020-04-22 01:11:37 -040037 uint32_t getDynamicOffsetIndex(uint32_t setNumber, uint32_t bindingNumber) const;
Nicolas Capenseb682442020-06-01 15:24:52 -040038 uint32_t getDescriptorCount(uint32_t setNumber, uint32_t bindingNumber) const;
Nicolas Capensc7d5ec32020-04-22 01:11:37 -040039 uint32_t getBindingOffset(uint32_t setNumber, uint32_t bindingNumber) const;
40 VkDescriptorType getDescriptorType(uint32_t setNumber, uint32_t bindingNumber) const;
41 uint32_t getDescriptorSize(uint32_t setNumber, uint32_t bindingNumber) const;
42 bool isDescriptorDynamic(uint32_t setNumber, uint32_t bindingNumber) const;
Ben Clayton76e9bc02019-02-26 15:02:18 +000043
Nicolas Capens5ab1f362020-04-22 01:39:36 -040044 const uint32_t identifier;
45
Trevor David Black3ad285a2020-05-26 19:28:05 +000046 uint32_t incRefCount();
47 uint32_t decRefCount();
48
Alexis Hetu000df8b2018-10-24 15:22:41 -040049private:
Nicolas Capens026f7d02020-04-23 23:44:57 -040050 struct Binding
51 {
52 VkDescriptorType descriptorType;
Nicolas Capenseb682442020-06-01 15:24:52 -040053 uint32_t offset; // Offset in bytes in the descriptor set data.
54 uint32_t dynamicOffsetIndex;
55 uint32_t descriptorCount;
Nicolas Capens026f7d02020-04-23 23:44:57 -040056 };
57
58 struct DescriptorSet
59 {
60 Binding *bindings;
Nicolas Capens026f7d02020-04-23 23:44:57 -040061 uint32_t bindingCount;
62 };
63
64 DescriptorSet descriptorSets[MAX_BOUND_DESCRIPTOR_SETS];
Nicolas Capensc7d5ec32020-04-22 01:11:37 -040065
66 const uint32_t descriptorSetCount = 0;
Nicolas Capensc7d5ec32020-04-22 01:11:37 -040067 const uint32_t pushConstantRangeCount = 0;
Ben Clayton2ed93ab2019-12-17 20:38:03 +000068 VkPushConstantRange *pushConstantRanges = nullptr;
Trevor David Black3ad285a2020-05-26 19:28:05 +000069
70 std::atomic<uint32_t> refCount{ 0 };
Alexis Hetu000df8b2018-10-24 15:22:41 -040071};
72
Ben Clayton2ed93ab2019-12-17 20:38:03 +000073static inline PipelineLayout *Cast(VkPipelineLayout object)
Alexis Hetu000df8b2018-10-24 15:22:41 -040074{
Alexis Hetubd4cf812019-06-14 15:14:07 -040075 return PipelineLayout::Cast(object);
Alexis Hetu000df8b2018-10-24 15:22:41 -040076}
77
Nicolas Capens157ba262019-12-10 17:49:14 -050078} // namespace vk
Alexis Hetu000df8b2018-10-24 15:22:41 -040079
Ben Clayton2ed93ab2019-12-17 20:38:03 +000080#endif // VK_PIPELINE_LAYOUT_HPP_