7 #include "flutter/flutter_vma/flutter_vma.h"
8 #include "flutter/fml/trace_event.h"
10 #include "vulkan/vulkan_core.h"
15 std::weak_ptr<Context> context,
17 VmaAllocationInfo info)
19 context_(
std::move(context)),
20 resource_(
ContextVK::Cast(*context_.lock().get()).GetResourceManager(),
28 uint8_t* DeviceBufferVK::OnGetContents()
const {
29 return static_cast<uint8_t*
>(resource_->info.pMappedData);
32 bool DeviceBufferVK::OnCopyHostBuffer(
const uint8_t* source,
35 uint8_t* dest = OnGetContents();
42 ::memmove(dest +
offset, source + source_range.offset, source_range.length);
44 ::vmaFlushAllocation(resource_->buffer.get().allocator,
45 resource_->buffer.get().allocation,
offset,
51 bool DeviceBufferVK::SetLabel(
const std::string& label) {
52 auto context = context_.lock();
53 if (!context || !resource_->buffer.is_valid()) {
58 ::vmaSetAllocationName(resource_->buffer.get().allocator,
59 resource_->buffer.get().allocation,
67 void DeviceBufferVK::Flush(std::optional<Range> range)
const {
69 ::vmaFlushAllocation(resource_->buffer.get().allocator,
70 resource_->buffer.get().allocation, flush_range.offset,
74 void DeviceBufferVK::Invalidate(std::optional<Range> range)
const {
76 ::vmaInvalidateAllocation(resource_->buffer.get().allocator,
77 resource_->buffer.get().allocation,
78 flush_range.offset, flush_range.length);
81 bool DeviceBufferVK::SetLabel(
const std::string& label, Range range) {
83 return SetLabel(label);
87 return resource_->buffer.get().buffer;