mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-23 10:35:03 +00:00
initial codebase
This commit is contained in:
parent
2aee03218c
commit
09f844add1
@ -893,6 +893,8 @@ set(VIDEO_CORE src/video_core/amdgpu/liverpool.cpp
|
|||||||
src/video_core/buffer_cache/word_manager.h
|
src/video_core/buffer_cache/word_manager.h
|
||||||
src/video_core/renderer_vulkan/liverpool_to_vk.cpp
|
src/video_core/renderer_vulkan/liverpool_to_vk.cpp
|
||||||
src/video_core/renderer_vulkan/liverpool_to_vk.h
|
src/video_core/renderer_vulkan/liverpool_to_vk.h
|
||||||
|
src/video_core/renderer_vulkan/shader_cache.cpp
|
||||||
|
src/video_core/renderer_vulkan/shader_cache.h
|
||||||
src/video_core/renderer_vulkan/vk_common.cpp
|
src/video_core/renderer_vulkan/vk_common.cpp
|
||||||
src/video_core/renderer_vulkan/vk_common.h
|
src/video_core/renderer_vulkan/vk_common.h
|
||||||
src/video_core/renderer_vulkan/vk_compute_pipeline.cpp
|
src/video_core/renderer_vulkan/vk_compute_pipeline.cpp
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#include <iostream>
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using u32 = uint32_t;
|
using u32 = uint32_t;
|
||||||
|
@ -1,12 +1,21 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <string>
|
||||||
|
#include "common/path_util.h"
|
||||||
|
#include "common/io_file.h"
|
||||||
|
#include "common/binary_helper.h"
|
||||||
|
#include "shader_recompiler/info.h"
|
||||||
|
|
||||||
|
using u64 = uint64_t;
|
||||||
|
|
||||||
namespace ShaderCache {
|
namespace ShaderCache {
|
||||||
|
|
||||||
const auto shader_cache_dir = Common::FS::GetUserPath(Common::FS::PathType::ShaderDir) / "cache";
|
const auto shader_cache_dir = Common::FS::GetUserPath(Common::FS::PathType::ShaderDir) / "cache";
|
||||||
std::string CreateShaderID(std::ostream& info_dump, std::ostream& profile_dump) {
|
|
||||||
|
std::string CreateShaderID(u64 pgm_hash, size_t perm_idx, std::ostream& info_dump, std::ostream& profile_dump) {
|
||||||
std::ostringstream info_stream, profile_stream;
|
std::ostringstream info_stream, profile_stream;
|
||||||
|
info_stream << pgm_hash << perm_idx;
|
||||||
info_stream << info_dump.rdbuf();
|
info_stream << info_dump.rdbuf();
|
||||||
profile_stream << profile_dump.rdbuf();
|
profile_stream << profile_dump.rdbuf();
|
||||||
|
|
||||||
@ -17,12 +26,51 @@ std::string CreateShaderID(std::ostream& info_dump, std::ostream& profile_dump)
|
|||||||
return std::to_string(shader_id);
|
return std::to_string(shader_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetShader{
|
void DumpInfo(std::ostream& info_dump, Shader::Info info) {
|
||||||
|
writeBin(info_dump, info.mrt_mask);
|
||||||
}
|
|
||||||
void AddShader(std::vector<u32> spv, std::ostream& info_dump, std::ostream& profile_dump) {
|
|
||||||
|
|
||||||
std::string spirv_cache_filename = shader_name + ".spv ";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
void DumpProfile(std::ostream& profile_dump, Shader::Profile profile) {
|
||||||
|
writeBin(profile_dump, profile.has_broken_spirv_clamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CheckShaderCache(std::string shader_id) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GetShader(std::string shader_id) {
|
||||||
|
std::string spirv_cache_filename = shader_id + ".spv ";
|
||||||
|
std::filesystem::path spirv_cache_file_path = shader_cache_dir / spirv_cache_filename;
|
||||||
|
Common::FS::IOFile spirv_cache_file(spirv_cache_file_path,
|
||||||
|
Common::FS::FileAccessMode::Read);
|
||||||
|
std::vector<u32> spv;
|
||||||
|
spv.resize(spirv_cache_file.GetSize() / sizeof(u32));
|
||||||
|
spirv_cache_file.Read(spv);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddShader(std::string shader_id, std::vector<u32> spv, std::ostream& info_dump, std::ostream& profile_dump) {
|
||||||
|
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);
|
||||||
|
shader_cache_file.WriteSpan(std::span<const u32>(spv));
|
||||||
|
|
||||||
|
std::filesystem::path resources_dump_file_path = shader_cache_dir / (shader_id + ".resources");
|
||||||
|
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();
|
||||||
|
|
||||||
|
// Schreibe zuerst die Größe des info-Dumps, dann die Daten
|
||||||
|
u32 info_size = static_cast<u32>(info_stream.str().size());
|
||||||
|
resources_dump_file.WriteString(std::span<const char>(info_stream.str().data(), info_size));
|
||||||
|
|
||||||
|
// Schreibe danach die Größe des profile-Dumps, dann die Daten
|
||||||
|
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
|
@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include "shader_recompiler/info.h"
|
||||||
|
|
||||||
|
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);
|
||||||
|
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,
|
||||||
|
std::ostream& profile_dump);
|
||||||
|
|
||||||
|
} // namespace ShaderCache
|
@ -12,6 +12,7 @@
|
|||||||
#include "shader_recompiler/info.h"
|
#include "shader_recompiler/info.h"
|
||||||
#include "shader_recompiler/recompiler.h"
|
#include "shader_recompiler/recompiler.h"
|
||||||
#include "shader_recompiler/runtime_info.h"
|
#include "shader_recompiler/runtime_info.h"
|
||||||
|
#include "video_core/renderer_vulkan/shader_cache.h"
|
||||||
#include "video_core/renderer_vulkan/vk_instance.h"
|
#include "video_core/renderer_vulkan/vk_instance.h"
|
||||||
#include "video_core/renderer_vulkan/vk_pipeline_cache.h"
|
#include "video_core/renderer_vulkan/vk_pipeline_cache.h"
|
||||||
#include "video_core/renderer_vulkan/vk_presenter.h"
|
#include "video_core/renderer_vulkan/vk_presenter.h"
|
||||||
@ -492,30 +493,30 @@ vk::ShaderModule PipelineCache::CompileModule(Shader::Info& info, Shader::Runtim
|
|||||||
perm_idx != 0 ? "(permutation)" : "");
|
perm_idx != 0 ? "(permutation)" : "");
|
||||||
DumpShader(code, info.pgm_hash, info.stage, perm_idx, "bin");
|
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);
|
||||||
|
LOG_INFO(Render_Vulkan, "Shader ID: {}", shader_id);
|
||||||
|
|
||||||
const auto ir_program = Shader::TranslateProgram(code, pools, info, runtime_info, profile);
|
const auto ir_program = Shader::TranslateProgram(code, pools, info, runtime_info, profile);
|
||||||
|
|
||||||
std::string shader_name = GetShaderName(info.stage, info.pgm_hash, perm_idx);
|
std::string shader_name = GetShaderName(info.stage, info.pgm_hash, perm_idx);
|
||||||
std::string spirv_cache_filename =
|
|
||||||
shader_name + "_" + Common::g_scm_rev + ".spv ";
|
|
||||||
|
|
||||||
|
|
||||||
std::filesystem::path spirv_cache_file_path = shader_cache_dir / spirv_cache_filename;
|
|
||||||
|
|
||||||
std::vector<u32> spv;
|
std::vector<u32> spv;
|
||||||
|
|
||||||
if (std::filesystem::exists(spirv_cache_file_path)) {
|
if (::ShaderCache::CheckShaderCache(shader_id)) {
|
||||||
Common::FS::IOFile spirv_cache_file(spirv_cache_file_path, Common::FS::FileAccessMode::Read);
|
LOG_INFO(Render_Vulkan, "Loaded SPIR-V from cache");
|
||||||
spv.resize(spirv_cache_file.GetSize() / sizeof(u32));
|
|
||||||
spirv_cache_file.Read(spv);
|
|
||||||
LOG_INFO(Render_Vulkan, "Loaded SPIR-V from cache: {}", spirv_cache_file_path.string());
|
|
||||||
} else {
|
} else {
|
||||||
spv = Shader::Backend::SPIRV::EmitSPIRV(profile, runtime_info, ir_program, binding);
|
spv = Shader::Backend::SPIRV::EmitSPIRV(profile, runtime_info, ir_program, binding);
|
||||||
|
|
||||||
DumpShader(spv, info.pgm_hash, info.stage, perm_idx, "spv");
|
DumpShader(spv, info.pgm_hash, info.stage, perm_idx, "spv");
|
||||||
|
|
||||||
Common::FS::IOFile shader_cache_file(spirv_cache_file_path, Common::FS::FileAccessMode::Write);
|
|
||||||
shader_cache_file.WriteSpan(std::span<const u32>(spv));
|
LOG_INFO(Render_Vulkan, "Compiled SPIR-V and stored in cache");
|
||||||
LOG_INFO(Render_Vulkan, "Compiled SPIR-V and stored in cache: {}", spirv_cache_file_path.string());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vk::ShaderModule module;
|
vk::ShaderModule module;
|
||||||
|
Loading…
Reference in New Issue
Block a user