blob: 8c8a600a1d87438b52b442f4ffa5ea77fed23577 [file] [log] [blame]
Alexis Hetuc8176632019-01-22 17:01:28 -05001// 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_DESCRIPTOR_POOL_HPP_
16#define VK_DESCRIPTOR_POOL_HPP_
17
18#include "VkObject.hpp"
19#include <set>
20
21namespace vk
22{
23 class DescriptorPool : public Object<DescriptorPool, VkDescriptorPool>
24 {
25 public:
26 DescriptorPool(const VkDescriptorPoolCreateInfo* pCreateInfo, void* mem);
Alexis Hetuc8176632019-01-22 17:01:28 -050027 void destroy(const VkAllocationCallbacks* pAllocator);
28
29 static size_t ComputeRequiredAllocationSize(const VkDescriptorPoolCreateInfo* pCreateInfo);
30
31 VkResult allocateSets(uint32_t descriptorSetCount, const VkDescriptorSetLayout* pSetLayouts, VkDescriptorSet* pDescriptorSets);
32 void freeSets(uint32_t descriptorSetCount, const VkDescriptorSet* pDescriptorSets);
33 VkResult reset();
34
35 private:
36 VkResult allocateSets(size_t* sizes, uint32_t numAllocs, VkDescriptorSet* pDescriptorSets);
Alexis Hetu2d77aea2019-06-17 13:43:50 -040037 uint8_t* findAvailableMemory(size_t size);
Alexis Hetuc8176632019-01-22 17:01:28 -050038 void freeSet(const VkDescriptorSet descriptorSet);
39 size_t computeTotalFreeSize() const;
40
41 struct Node
42 {
Alexis Hetu2d77aea2019-06-17 13:43:50 -040043 Node(uint8_t* set, size_t size) : set(set), size(size) {}
Alexis Hetu126bd7a2019-05-10 17:07:42 -040044 bool operator<(const Node& node) const { return set < node.set; }
Alexis Hetu2d77aea2019-06-17 13:43:50 -040045 bool operator==(const uint8_t* other) const { return set == other; }
Alexis Hetuc8176632019-01-22 17:01:28 -050046
Alexis Hetu2d77aea2019-06-17 13:43:50 -040047 uint8_t* set = nullptr;
Alexis Hetu67cf8a92019-05-09 17:46:07 -040048 size_t size = 0;
Alexis Hetuc8176632019-01-22 17:01:28 -050049 };
50 std::set<Node> nodes;
51
Alexis Hetu2d77aea2019-06-17 13:43:50 -040052 uint8_t* pool = nullptr;
Alexis Hetuc8176632019-01-22 17:01:28 -050053 size_t poolSize = 0;
54 };
55
56 static inline DescriptorPool* Cast(VkDescriptorPool object)
57 {
Alexis Hetubd4cf812019-06-14 15:14:07 -040058 return DescriptorPool::Cast(object);
Alexis Hetuc8176632019-01-22 17:01:28 -050059 }
60
61} // namespace vk
62
63#endif // VK_DESCRIPTOR_POOL_HPP_