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 Jun 29, 2023

For devices that don't support memoryless textures, the fullscreen MSAA texture adds a substantial amount of memory thrashing when it is allocated and deallocated. For these devices, lets cache the MSAA texture in the swapchain image.

flutter/flutter#129737

for (auto i = 0u; i < memory_properties.memoryTypeCount; i++) {
if (memory_properties.memoryTypes[i].propertyFlags &
vk::MemoryPropertyFlagBits::eLazilyAllocated) {
supports_memoryless_textures_ = true;
Copy link
Member

Choose a reason for hiding this comment

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

I sound like a broken record, but I don't think one can make the leap. I'm reading through https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#memory-device-lazy_allocation and it doesn't talk about this.

Maybe there is an extension that can give us an exact query for this support?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand that you are not convinced this is sufficient. However, lacking evidence of a phone where this is an issue I think we should focus on the existing pile of concrete problems.

Copy link
Member

Choose a reason for hiding this comment

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

Yea, fair point. The Android ecosystem is so diverse, it's difficult to know if there is a device that would pass this test but have better performance caching the textures instead. As a tools developer too we don't have analytics or anything that will tip us off if there is a problem. I think it's worth at least looking, I was hoping there some documentation somewhere about this.

Copy link
Member

Choose a reason for hiding this comment

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

Here is the documentation I could find. The name vulkan gives this is "Transient Attachments": https://github.com/KhronosGroup/Vulkan-Samples/tree/main/samples/performance/subpasses#transient-attachments

We should use that nomenclature instead of memoryless textures. I couldn't find a more apropos capabilities check than this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

memoryless is consistent with the nomenclature of the Metal backend and is what @chinmaygarde asked me to use here.

@jonahwilliams jonahwilliams marked this pull request as ready for review June 29, 2023 23:08
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@jonahwilliams jonahwilliams changed the title Cache msaa tex in swapchain [Impeller] cache MSAA texture in swapchain for devices that do not support memoryless. Jun 29, 2023
private:
vk::Image image_ = VK_NULL_HANDLE;
vk::UniqueImageView image_view_ = {};
std::shared_ptr<Texture> msaa_tex_;
Copy link
Member

Choose a reason for hiding this comment

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

This is rough as these textures are huge. We should measure memory usage but I doubt we can use the Vulkan backend in this instance. This is just the the swapchain images. These will add up for intermediates as well.

If this is to stabilize the benchmarks, its fine I suppose. But we should then find a device to put in the lab that does support lazily allocated images.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I'd like to punt on whether or not we decided to ship Vulkan on these devices. We'll likely learn even more once we actually attempt the Vulkan to GL texture interop.

Though for the short term, we must keep something on CI using Vulkan and I don't think we have any other devices.

Copy link
Member

@gaaclarke gaaclarke Jun 30, 2023

Choose a reason for hiding this comment

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

I doubt we can use the Vulkan backend in this instance

Couldn't we use a different AA than MSAA, like fxaa?

@jonahwilliams
Copy link
Contributor Author

I don't think memory usage vs memoryless is the right comparsion to think about for this. Clearly our current strategy is using dramatically more memory than OpenGL due to the spikey performance. And if OpenGL has access to the same capabilities as Vulkan does on this phone (probably) then I don't think we'll be worse off.

Shipping OpenGL backend to more devices is absolutely an option, but we should try to figure out if we're actually using more memory than an equivalent OpenGLES application. If not, we may just want to take the L and deal with the overhead.

As a secondary concern, the current OpenGLES backend has no offscreen MSAA. Which, seem appropriate given the low target. But if we need to dramatically expand the number of devices that opt into OpenGL then I don't think we can accept the visual fidelity regression.

@gaaclarke
Copy link
Member

the current OpenGLES backend has no offscreen MSAA

So, instead of switching Vulkan to OpenGLES if we just turn off MSAA in Vulkan we'll be no worse off? Seems like keeping the largest number of devices on the Vulkan backend is the most economical solution since it will absorb the most resources. The pixel 4a isn't passing the SupportsMemorylessTextures pass and it isn't an old phone and didn't really suffer the same as other phones from this problem.

The ideal layout would be 90% of phones on Vulkan and increasing, or 100% of phones on OpenGLES. Being in a situation where it's a 50/50 split is going to be costly since it will divide our resources.

@jonahwilliams
Copy link
Contributor Author

I'm absolutely not suggesting we turn of MSAA, on the contrary suggesting that we can't ship with no offscreen MSAA for a large % of Android devices.

@jonahwilliams
Copy link
Contributor Author

and in this case, we're talking about onscreen msaa - which we need to pay for vulkan or opengl

@jonahwilliams
Copy link
Contributor Author

yolo

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 30, 2023
@auto-submit auto-submit bot merged commit e6b8292 into flutter:main Jun 30, 2023
@jonahwilliams jonahwilliams deleted the cache_msaa_tex_in_swapchain branch June 30, 2023 18:39
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 30, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jun 30, 2023
…129852)

flutter/engine@54b573e...e6b8292

2023-06-30 [email protected] [Impeller] cache MSAA texture in swapchain for devices that do not support memoryless. (flutter/engine#43349)
2023-06-30 [email protected] [Impeller] Fix validation error in position color shader. (flutter/engine#43356)
2023-06-30 [email protected] Fix inverted boolean in Windows document selection changed a11y event (flutter/engine#43281)
2023-06-30 [email protected] Revert "Reland "add non-rendering operation culling to DisplayListBuilder" (#41463)" (flutter/engine#43358)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
kjlubick pushed a commit to kjlubick/engine that referenced this pull request Jul 14, 2023
…pport memoryless. (flutter#43349)

For devices that don't support memoryless textures, the fullscreen MSAA texture adds a substantial amount of memory thrashing when it is allocated and deallocated. For these devices, lets cache the MSAA texture in the swapchain image.

flutter/flutter#129737
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 needs tests

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants