From 090bc588e5498c6a2cea136d28bfe43354aa2096 Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Wed, 22 Feb 2023 00:26:07 -0500 Subject: texture_cache: Add async texture decoding --- src/video_core/texture_cache/image_base.h | 3 + src/video_core/texture_cache/texture_cache.h | 69 +++++++++++++++++++++++ src/video_core/texture_cache/texture_cache_base.h | 16 ++++++ 3 files changed, 88 insertions(+) (limited to 'src/video_core/texture_cache') 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 { Rescaled = 1 << 13, CheckingRescalable = 1 << 14, IsRescalable = 1 << 15, + + AsynchronousDecode = 1 << 16, + IsDecoding = 1 << 17, ///< Is currently being decoded asynchornously. }; DECLARE_ENUM_FLAG_OPERATORS(ImageFlagBits) 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
::RunGarbageCollector() { } --num_iterations; auto& image = slot_images[image_id]; + if (True(image.flags & ImageFlagBits::IsDecoding)) { + // This image is still being decoded, deleting it will invalidate the slot + // used by the async decoder thread. + return false; + } const bool must_download = image.IsSafeDownload() && False(image.flags & ImageFlagBits::BadOverlap); if (!high_priority_mode && @@ -133,6 +138,8 @@ void TextureCache
::TickFrame() { sentenced_images.Tick(); sentenced_framebuffers.Tick(); sentenced_image_view.Tick(); + TickAsyncDecode(); + runtime.TickFrame(); critical_gc = 0; ++frame_tick; @@ -777,6 +784,10 @@ void TextureCache
::RefreshContents(Image& image, ImageId image_id) { LOG_WARNING(HW_GPU, "MSAA image uploads are not implemented"); return; } + if (True(image.flags & ImageFlagBits::AsynchronousDecode)) { + QueueAsyncDecode(image, image_id); + return; + } auto staging = runtime.UploadStagingBuffer(MapSizeBytes(image)); UploadImageContents(image, staging); runtime.InsertUploadMemoryBarrier(); @@ -989,6 +1000,64 @@ u64 TextureCache
::GetScaledImageSizeBytes(const ImageBase& image) {
return fitted_size;
}
+template ::QueueAsyncDecode(Image& image, ImageId image_id) {
+ UNIMPLEMENTED_IF(False(image.flags & ImageFlagBits::Converted));
+
+ image.flags |= ImageFlagBits::IsDecoding;
+ auto decode = std::make_unique ::TickAsyncDecode() {
+ bool has_uploads{};
+ auto i = async_decodes.begin();
+ while (i != async_decodes.end()) {
+ auto* async_decode = i->get();
+ std::unique_lock lock{async_decode->mutex};
+ if (!async_decode->complete) {
+ ++i;
+ continue;
+ }
+ Image& image = slot_images[async_decode->image_id];
+ auto staging = runtime.UploadStagingBuffer(MapSizeBytes(image));
+ std::memcpy(staging.mapped_span.data(), async_decode->decoded_data.data(),
+ async_decode->decoded_data.size());
+ image.UploadMemory(staging, async_decode->copies);
+ image.flags &= ~ImageFlagBits::IsDecoding;
+ has_uploads = true;
+ i = async_decodes.erase(i);
+ }
+ if (has_uploads) {
+ runtime.InsertUploadMemoryBarrier();
+ }
+}
+
template ::ScaleUp(Image& image) {
const bool has_copy = image.HasScaled();
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 @@
#pragma once
+#include