• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Amber Authors.
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 SRC_VULKAN_DESCRIPTOR_H_
16 #define SRC_VULKAN_DESCRIPTOR_H_
17 
18 #include <memory>
19 #include <vector>
20 
21 #include "amber/result.h"
22 #include "amber/value.h"
23 #include "amber/vulkan_header.h"
24 #include "src/buffer.h"
25 #include "src/engine.h"
26 #include "src/vulkan/resource.h"
27 
28 namespace amber {
29 namespace vulkan {
30 
31 class CommandBuffer;
32 class Device;
33 class BufferDescriptor;
34 class BufferBackedDescriptor;
35 class SamplerDescriptor;
36 
37 enum class DescriptorType : uint8_t {
38   kStorageBuffer = 0,
39   kStorageBufferDynamic,
40   kUniformBuffer,
41   kUniformBufferDynamic,
42   kStorageImage,
43   kSampledImage,
44   kCombinedImageSampler,
45   kUniformTexelBuffer,
46   kStorageTexelBuffer,
47   kSampler
48 };
49 
50 class Descriptor {
51  public:
52   Descriptor(DescriptorType type,
53              Device* device,
54              uint32_t desc_set,
55              uint32_t binding);
56   virtual ~Descriptor();
57 
58   virtual void UpdateDescriptorSetIfNeeded(VkDescriptorSet descriptor_set) = 0;
59   virtual Result CreateResourceIfNeeded() = 0;
RecordCopyDataToResourceIfNeeded(CommandBuffer *)60   virtual Result RecordCopyDataToResourceIfNeeded(CommandBuffer*) { return {}; }
RecordCopyDataToHost(CommandBuffer *)61   virtual Result RecordCopyDataToHost(CommandBuffer*) { return {}; }
MoveResourceToBufferOutput()62   virtual Result MoveResourceToBufferOutput() { return {}; }
SetSizeInElements(uint32_t)63   virtual Result SetSizeInElements(uint32_t) { return {}; }
AddToBuffer(const std::vector<Value> &,uint32_t)64   virtual Result AddToBuffer(const std::vector<Value>&, uint32_t) { return {}; }
GetDescriptorCount()65   virtual uint32_t GetDescriptorCount() { return 1; }
GetDynamicOffsets()66   virtual std::vector<uint32_t> GetDynamicOffsets() { return {}; }
AsBufferDescriptor()67   virtual BufferDescriptor* AsBufferDescriptor() { return nullptr; }
AsBufferBackedDescriptor()68   virtual BufferBackedDescriptor* AsBufferBackedDescriptor() { return nullptr; }
AsSamplerDescriptor()69   virtual SamplerDescriptor* AsSamplerDescriptor() { return nullptr; }
GetDescriptorSet()70   uint32_t GetDescriptorSet() const { return descriptor_set_; }
GetBinding()71   uint32_t GetBinding() const { return binding_; }
72   VkDescriptorType GetVkDescriptorType() const;
GetDescriptorType()73   DescriptorType GetDescriptorType() const { return type_; }
74 
IsStorageBuffer()75   bool IsStorageBuffer() const {
76     return type_ == DescriptorType::kStorageBuffer;
77   }
IsStorageBufferDynamic()78   bool IsStorageBufferDynamic() const {
79     return type_ == DescriptorType::kStorageBufferDynamic;
80   }
IsUniformBuffer()81   bool IsUniformBuffer() const {
82     return type_ == DescriptorType::kUniformBuffer;
83   }
IsUniformBufferDynamic()84   bool IsUniformBufferDynamic() const {
85     return type_ == DescriptorType::kUniformBufferDynamic;
86   }
IsUniformTexelBuffer()87   bool IsUniformTexelBuffer() const {
88     return type_ == DescriptorType::kUniformTexelBuffer;
89   }
IsStorageTexelBuffer()90   bool IsStorageTexelBuffer() const {
91     return type_ == DescriptorType::kStorageTexelBuffer;
92   }
93 
94  protected:
95   Device* device_ = nullptr;
96   DescriptorType type_ = DescriptorType::kStorageBuffer;
97   uint32_t descriptor_set_ = 0;
98   uint32_t binding_ = 0;
99   bool is_descriptor_set_update_needed_ = false;
100 };
101 
102 }  // namespace vulkan
103 }  // namespace amber
104 
105 #endif  // SRC_VULKAN_DESCRIPTOR_H_
106