[Impeller] ensure that OpenGL "flipped" textures do not leak via texture readback.#163501
[Impeller] ensure that OpenGL "flipped" textures do not leak via texture readback.#163501auto-submit[bot] merged 7 commits intoflutter:masterfrom
Conversation
chinmaygarde
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
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.
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.
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.
oops...
But thanks to associativity it is mathematically equivalent 😆
|
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".