@@ -43,16 +43,20 @@ TextureCache::TextureCache(const Vulkan::Instance& instance_, Vulkan::Scheduler&
43
43
44
44
TextureCache::~TextureCache () = default ;
45
45
46
- void TextureCache::InvalidateMemory (VAddr addr, VAddr addr_aligned , size_t size) {
46
+ void TextureCache::InvalidateMemory (VAddr addr, VAddr page_addr , size_t size) {
47
47
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 ) {
52
50
// This page access may or may not modify the image.
53
51
// We should not mark it as dirty now, if it really was modified,
54
52
// 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
+ }
56
60
// Image ends on this page so it can not receive any more invalidations.
57
61
// We will check it's hash later to see if it really was modified.
58
62
image.flags |= ImageFlagBits::MaybeCpuDirty;
@@ -64,7 +68,7 @@ void TextureCache::InvalidateMemory(VAddr addr, VAddr addr_aligned, size_t size)
64
68
return ;
65
69
}
66
70
67
- if (addr < image_end ) {
71
+ if (addr < image. cpu_addr_end ) {
68
72
// Ensure image is reuploaded when accessed again.
69
73
image.flags |= ImageFlagBits::CpuDirty;
70
74
}
0 commit comments