summaryrefslogtreecommitdiff
path: root/src/video_core/texture_cache
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2022-12-28 09:32:31 -0500
committerGravatar Fernando Sahmkow2023-01-03 22:52:15 -0500
commit03ccd8bf432e8b2c945b68f00e8fa88f67388098 (patch)
tree446afdee8cfc6f5ec126bbdae7dbbe23b05d8550 /src/video_core/texture_cache
parentVulkan: Update blacklisting to latest driver versions. (diff)
downloadyuzu-03ccd8bf432e8b2c945b68f00e8fa88f67388098.tar.gz
yuzu-03ccd8bf432e8b2c945b68f00e8fa88f67388098.tar.xz
yuzu-03ccd8bf432e8b2c945b68f00e8fa88f67388098.zip
Texture Cache: Implement async texture downloads.
Diffstat (limited to 'src/video_core/texture_cache')
-rw-r--r--src/video_core/texture_cache/texture_cache.h104
-rw-r--r--src/video_core/texture_cache/texture_cache_base.h6
2 files changed, 78 insertions, 32 deletions
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h
index 7fe451b5a..87152c8e9 100644
--- a/src/video_core/texture_cache/texture_cache.h
+++ b/src/video_core/texture_cache/texture_cache.h
@@ -646,7 +646,28 @@ bool TextureCache<P>::ShouldWaitAsyncFlushes() const noexcept {
646template <class P> 646template <class P>
647void TextureCache<P>::CommitAsyncFlushes() { 647void TextureCache<P>::CommitAsyncFlushes() {
648 // This is intentionally passing the value by copy 648 // This is intentionally passing the value by copy
649 committed_downloads.push(uncommitted_downloads); 649 if constexpr (IMPLEMENTS_ASYNC_DOWNLOADS) {
650 const std::span<const ImageId> download_ids = uncommitted_downloads;
651 if (download_ids.empty()) {
652 committed_downloads.emplace_back(std::move(uncommitted_downloads));
653 uncommitted_downloads.clear();
654 async_buffers.emplace_back(std::optional<AsyncBuffer>{});
655 return;
656 }
657 size_t total_size_bytes = 0;
658 for (const ImageId image_id : download_ids) {
659 total_size_bytes += slot_images[image_id].unswizzled_size_bytes;
660 }
661 auto download_map = runtime.DownloadStagingBuffer(total_size_bytes, true);
662 for (const ImageId image_id : download_ids) {
663 Image& image = slot_images[image_id];
664 const auto copies = FullDownloadCopies(image.info);
665 image.DownloadMemory(download_map, copies);
666 download_map.offset += Common::AlignUp(image.unswizzled_size_bytes, 64);
667 }
668 async_buffers.emplace_back(download_map);
669 }
670 committed_downloads.emplace_back(std::move(uncommitted_downloads));
650 uncommitted_downloads.clear(); 671 uncommitted_downloads.clear();
651} 672}
652 673
@@ -655,37 +676,58 @@ void TextureCache<P>::PopAsyncFlushes() {
655 if (committed_downloads.empty()) { 676 if (committed_downloads.empty()) {
656 return; 677 return;
657 } 678 }
658 const std::span<const ImageId> download_ids = committed_downloads.front(); 679 if constexpr (IMPLEMENTS_ASYNC_DOWNLOADS) {
659 if (download_ids.empty()) { 680 const std::span<const ImageId> download_ids = committed_downloads.front();
660 committed_downloads.pop(); 681 if (download_ids.empty()) {
661 return; 682 committed_downloads.pop_front();
662 } 683 async_buffers.pop_front();
663 size_t total_size_bytes = 0; 684 return;
664 for (const ImageId image_id : download_ids) { 685 }
665 total_size_bytes += slot_images[image_id].unswizzled_size_bytes; 686 auto download_map = *async_buffers.front();
666 } 687 std::span<u8> download_span = download_map.mapped_span;
667 auto download_map = runtime.DownloadStagingBuffer(total_size_bytes); 688 for (size_t i = download_ids.size(); i > 0; i--) {
668 const size_t original_offset = download_map.offset; 689 const ImageBase& image = slot_images[download_ids[i - 1]];
669 for (const ImageId image_id : download_ids) { 690 const auto copies = FullDownloadCopies(image.info);
670 Image& image = slot_images[image_id]; 691 download_map.offset -= Common::AlignUp(image.unswizzled_size_bytes, 64);
671 const auto copies = FullDownloadCopies(image.info); 692 std::span<u8> download_span_alt = download_span.subspan(download_map.offset);
672 image.DownloadMemory(download_map, copies); 693 SwizzleImage(*gpu_memory, image.gpu_addr, image.info, copies, download_span_alt,
673 download_map.offset += image.unswizzled_size_bytes; 694 swizzle_data_buffer);
674 } 695 }
675 // Wait for downloads to finish 696 runtime.FreeDeferredStagingBuffer(download_map);
676 runtime.Finish(); 697 committed_downloads.pop_front();
677 698 async_buffers.pop_front();
678 download_map.offset = original_offset; 699 } else {
679 std::span<u8> download_span = download_map.mapped_span; 700 const std::span<const ImageId> download_ids = committed_downloads.front();
680 for (const ImageId image_id : download_ids) { 701 if (download_ids.empty()) {
681 const ImageBase& image = slot_images[image_id]; 702 committed_downloads.pop_front();
682 const auto copies = FullDownloadCopies(image.info); 703 return;
683 SwizzleImage(*gpu_memory, image.gpu_addr, image.info, copies, download_span, 704 }
684 swizzle_data_buffer); 705 size_t total_size_bytes = 0;
685 download_map.offset += image.unswizzled_size_bytes; 706 for (const ImageId image_id : download_ids) {
686 download_span = download_span.subspan(image.unswizzled_size_bytes); 707 total_size_bytes += slot_images[image_id].unswizzled_size_bytes;
708 }
709 auto download_map = runtime.DownloadStagingBuffer(total_size_bytes);
710 const size_t original_offset = download_map.offset;
711 for (const ImageId image_id : download_ids) {
712 Image& image = slot_images[image_id];
713 const auto copies = FullDownloadCopies(image.info);
714 image.DownloadMemory(download_map, copies);
715 download_map.offset += image.unswizzled_size_bytes;
716 }
717 // Wait for downloads to finish
718 runtime.Finish();
719 download_map.offset = original_offset;
720 std::span<u8> download_span = download_map.mapped_span;
721 for (const ImageId image_id : download_ids) {
722 const ImageBase& image = slot_images[image_id];
723 const auto copies = FullDownloadCopies(image.info);
724 SwizzleImage(*gpu_memory, image.gpu_addr, image.info, copies, download_span,
725 swizzle_data_buffer);
726 download_map.offset += image.unswizzled_size_bytes;
727 download_span = download_span.subspan(image.unswizzled_size_bytes);
728 }
729 committed_downloads.pop_front();
687 } 730 }
688 committed_downloads.pop();
689} 731}
690 732
691template <class P> 733template <class P>
diff --git a/src/video_core/texture_cache/texture_cache_base.h b/src/video_core/texture_cache/texture_cache_base.h
index 6b2898705..4eea1f609 100644
--- a/src/video_core/texture_cache/texture_cache_base.h
+++ b/src/video_core/texture_cache/texture_cache_base.h
@@ -92,6 +92,8 @@ class TextureCache : public VideoCommon::ChannelSetupCaches<TextureCacheChannelI
92 static constexpr bool HAS_EMULATED_COPIES = P::HAS_EMULATED_COPIES; 92 static constexpr bool HAS_EMULATED_COPIES = P::HAS_EMULATED_COPIES;
93 /// True when the API can provide info about the memory of the device. 93 /// True when the API can provide info about the memory of the device.
94 static constexpr bool HAS_DEVICE_MEMORY_INFO = P::HAS_DEVICE_MEMORY_INFO; 94 static constexpr bool HAS_DEVICE_MEMORY_INFO = P::HAS_DEVICE_MEMORY_INFO;
95 /// True when the API can do asynchronous texture downloads.
96 static constexpr bool IMPLEMENTS_ASYNC_DOWNLOADS = P::IMPLEMENTS_ASYNC_DOWNLOADS;
95 97
96 static constexpr size_t UNSET_CHANNEL{std::numeric_limits<size_t>::max()}; 98 static constexpr size_t UNSET_CHANNEL{std::numeric_limits<size_t>::max()};
97 99
@@ -106,6 +108,7 @@ class TextureCache : public VideoCommon::ChannelSetupCaches<TextureCacheChannelI
106 using ImageView = typename P::ImageView; 108 using ImageView = typename P::ImageView;
107 using Sampler = typename P::Sampler; 109 using Sampler = typename P::Sampler;
108 using Framebuffer = typename P::Framebuffer; 110 using Framebuffer = typename P::Framebuffer;
111 using AsyncBuffer = typename P::AsyncBuffer;
109 112
110 struct BlitImages { 113 struct BlitImages {
111 ImageId dst_id; 114 ImageId dst_id;
@@ -403,7 +406,8 @@ private:
403 406
404 // TODO: This data structure is not optimal and it should be reworked 407 // TODO: This data structure is not optimal and it should be reworked
405 std::vector<ImageId> uncommitted_downloads; 408 std::vector<ImageId> uncommitted_downloads;
406 std::queue<std::vector<ImageId>> committed_downloads; 409 std::deque<std::vector<ImageId>> committed_downloads;
410 std::deque<std::optional<AsyncBuffer>> async_buffers;
407 411
408 struct LRUItemParams { 412 struct LRUItemParams {
409 using ObjectType = ImageId; 413 using ObjectType = ImageId;