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 DescriptorSetHeader header;
48 alignas(16) uint8_t data[1];
49
50 private:
51 enum NotificationType
52 {
53 CONTENTS_CHANGED,
54 PREPARE_FOR_SAMPLING
55 };
56 static void ParseDescriptors(const Array &descriptorSets, const PipelineLayout *layout, Device *device, NotificationType notificationType);
57 };
58
Cast(VkDescriptorSet object)59 inline DescriptorSet *Cast(VkDescriptorSet object)
60 {
61 return DescriptorSet::Cast(object);
62 }
63
64 } // namespace vk
65
66 #endif // VK_DESCRIPTOR_SET_HPP_
67