• 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_BUFFER_BACKED_DESCRIPTOR_H_
16 #define SRC_VULKAN_BUFFER_BACKED_DESCRIPTOR_H_
17 
18 #include <memory>
19 #include <utility>
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/descriptor.h"
28 #include "src/vulkan/pipeline.h"
29 #include "src/vulkan/resource.h"
30 
31 namespace amber {
32 namespace vulkan {
33 
34 class BufferBackedDescriptor : public Descriptor {
35  public:
36   BufferBackedDescriptor(Buffer* buffer,
37                          DescriptorType type,
38                          Device* device,
39                          uint32_t desc_set,
40                          uint32_t binding,
41                          Pipeline* pipeline);
42   ~BufferBackedDescriptor() override;
43 
CreateResourceIfNeeded()44   Result CreateResourceIfNeeded() override { return {}; }
45   static Result RecordCopyBufferDataToTransferResourceIfNeeded(
46       CommandBuffer* command_buffer,
47       Buffer* buffer,
48       Resource* transfer_resource);
49   static Result RecordCopyTransferResourceToHost(CommandBuffer* command_buffer,
50                                                  Resource* transfer_resource);
51   static Result MoveTransferResourceToBufferOutput(Resource* transfer_resource,
52                                                    Buffer* buffer);
GetDescriptorCount()53   uint32_t GetDescriptorCount() override {
54     return static_cast<uint32_t>(amber_buffers_.size());
55   }
GetAmberBuffers()56   const std::vector<Buffer*>& GetAmberBuffers() const { return amber_buffers_; }
AddAmberBuffer(Buffer * buffer)57   void AddAmberBuffer(Buffer* buffer) { amber_buffers_.push_back(buffer); }
AsBufferBackedDescriptor()58   BufferBackedDescriptor* AsBufferBackedDescriptor() override { return this; }
59   bool IsReadOnly() const;
60 
61  protected:
62   // Pipeline where this descriptor is attached to.
63   Pipeline* pipeline_;
64 
65  private:
66   std::vector<Buffer*> amber_buffers_;
67 };
68 
69 }  // namespace vulkan
70 }  // namespace amber
71 
72 #endif  // SRC_VULKAN_BUFFER_BACKED_DESCRIPTOR_H_
73