summaryrefslogtreecommitdiff
path: root/src/video_core/texture_cache
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2021-07-28 02:47:06 -0300
committerGravatar Fernando Sahmkow2021-11-16 22:11:28 +0100
commit56ccda1d9952368d0c1e29d7c4b486c547de9549 (patch)
treeb2064ced92ef5ee0f4a67169df10462414664db9 /src/video_core/texture_cache
parentVulkan: Fix downscaling Blit. (diff)
downloadyuzu-56ccda1d9952368d0c1e29d7c4b486c547de9549.tar.gz
yuzu-56ccda1d9952368d0c1e29d7c4b486c547de9549.tar.xz
yuzu-56ccda1d9952368d0c1e29d7c4b486c547de9549.zip
texture_cache: Simplify image view queries and blacklisting
Diffstat (limited to 'src/video_core/texture_cache')
-rw-r--r--src/video_core/texture_cache/image_base.cpp2
-rw-r--r--src/video_core/texture_cache/image_base.h3
-rw-r--r--src/video_core/texture_cache/image_view_base.cpp2
-rw-r--r--src/video_core/texture_cache/image_view_base.h4
-rw-r--r--src/video_core/texture_cache/texture_cache.h47
-rw-r--r--src/video_core/texture_cache/texture_cache_base.h30
-rw-r--r--src/video_core/texture_cache/types.h7
7 files changed, 60 insertions, 35 deletions
diff --git a/src/video_core/texture_cache/image_base.cpp b/src/video_core/texture_cache/image_base.cpp
index e9e725edf..25a211df8 100644
--- a/src/video_core/texture_cache/image_base.cpp
+++ b/src/video_core/texture_cache/image_base.cpp
@@ -69,6 +69,8 @@ ImageBase::ImageBase(const ImageInfo& info_, GPUVAddr gpu_addr_, VAddr cpu_addr_
69 } 69 }
70} 70}
71 71
72ImageBase::ImageBase(const NullImageParams&) {}
73
72ImageMapView::ImageMapView(GPUVAddr gpu_addr_, VAddr cpu_addr_, size_t size_, ImageId image_id_) 74ImageMapView::ImageMapView(GPUVAddr gpu_addr_, VAddr cpu_addr_, size_t size_, ImageId image_id_)
73 : gpu_addr{gpu_addr_}, cpu_addr{cpu_addr_}, size{size_}, image_id{image_id_} {} 75 : gpu_addr{gpu_addr_}, cpu_addr{cpu_addr_}, size{size_}, image_id{image_id_} {}
74 76
diff --git a/src/video_core/texture_cache/image_base.h b/src/video_core/texture_cache/image_base.h
index 97f107b4d..9c34687e0 100644
--- a/src/video_core/texture_cache/image_base.h
+++ b/src/video_core/texture_cache/image_base.h
@@ -48,8 +48,11 @@ struct AliasedImage {
48 ImageId id; 48 ImageId id;
49}; 49};
50 50
51struct NullImageParams {};
52
51struct ImageBase { 53struct ImageBase {
52 explicit ImageBase(const ImageInfo& info, GPUVAddr gpu_addr, VAddr cpu_addr); 54 explicit ImageBase(const ImageInfo& info, GPUVAddr gpu_addr, VAddr cpu_addr);
55 explicit ImageBase(const NullImageParams&);
53 56
54 [[nodiscard]] std::optional<SubresourceBase> TryFindBase(GPUVAddr other_addr) const noexcept; 57 [[nodiscard]] std::optional<SubresourceBase> TryFindBase(GPUVAddr other_addr) const noexcept;
55 58
diff --git a/src/video_core/texture_cache/image_view_base.cpp b/src/video_core/texture_cache/image_view_base.cpp
index 450becbeb..e66dc9320 100644
--- a/src/video_core/texture_cache/image_view_base.cpp
+++ b/src/video_core/texture_cache/image_view_base.cpp
@@ -45,6 +45,6 @@ ImageViewBase::ImageViewBase(const ImageInfo& info, const ImageViewInfo& view_in
45 ASSERT_MSG(view_info.type == ImageViewType::Buffer, "Expected texture buffer"); 45 ASSERT_MSG(view_info.type == ImageViewType::Buffer, "Expected texture buffer");
46} 46}
47 47
48ImageViewBase::ImageViewBase(const NullImageParams&) {} 48ImageViewBase::ImageViewBase(const NullImageViewParams&) : image_id{NULL_IMAGE_ID} {}
49 49
50} // namespace VideoCommon 50} // namespace VideoCommon
diff --git a/src/video_core/texture_cache/image_view_base.h b/src/video_core/texture_cache/image_view_base.h
index 903f715c5..9c24c5359 100644
--- a/src/video_core/texture_cache/image_view_base.h
+++ b/src/video_core/texture_cache/image_view_base.h
@@ -15,7 +15,7 @@ using VideoCore::Surface::PixelFormat;
15struct ImageViewInfo; 15struct ImageViewInfo;
16struct ImageInfo; 16struct ImageInfo;
17 17
18struct NullImageParams {}; 18struct NullImageViewParams {};
19 19
20enum class ImageViewFlagBits : u16 { 20enum class ImageViewFlagBits : u16 {
21 PreemtiveDownload = 1 << 0, 21 PreemtiveDownload = 1 << 0,
@@ -28,7 +28,7 @@ struct ImageViewBase {
28 explicit ImageViewBase(const ImageViewInfo& info, const ImageInfo& image_info, 28 explicit ImageViewBase(const ImageViewInfo& info, const ImageInfo& image_info,
29 ImageId image_id); 29 ImageId image_id);
30 explicit ImageViewBase(const ImageInfo& info, const ImageViewInfo& view_info); 30 explicit ImageViewBase(const ImageInfo& info, const ImageViewInfo& view_info);
31 explicit ImageViewBase(const NullImageParams&); 31 explicit ImageViewBase(const NullImageViewParams&);
32 32
33 [[nodiscard]] bool IsBuffer() const noexcept { 33 [[nodiscard]] bool IsBuffer() const noexcept {
34 return type == ImageViewType::Buffer; 34 return type == ImageViewType::Buffer;
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h
index be40f6b88..4e97a9e6a 100644
--- a/src/video_core/texture_cache/texture_cache.h
+++ b/src/video_core/texture_cache/texture_cache.h
@@ -36,7 +36,6 @@ TextureCache<P>::TextureCache(Runtime& runtime_, VideoCore::RasterizerInterface&
36 Tegra::MemoryManager& gpu_memory_) 36 Tegra::MemoryManager& gpu_memory_)
37 : runtime{runtime_}, rasterizer{rasterizer_}, maxwell3d{maxwell3d_}, 37 : runtime{runtime_}, rasterizer{rasterizer_}, maxwell3d{maxwell3d_},
38 kepler_compute{kepler_compute_}, gpu_memory{gpu_memory_} { 38 kepler_compute{kepler_compute_}, gpu_memory{gpu_memory_} {
39 runtime.Init();
40 // Configure null sampler 39 // Configure null sampler
41 TSCEntry sampler_descriptor{}; 40 TSCEntry sampler_descriptor{};
42 sampler_descriptor.min_filter.Assign(Tegra::Texture::TextureFilter::Linear); 41 sampler_descriptor.min_filter.Assign(Tegra::Texture::TextureFilter::Linear);
@@ -46,7 +45,8 @@ TextureCache<P>::TextureCache(Runtime& runtime_, VideoCore::RasterizerInterface&
46 45
47 // Make sure the first index is reserved for the null resources 46 // Make sure the first index is reserved for the null resources
48 // This way the null resource becomes a compile time constant 47 // This way the null resource becomes a compile time constant
49 void(slot_image_views.insert(runtime, NullImageParams{})); 48 void(slot_images.insert(NullImageParams{}));
49 void(slot_image_views.insert(runtime, NullImageViewParams{}));
50 void(slot_samplers.insert(runtime, sampler_descriptor)); 50 void(slot_samplers.insert(runtime, sampler_descriptor));
51 51
52 if constexpr (HAS_DEVICE_MEMORY_INFO) { 52 if constexpr (HAS_DEVICE_MEMORY_INFO) {
@@ -57,7 +57,7 @@ TextureCache<P>::TextureCache(Runtime& runtime_, VideoCore::RasterizerInterface&
57 critical_memory = std::max(possible_critical_memory, DEFAULT_CRITICAL_MEMORY); 57 critical_memory = std::max(possible_critical_memory, DEFAULT_CRITICAL_MEMORY);
58 minimum_memory = 0; 58 minimum_memory = 0;
59 } else { 59 } else {
60 // on OGL we can be more conservatives as the driver takes care. 60 // On OpenGL we can be more conservatives as the driver takes care.
61 expected_memory = DEFAULT_EXPECTED_MEMORY + 512_MiB; 61 expected_memory = DEFAULT_EXPECTED_MEMORY + 512_MiB;
62 critical_memory = DEFAULT_CRITICAL_MEMORY + 1_GiB; 62 critical_memory = DEFAULT_CRITICAL_MEMORY + 1_GiB;
63 minimum_memory = expected_memory; 63 minimum_memory = expected_memory;
@@ -135,15 +135,14 @@ void TextureCache<P>::MarkModification(ImageId id) noexcept {
135} 135}
136 136
137template <class P> 137template <class P>
138void TextureCache<P>::FillGraphicsImageViews(std::span<const u32> indices, 138template <bool has_blacklists>
139 std::span<ImageViewId> image_view_ids) { 139void TextureCache<P>::FillGraphicsImageViews(std::span<ImageViewInOut> views) {
140 FillImageViews(graphics_image_table, graphics_image_view_ids, indices, image_view_ids); 140 FillImageViews<has_blacklists>(graphics_image_table, graphics_image_view_ids, views);
141} 141}
142 142
143template <class P> 143template <class P>
144void TextureCache<P>::FillComputeImageViews(std::span<const u32> indices, 144void TextureCache<P>::FillComputeImageViews(std::span<ImageViewInOut> views) {
145 std::span<ImageViewId> image_view_ids) { 145 FillImageViews<false>(compute_image_table, compute_image_view_ids, views);
146 FillImageViews(compute_image_table, compute_image_view_ids, indices, image_view_ids);
147} 146}
148 147
149template <class P> 148template <class P>
@@ -346,17 +345,26 @@ typename P::Framebuffer* TextureCache<P>::GetFramebuffer() {
346} 345}
347 346
348template <class P> 347template <class P>
348template <bool has_blacklists>
349void TextureCache<P>::FillImageViews(DescriptorTable<TICEntry>& table, 349void TextureCache<P>::FillImageViews(DescriptorTable<TICEntry>& table,
350 std::span<ImageViewId> cached_image_view_ids, 350 std::span<ImageViewId> cached_image_view_ids,
351 std::span<const u32> indices, 351 std::span<ImageViewInOut> views) {
352 std::span<ImageViewId> image_view_ids) { 352 bool has_blacklisted;
353 ASSERT(indices.size() <= image_view_ids.size());
354 do { 353 do {
355 has_deleted_images = false; 354 has_deleted_images = false;
356 std::ranges::transform(indices, image_view_ids.begin(), [&](u32 index) { 355 if constexpr (has_blacklists) {
357 return VisitImageView(table, cached_image_view_ids, index); 356 has_blacklisted = false;
358 }); 357 }
359 } while (has_deleted_images); 358 for (ImageViewInOut& view : views) {
359 view.id = VisitImageView(table, cached_image_view_ids, view.index);
360 if constexpr (has_blacklists) {
361 if (view.blacklist && view.id != NULL_IMAGE_VIEW_ID) {
362 const ImageViewBase& image_view{slot_image_views[view.id]};
363 has_blacklisted |= BlackListImage(image_view.image_id);
364 }
365 }
366 }
367 } while (has_deleted_images || (has_blacklists && has_blacklisted));
360} 368}
361 369
362template <class P> 370template <class P>
@@ -622,7 +630,7 @@ void TextureCache<P>::PopAsyncFlushes() {
622} 630}
623 631
624template <class P> 632template <class P>
625bool TextureCache<P>::IsRescaling() { 633bool TextureCache<P>::IsRescaling() const noexcept {
626 return is_rescaling; 634 return is_rescaling;
627} 635}
628 636
@@ -775,12 +783,11 @@ bool TextureCache<P>::BlackListImage(ImageId image_id) {
775} 783}
776 784
777template <class P> 785template <class P>
778bool TextureCache<P>::ImageCanRescale(Image& image) { 786bool TextureCache<P>::ImageCanRescale(ImageBase& image) {
779 if (True(image.flags & ImageFlagBits::Blacklisted)) { 787 if (True(image.flags & ImageFlagBits::Blacklisted)) {
780 return false; 788 return false;
781 } 789 }
782 if (True(image.flags & ImageFlagBits::Rescaled) || 790 if (True(image.flags & (ImageFlagBits::Rescaled | ImageFlagBits::RescaleChecked))) {
783 True(image.flags & ImageFlagBits::RescaleChecked)) {
784 return true; 791 return true;
785 } 792 }
786 if (!image.info.rescaleable) { 793 if (!image.info.rescaleable) {
diff --git a/src/video_core/texture_cache/texture_cache_base.h b/src/video_core/texture_cache/texture_cache_base.h
index 35a29cd9b..b6cc09682 100644
--- a/src/video_core/texture_cache/texture_cache_base.h
+++ b/src/video_core/texture_cache/texture_cache_base.h
@@ -39,6 +39,16 @@ using VideoCore::Surface::PixelFormatFromDepthFormat;
39using VideoCore::Surface::PixelFormatFromRenderTargetFormat; 39using VideoCore::Surface::PixelFormatFromRenderTargetFormat;
40using namespace Common::Literals; 40using namespace Common::Literals;
41 41
42struct ImageViewInOut {
43 u32 index;
44 bool blacklist;
45 union {
46 struct Empty {
47 } empty{};
48 ImageViewId id;
49 };
50};
51
42template <class P> 52template <class P>
43class TextureCache { 53class TextureCache {
44 /// Address shift for caching images into a hash table 54 /// Address shift for caching images into a hash table
@@ -53,11 +63,6 @@ class TextureCache {
53 /// True when the API can provide info about the memory of the device. 63 /// True when the API can provide info about the memory of the device.
54 static constexpr bool HAS_DEVICE_MEMORY_INFO = P::HAS_DEVICE_MEMORY_INFO; 64 static constexpr bool HAS_DEVICE_MEMORY_INFO = P::HAS_DEVICE_MEMORY_INFO;
55 65
56 /// Image view ID for null descriptors
57 static constexpr ImageViewId NULL_IMAGE_VIEW_ID{0};
58 /// Sampler ID for bugged sampler ids
59 static constexpr SamplerId NULL_SAMPLER_ID{0};
60
61 static constexpr u64 DEFAULT_EXPECTED_MEMORY = 1_GiB; 66 static constexpr u64 DEFAULT_EXPECTED_MEMORY = 1_GiB;
62 static constexpr u64 DEFAULT_CRITICAL_MEMORY = 2_GiB; 67 static constexpr u64 DEFAULT_CRITICAL_MEMORY = 2_GiB;
63 68
@@ -105,11 +110,11 @@ public:
105 void MarkModification(ImageId id) noexcept; 110 void MarkModification(ImageId id) noexcept;
106 111
107 /// Fill image_view_ids with the graphics images in indices 112 /// Fill image_view_ids with the graphics images in indices
108 void FillGraphicsImageViews(std::span<const u32> indices, 113 template <bool has_blacklists>
109 std::span<ImageViewId> image_view_ids); 114 void FillGraphicsImageViews(std::span<ImageViewInOut> views);
110 115
111 /// Fill image_view_ids with the compute images in indices 116 /// Fill image_view_ids with the compute images in indices
112 void FillComputeImageViews(std::span<const u32> indices, std::span<ImageViewId> image_view_ids); 117 void FillComputeImageViews(std::span<ImageViewInOut> views);
113 118
114 /// Get the sampler from the graphics descriptor table in the specified index 119 /// Get the sampler from the graphics descriptor table in the specified index
115 Sampler* GetGraphicsSampler(u32 index); 120 Sampler* GetGraphicsSampler(u32 index);
@@ -174,7 +179,7 @@ public:
174 /// Return true when a CPU region is modified from the GPU 179 /// Return true when a CPU region is modified from the GPU
175 [[nodiscard]] bool IsRegionGpuModified(VAddr addr, size_t size); 180 [[nodiscard]] bool IsRegionGpuModified(VAddr addr, size_t size);
176 181
177 [[nodiscard]] bool IsRescaling(); 182 [[nodiscard]] bool IsRescaling() const noexcept;
178 183
179 [[nodiscard]] bool BlackListImage(ImageId image_id); 184 [[nodiscard]] bool BlackListImage(ImageId image_id);
180 185
@@ -216,9 +221,10 @@ private:
216 void RunGarbageCollector(); 221 void RunGarbageCollector();
217 222
218 /// Fills image_view_ids in the image views in indices 223 /// Fills image_view_ids in the image views in indices
224 template <bool has_blacklists>
219 void FillImageViews(DescriptorTable<TICEntry>& table, 225 void FillImageViews(DescriptorTable<TICEntry>& table,
220 std::span<ImageViewId> cached_image_view_ids, std::span<const u32> indices, 226 std::span<ImageViewId> cached_image_view_ids,
221 std::span<ImageViewId> image_view_ids); 227 std::span<ImageViewInOut> views);
222 228
223 /// Find or create an image view in the guest descriptor table 229 /// Find or create an image view in the guest descriptor table
224 ImageViewId VisitImageView(DescriptorTable<TICEntry>& table, 230 ImageViewId VisitImageView(DescriptorTable<TICEntry>& table,
@@ -336,7 +342,7 @@ private:
336 /// Returns true if the current clear parameters clear the whole image of a given image view 342 /// Returns true if the current clear parameters clear the whole image of a given image view
337 [[nodiscard]] bool IsFullClear(ImageViewId id); 343 [[nodiscard]] bool IsFullClear(ImageViewId id);
338 344
339 bool ImageCanRescale(Image& image); 345 bool ImageCanRescale(ImageBase& image);
340 void InvalidateScale(Image& image); 346 void InvalidateScale(Image& image);
341 bool ScaleUp(Image& image); 347 bool ScaleUp(Image& image);
342 bool ScaleDown(Image& image); 348 bool ScaleDown(Image& image);
diff --git a/src/video_core/texture_cache/types.h b/src/video_core/texture_cache/types.h
index 47a11cb2f..5c274abdf 100644
--- a/src/video_core/texture_cache/types.h
+++ b/src/video_core/texture_cache/types.h
@@ -22,6 +22,13 @@ using ImageAllocId = SlotId;
22using SamplerId = SlotId; 22using SamplerId = SlotId;
23using FramebufferId = SlotId; 23using FramebufferId = SlotId;
24 24
25/// Fake image ID for null image views
26constexpr ImageId NULL_IMAGE_ID{0};
27/// Image view ID for null descriptors
28constexpr ImageViewId NULL_IMAGE_VIEW_ID{0};
29/// Sampler ID for bugged sampler ids
30constexpr SamplerId NULL_SAMPLER_ID{0};
31
25enum class ImageType : u32 { 32enum class ImageType : u32 {
26 e1D, 33 e1D,
27 e2D, 34 e2D,