• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Amber Authors.
2 // Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SRC_VULKAN_DESCRIPTOR_H_
17 #define SRC_VULKAN_DESCRIPTOR_H_
18 
19 #include <memory>
20 #include <vector>
21 
22 #include "amber/result.h"
23 #include "amber/value.h"
24 #include "amber/vulkan_header.h"
25 #include "src/buffer.h"
26 #include "src/engine.h"
27 #include "src/vulkan/resource.h"
28 
29 namespace amber {
30 namespace vulkan {
31 
32 class CommandBuffer;
33 class Device;
34 class BufferDescriptor;
35 class ImageDescriptor;
36 class BufferBackedDescriptor;
37 class SamplerDescriptor;
38 class TLASDescriptor;
39 
40 enum class DescriptorType : uint8_t {
41   kStorageBuffer = 0,
42   kStorageBufferDynamic,
43   kUniformBuffer,
44   kUniformBufferDynamic,
45   kStorageImage,
46   kSampledImage,
47   kCombinedImageSampler,
48   kUniformTexelBuffer,
49   kStorageTexelBuffer,
50   kSampler,
51   kTLAS
52 };
53 
54 class Descriptor {
55  public:
56   Descriptor(DescriptorType type,
57              Device* device,
58              uint32_t desc_set,
59              uint32_t binding);
60   virtual ~Descriptor();
61 
62   virtual void UpdateDescriptorSetIfNeeded(VkDescriptorSet descriptor_set) = 0;
63   virtual Result CreateResourceIfNeeded() = 0;
GetDescriptorCount()64   virtual uint32_t GetDescriptorCount() { return 1; }
GetDynamicOffsets()65   virtual std::vector<uint32_t> GetDynamicOffsets() { return {}; }
GetDescriptorOffsets()66   virtual std::vector<VkDeviceSize> GetDescriptorOffsets() { return {}; }
GetDescriptorRanges()67   virtual std::vector<VkDeviceSize> GetDescriptorRanges() { return {}; }
AsBufferDescriptor()68   virtual BufferDescriptor* AsBufferDescriptor() { return nullptr; }
AsImageDescriptor()69   virtual ImageDescriptor* AsImageDescriptor() { return nullptr; }
AsBufferBackedDescriptor()70   virtual BufferBackedDescriptor* AsBufferBackedDescriptor() { return nullptr; }
AsSamplerDescriptor()71   virtual SamplerDescriptor* AsSamplerDescriptor() { return nullptr; }
AsTLASDescriptor()72   virtual TLASDescriptor* AsTLASDescriptor() { return nullptr; }
GetDescriptorSet()73   uint32_t GetDescriptorSet() const { return descriptor_set_; }
GetBinding()74   uint32_t GetBinding() const { return binding_; }
75   VkDescriptorType GetVkDescriptorType() const;
GetDescriptorType()76   DescriptorType GetDescriptorType() const { return type_; }
77 
IsStorageBuffer()78   bool IsStorageBuffer() const {
79     return type_ == DescriptorType::kStorageBuffer;
80   }
IsStorageBufferDynamic()81   bool IsStorageBufferDynamic() const {
82     return type_ == DescriptorType::kStorageBufferDynamic;
83   }
IsUniformBuffer()84   bool IsUniformBuffer() const {
85     return type_ == DescriptorType::kUniformBuffer;
86   }
IsUniformBufferDynamic()87   bool IsUniformBufferDynamic() const {
88     return type_ == DescriptorType::kUniformBufferDynamic;
89   }
IsUniformTexelBuffer()90   bool IsUniformTexelBuffer() const {
91     return type_ == DescriptorType::kUniformTexelBuffer;
92   }
IsStorageTexelBuffer()93   bool IsStorageTexelBuffer() const {
94     return type_ == DescriptorType::kStorageTexelBuffer;
95   }
96 
97  protected:
98   Device* device_ = nullptr;
99   DescriptorType type_ = DescriptorType::kStorageBuffer;
100   uint32_t descriptor_set_ = 0;
101   uint32_t binding_ = 0;
102   bool is_descriptor_set_update_needed_ = false;
103 };
104 
105 }  // namespace vulkan
106 }  // namespace amber
107 
108 #endif  // SRC_VULKAN_DESCRIPTOR_H_
109