mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-22 10:04:39 +00:00
cleanup
This commit is contained in:
parent
c171657b4f
commit
99cad6efa1
@ -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<bool>(gpu, "directMemoryAccess", directMemoryAccessEnabled);
|
||||
shouldDumpShaders = toml::find_or<bool>(gpu, "dumpShaders", shouldDumpShaders);
|
||||
shouldPatchShaders = toml::find_or<bool>(gpu, "patchShaders", shouldPatchShaders);
|
||||
shaderCachePreloadEnabled = toml::find_or<bool>(gpu, "shaderCachePreload", shaderCachePreloadEnabled);
|
||||
shaderCachePreloadEnabled =
|
||||
toml::find_or<bool>(gpu, "shaderCachePreload", shaderCachePreloadEnabled);
|
||||
vblankDivider = toml::find_or<int>(gpu, "vblankDivider", vblankDivider);
|
||||
isFullscreen = toml::find_or<bool>(gpu, "Fullscreen", isFullscreen);
|
||||
fullscreenMode = toml::find_or<std::string>(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
|
@ -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
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include <boost/container/small_vector.hpp>
|
||||
#include <cereal/archives/binary.hpp>
|
||||
|
||||
#include <common/types.h>
|
||||
|
||||
namespace cereal {
|
||||
|
@ -266,7 +266,8 @@ void Emulator::Run(std::filesystem::path file, const std::vector<std::string> 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());
|
||||
|
@ -1,33 +1,24 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <fstream>
|
||||
|
||||
#include <cereal/archives/binary.hpp>
|
||||
|
||||
#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<u32>& 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);
|
||||
|
@ -7,27 +7,33 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#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<std::string, u64> shader_registry; // shader_key:offset
|
||||
inline std::map<std::string, std::pair<std::vector<u32>, std::string>> shader_cache; // only used when preload active // shader_key:blob
|
||||
inline std::map<std::string, std::pair<std::vector<u32>, 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<u32>& spv);
|
||||
void AddShader(std::string shader_id, std::vector<u32> spv, std::ostringstream& info_serialized);
|
||||
|
||||
} // namespace ShaderCache
|
||||
} // namespace ShaderCache
|
@ -4,13 +4,12 @@
|
||||
|
||||
#include <cereal/types/array.hpp>
|
||||
#include <cereal/types/map.hpp>
|
||||
#include <cereal/types/string.hpp>
|
||||
#include <cereal/types/utility.hpp>
|
||||
#include <cereal/types/variant.hpp>
|
||||
#include <cereal/types/vector.hpp>
|
||||
#include <cereal/types/string.hpp>
|
||||
#include "common/serialization.h"
|
||||
#include "shader_recompiler/info.h"
|
||||
|
||||
#include "common/serialization.h"
|
||||
#include "shader_recompiler/info.h"
|
||||
|
||||
namespace cereal {
|
||||
|
@ -497,12 +497,13 @@ bool PipelineCache::RefreshComputeKey() {
|
||||
|
||||
vk::ShaderModule PipelineCache::CompileModule(Shader::Info& info, Shader::RuntimeInfo& runtime_info,
|
||||
std::span<const u32> 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<u32> 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));
|
||||
|
@ -82,7 +82,8 @@ private:
|
||||
std::string_view ext);
|
||||
vk::ShaderModule CompileModule(Shader::Info& info, Shader::RuntimeInfo& runtime_info,
|
||||
std::span<const u32> 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:
|
||||
|
Loading…
Reference in New Issue
Block a user