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