texture_cache: More precise invalidation from compute

* Fixes unrelated render targets being cleared
This commit is contained in:
IndecisiveTurtle 2024-08-12 16:40:56 +03:00
parent ceb7e300e5
commit 52057b467d
3 changed files with 7 additions and 5 deletions

View File

@ -96,7 +96,7 @@ bool ComputePipeline::BindResources(VideoCore::BufferCache& buffer_cache,
Shader::PushData push_data{}; Shader::PushData push_data{};
u32 binding{}; u32 binding{};
for (u32 i = 0; const auto& buffer : info.buffers) { for (const auto& buffer : info.buffers) {
const auto vsharp = buffer.GetVsharp(info); const auto vsharp = buffer.GetVsharp(info);
const VAddr address = vsharp.base_address; const VAddr address = vsharp.base_address;
// Most of the time when a metadata is updated with a shader it gets cleared. It means we // Most of the time when a metadata is updated with a shader it gets cleared. It means we
@ -115,7 +115,7 @@ bool ComputePipeline::BindResources(VideoCore::BufferCache& buffer_cache,
} }
const u32 size = vsharp.GetSize(); const u32 size = vsharp.GetSize();
if (buffer.is_written) { if (buffer.is_written) {
texture_cache.InvalidateMemory(address, size); texture_cache.InvalidateMemory(address, size, true);
} }
const u32 alignment = const u32 alignment =
buffer.is_storage ? instance.StorageMinAlignment() : instance.UniformMinAlignment(); buffer.is_storage ? instance.StorageMinAlignment() : instance.UniformMinAlignment();
@ -137,7 +137,6 @@ bool ComputePipeline::BindResources(VideoCore::BufferCache& buffer_cache,
: vk::DescriptorType::eUniformBuffer, : vk::DescriptorType::eUniformBuffer,
.pBufferInfo = &buffer_infos.back(), .pBufferInfo = &buffer_infos.back(),
}); });
i++;
} }
for (const auto& image_desc : info.images) { for (const auto& image_desc : info.images) {

View File

@ -31,9 +31,12 @@ TextureCache::TextureCache(const Vulkan::Instance& instance_, Vulkan::Scheduler&
TextureCache::~TextureCache() = default; TextureCache::~TextureCache() = default;
void TextureCache::InvalidateMemory(VAddr address, size_t size) { void TextureCache::InvalidateMemory(VAddr address, size_t size, bool from_compute) {
std::unique_lock lock{mutex}; std::unique_lock lock{mutex};
ForEachImageInRegion(address, size, [&](ImageId image_id, Image& image) { ForEachImageInRegion(address, size, [&](ImageId image_id, Image& image) {
if (from_compute && !image.Overlaps(address, size)) {
return;
}
// Ensure image is reuploaded when accessed again. // Ensure image is reuploaded when accessed again.
image.flags |= ImageFlagBits::CpuModified; image.flags |= ImageFlagBits::CpuModified;
// Untrack image, so the range is unprotected and the guest can write freely. // Untrack image, so the range is unprotected and the guest can write freely.

View File

@ -38,7 +38,7 @@ public:
~TextureCache(); ~TextureCache();
/// Invalidates any image in the logical page range. /// Invalidates any image in the logical page range.
void InvalidateMemory(VAddr address, size_t size); void InvalidateMemory(VAddr address, size_t size, bool from_compute = false);
/// Evicts any images that overlap the unmapped range. /// Evicts any images that overlap the unmapped range.
void UnmapMemory(VAddr cpu_addr, size_t size); void UnmapMemory(VAddr cpu_addr, size_t size);