Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Impeller] re-enable buffer to texture blit Vulkan. #43129

Merged
merged 1 commit into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions impeller/core/device_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ std::shared_ptr<Texture> DeviceBuffer::AsTexture(
return texture;
}

void DeviceBuffer::Flush() {}

const DeviceBufferDescriptor& DeviceBuffer::GetDeviceBufferDescriptor() const {
return desc_;
}
Expand Down
2 changes: 2 additions & 0 deletions impeller/core/device_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class DeviceBuffer : public Buffer,

BufferView AsBufferView() const;

virtual void Flush();

virtual std::shared_ptr<Texture> AsTexture(
Allocator& allocator,
const TextureDescriptor& descriptor,
Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/vulkan/capabilities_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ bool CapabilitiesVK::SupportsSSBO() const {

// |Capabilities|
bool CapabilitiesVK::SupportsBufferToTextureBlits() const {
return false;
return true;
}

// |Capabilities|
Expand Down
4 changes: 4 additions & 0 deletions impeller/renderer/backend/vulkan/device_buffer_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ bool DeviceBufferVK::OnCopyHostBuffer(const uint8_t* source,
return true;
}

void DeviceBufferVK::Flush() {
::vmaFlushAllocation(allocator_, allocation_, 0, VK_WHOLE_SIZE);
}

bool DeviceBufferVK::SetLabel(const std::string& label) {
auto context = context_.lock();
if (!context || !buffer_) {
Expand Down
5 changes: 5 additions & 0 deletions impeller/renderer/backend/vulkan/device_buffer_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class DeviceBufferVK final : public DeviceBuffer,

vk::Buffer GetBuffer() const;

// If the contents of this buffer have been written to with
// `OnGetContents`, then calling flush may be necessary if the memory is
// non-coherent.
void Flush() override;

private:
friend class AllocatorVK;

Expand Down
3 changes: 3 additions & 0 deletions lib/ui/painting/image_decoder_impeller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,9 @@ ImpellerAllocator::ImpellerAllocator(

std::optional<std::shared_ptr<impeller::DeviceBuffer>>
ImpellerAllocator::GetDeviceBuffer() const {
if (buffer_.has_value()) {
buffer_.value()->Flush();
}
Comment on lines +513 to +515
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the right time to flush?

Why not flush it explicitly in the blit pass where it's getting used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we only need to flush here because we've written directly to the ptr due to the skia interop. Adding the flush anywhere else would cause extra work, as if the buffer was populated with setcontents that would be redundant

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I misread which class this was in. LGTM.

return buffer_;
}

Expand Down