7 #include "flutter/flutter_vma/flutter_vma.h"
13 std::weak_ptr<Context> context,
15 VmaAllocationInfo info,
16 bool is_host_coherent)
18 context_(
std::move(context)),
19 resource_(
ContextVK::Cast(*context_.lock().get()).GetResourceManager(),
24 is_host_coherent_(is_host_coherent) {}
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(std::string_view label) {
53 auto context = context_.lock();
54 if (!context || !resource_->buffer.is_valid()) {
59 ::vmaSetAllocationName(resource_->buffer.get().allocator,
60 resource_->buffer.get().allocation,
71 void DeviceBufferVK::Flush(std::optional<Range> range)
const {
72 if (is_host_coherent_) {
76 ::vmaFlushAllocation(resource_->buffer.get().allocator,
77 resource_->buffer.get().allocation, flush_range.offset,
83 return is_host_coherent_;
86 void DeviceBufferVK::Invalidate(std::optional<Range> range)
const {
88 ::vmaInvalidateAllocation(resource_->buffer.get().allocator,
89 resource_->buffer.get().allocation,
90 flush_range.offset, flush_range.length);
93 bool DeviceBufferVK::SetLabel(std::string_view label, Range range) {
95 return SetLabel(label);
99 return resource_->buffer.get().buffer;
static ContextVK & Cast(Context &base)
bool SetDebugName(T handle, std::string_view label) const
const DeviceBufferDescriptor & GetDeviceBufferDescriptor() const
bool IsHostCoherent() const
DeviceBufferVK(DeviceBufferDescriptor desc, std::weak_ptr< Context > context, UniqueBufferVMA buffer, VmaAllocationInfo info, bool is_host_coherent)
~DeviceBufferVK() override
vk::Buffer GetBuffer() const
Resource< BufferView > BufferResource
fml::UniqueObject< BufferVMA, BufferVMATraits > UniqueBufferVMA