diff options
Diffstat (limited to 'src/video_core/texture_cache')
| -rw-r--r-- | src/video_core/texture_cache/image_base.cpp | 17 | ||||
| -rw-r--r-- | src/video_core/texture_cache/image_base.h | 2 | ||||
| -rw-r--r-- | src/video_core/texture_cache/slot_vector.h | 70 | ||||
| -rw-r--r-- | src/video_core/texture_cache/texture_cache.h | 44 |
4 files changed, 121 insertions, 12 deletions
diff --git a/src/video_core/texture_cache/image_base.cpp b/src/video_core/texture_cache/image_base.cpp index 9914926b3..bd0e7e64e 100644 --- a/src/video_core/texture_cache/image_base.cpp +++ b/src/video_core/texture_cache/image_base.cpp | |||
| @@ -113,6 +113,23 @@ void ImageBase::InsertView(const ImageViewInfo& view_info, ImageViewId image_vie | |||
| 113 | image_view_ids.push_back(image_view_id); | 113 | image_view_ids.push_back(image_view_id); |
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | bool ImageBase::IsSafeDownload() const noexcept { | ||
| 117 | // Skip images that were not modified from the GPU | ||
| 118 | if (False(flags & ImageFlagBits::GpuModified)) { | ||
| 119 | return false; | ||
| 120 | } | ||
| 121 | // Skip images that .are. modified from the CPU | ||
| 122 | // We don't want to write sensitive data from the guest | ||
| 123 | if (True(flags & ImageFlagBits::CpuModified)) { | ||
| 124 | return false; | ||
| 125 | } | ||
| 126 | if (info.num_samples > 1) { | ||
| 127 | LOG_WARNING(HW_GPU, "MSAA image downloads are not implemented"); | ||
| 128 | return false; | ||
| 129 | } | ||
| 130 | return true; | ||
| 131 | } | ||
| 132 | |||
| 116 | void AddImageAlias(ImageBase& lhs, ImageBase& rhs, ImageId lhs_id, ImageId rhs_id) { | 133 | void AddImageAlias(ImageBase& lhs, ImageBase& rhs, ImageId lhs_id, ImageId rhs_id) { |
| 117 | static constexpr auto OPTIONS = RelaxedOptions::Size | RelaxedOptions::Format; | 134 | static constexpr auto OPTIONS = RelaxedOptions::Size | RelaxedOptions::Format; |
| 118 | ASSERT(lhs.info.type == rhs.info.type); | 135 | ASSERT(lhs.info.type == rhs.info.type); |
diff --git a/src/video_core/texture_cache/image_base.h b/src/video_core/texture_cache/image_base.h index b7f3b7e43..0f69d8a32 100644 --- a/src/video_core/texture_cache/image_base.h +++ b/src/video_core/texture_cache/image_base.h | |||
| @@ -44,6 +44,8 @@ struct ImageBase { | |||
| 44 | 44 | ||
| 45 | void InsertView(const ImageViewInfo& view_info, ImageViewId image_view_id); | 45 | void InsertView(const ImageViewInfo& view_info, ImageViewId image_view_id); |
| 46 | 46 | ||
| 47 | [[nodiscard]] bool IsSafeDownload() const noexcept; | ||
| 48 | |||
| 47 | [[nodiscard]] bool Overlaps(VAddr overlap_cpu_addr, size_t overlap_size) const noexcept { | 49 | [[nodiscard]] bool Overlaps(VAddr overlap_cpu_addr, size_t overlap_size) const noexcept { |
| 48 | const VAddr overlap_end = overlap_cpu_addr + overlap_size; | 50 | const VAddr overlap_end = overlap_cpu_addr + overlap_size; |
| 49 | return cpu_addr < overlap_end && overlap_cpu_addr < cpu_addr_end; | 51 | return cpu_addr < overlap_end && overlap_cpu_addr < cpu_addr_end; |
diff --git a/src/video_core/texture_cache/slot_vector.h b/src/video_core/texture_cache/slot_vector.h index eae3be6ea..1259e8263 100644 --- a/src/video_core/texture_cache/slot_vector.h +++ b/src/video_core/texture_cache/slot_vector.h | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <bit> | ||
| 8 | #include <concepts> | 9 | #include <concepts> |
| 9 | #include <numeric> | 10 | #include <numeric> |
| 10 | #include <type_traits> | 11 | #include <type_traits> |
| @@ -32,6 +33,60 @@ template <class T> | |||
| 32 | requires std::is_nothrow_move_assignable_v<T>&& | 33 | requires std::is_nothrow_move_assignable_v<T>&& |
| 33 | std::is_nothrow_move_constructible_v<T> class SlotVector { | 34 | std::is_nothrow_move_constructible_v<T> class SlotVector { |
| 34 | public: | 35 | public: |
| 36 | class Iterator { | ||
| 37 | friend SlotVector<T>; | ||
| 38 | |||
| 39 | public: | ||
| 40 | constexpr Iterator() = default; | ||
| 41 | |||
| 42 | Iterator& operator++() noexcept { | ||
| 43 | const u64* const bitset = slot_vector->stored_bitset.data(); | ||
| 44 | const u32 size = static_cast<u32>(slot_vector->stored_bitset.size()) * 64; | ||
| 45 | if (id.index < size) { | ||
| 46 | do { | ||
| 47 | ++id.index; | ||
| 48 | } while (id.index < size && !IsValid(bitset)); | ||
| 49 | if (id.index == size) { | ||
| 50 | id.index = SlotId::INVALID_INDEX; | ||
| 51 | } | ||
| 52 | } | ||
| 53 | return *this; | ||
| 54 | } | ||
| 55 | |||
| 56 | Iterator operator++(int) noexcept { | ||
| 57 | const Iterator copy{*this}; | ||
| 58 | ++*this; | ||
| 59 | return copy; | ||
| 60 | } | ||
| 61 | |||
| 62 | bool operator==(const Iterator& other) const noexcept { | ||
| 63 | return id.index == other.id.index; | ||
| 64 | } | ||
| 65 | |||
| 66 | bool operator!=(const Iterator& other) const noexcept { | ||
| 67 | return id.index != other.id.index; | ||
| 68 | } | ||
| 69 | |||
| 70 | std::pair<SlotId, T*> operator*() const noexcept { | ||
| 71 | return {id, std::addressof((*slot_vector)[id])}; | ||
| 72 | } | ||
| 73 | |||
| 74 | T* operator->() const noexcept { | ||
| 75 | return std::addressof((*slot_vector)[id]); | ||
| 76 | } | ||
| 77 | |||
| 78 | private: | ||
| 79 | Iterator(SlotVector<T>* slot_vector_, SlotId id_) noexcept | ||
| 80 | : slot_vector{slot_vector_}, id{id_} {} | ||
| 81 | |||
| 82 | bool IsValid(const u64* bitset) noexcept { | ||
| 83 | return ((bitset[id.index / 64] >> (id.index % 64)) & 1) != 0; | ||
| 84 | } | ||
| 85 | |||
| 86 | SlotVector<T>* slot_vector; | ||
| 87 | SlotId id; | ||
| 88 | }; | ||
| 89 | |||
| 35 | ~SlotVector() noexcept { | 90 | ~SlotVector() noexcept { |
| 36 | size_t index = 0; | 91 | size_t index = 0; |
| 37 | for (u64 bits : stored_bitset) { | 92 | for (u64 bits : stored_bitset) { |
| @@ -70,6 +125,20 @@ public: | |||
| 70 | ResetStorageBit(id.index); | 125 | ResetStorageBit(id.index); |
| 71 | } | 126 | } |
| 72 | 127 | ||
| 128 | [[nodiscard]] Iterator begin() noexcept { | ||
| 129 | const auto it = std::ranges::find_if(stored_bitset, [](u64 value) { return value != 0; }); | ||
| 130 | if (it == stored_bitset.end()) { | ||
| 131 | return end(); | ||
| 132 | } | ||
| 133 | const u32 word_index = static_cast<u32>(std::distance(it, stored_bitset.begin())); | ||
| 134 | const SlotId first_id{word_index * 64 + static_cast<u32>(std::countr_zero(*it))}; | ||
| 135 | return Iterator(this, first_id); | ||
| 136 | } | ||
| 137 | |||
| 138 | [[nodiscard]] Iterator end() noexcept { | ||
| 139 | return Iterator(this, SlotId{SlotId::INVALID_INDEX}); | ||
| 140 | } | ||
| 141 | |||
| 73 | private: | 142 | private: |
| 74 | struct NonTrivialDummy { | 143 | struct NonTrivialDummy { |
| 75 | NonTrivialDummy() noexcept {} | 144 | NonTrivialDummy() noexcept {} |
| @@ -140,7 +209,6 @@ private: | |||
| 140 | 209 | ||
| 141 | Entry* values = nullptr; | 210 | Entry* values = nullptr; |
| 142 | size_t values_capacity = 0; | 211 | size_t values_capacity = 0; |
| 143 | size_t values_size = 0; | ||
| 144 | 212 | ||
| 145 | std::vector<u64> stored_bitset; | 213 | std::vector<u64> stored_bitset; |
| 146 | std::vector<u32> free_list; | 214 | std::vector<u32> free_list; |
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index 59b7c678b..45ef155b5 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h | |||
| @@ -353,6 +353,7 @@ private: | |||
| 353 | 353 | ||
| 354 | u64 modification_tick = 0; | 354 | u64 modification_tick = 0; |
| 355 | u64 frame_tick = 0; | 355 | u64 frame_tick = 0; |
| 356 | typename SlotVector<Image>::Iterator deletion_iterator; | ||
| 356 | }; | 357 | }; |
| 357 | 358 | ||
| 358 | template <class P> | 359 | template <class P> |
| @@ -373,10 +374,41 @@ TextureCache<P>::TextureCache(Runtime& runtime_, VideoCore::RasterizerInterface& | |||
| 373 | // This way the null resource becomes a compile time constant | 374 | // This way the null resource becomes a compile time constant |
| 374 | void(slot_image_views.insert(runtime, NullImageParams{})); | 375 | void(slot_image_views.insert(runtime, NullImageParams{})); |
| 375 | void(slot_samplers.insert(runtime, sampler_descriptor)); | 376 | void(slot_samplers.insert(runtime, sampler_descriptor)); |
| 377 | |||
| 378 | deletion_iterator = slot_images.begin(); | ||
| 376 | } | 379 | } |
| 377 | 380 | ||
| 378 | template <class P> | 381 | template <class P> |
| 379 | void TextureCache<P>::TickFrame() { | 382 | void TextureCache<P>::TickFrame() { |
| 383 | static constexpr u64 ticks_to_destroy = 120; | ||
| 384 | int num_iterations = 32; | ||
| 385 | for (; num_iterations > 0; --num_iterations) { | ||
| 386 | if (deletion_iterator == slot_images.end()) { | ||
| 387 | deletion_iterator = slot_images.begin(); | ||
| 388 | if (deletion_iterator == slot_images.end()) { | ||
| 389 | break; | ||
| 390 | } | ||
| 391 | } | ||
| 392 | const auto [image_id, image] = *deletion_iterator; | ||
| 393 | if (image->frame_tick + ticks_to_destroy < frame_tick) { | ||
| 394 | if (image->IsSafeDownload() && | ||
| 395 | std::ranges::none_of(image->aliased_images, [&](const AliasedImage& alias) { | ||
| 396 | return slot_images[alias.id].modification_tick > image->modification_tick; | ||
| 397 | })) { | ||
| 398 | auto map = runtime.DownloadStagingBuffer(image->unswizzled_size_bytes); | ||
| 399 | const auto copies = FullDownloadCopies(image->info); | ||
| 400 | image->DownloadMemory(map, copies); | ||
| 401 | runtime.Finish(); | ||
| 402 | SwizzleImage(gpu_memory, image->gpu_addr, image->info, copies, map.mapped_span); | ||
| 403 | } | ||
| 404 | if (True(image->flags & ImageFlagBits::Tracked)) { | ||
| 405 | UntrackImage(*image); | ||
| 406 | } | ||
| 407 | UnregisterImage(image_id); | ||
| 408 | DeleteImage(image_id); | ||
| 409 | } | ||
| 410 | ++deletion_iterator; | ||
| 411 | } | ||
| 380 | // Tick sentenced resources in this order to ensure they are destroyed in the right order | 412 | // Tick sentenced resources in this order to ensure they are destroyed in the right order |
| 381 | sentenced_images.Tick(); | 413 | sentenced_images.Tick(); |
| 382 | sentenced_framebuffers.Tick(); | 414 | sentenced_framebuffers.Tick(); |
| @@ -568,17 +600,7 @@ template <class P> | |||
| 568 | void TextureCache<P>::DownloadMemory(VAddr cpu_addr, size_t size) { | 600 | void TextureCache<P>::DownloadMemory(VAddr cpu_addr, size_t size) { |
| 569 | std::vector<ImageId> images; | 601 | std::vector<ImageId> images; |
| 570 | ForEachImageInRegion(cpu_addr, size, [this, &images](ImageId image_id, ImageBase& image) { | 602 | ForEachImageInRegion(cpu_addr, size, [this, &images](ImageId image_id, ImageBase& image) { |
| 571 | // Skip images that were not modified from the GPU | 603 | if (!image.IsSafeDownload()) { |
| 572 | if (False(image.flags & ImageFlagBits::GpuModified)) { | ||
| 573 | return; | ||
| 574 | } | ||
| 575 | // Skip images that .are. modified from the CPU | ||
| 576 | // We don't want to write sensitive data from the guest | ||
| 577 | if (True(image.flags & ImageFlagBits::CpuModified)) { | ||
| 578 | return; | ||
| 579 | } | ||
| 580 | if (image.info.num_samples > 1) { | ||
| 581 | LOG_WARNING(HW_GPU, "MSAA image downloads are not implemented"); | ||
| 582 | return; | 604 | return; |
| 583 | } | 605 | } |
| 584 | image.flags &= ~ImageFlagBits::GpuModified; | 606 | image.flags &= ~ImageFlagBits::GpuModified; |