Merge branch 'master' of https://github.com/GPUCode/citra into vulkan-2

This commit is contained in:
GPUCode
2023-03-26 11:50:15 +03:00
10 changed files with 71 additions and 50 deletions

View File

@ -1187,6 +1187,8 @@ void OpenFStream<std::ios_base::in>(
boost_iostreams<boost::iostreams::file_descriptor_source>& fstream, boost_iostreams<boost::iostreams::file_descriptor_source>& fstream,
const std::string& filename) { const std::string& filename) {
IOFile file(filename, "r"); IOFile file(filename, "r");
if (file.GetFd() == -1)
return;
int fd = dup(file.GetFd()); int fd = dup(file.GetFd());
if (fd == -1) if (fd == -1)
return; return;
@ -1199,6 +1201,8 @@ template <>
void OpenFStream<std::ios_base::out>( void OpenFStream<std::ios_base::out>(
boost_iostreams<boost::iostreams::file_descriptor_sink>& fstream, const std::string& filename) { boost_iostreams<boost::iostreams::file_descriptor_sink>& fstream, const std::string& filename) {
IOFile file(filename, "w"); IOFile file(filename, "w");
if (file.GetFd() == -1)
return;
int fd = dup(file.GetFd()); int fd = dup(file.GetFd());
if (fd == -1) if (fd == -1)
return; return;

View File

@ -80,6 +80,9 @@ ResultCode Applet::Create(Service::APT::AppletId id, Service::APT::AppletId pare
manager->FinishPreloadingLibraryApplet(id); manager->FinishPreloadingLibraryApplet(id);
} }
// Schedule the update event
Core::System::GetInstance().CoreTiming().ScheduleEvent(
usToCycles(applet_update_interval_us), applet_update_event, static_cast<u64>(id));
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }
@ -96,7 +99,9 @@ static void AppletUpdateEvent(u64 applet_id, s64 cycles_late) {
const auto applet = Applet::Get(id); const auto applet = Applet::Get(id);
ASSERT_MSG(applet != nullptr, "Applet doesn't exist! applet_id={:08X}", id); ASSERT_MSG(applet != nullptr, "Applet doesn't exist! applet_id={:08X}", id);
applet->Update(); if (applet->IsActive()) {
applet->Update();
}
// If the applet is still running after the last update, reschedule the event // If the applet is still running after the last update, reschedule the event
if (applet->IsRunning()) { if (applet->IsRunning()) {
@ -112,14 +117,16 @@ bool Applet::IsRunning() const {
return is_running; return is_running;
} }
bool Applet::IsActive() const {
return is_active;
}
ResultCode Applet::ReceiveParameter(const Service::APT::MessageParameter& parameter) { ResultCode Applet::ReceiveParameter(const Service::APT::MessageParameter& parameter) {
switch (parameter.signal) { switch (parameter.signal) {
case Service::APT::SignalType::Wakeup: { case Service::APT::SignalType::Wakeup: {
ResultCode result = Start(parameter); ResultCode result = Start(parameter);
if (!result.IsError()) { if (!result.IsError()) {
// Schedule the update event is_active = true;
Core::System::GetInstance().CoreTiming().ScheduleEvent(
usToCycles(applet_update_interval_us), applet_update_event, static_cast<u64>(id));
} }
return result; return result;
} }
@ -146,6 +153,7 @@ void Applet::CloseApplet(std::shared_ptr<Kernel::Object> object, const std::vect
LOG_ERROR(Service_APT, "called after destructing applet manager"); LOG_ERROR(Service_APT, "called after destructing applet manager");
} }
is_active = false;
is_running = false; is_running = false;
} }

View File

@ -40,10 +40,15 @@ public:
ResultCode ReceiveParameter(const Service::APT::MessageParameter& parameter); ResultCode ReceiveParameter(const Service::APT::MessageParameter& parameter);
/** /**
* Whether the applet is currently executing instead of the host application or not. * Whether the applet is currently running.
*/ */
[[nodiscard]] bool IsRunning() const; [[nodiscard]] bool IsRunning() const;
/**
* Whether the applet is currently active instead of the host application or not.
*/
[[nodiscard]] bool IsActive() const;
/** /**
* Handles an update tick for the Applet, lets it update the screen, send commands, etc. * Handles an update tick for the Applet, lets it update the screen, send commands, etc.
*/ */
@ -79,8 +84,11 @@ protected:
bool preload; ///< Whether the Applet is being preloaded. bool preload; ///< Whether the Applet is being preloaded.
std::shared_ptr<std::vector<u8>> heap_memory; ///< Heap memory for this Applet std::shared_ptr<std::vector<u8>> heap_memory; ///< Heap memory for this Applet
/// Whether this applet is currently running instead of the host application or not. /// Whether this applet is running.
bool is_running = false; bool is_running = true;
/// Whether this applet is currently active instead of the host application or not.
bool is_active = false;
void SendParameter(const Service::APT::MessageParameter& parameter); void SendParameter(const Service::APT::MessageParameter& parameter);
void CloseApplet(std::shared_ptr<Kernel::Object> object, const std::vector<u8>& buffer); void CloseApplet(std::shared_ptr<Kernel::Object> object, const std::vector<u8>& buffer);

View File

@ -44,7 +44,6 @@ ResultCode ErrEula::ReceiveParameterImpl(const Service::APT::MessageParameter& p
} }
ResultCode ErrEula::Start(const Service::APT::MessageParameter& parameter) { ResultCode ErrEula::Start(const Service::APT::MessageParameter& parameter) {
is_running = true;
startup_param = parameter.buffer; startup_param = parameter.buffer;
// TODO(Subv): Set the expected fields in the response buffer before resending it to the // TODO(Subv): Set the expected fields in the response buffer before resending it to the

View File

@ -65,7 +65,6 @@ ResultCode MiiSelector::Start(const Service::APT::MessageParameter& parameter) {
MiiSelectorConfig frontend_config = ToFrontendConfig(config); MiiSelectorConfig frontend_config = ToFrontendConfig(config);
frontend_applet->Setup(frontend_config); frontend_applet->Setup(frontend_config);
is_running = true;
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }

View File

@ -44,7 +44,6 @@ ResultCode Mint::ReceiveParameterImpl(const Service::APT::MessageParameter& para
} }
ResultCode Mint::Start(const Service::APT::MessageParameter& parameter) { ResultCode Mint::Start(const Service::APT::MessageParameter& parameter) {
is_running = true;
startup_param = parameter.buffer; startup_param = parameter.buffer;
// TODO(Subv): Set the expected fields in the response buffer before resending it to the // TODO(Subv): Set the expected fields in the response buffer before resending it to the

View File

@ -106,7 +106,6 @@ ResultCode SoftwareKeyboard::Start(Service::APT::MessageParameter const& paramet
frontend_applet->Execute(ToFrontendConfig(config)); frontend_applet->Execute(ToFrontendConfig(config));
is_running = true;
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }

View File

@ -1137,6 +1137,7 @@ void SVC::Break(u8 break_reason) {
break; break;
} }
LOG_CRITICAL(Debug_Emulated, "Break reason: {}", reason_str); LOG_CRITICAL(Debug_Emulated, "Break reason: {}", reason_str);
system.SetStatus(Core::System::ResultStatus::ErrorUnknown);
} }
/// Used to output a message on a debug hardware unit - does nothing on a retail unit /// Used to output a message on a debug hardware unit - does nothing on a retail unit

View File

@ -104,7 +104,10 @@ bool ShaderDiskCacheRaw::Save(FileUtil::IOFile& file) const {
return true; return true;
} }
ShaderDiskCache::ShaderDiskCache(bool separable) : separable{separable} {} ShaderDiskCache::ShaderDiskCache(bool separable)
: separable{separable}, transferable_file(AppendTransferableFile()),
// seperable shaders use the virtual precompile file, that already has a header.
precompiled_file(AppendPrecompiledFile(!separable)) {}
std::optional<std::vector<ShaderDiskCacheRaw>> ShaderDiskCache::LoadTransferable() { std::optional<std::vector<ShaderDiskCacheRaw>> ShaderDiskCache::LoadTransferable() {
const bool has_title_id = GetProgramID() != 0; const bool has_title_id = GetProgramID() != 0;
@ -114,15 +117,14 @@ std::optional<std::vector<ShaderDiskCacheRaw>> ShaderDiskCache::LoadTransferable
} }
tried_to_load = true; tried_to_load = true;
FileUtil::IOFile file(GetTransferablePath(), "rb"); if (transferable_file.GetSize() == 0) {
if (!file.IsOpen()) {
LOG_INFO(Render_OpenGL, "No transferable shader cache found for game with title id={}", LOG_INFO(Render_OpenGL, "No transferable shader cache found for game with title id={}",
GetTitleID()); GetTitleID());
return std::nullopt; return std::nullopt;
} }
u32 version{}; u32 version{};
if (file.ReadBytes(&version, sizeof(version)) != sizeof(version)) { if (transferable_file.ReadBytes(&version, sizeof(version)) != sizeof(version)) {
LOG_ERROR(Render_OpenGL, LOG_ERROR(Render_OpenGL,
"Failed to get transferable cache version for title id={} - skipping", "Failed to get transferable cache version for title id={} - skipping",
GetTitleID()); GetTitleID());
@ -131,7 +133,6 @@ std::optional<std::vector<ShaderDiskCacheRaw>> ShaderDiskCache::LoadTransferable
if (version < NativeVersion) { if (version < NativeVersion) {
LOG_INFO(Render_OpenGL, "Transferable shader cache is old - removing"); LOG_INFO(Render_OpenGL, "Transferable shader cache is old - removing");
file.Close();
InvalidateAll(); InvalidateAll();
return std::nullopt; return std::nullopt;
} }
@ -143,9 +144,9 @@ std::optional<std::vector<ShaderDiskCacheRaw>> ShaderDiskCache::LoadTransferable
// Version is valid, load the shaders // Version is valid, load the shaders
std::vector<ShaderDiskCacheRaw> raws; std::vector<ShaderDiskCacheRaw> raws;
while (file.Tell() < file.GetSize()) { while (transferable_file.Tell() < transferable_file.GetSize()) {
TransferableEntryKind kind{}; TransferableEntryKind kind{};
if (file.ReadBytes(&kind, sizeof(u32)) != sizeof(u32)) { if (transferable_file.ReadBytes(&kind, sizeof(u32)) != sizeof(u32)) {
LOG_ERROR(Render_OpenGL, "Failed to read transferable file - skipping"); LOG_ERROR(Render_OpenGL, "Failed to read transferable file - skipping");
return std::nullopt; return std::nullopt;
} }
@ -153,7 +154,7 @@ std::optional<std::vector<ShaderDiskCacheRaw>> ShaderDiskCache::LoadTransferable
switch (kind) { switch (kind) {
case TransferableEntryKind::Raw: { case TransferableEntryKind::Raw: {
ShaderDiskCacheRaw entry; ShaderDiskCacheRaw entry;
if (!entry.Load(file)) { if (!entry.Load(transferable_file)) {
LOG_ERROR(Render_OpenGL, "Failed to load transferable raw entry - skipping"); LOG_ERROR(Render_OpenGL, "Failed to load transferable raw entry - skipping");
return std::nullopt; return std::nullopt;
} }
@ -177,19 +178,17 @@ ShaderDiskCache::LoadPrecompiled(bool compressed) {
if (!IsUsable()) if (!IsUsable())
return {}; return {};
FileUtil::IOFile file(GetPrecompiledPath(), "rb"); if (precompiled_file.GetSize() == 0) {
if (!file.IsOpen()) {
LOG_INFO(Render_OpenGL, "No precompiled shader cache found for game with title id={}", LOG_INFO(Render_OpenGL, "No precompiled shader cache found for game with title id={}",
GetTitleID()); GetTitleID());
return {}; return {};
} }
const auto result = LoadPrecompiledFile(file, compressed); const auto result = LoadPrecompiledFile(precompiled_file, compressed);
if (!result) { if (!result) {
LOG_INFO(Render_OpenGL, LOG_INFO(Render_OpenGL,
"Failed to load precompiled cache for game with title id={} - removing", "Failed to load precompiled cache for game with title id={} - removing",
GetTitleID()); GetTitleID());
file.Close();
InvalidatePrecompiled(); InvalidatePrecompiled();
return {}; return {};
} }
@ -331,10 +330,13 @@ bool ShaderDiskCache::SaveDecompiledToCache(u64 unique_identifier,
} }
void ShaderDiskCache::InvalidateAll() { void ShaderDiskCache::InvalidateAll() {
transferable_file.Close();
if (!FileUtil::Delete(GetTransferablePath())) { if (!FileUtil::Delete(GetTransferablePath())) {
LOG_ERROR(Render_OpenGL, "Failed to invalidate transferable file={}", LOG_ERROR(Render_OpenGL, "Failed to invalidate transferable file={}",
GetTransferablePath()); GetTransferablePath());
} }
transferable_file = AppendTransferableFile();
InvalidatePrecompiled(); InvalidatePrecompiled();
} }
@ -342,9 +344,11 @@ void ShaderDiskCache::InvalidatePrecompiled() {
// Clear virtual precompiled cache file // Clear virtual precompiled cache file
decompressed_precompiled_cache.resize(0); decompressed_precompiled_cache.resize(0);
precompiled_file.Close();
if (!FileUtil::Delete(GetPrecompiledPath())) { if (!FileUtil::Delete(GetPrecompiledPath())) {
LOG_ERROR(Render_OpenGL, "Failed to invalidate precompiled file={}", GetPrecompiledPath()); LOG_ERROR(Render_OpenGL, "Failed to invalidate precompiled file={}", GetPrecompiledPath());
} }
precompiled_file = AppendPrecompiledFile(!separable);
} }
void ShaderDiskCache::SaveRaw(const ShaderDiskCacheRaw& entry) { void ShaderDiskCache::SaveRaw(const ShaderDiskCacheRaw& entry) {
@ -357,12 +361,9 @@ void ShaderDiskCache::SaveRaw(const ShaderDiskCacheRaw& entry) {
return; return;
} }
FileUtil::IOFile file = AppendTransferableFile(); if (transferable_file.WriteObject(TransferableEntryKind::Raw) != 1 ||
if (!file.IsOpen()) !entry.Save(transferable_file)) {
return;
if (file.WriteObject(TransferableEntryKind::Raw) != 1 || !entry.Save(file)) {
LOG_ERROR(Render_OpenGL, "Failed to save raw transferable cache entry - removing"); LOG_ERROR(Render_OpenGL, "Failed to save raw transferable cache entry - removing");
file.Close();
InvalidateAll(); InvalidateAll();
return; return;
} }
@ -413,10 +414,6 @@ void ShaderDiskCache::SaveDumpToFile(u64 unique_identifier, GLuint program, bool
if (!IsUsable()) if (!IsUsable())
return; return;
FileUtil::IOFile file = AppendPrecompiledFile();
if (!file.IsOpen())
return;
GLint binary_length{}; GLint binary_length{};
glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &binary_length); glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &binary_length);
@ -424,11 +421,11 @@ void ShaderDiskCache::SaveDumpToFile(u64 unique_identifier, GLuint program, bool
std::vector<u8> binary(binary_length); std::vector<u8> binary(binary_length);
glGetProgramBinary(program, binary_length, nullptr, &binary_format, binary.data()); glGetProgramBinary(program, binary_length, nullptr, &binary_format, binary.data());
if (file.WriteObject(static_cast<u32>(PrecompiledEntryKind::Dump)) != 1 || if (precompiled_file.WriteObject(static_cast<u32>(PrecompiledEntryKind::Dump)) != 1 ||
file.WriteObject(unique_identifier) != 1 || precompiled_file.WriteObject(unique_identifier) != 1 ||
file.WriteObject(static_cast<u32>(binary_format)) != 1 || precompiled_file.WriteObject(static_cast<u32>(binary_format)) != 1 ||
file.WriteObject(static_cast<u32>(binary_length)) != 1 || precompiled_file.WriteObject(static_cast<u32>(binary_length)) != 1 ||
file.WriteArray(binary.data(), binary.size()) != binary.size()) { precompiled_file.WriteArray(binary.data(), binary.size()) != binary.size()) {
LOG_ERROR(Render_OpenGL, "Failed to save binary program file in shader={:016x} - removing", LOG_ERROR(Render_OpenGL, "Failed to save binary program file in shader={:016x} - removing",
unique_identifier); unique_identifier);
InvalidatePrecompiled(); InvalidatePrecompiled();
@ -437,7 +434,7 @@ void ShaderDiskCache::SaveDumpToFile(u64 unique_identifier, GLuint program, bool
// SaveDecompiled is used only to store the accurate multiplication setting, a better way is to // SaveDecompiled is used only to store the accurate multiplication setting, a better way is to
// probably change the header in SaveDump // probably change the header in SaveDump
SaveDecompiledToFile(file, unique_identifier, {}, sanitize_mul); SaveDecompiledToFile(precompiled_file, unique_identifier, {}, sanitize_mul);
} }
bool ShaderDiskCache::IsUsable() const { bool ShaderDiskCache::IsUsable() const {
@ -451,7 +448,7 @@ FileUtil::IOFile ShaderDiskCache::AppendTransferableFile() {
const auto transferable_path{GetTransferablePath()}; const auto transferable_path{GetTransferablePath()};
const bool existed = FileUtil::Exists(transferable_path); const bool existed = FileUtil::Exists(transferable_path);
FileUtil::IOFile file(transferable_path, "ab"); FileUtil::IOFile file(transferable_path, "ab+");
if (!file.IsOpen()) { if (!file.IsOpen()) {
LOG_ERROR(Render_OpenGL, "Failed to open transferable cache in path={}", transferable_path); LOG_ERROR(Render_OpenGL, "Failed to open transferable cache in path={}", transferable_path);
return {}; return {};
@ -467,20 +464,21 @@ FileUtil::IOFile ShaderDiskCache::AppendTransferableFile() {
return file; return file;
} }
FileUtil::IOFile ShaderDiskCache::AppendPrecompiledFile() { FileUtil::IOFile ShaderDiskCache::AppendPrecompiledFile(bool write_header) {
if (!EnsureDirectories()) if (!EnsureDirectories())
return {}; return {};
const auto precompiled_path{GetPrecompiledPath()}; const auto precompiled_path{GetPrecompiledPath()};
const bool existed = FileUtil::Exists(precompiled_path); const bool existed = FileUtil::Exists(precompiled_path);
FileUtil::IOFile file(precompiled_path, "ab"); FileUtil::IOFile file(precompiled_path, "ab+");
if (!file.IsOpen()) { if (!file.IsOpen()) {
LOG_ERROR(Render_OpenGL, "Failed to open precompiled cache in path={}", precompiled_path); LOG_ERROR(Render_OpenGL, "Failed to open precompiled cache in path={}", precompiled_path);
return {}; return {};
} }
if (!existed || file.GetSize() == 0) {
// If the file didn't exist, write its version // If the file didn't exist, write its version
if (write_header && (!existed || file.GetSize() == 0)) {
const auto hash{GetShaderCacheVersionHash()}; const auto hash{GetShaderCacheVersionHash()};
if (file.WriteArray(hash.data(), hash.size()) != hash.size()) { if (file.WriteArray(hash.data(), hash.size()) != hash.size()) {
LOG_ERROR(Render_OpenGL, "Failed to write precompiled cache version in path={}", LOG_ERROR(Render_OpenGL, "Failed to write precompiled cache version in path={}",
@ -506,13 +504,14 @@ void ShaderDiskCache::SaveVirtualPrecompiledFile() {
decompressed_precompiled_cache.data(), decompressed_precompiled_cache.size()); decompressed_precompiled_cache.data(), decompressed_precompiled_cache.size());
const auto precompiled_path{GetPrecompiledPath()}; const auto precompiled_path{GetPrecompiledPath()};
FileUtil::IOFile file(precompiled_path, "wb");
if (!file.IsOpen()) { precompiled_file.Close();
LOG_ERROR(Render_OpenGL, "Failed to open precompiled cache in path={}", precompiled_path); if (!FileUtil::Delete(GetPrecompiledPath())) {
return; LOG_ERROR(Render_OpenGL, "Failed to invalidate precompiled file={}", GetPrecompiledPath());
} }
if (file.WriteBytes(compressed.data(), compressed.size()) != compressed.size()) { precompiled_file = AppendPrecompiledFile(!separable);
if (precompiled_file.WriteBytes(compressed.data(), compressed.size()) != compressed.size()) {
LOG_ERROR(Render_OpenGL, "Failed to write precompiled cache version in path={}", LOG_ERROR(Render_OpenGL, "Failed to write precompiled cache version in path={}",
precompiled_path); precompiled_path);
return; return;

View File

@ -19,6 +19,7 @@
#include "common/assert.h" #include "common/assert.h"
#include "common/common_types.h" #include "common/common_types.h"
#include "common/file_util.h"
#include "video_core/regs.h" #include "video_core/regs.h"
#include "video_core/renderer_opengl/gl_shader_decompiler.h" #include "video_core/renderer_opengl/gl_shader_decompiler.h"
#include "video_core/renderer_opengl/gl_shader_gen.h" #include "video_core/renderer_opengl/gl_shader_gen.h"
@ -141,9 +142,12 @@ private:
/// Returns if the cache can be used /// Returns if the cache can be used
bool IsUsable() const; bool IsUsable() const;
/// Opens current game's transferable file and write it's header if it doesn't exist /// Opens current game's transferable file and write it's header if it doesn't exist.
FileUtil::IOFile AppendTransferableFile(); FileUtil::IOFile AppendTransferableFile();
/// Opens current game's precompiled file and write it's header if it doesn't exist
FileUtil::IOFile AppendPrecompiledFile(bool write_header);
/// Save precompiled header to precompiled_cache_in_memory /// Save precompiled header to precompiled_cache_in_memory
void SavePrecompiledHeaderToVirtualPrecompiledCache(); void SavePrecompiledHeaderToVirtualPrecompiledCache();
@ -223,7 +227,8 @@ private:
u64 program_id{}; u64 program_id{};
std::string title_id; std::string title_id;
FileUtil::IOFile AppendPrecompiledFile(); FileUtil::IOFile transferable_file;
FileUtil::IOFile precompiled_file;
}; };
} // namespace OpenGL } // namespace OpenGL