renderer: align texture overlap retirement

This commit is contained in:
nmzik
2026-08-18 03:53:45 +02:00
parent 840d742230
commit 6407add888
3 changed files with 21 additions and 51 deletions
+8 -37
View File
@@ -22,7 +22,7 @@
#include <cstring>
#include <limits>
#include <mutex>
#include <set>
#include <span>
#include <tuple>
#include <vulkan/vulkan_format_traits.hpp>
@@ -279,27 +279,6 @@ void TextureCache::FreeImage(ImageId id) {
DeleteImage(id);
}
void TextureCache::DeleteImages(std::span<const ImageId> ids,
std::optional<ImageId> native_source) {
std::set<std::pair<uint32_t, uint32_t>> unique;
for (const auto id: ids) {
if (!id || !unique.emplace(id.index, id.generation).second) {
continue;
}
auto owner = ResolveOwner(id);
if (owner == nullptr) {
continue;
}
if (native_source == id) {
ClearGpuModified(id);
} else if (owner->IsGpuModified()) {
DownloadImage(id);
ClearGpuModified(id);
}
DeleteImage(id);
}
}
void TextureCache::RetainImage(CommandBuffer& command, ImageId id) {
auto owner = ResolveOwner(id);
if (owner == nullptr) {
@@ -729,7 +708,6 @@ ImageId TextureCache::ResolveDepthOverlap(const ImageInfo& requested, BindingTyp
if (cached.binding.is_bound || cached.binding.is_target) {
cached.binding.needs_rebind = true;
}
bool copied = false;
if (cached.backing.samples == replacement.backing.samples) {
const bool copy_supported =
cached.backing.samples == 1 || cached.backing.format == replacement.backing.format ||
@@ -737,7 +715,6 @@ ImageId TextureCache::ResolveDepthOverlap(const ImageInfo& requested, BindingTyp
ImageViewOps::FormatsCompatible(cached.backing.format, replacement.backing.format));
if (copy_supported) {
CopyImage(replacement_id, cached_id);
copied = true;
} else {
LOGF_COLOR(Log::Color::BrightYellow,
"TextureCache: unsupported cross-format multisample depth copy\n");
@@ -754,18 +731,12 @@ ImageId TextureCache::ResolveDepthOverlap(const ImageInfo& requested, BindingTyp
RetainImage(command, cached_id);
RetainImage(command, replacement_id);
CommitGpuWrite(replacement);
copied = true;
} else {
LOGF_COLOR(Log::Color::BrightYellow,
"TextureCache: unsupported unequal-sample depth overlap copy (%u -> %u)\n",
cached.backing.samples, replacement.backing.samples);
}
if (copied) {
DeleteImages(std::array {cached_id}, cached_id);
} else {
ClearGpuModified(cached_id);
DeleteImage(cached_id);
}
FreeImage(cached_id);
return replacement_id;
}
@@ -787,7 +758,7 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques
if (requested.BlockExtent() != cached.info.BlockExtent() ||
requested_block != cached_block) {
if (safe_to_delete) {
DeleteImages(std::array {cached_id}, cached_id);
FreeImage(cached_id);
}
return {merged_id};
}
@@ -804,7 +775,7 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques
}
if (requested.tile_mode != cached.info.tile_mode) {
if (safe_to_delete) {
DeleteImages(std::array {cached_id}, cached_id);
FreeImage(cached_id);
}
return {merged_id};
}
@@ -840,7 +811,7 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques
}
}
if (safe_to_delete) {
DeleteImages(std::array {cached_id}, cached_id);
FreeImage(cached_id);
}
return {};
}
@@ -854,13 +825,13 @@ TextureCache::OverlapResult TextureCache::ResolveOverlap(const ImageInfo& reques
if (merged_id) {
ResolveImage(merged_id).binding.is_target = true;
}
DeleteImages(std::array {cached_id}, cached_id);
FreeImage(cached_id);
return {merged_id};
}
if (merged_id) {
CopyImageMip(merged_id, cached_id, static_cast<uint32_t>(mip),
static_cast<uint32_t>(layer));
DeleteImages(std::array {cached_id}, cached_id);
FreeImage(cached_id);
}
}
}
@@ -879,7 +850,7 @@ ImageId TextureCache::ExpandImage(const ImageInfo& info, ImageId source_id) {
InitializeImage(expanded_id,
ImageDesc {.info = info, .view_info = {}, .type = UploadBinding(source)});
CopyImage(expanded_id, source_id);
DeleteImages(std::array {source_id}, source_id);
FreeImage(source_id);
return expanded_id;
}
+11 -14
View File
@@ -13,9 +13,7 @@
#include <compare>
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <span>
#include <utility>
#include <vector>
@@ -111,18 +109,17 @@ private:
void UnregisterImage(ImageId id);
void DeleteImage(ImageId id);
void FreeImage(ImageId id);
void DeleteImages(std::span<const ImageId> ids, std::optional<ImageId> native_source = {});
void RetainImage(CommandBuffer& command, ImageId id);
void TouchImage(Image& image);
void TrackImage(ImageId id);
void TrackImageHead(ImageId id);
void TrackImageTail(ImageId id);
void UntrackImage(ImageId id);
void UntrackImageHead(ImageId id);
void UntrackImageTail(ImageId id);
void MarkAsMaybeDirty(ImageId id, Image& image);
void TrackImageDownload(ImageId id);
void TrackImageDownloadLocked(ImageId id, Image& image);
void RetainImage(CommandBuffer& command, ImageId id);
void TouchImage(Image& image);
void TrackImage(ImageId id);
void TrackImageHead(ImageId id);
void TrackImageTail(ImageId id);
void UntrackImage(ImageId id);
void UntrackImageHead(ImageId id);
void UntrackImageTail(ImageId id);
void MarkAsMaybeDirty(ImageId id, Image& image);
void TrackImageDownload(ImageId id);
void TrackImageDownloadLocked(ImageId id, Image& image);
[[nodiscard]] static bool SameBacking(const ImageInfo& cached, const ImageInfo& requested,
bool exact_format);
[[nodiscard]] static BindingType UploadBinding(const Image& image);
+2
View File
@@ -7646,6 +7646,8 @@ public:
array_target_view != nullptr && array_target_owner != nullptr &&
array_target_owner->binding.needs_rebind &&
expanded_array_id != array_target_id &&
!TextureCacheTestAccess::Contains(texture_cache,
array_target_id) &&
array_binding.resources.images[0].image_view != nullptr &&
array_binding.resources.images[0].desc.info.type ==
Prospero::ImageType::kColor2D &&