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

View File

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

View File

@ -40,10 +40,15 @@ public:
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;
/**
* 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.
*/
@ -79,8 +84,11 @@ protected:
bool preload; ///< Whether the Applet is being preloaded.
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.
bool is_running = false;
/// Whether this applet is running.
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 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) {
is_running = true;
startup_param = parameter.buffer;
// 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);
frontend_applet->Setup(frontend_config);
is_running = true;
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) {
is_running = true;
startup_param = parameter.buffer;
// 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));
is_running = true;
return RESULT_SUCCESS;
}

View File

@ -1137,6 +1137,7 @@ void SVC::Break(u8 break_reason) {
break;
}
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

View File

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

View File

@ -19,6 +19,7 @@
#include "common/assert.h"
#include "common/common_types.h"
#include "common/file_util.h"
#include "video_core/regs.h"
#include "video_core/renderer_opengl/gl_shader_decompiler.h"
#include "video_core/renderer_opengl/gl_shader_gen.h"
@ -141,9 +142,12 @@ private:
/// Returns if the cache can be used
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();
/// 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
void SavePrecompiledHeaderToVirtualPrecompiledCache();
@ -223,7 +227,8 @@ private:
u64 program_id{};
std::string title_id;
FileUtil::IOFile AppendPrecompiledFile();
FileUtil::IOFile transferable_file;
FileUtil::IOFile precompiled_file;
};
} // namespace OpenGL