1 // Copyright 2019 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_SET_HPP_
16 #define VK_DESCRIPTOR_SET_HPP_
17
18 #include "VkObject.hpp"
19 #include "marl/mutex.h"
20
21 #include <array>
22 #include <cstdint>
23 #include <memory>
24
25 namespace vk {
26
27 class DescriptorSetLayout;
28 class Device;
29 class PipelineLayout;
30
31 struct alignas(16) DescriptorSetHeader
32 {
33 DescriptorSetLayout *layout;
34 marl::mutex mutex;
35 };
36
37 class alignas(16) DescriptorSet : public Object<DescriptorSet, VkDescriptorSet>
38 {
39 public:
40 using Array = std::array<DescriptorSet *, vk::MAX_BOUND_DESCRIPTOR_SETS>;
41 using Bindings = std::array<uint8_t *, vk::MAX_BOUND_DESCRIPTOR_SETS>;
42 using DynamicOffsets = std::array<uint32_t, vk::MAX_DESCRIPTOR_SET_COMBINED_BUFFERS_DYNAMIC>;
43
44 static void ContentsChanged(const Array &descriptorSets, const PipelineLayout *layout, Device *device);
45 static void PrepareForSampling(const Array &descriptorSets, const PipelineLayout *layout, Device *device);
46
47 uint8_t *getDataAddress(); // Returns a pointer to the descriptor payload following the header.
48
49 DescriptorSetHeader header;
50
51 private:
52 enum NotificationType
53 {
54 CONTENTS_CHANGED,
55 PREPARE_FOR_SAMPLING
56 };
57 static void ParseDescriptors(const Array &descriptorSets, const PipelineLayout *layout, Device *device, NotificationType notificationType);
58 };
59
Cast(VkDescriptorSet object)60 inline DescriptorSet *Cast(VkDescriptorSet object)
61 {
62 return DescriptorSet::Cast(object);
63 }
64
65 } // namespace vk
66
67 #endif // VK_DESCRIPTOR_SET_HPP_
68