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

Conversation

@jonahwilliams
Copy link
Contributor

@jonahwilliams jonahwilliams commented Mar 17, 2023

I'm not sure if we can land this until we figure out image upload performance issues

Patch 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

size_t source_offset,
IPoint destination_origin,
std::string label) override {
return false;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO

Copy link
Contributor

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

Copy link
Contributor Author

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;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO

Copy link
Contributor

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.

Copy link
Contributor Author

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, *)) {
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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

Copy link
Contributor Author

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

@jonahwilliams jonahwilliams force-pushed the blit_to_private_texture branch from 9dde59a to 4fc53d3 Compare March 17, 2023 23:12
@jonahwilliams jonahwilliams force-pushed the blit_to_private_texture branch from 4fc53d3 to a8b8aff Compare March 17, 2023 23:14
@chinmaygarde chinmaygarde changed the title [impeller] allocate images into host buffer, blit to device private texture [Impeller] allocate images into host buffer, blit to device private texture. Mar 18, 2023
Copy link
Contributor

@chinmaygarde chinmaygarde left a 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;
Copy link
Contributor

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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,
Copy link
Contributor

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.

Copy link
Contributor Author

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;
Copy link
Contributor

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.

};

struct BlitCopyBufferToTextureCommand : public BlitCommand {
std::shared_ptr<DeviceBuffer> source;
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@chinmaygarde chinmaygarde changed the title [Impeller] allocate images into host buffer, blit to device private texture. [Impeller] Allocate images into host buffer, blit to device private texture. Mar 18, 2023
@jonahwilliams jonahwilliams force-pushed the blit_to_private_texture branch from 6d816e0 to 5fbc677 Compare March 19, 2023 17:12
@jonahwilliams
Copy link
Contributor Author

To make the BufferView change work I had to update the mtl texture to allow casting from a DeviceBuffer to casting from a Buffer.

@jonahwilliams jonahwilliams marked this pull request as ready for review March 19, 2023 17:14
@jonahwilliams
Copy link
Contributor Author

Landing this as is will likely regress worst frame times on gallery, as texture blitting competes with the frame workload

@jonahwilliams jonahwilliams marked this pull request as draft March 20, 2023 19:25
@jonahwilliams jonahwilliams marked this pull request as ready for review March 20, 2023 22:53
@jonahwilliams jonahwilliams force-pushed the blit_to_private_texture branch from d9fc482 to c1fb18a Compare March 21, 2023 00:47
@jonahwilliams
Copy link
Contributor Author

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

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 21, 2023
@auto-submit auto-submit bot merged commit 0451913 into flutter:main Mar 21, 2023
@jonahwilliams jonahwilliams deleted the blit_to_private_texture branch March 21, 2023 21:24
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 21, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 21, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 21, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 22, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 22, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

autosubmit Merge PR when tree becomes green via auto submit App e: impeller

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants