-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Allocate images into host buffer, blit to device private texture. #40410
[Impeller] Allocate images into host buffer, blit to device private texture. #40410
Conversation
| size_t source_offset, | ||
| IPoint destination_origin, | ||
| std::string label) override { | ||
| return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally fine. But IMPELLER_UNIMPLEMENTED in //impeller/base/config.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| size_t source_offset, | ||
| IPoint destination_origin, | ||
| std::string label) override { | ||
| return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem. I'll handle it. But again, FML_UNIMPLEMENTED so its easier to grep for more than anything else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
|
||
| mtl_texture_desc.storageMode = ToMTLStorageMode( | ||
| desc.storage_mode, supports_memoryless_targets_, supports_uma_); | ||
| if (@available(macOS 12.5, ios 15.0, *)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: make configurable, figure out if it has reasonable behavior for image textures
| return (negative ? -1.f : 1.f) * pow_value * (1.0f + fFraction); | ||
| } | ||
| } // namespace | ||
| // namespace { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: all of these tests need to be moved to a different TU that has an impeller context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mocked out the allocator. Done
9dde59a to
4fc53d3
Compare
4fc53d3 to
a8b8aff
Compare
chinmaygarde
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial comments but all nits. We can rework this later as needed. Let's not worry about the other backends either.
| size_t source_offset, | ||
| IPoint destination_origin, | ||
| std::string label) override { | ||
| return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally fine. But IMPELLER_UNIMPLEMENTED in //impeller/base/config.h
| desc.storage_mode, supports_memoryless_targets_, supports_uma_); | ||
| if (@available(macOS 12.5, ios 15.0, *)) { | ||
| if (mtl_texture_desc.storageMode == MTLStorageModePrivate) { | ||
| mtl_texture_desc.compressionType = MTLTextureCompressionTypeLossy; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to attempt this in another patch and have this flag be present on impeller::TextureDescriptor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, removed for now.
| std::string label) override; | ||
|
|
||
| // |BlitPass| | ||
| bool OnCopyBufferToTextureCommand(std::shared_ptr<DeviceBuffer> source, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should make the source a buffer view. That way we can specify ranges in the source. Also, you'll be able to get rid of source_offset which pretty much does the same thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| size_t source_offset, | ||
| IPoint destination_origin, | ||
| std::string label) override { | ||
| return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem. I'll handle it. But again, FML_UNIMPLEMENTED so its easier to grep for more than anything else.
impeller/renderer/blit_command.h
Outdated
| }; | ||
|
|
||
| struct BlitCopyBufferToTextureCommand : public BlitCommand { | ||
| std::shared_ptr<DeviceBuffer> source; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider a buffer view here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
6d816e0 to
5fbc677
Compare
|
To make the BufferView change work I had to update the mtl texture to allow casting from a DeviceBuffer to casting from a Buffer. |
|
Landing this as is will likely regress worst frame times on gallery, as texture blitting competes with the frame workload |
d9fc482 to
c1fb18a
Compare
|
I've updated this patch so that we retain two different strategies, one to create hostVisible and one to create device private. For host visible, I've exposed an option to disable mip creation. For mutiframe codecs, I use the host visible texture with no mips for the fastest throughput |
I'm not sure if we can land this until we figure out image upload performance issuesPatch landed to force serialization of texture upload in #40464
Updated patch so that multiframe codecs always go to host visible textures and don't generate mipmaps. This should help throughput performance since UMA don't have much cost for creating these textures
This would allow us to apply lossy compression to image textures, which dramatically reduces (50%?) memory usage on certain formats. From experimenting with the metal memory profiler, this does appear to use less memory that using host visible textures - possibly due to lossless compression. I've also confirmed that the primary memory category we measure does not include private metal resources, so there is an accounting aspect to it. That said, all categories appear lower after this change.
I experimented with this by swiping through wonderous for a few seconds and then letting the app rest a bit:
Using the VM tracker which includes all alloctions, without this patch we stabilize at ~320 MB of dirty memory and 2 MB of swap, while with this patch we stabilize at 237 MB of dirty memory and 42 MB of swap.
The metal resource events category also is reduced with this patch, previously peaking at 325 MB and dropping down to 287. Finally, mostly due to accounting the all heap and anon VM category drops from 280 to 90 MB.
Leaves the existing path more or less for gles/vulkan as we need to determine if private textures make sense there and implement support for buffer to texture blit.
flutter/flutter#122914
flutter/flutter#122918
flutter/flutter#122406