This commit is contained in:
Fire Cube 2025-04-30 23:02:05 +02:00
parent 09f844add1
commit bde3873781
3 changed files with 25 additions and 19 deletions

View File

@ -13,11 +13,11 @@ namespace ShaderCache {
const auto shader_cache_dir = Common::FS::GetUserPath(Common::FS::PathType::ShaderDir) / "cache";
std::string CreateShaderID(u64 pgm_hash, size_t perm_idx, std::ostream& info_dump, std::ostream& profile_dump) {
std::string CreateShaderID(u64 pgm_hash, size_t perm_idx, std::ostream& info_serialized, std::ostream& profile_serialized) {
std::ostringstream info_stream, profile_stream;
info_stream << pgm_hash << perm_idx;
info_stream << info_dump.rdbuf();
profile_stream << profile_dump.rdbuf();
info_stream << info_serialized.rdbuf();
profile_stream << profile_serialized.rdbuf();
std::string combined_data = info_stream.str() + profile_stream.str();
@ -26,12 +26,20 @@ std::string CreateShaderID(u64 pgm_hash, size_t perm_idx, std::ostream& info_dum
return std::to_string(shader_id);
}
void DumpInfo(std::ostream& info_dump, Shader::Info info) {
writeBin(info_dump, info.mrt_mask);
void SerializeInfo(std::ostream& info_serialized, Shader::Info info) {
writeBin(info_serialized, info.mrt_mask);
}
void DumpProfile(std::ostream& profile_dump, Shader::Profile profile) {
writeBin(profile_dump, profile.has_broken_spirv_clamp);
void DeserializeInfo(std::istream& info_serialized, Shader::Info& info) {
readBin(info_serialized, info.mrt_mask);
}
void SerializeProfile(std::ostream& profile_serialized, Shader::Profile profile) {
writeBin(profile_serialized, profile.has_broken_spirv_clamp);
}
void DeserializeProfile(std::istream& profile_serialized, Shader::Profile& profile) {
readBin(profile_serialized, profile.has_broken_spirv_clamp);
}
bool CheckShaderCache(std::string shader_id) {
@ -48,7 +56,7 @@ bool GetShader(std::string shader_id) {
spirv_cache_file.Read(spv);
}
void AddShader(std::string shader_id, std::vector<u32> spv, std::ostream& info_dump, std::ostream& profile_dump) {
void AddShader(std::string shader_id, std::vector<u32> spv, std::ostream& info_serialized, std::ostream& profile_serialized) {
std::string spirv_cache_filename = shader_id + ".spv ";
std::filesystem::path spirv_cache_file_path = shader_cache_dir / spirv_cache_filename;
Common::FS::IOFile shader_cache_file(spirv_cache_file_path, Common::FS::FileAccessMode::Write);
@ -58,8 +66,8 @@ void AddShader(std::string shader_id, std::vector<u32> spv, std::ostream& info_d
Common::FS::IOFile resources_dump_file(resources_dump_file_path, Common::FS::FileAccessMode::Write);
// Schreibe beide Streams nacheinander in die Ressourcen-Datei
std::ostringstream info_stream, profile_stream;
info_stream << info_dump.rdbuf();
profile_stream << profile_dump.rdbuf();
info_stream << info_serialized.rdbuf();
profile_stream << profile_serialized.rdbuf();
// Schreibe zuerst die Größe des info-Dumps, dann die Daten
u32 info_size = static_cast<u32>(info_stream.str().size());
@ -69,8 +77,6 @@ void AddShader(std::string shader_id, std::vector<u32> spv, std::ostream& info_d
u32 profile_size = static_cast<u32>(profile_stream.str().size());
resources_dump_file.WriteString(
std::span<const char>(profile_stream.str().data(), profile_size));
}
} // namespace ShaderCache

View File

@ -10,8 +10,8 @@ namespace ShaderCache {
std::string CreateShaderID(u64 pgm_hash, size_t perm_idx, std::ostream& info_dump,
std::ostream& profile_dump);
void DumpInfo(std::ostream& info_dump, Shader::Info info);
void DumpProfile(std::ostream& profile_dump, Shader::Profile profile);
void SerializeInfo(std::ostream& info_dump, Shader::Info info);
void SerializeProfile(std::ostream& profile_dump, Shader::Profile profile);
bool CheckShaderCache(std::string shader_id);
bool GetShader(std::string shader_id);
void AddShader(std::string shader_id, std::vector<u32> spv, std::ostream& info_dump,

View File

@ -493,11 +493,11 @@ vk::ShaderModule PipelineCache::CompileModule(Shader::Info& info, Shader::Runtim
perm_idx != 0 ? "(permutation)" : "");
DumpShader(code, info.pgm_hash, info.stage, perm_idx, "bin");
std::ostringstream info_dump, profile_dump;
::ShaderCache::DumpInfo(info_dump, info);
::ShaderCache::DumpProfile(profile_dump, profile);
std::string shader_id = ::ShaderCache::CreateShaderID(info.pgm_hash, perm_idx, info_dump, profile_dump);
::ShaderCache::AddShader(shader_id, std::vector<u32>{}, info_dump, profile_dump);
std::ostringstream info_serialized, profile_serialized;
::ShaderCache::SerializeInfo(info_serialized, info);
::ShaderCache::SerializeProfile(profile_serialized, profile);
std::string shader_id = ::ShaderCache::CreateShaderID(info.pgm_hash, perm_idx, info_serialized, profile_serialized);
::ShaderCache::AddShader(shader_id, std::vector<u32>{}, info_serialized, profile_serialized);
LOG_INFO(Render_Vulkan, "Shader ID: {}", shader_id);
const auto ir_program = Shader::TranslateProgram(code, pools, info, runtime_info, profile);