Compare commits

..

14 Commits

Author SHA1 Message Date
d33937748f Android #155 2023-12-09 00:57:26 +00:00
52e6b8a2d3 Merge pull request #12274 from liamwhite/srgb-nonsense
renderer_vulkan: do not recreate swapchain for srgb
2023-12-08 12:26:13 -05:00
13131e602f Merge pull request #12208 from liamwhite/romfs
romfs: optimize parsing and building
2023-12-08 12:25:58 -05:00
7761f29892 Merge pull request #11214 from lat9nq/ff-deprecated
codec: Update to use av frame flags
2023-12-07 23:13:13 -05:00
e92b10f971 dist: add udev rule to enable user hidraw access (#12292)
* dist: add udev rule to enable user hidraw access

* dist: amend install instructions for udev rules

* dist: change udev prefix prefix from 99 to 72

* dist: fix header typo for udev rule

* Update dist/72-yuzu-input.rules

shoutout to @liamwhite

Co-authored-by: liamwhite <liamwhite@users.noreply.github.com>

* Update dist/72-yuzu-input.rules

shout out to @liamwhite

Co-authored-by: liamwhite <liamwhite@users.noreply.github.com>

* Update dist/72-yuzu-input.rules

shout out to @liamwhite

Co-authored-by: liamwhite <liamwhite@users.noreply.github.com>

* Update dist/72-yuzu-input.rules

shout out to @liamwhite

Co-authored-by: liamwhite <liamwhite@users.noreply.github.com>

* Update dist/72-yuzu-input.rules

Co-authored-by: liamwhite <liamwhite@users.noreply.github.com>

* dist: add spdx header to udev rules

* dist: change udev modes to 0660

* Update dist/72-yuzu-input.rules

Co-authored-by: liamwhite <liamwhite@users.noreply.github.com>

* Update dist/72-yuzu-input.rules

Co-authored-by: liamwhite <liamwhite@users.noreply.github.com>

---------

Co-authored-by: HurricanePootis <hurricanepootis@protonmail.com>
Co-authored-by: liamwhite <liamwhite@users.noreply.github.com>
2023-12-07 23:12:56 -05:00
8a79dd2d6c Merge pull request #12236 from liamwhite/cpu-refactor
core: refactor emulated cpu core activation
2023-12-06 14:19:17 +01:00
4cd3f9f4f9 codec: Update to use av frame flags
Resolves Clang -Wdeprecated-declarations warning from interlaced_frame
2023-12-05 21:10:38 -05:00
f0ee3e29cb arm: fix context save of vector regs 2023-12-04 22:19:11 -05:00
45c87c7e6e core: refactor emulated cpu core activation 2023-12-04 10:37:16 -05:00
6b7dc587cf texture_cache: fix max_element comparison function 2023-12-03 18:40:19 -05:00
f05cb69d4f renderer_opengl: remove srgb conversion logic 2023-12-03 17:08:25 -05:00
382cf087a0 renderer_vulkan: do not recreate swapchain for srgb 2023-12-03 16:43:54 -05:00
0751488727 fsmitm_romfsbuild: optimize for data locality 2023-12-03 16:29:57 -05:00
4bc932261b romfs: cache file and directory metadata tables 2023-12-03 16:29:57 -05:00
22 changed files with 234 additions and 197 deletions

View File

@ -1,6 +1,5 @@
| Pull Request | Commit | Title | Author | Merged? | | Pull Request | Commit | Title | Author | Merged? |
|----|----|----|----|----| |----|----|----|----|----|
| [12236](https://github.com/yuzu-emu/yuzu//pull/12236) | [`f0ee3e29c`](https://github.com/yuzu-emu/yuzu//pull/12236/files) | core: refactor emulated cpu core activation | [liamwhite](https://github.com/liamwhite/) | Yes |
End of merge log. You can find the original README.md below the break. End of merge log. You can find the original README.md below the break.

19
dist/72-yuzu-input.rules vendored Normal file
View File

@ -0,0 +1,19 @@
# SPDX-FileCopyrightText: 2023 yuzu Emulator Project
# SPDX-License-Identifier: GPL-2.0-or-later
# Allow systemd-logind to manage user access to hidraw with this file
# On most systems, this file should be installed to /etc/udev/rules.d/72-yuzu-input.rules
# Consult your distro if this is not the case
# Switch Pro Controller (USB/Bluetooth)
KERNEL=="hidraw*", ATTRS{idVendor}=="057e", ATTRS{idProduct}=="2009", MODE="0660", TAG+="uaccess"
KERNEL=="hidraw*", KERNELS=="*057e:2009*", MODE="0660", TAG+="uaccess"
# Joy-Con L (Bluetooth)
KERNEL=="hidraw*", KERNELS=="*057e:2006*", MODE="0660", TAG+="uaccess"
# Joy-Con R (Bluetooth)
KERNEL=="hidraw*", KERNELS=="*057e:2007*", MODE="0660", TAG+="uaccess"
# Joy-Con Charging Grip (USB)
KERNEL=="hidraw*", ATTRS{idVendor}=="057e", ATTRS{idProduct}=="200e", MODE="0660", TAG+="uaccess"

View File

@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include <cstring> #include <cstring>
#include <span>
#include <string_view> #include <string_view>
#include "common/alignment.h" #include "common/alignment.h"
#include "common/assert.h" #include "common/assert.h"
@ -134,7 +135,7 @@ void RomFSBuildContext::VisitDirectory(VirtualDir romfs_dir, VirtualDir ext_dir,
child->size = child->source->GetSize(); child->size = child->source->GetSize();
AddFile(parent, child); AddFile(parent, std::move(child));
} }
for (auto& child_romfs_dir : romfs_dir->GetSubdirectories()) { for (auto& child_romfs_dir : romfs_dir->GetSubdirectories()) {
@ -163,36 +164,24 @@ void RomFSBuildContext::VisitDirectory(VirtualDir romfs_dir, VirtualDir ext_dir,
bool RomFSBuildContext::AddDirectory(std::shared_ptr<RomFSBuildDirectoryContext> parent_dir_ctx, bool RomFSBuildContext::AddDirectory(std::shared_ptr<RomFSBuildDirectoryContext> parent_dir_ctx,
std::shared_ptr<RomFSBuildDirectoryContext> dir_ctx) { std::shared_ptr<RomFSBuildDirectoryContext> dir_ctx) {
// Check whether it's already in the known directories.
const auto [it, is_new] = directories.emplace(dir_ctx->path, nullptr);
if (!is_new) {
return false;
}
// Add a new directory. // Add a new directory.
num_dirs++; num_dirs++;
dir_table_size += dir_table_size +=
sizeof(RomFSDirectoryEntry) + Common::AlignUp(dir_ctx->path_len - dir_ctx->cur_path_ofs, 4); sizeof(RomFSDirectoryEntry) + Common::AlignUp(dir_ctx->path_len - dir_ctx->cur_path_ofs, 4);
dir_ctx->parent = parent_dir_ctx; dir_ctx->parent = std::move(parent_dir_ctx);
it->second = dir_ctx; directories.emplace_back(std::move(dir_ctx));
return true; return true;
} }
bool RomFSBuildContext::AddFile(std::shared_ptr<RomFSBuildDirectoryContext> parent_dir_ctx, bool RomFSBuildContext::AddFile(std::shared_ptr<RomFSBuildDirectoryContext> parent_dir_ctx,
std::shared_ptr<RomFSBuildFileContext> file_ctx) { std::shared_ptr<RomFSBuildFileContext> file_ctx) {
// Check whether it's already in the known files.
const auto [it, is_new] = files.emplace(file_ctx->path, nullptr);
if (!is_new) {
return false;
}
// Add a new file. // Add a new file.
num_files++; num_files++;
file_table_size += file_table_size +=
sizeof(RomFSFileEntry) + Common::AlignUp(file_ctx->path_len - file_ctx->cur_path_ofs, 4); sizeof(RomFSFileEntry) + Common::AlignUp(file_ctx->path_len - file_ctx->cur_path_ofs, 4);
file_ctx->parent = parent_dir_ctx; file_ctx->parent = std::move(parent_dir_ctx);
it->second = file_ctx; files.emplace_back(std::move(file_ctx));
return true; return true;
} }
@ -201,7 +190,7 @@ RomFSBuildContext::RomFSBuildContext(VirtualDir base_, VirtualDir ext_)
: base(std::move(base_)), ext(std::move(ext_)) { : base(std::move(base_)), ext(std::move(ext_)) {
root = std::make_shared<RomFSBuildDirectoryContext>(); root = std::make_shared<RomFSBuildDirectoryContext>();
root->path = "\0"; root->path = "\0";
directories.emplace(root->path, root); directories.emplace_back(root);
num_dirs = 1; num_dirs = 1;
dir_table_size = 0x18; dir_table_size = 0x18;
@ -210,28 +199,43 @@ RomFSBuildContext::RomFSBuildContext(VirtualDir base_, VirtualDir ext_)
RomFSBuildContext::~RomFSBuildContext() = default; RomFSBuildContext::~RomFSBuildContext() = default;
std::multimap<u64, VirtualFile> RomFSBuildContext::Build() { std::vector<std::pair<u64, VirtualFile>> RomFSBuildContext::Build() {
const u64 dir_hash_table_entry_count = romfs_get_hash_table_count(num_dirs); const u64 dir_hash_table_entry_count = romfs_get_hash_table_count(num_dirs);
const u64 file_hash_table_entry_count = romfs_get_hash_table_count(num_files); const u64 file_hash_table_entry_count = romfs_get_hash_table_count(num_files);
dir_hash_table_size = 4 * dir_hash_table_entry_count; dir_hash_table_size = 4 * dir_hash_table_entry_count;
file_hash_table_size = 4 * file_hash_table_entry_count; file_hash_table_size = 4 * file_hash_table_entry_count;
// Assign metadata pointers // Assign metadata pointers.
RomFSHeader header{}; RomFSHeader header{};
std::vector<u32> dir_hash_table(dir_hash_table_entry_count, ROMFS_ENTRY_EMPTY); std::vector<u8> metadata(file_hash_table_size + file_table_size + dir_hash_table_size +
std::vector<u32> file_hash_table(file_hash_table_entry_count, ROMFS_ENTRY_EMPTY); dir_table_size);
u32* const dir_hash_table_pointer = reinterpret_cast<u32*>(metadata.data());
u8* const dir_table_pointer = metadata.data() + dir_hash_table_size;
u32* const file_hash_table_pointer =
reinterpret_cast<u32*>(metadata.data() + dir_hash_table_size + dir_table_size);
u8* const file_table_pointer =
metadata.data() + dir_hash_table_size + dir_table_size + file_hash_table_size;
std::vector<u8> dir_table(dir_table_size); std::span<u32> dir_hash_table(dir_hash_table_pointer, dir_hash_table_entry_count);
std::vector<u8> file_table(file_table_size); std::span<u32> file_hash_table(file_hash_table_pointer, file_hash_table_entry_count);
std::span<u8> dir_table(dir_table_pointer, dir_table_size);
std::span<u8> file_table(file_table_pointer, file_table_size);
std::shared_ptr<RomFSBuildFileContext> cur_file; // Initialize hash tables.
std::memset(dir_hash_table.data(), 0xFF, dir_hash_table.size_bytes());
std::memset(file_hash_table.data(), 0xFF, file_hash_table.size_bytes());
// Sort tables by name.
std::sort(files.begin(), files.end(),
[](const auto& a, const auto& b) { return a->path < b->path; });
std::sort(directories.begin(), directories.end(),
[](const auto& a, const auto& b) { return a->path < b->path; });
// Determine file offsets. // Determine file offsets.
u32 entry_offset = 0; u32 entry_offset = 0;
std::shared_ptr<RomFSBuildFileContext> prev_file = nullptr; std::shared_ptr<RomFSBuildFileContext> prev_file = nullptr;
for (const auto& it : files) { for (const auto& cur_file : files) {
cur_file = it.second;
file_partition_size = Common::AlignUp(file_partition_size, 16); file_partition_size = Common::AlignUp(file_partition_size, 16);
cur_file->offset = file_partition_size; cur_file->offset = file_partition_size;
file_partition_size += cur_file->size; file_partition_size += cur_file->size;
@ -243,34 +247,48 @@ std::multimap<u64, VirtualFile> RomFSBuildContext::Build() {
} }
// Assign deferred parent/sibling ownership. // Assign deferred parent/sibling ownership.
for (auto it = files.rbegin(); it != files.rend(); ++it) { for (auto it = files.rbegin(); it != files.rend(); ++it) {
cur_file = it->second; auto& cur_file = *it;
cur_file->sibling = cur_file->parent->file; cur_file->sibling = cur_file->parent->file;
cur_file->parent->file = cur_file; cur_file->parent->file = cur_file;
} }
std::shared_ptr<RomFSBuildDirectoryContext> cur_dir;
// Determine directory offsets. // Determine directory offsets.
entry_offset = 0; entry_offset = 0;
for (const auto& it : directories) { for (const auto& cur_dir : directories) {
cur_dir = it.second;
cur_dir->entry_offset = entry_offset; cur_dir->entry_offset = entry_offset;
entry_offset += entry_offset +=
static_cast<u32>(sizeof(RomFSDirectoryEntry) + static_cast<u32>(sizeof(RomFSDirectoryEntry) +
Common::AlignUp(cur_dir->path_len - cur_dir->cur_path_ofs, 4)); Common::AlignUp(cur_dir->path_len - cur_dir->cur_path_ofs, 4));
} }
// Assign deferred parent/sibling ownership. // Assign deferred parent/sibling ownership.
for (auto it = directories.rbegin(); it->second != root; ++it) { for (auto it = directories.rbegin(); (*it) != root; ++it) {
cur_dir = it->second; auto& cur_dir = *it;
cur_dir->sibling = cur_dir->parent->child; cur_dir->sibling = cur_dir->parent->child;
cur_dir->parent->child = cur_dir; cur_dir->parent->child = cur_dir;
} }
std::multimap<u64, VirtualFile> out; // Create output map.
std::vector<std::pair<u64, VirtualFile>> out;
out.reserve(num_files + 2);
// Set header fields.
header.header_size = sizeof(RomFSHeader);
header.file_hash_table_size = file_hash_table_size;
header.file_table_size = file_table_size;
header.dir_hash_table_size = dir_hash_table_size;
header.dir_table_size = dir_table_size;
header.file_partition_ofs = ROMFS_FILEPARTITION_OFS;
header.dir_hash_table_ofs = Common::AlignUp(header.file_partition_ofs + file_partition_size, 4);
header.dir_table_ofs = header.dir_hash_table_ofs + header.dir_hash_table_size;
header.file_hash_table_ofs = header.dir_table_ofs + header.dir_table_size;
header.file_table_ofs = header.file_hash_table_ofs + header.file_hash_table_size;
std::vector<u8> header_data(sizeof(RomFSHeader));
std::memcpy(header_data.data(), &header, header_data.size());
out.emplace_back(0, std::make_shared<VectorVfsFile>(std::move(header_data)));
// Populate file tables. // Populate file tables.
for (const auto& it : files) { for (const auto& cur_file : files) {
cur_file = it.second;
RomFSFileEntry cur_entry{}; RomFSFileEntry cur_entry{};
cur_entry.parent = cur_file->parent->entry_offset; cur_entry.parent = cur_file->parent->entry_offset;
@ -287,7 +305,7 @@ std::multimap<u64, VirtualFile> RomFSBuildContext::Build() {
cur_entry.name_size = name_size; cur_entry.name_size = name_size;
out.emplace(cur_file->offset + ROMFS_FILEPARTITION_OFS, std::move(cur_file->source)); out.emplace_back(cur_file->offset + ROMFS_FILEPARTITION_OFS, std::move(cur_file->source));
std::memcpy(file_table.data() + cur_file->entry_offset, &cur_entry, sizeof(RomFSFileEntry)); std::memcpy(file_table.data() + cur_file->entry_offset, &cur_entry, sizeof(RomFSFileEntry));
std::memset(file_table.data() + cur_file->entry_offset + sizeof(RomFSFileEntry), 0, std::memset(file_table.data() + cur_file->entry_offset + sizeof(RomFSFileEntry), 0,
Common::AlignUp(cur_entry.name_size, 4)); Common::AlignUp(cur_entry.name_size, 4));
@ -296,8 +314,7 @@ std::multimap<u64, VirtualFile> RomFSBuildContext::Build() {
} }
// Populate dir tables. // Populate dir tables.
for (const auto& it : directories) { for (const auto& cur_dir : directories) {
cur_dir = it.second;
RomFSDirectoryEntry cur_entry{}; RomFSDirectoryEntry cur_entry{};
cur_entry.parent = cur_dir == root ? 0 : cur_dir->parent->entry_offset; cur_entry.parent = cur_dir == root ? 0 : cur_dir->parent->entry_offset;
@ -323,34 +340,13 @@ std::multimap<u64, VirtualFile> RomFSBuildContext::Build() {
cur_dir->path.data() + cur_dir->cur_path_ofs, name_size); cur_dir->path.data() + cur_dir->cur_path_ofs, name_size);
} }
// Set header fields. // Write metadata.
header.header_size = sizeof(RomFSHeader); out.emplace_back(header.dir_hash_table_ofs,
header.file_hash_table_size = file_hash_table_size; std::make_shared<VectorVfsFile>(std::move(metadata)));
header.file_table_size = file_table_size;
header.dir_hash_table_size = dir_hash_table_size;
header.dir_table_size = dir_table_size;
header.file_partition_ofs = ROMFS_FILEPARTITION_OFS;
header.dir_hash_table_ofs = Common::AlignUp(header.file_partition_ofs + file_partition_size, 4);
header.dir_table_ofs = header.dir_hash_table_ofs + header.dir_hash_table_size;
header.file_hash_table_ofs = header.dir_table_ofs + header.dir_table_size;
header.file_table_ofs = header.file_hash_table_ofs + header.file_hash_table_size;
std::vector<u8> header_data(sizeof(RomFSHeader)); // Sort the output.
std::memcpy(header_data.data(), &header, header_data.size()); std::sort(out.begin(), out.end(),
out.emplace(0, std::make_shared<VectorVfsFile>(std::move(header_data))); [](const auto& a, const auto& b) { return a.first < b.first; });
std::vector<u8> metadata(file_hash_table_size + file_table_size + dir_hash_table_size +
dir_table_size);
std::size_t index = 0;
std::memcpy(metadata.data(), dir_hash_table.data(), dir_hash_table.size() * sizeof(u32));
index += dir_hash_table.size() * sizeof(u32);
std::memcpy(metadata.data() + index, dir_table.data(), dir_table.size());
index += dir_table.size();
std::memcpy(metadata.data() + index, file_hash_table.data(),
file_hash_table.size() * sizeof(u32));
index += file_hash_table.size() * sizeof(u32);
std::memcpy(metadata.data() + index, file_table.data(), file_table.size());
out.emplace(header.dir_hash_table_ofs, std::make_shared<VectorVfsFile>(std::move(metadata)));
return out; return out;
} }

View File

@ -22,14 +22,14 @@ public:
~RomFSBuildContext(); ~RomFSBuildContext();
// This finalizes the context. // This finalizes the context.
std::multimap<u64, VirtualFile> Build(); std::vector<std::pair<u64, VirtualFile>> Build();
private: private:
VirtualDir base; VirtualDir base;
VirtualDir ext; VirtualDir ext;
std::shared_ptr<RomFSBuildDirectoryContext> root; std::shared_ptr<RomFSBuildDirectoryContext> root;
std::map<std::string, std::shared_ptr<RomFSBuildDirectoryContext>, std::less<>> directories; std::vector<std::shared_ptr<RomFSBuildDirectoryContext>> directories;
std::map<std::string, std::shared_ptr<RomFSBuildFileContext>, std::less<>> files; std::vector<std::shared_ptr<RomFSBuildFileContext>> files;
u64 num_dirs = 0; u64 num_dirs = 0;
u64 num_files = 0; u64 num_files = 0;
u64 dir_table_size = 0; u64 dir_table_size = 0;

View File

@ -55,44 +55,68 @@ struct FileEntry {
}; };
static_assert(sizeof(FileEntry) == 0x20, "FileEntry has incorrect size."); static_assert(sizeof(FileEntry) == 0x20, "FileEntry has incorrect size.");
template <typename Entry> struct RomFSTraversalContext {
std::pair<Entry, std::string> GetEntry(const VirtualFile& file, std::size_t offset) { RomFSHeader header;
Entry entry{}; VirtualFile file;
if (file->ReadObject(&entry, offset) != sizeof(Entry)) std::vector<u8> directory_meta;
std::vector<u8> file_meta;
};
template <typename EntryType, auto Member>
std::pair<EntryType, std::string> GetEntry(const RomFSTraversalContext& ctx, size_t offset) {
const size_t entry_end = offset + sizeof(EntryType);
const std::vector<u8>& vec = ctx.*Member;
const size_t size = vec.size();
const u8* data = vec.data();
EntryType entry{};
if (entry_end > size) {
return {}; return {};
std::string string(entry.name_length, '\0'); }
if (file->ReadArray(&string[0], string.size(), offset + sizeof(Entry)) != string.size()) std::memcpy(&entry, data + offset, sizeof(EntryType));
return {};
return {entry, string}; const size_t name_length = std::min(entry_end + entry.name_length, size) - entry_end;
std::string name(reinterpret_cast<const char*>(data + entry_end), name_length);
return {entry, std::move(name)};
} }
void ProcessFile(const VirtualFile& file, std::size_t file_offset, std::size_t data_offset, std::pair<DirectoryEntry, std::string> GetDirectoryEntry(const RomFSTraversalContext& ctx,
u32 this_file_offset, std::shared_ptr<VectorVfsDirectory>& parent) { size_t directory_offset) {
while (this_file_offset != ROMFS_ENTRY_EMPTY) { return GetEntry<DirectoryEntry, &RomFSTraversalContext::directory_meta>(ctx, directory_offset);
auto entry = GetEntry<FileEntry>(file, file_offset + this_file_offset); }
parent->AddFile(std::make_shared<OffsetVfsFile>( std::pair<FileEntry, std::string> GetFileEntry(const RomFSTraversalContext& ctx,
file, entry.first.size, entry.first.offset + data_offset, entry.second)); size_t file_offset) {
return GetEntry<FileEntry, &RomFSTraversalContext::file_meta>(ctx, file_offset);
}
void ProcessFile(const RomFSTraversalContext& ctx, u32 this_file_offset,
std::shared_ptr<VectorVfsDirectory>& parent) {
while (this_file_offset != ROMFS_ENTRY_EMPTY) {
auto entry = GetFileEntry(ctx, this_file_offset);
parent->AddFile(std::make_shared<OffsetVfsFile>(ctx.file, entry.first.size,
entry.first.offset + ctx.header.data_offset,
std::move(entry.second)));
this_file_offset = entry.first.sibling; this_file_offset = entry.first.sibling;
} }
} }
void ProcessDirectory(const VirtualFile& file, std::size_t dir_offset, std::size_t file_offset, void ProcessDirectory(const RomFSTraversalContext& ctx, u32 this_dir_offset,
std::size_t data_offset, u32 this_dir_offset,
std::shared_ptr<VectorVfsDirectory>& parent) { std::shared_ptr<VectorVfsDirectory>& parent) {
while (this_dir_offset != ROMFS_ENTRY_EMPTY) { while (this_dir_offset != ROMFS_ENTRY_EMPTY) {
auto entry = GetEntry<DirectoryEntry>(file, dir_offset + this_dir_offset); auto entry = GetDirectoryEntry(ctx, this_dir_offset);
auto current = std::make_shared<VectorVfsDirectory>( auto current = std::make_shared<VectorVfsDirectory>(
std::vector<VirtualFile>{}, std::vector<VirtualDir>{}, entry.second); std::vector<VirtualFile>{}, std::vector<VirtualDir>{}, entry.second);
if (entry.first.child_file != ROMFS_ENTRY_EMPTY) { if (entry.first.child_file != ROMFS_ENTRY_EMPTY) {
ProcessFile(file, file_offset, data_offset, entry.first.child_file, current); ProcessFile(ctx, entry.first.child_file, current);
} }
if (entry.first.child_dir != ROMFS_ENTRY_EMPTY) { if (entry.first.child_dir != ROMFS_ENTRY_EMPTY) {
ProcessDirectory(file, dir_offset, file_offset, data_offset, entry.first.child_dir, ProcessDirectory(ctx, entry.first.child_dir, current);
current);
} }
parent->AddDirectory(current); parent->AddDirectory(current);
@ -107,22 +131,25 @@ VirtualDir ExtractRomFS(VirtualFile file) {
return root_container; return root_container;
} }
RomFSHeader header{}; RomFSTraversalContext ctx{};
if (file->ReadObject(&header) != sizeof(RomFSHeader)) {
return root_container; if (file->ReadObject(&ctx.header) != sizeof(RomFSHeader)) {
return nullptr;
} }
if (header.header_size != sizeof(RomFSHeader)) { if (ctx.header.header_size != sizeof(RomFSHeader)) {
return root_container; return nullptr;
} }
const u64 file_offset = header.file_meta.offset; ctx.file = file;
const u64 dir_offset = header.directory_meta.offset; ctx.directory_meta =
file->ReadBytes(ctx.header.directory_meta.size, ctx.header.directory_meta.offset);
ctx.file_meta = file->ReadBytes(ctx.header.file_meta.size, ctx.header.file_meta.offset);
ProcessDirectory(file, dir_offset, file_offset, header.data_offset, 0, root_container); ProcessDirectory(ctx, 0, root_container);
if (auto root = root_container->GetSubdirectory(""); root) { if (auto root = root_container->GetSubdirectory(""); root) {
return std::make_shared<CachedVfsDirectory>(std::move(root)); return root;
} }
ASSERT(false); ASSERT(false);

View File

@ -59,8 +59,8 @@ VirtualFile ConcatenatedVfsFile::MakeConcatenatedFile(std::string&& name,
return VirtualFile(new ConcatenatedVfsFile(std::move(name), std::move(concatenation_map))); return VirtualFile(new ConcatenatedVfsFile(std::move(name), std::move(concatenation_map)));
} }
VirtualFile ConcatenatedVfsFile::MakeConcatenatedFile(u8 filler_byte, std::string&& name, VirtualFile ConcatenatedVfsFile::MakeConcatenatedFile(
std::multimap<u64, VirtualFile>&& files) { u8 filler_byte, std::string&& name, std::vector<std::pair<u64, VirtualFile>>&& files) {
// Fold trivial cases. // Fold trivial cases.
if (files.empty()) { if (files.empty()) {
return nullptr; return nullptr;

View File

@ -37,7 +37,7 @@ public:
/// Convenience function that turns a map of offsets to files into a concatenated file, filling /// Convenience function that turns a map of offsets to files into a concatenated file, filling
/// gaps with a given filler byte. /// gaps with a given filler byte.
static VirtualFile MakeConcatenatedFile(u8 filler_byte, std::string&& name, static VirtualFile MakeConcatenatedFile(u8 filler_byte, std::string&& name,
std::multimap<u64, VirtualFile>&& files); std::vector<std::pair<u64, VirtualFile>>&& files);
std::string GetName() const override; std::string GetName() const override;
std::size_t GetSize() const override; std::size_t GetSize() const override;

View File

@ -3,6 +3,7 @@
#include <algorithm> #include <algorithm>
#include <set> #include <set>
#include <unordered_set>
#include <utility> #include <utility>
#include "core/file_sys/vfs_layered.h" #include "core/file_sys/vfs_layered.h"
@ -59,13 +60,12 @@ std::string LayeredVfsDirectory::GetFullPath() const {
std::vector<VirtualFile> LayeredVfsDirectory::GetFiles() const { std::vector<VirtualFile> LayeredVfsDirectory::GetFiles() const {
std::vector<VirtualFile> out; std::vector<VirtualFile> out;
std::set<std::string, std::less<>> out_names; std::unordered_set<std::string> out_names;
for (const auto& layer : dirs) { for (const auto& layer : dirs) {
for (auto& file : layer->GetFiles()) { for (auto& file : layer->GetFiles()) {
auto file_name = file->GetName(); const auto [it, is_new] = out_names.emplace(file->GetName());
if (!out_names.contains(file_name)) { if (is_new) {
out_names.emplace(std::move(file_name));
out.emplace_back(std::move(file)); out.emplace_back(std::move(file));
} }
} }
@ -75,18 +75,19 @@ std::vector<VirtualFile> LayeredVfsDirectory::GetFiles() const {
} }
std::vector<VirtualDir> LayeredVfsDirectory::GetSubdirectories() const { std::vector<VirtualDir> LayeredVfsDirectory::GetSubdirectories() const {
std::vector<std::string> names; std::vector<VirtualDir> out;
std::unordered_set<std::string> out_names;
for (const auto& layer : dirs) { for (const auto& layer : dirs) {
for (const auto& sd : layer->GetSubdirectories()) { for (const auto& sd : layer->GetSubdirectories()) {
if (std::find(names.begin(), names.end(), sd->GetName()) == names.end()) out_names.emplace(sd->GetName());
names.push_back(sd->GetName());
} }
} }
std::vector<VirtualDir> out; out.reserve(out_names.size());
out.reserve(names.size()); for (const auto& subdir : out_names) {
for (const auto& subdir : names)
out.emplace_back(GetSubdirectory(subdir)); out.emplace_back(GetSubdirectory(subdir));
}
return out; return out;
} }

View File

@ -233,7 +233,12 @@ std::unique_ptr<Frame> DecoderContext::ReceiveFrame(bool* out_is_interlaced) {
return false; return false;
} }
*out_is_interlaced = frame->interlaced_frame != 0; *out_is_interlaced =
#if defined(FF_API_INTERLACED_FRAME) || LIBAVUTIL_VERSION_MAJOR >= 59
(frame->flags & AV_FRAME_FLAG_INTERLACED) != 0;
#else
frame->interlaced_frame != 0;
#endif
return true; return true;
}; };

View File

@ -714,7 +714,8 @@ bool RasterizerOpenGL::AccelerateDisplay(const Tegra::FramebufferConfig& config,
MICROPROFILE_SCOPE(OpenGL_CacheManagement); MICROPROFILE_SCOPE(OpenGL_CacheManagement);
std::scoped_lock lock{texture_cache.mutex}; std::scoped_lock lock{texture_cache.mutex};
ImageView* const image_view{texture_cache.TryFindFramebufferImageView(framebuffer_addr)}; ImageView* const image_view{
texture_cache.TryFindFramebufferImageView(config, framebuffer_addr)};
if (!image_view) { if (!image_view) {
return false; return false;
} }
@ -725,7 +726,6 @@ bool RasterizerOpenGL::AccelerateDisplay(const Tegra::FramebufferConfig& config,
screen_info.texture.width = image_view->size.width; screen_info.texture.width = image_view->size.width;
screen_info.texture.height = image_view->size.height; screen_info.texture.height = image_view->size.height;
screen_info.display_texture = image_view->Handle(Shader::TextureType::Color2D); screen_info.display_texture = image_view->Handle(Shader::TextureType::Color2D);
screen_info.display_srgb = VideoCore::Surface::IsPixelFormatSRGB(image_view->format);
return true; return true;
} }

View File

@ -653,11 +653,7 @@ void RendererOpenGL::DrawScreen(const Layout::FramebufferLayout& layout) {
}; };
glNamedBufferSubData(vertex_buffer.handle, 0, sizeof(vertices), std::data(vertices)); glNamedBufferSubData(vertex_buffer.handle, 0, sizeof(vertices), std::data(vertices));
if (screen_info.display_srgb) { glDisable(GL_FRAMEBUFFER_SRGB);
glEnable(GL_FRAMEBUFFER_SRGB);
} else {
glDisable(GL_FRAMEBUFFER_SRGB);
}
glViewportIndexedf(0, 0.0f, 0.0f, static_cast<GLfloat>(layout.width), glViewportIndexedf(0, 0.0f, 0.0f, static_cast<GLfloat>(layout.width),
static_cast<GLfloat>(layout.height)); static_cast<GLfloat>(layout.height));
@ -710,8 +706,7 @@ void RendererOpenGL::RenderScreenshot() {
GLuint renderbuffer; GLuint renderbuffer;
glGenRenderbuffers(1, &renderbuffer); glGenRenderbuffers(1, &renderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, screen_info.display_srgb ? GL_SRGB8 : GL_RGB8, glRenderbufferStorage(GL_RENDERBUFFER, GL_SRGB8, layout.width, layout.height);
layout.width, layout.height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer);
DrawScreen(layout); DrawScreen(layout);

View File

@ -53,7 +53,6 @@ struct TextureInfo {
struct ScreenInfo { struct ScreenInfo {
GLuint display_texture{}; GLuint display_texture{};
bool was_accelerated = false; bool was_accelerated = false;
bool display_srgb{};
const Common::Rectangle<float> display_texcoords{0.0f, 0.0f, 1.0f, 1.0f}; const Common::Rectangle<float> display_texcoords{0.0f, 0.0f, 1.0f, 1.0f};
TextureInfo texture; TextureInfo texture;
}; };

View File

@ -94,7 +94,7 @@ RendererVulkan::RendererVulkan(Core::TelemetrySession& telemetry_session_,
device(CreateDevice(instance, dld, *surface)), memory_allocator(device), state_tracker(), device(CreateDevice(instance, dld, *surface)), memory_allocator(device), state_tracker(),
scheduler(device, state_tracker), scheduler(device, state_tracker),
swapchain(*surface, device, scheduler, render_window.GetFramebufferLayout().width, swapchain(*surface, device, scheduler, render_window.GetFramebufferLayout().width,
render_window.GetFramebufferLayout().height, false), render_window.GetFramebufferLayout().height),
present_manager(instance, render_window, device, memory_allocator, scheduler, swapchain, present_manager(instance, render_window, device, memory_allocator, scheduler, swapchain,
surface), surface),
blit_screen(cpu_memory, render_window, device, memory_allocator, swapchain, present_manager, blit_screen(cpu_memory, render_window, device, memory_allocator, swapchain, present_manager,
@ -131,11 +131,10 @@ void RendererVulkan::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) {
const VAddr framebuffer_addr = framebuffer->address + framebuffer->offset; const VAddr framebuffer_addr = framebuffer->address + framebuffer->offset;
const bool use_accelerated = const bool use_accelerated =
rasterizer.AccelerateDisplay(*framebuffer, framebuffer_addr, framebuffer->stride); rasterizer.AccelerateDisplay(*framebuffer, framebuffer_addr, framebuffer->stride);
const bool is_srgb = use_accelerated && screen_info.is_srgb;
RenderScreenshot(*framebuffer, use_accelerated); RenderScreenshot(*framebuffer, use_accelerated);
Frame* frame = present_manager.GetRenderFrame(); Frame* frame = present_manager.GetRenderFrame();
blit_screen.DrawToSwapchain(frame, *framebuffer, use_accelerated, is_srgb); blit_screen.DrawToSwapchain(frame, *framebuffer, use_accelerated);
scheduler.Flush(*frame->render_ready); scheduler.Flush(*frame->render_ready);
present_manager.Present(frame); present_manager.Present(frame);
@ -205,7 +204,7 @@ void Vulkan::RendererVulkan::RenderScreenshot(const Tegra::FramebufferConfig& fr
.flags = 0, .flags = 0,
.image = *staging_image, .image = *staging_image,
.viewType = VK_IMAGE_VIEW_TYPE_2D, .viewType = VK_IMAGE_VIEW_TYPE_2D,
.format = screen_info.is_srgb ? VK_FORMAT_B8G8R8A8_SRGB : VK_FORMAT_B8G8R8A8_UNORM, .format = VK_FORMAT_B8G8R8A8_UNORM,
.components{ .components{
.r = VK_COMPONENT_SWIZZLE_IDENTITY, .r = VK_COMPONENT_SWIZZLE_IDENTITY,
.g = VK_COMPONENT_SWIZZLE_IDENTITY, .g = VK_COMPONENT_SWIZZLE_IDENTITY,

View File

@ -127,9 +127,9 @@ BlitScreen::BlitScreen(Core::Memory::Memory& cpu_memory_, Core::Frontend::EmuWin
Scheduler& scheduler_, const ScreenInfo& screen_info_) Scheduler& scheduler_, const ScreenInfo& screen_info_)
: cpu_memory{cpu_memory_}, render_window{render_window_}, device{device_}, : cpu_memory{cpu_memory_}, render_window{render_window_}, device{device_},
memory_allocator{memory_allocator_}, swapchain{swapchain_}, present_manager{present_manager_}, memory_allocator{memory_allocator_}, swapchain{swapchain_}, present_manager{present_manager_},
scheduler{scheduler_}, image_count{swapchain.GetImageCount()}, screen_info{screen_info_}, scheduler{scheduler_}, image_count{swapchain.GetImageCount()}, screen_info{screen_info_} {
current_srgb{swapchain.IsSrgb()}, image_view_format{swapchain.GetImageViewFormat()} {
resource_ticks.resize(image_count); resource_ticks.resize(image_count);
swapchain_view_format = swapchain.GetImageViewFormat();
CreateStaticResources(); CreateStaticResources();
CreateDynamicResources(); CreateDynamicResources();
@ -480,28 +480,22 @@ void BlitScreen::Draw(const Tegra::FramebufferConfig& framebuffer,
} }
void BlitScreen::DrawToSwapchain(Frame* frame, const Tegra::FramebufferConfig& framebuffer, void BlitScreen::DrawToSwapchain(Frame* frame, const Tegra::FramebufferConfig& framebuffer,
bool use_accelerated, bool is_srgb) { bool use_accelerated) {
// Recreate dynamic resources if the the image count or colorspace changed // Recreate dynamic resources if the the image count or input format changed
const VkFormat current_framebuffer_format =
std::exchange(framebuffer_view_format, GetFormat(framebuffer));
if (const std::size_t swapchain_images = swapchain.GetImageCount(); if (const std::size_t swapchain_images = swapchain.GetImageCount();
swapchain_images != image_count || current_srgb != is_srgb) { swapchain_images != image_count || current_framebuffer_format != framebuffer_view_format) {
current_srgb = is_srgb;
#ifdef ANDROID
// Android is already ordered the same as Switch.
image_view_format = current_srgb ? VK_FORMAT_R8G8B8A8_SRGB : VK_FORMAT_R8G8B8A8_UNORM;
#else
image_view_format = current_srgb ? VK_FORMAT_B8G8R8A8_SRGB : VK_FORMAT_B8G8R8A8_UNORM;
#endif
image_count = swapchain_images; image_count = swapchain_images;
Recreate(); Recreate();
} }
// Recreate the presentation frame if the dimensions of the window changed // Recreate the presentation frame if the dimensions of the window changed
const Layout::FramebufferLayout layout = render_window.GetFramebufferLayout(); const Layout::FramebufferLayout layout = render_window.GetFramebufferLayout();
if (layout.width != frame->width || layout.height != frame->height || if (layout.width != frame->width || layout.height != frame->height) {
is_srgb != frame->is_srgb) {
Recreate(); Recreate();
present_manager.RecreateFrame(frame, layout.width, layout.height, is_srgb, present_manager.RecreateFrame(frame, layout.width, layout.height, swapchain_view_format,
image_view_format, *renderpass); *renderpass);
} }
const VkExtent2D render_area{frame->width, frame->height}; const VkExtent2D render_area{frame->width, frame->height};
@ -629,7 +623,7 @@ void BlitScreen::CreateDescriptorPool() {
} }
void BlitScreen::CreateRenderPass() { void BlitScreen::CreateRenderPass() {
renderpass = CreateRenderPassImpl(image_view_format); renderpass = CreateRenderPassImpl(swapchain_view_format);
} }
vk::RenderPass BlitScreen::CreateRenderPassImpl(VkFormat format) { vk::RenderPass BlitScreen::CreateRenderPassImpl(VkFormat format) {
@ -1149,7 +1143,7 @@ void BlitScreen::CreateRawImages(const Tegra::FramebufferConfig& framebuffer) {
.pNext = nullptr, .pNext = nullptr,
.flags = 0, .flags = 0,
.imageType = VK_IMAGE_TYPE_2D, .imageType = VK_IMAGE_TYPE_2D,
.format = used_on_framebuffer ? VK_FORMAT_R16G16B16A16_SFLOAT : GetFormat(framebuffer), .format = used_on_framebuffer ? VK_FORMAT_R16G16B16A16_SFLOAT : framebuffer_view_format,
.extent = .extent =
{ {
.width = (up_scale * framebuffer.width) >> down_shift, .width = (up_scale * framebuffer.width) >> down_shift,
@ -1174,7 +1168,7 @@ void BlitScreen::CreateRawImages(const Tegra::FramebufferConfig& framebuffer) {
.flags = 0, .flags = 0,
.image = *image, .image = *image,
.viewType = VK_IMAGE_VIEW_TYPE_2D, .viewType = VK_IMAGE_VIEW_TYPE_2D,
.format = used_on_framebuffer ? VK_FORMAT_R16G16B16A16_SFLOAT : GetFormat(framebuffer), .format = used_on_framebuffer ? VK_FORMAT_R16G16B16A16_SFLOAT : framebuffer_view_format,
.components = .components =
{ {
.r = VK_COMPONENT_SWIZZLE_IDENTITY, .r = VK_COMPONENT_SWIZZLE_IDENTITY,

View File

@ -52,7 +52,6 @@ struct ScreenInfo {
VkImageView image_view{}; VkImageView image_view{};
u32 width{}; u32 width{};
u32 height{}; u32 height{};
bool is_srgb{};
}; };
class BlitScreen { class BlitScreen {
@ -69,7 +68,7 @@ public:
const Layout::FramebufferLayout layout, VkExtent2D render_area, bool use_accelerated); const Layout::FramebufferLayout layout, VkExtent2D render_area, bool use_accelerated);
void DrawToSwapchain(Frame* frame, const Tegra::FramebufferConfig& framebuffer, void DrawToSwapchain(Frame* frame, const Tegra::FramebufferConfig& framebuffer,
bool use_accelerated, bool is_srgb); bool use_accelerated);
[[nodiscard]] vk::Framebuffer CreateFramebuffer(const VkImageView& image_view, [[nodiscard]] vk::Framebuffer CreateFramebuffer(const VkImageView& image_view,
VkExtent2D extent); VkExtent2D extent);
@ -161,8 +160,8 @@ private:
u32 raw_width = 0; u32 raw_width = 0;
u32 raw_height = 0; u32 raw_height = 0;
Service::android::PixelFormat pixel_format{}; Service::android::PixelFormat pixel_format{};
bool current_srgb; VkFormat framebuffer_view_format;
VkFormat image_view_format; VkFormat swapchain_view_format;
std::unique_ptr<FSR> fsr; std::unique_ptr<FSR> fsr;
std::unique_ptr<SMAA> smaa; std::unique_ptr<SMAA> smaa;

View File

@ -172,13 +172,12 @@ void PresentManager::Present(Frame* frame) {
}); });
} }
void PresentManager::RecreateFrame(Frame* frame, u32 width, u32 height, bool is_srgb, void PresentManager::RecreateFrame(Frame* frame, u32 width, u32 height, VkFormat image_view_format,
VkFormat image_view_format, VkRenderPass rd) { VkRenderPass rd) {
auto& dld = device.GetLogical(); auto& dld = device.GetLogical();
frame->width = width; frame->width = width;
frame->height = height; frame->height = height;
frame->is_srgb = is_srgb;
frame->image = memory_allocator.CreateImage({ frame->image = memory_allocator.CreateImage({
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
@ -289,7 +288,7 @@ void PresentManager::PresentThread(std::stop_token token) {
} }
void PresentManager::RecreateSwapchain(Frame* frame) { void PresentManager::RecreateSwapchain(Frame* frame) {
swapchain.Create(*surface, frame->width, frame->height, frame->is_srgb); swapchain.Create(*surface, frame->width, frame->height);
image_count = swapchain.GetImageCount(); image_count = swapchain.GetImageCount();
} }
@ -319,12 +318,12 @@ void PresentManager::CopyToSwapchain(Frame* frame) {
void PresentManager::CopyToSwapchainImpl(Frame* frame) { void PresentManager::CopyToSwapchainImpl(Frame* frame) {
MICROPROFILE_SCOPE(Vulkan_CopyToSwapchain); MICROPROFILE_SCOPE(Vulkan_CopyToSwapchain);
// If the size or colorspace of the incoming frames has changed, recreate the swapchain // If the size of the incoming frames has changed, recreate the swapchain
// to account for that. // to account for that.
const bool srgb_changed = swapchain.NeedsRecreation(frame->is_srgb); const bool is_suboptimal = swapchain.NeedsRecreation();
const bool size_changed = const bool size_changed =
swapchain.GetWidth() != frame->width || swapchain.GetHeight() != frame->height; swapchain.GetWidth() != frame->width || swapchain.GetHeight() != frame->height;
if (srgb_changed || size_changed) { if (is_suboptimal || size_changed) {
RecreateSwapchain(frame); RecreateSwapchain(frame);
} }

View File

@ -25,7 +25,6 @@ class Swapchain;
struct Frame { struct Frame {
u32 width; u32 width;
u32 height; u32 height;
bool is_srgb;
vk::Image image; vk::Image image;
vk::ImageView image_view; vk::ImageView image_view;
vk::Framebuffer framebuffer; vk::Framebuffer framebuffer;
@ -48,8 +47,8 @@ public:
void Present(Frame* frame); void Present(Frame* frame);
/// Recreates the present frame to match the provided parameters /// Recreates the present frame to match the provided parameters
void RecreateFrame(Frame* frame, u32 width, u32 height, bool is_srgb, void RecreateFrame(Frame* frame, u32 width, u32 height, VkFormat image_view_format,
VkFormat image_view_format, VkRenderPass rd); VkRenderPass rd);
/// Waits for the present thread to finish presenting all queued frames. /// Waits for the present thread to finish presenting all queued frames.
void WaitPresent(); void WaitPresent();

View File

@ -783,7 +783,8 @@ bool RasterizerVulkan::AccelerateDisplay(const Tegra::FramebufferConfig& config,
return false; return false;
} }
std::scoped_lock lock{texture_cache.mutex}; std::scoped_lock lock{texture_cache.mutex};
ImageView* const image_view = texture_cache.TryFindFramebufferImageView(framebuffer_addr); ImageView* const image_view =
texture_cache.TryFindFramebufferImageView(config, framebuffer_addr);
if (!image_view) { if (!image_view) {
return false; return false;
} }
@ -792,7 +793,6 @@ bool RasterizerVulkan::AccelerateDisplay(const Tegra::FramebufferConfig& config,
screen_info.image_view = image_view->Handle(Shader::TextureType::Color2D); screen_info.image_view = image_view->Handle(Shader::TextureType::Color2D);
screen_info.width = image_view->size.width; screen_info.width = image_view->size.width;
screen_info.height = image_view->size.height; screen_info.height = image_view->size.height;
screen_info.is_srgb = VideoCore::Surface::IsPixelFormatSRGB(image_view->format);
return true; return true;
} }

View File

@ -105,14 +105,14 @@ VkCompositeAlphaFlagBitsKHR ChooseAlphaFlags(const VkSurfaceCapabilitiesKHR& cap
} // Anonymous namespace } // Anonymous namespace
Swapchain::Swapchain(VkSurfaceKHR surface_, const Device& device_, Scheduler& scheduler_, Swapchain::Swapchain(VkSurfaceKHR surface_, const Device& device_, Scheduler& scheduler_,
u32 width_, u32 height_, bool srgb) u32 width_, u32 height_)
: surface{surface_}, device{device_}, scheduler{scheduler_} { : surface{surface_}, device{device_}, scheduler{scheduler_} {
Create(surface_, width_, height_, srgb); Create(surface_, width_, height_);
} }
Swapchain::~Swapchain() = default; Swapchain::~Swapchain() = default;
void Swapchain::Create(VkSurfaceKHR surface_, u32 width_, u32 height_, bool srgb) { void Swapchain::Create(VkSurfaceKHR surface_, u32 width_, u32 height_) {
is_outdated = false; is_outdated = false;
is_suboptimal = false; is_suboptimal = false;
width = width_; width = width_;
@ -127,7 +127,7 @@ void Swapchain::Create(VkSurfaceKHR surface_, u32 width_, u32 height_, bool srgb
Destroy(); Destroy();
CreateSwapchain(capabilities, srgb); CreateSwapchain(capabilities);
CreateSemaphores(); CreateSemaphores();
resource_ticks.clear(); resource_ticks.clear();
@ -196,7 +196,7 @@ void Swapchain::Present(VkSemaphore render_semaphore) {
} }
} }
void Swapchain::CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities, bool srgb) { void Swapchain::CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities) {
const auto physical_device{device.GetPhysical()}; const auto physical_device{device.GetPhysical()};
const auto formats{physical_device.GetSurfaceFormatsKHR(surface)}; const auto formats{physical_device.GetSurfaceFormatsKHR(surface)};
const auto present_modes = physical_device.GetSurfacePresentModesKHR(surface); const auto present_modes = physical_device.GetSurfacePresentModesKHR(surface);
@ -274,15 +274,14 @@ void Swapchain::CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities, bo
swapchain = device.GetLogical().CreateSwapchainKHR(swapchain_ci); swapchain = device.GetLogical().CreateSwapchainKHR(swapchain_ci);
extent = swapchain_ci.imageExtent; extent = swapchain_ci.imageExtent;
current_srgb = srgb;
images = swapchain.GetImages(); images = swapchain.GetImages();
image_count = static_cast<u32>(images.size()); image_count = static_cast<u32>(images.size());
#ifdef ANDROID #ifdef ANDROID
// Android is already ordered the same as Switch. // Android is already ordered the same as Switch.
image_view_format = srgb ? VK_FORMAT_R8G8B8A8_SRGB : VK_FORMAT_R8G8B8A8_UNORM; image_view_format = VK_FORMAT_R8G8B8A8_UNORM;
#else #else
image_view_format = srgb ? VK_FORMAT_B8G8R8A8_SRGB : VK_FORMAT_B8G8R8A8_UNORM; image_view_format = VK_FORMAT_B8G8R8A8_UNORM;
#endif #endif
} }

View File

@ -20,11 +20,11 @@ class Scheduler;
class Swapchain { class Swapchain {
public: public:
explicit Swapchain(VkSurfaceKHR surface, const Device& device, Scheduler& scheduler, u32 width, explicit Swapchain(VkSurfaceKHR surface, const Device& device, Scheduler& scheduler, u32 width,
u32 height, bool srgb); u32 height);
~Swapchain(); ~Swapchain();
/// Creates (or recreates) the swapchain with a given size. /// Creates (or recreates) the swapchain with a given size.
void Create(VkSurfaceKHR surface, u32 width, u32 height, bool srgb); void Create(VkSurfaceKHR surface, u32 width, u32 height);
/// Acquires the next image in the swapchain, waits as needed. /// Acquires the next image in the swapchain, waits as needed.
bool AcquireNextImage(); bool AcquireNextImage();
@ -33,13 +33,8 @@ public:
void Present(VkSemaphore render_semaphore); void Present(VkSemaphore render_semaphore);
/// Returns true when the swapchain needs to be recreated. /// Returns true when the swapchain needs to be recreated.
bool NeedsRecreation(bool is_srgb) const { bool NeedsRecreation() const {
return HasColorSpaceChanged(is_srgb) || IsSubOptimal() || NeedsPresentModeUpdate(); return IsSubOptimal() || NeedsPresentModeUpdate();
}
/// Returns true when the color space has changed.
bool HasColorSpaceChanged(bool is_srgb) const {
return current_srgb != is_srgb;
} }
/// Returns true when the swapchain is outdated. /// Returns true when the swapchain is outdated.
@ -52,11 +47,6 @@ public:
return is_suboptimal; return is_suboptimal;
} }
/// Returns true when the swapchain format is in the srgb color space
bool IsSrgb() const {
return current_srgb;
}
VkExtent2D GetSize() const { VkExtent2D GetSize() const {
return extent; return extent;
} }
@ -110,7 +100,7 @@ public:
} }
private: private:
void CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities, bool srgb); void CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities);
void CreateSemaphores(); void CreateSemaphores();
void CreateImageViews(); void CreateImageViews();
@ -144,7 +134,6 @@ private:
bool has_mailbox{false}; bool has_mailbox{false};
bool has_fifo_relaxed{false}; bool has_fifo_relaxed{false};
bool current_srgb{};
bool is_outdated{}; bool is_outdated{};
bool is_suboptimal{}; bool is_suboptimal{};
}; };

View File

@ -712,14 +712,15 @@ bool TextureCache<P>::BlitImage(const Tegra::Engines::Fermi2D::Surface& dst,
} }
template <class P> template <class P>
typename P::ImageView* TextureCache<P>::TryFindFramebufferImageView(VAddr cpu_addr) { typename P::ImageView* TextureCache<P>::TryFindFramebufferImageView(
const Tegra::FramebufferConfig& config, VAddr cpu_addr) {
// TODO: Properly implement this // TODO: Properly implement this
const auto it = page_table.find(cpu_addr >> YUZU_PAGEBITS); const auto it = page_table.find(cpu_addr >> YUZU_PAGEBITS);
if (it == page_table.end()) { if (it == page_table.end()) {
return nullptr; return nullptr;
} }
const auto& image_map_ids = it->second; const auto& image_map_ids = it->second;
boost::container::small_vector<const ImageBase*, 4> valid_images; boost::container::small_vector<ImageId, 4> valid_image_ids;
for (const ImageMapId map_id : image_map_ids) { for (const ImageMapId map_id : image_map_ids) {
const ImageMapView& map = slot_map_views[map_id]; const ImageMapView& map = slot_map_views[map_id];
const ImageBase& image = slot_images[map.image_id]; const ImageBase& image = slot_images[map.image_id];
@ -729,18 +730,34 @@ typename P::ImageView* TextureCache<P>::TryFindFramebufferImageView(VAddr cpu_ad
if (image.image_view_ids.empty()) { if (image.image_view_ids.empty()) {
continue; continue;
} }
valid_images.push_back(&image); valid_image_ids.push_back(map.image_id);
} }
if (valid_images.size() == 1) [[likely]] { const auto view_format = [&]() {
return &slot_image_views[valid_images[0]->image_view_ids.at(0)]; 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]] { if (valid_image_ids.size() > 0) [[unlikely]] {
std::ranges::sort(valid_images, [](const auto* a, const auto* b) { auto most_recent = std::ranges::max_element(valid_image_ids, [&](auto a, auto b) {
return a->modification_tick > b->modification_tick; 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; return nullptr;

View File

@ -209,7 +209,8 @@ public:
const Tegra::Engines::Fermi2D::Config& copy); const Tegra::Engines::Fermi2D::Config& copy);
/// Try to find a cached image view in the given CPU address /// 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 /// Return true when there are uncommitted images to be downloaded
[[nodiscard]] bool HasUncommittedFlushes() const noexcept; [[nodiscard]] bool HasUncommittedFlushes() const noexcept;