Compare commits
27 Commits
android-15
...
android-15
Author | SHA1 | Date | |
---|---|---|---|
a951a29f8d | |||
875568bb3e | |||
988e557ec8 | |||
6d2af32f29 | |||
8f9d5c3143 | |||
dc0fb56f3a | |||
8ef1fdafa2 | |||
c1924951ad | |||
5646e313a0 | |||
f447996080 | |||
42b34a0dc5 | |||
fe5e4bd846 | |||
a53cd2854e | |||
8225ac004e | |||
52e6b8a2d3 | |||
13131e602f | |||
7761f29892 | |||
e92b10f971 | |||
9268f265a1 | |||
e445ef9d60 | |||
40bb176c39 | |||
4cd3f9f4f9 | |||
6b7dc587cf | |||
f05cb69d4f | |||
382cf087a0 | |||
0751488727 | |||
4bc932261b |
@ -1,3 +1,11 @@
|
|||||||
|
| Pull Request | Commit | Title | Author | Merged? |
|
||||||
|
|----|----|----|----|----|
|
||||||
|
|
||||||
|
|
||||||
|
End of merge log. You can find the original README.md below the break.
|
||||||
|
|
||||||
|
-----
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
SPDX-FileCopyrightText: 2018 yuzu Emulator Project
|
SPDX-FileCopyrightText: 2018 yuzu Emulator Project
|
||||||
SPDX-License-Identifier: GPL-2.0-or-later
|
SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
19
dist/72-yuzu-input.rules
vendored
Normal file
19
dist/72-yuzu-input.rules
vendored
Normal 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"
|
@ -14,8 +14,10 @@ import org.yuzu.yuzu_emu.R
|
|||||||
import org.yuzu.yuzu_emu.databinding.DialogAddFolderBinding
|
import org.yuzu.yuzu_emu.databinding.DialogAddFolderBinding
|
||||||
import org.yuzu.yuzu_emu.model.GameDir
|
import org.yuzu.yuzu_emu.model.GameDir
|
||||||
import org.yuzu.yuzu_emu.model.GamesViewModel
|
import org.yuzu.yuzu_emu.model.GamesViewModel
|
||||||
|
import org.yuzu.yuzu_emu.model.HomeViewModel
|
||||||
|
|
||||||
class AddGameFolderDialogFragment : DialogFragment() {
|
class AddGameFolderDialogFragment : DialogFragment() {
|
||||||
|
private val homeViewModel: HomeViewModel by activityViewModels()
|
||||||
private val gamesViewModel: GamesViewModel by activityViewModels()
|
private val gamesViewModel: GamesViewModel by activityViewModels()
|
||||||
|
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
@ -30,6 +32,7 @@ class AddGameFolderDialogFragment : DialogFragment() {
|
|||||||
.setTitle(R.string.add_game_folder)
|
.setTitle(R.string.add_game_folder)
|
||||||
.setPositiveButton(android.R.string.ok) { _: DialogInterface, _: Int ->
|
.setPositiveButton(android.R.string.ok) { _: DialogInterface, _: Int ->
|
||||||
val newGameDir = GameDir(folderUriString!!, binding.deepScanSwitch.isChecked)
|
val newGameDir = GameDir(folderUriString!!, binding.deepScanSwitch.isChecked)
|
||||||
|
homeViewModel.setGamesDirSelected(true)
|
||||||
gamesViewModel.addFolder(newGameDir)
|
gamesViewModel.addFolder(newGameDir)
|
||||||
}
|
}
|
||||||
.setNegativeButton(android.R.string.cancel, null)
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
package org.yuzu.yuzu_emu.fragments
|
package org.yuzu.yuzu_emu.fragments
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@ -75,6 +76,8 @@ class SetupFragment : Fragment() {
|
|||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is using the correct scope, lint is just acting up
|
||||||
|
@SuppressLint("UnsafeRepeatOnLifecycleDetector")
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
mainActivity = requireActivity() as MainActivity
|
mainActivity = requireActivity() as MainActivity
|
||||||
|
|
||||||
@ -206,7 +209,8 @@ class SetupFragment : Fragment() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
viewLifecycleOwner.lifecycleScope.launch {
|
viewLifecycleOwner.lifecycleScope.apply {
|
||||||
|
launch {
|
||||||
repeatOnLifecycle(Lifecycle.State.CREATED) {
|
repeatOnLifecycle(Lifecycle.State.CREATED) {
|
||||||
homeViewModel.shouldPageForward.collect {
|
homeViewModel.shouldPageForward.collect {
|
||||||
if (it) {
|
if (it) {
|
||||||
@ -216,6 +220,17 @@ class SetupFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
launch {
|
||||||
|
repeatOnLifecycle(Lifecycle.State.CREATED) {
|
||||||
|
homeViewModel.gamesDirSelected.collect {
|
||||||
|
if (it) {
|
||||||
|
gamesDirCallback.onStepCompleted()
|
||||||
|
homeViewModel.setGamesDirSelected(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
binding.viewPager2.apply {
|
binding.viewPager2.apply {
|
||||||
adapter = SetupAdapter(requireActivity() as AppCompatActivity, pages)
|
adapter = SetupAdapter(requireActivity() as AppCompatActivity, pages)
|
||||||
@ -339,7 +354,6 @@ class SetupFragment : Fragment() {
|
|||||||
registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { result ->
|
registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { result ->
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
mainActivity.processGamesDir(result)
|
mainActivity.processGamesDir(result)
|
||||||
gamesDirCallback.onStepCompleted()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ class GamesViewModel : ViewModel() {
|
|||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
NativeConfig.addGameDir(gameDir)
|
NativeConfig.addGameDir(gameDir)
|
||||||
getGameDirs()
|
getGameDirs(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ package org.yuzu.yuzu_emu.model
|
|||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
|
||||||
class HomeViewModel : ViewModel() {
|
class HomeViewModel : ViewModel() {
|
||||||
val navigationVisible: StateFlow<Pair<Boolean, Boolean>> get() = _navigationVisible
|
val navigationVisible: StateFlow<Pair<Boolean, Boolean>> get() = _navigationVisible
|
||||||
@ -17,6 +18,9 @@ class HomeViewModel : ViewModel() {
|
|||||||
val shouldPageForward: StateFlow<Boolean> get() = _shouldPageForward
|
val shouldPageForward: StateFlow<Boolean> get() = _shouldPageForward
|
||||||
private val _shouldPageForward = MutableStateFlow(false)
|
private val _shouldPageForward = MutableStateFlow(false)
|
||||||
|
|
||||||
|
private val _gamesDirSelected = MutableStateFlow(false)
|
||||||
|
val gamesDirSelected get() = _gamesDirSelected.asStateFlow()
|
||||||
|
|
||||||
var navigatedToSetup = false
|
var navigatedToSetup = false
|
||||||
|
|
||||||
fun setNavigationVisibility(visible: Boolean, animated: Boolean) {
|
fun setNavigationVisibility(visible: Boolean, animated: Boolean) {
|
||||||
@ -36,4 +40,8 @@ class HomeViewModel : ViewModel() {
|
|||||||
fun setShouldPageForward(pageForward: Boolean) {
|
fun setShouldPageForward(pageForward: Boolean) {
|
||||||
_shouldPageForward.value = pageForward
|
_shouldPageForward.value = pageForward
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setGamesDirSelected(selected: Boolean) {
|
||||||
|
_gamesDirSelected.value = selected
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,12 +160,16 @@ static bool is_nce_enabled = false;
|
|||||||
|
|
||||||
void SetNceEnabled(bool is_39bit) {
|
void SetNceEnabled(bool is_39bit) {
|
||||||
const bool is_nce_selected = values.cpu_backend.GetValue() == CpuBackend::Nce;
|
const bool is_nce_selected = values.cpu_backend.GetValue() == CpuBackend::Nce;
|
||||||
is_nce_enabled = IsFastmemEnabled() && is_nce_selected && is_39bit;
|
if (is_nce_selected && !IsFastmemEnabled()) {
|
||||||
if (is_nce_selected && !is_nce_enabled) {
|
LOG_WARNING(Common, "Fastmem is required to natively execute code in a performant manner, "
|
||||||
|
"falling back to Dynarmic");
|
||||||
|
}
|
||||||
|
if (is_nce_selected && !is_39bit) {
|
||||||
LOG_WARNING(
|
LOG_WARNING(
|
||||||
Common,
|
Common,
|
||||||
"Program does not utilize 39-bit address space, unable to natively execute code");
|
"Program does not utilize 39-bit address space, unable to natively execute code");
|
||||||
}
|
}
|
||||||
|
is_nce_enabled = IsFastmemEnabled() && is_nce_selected && is_39bit;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsNceEnabled() {
|
bool IsNceEnabled() {
|
||||||
|
@ -180,14 +180,20 @@ struct Values {
|
|||||||
&use_speed_limit};
|
&use_speed_limit};
|
||||||
|
|
||||||
// Cpu
|
// Cpu
|
||||||
SwitchableSetting<CpuBackend, true> cpu_backend{
|
SwitchableSetting<CpuBackend, true> cpu_backend{linkage,
|
||||||
linkage, CpuBackend::Dynarmic, CpuBackend::Dynarmic,
|
|
||||||
#ifdef HAS_NCE
|
#ifdef HAS_NCE
|
||||||
CpuBackend::Nce,
|
CpuBackend::Nce,
|
||||||
#else
|
#else
|
||||||
CpuBackend::Dynarmic,
|
CpuBackend::Dynarmic,
|
||||||
#endif
|
#endif
|
||||||
"cpu_backend", Category::Cpu};
|
CpuBackend::Dynarmic,
|
||||||
|
#ifdef HAS_NCE
|
||||||
|
CpuBackend::Nce,
|
||||||
|
#else
|
||||||
|
CpuBackend::Dynarmic,
|
||||||
|
#endif
|
||||||
|
"cpu_backend",
|
||||||
|
Category::Cpu};
|
||||||
SwitchableSetting<CpuAccuracy, true> cpu_accuracy{linkage, CpuAccuracy::Auto,
|
SwitchableSetting<CpuAccuracy, true> cpu_accuracy{linkage, CpuAccuracy::Auto,
|
||||||
CpuAccuracy::Auto, CpuAccuracy::Paranoid,
|
CpuAccuracy::Auto, CpuAccuracy::Paranoid,
|
||||||
"cpu_accuracy", Category::Cpu};
|
"cpu_accuracy", Category::Cpu};
|
||||||
|
@ -251,10 +251,16 @@ add_library(core STATIC
|
|||||||
hle/kernel/k_hardware_timer.h
|
hle/kernel/k_hardware_timer.h
|
||||||
hle/kernel/k_interrupt_manager.cpp
|
hle/kernel/k_interrupt_manager.cpp
|
||||||
hle/kernel/k_interrupt_manager.h
|
hle/kernel/k_interrupt_manager.h
|
||||||
|
hle/kernel/k_light_client_session.cpp
|
||||||
|
hle/kernel/k_light_client_session.h
|
||||||
hle/kernel/k_light_condition_variable.cpp
|
hle/kernel/k_light_condition_variable.cpp
|
||||||
hle/kernel/k_light_condition_variable.h
|
hle/kernel/k_light_condition_variable.h
|
||||||
hle/kernel/k_light_lock.cpp
|
hle/kernel/k_light_lock.cpp
|
||||||
hle/kernel/k_light_lock.h
|
hle/kernel/k_light_lock.h
|
||||||
|
hle/kernel/k_light_server_session.cpp
|
||||||
|
hle/kernel/k_light_server_session.h
|
||||||
|
hle/kernel/k_light_session.cpp
|
||||||
|
hle/kernel/k_light_session.h
|
||||||
hle/kernel/k_memory_block.h
|
hle/kernel/k_memory_block.h
|
||||||
hle/kernel/k_memory_block_manager.cpp
|
hle/kernel/k_memory_block_manager.cpp
|
||||||
hle/kernel/k_memory_block_manager.h
|
hle/kernel/k_memory_block_manager.h
|
||||||
@ -543,6 +549,8 @@ add_library(core STATIC
|
|||||||
hle/service/hid/xcd.cpp
|
hle/service/hid/xcd.cpp
|
||||||
hle/service/hid/xcd.h
|
hle/service/hid/xcd.h
|
||||||
hle/service/hid/errors.h
|
hle/service/hid/errors.h
|
||||||
|
hle/service/hid/controllers/applet_resource.cpp
|
||||||
|
hle/service/hid/controllers/applet_resource.h
|
||||||
hle/service/hid/controllers/console_six_axis.cpp
|
hle/service/hid/controllers/console_six_axis.cpp
|
||||||
hle/service/hid/controllers/console_six_axis.h
|
hle/service/hid/controllers/console_six_axis.h
|
||||||
hle/service/hid/controllers/controller_base.cpp
|
hle/service/hid/controllers/controller_base.cpp
|
||||||
|
@ -282,6 +282,8 @@ Loader::AppLoader::Modules FindModules(const Kernel::KProcess* process) {
|
|||||||
|
|
||||||
// Ignore leading directories.
|
// Ignore leading directories.
|
||||||
char* path_pointer = module_path.path.data();
|
char* path_pointer = module_path.path.data();
|
||||||
|
char* path_end =
|
||||||
|
path_pointer + std::min(PathLengthMax, module_path.path_length);
|
||||||
|
|
||||||
for (s32 i = 0; i < std::min(PathLengthMax, module_path.path_length) &&
|
for (s32 i = 0; i < std::min(PathLengthMax, module_path.path_length) &&
|
||||||
module_path.path[i] != '\0';
|
module_path.path[i] != '\0';
|
||||||
@ -292,7 +294,8 @@ Loader::AppLoader::Modules FindModules(const Kernel::KProcess* process) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Insert output.
|
// Insert output.
|
||||||
modules.emplace(svc_mem_info.base_address, path_pointer);
|
modules.emplace(svc_mem_info.base_address,
|
||||||
|
std::string_view(path_pointer, path_end));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -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);
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "common/scope_exit.h"
|
#include "common/scope_exit.h"
|
||||||
#include "core/hle/kernel/k_client_port.h"
|
#include "core/hle/kernel/k_client_port.h"
|
||||||
|
#include "core/hle/kernel/k_light_session.h"
|
||||||
#include "core/hle/kernel/k_port.h"
|
#include "core/hle/kernel/k_port.h"
|
||||||
#include "core/hle/kernel/k_scheduler.h"
|
#include "core/hle/kernel/k_scheduler.h"
|
||||||
#include "core/hle/kernel/k_scoped_resource_reservation.h"
|
#include "core/hle/kernel/k_scoped_resource_reservation.h"
|
||||||
@ -63,6 +64,7 @@ Result KClientPort::CreateSession(KClientSession** out) {
|
|||||||
R_UNLESS(session_reservation.Succeeded(), ResultLimitReached);
|
R_UNLESS(session_reservation.Succeeded(), ResultLimitReached);
|
||||||
|
|
||||||
// Allocate a session normally.
|
// Allocate a session normally.
|
||||||
|
// TODO: Dynamic resource limits
|
||||||
session = KSession::Create(m_kernel);
|
session = KSession::Create(m_kernel);
|
||||||
|
|
||||||
// Check that we successfully created a session.
|
// Check that we successfully created a session.
|
||||||
@ -119,4 +121,71 @@ Result KClientPort::CreateSession(KClientSession** out) {
|
|||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result KClientPort::CreateLightSession(KLightClientSession** out) {
|
||||||
|
// Declare the session we're going to allocate.
|
||||||
|
KLightSession* session{};
|
||||||
|
|
||||||
|
// Reserve a new session from the resource limit.
|
||||||
|
KScopedResourceReservation session_reservation(GetCurrentProcessPointer(m_kernel),
|
||||||
|
Svc::LimitableResource::SessionCountMax);
|
||||||
|
R_UNLESS(session_reservation.Succeeded(), ResultLimitReached);
|
||||||
|
|
||||||
|
// Allocate a session normally.
|
||||||
|
// TODO: Dynamic resource limits
|
||||||
|
session = KLightSession::Create(m_kernel);
|
||||||
|
|
||||||
|
// Check that we successfully created a session.
|
||||||
|
R_UNLESS(session != nullptr, ResultOutOfResource);
|
||||||
|
|
||||||
|
// Update the session counts.
|
||||||
|
{
|
||||||
|
ON_RESULT_FAILURE {
|
||||||
|
session->Close();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Atomically increment the number of sessions.
|
||||||
|
s32 new_sessions;
|
||||||
|
{
|
||||||
|
const auto max = m_max_sessions;
|
||||||
|
auto cur_sessions = m_num_sessions.load(std::memory_order_acquire);
|
||||||
|
do {
|
||||||
|
R_UNLESS(cur_sessions < max, ResultOutOfSessions);
|
||||||
|
new_sessions = cur_sessions + 1;
|
||||||
|
} while (!m_num_sessions.compare_exchange_weak(cur_sessions, new_sessions,
|
||||||
|
std::memory_order_relaxed));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Atomically update the peak session tracking.
|
||||||
|
{
|
||||||
|
auto peak = m_peak_sessions.load(std::memory_order_acquire);
|
||||||
|
do {
|
||||||
|
if (peak >= new_sessions) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (!m_peak_sessions.compare_exchange_weak(peak, new_sessions,
|
||||||
|
std::memory_order_relaxed));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize the session.
|
||||||
|
session->Initialize(this, m_parent->GetName());
|
||||||
|
|
||||||
|
// Commit the session reservation.
|
||||||
|
session_reservation.Commit();
|
||||||
|
|
||||||
|
// Register the session.
|
||||||
|
KLightSession::Register(m_kernel, session);
|
||||||
|
ON_RESULT_FAILURE {
|
||||||
|
session->GetClientSession().Close();
|
||||||
|
session->GetServerSession().Close();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Enqueue the session with our parent.
|
||||||
|
R_TRY(m_parent->EnqueueSession(std::addressof(session->GetServerSession())));
|
||||||
|
|
||||||
|
// We succeeded, so set the output.
|
||||||
|
*out = std::addressof(session->GetClientSession());
|
||||||
|
R_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
|
class KLightClientSession;
|
||||||
class KClientSession;
|
class KClientSession;
|
||||||
class KernelCore;
|
class KernelCore;
|
||||||
class KPort;
|
class KPort;
|
||||||
@ -51,6 +52,7 @@ public:
|
|||||||
bool IsSignaled() const override;
|
bool IsSignaled() const override;
|
||||||
|
|
||||||
Result CreateSession(KClientSession** out);
|
Result CreateSession(KClientSession** out);
|
||||||
|
Result CreateLightSession(KLightClientSession** out);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::atomic<s32> m_num_sessions{};
|
std::atomic<s32> m_num_sessions{};
|
||||||
|
@ -10,9 +10,7 @@
|
|||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
static constexpr u32 MessageBufferSize = 0x100;
|
KClientSession::KClientSession(KernelCore& kernel) : KAutoObject{kernel} {}
|
||||||
|
|
||||||
KClientSession::KClientSession(KernelCore& kernel) : KAutoObjectWithSlabHeapAndContainer{kernel} {}
|
|
||||||
KClientSession::~KClientSession() = default;
|
KClientSession::~KClientSession() = default;
|
||||||
|
|
||||||
void KClientSession::Destroy() {
|
void KClientSession::Destroy() {
|
||||||
@ -22,18 +20,30 @@ void KClientSession::Destroy() {
|
|||||||
|
|
||||||
void KClientSession::OnServerClosed() {}
|
void KClientSession::OnServerClosed() {}
|
||||||
|
|
||||||
Result KClientSession::SendSyncRequest() {
|
Result KClientSession::SendSyncRequest(uintptr_t address, size_t size) {
|
||||||
// Create a session request.
|
// Create a session request.
|
||||||
KSessionRequest* request = KSessionRequest::Create(m_kernel);
|
KSessionRequest* request = KSessionRequest::Create(m_kernel);
|
||||||
R_UNLESS(request != nullptr, ResultOutOfResource);
|
R_UNLESS(request != nullptr, ResultOutOfResource);
|
||||||
SCOPE_EXIT({ request->Close(); });
|
SCOPE_EXIT({ request->Close(); });
|
||||||
|
|
||||||
// Initialize the request.
|
// Initialize the request.
|
||||||
request->Initialize(nullptr, GetInteger(GetCurrentThread(m_kernel).GetTlsAddress()),
|
request->Initialize(nullptr, address, size);
|
||||||
MessageBufferSize);
|
|
||||||
|
|
||||||
// Send the request.
|
// Send the request.
|
||||||
R_RETURN(m_parent->GetServerSession().OnRequest(request));
|
R_RETURN(m_parent->OnRequest(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
Result KClientSession::SendAsyncRequest(KEvent* event, uintptr_t address, size_t size) {
|
||||||
|
// Create a session request.
|
||||||
|
KSessionRequest* request = KSessionRequest::Create(m_kernel);
|
||||||
|
R_UNLESS(request != nullptr, ResultOutOfResource);
|
||||||
|
SCOPE_EXIT({ request->Close(); });
|
||||||
|
|
||||||
|
// Initialize the request.
|
||||||
|
request->Initialize(event, address, size);
|
||||||
|
|
||||||
|
// Send the request.
|
||||||
|
R_RETURN(m_parent->OnRequest(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
@ -9,24 +9,12 @@
|
|||||||
#include "core/hle/kernel/slab_helpers.h"
|
#include "core/hle/kernel/slab_helpers.h"
|
||||||
#include "core/hle/result.h"
|
#include "core/hle/result.h"
|
||||||
|
|
||||||
union Result;
|
|
||||||
|
|
||||||
namespace Core::Memory {
|
|
||||||
class Memory;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Core::Timing {
|
|
||||||
class CoreTiming;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
class KernelCore;
|
class KernelCore;
|
||||||
class KSession;
|
class KSession;
|
||||||
class KThread;
|
|
||||||
|
|
||||||
class KClientSession final
|
class KClientSession final : public KAutoObject {
|
||||||
: public KAutoObjectWithSlabHeapAndContainer<KClientSession, KAutoObjectWithList> {
|
|
||||||
KERNEL_AUTOOBJECT_TRAITS(KClientSession, KAutoObject);
|
KERNEL_AUTOOBJECT_TRAITS(KClientSession, KAutoObject);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -39,13 +27,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Destroy() override;
|
void Destroy() override;
|
||||||
static void PostDestroy(uintptr_t arg) {}
|
|
||||||
|
|
||||||
KSession* GetParent() const {
|
KSession* GetParent() const {
|
||||||
return m_parent;
|
return m_parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result SendSyncRequest();
|
Result SendSyncRequest(uintptr_t address, size_t size);
|
||||||
|
Result SendAsyncRequest(KEvent* event, uintptr_t address, size_t size);
|
||||||
|
|
||||||
void OnServerClosed();
|
void OnServerClosed();
|
||||||
|
|
||||||
|
31
src/core/hle/kernel/k_light_client_session.cpp
Normal file
31
src/core/hle/kernel/k_light_client_session.cpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include "core/hle/kernel/k_light_client_session.h"
|
||||||
|
#include "core/hle/kernel/k_light_session.h"
|
||||||
|
#include "core/hle/kernel/k_thread.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
|
||||||
|
KLightClientSession::KLightClientSession(KernelCore& kernel) : KAutoObject(kernel) {}
|
||||||
|
|
||||||
|
KLightClientSession::~KLightClientSession() = default;
|
||||||
|
|
||||||
|
void KLightClientSession::Destroy() {
|
||||||
|
m_parent->OnClientClosed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void KLightClientSession::OnServerClosed() {}
|
||||||
|
|
||||||
|
Result KLightClientSession::SendSyncRequest(u32* data) {
|
||||||
|
// Get the request thread.
|
||||||
|
KThread* cur_thread = GetCurrentThreadPointer(m_kernel);
|
||||||
|
|
||||||
|
// Set the light data.
|
||||||
|
cur_thread->SetLightSessionData(data);
|
||||||
|
|
||||||
|
// Send the request.
|
||||||
|
R_RETURN(m_parent->OnRequest(cur_thread));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Kernel
|
39
src/core/hle/kernel/k_light_client_session.h
Normal file
39
src/core/hle/kernel/k_light_client_session.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "core/hle/kernel/k_auto_object.h"
|
||||||
|
#include "core/hle/result.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
|
||||||
|
class KLightSession;
|
||||||
|
|
||||||
|
class KLightClientSession final : public KAutoObject {
|
||||||
|
KERNEL_AUTOOBJECT_TRAITS(KLightClientSession, KAutoObject);
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit KLightClientSession(KernelCore& kernel);
|
||||||
|
~KLightClientSession();
|
||||||
|
|
||||||
|
void Initialize(KLightSession* parent) {
|
||||||
|
// Set member variables.
|
||||||
|
m_parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void Destroy() override;
|
||||||
|
|
||||||
|
const KLightSession* GetParent() const {
|
||||||
|
return m_parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result SendSyncRequest(u32* data);
|
||||||
|
|
||||||
|
void OnServerClosed();
|
||||||
|
|
||||||
|
private:
|
||||||
|
KLightSession* m_parent;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Kernel
|
247
src/core/hle/kernel/k_light_server_session.cpp
Normal file
247
src/core/hle/kernel/k_light_server_session.cpp
Normal file
@ -0,0 +1,247 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include "core/hle/kernel/k_light_server_session.h"
|
||||||
|
#include "core/hle/kernel/k_light_session.h"
|
||||||
|
#include "core/hle/kernel/k_thread.h"
|
||||||
|
#include "core/hle/kernel/k_thread_queue.h"
|
||||||
|
#include "core/hle/kernel/svc_results.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
constexpr u64 InvalidThreadId = std::numeric_limits<u64>::max();
|
||||||
|
|
||||||
|
class ThreadQueueImplForKLightServerSessionRequest final : public KThreadQueue {
|
||||||
|
private:
|
||||||
|
KThread::WaiterList* m_wait_list;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ThreadQueueImplForKLightServerSessionRequest(KernelCore& kernel, KThread::WaiterList* wl)
|
||||||
|
: KThreadQueue(kernel), m_wait_list(wl) {}
|
||||||
|
|
||||||
|
virtual void EndWait(KThread* waiting_thread, Result wait_result) override {
|
||||||
|
// Remove the thread from our wait list.
|
||||||
|
m_wait_list->erase(m_wait_list->iterator_to(*waiting_thread));
|
||||||
|
|
||||||
|
// Invoke the base end wait handler.
|
||||||
|
KThreadQueue::EndWait(waiting_thread, wait_result);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void CancelWait(KThread* waiting_thread, Result wait_result,
|
||||||
|
bool cancel_timer_task) override {
|
||||||
|
// Remove the thread from our wait list.
|
||||||
|
m_wait_list->erase(m_wait_list->iterator_to(*waiting_thread));
|
||||||
|
|
||||||
|
// Invoke the base cancel wait handler.
|
||||||
|
KThreadQueue::CancelWait(waiting_thread, wait_result, cancel_timer_task);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class ThreadQueueImplForKLightServerSessionReceive final : public KThreadQueue {
|
||||||
|
private:
|
||||||
|
KThread** m_server_thread;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ThreadQueueImplForKLightServerSessionReceive(KernelCore& kernel, KThread** st)
|
||||||
|
: KThreadQueue(kernel), m_server_thread(st) {}
|
||||||
|
|
||||||
|
virtual void EndWait(KThread* waiting_thread, Result wait_result) override {
|
||||||
|
// Clear the server thread.
|
||||||
|
*m_server_thread = nullptr;
|
||||||
|
|
||||||
|
// Set the waiting thread as not cancelable.
|
||||||
|
waiting_thread->ClearCancellable();
|
||||||
|
|
||||||
|
// Invoke the base end wait handler.
|
||||||
|
KThreadQueue::EndWait(waiting_thread, wait_result);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void CancelWait(KThread* waiting_thread, Result wait_result,
|
||||||
|
bool cancel_timer_task) override {
|
||||||
|
// Clear the server thread.
|
||||||
|
*m_server_thread = nullptr;
|
||||||
|
|
||||||
|
// Set the waiting thread as not cancelable.
|
||||||
|
waiting_thread->ClearCancellable();
|
||||||
|
|
||||||
|
// Invoke the base cancel wait handler.
|
||||||
|
KThreadQueue::CancelWait(waiting_thread, wait_result, cancel_timer_task);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
KLightServerSession::KLightServerSession(KernelCore& kernel) : KAutoObject(kernel) {}
|
||||||
|
KLightServerSession::~KLightServerSession() = default;
|
||||||
|
|
||||||
|
void KLightServerSession::Destroy() {
|
||||||
|
this->CleanupRequests();
|
||||||
|
|
||||||
|
m_parent->OnServerClosed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void KLightServerSession::OnClientClosed() {
|
||||||
|
this->CleanupRequests();
|
||||||
|
}
|
||||||
|
|
||||||
|
Result KLightServerSession::OnRequest(KThread* request_thread) {
|
||||||
|
ThreadQueueImplForKLightServerSessionRequest wait_queue(m_kernel,
|
||||||
|
std::addressof(m_request_list));
|
||||||
|
|
||||||
|
// Send the request.
|
||||||
|
{
|
||||||
|
// Lock the scheduler.
|
||||||
|
KScopedSchedulerLock sl(m_kernel);
|
||||||
|
|
||||||
|
// Check that the server isn't closed.
|
||||||
|
R_UNLESS(!m_parent->IsServerClosed(), ResultSessionClosed);
|
||||||
|
|
||||||
|
// Check that the request thread isn't terminating.
|
||||||
|
R_UNLESS(!request_thread->IsTerminationRequested(), ResultTerminationRequested);
|
||||||
|
|
||||||
|
// Add the request thread to our list.
|
||||||
|
m_request_list.push_back(*request_thread);
|
||||||
|
|
||||||
|
// Begin waiting on the request.
|
||||||
|
request_thread->SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::IPC);
|
||||||
|
request_thread->BeginWait(std::addressof(wait_queue));
|
||||||
|
|
||||||
|
// If we have a server thread, end its wait.
|
||||||
|
if (m_server_thread != nullptr) {
|
||||||
|
m_server_thread->EndWait(ResultSuccess);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: Nintendo returns GetCurrentThread().GetWaitResult() here.
|
||||||
|
// This is technically incorrect, although it doesn't cause problems in practice
|
||||||
|
// because this is only ever called with request_thread = GetCurrentThreadPointer().
|
||||||
|
R_RETURN(request_thread->GetWaitResult());
|
||||||
|
}
|
||||||
|
|
||||||
|
Result KLightServerSession::ReplyAndReceive(u32* data) {
|
||||||
|
// Set the server context.
|
||||||
|
GetCurrentThread(m_kernel).SetLightSessionData(data);
|
||||||
|
|
||||||
|
// Reply, if we need to.
|
||||||
|
if (data[0] & KLightSession::ReplyFlag) {
|
||||||
|
KScopedSchedulerLock sl(m_kernel);
|
||||||
|
|
||||||
|
// Check that we're open.
|
||||||
|
R_UNLESS(!m_parent->IsClientClosed(), ResultSessionClosed);
|
||||||
|
R_UNLESS(!m_parent->IsServerClosed(), ResultSessionClosed);
|
||||||
|
|
||||||
|
// Check that we have a request to reply to.
|
||||||
|
R_UNLESS(m_current_request != nullptr, ResultInvalidState);
|
||||||
|
|
||||||
|
// Check that the server thread id is correct.
|
||||||
|
R_UNLESS(m_server_thread_id == GetCurrentThread(m_kernel).GetId(), ResultInvalidState);
|
||||||
|
|
||||||
|
// If we can reply, do so.
|
||||||
|
if (!m_current_request->IsTerminationRequested()) {
|
||||||
|
std::memcpy(m_current_request->GetLightSessionData(),
|
||||||
|
GetCurrentThread(m_kernel).GetLightSessionData(), KLightSession::DataSize);
|
||||||
|
m_current_request->EndWait(ResultSuccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close our current request.
|
||||||
|
m_current_request->Close();
|
||||||
|
|
||||||
|
// Clear our current request.
|
||||||
|
m_current_request = nullptr;
|
||||||
|
m_server_thread_id = InvalidThreadId;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the wait queue for our receive.
|
||||||
|
ThreadQueueImplForKLightServerSessionReceive wait_queue(m_kernel,
|
||||||
|
std::addressof(m_server_thread));
|
||||||
|
|
||||||
|
// Receive.
|
||||||
|
while (true) {
|
||||||
|
// Try to receive a request.
|
||||||
|
{
|
||||||
|
KScopedSchedulerLock sl(m_kernel);
|
||||||
|
|
||||||
|
// Check that we aren't already receiving.
|
||||||
|
R_UNLESS(m_server_thread == nullptr, ResultInvalidState);
|
||||||
|
R_UNLESS(m_server_thread_id == InvalidThreadId, ResultInvalidState);
|
||||||
|
|
||||||
|
// Check that we're open.
|
||||||
|
R_UNLESS(!m_parent->IsClientClosed(), ResultSessionClosed);
|
||||||
|
R_UNLESS(!m_parent->IsServerClosed(), ResultSessionClosed);
|
||||||
|
|
||||||
|
// Check that we're not terminating.
|
||||||
|
R_UNLESS(!GetCurrentThread(m_kernel).IsTerminationRequested(),
|
||||||
|
ResultTerminationRequested);
|
||||||
|
|
||||||
|
// If we have a request available, use it.
|
||||||
|
if (auto head = m_request_list.begin(); head != m_request_list.end()) {
|
||||||
|
// Set our current request.
|
||||||
|
m_current_request = std::addressof(*head);
|
||||||
|
m_current_request->Open();
|
||||||
|
|
||||||
|
// Set our server thread id.
|
||||||
|
m_server_thread_id = GetCurrentThread(m_kernel).GetId();
|
||||||
|
|
||||||
|
// Copy the client request data.
|
||||||
|
std::memcpy(GetCurrentThread(m_kernel).GetLightSessionData(),
|
||||||
|
m_current_request->GetLightSessionData(), KLightSession::DataSize);
|
||||||
|
|
||||||
|
// We successfully received.
|
||||||
|
R_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
|
// We need to wait for a request to come in.
|
||||||
|
|
||||||
|
// Check if we were cancelled.
|
||||||
|
if (GetCurrentThread(m_kernel).IsWaitCancelled()) {
|
||||||
|
GetCurrentThread(m_kernel).ClearWaitCancelled();
|
||||||
|
R_THROW(ResultCancelled);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mark ourselves as cancellable.
|
||||||
|
GetCurrentThread(m_kernel).SetCancellable();
|
||||||
|
|
||||||
|
// Wait for a request to come in.
|
||||||
|
m_server_thread = GetCurrentThreadPointer(m_kernel);
|
||||||
|
GetCurrentThread(m_kernel).SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::IPC);
|
||||||
|
GetCurrentThread(m_kernel).BeginWait(std::addressof(wait_queue));
|
||||||
|
}
|
||||||
|
|
||||||
|
// We waited to receive a request; if our wait failed, return the failing result.
|
||||||
|
R_TRY(GetCurrentThread(m_kernel).GetWaitResult());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void KLightServerSession::CleanupRequests() {
|
||||||
|
// Cleanup all pending requests.
|
||||||
|
{
|
||||||
|
KScopedSchedulerLock sl(m_kernel);
|
||||||
|
|
||||||
|
// Handle the current request.
|
||||||
|
if (m_current_request != nullptr) {
|
||||||
|
// Reply to the current request.
|
||||||
|
if (!m_current_request->IsTerminationRequested()) {
|
||||||
|
m_current_request->EndWait(ResultSessionClosed);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear our current request.
|
||||||
|
m_current_request->Close();
|
||||||
|
m_current_request = nullptr;
|
||||||
|
m_server_thread_id = InvalidThreadId;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reply to all other requests.
|
||||||
|
for (auto& thread : m_request_list) {
|
||||||
|
thread.EndWait(ResultSessionClosed);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait up our server thread, if we have one.
|
||||||
|
if (m_server_thread != nullptr) {
|
||||||
|
m_server_thread->EndWait(ResultSessionClosed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Kernel
|
49
src/core/hle/kernel/k_light_server_session.h
Normal file
49
src/core/hle/kernel/k_light_server_session.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "core/hle/kernel/k_auto_object.h"
|
||||||
|
#include "core/hle/kernel/k_thread.h"
|
||||||
|
#include "core/hle/result.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
|
||||||
|
class KLightSession;
|
||||||
|
|
||||||
|
class KLightServerSession final : public KAutoObject,
|
||||||
|
public Common::IntrusiveListBaseNode<KLightServerSession> {
|
||||||
|
KERNEL_AUTOOBJECT_TRAITS(KLightServerSession, KAutoObject);
|
||||||
|
|
||||||
|
private:
|
||||||
|
KLightSession* m_parent{};
|
||||||
|
KThread::WaiterList m_request_list{};
|
||||||
|
KThread* m_current_request{};
|
||||||
|
u64 m_server_thread_id{std::numeric_limits<u64>::max()};
|
||||||
|
KThread* m_server_thread{};
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit KLightServerSession(KernelCore& kernel);
|
||||||
|
~KLightServerSession();
|
||||||
|
|
||||||
|
void Initialize(KLightSession* parent) {
|
||||||
|
// Set member variables. */
|
||||||
|
m_parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void Destroy() override;
|
||||||
|
|
||||||
|
constexpr const KLightSession* GetParent() const {
|
||||||
|
return m_parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result OnRequest(KThread* request_thread);
|
||||||
|
Result ReplyAndReceive(u32* data);
|
||||||
|
|
||||||
|
void OnClientClosed();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void CleanupRequests();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Kernel
|
81
src/core/hle/kernel/k_light_session.cpp
Normal file
81
src/core/hle/kernel/k_light_session.cpp
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include "core/hle/kernel/k_client_port.h"
|
||||||
|
#include "core/hle/kernel/k_light_client_session.h"
|
||||||
|
#include "core/hle/kernel/k_light_server_session.h"
|
||||||
|
#include "core/hle/kernel/k_light_session.h"
|
||||||
|
#include "core/hle/kernel/k_process.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
|
||||||
|
KLightSession::KLightSession(KernelCore& kernel)
|
||||||
|
: KAutoObjectWithSlabHeapAndContainer(kernel), m_server(kernel), m_client(kernel) {}
|
||||||
|
KLightSession::~KLightSession() = default;
|
||||||
|
|
||||||
|
void KLightSession::Initialize(KClientPort* client_port, uintptr_t name) {
|
||||||
|
// Increment reference count.
|
||||||
|
// Because reference count is one on creation, this will result
|
||||||
|
// in a reference count of two. Thus, when both server and client are closed
|
||||||
|
// this object will be destroyed.
|
||||||
|
this->Open();
|
||||||
|
|
||||||
|
// Create our sub sessions.
|
||||||
|
KAutoObject::Create(std::addressof(m_server));
|
||||||
|
KAutoObject::Create(std::addressof(m_client));
|
||||||
|
|
||||||
|
// Initialize our sub sessions.
|
||||||
|
m_server.Initialize(this);
|
||||||
|
m_client.Initialize(this);
|
||||||
|
|
||||||
|
// Set state and name.
|
||||||
|
m_state = State::Normal;
|
||||||
|
m_name = name;
|
||||||
|
|
||||||
|
// Set our owner process.
|
||||||
|
m_process = GetCurrentProcessPointer(m_kernel);
|
||||||
|
m_process->Open();
|
||||||
|
|
||||||
|
// Set our port.
|
||||||
|
m_port = client_port;
|
||||||
|
if (m_port != nullptr) {
|
||||||
|
m_port->Open();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mark initialized.
|
||||||
|
m_initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KLightSession::Finalize() {
|
||||||
|
if (m_port != nullptr) {
|
||||||
|
m_port->OnSessionFinalized();
|
||||||
|
m_port->Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void KLightSession::OnServerClosed() {
|
||||||
|
if (m_state == State::Normal) {
|
||||||
|
m_state = State::ServerClosed;
|
||||||
|
m_client.OnServerClosed();
|
||||||
|
}
|
||||||
|
|
||||||
|
this->Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void KLightSession::OnClientClosed() {
|
||||||
|
if (m_state == State::Normal) {
|
||||||
|
m_state = State::ClientClosed;
|
||||||
|
m_server.OnClientClosed();
|
||||||
|
}
|
||||||
|
|
||||||
|
this->Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void KLightSession::PostDestroy(uintptr_t arg) {
|
||||||
|
// Release the session count resource the owner process holds.
|
||||||
|
KProcess* owner = reinterpret_cast<KProcess*>(arg);
|
||||||
|
owner->ReleaseResource(Svc::LimitableResource::SessionCountMax, 1);
|
||||||
|
owner->Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Kernel
|
86
src/core/hle/kernel/k_light_session.h
Normal file
86
src/core/hle/kernel/k_light_session.h
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "core/hle/kernel/k_light_client_session.h"
|
||||||
|
#include "core/hle/kernel/k_light_server_session.h"
|
||||||
|
#include "core/hle/kernel/slab_helpers.h"
|
||||||
|
#include "core/hle/result.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
|
||||||
|
class KClientPort;
|
||||||
|
class KProcess;
|
||||||
|
|
||||||
|
// TODO: SupportDynamicExpansion for SlabHeap
|
||||||
|
class KLightSession final
|
||||||
|
: public KAutoObjectWithSlabHeapAndContainer<KLightSession, KAutoObjectWithList> {
|
||||||
|
KERNEL_AUTOOBJECT_TRAITS(KLightSession, KAutoObject);
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum class State : u8 {
|
||||||
|
Invalid = 0,
|
||||||
|
Normal = 1,
|
||||||
|
ClientClosed = 2,
|
||||||
|
ServerClosed = 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
static constexpr size_t DataSize = sizeof(u32) * 7;
|
||||||
|
static constexpr u32 ReplyFlag = (1U << 31);
|
||||||
|
|
||||||
|
private:
|
||||||
|
KLightServerSession m_server;
|
||||||
|
KLightClientSession m_client;
|
||||||
|
State m_state{State::Invalid};
|
||||||
|
KClientPort* m_port{};
|
||||||
|
uintptr_t m_name{};
|
||||||
|
KProcess* m_process{};
|
||||||
|
bool m_initialized{};
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit KLightSession(KernelCore& kernel);
|
||||||
|
~KLightSession();
|
||||||
|
|
||||||
|
void Initialize(KClientPort* client_port, uintptr_t name);
|
||||||
|
void Finalize() override;
|
||||||
|
|
||||||
|
bool IsInitialized() const override {
|
||||||
|
return m_initialized;
|
||||||
|
}
|
||||||
|
uintptr_t GetPostDestroyArgument() const override {
|
||||||
|
return reinterpret_cast<uintptr_t>(m_process);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void PostDestroy(uintptr_t arg);
|
||||||
|
|
||||||
|
void OnServerClosed();
|
||||||
|
void OnClientClosed();
|
||||||
|
|
||||||
|
bool IsServerClosed() const {
|
||||||
|
return m_state != State::Normal;
|
||||||
|
}
|
||||||
|
bool IsClientClosed() const {
|
||||||
|
return m_state != State::Normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result OnRequest(KThread* request_thread) {
|
||||||
|
R_RETURN(m_server.OnRequest(request_thread));
|
||||||
|
}
|
||||||
|
|
||||||
|
KLightClientSession& GetClientSession() {
|
||||||
|
return m_client;
|
||||||
|
}
|
||||||
|
KLightServerSession& GetServerSession() {
|
||||||
|
return m_server;
|
||||||
|
}
|
||||||
|
const KLightClientSession& GetClientSession() const {
|
||||||
|
return m_client;
|
||||||
|
}
|
||||||
|
const KLightServerSession& GetServerSession() const {
|
||||||
|
return m_server;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Kernel
|
@ -58,4 +58,13 @@ Result KPort::EnqueueSession(KServerSession* session) {
|
|||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result KPort::EnqueueSession(KLightServerSession* session) {
|
||||||
|
KScopedSchedulerLock sl{m_kernel};
|
||||||
|
|
||||||
|
R_UNLESS(m_state == State::Normal, ResultPortClosed);
|
||||||
|
|
||||||
|
m_server.EnqueueSession(session);
|
||||||
|
R_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
|
class KLightServerSession;
|
||||||
class KServerSession;
|
class KServerSession;
|
||||||
|
|
||||||
class KPort final : public KAutoObjectWithSlabHeapAndContainer<KPort, KAutoObjectWithList> {
|
class KPort final : public KAutoObjectWithSlabHeapAndContainer<KPort, KAutoObjectWithList> {
|
||||||
@ -38,6 +39,7 @@ public:
|
|||||||
bool IsServerClosed() const;
|
bool IsServerClosed() const;
|
||||||
|
|
||||||
Result EnqueueSession(KServerSession* session);
|
Result EnqueueSession(KServerSession* session);
|
||||||
|
Result EnqueueSession(KLightServerSession* session);
|
||||||
|
|
||||||
KClientPort& GetClientPort() {
|
KClientPort& GetClientPort() {
|
||||||
return m_client;
|
return m_client;
|
||||||
|
@ -27,12 +27,14 @@ bool KServerPort::IsLight() const {
|
|||||||
void KServerPort::CleanupSessions() {
|
void KServerPort::CleanupSessions() {
|
||||||
// Ensure our preconditions are met.
|
// Ensure our preconditions are met.
|
||||||
if (this->IsLight()) {
|
if (this->IsLight()) {
|
||||||
UNIMPLEMENTED();
|
ASSERT(m_session_list.empty());
|
||||||
|
} else {
|
||||||
|
ASSERT(m_light_session_list.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup the session list.
|
// Cleanup the session list.
|
||||||
while (true) {
|
while (true) {
|
||||||
// Get the last session in the list
|
// Get the last session in the list.
|
||||||
KServerSession* session = nullptr;
|
KServerSession* session = nullptr;
|
||||||
{
|
{
|
||||||
KScopedSchedulerLock sl{m_kernel};
|
KScopedSchedulerLock sl{m_kernel};
|
||||||
@ -49,6 +51,26 @@ void KServerPort::CleanupSessions() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cleanup the light session list.
|
||||||
|
while (true) {
|
||||||
|
// Get the last session in the list.
|
||||||
|
KLightServerSession* session = nullptr;
|
||||||
|
{
|
||||||
|
KScopedSchedulerLock sl{m_kernel};
|
||||||
|
if (!m_light_session_list.empty()) {
|
||||||
|
session = std::addressof(m_light_session_list.front());
|
||||||
|
m_light_session_list.pop_front();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close the session.
|
||||||
|
if (session != nullptr) {
|
||||||
|
session->Close();
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KServerPort::Destroy() {
|
void KServerPort::Destroy() {
|
||||||
@ -64,8 +86,7 @@ void KServerPort::Destroy() {
|
|||||||
|
|
||||||
bool KServerPort::IsSignaled() const {
|
bool KServerPort::IsSignaled() const {
|
||||||
if (this->IsLight()) {
|
if (this->IsLight()) {
|
||||||
UNIMPLEMENTED();
|
return !m_light_session_list.empty();
|
||||||
return false;
|
|
||||||
} else {
|
} else {
|
||||||
return !m_session_list.empty();
|
return !m_session_list.empty();
|
||||||
}
|
}
|
||||||
@ -83,6 +104,18 @@ void KServerPort::EnqueueSession(KServerSession* session) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KServerPort::EnqueueSession(KLightServerSession* session) {
|
||||||
|
ASSERT(this->IsLight());
|
||||||
|
|
||||||
|
KScopedSchedulerLock sl{m_kernel};
|
||||||
|
|
||||||
|
// Add the session to our queue.
|
||||||
|
m_light_session_list.push_back(*session);
|
||||||
|
if (m_light_session_list.size() == 1) {
|
||||||
|
this->NotifyAvailable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
KServerSession* KServerPort::AcceptSession() {
|
KServerSession* KServerPort::AcceptSession() {
|
||||||
ASSERT(!this->IsLight());
|
ASSERT(!this->IsLight());
|
||||||
|
|
||||||
@ -98,4 +131,19 @@ KServerSession* KServerPort::AcceptSession() {
|
|||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KLightServerSession* KServerPort::AcceptLightSession() {
|
||||||
|
ASSERT(this->IsLight());
|
||||||
|
|
||||||
|
KScopedSchedulerLock sl{m_kernel};
|
||||||
|
|
||||||
|
// Return the first session in the list.
|
||||||
|
if (m_light_session_list.empty()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
KLightServerSession* session = std::addressof(m_light_session_list.front());
|
||||||
|
m_light_session_list.pop_front();
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "common/intrusive_list.h"
|
#include "common/intrusive_list.h"
|
||||||
|
|
||||||
|
#include "core/hle/kernel/k_light_server_session.h"
|
||||||
#include "core/hle/kernel/k_server_session.h"
|
#include "core/hle/kernel/k_server_session.h"
|
||||||
#include "core/hle/kernel/k_synchronization_object.h"
|
#include "core/hle/kernel/k_synchronization_object.h"
|
||||||
|
|
||||||
@ -28,8 +29,10 @@ public:
|
|||||||
void Initialize(KPort* parent);
|
void Initialize(KPort* parent);
|
||||||
|
|
||||||
void EnqueueSession(KServerSession* session);
|
void EnqueueSession(KServerSession* session);
|
||||||
|
void EnqueueSession(KLightServerSession* session);
|
||||||
|
|
||||||
KServerSession* AcceptSession();
|
KServerSession* AcceptSession();
|
||||||
|
KLightServerSession* AcceptLightSession();
|
||||||
|
|
||||||
const KPort* GetParent() const {
|
const KPort* GetParent() const {
|
||||||
return m_parent;
|
return m_parent;
|
||||||
@ -43,10 +46,12 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
using SessionList = Common::IntrusiveListBaseTraits<KServerSession>::ListType;
|
using SessionList = Common::IntrusiveListBaseTraits<KServerSession>::ListType;
|
||||||
|
using LightSessionList = Common::IntrusiveListBaseTraits<KLightServerSession>::ListType;
|
||||||
|
|
||||||
void CleanupSessions();
|
void CleanupSessions();
|
||||||
|
|
||||||
SessionList m_session_list{};
|
SessionList m_session_list{};
|
||||||
|
LightSessionList m_light_session_list{};
|
||||||
KPort* m_parent{};
|
KPort* m_parent{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -453,6 +453,11 @@ Result KServerSession::ReceiveRequest(std::shared_ptr<Service::HLERequestContext
|
|||||||
size_t client_buffer_size = request->GetSize();
|
size_t client_buffer_size = request->GetSize();
|
||||||
// bool recv_list_broken = false;
|
// bool recv_list_broken = false;
|
||||||
|
|
||||||
|
if (!client_message) {
|
||||||
|
client_message = GetInteger(client_thread->GetTlsAddress());
|
||||||
|
client_buffer_size = MessageBufferSize;
|
||||||
|
}
|
||||||
|
|
||||||
// Receive the message.
|
// Receive the message.
|
||||||
Core::Memory::Memory& memory{client_thread->GetOwnerProcess()->GetMemory()};
|
Core::Memory::Memory& memory{client_thread->GetOwnerProcess()->GetMemory()};
|
||||||
if (out_context != nullptr) {
|
if (out_context != nullptr) {
|
||||||
|
@ -46,6 +46,10 @@ public:
|
|||||||
return this->GetState() != State::Normal;
|
return this->GetState() != State::Normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result OnRequest(KSessionRequest* request) {
|
||||||
|
R_RETURN(m_server.OnRequest(request));
|
||||||
|
}
|
||||||
|
|
||||||
KClientSession& GetClientSession() {
|
KClientSession& GetClientSession() {
|
||||||
return m_client;
|
return m_client;
|
||||||
}
|
}
|
||||||
|
@ -385,6 +385,13 @@ public:
|
|||||||
m_cancellable = false;
|
m_cancellable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u32* GetLightSessionData() const {
|
||||||
|
return m_light_ipc_data;
|
||||||
|
}
|
||||||
|
void SetLightSessionData(u32* data) {
|
||||||
|
m_light_ipc_data = data;
|
||||||
|
}
|
||||||
|
|
||||||
bool IsTerminationRequested() const {
|
bool IsTerminationRequested() const {
|
||||||
return m_termination_requested || GetRawState() == ThreadState::Terminated;
|
return m_termination_requested || GetRawState() == ThreadState::Terminated;
|
||||||
}
|
}
|
||||||
|
@ -1340,6 +1340,7 @@ struct KernelCore::SlabHeapContainer {
|
|||||||
KSlabHeap<KProcess> process;
|
KSlabHeap<KProcess> process;
|
||||||
KSlabHeap<KResourceLimit> resource_limit;
|
KSlabHeap<KResourceLimit> resource_limit;
|
||||||
KSlabHeap<KSession> session;
|
KSlabHeap<KSession> session;
|
||||||
|
KSlabHeap<KLightSession> light_session;
|
||||||
KSlabHeap<KSharedMemory> shared_memory;
|
KSlabHeap<KSharedMemory> shared_memory;
|
||||||
KSlabHeap<KSharedMemoryInfo> shared_memory_info;
|
KSlabHeap<KSharedMemoryInfo> shared_memory_info;
|
||||||
KSlabHeap<KThread> thread;
|
KSlabHeap<KThread> thread;
|
||||||
@ -1370,6 +1371,8 @@ KSlabHeap<T>& KernelCore::SlabHeap() {
|
|||||||
return slab_heap_container->resource_limit;
|
return slab_heap_container->resource_limit;
|
||||||
} else if constexpr (std::is_same_v<T, KSession>) {
|
} else if constexpr (std::is_same_v<T, KSession>) {
|
||||||
return slab_heap_container->session;
|
return slab_heap_container->session;
|
||||||
|
} else if constexpr (std::is_same_v<T, KLightSession>) {
|
||||||
|
return slab_heap_container->light_session;
|
||||||
} else if constexpr (std::is_same_v<T, KSharedMemory>) {
|
} else if constexpr (std::is_same_v<T, KSharedMemory>) {
|
||||||
return slab_heap_container->shared_memory;
|
return slab_heap_container->shared_memory;
|
||||||
} else if constexpr (std::is_same_v<T, KSharedMemoryInfo>) {
|
} else if constexpr (std::is_same_v<T, KSharedMemoryInfo>) {
|
||||||
@ -1407,6 +1410,7 @@ template KSlabHeap<KPort>& KernelCore::SlabHeap();
|
|||||||
template KSlabHeap<KProcess>& KernelCore::SlabHeap();
|
template KSlabHeap<KProcess>& KernelCore::SlabHeap();
|
||||||
template KSlabHeap<KResourceLimit>& KernelCore::SlabHeap();
|
template KSlabHeap<KResourceLimit>& KernelCore::SlabHeap();
|
||||||
template KSlabHeap<KSession>& KernelCore::SlabHeap();
|
template KSlabHeap<KSession>& KernelCore::SlabHeap();
|
||||||
|
template KSlabHeap<KLightSession>& KernelCore::SlabHeap();
|
||||||
template KSlabHeap<KSharedMemory>& KernelCore::SlabHeap();
|
template KSlabHeap<KSharedMemory>& KernelCore::SlabHeap();
|
||||||
template KSlabHeap<KSharedMemoryInfo>& KernelCore::SlabHeap();
|
template KSlabHeap<KSharedMemoryInfo>& KernelCore::SlabHeap();
|
||||||
template KSlabHeap<KThread>& KernelCore::SlabHeap();
|
template KSlabHeap<KThread>& KernelCore::SlabHeap();
|
||||||
|
@ -7,71 +7,39 @@
|
|||||||
#include "core/hle/kernel/k_client_session.h"
|
#include "core/hle/kernel/k_client_session.h"
|
||||||
#include "core/hle/kernel/k_hardware_timer.h"
|
#include "core/hle/kernel/k_hardware_timer.h"
|
||||||
#include "core/hle/kernel/k_process.h"
|
#include "core/hle/kernel/k_process.h"
|
||||||
|
#include "core/hle/kernel/k_scoped_resource_reservation.h"
|
||||||
#include "core/hle/kernel/k_server_session.h"
|
#include "core/hle/kernel/k_server_session.h"
|
||||||
|
#include "core/hle/kernel/k_session.h"
|
||||||
#include "core/hle/kernel/svc.h"
|
#include "core/hle/kernel/svc.h"
|
||||||
#include "core/hle/kernel/svc_results.h"
|
#include "core/hle/kernel/svc_results.h"
|
||||||
|
|
||||||
namespace Kernel::Svc {
|
namespace Kernel::Svc {
|
||||||
|
|
||||||
/// Makes a blocking IPC call to a service.
|
namespace {
|
||||||
Result SendSyncRequest(Core::System& system, Handle handle) {
|
|
||||||
// Get the client session from its handle.
|
Result SendSyncRequestImpl(KernelCore& kernel, uintptr_t message, size_t buffer_size,
|
||||||
|
Handle session_handle) {
|
||||||
|
// Get the client session.
|
||||||
KScopedAutoObject session =
|
KScopedAutoObject session =
|
||||||
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KClientSession>(handle);
|
GetCurrentProcess(kernel).GetHandleTable().GetObject<KClientSession>(session_handle);
|
||||||
R_UNLESS(session.IsNotNull(), ResultInvalidHandle);
|
R_UNLESS(session.IsNotNull(), ResultInvalidHandle);
|
||||||
|
|
||||||
LOG_TRACE(Kernel_SVC, "called handle=0x{:08X}", handle);
|
// Get the parent, and persist a reference to it until we're done.
|
||||||
|
KScopedAutoObject parent = session->GetParent();
|
||||||
|
ASSERT(parent.IsNotNull());
|
||||||
|
|
||||||
R_RETURN(session->SendSyncRequest());
|
// Send the request.
|
||||||
|
R_RETURN(session->SendSyncRequest(message, buffer_size));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result SendSyncRequestWithUserBuffer(Core::System& system, uint64_t message_buffer,
|
Result ReplyAndReceiveImpl(KernelCore& kernel, int32_t* out_index, uintptr_t message,
|
||||||
uint64_t message_buffer_size, Handle session_handle) {
|
size_t buffer_size, KPhysicalAddress message_paddr,
|
||||||
UNIMPLEMENTED();
|
KSynchronizationObject** objs, int32_t num_objects, Handle reply_target,
|
||||||
R_THROW(ResultNotImplemented);
|
int64_t timeout_ns) {
|
||||||
}
|
|
||||||
|
|
||||||
Result SendAsyncRequestWithUserBuffer(Core::System& system, Handle* out_event_handle,
|
|
||||||
uint64_t message_buffer, uint64_t message_buffer_size,
|
|
||||||
Handle session_handle) {
|
|
||||||
UNIMPLEMENTED();
|
|
||||||
R_THROW(ResultNotImplemented);
|
|
||||||
}
|
|
||||||
|
|
||||||
Result ReplyAndReceive(Core::System& system, s32* out_index, uint64_t handles_addr, s32 num_handles,
|
|
||||||
Handle reply_target, s64 timeout_ns) {
|
|
||||||
// Ensure number of handles is valid.
|
|
||||||
R_UNLESS(0 <= num_handles && num_handles <= ArgumentHandleCountMax, ResultOutOfRange);
|
|
||||||
|
|
||||||
// Get the synchronization context.
|
|
||||||
auto& kernel = system.Kernel();
|
|
||||||
auto& handle_table = GetCurrentProcess(kernel).GetHandleTable();
|
|
||||||
auto objs = GetCurrentThread(kernel).GetSynchronizationObjectBuffer();
|
|
||||||
auto handles = GetCurrentThread(kernel).GetHandleBuffer();
|
|
||||||
|
|
||||||
// Copy user handles.
|
|
||||||
if (num_handles > 0) {
|
|
||||||
// Get the handles.
|
|
||||||
R_UNLESS(GetCurrentMemory(kernel).ReadBlock(handles_addr, handles.data(),
|
|
||||||
sizeof(Handle) * num_handles),
|
|
||||||
ResultInvalidPointer);
|
|
||||||
|
|
||||||
// Convert the handles to objects.
|
|
||||||
R_UNLESS(handle_table.GetMultipleObjects<KSynchronizationObject>(
|
|
||||||
objs.data(), handles.data(), num_handles),
|
|
||||||
ResultInvalidHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure handles are closed when we're done.
|
|
||||||
SCOPE_EXIT({
|
|
||||||
for (auto i = 0; i < num_handles; ++i) {
|
|
||||||
objs[i]->Close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Reply to the target, if one is specified.
|
// Reply to the target, if one is specified.
|
||||||
if (reply_target != InvalidHandle) {
|
if (reply_target != InvalidHandle) {
|
||||||
KScopedAutoObject session = handle_table.GetObject<KServerSession>(reply_target);
|
KScopedAutoObject session =
|
||||||
|
GetCurrentProcess(kernel).GetHandleTable().GetObject<KServerSession>(reply_target);
|
||||||
R_UNLESS(session.IsNotNull(), ResultInvalidHandle);
|
R_UNLESS(session.IsNotNull(), ResultInvalidHandle);
|
||||||
|
|
||||||
// If we fail to reply, we want to set the output index to -1.
|
// If we fail to reply, we want to set the output index to -1.
|
||||||
@ -81,8 +49,11 @@ Result ReplyAndReceive(Core::System& system, s32* out_index, uint64_t handles_ad
|
|||||||
|
|
||||||
// Send the reply.
|
// Send the reply.
|
||||||
R_TRY(session->SendReply());
|
R_TRY(session->SendReply());
|
||||||
|
// R_TRY(session->SendReply(message, buffer_size, message_paddr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Receive a message.
|
||||||
|
{
|
||||||
// Convert the timeout from nanoseconds to ticks.
|
// Convert the timeout from nanoseconds to ticks.
|
||||||
// NOTE: Nintendo does not use this conversion logic in WaitSynchronization...
|
// NOTE: Nintendo does not use this conversion logic in WaitSynchronization...
|
||||||
s64 timeout;
|
s64 timeout;
|
||||||
@ -104,18 +75,19 @@ Result ReplyAndReceive(Core::System& system, s32* out_index, uint64_t handles_ad
|
|||||||
while (true) {
|
while (true) {
|
||||||
// Wait for an object.
|
// Wait for an object.
|
||||||
s32 index;
|
s32 index;
|
||||||
Result result = KSynchronizationObject::Wait(kernel, std::addressof(index), objs.data(),
|
Result result = KSynchronizationObject::Wait(kernel, std::addressof(index), objs,
|
||||||
num_handles, timeout);
|
num_objects, timeout);
|
||||||
if (result == ResultTimedOut) {
|
if (ResultTimedOut == result) {
|
||||||
R_RETURN(result);
|
R_THROW(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Receive the request.
|
// Receive the request.
|
||||||
if (R_SUCCEEDED(result)) {
|
if (R_SUCCEEDED(result)) {
|
||||||
KServerSession* session = objs[index]->DynamicCast<KServerSession*>();
|
KServerSession* session = objs[index]->DynamicCast<KServerSession*>();
|
||||||
if (session != nullptr) {
|
if (session != nullptr) {
|
||||||
|
// result = session->ReceiveRequest(message, buffer_size, message_paddr);
|
||||||
result = session->ReceiveRequest();
|
result = session->ReceiveRequest();
|
||||||
if (result == ResultNotFound) {
|
if (ResultNotFound == result) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,13 +97,175 @@ Result ReplyAndReceive(Core::System& system, s32* out_index, uint64_t handles_ad
|
|||||||
R_RETURN(result);
|
R_RETURN(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Result ReplyAndReceiveWithUserBuffer(Core::System& system, int32_t* out_index,
|
Result ReplyAndReceiveImpl(KernelCore& kernel, int32_t* out_index, uintptr_t message,
|
||||||
uint64_t message_buffer, uint64_t message_buffer_size,
|
size_t buffer_size, KPhysicalAddress message_paddr,
|
||||||
uint64_t handles, int32_t num_handles, Handle reply_target,
|
KProcessAddress user_handles, int32_t num_handles, Handle reply_target,
|
||||||
int64_t timeout_ns) {
|
int64_t timeout_ns) {
|
||||||
UNIMPLEMENTED();
|
// Ensure number of handles is valid.
|
||||||
R_THROW(ResultNotImplemented);
|
R_UNLESS(0 <= num_handles && num_handles <= Svc::ArgumentHandleCountMax, ResultOutOfRange);
|
||||||
|
|
||||||
|
// Get the synchronization context.
|
||||||
|
auto& process = GetCurrentProcess(kernel);
|
||||||
|
auto& thread = GetCurrentThread(kernel);
|
||||||
|
auto& handle_table = process.GetHandleTable();
|
||||||
|
KSynchronizationObject** objs = thread.GetSynchronizationObjectBuffer().data();
|
||||||
|
Handle* handles = thread.GetHandleBuffer().data();
|
||||||
|
|
||||||
|
// Copy user handles.
|
||||||
|
if (num_handles > 0) {
|
||||||
|
// Ensure that we can try to get the handles.
|
||||||
|
R_UNLESS(process.GetPageTable().Contains(user_handles, num_handles * sizeof(Handle)),
|
||||||
|
ResultInvalidPointer);
|
||||||
|
|
||||||
|
// Get the handles
|
||||||
|
R_UNLESS(
|
||||||
|
GetCurrentMemory(kernel).ReadBlock(user_handles, handles, sizeof(Handle) * num_handles),
|
||||||
|
ResultInvalidPointer);
|
||||||
|
|
||||||
|
// Convert the handles to objects.
|
||||||
|
R_UNLESS(
|
||||||
|
handle_table.GetMultipleObjects<KSynchronizationObject>(objs, handles, num_handles),
|
||||||
|
ResultInvalidHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure handles are closed when we're done.
|
||||||
|
SCOPE_EXIT({
|
||||||
|
for (auto i = 0; i < num_handles; ++i) {
|
||||||
|
objs[i]->Close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
R_RETURN(ReplyAndReceiveImpl(kernel, out_index, message, buffer_size, message_paddr, objs,
|
||||||
|
num_handles, reply_target, timeout_ns));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
/// Makes a blocking IPC call to a service.
|
||||||
|
Result SendSyncRequest(Core::System& system, Handle session_handle) {
|
||||||
|
R_RETURN(SendSyncRequestImpl(system.Kernel(), 0, 0, session_handle));
|
||||||
|
}
|
||||||
|
|
||||||
|
Result SendSyncRequestWithUserBuffer(Core::System& system, uint64_t message, uint64_t buffer_size,
|
||||||
|
Handle session_handle) {
|
||||||
|
auto& kernel = system.Kernel();
|
||||||
|
|
||||||
|
// Validate that the message buffer is page aligned and does not overflow.
|
||||||
|
R_UNLESS(Common::IsAligned(message, PageSize), ResultInvalidAddress);
|
||||||
|
R_UNLESS(buffer_size > 0, ResultInvalidSize);
|
||||||
|
R_UNLESS(Common::IsAligned(buffer_size, PageSize), ResultInvalidSize);
|
||||||
|
R_UNLESS(message < message + buffer_size, ResultInvalidCurrentMemory);
|
||||||
|
|
||||||
|
// Get the process page table.
|
||||||
|
auto& page_table = GetCurrentProcess(kernel).GetPageTable();
|
||||||
|
|
||||||
|
// Lock the message buffer.
|
||||||
|
R_TRY(page_table.LockForIpcUserBuffer(nullptr, message, buffer_size));
|
||||||
|
|
||||||
|
{
|
||||||
|
// If we fail to send the message, unlock the message buffer.
|
||||||
|
ON_RESULT_FAILURE {
|
||||||
|
page_table.UnlockForIpcUserBuffer(message, buffer_size);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Send the request.
|
||||||
|
ASSERT(message != 0);
|
||||||
|
R_TRY(SendSyncRequestImpl(kernel, message, buffer_size, session_handle));
|
||||||
|
}
|
||||||
|
|
||||||
|
// We successfully processed, so try to unlock the message buffer.
|
||||||
|
R_RETURN(page_table.UnlockForIpcUserBuffer(message, buffer_size));
|
||||||
|
}
|
||||||
|
|
||||||
|
Result SendAsyncRequestWithUserBuffer(Core::System& system, Handle* out_event_handle,
|
||||||
|
uint64_t message, uint64_t buffer_size,
|
||||||
|
Handle session_handle) {
|
||||||
|
// Get the process and handle table.
|
||||||
|
auto& process = GetCurrentProcess(system.Kernel());
|
||||||
|
auto& handle_table = process.GetHandleTable();
|
||||||
|
|
||||||
|
// Reserve a new event from the process resource limit.
|
||||||
|
KScopedResourceReservation event_reservation(std::addressof(process),
|
||||||
|
Svc::LimitableResource::EventCountMax);
|
||||||
|
R_UNLESS(event_reservation.Succeeded(), ResultLimitReached);
|
||||||
|
|
||||||
|
// Get the client session.
|
||||||
|
KScopedAutoObject session = process.GetHandleTable().GetObject<KClientSession>(session_handle);
|
||||||
|
R_UNLESS(session.IsNotNull(), ResultInvalidHandle);
|
||||||
|
|
||||||
|
// Get the parent, and persist a reference to it until we're done.
|
||||||
|
KScopedAutoObject parent = session->GetParent();
|
||||||
|
ASSERT(parent.IsNotNull());
|
||||||
|
|
||||||
|
// Create a new event.
|
||||||
|
KEvent* event = KEvent::Create(system.Kernel());
|
||||||
|
R_UNLESS(event != nullptr, ResultOutOfResource);
|
||||||
|
|
||||||
|
// Initialize the event.
|
||||||
|
event->Initialize(std::addressof(process));
|
||||||
|
|
||||||
|
// Commit our reservation.
|
||||||
|
event_reservation.Commit();
|
||||||
|
|
||||||
|
// At end of scope, kill the standing references to the sub events.
|
||||||
|
SCOPE_EXIT({
|
||||||
|
event->GetReadableEvent().Close();
|
||||||
|
event->Close();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Register the event.
|
||||||
|
KEvent::Register(system.Kernel(), event);
|
||||||
|
|
||||||
|
// Add the readable event to the handle table.
|
||||||
|
R_TRY(handle_table.Add(out_event_handle, std::addressof(event->GetReadableEvent())));
|
||||||
|
|
||||||
|
// Ensure that if we fail to send the request, we close the readable handle.
|
||||||
|
ON_RESULT_FAILURE {
|
||||||
|
handle_table.Remove(*out_event_handle);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Send the async request.
|
||||||
|
R_RETURN(session->SendAsyncRequest(event, message, buffer_size));
|
||||||
|
}
|
||||||
|
|
||||||
|
Result ReplyAndReceive(Core::System& system, s32* out_index, uint64_t handles, s32 num_handles,
|
||||||
|
Handle reply_target, s64 timeout_ns) {
|
||||||
|
R_RETURN(ReplyAndReceiveImpl(system.Kernel(), out_index, 0, 0, 0, handles, num_handles,
|
||||||
|
reply_target, timeout_ns));
|
||||||
|
}
|
||||||
|
|
||||||
|
Result ReplyAndReceiveWithUserBuffer(Core::System& system, int32_t* out_index, uint64_t message,
|
||||||
|
uint64_t buffer_size, uint64_t handles, int32_t num_handles,
|
||||||
|
Handle reply_target, int64_t timeout_ns) {
|
||||||
|
// Validate that the message buffer is page aligned and does not overflow.
|
||||||
|
R_UNLESS(Common::IsAligned(message, PageSize), ResultInvalidAddress);
|
||||||
|
R_UNLESS(buffer_size > 0, ResultInvalidSize);
|
||||||
|
R_UNLESS(Common::IsAligned(buffer_size, PageSize), ResultInvalidSize);
|
||||||
|
R_UNLESS(message < message + buffer_size, ResultInvalidCurrentMemory);
|
||||||
|
|
||||||
|
// Get the process page table.
|
||||||
|
auto& page_table = GetCurrentProcess(system.Kernel()).GetPageTable();
|
||||||
|
|
||||||
|
// Lock the message buffer, getting its physical address.
|
||||||
|
KPhysicalAddress message_paddr;
|
||||||
|
R_TRY(page_table.LockForIpcUserBuffer(std::addressof(message_paddr), message, buffer_size));
|
||||||
|
|
||||||
|
{
|
||||||
|
// If we fail to send the message, unlock the message buffer.
|
||||||
|
ON_RESULT_FAILURE {
|
||||||
|
page_table.UnlockForIpcUserBuffer(message, buffer_size);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Reply/Receive the request.
|
||||||
|
ASSERT(message != 0);
|
||||||
|
R_TRY(ReplyAndReceiveImpl(system.Kernel(), out_index, message, buffer_size, message_paddr,
|
||||||
|
handles, num_handles, reply_target, timeout_ns));
|
||||||
|
}
|
||||||
|
|
||||||
|
// We successfully processed, so try to unlock the message buffer.
|
||||||
|
R_RETURN(page_table.UnlockForIpcUserBuffer(message, buffer_size));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result SendSyncRequest64(Core::System& system, Handle session_handle) {
|
Result SendSyncRequest64(Core::System& system, Handle session_handle) {
|
||||||
|
@ -1,21 +1,40 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include "core/arm/arm_interface.h"
|
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
|
#include "core/hle/kernel/k_light_client_session.h"
|
||||||
|
#include "core/hle/kernel/k_light_server_session.h"
|
||||||
|
#include "core/hle/kernel/k_process.h"
|
||||||
|
#include "core/hle/kernel/k_thread.h"
|
||||||
#include "core/hle/kernel/svc.h"
|
#include "core/hle/kernel/svc.h"
|
||||||
#include "core/hle/kernel/svc_results.h"
|
#include "core/hle/kernel/svc_results.h"
|
||||||
|
|
||||||
namespace Kernel::Svc {
|
namespace Kernel::Svc {
|
||||||
|
|
||||||
Result SendSyncRequestLight(Core::System& system, Handle session_handle, u32* args) {
|
Result SendSyncRequestLight(Core::System& system, Handle session_handle, u32* args) {
|
||||||
UNIMPLEMENTED();
|
// Get the light client session from its handle.
|
||||||
R_THROW(ResultNotImplemented);
|
KScopedAutoObject session = GetCurrentProcess(system.Kernel())
|
||||||
|
.GetHandleTable()
|
||||||
|
.GetObject<KLightClientSession>(session_handle);
|
||||||
|
R_UNLESS(session.IsNotNull(), ResultInvalidHandle);
|
||||||
|
|
||||||
|
// Send the request.
|
||||||
|
R_TRY(session->SendSyncRequest(args));
|
||||||
|
|
||||||
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result ReplyAndReceiveLight(Core::System& system, Handle session_handle, u32* args) {
|
Result ReplyAndReceiveLight(Core::System& system, Handle session_handle, u32* args) {
|
||||||
UNIMPLEMENTED();
|
// Get the light server session from its handle.
|
||||||
R_THROW(ResultNotImplemented);
|
KScopedAutoObject session = GetCurrentProcess(system.Kernel())
|
||||||
|
.GetHandleTable()
|
||||||
|
.GetObject<KLightServerSession>(session_handle);
|
||||||
|
R_UNLESS(session.IsNotNull(), ResultInvalidHandle);
|
||||||
|
|
||||||
|
// Handle the request.
|
||||||
|
R_TRY(session->ReplyAndReceive(args));
|
||||||
|
|
||||||
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result SendSyncRequestLight64(Core::System& system, Handle session_handle, u32* args) {
|
Result SendSyncRequestLight64(Core::System& system, Handle session_handle, u32* args) {
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/hle/kernel/k_client_port.h"
|
#include "core/hle/kernel/k_client_port.h"
|
||||||
#include "core/hle/kernel/k_client_session.h"
|
#include "core/hle/kernel/k_client_session.h"
|
||||||
|
#include "core/hle/kernel/k_light_client_session.h"
|
||||||
#include "core/hle/kernel/k_object_name.h"
|
#include "core/hle/kernel/k_object_name.h"
|
||||||
#include "core/hle/kernel/k_port.h"
|
#include "core/hle/kernel/k_port.h"
|
||||||
#include "core/hle/kernel/k_process.h"
|
#include "core/hle/kernel/k_process.h"
|
||||||
@ -51,13 +52,73 @@ Result ConnectToNamedPort(Core::System& system, Handle* out, u64 user_name) {
|
|||||||
|
|
||||||
Result CreatePort(Core::System& system, Handle* out_server, Handle* out_client,
|
Result CreatePort(Core::System& system, Handle* out_server, Handle* out_client,
|
||||||
int32_t max_sessions, bool is_light, uint64_t name) {
|
int32_t max_sessions, bool is_light, uint64_t name) {
|
||||||
UNIMPLEMENTED();
|
auto& kernel = system.Kernel();
|
||||||
R_THROW(ResultNotImplemented);
|
|
||||||
|
// Ensure max sessions is valid.
|
||||||
|
R_UNLESS(max_sessions > 0, ResultOutOfRange);
|
||||||
|
|
||||||
|
// Get the current handle table.
|
||||||
|
auto& handle_table = GetCurrentProcess(kernel).GetHandleTable();
|
||||||
|
|
||||||
|
// Create a new port.
|
||||||
|
KPort* port = KPort::Create(kernel);
|
||||||
|
R_UNLESS(port != nullptr, ResultOutOfResource);
|
||||||
|
|
||||||
|
// Initialize the port.
|
||||||
|
port->Initialize(max_sessions, is_light, name);
|
||||||
|
|
||||||
|
// Ensure that we clean up the port (and its only references are handle table) on function end.
|
||||||
|
SCOPE_EXIT({
|
||||||
|
port->GetServerPort().Close();
|
||||||
|
port->GetClientPort().Close();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Register the port.
|
||||||
|
KPort::Register(kernel, port);
|
||||||
|
|
||||||
|
// Add the client to the handle table.
|
||||||
|
R_TRY(handle_table.Add(out_client, std::addressof(port->GetClientPort())));
|
||||||
|
|
||||||
|
// Ensure that we maintain a clean handle state on exit.
|
||||||
|
ON_RESULT_FAILURE {
|
||||||
|
handle_table.Remove(*out_client);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add the server to the handle table.
|
||||||
|
R_RETURN(handle_table.Add(out_server, std::addressof(port->GetServerPort())));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result ConnectToPort(Core::System& system, Handle* out_handle, Handle port) {
|
Result ConnectToPort(Core::System& system, Handle* out, Handle port) {
|
||||||
UNIMPLEMENTED();
|
// Get the current handle table.
|
||||||
R_THROW(ResultNotImplemented);
|
auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
|
||||||
|
|
||||||
|
// Get the client port.
|
||||||
|
KScopedAutoObject client_port = handle_table.GetObject<KClientPort>(port);
|
||||||
|
R_UNLESS(client_port.IsNotNull(), ResultInvalidHandle);
|
||||||
|
|
||||||
|
// Reserve a handle for the port.
|
||||||
|
// NOTE: Nintendo really does write directly to the output handle here.
|
||||||
|
R_TRY(handle_table.Reserve(out));
|
||||||
|
ON_RESULT_FAILURE {
|
||||||
|
handle_table.Unreserve(*out);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create the session.
|
||||||
|
KAutoObject* session;
|
||||||
|
if (client_port->IsLight()) {
|
||||||
|
R_TRY(client_port->CreateLightSession(
|
||||||
|
reinterpret_cast<KLightClientSession**>(std::addressof(session))));
|
||||||
|
} else {
|
||||||
|
R_TRY(client_port->CreateSession(
|
||||||
|
reinterpret_cast<KClientSession**>(std::addressof(session))));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register the session.
|
||||||
|
handle_table.Register(*out, session);
|
||||||
|
session->Close();
|
||||||
|
|
||||||
|
// We succeeded.
|
||||||
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result ManageNamedPort(Core::System& system, Handle* out_server_handle, uint64_t user_name,
|
Result ManageNamedPort(Core::System& system, Handle* out_server_handle, uint64_t user_name,
|
||||||
|
@ -3,8 +3,10 @@
|
|||||||
|
|
||||||
#include "common/scope_exit.h"
|
#include "common/scope_exit.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
|
#include "core/hle/kernel/k_light_session.h"
|
||||||
#include "core/hle/kernel/k_process.h"
|
#include "core/hle/kernel/k_process.h"
|
||||||
#include "core/hle/kernel/k_scoped_resource_reservation.h"
|
#include "core/hle/kernel/k_scoped_resource_reservation.h"
|
||||||
|
#include "core/hle/kernel/k_server_port.h"
|
||||||
#include "core/hle/kernel/k_session.h"
|
#include "core/hle/kernel/k_session.h"
|
||||||
#include "core/hle/kernel/svc.h"
|
#include "core/hle/kernel/svc.h"
|
||||||
|
|
||||||
@ -20,7 +22,7 @@ Result CreateSession(Core::System& system, Handle* out_server, Handle* out_clien
|
|||||||
T* session;
|
T* session;
|
||||||
|
|
||||||
// Reserve a new session from the process resource limit.
|
// Reserve a new session from the process resource limit.
|
||||||
// FIXME: LimitableResource_SessionCountMax
|
// TODO: Dynamic resource limits
|
||||||
KScopedResourceReservation session_reservation(std::addressof(process),
|
KScopedResourceReservation session_reservation(std::addressof(process),
|
||||||
LimitableResource::SessionCountMax);
|
LimitableResource::SessionCountMax);
|
||||||
if (session_reservation.Succeeded()) {
|
if (session_reservation.Succeeded()) {
|
||||||
@ -92,16 +94,42 @@ Result CreateSession(Core::System& system, Handle* out_server, Handle* out_clien
|
|||||||
Result CreateSession(Core::System& system, Handle* out_server, Handle* out_client, bool is_light,
|
Result CreateSession(Core::System& system, Handle* out_server, Handle* out_client, bool is_light,
|
||||||
u64 name) {
|
u64 name) {
|
||||||
if (is_light) {
|
if (is_light) {
|
||||||
// return CreateSession<KLightSession>(system, out_server, out_client, name);
|
R_RETURN(CreateSession<KLightSession>(system, out_server, out_client, name));
|
||||||
R_THROW(ResultNotImplemented);
|
|
||||||
} else {
|
} else {
|
||||||
R_RETURN(CreateSession<KSession>(system, out_server, out_client, name));
|
R_RETURN(CreateSession<KSession>(system, out_server, out_client, name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Result AcceptSession(Core::System& system, Handle* out_handle, Handle port_handle) {
|
Result AcceptSession(Core::System& system, Handle* out, Handle port_handle) {
|
||||||
UNIMPLEMENTED();
|
// Get the current handle table.
|
||||||
R_THROW(ResultNotImplemented);
|
auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
|
||||||
|
|
||||||
|
// Get the server port.
|
||||||
|
KScopedAutoObject port = handle_table.GetObject<KServerPort>(port_handle);
|
||||||
|
R_UNLESS(port.IsNotNull(), ResultInvalidHandle);
|
||||||
|
|
||||||
|
// Reserve an entry for the new session.
|
||||||
|
R_TRY(handle_table.Reserve(out));
|
||||||
|
ON_RESULT_FAILURE {
|
||||||
|
handle_table.Unreserve(*out);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Accept the session.
|
||||||
|
KAutoObject* session;
|
||||||
|
if (port->IsLight()) {
|
||||||
|
session = port->AcceptLightSession();
|
||||||
|
} else {
|
||||||
|
session = port->AcceptSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure we accepted successfully.
|
||||||
|
R_UNLESS(session != nullptr, ResultNotFound);
|
||||||
|
|
||||||
|
// Register the session.
|
||||||
|
handle_table.Register(*out, session);
|
||||||
|
session->Close();
|
||||||
|
|
||||||
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result CreateSession64(Core::System& system, Handle* out_server_session_handle,
|
Result CreateSession64(Core::System& system, Handle* out_server_session_handle,
|
||||||
|
199
src/core/hle/service/hid/controllers/applet_resource.cpp
Normal file
199
src/core/hle/service/hid/controllers/applet_resource.cpp
Normal file
@ -0,0 +1,199 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
#include "core/core.h"
|
||||||
|
#include "core/hle/kernel/k_shared_memory.h"
|
||||||
|
#include "core/hle/service/hid/controllers/applet_resource.h"
|
||||||
|
#include "core/hle/service/hid/errors.h"
|
||||||
|
|
||||||
|
namespace Service::HID {
|
||||||
|
|
||||||
|
AppletResource::AppletResource(Core::System& system_) : system{system_} {}
|
||||||
|
|
||||||
|
AppletResource::~AppletResource() = default;
|
||||||
|
|
||||||
|
Result AppletResource::CreateAppletResource(u64 aruid) {
|
||||||
|
const u64 index = GetIndexFromAruid(aruid);
|
||||||
|
|
||||||
|
if (index >= AruidIndexMax) {
|
||||||
|
return ResultAruidNotRegistered;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data[index].flag.is_assigned) {
|
||||||
|
return ResultAruidAlreadyRegistered;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Here shared memory is created for the process we don't quite emulate this part so
|
||||||
|
// obtain this pointer from system
|
||||||
|
auto& shared_memory = system.Kernel().GetHidSharedMem();
|
||||||
|
|
||||||
|
data[index].shared_memory_handle = &shared_memory;
|
||||||
|
data[index].flag.is_assigned.Assign(true);
|
||||||
|
// TODO: InitializeSixAxisControllerConfig(false);
|
||||||
|
active_aruid = aruid;
|
||||||
|
return ResultSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result AppletResource::RegisterAppletResourceUserId(u64 aruid, bool enable_input) {
|
||||||
|
const u64 index = GetIndexFromAruid(aruid);
|
||||||
|
|
||||||
|
if (index < AruidIndexMax) {
|
||||||
|
return ResultAruidAlreadyRegistered;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t data_index = AruidIndexMax;
|
||||||
|
for (std::size_t i = 0; i < AruidIndexMax; i++) {
|
||||||
|
if (!data[i].flag.is_initialized) {
|
||||||
|
data_index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data_index == AruidIndexMax) {
|
||||||
|
return ResultAruidNoAvailableEntries;
|
||||||
|
}
|
||||||
|
|
||||||
|
AruidData& aruid_data = data[data_index];
|
||||||
|
|
||||||
|
aruid_data.aruid = aruid;
|
||||||
|
aruid_data.flag.is_initialized.Assign(true);
|
||||||
|
if (enable_input) {
|
||||||
|
aruid_data.flag.enable_pad_input.Assign(true);
|
||||||
|
aruid_data.flag.enable_six_axis_sensor.Assign(true);
|
||||||
|
aruid_data.flag.bit_18.Assign(true);
|
||||||
|
aruid_data.flag.enable_touchscreen.Assign(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
data_index = AruidIndexMax;
|
||||||
|
for (std::size_t i = 0; i < AruidIndexMax; i++) {
|
||||||
|
if (registration_list.flag[i] == RegistrationStatus::Initialized) {
|
||||||
|
if (registration_list.aruid[i] != aruid) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
data_index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (registration_list.flag[i] == RegistrationStatus::None) {
|
||||||
|
data_index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data_index == AruidIndexMax) {
|
||||||
|
return ResultSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
registration_list.flag[data_index] = RegistrationStatus::Initialized;
|
||||||
|
registration_list.aruid[data_index] = aruid;
|
||||||
|
|
||||||
|
return ResultSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletResource::UnregisterAppletResourceUserId(u64 aruid) {
|
||||||
|
u64 index = GetIndexFromAruid(aruid);
|
||||||
|
|
||||||
|
if (index < AruidIndexMax) {
|
||||||
|
if (data[index].flag.is_assigned) {
|
||||||
|
data[index].shared_memory_handle = nullptr;
|
||||||
|
data[index].flag.is_assigned.Assign(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
index = GetIndexFromAruid(aruid);
|
||||||
|
if (index < AruidIndexMax) {
|
||||||
|
DestroySevenSixAxisTransferMemory();
|
||||||
|
data[index].flag.raw = 0;
|
||||||
|
data[index].aruid = 0;
|
||||||
|
|
||||||
|
index = GetIndexFromAruid(aruid);
|
||||||
|
if (index < AruidIndexMax) {
|
||||||
|
registration_list.flag[index] = RegistrationStatus::PendingDelete;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 AppletResource::GetActiveAruid() {
|
||||||
|
return active_aruid;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result AppletResource::GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid) {
|
||||||
|
u64 index = GetIndexFromAruid(aruid);
|
||||||
|
if (index >= AruidIndexMax) {
|
||||||
|
return ResultAruidNotRegistered;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out_handle = data[index].shared_memory_handle;
|
||||||
|
return ResultSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 AppletResource::GetIndexFromAruid(u64 aruid) {
|
||||||
|
for (std::size_t i = 0; i < AruidIndexMax; i++) {
|
||||||
|
if (registration_list.flag[i] == RegistrationStatus::Initialized &&
|
||||||
|
registration_list.aruid[i] == aruid) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return AruidIndexMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result AppletResource::DestroySevenSixAxisTransferMemory() {
|
||||||
|
// TODO
|
||||||
|
return ResultSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletResource::EnableInput(u64 aruid, bool is_enabled) {
|
||||||
|
const u64 index = GetIndexFromAruid(aruid);
|
||||||
|
if (index >= AruidIndexMax) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
data[index].flag.enable_pad_input.Assign(is_enabled);
|
||||||
|
data[index].flag.enable_touchscreen.Assign(is_enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletResource::EnableSixAxisSensor(u64 aruid, bool is_enabled) {
|
||||||
|
const u64 index = GetIndexFromAruid(aruid);
|
||||||
|
if (index >= AruidIndexMax) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
data[index].flag.enable_six_axis_sensor.Assign(is_enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletResource::EnablePadInput(u64 aruid, bool is_enabled) {
|
||||||
|
const u64 index = GetIndexFromAruid(aruid);
|
||||||
|
if (index >= AruidIndexMax) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
data[index].flag.enable_pad_input.Assign(is_enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletResource::EnableTouchScreen(u64 aruid, bool is_enabled) {
|
||||||
|
const u64 index = GetIndexFromAruid(aruid);
|
||||||
|
if (index >= AruidIndexMax) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
data[index].flag.enable_touchscreen.Assign(is_enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletResource::SetIsPalmaConnectable(u64 aruid, bool is_connectable) {
|
||||||
|
const u64 index = GetIndexFromAruid(aruid);
|
||||||
|
if (index >= AruidIndexMax) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
data[index].flag.is_palma_connectable.Assign(is_connectable);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletResource::EnablePalmaBoostMode(u64 aruid, bool is_enabled) {
|
||||||
|
const u64 index = GetIndexFromAruid(aruid);
|
||||||
|
if (index >= AruidIndexMax) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
data[index].flag.enable_palma_boost_mode.Assign(is_enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Service::HID
|
87
src/core/hle/service/hid/controllers/applet_resource.h
Normal file
87
src/core/hle/service/hid/controllers/applet_resource.h
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
#include "common/bit_field.h"
|
||||||
|
#include "common/common_types.h"
|
||||||
|
#include "core/hle/result.h"
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
class System;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
class KSharedMemory;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Service::HID {
|
||||||
|
class AppletResource {
|
||||||
|
public:
|
||||||
|
explicit AppletResource(Core::System& system_);
|
||||||
|
~AppletResource();
|
||||||
|
|
||||||
|
Result CreateAppletResource(u64 aruid);
|
||||||
|
|
||||||
|
Result RegisterAppletResourceUserId(u64 aruid, bool enable_input);
|
||||||
|
void UnregisterAppletResourceUserId(u64 aruid);
|
||||||
|
|
||||||
|
u64 GetActiveAruid();
|
||||||
|
Result GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid);
|
||||||
|
|
||||||
|
u64 GetIndexFromAruid(u64 aruid);
|
||||||
|
|
||||||
|
Result DestroySevenSixAxisTransferMemory();
|
||||||
|
|
||||||
|
void EnableInput(u64 aruid, bool is_enabled);
|
||||||
|
void EnableSixAxisSensor(u64 aruid, bool is_enabled);
|
||||||
|
void EnablePadInput(u64 aruid, bool is_enabled);
|
||||||
|
void EnableTouchScreen(u64 aruid, bool is_enabled);
|
||||||
|
void SetIsPalmaConnectable(u64 aruid, bool is_connectable);
|
||||||
|
void EnablePalmaBoostMode(u64 aruid, bool is_enabled);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static constexpr std::size_t AruidIndexMax = 0x20;
|
||||||
|
|
||||||
|
enum RegistrationStatus : u32 {
|
||||||
|
None,
|
||||||
|
Initialized,
|
||||||
|
PendingDelete,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DataStatusFlag {
|
||||||
|
union {
|
||||||
|
u32 raw{};
|
||||||
|
|
||||||
|
BitField<0, 1, u32> is_initialized;
|
||||||
|
BitField<1, 1, u32> is_assigned;
|
||||||
|
BitField<16, 1, u32> enable_pad_input;
|
||||||
|
BitField<17, 1, u32> enable_six_axis_sensor;
|
||||||
|
BitField<18, 1, u32> bit_18;
|
||||||
|
BitField<19, 1, u32> is_palma_connectable;
|
||||||
|
BitField<20, 1, u32> enable_palma_boost_mode;
|
||||||
|
BitField<21, 1, u32> enable_touchscreen;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AruidRegisterList {
|
||||||
|
std::array<RegistrationStatus, AruidIndexMax> flag{};
|
||||||
|
std::array<u64, AruidIndexMax> aruid{};
|
||||||
|
};
|
||||||
|
static_assert(sizeof(AruidRegisterList) == 0x180, "AruidRegisterList is an invalid size");
|
||||||
|
|
||||||
|
struct AruidData {
|
||||||
|
DataStatusFlag flag{};
|
||||||
|
u64 aruid{};
|
||||||
|
Kernel::KSharedMemory* shared_memory_handle{nullptr};
|
||||||
|
};
|
||||||
|
|
||||||
|
u64 active_aruid{};
|
||||||
|
AruidRegisterList registration_list{};
|
||||||
|
std::array<AruidData, AruidIndexMax> data{};
|
||||||
|
|
||||||
|
Core::System& system;
|
||||||
|
};
|
||||||
|
} // namespace Service::HID
|
@ -19,6 +19,11 @@ constexpr Result NpadIsSameType{ErrorModule::HID, 602};
|
|||||||
constexpr Result InvalidNpadId{ErrorModule::HID, 709};
|
constexpr Result InvalidNpadId{ErrorModule::HID, 709};
|
||||||
constexpr Result NpadNotConnected{ErrorModule::HID, 710};
|
constexpr Result NpadNotConnected{ErrorModule::HID, 710};
|
||||||
constexpr Result InvalidArraySize{ErrorModule::HID, 715};
|
constexpr Result InvalidArraySize{ErrorModule::HID, 715};
|
||||||
|
|
||||||
|
constexpr Result ResultAruidNoAvailableEntries{ErrorModule::HID, 1044};
|
||||||
|
constexpr Result ResultAruidAlreadyRegistered{ErrorModule::HID, 1046};
|
||||||
|
constexpr Result ResultAruidNotRegistered{ErrorModule::HID, 1047};
|
||||||
|
|
||||||
constexpr Result InvalidPalmaHandle{ErrorModule::HID, 3302};
|
constexpr Result InvalidPalmaHandle{ErrorModule::HID, 3302};
|
||||||
|
|
||||||
} // namespace Service::HID
|
} // namespace Service::HID
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include "core/hle/kernel/k_process.h"
|
||||||
|
#include "core/hle/kernel/kernel.h"
|
||||||
#include "core/hle/service/hid/hid.h"
|
#include "core/hle/service/hid/hid.h"
|
||||||
#include "core/hle/service/hid/hid_debug_server.h"
|
#include "core/hle/service/hid/hid_debug_server.h"
|
||||||
#include "core/hle/service/hid/hid_firmware_settings.h"
|
#include "core/hle/service/hid/hid_firmware_settings.h"
|
||||||
@ -20,6 +22,12 @@ void LoopProcess(Core::System& system) {
|
|||||||
std::shared_ptr<HidFirmwareSettings> firmware_settings =
|
std::shared_ptr<HidFirmwareSettings> firmware_settings =
|
||||||
std::make_shared<HidFirmwareSettings>();
|
std::make_shared<HidFirmwareSettings>();
|
||||||
|
|
||||||
|
// TODO: Remove this hack until this service is emulated properly.
|
||||||
|
const auto process_list = system.Kernel().GetProcessList();
|
||||||
|
if (!process_list.empty()) {
|
||||||
|
resouce_manager->RegisterAppletResourceUserId(process_list[0]->GetId(), true);
|
||||||
|
}
|
||||||
|
|
||||||
server_manager->RegisterNamedService(
|
server_manager->RegisterNamedService(
|
||||||
"hid", std::make_shared<IHidServer>(system, resouce_manager, firmware_settings));
|
"hid", std::make_shared<IHidServer>(system, resouce_manager, firmware_settings));
|
||||||
server_manager->RegisterNamedService(
|
server_manager->RegisterNamedService(
|
||||||
|
@ -224,8 +224,13 @@ void IHidServer::CreateAppletResource(HLERequestContext& ctx) {
|
|||||||
|
|
||||||
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
|
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
|
||||||
|
|
||||||
|
Result result = GetResourceManager()->CreateAppletResource(applet_resource_user_id);
|
||||||
|
if (result.IsSuccess()) {
|
||||||
|
result = GetResourceManager()->GetNpad()->Activate(applet_resource_user_id);
|
||||||
|
}
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
||||||
rb.Push(ResultSuccess);
|
rb.Push(result);
|
||||||
rb.PushIpcInterface<IAppletResource>(system, resource_manager);
|
rb.PushIpcInterface<IAppletResource>(system, resource_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "core/hid/hid_core.h"
|
#include "core/hid/hid_core.h"
|
||||||
#include "core/hle/service/hid/controllers/npad.h"
|
#include "core/hle/service/hid/controllers/npad.h"
|
||||||
|
#include "core/hle/service/hid/controllers/palma.h"
|
||||||
#include "core/hle/service/hid/controllers/touchscreen.h"
|
#include "core/hle/service/hid/controllers/touchscreen.h"
|
||||||
#include "core/hle/service/hid/errors.h"
|
#include "core/hle/service/hid/errors.h"
|
||||||
#include "core/hle/service/hid/hid_system_server.h"
|
#include "core/hle/service/hid/hid_system_server.h"
|
||||||
@ -63,13 +64,13 @@ IHidSystemServer::IHidSystemServer(Core::System& system_, std::shared_ptr<Resour
|
|||||||
{329, nullptr, "DetachAbstractedPadAll"},
|
{329, nullptr, "DetachAbstractedPadAll"},
|
||||||
{330, nullptr, "CheckAbstractedPadConnection"},
|
{330, nullptr, "CheckAbstractedPadConnection"},
|
||||||
{500, nullptr, "SetAppletResourceUserId"},
|
{500, nullptr, "SetAppletResourceUserId"},
|
||||||
{501, nullptr, "RegisterAppletResourceUserId"},
|
{501, &IHidSystemServer::RegisterAppletResourceUserId, "RegisterAppletResourceUserId"},
|
||||||
{502, nullptr, "UnregisterAppletResourceUserId"},
|
{502, &IHidSystemServer::UnregisterAppletResourceUserId, "UnregisterAppletResourceUserId"},
|
||||||
{503, nullptr, "EnableAppletToGetInput"},
|
{503, &IHidSystemServer::EnableAppletToGetInput, "EnableAppletToGetInput"},
|
||||||
{504, nullptr, "SetAruidValidForVibration"},
|
{504, nullptr, "SetAruidValidForVibration"},
|
||||||
{505, nullptr, "EnableAppletToGetSixAxisSensor"},
|
{505, &IHidSystemServer::EnableAppletToGetSixAxisSensor, "EnableAppletToGetSixAxisSensor"},
|
||||||
{506, nullptr, "EnableAppletToGetPadInput"},
|
{506, &IHidSystemServer::EnableAppletToGetPadInput, "EnableAppletToGetPadInput"},
|
||||||
{507, nullptr, "EnableAppletToGetTouchScreen"},
|
{507, &IHidSystemServer::EnableAppletToGetTouchScreen, "EnableAppletToGetTouchScreen"},
|
||||||
{510, nullptr, "SetVibrationMasterVolume"},
|
{510, nullptr, "SetVibrationMasterVolume"},
|
||||||
{511, nullptr, "GetVibrationMasterVolume"},
|
{511, nullptr, "GetVibrationMasterVolume"},
|
||||||
{512, nullptr, "BeginPermitVibrationSession"},
|
{512, nullptr, "BeginPermitVibrationSession"},
|
||||||
@ -420,6 +421,129 @@ void IHidSystemServer::GetIrSensorState(HLERequestContext& ctx) {
|
|||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
rb.Push(ResultSuccess);
|
rb.Push(ResultSuccess);
|
||||||
}
|
}
|
||||||
|
void IHidSystemServer::RegisterAppletResourceUserId(HLERequestContext& ctx) {
|
||||||
|
IPC::RequestParser rp{ctx};
|
||||||
|
struct Parameters {
|
||||||
|
bool enable_input;
|
||||||
|
INSERT_PADDING_WORDS_NOINIT(1);
|
||||||
|
u64 applet_resource_user_id;
|
||||||
|
};
|
||||||
|
static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
|
||||||
|
|
||||||
|
const auto parameters{rp.PopRaw<Parameters>()};
|
||||||
|
|
||||||
|
LOG_INFO(Service_HID, "called, enable_input={}, applet_resource_user_id={}",
|
||||||
|
parameters.enable_input, parameters.applet_resource_user_id);
|
||||||
|
|
||||||
|
Result result = GetResourceManager()->RegisterAppletResourceUserId(
|
||||||
|
parameters.applet_resource_user_id, parameters.enable_input);
|
||||||
|
|
||||||
|
if (result.IsSuccess()) {
|
||||||
|
// result = GetResourceManager()->GetNpad()->RegisterAppletResourceUserId(
|
||||||
|
// parameters.applet_resource_user_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
|
rb.Push(ResultSuccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IHidSystemServer::UnregisterAppletResourceUserId(HLERequestContext& ctx) {
|
||||||
|
IPC::RequestParser rp{ctx};
|
||||||
|
u64 applet_resource_user_id{rp.Pop<u64>()};
|
||||||
|
|
||||||
|
LOG_INFO(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
|
||||||
|
|
||||||
|
GetResourceManager()->UnregisterAppletResourceUserId(applet_resource_user_id);
|
||||||
|
// GetResourceManager()->GetNpad()->UnregisterAppletResourceUserId(applet_resource_user_id);
|
||||||
|
// GetResourceManager()->GetPalma()->UnregisterAppletResourceUserId(applet_resource_user_id);
|
||||||
|
|
||||||
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
|
rb.Push(ResultSuccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IHidSystemServer::EnableAppletToGetInput(HLERequestContext& ctx) {
|
||||||
|
IPC::RequestParser rp{ctx};
|
||||||
|
struct Parameters {
|
||||||
|
bool is_enabled;
|
||||||
|
INSERT_PADDING_WORDS_NOINIT(1);
|
||||||
|
u64 applet_resource_user_id;
|
||||||
|
};
|
||||||
|
static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
|
||||||
|
|
||||||
|
const auto parameters{rp.PopRaw<Parameters>()};
|
||||||
|
|
||||||
|
LOG_INFO(Service_HID, "called, is_enabled={}, applet_resource_user_id={}",
|
||||||
|
parameters.is_enabled, parameters.applet_resource_user_id);
|
||||||
|
|
||||||
|
GetResourceManager()->EnableInput(parameters.applet_resource_user_id, parameters.is_enabled);
|
||||||
|
// GetResourceManager()->GetNpad()->EnableInput(parameters.applet_resource_user_id);
|
||||||
|
|
||||||
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
|
rb.Push(ResultSuccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IHidSystemServer::EnableAppletToGetSixAxisSensor(HLERequestContext& ctx) {
|
||||||
|
IPC::RequestParser rp{ctx};
|
||||||
|
struct Parameters {
|
||||||
|
bool is_enabled;
|
||||||
|
INSERT_PADDING_WORDS_NOINIT(1);
|
||||||
|
u64 applet_resource_user_id;
|
||||||
|
};
|
||||||
|
static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
|
||||||
|
|
||||||
|
const auto parameters{rp.PopRaw<Parameters>()};
|
||||||
|
|
||||||
|
LOG_INFO(Service_HID, "called, is_enabled={}, applet_resource_user_id={}",
|
||||||
|
parameters.is_enabled, parameters.applet_resource_user_id);
|
||||||
|
|
||||||
|
GetResourceManager()->EnableTouchScreen(parameters.applet_resource_user_id,
|
||||||
|
parameters.is_enabled);
|
||||||
|
|
||||||
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
|
rb.Push(ResultSuccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IHidSystemServer::EnableAppletToGetPadInput(HLERequestContext& ctx) {
|
||||||
|
IPC::RequestParser rp{ctx};
|
||||||
|
struct Parameters {
|
||||||
|
bool is_enabled;
|
||||||
|
INSERT_PADDING_WORDS_NOINIT(1);
|
||||||
|
u64 applet_resource_user_id;
|
||||||
|
};
|
||||||
|
static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
|
||||||
|
|
||||||
|
const auto parameters{rp.PopRaw<Parameters>()};
|
||||||
|
|
||||||
|
LOG_INFO(Service_HID, "called, is_enabled={}, applet_resource_user_id={}",
|
||||||
|
parameters.is_enabled, parameters.applet_resource_user_id);
|
||||||
|
|
||||||
|
GetResourceManager()->EnablePadInput(parameters.applet_resource_user_id, parameters.is_enabled);
|
||||||
|
// GetResourceManager()->GetNpad()->EnableInput(parameters.applet_resource_user_id);
|
||||||
|
|
||||||
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
|
rb.Push(ResultSuccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IHidSystemServer::EnableAppletToGetTouchScreen(HLERequestContext& ctx) {
|
||||||
|
IPC::RequestParser rp{ctx};
|
||||||
|
struct Parameters {
|
||||||
|
bool is_enabled;
|
||||||
|
INSERT_PADDING_WORDS_NOINIT(1);
|
||||||
|
u64 applet_resource_user_id;
|
||||||
|
};
|
||||||
|
static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
|
||||||
|
|
||||||
|
const auto parameters{rp.PopRaw<Parameters>()};
|
||||||
|
|
||||||
|
LOG_INFO(Service_HID, "called, is_enabled={}, applet_resource_user_id={}",
|
||||||
|
parameters.is_enabled, parameters.applet_resource_user_id);
|
||||||
|
|
||||||
|
GetResourceManager()->EnableTouchScreen(parameters.applet_resource_user_id,
|
||||||
|
parameters.is_enabled);
|
||||||
|
|
||||||
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
|
rb.Push(ResultSuccess);
|
||||||
|
}
|
||||||
|
|
||||||
void IHidSystemServer::AcquireConnectionTriggerTimeoutEvent(HLERequestContext& ctx) {
|
void IHidSystemServer::AcquireConnectionTriggerTimeoutEvent(HLERequestContext& ctx) {
|
||||||
LOG_INFO(Service_AM, "(STUBBED) called");
|
LOG_INFO(Service_AM, "(STUBBED) called");
|
||||||
|
@ -38,6 +38,12 @@ private:
|
|||||||
void HasLeftRightBattery(HLERequestContext& ctx);
|
void HasLeftRightBattery(HLERequestContext& ctx);
|
||||||
void GetUniquePadsFromNpad(HLERequestContext& ctx);
|
void GetUniquePadsFromNpad(HLERequestContext& ctx);
|
||||||
void GetIrSensorState(HLERequestContext& ctx);
|
void GetIrSensorState(HLERequestContext& ctx);
|
||||||
|
void RegisterAppletResourceUserId(HLERequestContext& ctx);
|
||||||
|
void UnregisterAppletResourceUserId(HLERequestContext& ctx);
|
||||||
|
void EnableAppletToGetInput(HLERequestContext& ctx);
|
||||||
|
void EnableAppletToGetSixAxisSensor(HLERequestContext& ctx);
|
||||||
|
void EnableAppletToGetPadInput(HLERequestContext& ctx);
|
||||||
|
void EnableAppletToGetTouchScreen(HLERequestContext& ctx);
|
||||||
void AcquireConnectionTriggerTimeoutEvent(HLERequestContext& ctx);
|
void AcquireConnectionTriggerTimeoutEvent(HLERequestContext& ctx);
|
||||||
void AcquireDeviceRegisteredEventForControllerSupport(HLERequestContext& ctx);
|
void AcquireDeviceRegisteredEventForControllerSupport(HLERequestContext& ctx);
|
||||||
void GetRegisteredDevices(HLERequestContext& ctx);
|
void GetRegisteredDevices(HLERequestContext& ctx);
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "core/hle/service/hid/resource_manager.h"
|
#include "core/hle/service/hid/resource_manager.h"
|
||||||
#include "core/hle/service/ipc_helpers.h"
|
#include "core/hle/service/ipc_helpers.h"
|
||||||
|
|
||||||
|
#include "core/hle/service/hid/controllers/applet_resource.h"
|
||||||
#include "core/hle/service/hid/controllers/console_six_axis.h"
|
#include "core/hle/service/hid/controllers/console_six_axis.h"
|
||||||
#include "core/hle/service/hid/controllers/debug_pad.h"
|
#include "core/hle/service/hid/controllers/debug_pad.h"
|
||||||
#include "core/hle/service/hid/controllers/gesture.h"
|
#include "core/hle/service/hid/controllers/gesture.h"
|
||||||
@ -33,7 +34,9 @@ constexpr auto mouse_keyboard_update_ns = std::chrono::nanoseconds{8 * 1000 * 10
|
|||||||
constexpr auto motion_update_ns = std::chrono::nanoseconds{5 * 1000 * 1000}; // (5ms, 200Hz)
|
constexpr auto motion_update_ns = std::chrono::nanoseconds{5 * 1000 * 1000}; // (5ms, 200Hz)
|
||||||
|
|
||||||
ResourceManager::ResourceManager(Core::System& system_)
|
ResourceManager::ResourceManager(Core::System& system_)
|
||||||
: system{system_}, service_context{system_, "hid"} {}
|
: system{system_}, service_context{system_, "hid"} {
|
||||||
|
applet_resource = std::make_shared<AppletResource>(system);
|
||||||
|
}
|
||||||
|
|
||||||
ResourceManager::~ResourceManager() = default;
|
ResourceManager::~ResourceManager() = default;
|
||||||
|
|
||||||
@ -77,6 +80,11 @@ void ResourceManager::Initialize() {
|
|||||||
system.HIDCore().ReloadInputDevices();
|
system.HIDCore().ReloadInputDevices();
|
||||||
is_initialized = true;
|
is_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<AppletResource> ResourceManager::GetAppletResource() const {
|
||||||
|
return applet_resource;
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<CaptureButton> ResourceManager::GetCaptureButton() const {
|
std::shared_ptr<CaptureButton> ResourceManager::GetCaptureButton() const {
|
||||||
return capture_button;
|
return capture_button;
|
||||||
}
|
}
|
||||||
@ -137,6 +145,46 @@ std::shared_ptr<UniquePad> ResourceManager::GetUniquePad() const {
|
|||||||
return unique_pad;
|
return unique_pad;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result ResourceManager::CreateAppletResource(u64 aruid) {
|
||||||
|
std::scoped_lock lock{shared_mutex};
|
||||||
|
return applet_resource->CreateAppletResource(aruid);
|
||||||
|
}
|
||||||
|
|
||||||
|
Result ResourceManager::RegisterAppletResourceUserId(u64 aruid, bool bool_value) {
|
||||||
|
std::scoped_lock lock{shared_mutex};
|
||||||
|
return applet_resource->RegisterAppletResourceUserId(aruid, bool_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResourceManager::UnregisterAppletResourceUserId(u64 aruid) {
|
||||||
|
std::scoped_lock lock{shared_mutex};
|
||||||
|
applet_resource->UnregisterAppletResourceUserId(aruid);
|
||||||
|
}
|
||||||
|
|
||||||
|
Result ResourceManager::GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid) {
|
||||||
|
std::scoped_lock lock{shared_mutex};
|
||||||
|
return applet_resource->GetSharedMemoryHandle(out_handle, aruid);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResourceManager::EnableInput(u64 aruid, bool is_enabled) {
|
||||||
|
std::scoped_lock lock{shared_mutex};
|
||||||
|
applet_resource->EnableInput(aruid, is_enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResourceManager::EnableSixAxisSensor(u64 aruid, bool is_enabled) {
|
||||||
|
std::scoped_lock lock{shared_mutex};
|
||||||
|
applet_resource->EnableSixAxisSensor(aruid, is_enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResourceManager::EnablePadInput(u64 aruid, bool is_enabled) {
|
||||||
|
std::scoped_lock lock{shared_mutex};
|
||||||
|
applet_resource->EnablePadInput(aruid, is_enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResourceManager::EnableTouchScreen(u64 aruid, bool is_enabled) {
|
||||||
|
std::scoped_lock lock{shared_mutex};
|
||||||
|
applet_resource->EnableTouchScreen(aruid, is_enabled);
|
||||||
|
}
|
||||||
|
|
||||||
void ResourceManager::UpdateControllers(std::uintptr_t user_data,
|
void ResourceManager::UpdateControllers(std::uintptr_t user_data,
|
||||||
std::chrono::nanoseconds ns_late) {
|
std::chrono::nanoseconds ns_late) {
|
||||||
auto& core_timing = system.CoreTiming();
|
auto& core_timing = system.CoreTiming();
|
||||||
@ -172,14 +220,12 @@ void ResourceManager::UpdateMotion(std::uintptr_t user_data, std::chrono::nanose
|
|||||||
}
|
}
|
||||||
|
|
||||||
IAppletResource::IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource)
|
IAppletResource::IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource)
|
||||||
: ServiceFramework{system_, "IAppletResource"} {
|
: ServiceFramework{system_, "IAppletResource"}, resource_manager{resource} {
|
||||||
static const FunctionInfo functions[] = {
|
static const FunctionInfo functions[] = {
|
||||||
{0, &IAppletResource::GetSharedMemoryHandle, "GetSharedMemoryHandle"},
|
{0, &IAppletResource::GetSharedMemoryHandle, "GetSharedMemoryHandle"},
|
||||||
};
|
};
|
||||||
RegisterHandlers(functions);
|
RegisterHandlers(functions);
|
||||||
|
|
||||||
resource->Initialize();
|
|
||||||
|
|
||||||
// Register update callbacks
|
// Register update callbacks
|
||||||
npad_update_event = Core::Timing::CreateEvent(
|
npad_update_event = Core::Timing::CreateEvent(
|
||||||
"HID::UpdatePadCallback",
|
"HID::UpdatePadCallback",
|
||||||
@ -233,9 +279,13 @@ IAppletResource::~IAppletResource() {
|
|||||||
void IAppletResource::GetSharedMemoryHandle(HLERequestContext& ctx) {
|
void IAppletResource::GetSharedMemoryHandle(HLERequestContext& ctx) {
|
||||||
LOG_DEBUG(Service_HID, "called");
|
LOG_DEBUG(Service_HID, "called");
|
||||||
|
|
||||||
|
Kernel::KSharedMemory* handle;
|
||||||
|
const u64 applet_resource_user_id = resource_manager->GetAppletResource()->GetActiveAruid();
|
||||||
|
const auto result = resource_manager->GetSharedMemoryHandle(&handle, applet_resource_user_id);
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2, 1};
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
||||||
rb.Push(ResultSuccess);
|
rb.Push(result);
|
||||||
rb.PushCopyObjects(&system.Kernel().GetHidSharedMem());
|
rb.PushCopyObjects(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Service::HID
|
} // namespace Service::HID
|
||||||
|
@ -6,11 +6,20 @@
|
|||||||
#include "core/hle/service/kernel_helpers.h"
|
#include "core/hle/service/kernel_helpers.h"
|
||||||
#include "core/hle/service/service.h"
|
#include "core/hle/service/service.h"
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
class System;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Core::Timing {
|
namespace Core::Timing {
|
||||||
struct EventType;
|
struct EventType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
class KSharedMemory;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Service::HID {
|
namespace Service::HID {
|
||||||
|
class AppletResource;
|
||||||
class Controller_Stubbed;
|
class Controller_Stubbed;
|
||||||
class ConsoleSixAxis;
|
class ConsoleSixAxis;
|
||||||
class DebugPad;
|
class DebugPad;
|
||||||
@ -38,6 +47,7 @@ public:
|
|||||||
|
|
||||||
void Initialize();
|
void Initialize();
|
||||||
|
|
||||||
|
std::shared_ptr<AppletResource> GetAppletResource() const;
|
||||||
std::shared_ptr<CaptureButton> GetCaptureButton() const;
|
std::shared_ptr<CaptureButton> GetCaptureButton() const;
|
||||||
std::shared_ptr<ConsoleSixAxis> GetConsoleSixAxis() const;
|
std::shared_ptr<ConsoleSixAxis> GetConsoleSixAxis() const;
|
||||||
std::shared_ptr<DebugMouse> GetDebugMouse() const;
|
std::shared_ptr<DebugMouse> GetDebugMouse() const;
|
||||||
@ -54,6 +64,18 @@ public:
|
|||||||
std::shared_ptr<TouchScreen> GetTouchScreen() const;
|
std::shared_ptr<TouchScreen> GetTouchScreen() const;
|
||||||
std::shared_ptr<UniquePad> GetUniquePad() const;
|
std::shared_ptr<UniquePad> GetUniquePad() const;
|
||||||
|
|
||||||
|
Result CreateAppletResource(u64 aruid);
|
||||||
|
|
||||||
|
Result RegisterAppletResourceUserId(u64 aruid, bool bool_value);
|
||||||
|
void UnregisterAppletResourceUserId(u64 aruid);
|
||||||
|
|
||||||
|
Result GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid);
|
||||||
|
|
||||||
|
void EnableInput(u64 aruid, bool is_enabled);
|
||||||
|
void EnableSixAxisSensor(u64 aruid, bool is_enabled);
|
||||||
|
void EnablePadInput(u64 aruid, bool is_enabled);
|
||||||
|
void EnableTouchScreen(u64 aruid, bool is_enabled);
|
||||||
|
|
||||||
void UpdateControllers(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
|
void UpdateControllers(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
|
||||||
void UpdateNpad(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
|
void UpdateNpad(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
|
||||||
void UpdateMouseKeyboard(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
|
void UpdateMouseKeyboard(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
|
||||||
@ -62,6 +84,9 @@ public:
|
|||||||
private:
|
private:
|
||||||
bool is_initialized{false};
|
bool is_initialized{false};
|
||||||
|
|
||||||
|
mutable std::mutex shared_mutex;
|
||||||
|
std::shared_ptr<AppletResource> applet_resource = nullptr;
|
||||||
|
|
||||||
std::shared_ptr<CaptureButton> capture_button = nullptr;
|
std::shared_ptr<CaptureButton> capture_button = nullptr;
|
||||||
std::shared_ptr<ConsoleSixAxis> console_six_axis = nullptr;
|
std::shared_ptr<ConsoleSixAxis> console_six_axis = nullptr;
|
||||||
std::shared_ptr<DebugMouse> debug_mouse = nullptr;
|
std::shared_ptr<DebugMouse> debug_mouse = nullptr;
|
||||||
@ -106,6 +131,8 @@ private:
|
|||||||
std::shared_ptr<Core::Timing::EventType> default_update_event;
|
std::shared_ptr<Core::Timing::EventType> default_update_event;
|
||||||
std::shared_ptr<Core::Timing::EventType> mouse_keyboard_update_event;
|
std::shared_ptr<Core::Timing::EventType> mouse_keyboard_update_event;
|
||||||
std::shared_ptr<Core::Timing::EventType> motion_update_event;
|
std::shared_ptr<Core::Timing::EventType> motion_update_event;
|
||||||
|
|
||||||
|
std::shared_ptr<ResourceManager> resource_manager;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Service::HID
|
} // namespace Service::HID
|
||||||
|
@ -171,6 +171,7 @@ void MakeGraphicBuffer(android::BufferQueueProducer& producer, u32 slot, u32 han
|
|||||||
buffer->height = SharedBufferHeight;
|
buffer->height = SharedBufferHeight;
|
||||||
buffer->stride = SharedBufferBlockLinearStride;
|
buffer->stride = SharedBufferBlockLinearStride;
|
||||||
buffer->format = SharedBufferBlockLinearFormat;
|
buffer->format = SharedBufferBlockLinearFormat;
|
||||||
|
buffer->external_format = SharedBufferBlockLinearFormat;
|
||||||
buffer->buffer_id = handle;
|
buffer->buffer_id = handle;
|
||||||
buffer->offset = slot * SharedBufferSlotSize;
|
buffer->offset = slot * SharedBufferSlotSize;
|
||||||
ASSERT(producer.SetPreallocatedBuffer(slot, buffer) == android::Status::NoError);
|
ASSERT(producer.SetPreallocatedBuffer(slot, buffer) == android::Status::NoError);
|
||||||
|
@ -192,8 +192,6 @@ Result SM::GetServiceImpl(Kernel::KClientSession** out_client_session, HLEReques
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DEBUG(Service_SM, "called service={} -> session={}", name, session->GetId());
|
|
||||||
|
|
||||||
*out_client_session = session;
|
*out_client_session = session;
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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) {
|
|
||||||
glEnable(GL_FRAMEBUFFER_SRGB);
|
|
||||||
} else {
|
|
||||||
glDisable(GL_FRAMEBUFFER_SRGB);
|
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);
|
||||||
|
@ -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;
|
||||||
};
|
};
|
||||||
|
@ -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,
|
||||||
|
@ -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,
|
||||||
|
@ -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;
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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();
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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{};
|
||||||
};
|
};
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
||||||
|
Reference in New Issue
Block a user