From 779f4ac72d2ea2788c2106c8d2d1ec0e01b77b81 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Sun, 21 Nov 2021 05:32:34 +0100 Subject: TextureCache: Eliminate format deduction as full depth conversion has been supported. --- src/video_core/texture_cache/texture_cache.h | 6 ++---- src/video_core/texture_cache/util.cpp | 28 +++------------------------- 2 files changed, 5 insertions(+), 29 deletions(-) (limited to 'src/video_core/texture_cache') diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index 44a0d42ba..0e4907c53 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h @@ -1079,7 +1079,7 @@ ImageId TextureCache
::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VA
template ::BlitImages TextureCache ::GetBlitImages(
const Tegra::Engines::Fermi2D::Surface& dst, const Tegra::Engines::Fermi2D::Surface& src) {
- static constexpr auto FIND_OPTIONS = RelaxedOptions::Format | RelaxedOptions::Samples;
+ static constexpr auto FIND_OPTIONS = RelaxedOptions::Samples;
const GPUVAddr dst_addr = dst.Address();
const GPUVAddr src_addr = src.Address();
ImageInfo dst_info(dst);
@@ -1093,9 +1093,7 @@ typename TextureCache ::BlitImages TextureCache ::GetBlitImages(
const ImageBase* const dst_image = dst_id ? &slot_images[dst_id] : nullptr;
const ImageBase* const src_image = src_id ? &slot_images[src_id] : nullptr;
DeduceBlitImages(dst_info, src_info, dst_image, src_image);
- if (GetFormatType(dst_info.format) != GetFormatType(src_info.format)) {
- continue;
- }
+ ASSERT(GetFormatType(dst_info.format) == GetFormatType(src_info.format));
RelaxedOptions find_options{};
if (src_info.num_samples > 1) {
// it's a resolve, we must enforce the same format.
diff --git a/src/video_core/texture_cache/util.cpp b/src/video_core/texture_cache/util.cpp
index e4d82631e..777503488 100644
--- a/src/video_core/texture_cache/util.cpp
+++ b/src/video_core/texture_cache/util.cpp
@@ -1152,36 +1152,14 @@ bool IsSubresource(const ImageInfo& candidate, const ImageBase& image, GPUVAddr
void DeduceBlitImages(ImageInfo& dst_info, ImageInfo& src_info, const ImageBase* dst,
const ImageBase* src) {
bool is_resolve = false;
- const auto original_src_format = src_info.format;
- const auto original_dst_format = dst_info.format;
if (src) {
- if (GetFormatType(src->info.format) != SurfaceType::ColorTexture) {
- src_info.format = src->info.format;
- }
is_resolve = src->info.num_samples > 1;
src_info.num_samples = src->info.num_samples;
src_info.size = src->info.size;
}
- if (dst && GetFormatType(dst->info.format) != SurfaceType::ColorTexture) {
- dst_info.format = dst->info.format;
- }
- if (src && GetFormatType(src->info.format) != SurfaceType::ColorTexture) {
- if (dst) {
- if (GetFormatType(dst->info.format) == SurfaceType::ColorTexture) {
- src_info.format = original_src_format;
- }
- } else {
- dst_info.format = src->info.format;
- }
- }
- if (dst && GetFormatType(dst->info.format) != SurfaceType::ColorTexture) {
- if (src) {
- if (GetFormatType(src->info.format) == SurfaceType::ColorTexture) {
- dst_info.format = original_dst_format;
- }
- } else {
- src_info.format = dst->info.format;
- }
+ if (dst) {
+ dst_info.num_samples = dst->info.num_samples;
+ dst_info.size = dst->info.size;
}
ASSERT(!is_resolve || dst_info.format == src_info.format);
}
--
cgit v1.2.3
From 853284943901560081f6ff992b6c04b7c33f0d21 Mon Sep 17 00:00:00 2001
From: Fernando Sahmkow
Date: Mon, 22 Nov 2021 00:00:01 +0100
Subject: TextureCache: Simplify blitting of D24S8 formats and fix bugs.
---
src/video_core/texture_cache/texture_cache.h | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
(limited to 'src/video_core/texture_cache')
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h
index 0e4907c53..9548abec8 100644
--- a/src/video_core/texture_cache/texture_cache.h
+++ b/src/video_core/texture_cache/texture_cache.h
@@ -1781,7 +1781,13 @@ void TextureCache ::CopyImage(ImageId dst_id, ImageId src_id, std::vector ::BlitImages TextureCache ::GetBlitImages(
ImageId src_id;
do {
has_deleted_images = false;
- dst_id = FindImage(dst_info, dst_addr, FIND_OPTIONS);
src_id = FindImage(src_info, src_addr, FIND_OPTIONS);
- const ImageBase* const dst_image = dst_id ? &slot_images[dst_id] : nullptr;
const ImageBase* const src_image = src_id ? &slot_images[src_id] : nullptr;
- DeduceBlitImages(dst_info, src_info, dst_image, src_image);
- ASSERT(GetFormatType(dst_info.format) == GetFormatType(src_info.format));
- RelaxedOptions find_options{};
- if (src_info.num_samples > 1) {
- // it's a resolve, we must enforce the same format.
- find_options = RelaxedOptions::ForceBrokenViews;
- }
- src_id = FindOrInsertImage(src_info, src_addr, find_options);
- dst_id = FindOrInsertImage(dst_info, dst_addr, find_options);
+ if (src_image && src_image->info.num_samples > 1) {
+ RelaxedOptions find_options{FIND_OPTIONS | RelaxedOptions::ForceBrokenViews};
+ src_id = FindOrInsertImage(src_info, src_addr, find_options);
+ dst_id = FindOrInsertImage(dst_info, dst_addr, find_options);
+ if (has_deleted_images) {
+ continue;
+ }
+ }
+ dst_id = FindImage(dst_info, dst_addr, FIND_OPTIONS);
+ if (!src_id) {
+ src_id = InsertImage(src_info, src_addr, RelaxedOptions{});
+ }
+ if (!dst_id) {
+ dst_id = InsertImage(dst_info, dst_addr, RelaxedOptions{});
+ }
} while (has_deleted_images);
return BlitImages{
.dst_id = dst_id,
--
cgit v1.2.3
From ecefc932e64bf4ab8442d3c9808a2e54429e7001 Mon Sep 17 00:00:00 2001
From: Fernando Sahmkow
Date: Fri, 26 Nov 2021 21:36:53 +0100
Subject: Texture Cache: Redesigning the blitting system (again).
---
src/video_core/texture_cache/texture_cache.h | 52 +++++++++++++++++++----
src/video_core/texture_cache/texture_cache_base.h | 3 +-
src/video_core/texture_cache/util.cpp | 32 ++++++++------
3 files changed, 64 insertions(+), 23 deletions(-)
(limited to 'src/video_core/texture_cache')
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h
index 570da2b04..f24de9a38 100644
--- a/src/video_core/texture_cache/texture_cache.h
+++ b/src/video_core/texture_cache/texture_cache.h
@@ -472,7 +472,7 @@ template ::BlitImage(const Tegra::Engines::Fermi2D::Surface& dst,
const Tegra::Engines::Fermi2D::Surface& src,
const Tegra::Engines::Fermi2D::Config& copy) {
- const BlitImages images = GetBlitImages(dst, src);
+ const BlitImages images = GetBlitImages(dst, src, copy);
const ImageId dst_id = images.dst_id;
const ImageId src_id = images.src_id;
@@ -762,12 +762,15 @@ ImageId TextureCache ::FindImage(const ImageInfo& info, GPUVAddr gpu_addr,
const bool broken_views =
runtime.HasBrokenTextureViewFormats() || True(options & RelaxedOptions::ForceBrokenViews);
const bool native_bgr = runtime.HasNativeBgr();
- ImageId image_id;
+ const bool flexible_formats = True(options & RelaxedOptions::Format);
+ ImageId image_id{};
+ boost::container::small_vector ::FindImage(const ImageInfo& info, GPUVAddr gpu_addr,
IsPitchLinearSameSize(existing, info, strict_size) &&
IsViewCompatible(existing.format, info.format, broken_views, native_bgr)) {
image_id = existing_image_id;
- return true;
+ image_ids.push_back(existing_image_id);
+ return !flexible_formats && existing.format == info.format;
}
} else if (IsSubresource(info, existing_image, gpu_addr, options, broken_views,
native_bgr)) {
image_id = existing_image_id;
- return true;
+ image_ids.push_back(existing_image_id);
+ return !flexible_formats && existing_image.info.format == info.format;
}
return false;
};
ForEachImageInRegion(*cpu_addr, CalculateGuestSizeInBytes(info), lambda);
- return image_id;
+ if (image_ids.size() <= 1) [[likely]] {
+ return image_id;
+ }
+ auto image_ids_compare = [this](ImageId a, ImageId b) {
+ auto& image_a = slot_images[a];
+ auto& image_b = slot_images[b];
+ return image_a.modification_tick < image_b.modification_tick;
+ };
+ return *std::ranges::max_element(image_ids, image_ids_compare);
}
template ::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VA
template ::BlitImages TextureCache ::GetBlitImages(
- const Tegra::Engines::Fermi2D::Surface& dst, const Tegra::Engines::Fermi2D::Surface& src) {
+ const Tegra::Engines::Fermi2D::Surface& dst, const Tegra::Engines::Fermi2D::Surface& src,
+ const Tegra::Engines::Fermi2D::Config& copy) {
+
static constexpr auto FIND_OPTIONS = RelaxedOptions::Samples;
const GPUVAddr dst_addr = dst.Address();
const GPUVAddr src_addr = src.Address();
ImageInfo dst_info(dst);
ImageInfo src_info(src);
+ const bool can_be_depth_blit =
+ dst_info.format == src_info.format && copy.filter == Tegra::Engines::Fermi2D::Filter::Point;
ImageId dst_id;
ImageId src_id;
+ RelaxedOptions try_options = FIND_OPTIONS;
+ if (can_be_depth_blit) {
+ try_options |= RelaxedOptions::Format;
+ }
do {
has_deleted_images = false;
- src_id = FindImage(src_info, src_addr, FIND_OPTIONS);
+ src_id = FindImage(src_info, src_addr, try_options);
+ dst_id = FindImage(dst_info, dst_addr, try_options);
const ImageBase* const src_image = src_id ? &slot_images[src_id] : nullptr;
if (src_image && src_image->info.num_samples > 1) {
RelaxedOptions find_options{FIND_OPTIONS | RelaxedOptions::ForceBrokenViews};
@@ -1097,8 +1119,15 @@ typename TextureCache ::BlitImages TextureCache ::GetBlitImages(
if (has_deleted_images) {
continue;
}
+ break;
+ }
+ if (can_be_depth_blit) {
+ const ImageBase* const dst_image = src_id ? &slot_images[src_id] : nullptr;
+ DeduceBlitImages(dst_info, src_info, dst_image, src_image);
+ if (GetFormatType(dst_info.format) != GetFormatType(src_info.format)) {
+ continue;
+ }
}
- dst_id = FindImage(dst_info, dst_addr, FIND_OPTIONS);
if (!src_id) {
src_id = InsertImage(src_info, src_addr, RelaxedOptions{});
}
@@ -1106,6 +1135,11 @@ typename TextureCache ::BlitImages TextureCache ::GetBlitImages(
dst_id = InsertImage(dst_info, dst_addr, RelaxedOptions{});
}
} while (has_deleted_images);
+ if (GetFormatType(dst_info.format) != SurfaceType::ColorTexture) {
+ // Make sure the images are depth and/or stencil textures.
+ src_id = FindOrInsertImage(src_info, src_addr, RelaxedOptions{});
+ dst_id = FindOrInsertImage(dst_info, dst_addr, RelaxedOptions{});
+ }
return BlitImages{
.dst_id = dst_id,
.src_id = src_id,
diff --git a/src/video_core/texture_cache/texture_cache_base.h b/src/video_core/texture_cache/texture_cache_base.h
index 643ad811c..7107887a6 100644
--- a/src/video_core/texture_cache/texture_cache_base.h
+++ b/src/video_core/texture_cache/texture_cache_base.h
@@ -252,7 +252,8 @@ private:
/// Return a blit image pair from the given guest blit parameters
[[nodiscard]] BlitImages GetBlitImages(const Tegra::Engines::Fermi2D::Surface& dst,
- const Tegra::Engines::Fermi2D::Surface& src);
+ const Tegra::Engines::Fermi2D::Surface& src,
+ const Tegra::Engines::Fermi2D::Config& copy);
/// Find or create a sampler from a guest descriptor sampler
[[nodiscard]] SamplerId FindSampler(const TSCEntry& config);
diff --git a/src/video_core/texture_cache/util.cpp b/src/video_core/texture_cache/util.cpp
index 9b1613008..7bd31b211 100644
--- a/src/video_core/texture_cache/util.cpp
+++ b/src/video_core/texture_cache/util.cpp
@@ -1151,19 +1151,25 @@ bool IsSubresource(const ImageInfo& candidate, const ImageBase& image, GPUVAddr
void DeduceBlitImages(ImageInfo& dst_info, ImageInfo& src_info, const ImageBase* dst,
const ImageBase* src) {
- bool is_resolve = false;
- if (src) {
- is_resolve = src->info.num_samples > 1;
- src_info.num_samples = src->info.num_samples;
- src_info.size.width = src->info.size.width;
- src_info.size.height = src->info.size.height;
- }
- if (dst) {
- dst_info.num_samples = dst->info.num_samples;
- dst_info.size.width = dst->info.size.width;
- dst_info.size.height = dst->info.size.height;
- }
- ASSERT(!is_resolve || dst_info.format == src_info.format);
+ const auto original_dst_format = dst_info.format;
+ if (src && GetFormatType(src->info.format) != SurfaceType::ColorTexture) {
+ src_info.format = src->info.format;
+ }
+ if (dst && GetFormatType(dst->info.format) != SurfaceType::ColorTexture) {
+ dst_info.format = dst->info.format;
+ }
+ if (src && GetFormatType(src->info.format) != SurfaceType::ColorTexture) {
+ dst_info.format = src->info.format;
+ }
+ if (dst && GetFormatType(dst->info.format) != SurfaceType::ColorTexture) {
+ if (src) {
+ if (GetFormatType(src->info.format) == SurfaceType::ColorTexture) {
+ dst_info.format = original_dst_format;
+ }
+ } else {
+ src_info.format = dst->info.format;
+ }
+ }
}
u32 MapSizeBytes(const ImageBase& image) {
--
cgit v1.2.3
From 5a3463bc2b1489dda6b5fe90110f9260f6b68463 Mon Sep 17 00:00:00 2001
From: Fernando Sahmkow
Date: Sat, 27 Nov 2021 23:49:56 +0100
Subject: Texture Cache: Secure insertions against deletions.
---
src/video_core/texture_cache/texture_cache.h | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
(limited to 'src/video_core/texture_cache')
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h
index f24de9a38..565b99254 100644
--- a/src/video_core/texture_cache/texture_cache.h
+++ b/src/video_core/texture_cache/texture_cache.h
@@ -1137,8 +1137,11 @@ typename TextureCache ::BlitImages TextureCache ::GetBlitImages(
} while (has_deleted_images);
if (GetFormatType(dst_info.format) != SurfaceType::ColorTexture) {
// Make sure the images are depth and/or stencil textures.
- src_id = FindOrInsertImage(src_info, src_addr, RelaxedOptions{});
- dst_id = FindOrInsertImage(dst_info, dst_addr, RelaxedOptions{});
+ do {
+ has_deleted_images = false;
+ src_id = FindOrInsertImage(src_info, src_addr, RelaxedOptions{});
+ dst_id = FindOrInsertImage(dst_info, dst_addr, RelaxedOptions{});
+ } while (has_deleted_images);
}
return BlitImages{
.dst_id = dst_id,
@@ -1196,7 +1199,14 @@ template ::FindRenderTargetView(const ImageInfo& info, GPUVAddr gpu_addr,
bool is_clear) {
const auto options = is_clear ? RelaxedOptions::Samples : RelaxedOptions{};
- const ImageId image_id = FindOrInsertImage(info, gpu_addr, options);
+ ImageId image_id{};
+ bool delete_state = has_deleted_images;
+ do {
+ has_deleted_images = false;
+ image_id = FindOrInsertImage(info, gpu_addr, options);
+ delete_state |= has_deleted_images;
+ } while (has_deleted_images);
+ has_deleted_images = delete_state;
if (!image_id) {
return NULL_IMAGE_VIEW_ID;
}
--
cgit v1.2.3