Skip to content

Commit

Permalink
texture_cache: Lock when updating image. (shadps4-emu#2198)
Browse files Browse the repository at this point in the history
  • Loading branch information
squidbus authored Jan 20, 2025
1 parent a3967cc commit 95a30b2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/video_core/texture_cache/texture_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,13 @@ void TextureCache::MarkAsMaybeDirty(ImageId image_id, Image& image) {

void TextureCache::InvalidateMemory(VAddr addr, size_t size) {
std::scoped_lock lock{mutex};
const auto end = addr + size;
const auto pages_start = PageManager::GetPageAddr(addr);
const auto pages_end = PageManager::GetNextPageAddr(addr + size - 1);
ForEachImageInRegion(pages_start, pages_end - pages_start, [&](ImageId image_id, Image& image) {
const auto image_begin = image.info.guest_address;
const auto image_end = image.info.guest_address + image.info.guest_size;
if (image_begin < end && addr < image_end) {
// Start or end of the modified region is in the image, or the image is entirely within
// the modified region, so the image was definitely accessed by this page fault.
if (image.Overlaps(addr, size)) {
// Modified region overlaps image, so the image was definitely accessed by this fault.
// Untrack the image, so that the range is unprotected and the guest can write freely.
image.flags |= ImageFlagBits::CpuDirty;
UntrackImage(image_id);
Expand Down
1 change: 1 addition & 0 deletions src/video_core/texture_cache/texture_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class TextureCache {

/// Updates image contents if it was modified by CPU.
void UpdateImage(ImageId image_id, Vulkan::Scheduler* custom_scheduler = nullptr) {
std::scoped_lock lock{mutex};
Image& image = slot_images[image_id];
TrackImage(image_id);
RefreshImage(image, custom_scheduler);
Expand Down

0 comments on commit 95a30b2

Please sign in to comment.