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

Conversation

jonahwilliams
Copy link
Contributor

Uses the mipmap implementation from https://vulkan-tutorial.com/Generating_Mipmaps .

Today we generate all mip levels from mip level 0, which results in lost data. Instead we need to use the previous mip level

@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 "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use 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.

@chinmaygarde
Copy link
Member

When I first wrote this, my mental model was that generating data for mip level N from N-1 was similar to making a JPEG from a JPEG. Instead of making a JPEG of increasingly smaller size from a base original.

In the OpenGL spec, this is all implementation dependent. So I can't tell which one is correct. But if this matches what the other backends are doing, we should go for it.

@jonahwilliams
Copy link
Contributor Author

In writing a test for this I found #51761

Copy link
Member

@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.

I added suggestions for comments to make the barriers easier to understand.

barrier.srcAccessMask = vk::AccessFlagBits::eTransferWrite;
barrier.dstAccessMask = vk::AccessFlagBits::eTransferRead;

cmd.pipelineBarrier(vk::PipelineStageFlagBits::eTransfer,
Copy link
Member

Choose a reason for hiding this comment

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

Just to make this easier to read, add a comment about why the barrier is necessary. I'll attempt to jot down how I read it but please proofread.

Copy link
Member

Choose a reason for hiding this comment

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

Comment Suggestion:

We just finished writing to the previous (N-1) mip level. These were initialized to TransferDst earler. We are now going to read from it to write to the current level (N) . So it must be converted to TransferSrc.

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

barrier.srcAccessMask = vk::AccessFlagBits::eTransferRead;
barrier.dstAccessMask = vk::AccessFlagBits::eShaderRead;

cmd.pipelineBarrier(vk::PipelineStageFlagBits::eTransfer,
Copy link
Member

Choose a reason for hiding this comment

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

Comment Suggestion:

Now that the blit is done, the image at the previous level (N-1) is done reading from (TransferSrc). Now we must prepare it to be read from a shader (ShaderReadOnly).

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

// Transition the base mip level to transfer-src layout so we can read from
// it and transition the rest to dst-optimal since they are going to be
// written to.
InsertImageMemoryBarrier(
Copy link
Member

Choose a reason for hiding this comment

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

Comment Suggestion:

Initialize all mip levels to be in TransferDst mode. Later, in a loop, after writing to that mip level, we'll first switch its layout to TransferSrc to prepare the mip level after it, use the image as the source of the blit, before finally switching it to ShaderReadOnly so its available for sampling in a shader.

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

barrier.srcAccessMask = vk::AccessFlagBits::eTransferWrite;
barrier.dstAccessMask = vk::AccessFlagBits::eShaderRead;

cmd.pipelineBarrier(vk::PipelineStageFlagBits::eTransfer,
Copy link
Member

Choose a reason for hiding this comment

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

Comment SUggestion:

The very last mip level is still in TransferDst and must be converted to ShaderReadOnly.

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

mip_count - 1 // mip level count
);
0u, // mip level
mip_count);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Missing last comment.

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

@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

Changes reported for pull request #51749 at sha 4371b3b

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 29, 2024
@auto-submit auto-submit bot merged commit 7176173 into flutter:main Mar 29, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Mar 29, 2024
…145994)

flutter/engine@b16c0f1...7176173

2024-03-29 [email protected] [Impeller] generate mip level N from N-1 in Vulkan backend. (flutter/engine#51749)

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://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
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 will affect goldens

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants