Skip to content

Commit d0d523f

Browse files
sugoi1Commit Bot
authored andcommitted
Make copyTexImage2D robust when source area is out of bounds
Whenever the source area of the texture being copied is out of bounds and robust resource init is enabled, it is necessary to clear the invalid portion of the source area to 0 in the copy operation, EXCEPT if the source and the destination are the same, in which case clearing the destination would also clear the source. Bug: angleproject:3930 Change-Id: Ie9e0c52fff86b5626c82a511319688392b7b073b Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2391281 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Alexis Hétu <sugoi@chromium.org>
1 parent d701eae commit d0d523f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/libANGLE/Texture.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,9 +1188,17 @@ angle::Result Texture::copyImage(Context *context,
11881188
// the copy lies entirely off the source framebuffer, initialize as though a zero-size box is
11891189
// going to be set during the copy operation.
11901190
Box destBox;
1191+
bool forceCopySubImage = false;
11911192
if (context->isRobustResourceInitEnabled())
11921193
{
1193-
Extents fbSize = source->getReadColorAttachment()->getSize();
1194+
const FramebufferAttachment *sourceReadAttachment = source->getReadColorAttachment();
1195+
Extents fbSize = sourceReadAttachment->getSize();
1196+
// Force using copySubImage when the source area is out of bounds AND
1197+
// we're not copying to and from the same texture
1198+
forceCopySubImage = ((sourceArea.x < 0) || (sourceArea.y < 0) ||
1199+
((sourceArea.x + sourceArea.width) > fbSize.width) ||
1200+
((sourceArea.y + sourceArea.height) > fbSize.height)) &&
1201+
(sourceReadAttachment->getTexture() != this);
11941202
Rectangle clippedArea;
11951203
if (ClipRectangle(sourceArea, Rectangle(0, 0, fbSize.width, fbSize.height), &clippedArea))
11961204
{
@@ -1205,7 +1213,7 @@ angle::Result Texture::copyImage(Context *context,
12051213
// an initializeContents call, and then a copySubImage call. This ensures the destination
12061214
// texture exists before we try to clear it.
12071215
Extents size(sourceArea.width, sourceArea.height, 1);
1208-
if (doesSubImageNeedInit(context, index, destBox))
1216+
if (forceCopySubImage || doesSubImageNeedInit(context, index, destBox))
12091217
{
12101218
ANGLE_TRY(mTexture->setImage(context, index, internalFormat, size,
12111219
internalFormatInfo.format, internalFormatInfo.type,

0 commit comments

Comments
 (0)