Alexis Hetu | 000df8b | 2018-10-24 15:22:41 -0400 | [diff] [blame] | 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 | #ifndef VK_PIPELINE_LAYOUT_HPP_ |
| 16 | #define VK_PIPELINE_LAYOUT_HPP_ |
| 17 | |
Antonio Maiorano | 42fd159 | 2020-04-27 11:30:40 -0400 | [diff] [blame] | 18 | #include "VkConfig.hpp" |
Alexis Hetu | 8c1e8f1 | 2019-02-15 16:41:12 -0500 | [diff] [blame] | 19 | #include "VkDescriptorSetLayout.hpp" |
Alexis Hetu | 000df8b | 2018-10-24 15:22:41 -0400 | [diff] [blame] | 20 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 21 | namespace vk { |
Alexis Hetu | 000df8b | 2018-10-24 15:22:41 -0400 | [diff] [blame] | 22 | |
| 23 | class PipelineLayout : public Object<PipelineLayout, VkPipelineLayout> |
| 24 | { |
| 25 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 26 | PipelineLayout(const VkPipelineLayoutCreateInfo *pCreateInfo, void *mem); |
| 27 | void destroy(const VkAllocationCallbacks *pAllocator); |
Trevor David Black | 3ad285a | 2020-05-26 19:28:05 +0000 | [diff] [blame] | 28 | bool release(const VkAllocationCallbacks *pAllocator); |
Alexis Hetu | 000df8b | 2018-10-24 15:22:41 -0400 | [diff] [blame] | 29 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 30 | static size_t ComputeRequiredAllocationSize(const VkPipelineLayoutCreateInfo *pCreateInfo); |
Alexis Hetu | 000df8b | 2018-10-24 15:22:41 -0400 | [diff] [blame] | 31 | |
Nicolas Capens | c7d5ec3 | 2020-04-22 01:11:37 -0400 | [diff] [blame] | 32 | size_t getDescriptorSetCount() const; |
Alexis Hetu | 4f438a5 | 2020-06-15 16:13:51 -0400 | [diff] [blame] | 33 | uint32_t getBindingCount(uint32_t setNumber) const; |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 34 | |
Nicolas Capens | c7d5ec3 | 2020-04-22 01:11:37 -0400 | [diff] [blame] | 35 | // Returns the index into the pipeline's dynamic offsets array for |
Nicolas Capens | 026f7d0 | 2020-04-23 23:44:57 -0400 | [diff] [blame] | 36 | // the given descriptor set and binding number. |
Nicolas Capens | c7d5ec3 | 2020-04-22 01:11:37 -0400 | [diff] [blame] | 37 | uint32_t getDynamicOffsetIndex(uint32_t setNumber, uint32_t bindingNumber) const; |
Nicolas Capens | eb68244 | 2020-06-01 15:24:52 -0400 | [diff] [blame] | 38 | uint32_t getDescriptorCount(uint32_t setNumber, uint32_t bindingNumber) const; |
Nicolas Capens | c7d5ec3 | 2020-04-22 01:11:37 -0400 | [diff] [blame] | 39 | 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 Clayton | 76e9bc0 | 2019-02-26 15:02:18 +0000 | [diff] [blame] | 43 | |
Nicolas Capens | 5ab1f36 | 2020-04-22 01:39:36 -0400 | [diff] [blame] | 44 | const uint32_t identifier; |
| 45 | |
Trevor David Black | 3ad285a | 2020-05-26 19:28:05 +0000 | [diff] [blame] | 46 | uint32_t incRefCount(); |
| 47 | uint32_t decRefCount(); |
| 48 | |
Alexis Hetu | 000df8b | 2018-10-24 15:22:41 -0400 | [diff] [blame] | 49 | private: |
Nicolas Capens | 026f7d0 | 2020-04-23 23:44:57 -0400 | [diff] [blame] | 50 | struct Binding |
| 51 | { |
| 52 | VkDescriptorType descriptorType; |
Nicolas Capens | eb68244 | 2020-06-01 15:24:52 -0400 | [diff] [blame] | 53 | uint32_t offset; // Offset in bytes in the descriptor set data. |
| 54 | uint32_t dynamicOffsetIndex; |
| 55 | uint32_t descriptorCount; |
Nicolas Capens | 026f7d0 | 2020-04-23 23:44:57 -0400 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | struct DescriptorSet |
| 59 | { |
| 60 | Binding *bindings; |
Nicolas Capens | 026f7d0 | 2020-04-23 23:44:57 -0400 | [diff] [blame] | 61 | uint32_t bindingCount; |
| 62 | }; |
| 63 | |
| 64 | DescriptorSet descriptorSets[MAX_BOUND_DESCRIPTOR_SETS]; |
Nicolas Capens | c7d5ec3 | 2020-04-22 01:11:37 -0400 | [diff] [blame] | 65 | |
| 66 | const uint32_t descriptorSetCount = 0; |
Nicolas Capens | c7d5ec3 | 2020-04-22 01:11:37 -0400 | [diff] [blame] | 67 | const uint32_t pushConstantRangeCount = 0; |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 68 | VkPushConstantRange *pushConstantRanges = nullptr; |
Trevor David Black | 3ad285a | 2020-05-26 19:28:05 +0000 | [diff] [blame] | 69 | |
| 70 | std::atomic<uint32_t> refCount{ 0 }; |
Alexis Hetu | 000df8b | 2018-10-24 15:22:41 -0400 | [diff] [blame] | 71 | }; |
| 72 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 73 | static inline PipelineLayout *Cast(VkPipelineLayout object) |
Alexis Hetu | 000df8b | 2018-10-24 15:22:41 -0400 | [diff] [blame] | 74 | { |
Alexis Hetu | bd4cf81 | 2019-06-14 15:14:07 -0400 | [diff] [blame] | 75 | return PipelineLayout::Cast(object); |
Alexis Hetu | 000df8b | 2018-10-24 15:22:41 -0400 | [diff] [blame] | 76 | } |
| 77 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 78 | } // namespace vk |
Alexis Hetu | 000df8b | 2018-10-24 15:22:41 -0400 | [diff] [blame] | 79 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 80 | #endif // VK_PIPELINE_LAYOUT_HPP_ |