From 382cf087a09e1095f07c14aabc8e432ec0a1a2c1 Mon Sep 17 00:00:00 2001 From: Liam Date: Sun, 3 Dec 2023 14:02:20 -0500 Subject: renderer_vulkan: do not recreate swapchain for srgb --- src/video_core/texture_cache/texture_cache.h | 35 +++++++++++++++++------ src/video_core/texture_cache/texture_cache_base.h | 3 +- 2 files changed, 28 insertions(+), 10 deletions(-) (limited to 'src/video_core/texture_cache') diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index dade38b18..c36ecece2 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h @@ -712,14 +712,15 @@ bool TextureCache

::BlitImage(const Tegra::Engines::Fermi2D::Surface& dst, } template -typename P::ImageView* TextureCache

::TryFindFramebufferImageView(VAddr cpu_addr) { +typename P::ImageView* TextureCache

::TryFindFramebufferImageView( + const Tegra::FramebufferConfig& config, VAddr cpu_addr) { // TODO: Properly implement this const auto it = page_table.find(cpu_addr >> YUZU_PAGEBITS); if (it == page_table.end()) { return nullptr; } const auto& image_map_ids = it->second; - boost::container::small_vector valid_images; + boost::container::small_vector valid_image_ids; for (const ImageMapId map_id : image_map_ids) { const ImageMapView& map = slot_map_views[map_id]; const ImageBase& image = slot_images[map.image_id]; @@ -729,18 +730,34 @@ typename P::ImageView* TextureCache

::TryFindFramebufferImageView(VAddr cpu_ad if (image.image_view_ids.empty()) { continue; } - valid_images.push_back(&image); + valid_image_ids.push_back(map.image_id); } - if (valid_images.size() == 1) [[likely]] { - return &slot_image_views[valid_images[0]->image_view_ids.at(0)]; + const auto view_format = [&]() { + switch (config.pixel_format) { + case Service::android::PixelFormat::Rgb565: + return PixelFormat::R5G6B5_UNORM; + case Service::android::PixelFormat::Bgra8888: + return PixelFormat::B8G8R8A8_UNORM; + default: + return PixelFormat::A8B8G8R8_UNORM; + } + }(); + + const auto GetImageViewForFramebuffer = [&](ImageId image_id) { + const ImageViewInfo info{ImageViewType::e2D, view_format}; + return &slot_image_views[FindOrEmplaceImageView(image_id, info)]; + }; + + if (valid_image_ids.size() == 1) [[likely]] { + return GetImageViewForFramebuffer(valid_image_ids.front()); } - if (valid_images.size() > 0) [[unlikely]] { - std::ranges::sort(valid_images, [](const auto* a, const auto* b) { - return a->modification_tick > b->modification_tick; + if (valid_image_ids.size() > 0) [[unlikely]] { + auto most_recent = std::ranges::max_element(valid_image_ids, [&](auto a, auto b) { + return slot_images[a].modification_tick > slot_images[b].modification_tick; }); - return &slot_image_views[valid_images[0]->image_view_ids.at(0)]; + return GetImageViewForFramebuffer(*most_recent); } return nullptr; diff --git a/src/video_core/texture_cache/texture_cache_base.h b/src/video_core/texture_cache/texture_cache_base.h index a40825c9f..cbe56e166 100644 --- a/src/video_core/texture_cache/texture_cache_base.h +++ b/src/video_core/texture_cache/texture_cache_base.h @@ -209,7 +209,8 @@ public: const Tegra::Engines::Fermi2D::Config& copy); /// Try to find a cached image view in the given CPU address - [[nodiscard]] ImageView* TryFindFramebufferImageView(VAddr cpu_addr); + [[nodiscard]] ImageView* TryFindFramebufferImageView(const Tegra::FramebufferConfig& config, + VAddr cpu_addr); /// Return true when there are uncommitted images to be downloaded [[nodiscard]] bool HasUncommittedFlushes() const noexcept; -- cgit v1.2.3