-
Notifications
You must be signed in to change notification settings - Fork 29.7k
[Impeller] ensure that OpenGL "flipped" textures do not leak via texture readback. #163501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
A suggestion to use just one call to use ReadPixels with an inplace swap to avoid potential driver shenanigans. Perhaps its pinning memory weirdly.
OTOH, feel free to ignore. ReadPixels is slow either way.
| case TextureCoordinateSystem::kRenderToTexture: | ||
| // The texture is upside down, and must be inverted when copying | ||
| // byte data out. | ||
| size_t offset = destination_offset; |
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 have nothing to provide as evidence for this other than perhaps an irrational fear that multiple calls to ReadPixels will make some driver do the most insane thing possible. But can we read in one shot and then flip the image in place after instead?
Iterate over the rows picking two from each end and std::swap_ranges on each perhaps.
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.
This is a reasonable fear, but I also doubt my ability to correctly use std::swap_ranges so it might be 6 of 1 and half a dozen of another...
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.
static void FlipImage(uint8_t* buffer,
size_t width,
size_t height,
size_t stride) {
if (buffer == nullptr || stride == 0) {
return;
}
const auto byte_width = width * stride;
for (size_t top = 0; top < height; top++) {
size_t bottom = height - top - 1;
if (top >= bottom) {
break;
}
auto* top_row = buffer + byte_width * top;
auto* bottom_row = buffer + byte_width * bottom;
std::swap_ranges(top_row, top_row + byte_width, bottom_row);
}
}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.
Will update the PR to use this.
| case TextureCoordinateSystem::kRenderToTexture: | ||
| // The texture is upside down, and must be inverted when copying | ||
| // byte data out. | ||
| FlipImage(data + destination_offset, 4, source_region.GetHeight(), |
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.
These arguments aren't right. The stride goes last. It's the root buffer address, image width, image height, and the pixel stride.
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.
Oh, lol. The order doesn't matter since its its multiplied. Anyway, not how I meant the arguments would be interpreted 🙃
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.
oops...
But thanks to associativity it is mathematically equivalent 😆
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.
Fixed
|
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. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
…ure readback. (flutter#163501) Fixes flutter#163315 Fixes flutter#163521 Fixes flutter#142641 OpenGL has an inverted coordinate system (bottom left is zero) compared to Metal/Vulkan (top left is zero). We handle this by rendering things upside down on OpenGL. Unfortunately this can leak out of the renderer via readback (toImage), so we need to make sure to undo the inversion. This is not performed for the "TextureCoordinateSystem::kUploadFromHost" state as that indicates the texture is already "right side up".
…via texture readback. (flutter/flutter#163501)
…via texture readback. (flutter/flutter#163501)
…via texture readback. (flutter/flutter#163501)
…via texture readback. (flutter/flutter#163501)
…via texture readback. (flutter/flutter#163501)
…via texture readback. (flutter/flutter#163501)
…via texture readback. (flutter/flutter#163501)
…via texture readback. (flutter/flutter#163501)
…via texture readback. (flutter/flutter#163501)
…via texture readback. (flutter/flutter#163501)
…via texture readback. (flutter/flutter#163501)
…via texture readback. (flutter/flutter#163501)
…via texture readback. (flutter/flutter#163501)
…via texture readback. (flutter/flutter#163501)
…via texture readback. (flutter/flutter#163501)
…via texture readback. (flutter/flutter#163501)
…via texture readback. (flutter/flutter#163501)
…via texture readback. (flutter/flutter#163501)
…via texture readback. (flutter/flutter#163501)
…via texture readback. (flutter/flutter#163501)
…texture readback. (#163501) (#163667) Fixes #163315 Fixes #163521 Fixes #142641 OpenGL has an inverted coordinate system (bottom left is zero) compared to Metal/Vulkan (top left is zero). We handle this by rendering things upside down on OpenGL. Unfortunately this can leak out of the renderer via readback (toImage), so we need to make sure to undo the inversion. This is not performed for the "TextureCoordinateSystem::kUploadFromHost" state as that indicates the texture is already "right side up".
…texture readback. (flutter#163501) (flutter#163667) Fixes flutter#163315 Fixes flutter#163521 Fixes flutter#142641 OpenGL has an inverted coordinate system (bottom left is zero) compared to Metal/Vulkan (top left is zero). We handle this by rendering things upside down on OpenGL. Unfortunately this can leak out of the renderer via readback (toImage), so we need to make sure to undo the inversion. This is not performed for the "TextureCoordinateSystem::kUploadFromHost" state as that indicates the texture is already "right side up".
…via texture readback. (flutter/flutter#163501)
…via texture readback. (flutter/flutter#163501)
…via texture readback. (flutter/flutter#163501)
Fixes #163315
Fixes #163521
Fixes #142641
OpenGL has an inverted coordinate system (bottom left is zero) compared to Metal/Vulkan (top left is zero). We handle this by rendering things upside down on OpenGL. Unfortunately this can leak out of the renderer via readback (toImage), so we need to make sure to undo the inversion.
This is not performed for the "TextureCoordinateSystem::kUploadFromHost" state as that indicates the texture is already "right side up".