Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
6
7#include "flutter/flutter_vma/flutter_vma.h"
8#include "flutter/fml/trace_event.h"
10#include "vulkan/vulkan_core.h"
11
12namespace impeller {
13
15 std::weak_ptr<Context> context,
17 VmaAllocationInfo info)
18 : DeviceBuffer(desc),
19 context_(std::move(context)),
20 resource_(ContextVK::Cast(*context_.lock().get()).GetResourceManager(),
22 std::move(buffer), //
23 info //
24 }) {}
25
27
29 return static_cast<uint8_t*>(resource_->info.pMappedData);
30}
31
33 Range source_range,
34 size_t offset) {
35 uint8_t* dest = OnGetContents();
36
37 if (!dest) {
38 return false;
39 }
40
41 if (source) {
42 ::memmove(dest + offset, source + source_range.offset, source_range.length);
43 }
44 ::vmaFlushAllocation(resource_->buffer.get().allocator,
45 resource_->buffer.get().allocation, offset,
46 source_range.length);
47
48 return true;
49}
50
51bool DeviceBufferVK::SetLabel(const std::string& label) {
52 auto context = context_.lock();
53 if (!context || !resource_->buffer.is_valid()) {
54 // The context could have died at this point.
55 return false;
56 }
57
58 ::vmaSetAllocationName(resource_->buffer.get().allocator, //
59 resource_->buffer.get().allocation, //
60 label.c_str() //
61 );
62
63 return ContextVK::Cast(*context).SetDebugName(resource_->buffer.get().buffer,
64 label);
65}
66
67void DeviceBufferVK::Flush(std::optional<Range> range) const {
68 auto flush_range = range.value_or(Range{0, GetDeviceBufferDescriptor().size});
69 ::vmaFlushAllocation(resource_->buffer.get().allocator,
70 resource_->buffer.get().allocation, flush_range.offset,
71 flush_range.length);
72}
73
74void DeviceBufferVK::Invalidate(std::optional<Range> range) const {
75 auto flush_range = range.value_or(Range{0, GetDeviceBufferDescriptor().size});
76 ::vmaInvalidateAllocation(resource_->buffer.get().allocator,
77 resource_->buffer.get().allocation,
78 flush_range.offset, flush_range.length);
79}
80
81bool DeviceBufferVK::SetLabel(const std::string& label, Range range) {
82 // We do not have the ability to name ranges. Just name the whole thing.
83 return SetLabel(label);
84}
85
86vk::Buffer DeviceBufferVK::GetBuffer() const {
87 return resource_->buffer.get().buffer;
88}
89
90} // namespace impeller
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
static ContextVK & Cast(Context &base)
bool SetDebugName(T handle, std::string_view label) const
Definition context_vk.h:108
void Flush(std::optional< Range > range) const override
uint8_t * OnGetContents() const override
DeviceBufferVK(DeviceBufferDescriptor desc, std::weak_ptr< Context > context, UniqueBufferVMA buffer, VmaAllocationInfo info)
bool OnCopyHostBuffer(const uint8_t *source, Range source_range, size_t offset) override
bool SetLabel(const std::string &label) override
void Invalidate(std::optional< Range > range) const override
vk::Buffer GetBuffer() const
const DeviceBufferDescriptor & GetDeviceBufferDescriptor() const
SkBitmap source
Definition examples.cpp:28
static const uint8_t buffer[]
Resource< BufferView > BufferResource
Definition command.h:57
Definition ref_ptr.h:256
Point offset
size_t length
Definition range.h:16
size_t offset
Definition range.h:15