| Flutter Impeller |

device_buffer_vk.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_DEVICE_BUFFER_VK_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_DEVICE_BUFFER_VK_H_
7
8 #include <memory>
9
10 #include "impeller/base/backend_cast.h"
11 #include "impeller/core/device_buffer.h"
12 #include "impeller/renderer/backend/vulkan/resource_manager_vk.h"
13 #include "impeller/renderer/backend/vulkan/vma.h"
14
15 namespace impeller {
16
17 class DeviceBufferVK final : public DeviceBuffer,
18 public BackendCast<DeviceBufferVK, DeviceBuffer> {
19 public:
20 DeviceBufferVK(DeviceBufferDescriptor desc,
21 std::weak_ptr<Context> context,
22 UniqueBufferVMA buffer,
23 VmaAllocationInfo info,
24 bool is_host_coherent);
25
26 // |DeviceBuffer|
27 ~DeviceBufferVK() override;
28
29 vk::Buffer GetBuffer() const;
30
31 // Visible for testing.
32 bool IsHostCoherent() const;
33
34 private:
35 friend class AllocatorVK;
36
37 struct BufferResource {
38 UniqueBufferVMA buffer;
39 VmaAllocationInfo info = {};
40
41 BufferResource() = default;
42
43 BufferResource(UniqueBufferVMA p_buffer, VmaAllocationInfo p_info)
44 : buffer(std::move(p_buffer)), info(p_info) {}
45
46 BufferResource(BufferResource&& o) {
47 std::swap(o.buffer, buffer);
48 std::swap(o.info, info);
49 }
50
51 BufferResource(const BufferResource&) = delete;
52
53 BufferResource& operator=(const BufferResource&) = delete;
54 };
55
56 std::weak_ptr<Context> context_;
57 UniqueResourceVKT<BufferResource> resource_;
58 bool is_host_coherent_ = false;
59
60 // |DeviceBuffer|
61 uint8_t* OnGetContents() const override;
62
63 // |DeviceBuffer|
64 bool OnCopyHostBuffer(const uint8_t* source,
65 Range source_range,
66 size_t offset) override;
67
68 // |DeviceBuffer|
69 bool SetLabel(std::string_view label) override;
70
71 // |DeviceBuffer|
72 bool SetLabel(std::string_view label, Range range) override;
73
74 // |DeviceBuffer|
75 void Flush(std::optional<Range> range) const override;
76
77 // |DeviceBuffer|
78 void Invalidate(std::optional<Range> range) const override;
79
80 DeviceBufferVK(const DeviceBufferVK&) = delete;
81
82 DeviceBufferVK& operator=(const DeviceBufferVK&) = delete;
83 };
84
85 } // namespace impeller
86
87 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_DEVICE_BUFFER_VK_H_
backend_cast.h
impeller::AllocatorVK
Definition: allocator_vk.h:19
impeller::BackendCast
Definition: backend_cast.h:11
impeller::DeviceBuffer
Definition: device_buffer.h:18
impeller::DeviceBufferVK
Definition: device_buffer_vk.h:18
impeller::DeviceBufferVK::IsHostCoherent
bool IsHostCoherent() const
Definition: device_buffer_vk.cc:82
impeller::DeviceBufferVK::DeviceBufferVK
DeviceBufferVK(DeviceBufferDescriptor desc, std::weak_ptr< Context > context, UniqueBufferVMA buffer, VmaAllocationInfo info, bool is_host_coherent)
Definition: device_buffer_vk.cc:12
impeller::DeviceBufferVK::~DeviceBufferVK
~DeviceBufferVK() override
impeller::DeviceBufferVK::GetBuffer
vk::Buffer GetBuffer() const
Definition: device_buffer_vk.cc:98
device_buffer.h
impeller
Definition: allocation.cc:12
impeller::BufferResource
Resource< BufferView > BufferResource
Definition: command.h:54
impeller::UniqueBufferVMA
fml::UniqueObject< BufferVMA, BufferVMATraits > UniqueBufferVMA
Definition: vma.h:98
std
Definition: comparable.h:95
resource_manager_vk.h
impeller::DeviceBufferDescriptor
Definition: device_buffer_descriptor.h:14
vma.h