• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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_BUFFER_DESCRIPTOR_H_
16 #define SRC_VULKAN_BUFFER_DESCRIPTOR_H_
17 
18 #include <memory>
19 #include <unordered_map>
20 #include <utility>
21 #include <vector>
22 
23 #include "amber/result.h"
24 #include "amber/value.h"
25 #include "amber/vulkan_header.h"
26 #include "src/buffer.h"
27 #include "src/engine.h"
28 #include "src/vulkan/buffer_backed_descriptor.h"
29 #include "src/vulkan/pipeline.h"
30 #include "src/vulkan/transfer_buffer.h"
31 
32 namespace amber {
33 namespace vulkan {
34 
35 class CommandBuffer;
36 class Device;
37 
38 /// Stores descriptor set and binding information for storage and uniform
39 /// buffers.
40 class BufferDescriptor : public BufferBackedDescriptor {
41  public:
42   BufferDescriptor(Buffer* buffer,
43                    DescriptorType type,
44                    Device* device,
45                    uint32_t desc_set,
46                    uint32_t binding,
47                    vulkan::Pipeline* pipeline);
48   ~BufferDescriptor() override;
49 
50   void UpdateDescriptorSetIfNeeded(VkDescriptorSet descriptor_set) override;
51   Result CreateResourceIfNeeded() override;
GetDynamicOffsets()52   std::vector<uint32_t> GetDynamicOffsets() override {
53     return dynamic_offsets_;
54   }
AddDynamicOffset(uint32_t offset)55   void AddDynamicOffset(uint32_t offset) { dynamic_offsets_.push_back(offset); }
GetDescriptorOffsets()56   std::vector<uint64_t> GetDescriptorOffsets() override {
57     return descriptor_offsets_;
58   }
AddDescriptorOffset(uint64_t descriptor_offset)59   void AddDescriptorOffset(uint64_t descriptor_offset) {
60     descriptor_offsets_.push_back(descriptor_offset);
61   }
GetDescriptorRanges()62   std::vector<uint64_t> GetDescriptorRanges() override {
63     return descriptor_ranges_;
64   }
AddDescriptorRange(uint64_t descriptor_range)65   void AddDescriptorRange(uint64_t descriptor_range) {
66     descriptor_ranges_.push_back(descriptor_range);
67   }
68 
AsBufferDescriptor()69   BufferDescriptor* AsBufferDescriptor() override { return this; }
70 
71  private:
72   std::vector<uint32_t> dynamic_offsets_;
73   std::vector<VkDeviceSize> descriptor_offsets_;
74   std::vector<VkDeviceSize> descriptor_ranges_;
75 };
76 
77 }  // namespace vulkan
78 }  // namespace amber
79 
80 #endif  // SRC_VULKAN_BUFFER_DESCRIPTOR_H_
81