Skip to content
Permalink
Browse files

TextureCache: Don't copy out-of-range rectangles when stitching textures

This can cause driver crashes or GPU hangs if we do.
  • Loading branch information...
stenzek committed Feb 15, 2019
1 parent 2165523 commit 933f3ba008942cba96ed623c25e61d6ea86582fe
Showing with 22 additions and 0 deletions.
  1. +22 −0 Source/Core/VideoCommon/TextureCacheBase.cpp
@@ -384,6 +384,17 @@ TextureCacheBase::DoPartialTextureUpdates(TCacheEntry* entry_to_update, u8* pale
dst_y = 0;
}

// If the source rectangle is outside of what we actually have in VRAM, skip the copy.
// The backend doesn't do any clamping, so if we don't, we'd pass out-of-range coordinates
// to the graphics driver, which can cause GPU resets.
if (static_cast<u32>(src_x) >= entry->native_width ||
static_cast<u32>(src_y) >= entry->native_height ||
static_cast<u32>(dst_x) >= entry_to_update->native_width ||
static_cast<u32>(dst_y) >= entry_to_update->native_height)
{
continue;
}

u32 copy_width =
std::min(entry->native_width - src_x, entry_to_update->native_width - dst_x);
u32 copy_height =
@@ -1453,6 +1464,17 @@ TextureCacheBase::GetTextureFromOverlappingTextures(const TextureLookupInformati
dst_y = 0;
}

// If the source rectangle is outside of what we actually have in VRAM, skip the copy.
// The backend doesn't do any clamping, so if we don't, we'd pass out-of-range coordinates
// to the graphics driver, which can cause GPU resets.
if (static_cast<u32>(src_x) >= entry->native_width ||
static_cast<u32>(src_y) >= entry->native_height ||
static_cast<u32>(dst_x) >= stitched_entry->native_width ||
static_cast<u32>(dst_y) >= stitched_entry->native_height)
{
continue;
}

u32 copy_width = std::min(entry->native_width - src_x, stitched_entry->native_width - dst_x);
u32 copy_height = std::min(entry->native_height - src_y, stitched_entry->native_height - dst_y);

0 comments on commit 933f3ba

Please sign in to comment.
You can’t perform that action at this time.