| Flutter Impeller |

device_buffer_vk.cc
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 #include "impeller/renderer/backend/vulkan/device_buffer_vk.h"
6
7 #include "flutter/fml/logging.h"
8 #include "flutter/fml/trace_event.h"
9
10 namespace impeller {
11
12 DeviceBufferVK::DeviceBufferVK(DeviceBufferDescriptor desc,
13 std::weak_ptr<Context> context,
14 UniqueBufferVMA buffer,
15 VmaAllocationInfo info)
16 : DeviceBuffer(desc),
17 context_(std::move(context)),
18 resource_(ContextVK::Cast(*context_.lock().get()).GetResourceManager(),
19 BufferResource{
20 std::move(buffer), //
21 info //
22 }) {}
23
24 DeviceBufferVK::~DeviceBufferVK() = default;
25
26 uint8_t* DeviceBufferVK::OnGetContents() const {
27 return static_cast<uint8_t*>(resource_->info.pMappedData);
28 }
29
30 bool DeviceBufferVK::OnCopyHostBuffer(const uint8_t* source,
31 Range source_range,
32 size_t offset) {
33 TRACE_EVENT0("impeller", "CopyToDeviceBuffer");
34 uint8_t* dest = OnGetContents();
35
36 if (!dest) {
37 return false;
38 }
39
40 if (source) {
41 ::memmove(dest + offset, source + source_range.offset, source_range.length);
42 }
43 ::vmaFlushAllocation(resource_->buffer.get().allocator,
44 resource_->buffer.get().allocation, offset,
45 source_range.length);
46
47 return true;
48 }
49
50 bool DeviceBufferVK::SetLabel(const std::string& label) {
51 auto context = context_.lock();
52 if (!context || !resource_->buffer.is_valid()) {
53 // The context could have died at this point.
54 return false;
55 }
56
57 ::vmaSetAllocationName(resource_->buffer.get().allocator, //
58 resource_->buffer.get().allocation, //
59 label.c_str() //
60 );
61
62 return ContextVK::Cast(*context).SetDebugName(resource_->buffer.get().buffer,
63 label);
64 }
65
66 bool DeviceBufferVK::SetLabel(const std::string& label, Range range) {
67 // We do not have the ability to name ranges. Just name the whole thing.
68 return SetLabel(label);
69 }
70
71 vk::Buffer DeviceBufferVK::GetBuffer() const {
72 return resource_->buffer.get().buffer;
73 }
74
75 } // namespace impeller
impeller::DeviceBufferVK::GetBuffer
vk::Buffer GetBuffer() const
Definition: device_buffer_vk.cc:71
impeller::DeviceBuffer
Definition: device_buffer.h:20
impeller::DeviceBufferVK::DeviceBufferVK
DeviceBufferVK(DeviceBufferDescriptor desc, std::weak_ptr< Context > context, UniqueBufferVMA buffer, VmaAllocationInfo info)
Definition: device_buffer_vk.cc:12
impeller::DeviceBufferDescriptor
Definition: device_buffer_descriptor.h:13
impeller::DeviceBufferVK::~DeviceBufferVK
~DeviceBufferVK() override
impeller::ContextVK::SetDebugName
bool SetDebugName(T handle, std::string_view label) const
Definition: context_vk.h:96
impeller::ContextVK
Definition: context_vk.h:36
std
Definition: comparable.h:98
impeller::BackendCast< ContextVK, Context >::Cast
static ContextVK & Cast(Context &base)
Definition: backend_cast.h:14
device_buffer_vk.h
impeller::UniqueBufferVMA
fml::UniqueObject< BufferVMA, BufferVMATraits > UniqueBufferVMA
Definition: vma.h:97
impeller
Definition: aiks_context.cc:10
impeller::BufferResource
Resource< BufferView > BufferResource
Definition: command.h:60