diff --git a/src/common/config.cpp b/src/common/config.cpp index da028f9b7..72569a99a 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -113,6 +113,7 @@ static constexpr u64 total_entries = 55; int getVolumeSlider() { return volumeSlider; } + bool allowHDR() { return isHDRAllowed; } @@ -682,7 +683,8 @@ void load(const std::filesystem::path& path) { toml::find_or(gpu, "directMemoryAccess", directMemoryAccessEnabled); shouldDumpShaders = toml::find_or(gpu, "dumpShaders", shouldDumpShaders); shouldPatchShaders = toml::find_or(gpu, "patchShaders", shouldPatchShaders); - shaderCachePreloadEnabled = toml::find_or(gpu, "shaderCachePreload", shaderCachePreloadEnabled); + shaderCachePreloadEnabled = + toml::find_or(gpu, "shaderCachePreload", shaderCachePreloadEnabled); vblankDivider = toml::find_or(gpu, "vblankDivider", vblankDivider); isFullscreen = toml::find_or(gpu, "Fullscreen", isFullscreen); fullscreenMode = toml::find_or(gpu, "FullscreenMode", fullscreenMode); @@ -1065,6 +1067,7 @@ analog_deadzone = rightjoystick, 2, 127 override_controller_color = false, 0, 0, 255 )"; } + std::filesystem::path GetFoolproofKbmConfigFile(const std::string& game_id) { // Read configuration file of the game, and if it doesn't exist, generate it from default // If that doesn't exist either, generate that from getDefaultConfig() and try again @@ -1101,4 +1104,4 @@ std::filesystem::path GetFoolproofKbmConfigFile(const std::string& game_id) { return config_file; } -} // namespace Config +} // namespace Config \ No newline at end of file diff --git a/src/common/config.h b/src/common/config.h index 1c5401c38..fee2fd3ac 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -143,4 +143,4 @@ void setDefaultValues(); // todo: name and function location pending std::filesystem::path GetFoolproofKbmConfigFile(const std::string& game_id = ""); -}; // namespace Config +}; // namespace Config \ No newline at end of file diff --git a/src/common/serialization.h b/src/common/serialization.h index a05a1acab..efb50c889 100644 --- a/src/common/serialization.h +++ b/src/common/serialization.h @@ -5,6 +5,7 @@ #include #include + #include namespace cereal { diff --git a/src/emulator.cpp b/src/emulator.cpp index df57b96ca..edadac6fb 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -266,7 +266,8 @@ void Emulator::Run(std::filesystem::path file, const std::vector ar LOG_INFO(Loader, "Created shader cache directory: {}", SHADER_CACHE_DIR.string()); } ShaderCache::InitializeShaderCache(); - LOG_INFO(Loader, "{} shaders in cache {}", ShaderCache::shader_registry.size(), Config::getShaderCachePreloadEnabled() != 0 ? "(preloaded) " : ""); + LOG_INFO(Loader, "{} shaders in cache {}", ShaderCache::shader_registry.size(), + Config::getShaderCachePreloadEnabled() != 0 ? "(preloaded) " : ""); // Initialize kernel and library facilities. Libraries::InitHLELibs(&linker->GetHLESymbols()); diff --git a/src/video_core/renderer_vulkan/shader_cache.cpp b/src/video_core/renderer_vulkan/shader_cache.cpp index df895e684..8ff9a3006 100644 --- a/src/video_core/renderer_vulkan/shader_cache.cpp +++ b/src/video_core/renderer_vulkan/shader_cache.cpp @@ -1,33 +1,24 @@ // SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include +#include #include #include #include -#ifdef _WIN32 -#include -#else -#include -#include -#endif -#include + #include + +#include "common/config.h" #include "common/hash.h" #include "common/io_file.h" #include "common/logging/log.h" #include "common/path_util.h" -#include "common/config.h" +#include "shader_cache.h" #include "shader_recompiler/info.h" #include "shader_recompiler/ir/type.h" #include "shader_recompiler/specialization.h" #include "video_core/renderer_vulkan/shader_cache_serialization.h" -#include "shader_cache.h" - -using u64 = uint64_t; -using u32 = uint32_t; - namespace ShaderCache { u64 CalculateSpecializationHash(const Shader::StageSpecialization& spec) { @@ -252,7 +243,8 @@ bool CheckShaderCache(std::string shader_id) { } void InitializeShaderCache() { - if (!std::filesystem::exists(SHADER_CACHE_REGISTRY_PATH) || std::filesystem::file_size(SHADER_CACHE_REGISTRY_PATH) == 0) { + if (!std::filesystem::exists(SHADER_CACHE_REGISTRY_PATH) || + std::filesystem::file_size(SHADER_CACHE_REGISTRY_PATH) == 0) { return; } std::ifstream registry_file(SHADER_CACHE_REGISTRY_PATH, std::ios::binary); @@ -284,8 +276,7 @@ void GetShader(std::string shader_id, Shader::Info& info, std::vector& spv) auto& entry = shader_cache[shader_id]; spv = entry.first; resources = entry.second; - } - else { + } else { std::ifstream blob_file(SHADER_CACHE_BLOB_PATH, std::ios::binary); blob_file.seekg(shader_registry[shader_id], std::ios::beg); cereal::BinaryInputArchive ar(blob_file); diff --git a/src/video_core/renderer_vulkan/shader_cache.h b/src/video_core/renderer_vulkan/shader_cache.h index 2d8a3818c..975b8290e 100644 --- a/src/video_core/renderer_vulkan/shader_cache.h +++ b/src/video_core/renderer_vulkan/shader_cache.h @@ -7,27 +7,33 @@ #include #include +#include "common/elf_info.h" #include "shader_recompiler/info.h" #include "shader_recompiler/specialization.h" -#include "common/elf_info.h" namespace ShaderCache { -#define SHADER_CACHE_DIR (Common::FS::GetUserPath(Common::FS::PathType::ShaderDir) / "cache" / "portable") -#define SHADER_CACHE_BLOB_PATH (SHADER_CACHE_DIR / (std::string{Common::ElfInfo::Instance().GameSerial()} + "_shaders.bin")) -#define SHADER_CACHE_REGISTRY_PATH (SHADER_CACHE_DIR / (std::string{Common::ElfInfo::Instance().GameSerial()} + "_shaders_registry.bin")) +#define SHADER_CACHE_DIR \ + (Common::FS::GetUserPath(Common::FS::PathType::ShaderDir) / "cache" / "portable") + +#define SHADER_CACHE_BLOB_PATH \ + (SHADER_CACHE_DIR / (std::string{Common::ElfInfo::Instance().GameSerial()} + "_shaders.bin")) + +#define SHADER_CACHE_REGISTRY_PATH \ + (SHADER_CACHE_DIR / \ + (std::string{Common::ElfInfo::Instance().GameSerial()} + "_shaders_registry.bin")) inline std::map shader_registry; // shader_key:offset -inline std::map, std::string>> shader_cache; // only used when preload active // shader_key:blob +inline std::map, std::string>> shader_cache; +// only used when preload active // shader_key:blob[spv,info] u64 CalculateSpecializationHash(const Shader::StageSpecialization& spec); void InitializeShaderCache(); -void SerializeInfo( - std::ostream& info_serialized, Shader::Info& info); +void SerializeInfo(std::ostream& info_serialized, Shader::Info& info); void DeserializeInfo(std::istream& info_serialized, Shader::Info& info); bool CheckShaderCache(std::string shader_id); void GetShader(std::string shader_id, Shader::Info& info, std::vector& spv); void AddShader(std::string shader_id, std::vector spv, std::ostringstream& info_serialized); -} // namespace ShaderCache +} // namespace ShaderCache \ No newline at end of file diff --git a/src/video_core/renderer_vulkan/shader_cache_serialization.h b/src/video_core/renderer_vulkan/shader_cache_serialization.h index d83230efa..f3f5f22af 100644 --- a/src/video_core/renderer_vulkan/shader_cache_serialization.h +++ b/src/video_core/renderer_vulkan/shader_cache_serialization.h @@ -4,13 +4,12 @@ #include #include +#include #include #include #include -#include -#include "common/serialization.h" -#include "shader_recompiler/info.h" +#include "common/serialization.h" #include "shader_recompiler/info.h" namespace cereal { diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index e0a50b101..3ceb1fc9b 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp @@ -497,12 +497,13 @@ bool PipelineCache::RefreshComputeKey() { vk::ShaderModule PipelineCache::CompileModule(Shader::Info& info, Shader::RuntimeInfo& runtime_info, std::span code, size_t perm_idx, - Shader::Backend::Bindings& binding, Shader::StageSpecialization spec) { + Shader::Backend::Bindings& binding, + Shader::StageSpecialization spec) { LOG_INFO(Render_Vulkan, "Compiling {} shader {:#x} {}", info.stage, info.pgm_hash, perm_idx != 0 ? "(permutation)" : ""); DumpShader(code, info.pgm_hash, info.stage, perm_idx, "bin"); - + std::string shader_name = GetShaderName(info.stage, info.pgm_hash, perm_idx); std::vector spv; @@ -513,8 +514,8 @@ vk::ShaderModule PipelineCache::CompileModule(Shader::Info& info, Shader::Runtim ::ShaderCache::GetShader(shader_id, info, spv); info.RefreshFlatBuf(); } else { - LOG_INFO(Render_Vulkan, "Shader {} {:#x} {}not in cache", info.stage, - info.pgm_hash, perm_idx != 0 ? "(permutation) " : ""); + LOG_INFO(Render_Vulkan, "Shader {} {:#x} {}not in cache", info.stage, info.pgm_hash, + perm_idx != 0 ? "(permutation) " : ""); const auto ir_program = Shader::TranslateProgram(code, pools, info, runtime_info, profile); spv = Shader::Backend::SPIRV::EmitSPIRV(profile, runtime_info, ir_program, binding); std::ostringstream info_serialized; @@ -524,9 +525,8 @@ vk::ShaderModule PipelineCache::CompileModule(Shader::Info& info, Shader::Runtim LOG_INFO(Render_Vulkan, "Shader ID: {}", shader_id); DumpShader(spv, info.pgm_hash, info.stage, perm_idx, "spv"); - - LOG_INFO(Render_Vulkan, "Compiled shader {} {:#x} {}and saved it to cache", info.stage, info.pgm_hash, - perm_idx != 0 ? "(permutation) " : ""); + LOG_INFO(Render_Vulkan, "Compiled shader {} {:#x} {}and saved it to cache", info.stage, + info.pgm_hash, perm_idx != 0 ? "(permutation) " : ""); } vk::ShaderModule module; @@ -561,7 +561,8 @@ PipelineCache::Result PipelineCache::GetProgram(Stage stage, LogicalStage l_stag auto start = binding; Shader::StageSpecialization spec = Shader::StageSpecialization(program->info, runtime_info, profile, start); - const auto module = CompileModule(program->info, runtime_info, params.code, 0, binding, spec); + const auto module = + CompileModule(program->info, runtime_info, params.code, 0, binding, spec); program->AddPermut(module, std::move(spec)); return std::make_tuple(&program->info, module, spec.fetch_shader_data, HashCombine(params.hash, 0)); diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.h b/src/video_core/renderer_vulkan/vk_pipeline_cache.h index c20d06a7b..cf78def7a 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.h +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.h @@ -82,7 +82,8 @@ private: std::string_view ext); vk::ShaderModule CompileModule(Shader::Info& info, Shader::RuntimeInfo& runtime_info, std::span code, size_t perm_idx, - Shader::Backend::Bindings& binding, Shader::StageSpecialization spec); + Shader::Backend::Bindings& binding, + Shader::StageSpecialization spec); const Shader::RuntimeInfo& BuildRuntimeInfo(Shader::Stage stage, Shader::LogicalStage l_stage); private: