rebase, initialize hash, fix bounds check

This commit is contained in:
Vladislav Mikhalin 2024-11-25 09:50:24 +03:00
parent da28623315
commit ec10c5d94b
2 changed files with 12 additions and 8 deletions

View File

@ -43,16 +43,20 @@ TextureCache::TextureCache(const Vulkan::Instance& instance_, Vulkan::Scheduler&
TextureCache::~TextureCache() = default; TextureCache::~TextureCache() = default;
void TextureCache::InvalidateMemory(VAddr addr, VAddr addr_aligned, size_t size) { void TextureCache::InvalidateMemory(VAddr addr, VAddr page_addr, size_t size) {
std::scoped_lock lock{mutex}; std::scoped_lock lock{mutex};
ForEachImageInRegion(addr_aligned, size, [&](ImageId image_id, Image& image) { ForEachImageInRegion(page_addr, size, [&](ImageId image_id, Image& image) {
const auto image_end = image.info.guest_address + image.info.guest_size_bytes; if (addr < image.cpu_addr) {
const auto page_end = addr_aligned + size;
if (addr < image.info.guest_address) {
// This page access may or may not modify the image. // This page access may or may not modify the image.
// We should not mark it as dirty now, if it really was modified, // We should not mark it as dirty now, if it really was modified,
// it will receive more invalidations on subsequent pages. // it will receive more invalidations on subsequent pages.
if (image_end < page_end) { const auto page_end = page_addr + size;
if (image.cpu_addr_end <= page_end) {
if (image.hash == 0) {
// Initialize hash
const u8* addr = std::bit_cast<u8*>(image.info.guest_address);
image.hash = XXH3_64bits(addr, image.info.guest_size_bytes);
}
// Image ends on this page so it can not receive any more invalidations. // Image ends on this page so it can not receive any more invalidations.
// We will check it's hash later to see if it really was modified. // We will check it's hash later to see if it really was modified.
image.flags |= ImageFlagBits::MaybeCpuDirty; image.flags |= ImageFlagBits::MaybeCpuDirty;
@ -64,7 +68,7 @@ void TextureCache::InvalidateMemory(VAddr addr, VAddr addr_aligned, size_t size)
return; return;
} }
if (addr < image_end) { if (addr < image.cpu_addr_end) {
// Ensure image is reuploaded when accessed again. // Ensure image is reuploaded when accessed again.
image.flags |= ImageFlagBits::CpuDirty; image.flags |= ImageFlagBits::CpuDirty;
} }

View File

@ -95,7 +95,7 @@ public:
~TextureCache(); ~TextureCache();
/// Invalidates any image in the logical page range. /// Invalidates any image in the logical page range.
void InvalidateMemory(VAddr addr, VAddr addr_aligned, size_t size); void InvalidateMemory(VAddr addr, VAddr page_addr, size_t size);
/// Marks an image as dirty if it exists at the provided address. /// Marks an image as dirty if it exists at the provided address.
void InvalidateMemoryFromGPU(VAddr address, size_t max_size); void InvalidateMemoryFromGPU(VAddr address, size_t max_size);