graphics: avoid full-cache scans when deleting stencil associations

Co-authored-by: overlordxrz-source <overlordxrz-source@users.noreply.github.com>
Co-authored-by: TheCruZ <thecruzwtf@gmail.com>
This commit is contained in:
nmzik
2026-10-12 15:33:25 +02:00
parent df5b9b92be
commit f4692a450e
3 changed files with 42 additions and 11 deletions
+12 -8
View File
@@ -25,6 +25,7 @@
#include <mutex>
#include <span>
#include <tuple>
#include <utility>
#include <vulkan/vulkan_format_traits.hpp>
namespace Libs::Graphics {
@@ -251,14 +252,11 @@ void TextureCache::DeleteImage(ImageId id) {
if (image == nullptr || !image->registered) {
return;
}
if (!image->depth_id) {
std::vector<ImageId> associations;
m_slot_images.ForEach([&](ImageId candidate, const Image& associated) {
if (associated.depth_id == id) {
associations.push_back(candidate);
}
});
for (const auto association: associations) {
if (image->depth_id) {
std::erase(m_slot_images[image->depth_id].stencil_ids, id);
} else {
// Detach first: deleting each association also unlinks it from its depth owner.
for (const auto association: std::exchange(image->stencil_ids, {})) {
FreeImage(association);
}
}
@@ -1205,6 +1203,12 @@ ImageId TextureCache::AssociateStencil(ImageId depth_id, GuestRange stencil) {
plane.IsTiled() ? TileGetDepthPitch(plane.extent.width, 1, 0) : depth.info.pitch;
plane.bytes_per_block = 1;
plane.UpdateSize();
if (record.depth_id != depth_id) {
if (record.depth_id) {
std::erase(m_slot_images[record.depth_id].stencil_ids, association);
}
depth.stencil_ids.push_back(association);
}
record.info = plane;
record.depth_id = depth_id;
record.stencil_subresources = depth.stencil_subresources;
@@ -149,6 +149,8 @@ public:
uint64_t track_addr = 0;
uint64_t track_addr_end = 0;
ImageId depth_id {};
// Stencil associations that refer to this depth image.
std::vector<ImageId> stencil_ids;
// The current stencil plane's mapping into the depth image, also retained by its association.
ImageSubresourceRange stencil_subresources;
uint64_t tick_accessed_last = 0;