Skip to content

Commit ec10c5d

Browse files
committed
rebase, initialize hash, fix bounds check
1 parent da28623 commit ec10c5d

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/video_core/texture_cache/texture_cache.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,20 @@ TextureCache::TextureCache(const Vulkan::Instance& instance_, Vulkan::Scheduler&
4343

4444
TextureCache::~TextureCache() = default;
4545

46-
void TextureCache::InvalidateMemory(VAddr addr, VAddr addr_aligned, size_t size) {
46+
void TextureCache::InvalidateMemory(VAddr addr, VAddr page_addr, size_t size) {
4747
std::scoped_lock lock{mutex};
48-
ForEachImageInRegion(addr_aligned, size, [&](ImageId image_id, Image& image) {
49-
const auto image_end = image.info.guest_address + image.info.guest_size_bytes;
50-
const auto page_end = addr_aligned + size;
51-
if (addr < image.info.guest_address) {
48+
ForEachImageInRegion(page_addr, size, [&](ImageId image_id, Image& image) {
49+
if (addr < image.cpu_addr) {
5250
// This page access may or may not modify the image.
5351
// We should not mark it as dirty now, if it really was modified,
5452
// it will receive more invalidations on subsequent pages.
55-
if (image_end < page_end) {
53+
const auto page_end = page_addr + size;
54+
if (image.cpu_addr_end <= page_end) {
55+
if (image.hash == 0) {
56+
// Initialize hash
57+
const u8* addr = std::bit_cast<u8*>(image.info.guest_address);
58+
image.hash = XXH3_64bits(addr, image.info.guest_size_bytes);
59+
}
5660
// Image ends on this page so it can not receive any more invalidations.
5761
// We will check it's hash later to see if it really was modified.
5862
image.flags |= ImageFlagBits::MaybeCpuDirty;
@@ -64,7 +68,7 @@ void TextureCache::InvalidateMemory(VAddr addr, VAddr addr_aligned, size_t size)
6468
return;
6569
}
6670

67-
if (addr < image_end) {
71+
if (addr < image.cpu_addr_end) {
6872
// Ensure image is reuploaded when accessed again.
6973
image.flags |= ImageFlagBits::CpuDirty;
7074
}

src/video_core/texture_cache/texture_cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class TextureCache {
9595
~TextureCache();
9696

9797
/// Invalidates any image in the logical page range.
98-
void InvalidateMemory(VAddr addr, VAddr addr_aligned, size_t size);
98+
void InvalidateMemory(VAddr addr, VAddr page_addr, size_t size);
9999

100100
/// Marks an image as dirty if it exists at the provided address.
101101
void InvalidateMemoryFromGPU(VAddr address, size_t max_size);

0 commit comments

Comments
 (0)