mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-04 08:22:32 +00:00
rebase, initialize hash, fix bounds check
This commit is contained in:
parent
da28623315
commit
ec10c5d94b
@ -43,16 +43,20 @@ TextureCache::TextureCache(const Vulkan::Instance& instance_, Vulkan::Scheduler&
|
||||
|
||||
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};
|
||||
ForEachImageInRegion(addr_aligned, size, [&](ImageId image_id, Image& image) {
|
||||
const auto image_end = image.info.guest_address + image.info.guest_size_bytes;
|
||||
const auto page_end = addr_aligned + size;
|
||||
if (addr < image.info.guest_address) {
|
||||
ForEachImageInRegion(page_addr, size, [&](ImageId image_id, Image& image) {
|
||||
if (addr < image.cpu_addr) {
|
||||
// This page access may or may not modify the image.
|
||||
// We should not mark it as dirty now, if it really was modified,
|
||||
// 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.
|
||||
// We will check it's hash later to see if it really was modified.
|
||||
image.flags |= ImageFlagBits::MaybeCpuDirty;
|
||||
@ -64,7 +68,7 @@ void TextureCache::InvalidateMemory(VAddr addr, VAddr addr_aligned, size_t size)
|
||||
return;
|
||||
}
|
||||
|
||||
if (addr < image_end) {
|
||||
if (addr < image.cpu_addr_end) {
|
||||
// Ensure image is reuploaded when accessed again.
|
||||
image.flags |= ImageFlagBits::CpuDirty;
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ public:
|
||||
~TextureCache();
|
||||
|
||||
/// 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.
|
||||
void InvalidateMemoryFromGPU(VAddr address, size_t max_size);
|
||||
|
Loading…
Reference in New Issue
Block a user