mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-06-12 21:53:14 +00:00
Allow shader patching (#1633)
This commit is contained in:
parent
07f4a0305b
commit
2002e37ce9
5 changed files with 58 additions and 1 deletions
|
@ -406,8 +406,13 @@ vk::ShaderModule PipelineCache::CompileModule(Shader::Info& info,
|
|||
DumpShader(code, info.pgm_hash, info.stage, perm_idx, "bin");
|
||||
|
||||
const auto ir_program = Shader::TranslateProgram(code, pools, info, runtime_info, profile);
|
||||
const auto spv = Shader::Backend::SPIRV::EmitSPIRV(profile, runtime_info, ir_program, binding);
|
||||
auto spv = Shader::Backend::SPIRV::EmitSPIRV(profile, runtime_info, ir_program, binding);
|
||||
DumpShader(spv, info.pgm_hash, info.stage, perm_idx, "spv");
|
||||
auto patch = GetShaderPatch(info.pgm_hash, info.stage, perm_idx, "spv");
|
||||
if (patch) {
|
||||
spv = *patch;
|
||||
LOG_INFO(Loader, "Loaded patch for {} shader {:#x}", info.stage, info.pgm_hash);
|
||||
}
|
||||
|
||||
const auto module = CompileSPV(spv, instance.GetDevice());
|
||||
const auto name = fmt::format("{}_{:#x}_{}", info.stage, info.pgm_hash, perm_idx);
|
||||
|
@ -465,4 +470,27 @@ void PipelineCache::DumpShader(std::span<const u32> code, u64 hash, Shader::Stag
|
|||
file.WriteSpan(code);
|
||||
}
|
||||
|
||||
std::optional<std::vector<u32>> PipelineCache::GetShaderPatch(u64 hash, Shader::Stage stage,
|
||||
size_t perm_idx,
|
||||
std::string_view ext) {
|
||||
if (!Config::patchShaders()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
using namespace Common::FS;
|
||||
const auto patch_dir = GetUserPath(PathType::ShaderDir) / "patch";
|
||||
if (!std::filesystem::exists(patch_dir)) {
|
||||
std::filesystem::create_directories(patch_dir);
|
||||
}
|
||||
const auto filename = fmt::format("{}_{:#018x}_{}.{}", stage, hash, perm_idx, ext);
|
||||
const auto filepath = patch_dir / filename;
|
||||
if (!std::filesystem::exists(filepath)) {
|
||||
return {};
|
||||
}
|
||||
const auto file = IOFile{patch_dir / filename, FileAccessMode::Read};
|
||||
std::vector<u32> code(file.GetSize() / sizeof(u32));
|
||||
file.Read(code);
|
||||
return code;
|
||||
}
|
||||
|
||||
} // namespace Vulkan
|
||||
|
|
|
@ -56,6 +56,8 @@ private:
|
|||
|
||||
void DumpShader(std::span<const u32> code, u64 hash, Shader::Stage stage, size_t perm_idx,
|
||||
std::string_view ext);
|
||||
std::optional<std::vector<u32>> GetShaderPatch(u64 hash, Shader::Stage stage, size_t perm_idx,
|
||||
std::string_view ext);
|
||||
vk::ShaderModule CompileModule(Shader::Info& info, const Shader::RuntimeInfo& runtime_info,
|
||||
std::span<const u32> code, size_t perm_idx,
|
||||
Shader::Backend::Bindings& binding);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue