diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/scratch_buffer.h | 1 | ||||
| -rw-r--r-- | src/video_core/texture_cache/image_base.h | 3 | ||||
| -rw-r--r-- | src/video_core/texture_cache/texture_cache.h | 69 | ||||
| -rw-r--r-- | src/video_core/texture_cache/texture_cache_base.h | 16 |
4 files changed, 89 insertions, 0 deletions
diff --git a/src/common/scratch_buffer.h b/src/common/scratch_buffer.h index 1245a5086..26d4e76dc 100644 --- a/src/common/scratch_buffer.h +++ b/src/common/scratch_buffer.h | |||
| @@ -23,6 +23,7 @@ public: | |||
| 23 | buffer{Common::make_unique_for_overwrite<T[]>(initial_capacity)} {} | 23 | buffer{Common::make_unique_for_overwrite<T[]>(initial_capacity)} {} |
| 24 | 24 | ||
| 25 | ~ScratchBuffer() = default; | 25 | ~ScratchBuffer() = default; |
| 26 | ScratchBuffer(ScratchBuffer&&) = default; | ||
| 26 | 27 | ||
| 27 | /// This will only grow the buffer's capacity if size is greater than the current capacity. | 28 | /// This will only grow the buffer's capacity if size is greater than the current capacity. |
| 28 | /// The previously held data will remain intact. | 29 | /// The previously held data will remain intact. |
diff --git a/src/video_core/texture_cache/image_base.h b/src/video_core/texture_cache/image_base.h index 620565684..e8fa592d2 100644 --- a/src/video_core/texture_cache/image_base.h +++ b/src/video_core/texture_cache/image_base.h | |||
| @@ -38,6 +38,9 @@ enum class ImageFlagBits : u32 { | |||
| 38 | Rescaled = 1 << 13, | 38 | Rescaled = 1 << 13, |
| 39 | CheckingRescalable = 1 << 14, | 39 | CheckingRescalable = 1 << 14, |
| 40 | IsRescalable = 1 << 15, | 40 | IsRescalable = 1 << 15, |
| 41 | |||
| 42 | AsynchronousDecode = 1 << 16, | ||
| 43 | IsDecoding = 1 << 17, ///< Is currently being decoded asynchornously. | ||
| 41 | }; | 44 | }; |
| 42 | DECLARE_ENUM_FLAG_OPERATORS(ImageFlagBits) | 45 | DECLARE_ENUM_FLAG_OPERATORS(ImageFlagBits) |
| 43 | 46 | ||
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index 3e2cbb0b0..4159bc796 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h | |||
| @@ -85,6 +85,11 @@ void TextureCache<P>::RunGarbageCollector() { | |||
| 85 | } | 85 | } |
| 86 | --num_iterations; | 86 | --num_iterations; |
| 87 | auto& image = slot_images[image_id]; | 87 | auto& image = slot_images[image_id]; |
| 88 | if (True(image.flags & ImageFlagBits::IsDecoding)) { | ||
| 89 | // This image is still being decoded, deleting it will invalidate the slot | ||
| 90 | // used by the async decoder thread. | ||
| 91 | return false; | ||
| 92 | } | ||
| 88 | const bool must_download = | 93 | const bool must_download = |
| 89 | image.IsSafeDownload() && False(image.flags & ImageFlagBits::BadOverlap); | 94 | image.IsSafeDownload() && False(image.flags & ImageFlagBits::BadOverlap); |
| 90 | if (!high_priority_mode && | 95 | if (!high_priority_mode && |
| @@ -133,6 +138,8 @@ void TextureCache<P>::TickFrame() { | |||
| 133 | sentenced_images.Tick(); | 138 | sentenced_images.Tick(); |
| 134 | sentenced_framebuffers.Tick(); | 139 | sentenced_framebuffers.Tick(); |
| 135 | sentenced_image_view.Tick(); | 140 | sentenced_image_view.Tick(); |
| 141 | TickAsyncDecode(); | ||
| 142 | |||
| 136 | runtime.TickFrame(); | 143 | runtime.TickFrame(); |
| 137 | critical_gc = 0; | 144 | critical_gc = 0; |
| 138 | ++frame_tick; | 145 | ++frame_tick; |
| @@ -777,6 +784,10 @@ void TextureCache<P>::RefreshContents(Image& image, ImageId image_id) { | |||
| 777 | LOG_WARNING(HW_GPU, "MSAA image uploads are not implemented"); | 784 | LOG_WARNING(HW_GPU, "MSAA image uploads are not implemented"); |
| 778 | return; | 785 | return; |
| 779 | } | 786 | } |
| 787 | if (True(image.flags & ImageFlagBits::AsynchronousDecode)) { | ||
| 788 | QueueAsyncDecode(image, image_id); | ||
| 789 | return; | ||
| 790 | } | ||
| 780 | auto staging = runtime.UploadStagingBuffer(MapSizeBytes(image)); | 791 | auto staging = runtime.UploadStagingBuffer(MapSizeBytes(image)); |
| 781 | UploadImageContents(image, staging); | 792 | UploadImageContents(image, staging); |
| 782 | runtime.InsertUploadMemoryBarrier(); | 793 | runtime.InsertUploadMemoryBarrier(); |
| @@ -990,6 +1001,64 @@ u64 TextureCache<P>::GetScaledImageSizeBytes(const ImageBase& image) { | |||
| 990 | } | 1001 | } |
| 991 | 1002 | ||
| 992 | template <class P> | 1003 | template <class P> |
| 1004 | void TextureCache<P>::QueueAsyncDecode(Image& image, ImageId image_id) { | ||
| 1005 | UNIMPLEMENTED_IF(False(image.flags & ImageFlagBits::Converted)); | ||
| 1006 | |||
| 1007 | image.flags |= ImageFlagBits::IsDecoding; | ||
| 1008 | auto decode = std::make_unique<AsyncDecodeContext>(); | ||
| 1009 | auto* decode_ptr = decode.get(); | ||
| 1010 | decode->image_id = image_id; | ||
| 1011 | async_decodes.push_back(std::move(decode)); | ||
| 1012 | |||
| 1013 | Common::ScratchBuffer<u8> local_unswizzle_data_buffer(image.unswizzled_size_bytes); | ||
| 1014 | const size_t guest_size_bytes = image.guest_size_bytes; | ||
| 1015 | swizzle_data_buffer.resize_destructive(guest_size_bytes); | ||
| 1016 | gpu_memory->ReadBlockUnsafe(image.gpu_addr, swizzle_data_buffer.data(), guest_size_bytes); | ||
| 1017 | auto copies = UnswizzleImage(*gpu_memory, image.gpu_addr, image.info, swizzle_data_buffer, | ||
| 1018 | local_unswizzle_data_buffer); | ||
| 1019 | const size_t out_size = MapSizeBytes(image); | ||
| 1020 | |||
| 1021 | auto func = [out_size, copies, info = image.info, | ||
| 1022 | input = std::move(local_unswizzle_data_buffer), | ||
| 1023 | async_decode = decode_ptr]() mutable { | ||
| 1024 | async_decode->decoded_data.resize_destructive(out_size); | ||
| 1025 | std::span copies_span{copies.data(), copies.size()}; | ||
| 1026 | ConvertImage(input, info, async_decode->decoded_data, copies_span); | ||
| 1027 | |||
| 1028 | // TODO: Do we need this lock? | ||
| 1029 | std::unique_lock lock{async_decode->mutex}; | ||
| 1030 | async_decode->copies = std::move(copies); | ||
| 1031 | async_decode->complete = true; | ||
| 1032 | }; | ||
| 1033 | texture_decode_worker.QueueWork(std::move(func)); | ||
| 1034 | } | ||
| 1035 | |||
| 1036 | template <class P> | ||
| 1037 | void TextureCache<P>::TickAsyncDecode() { | ||
| 1038 | bool has_uploads{}; | ||
| 1039 | auto i = async_decodes.begin(); | ||
| 1040 | while (i != async_decodes.end()) { | ||
| 1041 | auto* async_decode = i->get(); | ||
| 1042 | std::unique_lock lock{async_decode->mutex}; | ||
| 1043 | if (!async_decode->complete) { | ||
| 1044 | ++i; | ||
| 1045 | continue; | ||
| 1046 | } | ||
| 1047 | Image& image = slot_images[async_decode->image_id]; | ||
| 1048 | auto staging = runtime.UploadStagingBuffer(MapSizeBytes(image)); | ||
| 1049 | std::memcpy(staging.mapped_span.data(), async_decode->decoded_data.data(), | ||
| 1050 | async_decode->decoded_data.size()); | ||
| 1051 | image.UploadMemory(staging, async_decode->copies); | ||
| 1052 | image.flags &= ~ImageFlagBits::IsDecoding; | ||
| 1053 | has_uploads = true; | ||
| 1054 | i = async_decodes.erase(i); | ||
| 1055 | } | ||
| 1056 | if (has_uploads) { | ||
| 1057 | runtime.InsertUploadMemoryBarrier(); | ||
| 1058 | } | ||
| 1059 | } | ||
| 1060 | |||
| 1061 | template <class P> | ||
| 993 | bool TextureCache<P>::ScaleUp(Image& image) { | 1062 | bool TextureCache<P>::ScaleUp(Image& image) { |
| 994 | const bool has_copy = image.HasScaled(); | 1063 | const bool has_copy = image.HasScaled(); |
| 995 | const bool rescaled = image.ScaleUp(); | 1064 | const bool rescaled = image.ScaleUp(); |
diff --git a/src/video_core/texture_cache/texture_cache_base.h b/src/video_core/texture_cache/texture_cache_base.h index 485eaabaa..013836933 100644 --- a/src/video_core/texture_cache/texture_cache_base.h +++ b/src/video_core/texture_cache/texture_cache_base.h | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include <atomic> | ||
| 6 | #include <deque> | 7 | #include <deque> |
| 7 | #include <limits> | 8 | #include <limits> |
| 8 | #include <mutex> | 9 | #include <mutex> |
| @@ -18,6 +19,7 @@ | |||
| 18 | #include "common/lru_cache.h" | 19 | #include "common/lru_cache.h" |
| 19 | #include "common/polyfill_ranges.h" | 20 | #include "common/polyfill_ranges.h" |
| 20 | #include "common/scratch_buffer.h" | 21 | #include "common/scratch_buffer.h" |
| 22 | #include "common/thread_worker.h" | ||
| 21 | #include "video_core/compatible_formats.h" | 23 | #include "video_core/compatible_formats.h" |
| 22 | #include "video_core/control/channel_state_cache.h" | 24 | #include "video_core/control/channel_state_cache.h" |
| 23 | #include "video_core/delayed_destruction_ring.h" | 25 | #include "video_core/delayed_destruction_ring.h" |
| @@ -54,6 +56,14 @@ struct ImageViewInOut { | |||
| 54 | ImageViewId id{}; | 56 | ImageViewId id{}; |
| 55 | }; | 57 | }; |
| 56 | 58 | ||
| 59 | struct AsyncDecodeContext { | ||
| 60 | ImageId image_id; | ||
| 61 | Common::ScratchBuffer<u8> decoded_data; | ||
| 62 | std::vector<BufferImageCopy> copies; | ||
| 63 | std::mutex mutex; | ||
| 64 | std::atomic_bool complete; | ||
| 65 | }; | ||
| 66 | |||
| 57 | using TextureCacheGPUMap = std::unordered_map<u64, std::vector<ImageId>, Common::IdentityHash<u64>>; | 67 | using TextureCacheGPUMap = std::unordered_map<u64, std::vector<ImageId>, Common::IdentityHash<u64>>; |
| 58 | 68 | ||
| 59 | class TextureCacheChannelInfo : public ChannelInfo { | 69 | class TextureCacheChannelInfo : public ChannelInfo { |
| @@ -377,6 +387,9 @@ private: | |||
| 377 | bool ScaleDown(Image& image); | 387 | bool ScaleDown(Image& image); |
| 378 | u64 GetScaledImageSizeBytes(const ImageBase& image); | 388 | u64 GetScaledImageSizeBytes(const ImageBase& image); |
| 379 | 389 | ||
| 390 | void QueueAsyncDecode(Image& image, ImageId image_id); | ||
| 391 | void TickAsyncDecode(); | ||
| 392 | |||
| 380 | Runtime& runtime; | 393 | Runtime& runtime; |
| 381 | 394 | ||
| 382 | VideoCore::RasterizerInterface& rasterizer; | 395 | VideoCore::RasterizerInterface& rasterizer; |
| @@ -430,6 +443,9 @@ private: | |||
| 430 | 443 | ||
| 431 | u64 modification_tick = 0; | 444 | u64 modification_tick = 0; |
| 432 | u64 frame_tick = 0; | 445 | u64 frame_tick = 0; |
| 446 | |||
| 447 | Common::ThreadWorker texture_decode_worker{1, "TextureDecoder"}; | ||
| 448 | std::vector<std::unique_ptr<AsyncDecodeContext>> async_decodes; | ||
| 433 | }; | 449 | }; |
| 434 | 450 | ||
| 435 | } // namespace VideoCommon | 451 | } // namespace VideoCommon |