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 <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/buffer_backed_descriptor.h"
27 #include "src/vulkan/transfer_buffer.h"
28 
29 namespace amber {
30 namespace vulkan {
31 
32 class CommandBuffer;
33 class Device;
34 
35 /// Stores descriptor set and binding information for storage and uniform
36 /// buffers.
37 class BufferDescriptor : public BufferBackedDescriptor {
38  public:
39   BufferDescriptor(Buffer* buffer,
40                    DescriptorType type,
41                    Device* device,
42                    uint32_t desc_set,
43                    uint32_t binding);
44   ~BufferDescriptor() override;
45 
46   void UpdateDescriptorSetIfNeeded(VkDescriptorSet descriptor_set) override;
47   Result CreateResourceIfNeeded() override;
48   Result MoveResourceToBufferOutput() override;
GetDynamicOffsets()49   std::vector<uint32_t> GetDynamicOffsets() override {
50     return dynamic_offsets_;
51   }
AddDynamicOffset(uint32_t offset)52   void AddDynamicOffset(uint32_t offset) { dynamic_offsets_.push_back(offset); }
AsBufferDescriptor()53   BufferDescriptor* AsBufferDescriptor() override { return this; }
54 
55  protected:
56   std::vector<Resource*> GetResources() override;
57 
58  private:
59   std::vector<std::unique_ptr<TransferBuffer>> transfer_buffers_;
60   std::vector<uint32_t> dynamic_offsets_;
61 };
62 
63 }  // namespace vulkan
64 }  // namespace amber
65 
66 #endif  // SRC_VULKAN_BUFFER_DESCRIPTOR_H_
67