From 933f3ba008942cba96ed623c25e61d6ea86582fe Mon Sep 17 00:00:00 2001 From: Stenzek Date: Fri, 15 Feb 2019 11:58:59 +1000 Subject: [PATCH] TextureCache: Don't copy out-of-range rectangles when stitching textures This can cause driver crashes or GPU hangs if we do. --- Source/Core/VideoCommon/TextureCacheBase.cpp | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index d0355b724b..90abc01c65 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/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(src_x) >= entry->native_width || + static_cast(src_y) >= entry->native_height || + static_cast(dst_x) >= entry_to_update->native_width || + static_cast(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(src_x) >= entry->native_width || + static_cast(src_y) >= entry->native_height || + static_cast(dst_x) >= stitched_entry->native_width || + static_cast(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);