mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-22 18:15:14 +00:00
fmask, refactoring, fixes and mac fix(?)
This commit is contained in:
parent
1c8c009221
commit
b1db45a64d
@ -690,6 +690,7 @@ set(COMMON src/common/logging/backend.cpp
|
|||||||
src/common/rdtsc.h
|
src/common/rdtsc.h
|
||||||
src/common/recursive_lock.cpp
|
src/common/recursive_lock.cpp
|
||||||
src/common/recursive_lock.h
|
src/common/recursive_lock.h
|
||||||
|
src/common/serialization.h
|
||||||
src/common/sha1.h
|
src/common/sha1.h
|
||||||
src/common/shared_first_mutex.h
|
src/common/shared_first_mutex.h
|
||||||
src/common/signal_context.h
|
src/common/signal_context.h
|
||||||
|
3
externals/CMakeLists.txt
vendored
3
externals/CMakeLists.txt
vendored
@ -216,7 +216,8 @@ if (NOT TARGET stb::headers)
|
|||||||
add_library(stb::headers ALIAS stb)
|
add_library(stb::headers ALIAS stb)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (NOT TARGET cereal::cereal)
|
# cereal
|
||||||
|
if (NOT TARGET cereal::cereal AND NOT APPLE)
|
||||||
set(SKIP_PERFORMANCE_COMPARISON ON "")
|
set(SKIP_PERFORMANCE_COMPARISON ON "")
|
||||||
set(BUILD_SANDBOX OFF "")
|
set(BUILD_SANDBOX OFF "")
|
||||||
set(BUILD_TESTS OFF "")
|
set(BUILD_TESTS OFF "")
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#include "core/memory.h"
|
#include "core/memory.h"
|
||||||
#include "emulator.h"
|
#include "emulator.h"
|
||||||
#include "video_core/renderdoc.h"
|
#include "video_core/renderdoc.h"
|
||||||
|
#include "video_core/renderer_vulkan/shader_cache.h"
|
||||||
|
|
||||||
Frontend::WindowSDL* g_window = nullptr;
|
Frontend::WindowSDL* g_window = nullptr;
|
||||||
|
|
||||||
@ -256,10 +257,9 @@ void Emulator::Run(std::filesystem::path file, const std::vector<std::string> ar
|
|||||||
}
|
}
|
||||||
VideoCore::SetOutputDir(mount_captures_dir, id);
|
VideoCore::SetOutputDir(mount_captures_dir, id);
|
||||||
|
|
||||||
const auto shader_cache_dir = Common::FS::GetUserPath(Common::FS::PathType::ShaderDir) / "cache";
|
if (!std::filesystem::exists(SHADER_CACHE_DIR)) {
|
||||||
if (!std::filesystem::exists(shader_cache_dir)) {
|
std::filesystem::create_directories(SHADER_CACHE_DIR);
|
||||||
std::filesystem::create_directories(shader_cache_dir);
|
LOG_INFO(Loader, "Created shader cache directory: {}", SHADER_CACHE_DIR.string());
|
||||||
LOG_INFO(Loader, "Created shader cache directory: {}", shader_cache_dir.string());
|
|
||||||
}
|
}
|
||||||
// Initialize kernel and library facilities.
|
// Initialize kernel and library facilities.
|
||||||
Libraries::InitHLELibs(&linker->GetHLESymbols());
|
Libraries::InitHLELibs(&linker->GetHLESymbols());
|
||||||
|
@ -29,8 +29,6 @@ using u32 = uint32_t;
|
|||||||
|
|
||||||
namespace ShaderCache {
|
namespace ShaderCache {
|
||||||
|
|
||||||
const auto shader_cache_dir = Common::FS::GetUserPath(Common::FS::PathType::ShaderDir) / "cache";
|
|
||||||
std::unordered_map<std::string, std::vector<u32>> g_ud_storage;
|
|
||||||
|
|
||||||
u64 CalculateSpecializationHash(const Shader::StageSpecialization& spec) {
|
u64 CalculateSpecializationHash(const Shader::StageSpecialization& spec) {
|
||||||
u64 hash = 0;
|
u64 hash = 0;
|
||||||
@ -246,8 +244,9 @@ u64 CalculateSpecializationHash(const Shader::StageSpecialization& spec) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool CheckShaderCache(std::string shader_id) {
|
bool CheckShaderCache(std::string shader_id) {
|
||||||
std::filesystem::path spirv_cache_file_path = shader_cache_dir / (shader_id + ".spv");
|
std::filesystem::path spirv_cache_file_path = SHADER_CACHE_DIR / static_cast<std::filesystem::path>(shader_id + ".spv");
|
||||||
std::filesystem::path resources_file_path = shader_cache_dir / (shader_id + ".resources");
|
std::filesystem::path resources_file_path = SHADER_CACHE_DIR / static_cast<std::filesystem::path>(shader_id + ".resources");
|
||||||
|
;
|
||||||
|
|
||||||
if (!std::filesystem::exists(spirv_cache_file_path)) {
|
if (!std::filesystem::exists(spirv_cache_file_path)) {
|
||||||
return false;
|
return false;
|
||||||
@ -282,14 +281,17 @@ bool CheckShaderCache(std::string shader_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GetShader(std::string shader_id, Shader::Info& info, std::vector<u32>& spv) {
|
void GetShader(std::string shader_id, Shader::Info& info, std::vector<u32>& spv) {
|
||||||
std::string spirv_cache_filename = shader_id + ".spv";
|
// read spirv
|
||||||
std::filesystem::path spirv_cache_file_path = shader_cache_dir / spirv_cache_filename;
|
std::filesystem::path 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);
|
Common::FS::IOFile spirv_cache_file(spirv_cache_file_path, Common::FS::FileAccessMode::Read);
|
||||||
spv.resize(spirv_cache_file.GetSize() / sizeof(u32));
|
spv.resize(spirv_cache_file.GetSize() / sizeof(u32));
|
||||||
spirv_cache_file.Read(spv);
|
spirv_cache_file.Read(spv);
|
||||||
spirv_cache_file.Close();
|
spirv_cache_file.Close();
|
||||||
|
|
||||||
std::filesystem::path resources_dump_file_path = shader_cache_dir / (shader_id + ".resources");
|
// read resources
|
||||||
|
std::filesystem::path resource_dump_filename = shader_id + ".resources";
|
||||||
|
std::filesystem::path resources_dump_file_path = SHADER_CACHE_DIR / resource_dump_filename;
|
||||||
Common::FS::IOFile resources_dump_file(resources_dump_file_path,
|
Common::FS::IOFile resources_dump_file(resources_dump_file_path,
|
||||||
Common::FS::FileAccessMode::Read);
|
Common::FS::FileAccessMode::Read);
|
||||||
|
|
||||||
@ -305,13 +307,14 @@ void GetShader(std::string shader_id, Shader::Info& info, std::vector<u32>& spv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AddShader(std::string shader_id, std::vector<u32> spv, std::ostream& info_serialized) {
|
void AddShader(std::string shader_id, std::vector<u32> spv, std::ostream& info_serialized) {
|
||||||
std::string spirv_cache_filename = shader_id + ".spv";
|
std::filesystem::path spirv_cache_filename = shader_id + ".spv";
|
||||||
std::filesystem::path spirv_cache_file_path = shader_cache_dir / spirv_cache_filename;
|
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);
|
Common::FS::IOFile shader_cache_file(spirv_cache_file_path, Common::FS::FileAccessMode::Write);
|
||||||
shader_cache_file.WriteSpan(std::span<const u32>(spv));
|
shader_cache_file.WriteSpan(std::span<const u32>(spv));
|
||||||
shader_cache_file.Close();
|
shader_cache_file.Close();
|
||||||
|
|
||||||
std::filesystem::path resources_dump_file_path = shader_cache_dir / (shader_id + ".resources");
|
std::filesystem::path resource_dump_filename = shader_id + ".resources";
|
||||||
|
std::filesystem::path resources_dump_file_path = SHADER_CACHE_DIR / resource_dump_filename;
|
||||||
Common::FS::IOFile resources_dump_file(resources_dump_file_path,
|
Common::FS::IOFile resources_dump_file(resources_dump_file_path,
|
||||||
Common::FS::FileAccessMode::Write);
|
Common::FS::FileAccessMode::Write);
|
||||||
|
|
||||||
@ -331,6 +334,7 @@ void SerializeInfo(std::ostream& info_serialized, Shader::Info &info) {
|
|||||||
ar << info.buffers;
|
ar << info.buffers;
|
||||||
ar << info.images;
|
ar << info.images;
|
||||||
ar << info.samplers;
|
ar << info.samplers;
|
||||||
|
ar << info.fmasks;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace ShaderCache {
|
namespace ShaderCache {
|
||||||
|
|
||||||
|
#define SHADER_CACHE_DIR (Common::FS::GetUserPath(Common::FS::PathType::ShaderDir) / "cache" / "portable")
|
||||||
|
|
||||||
u64 CalculateSpecializationHash(const Shader::StageSpecialization& spec);
|
u64 CalculateSpecializationHash(const Shader::StageSpecialization& spec);
|
||||||
void SerializeInfo(
|
void SerializeInfo(
|
||||||
std::ostream& info_serialized, Shader::Info& info);
|
std::ostream& info_serialized, Shader::Info& info);
|
||||||
|
@ -5,27 +5,12 @@
|
|||||||
#include <cereal/types/map.hpp>
|
#include <cereal/types/map.hpp>
|
||||||
#include <cereal/types/variant.hpp>
|
#include <cereal/types/variant.hpp>
|
||||||
#include <cereal/types/utility.hpp>
|
#include <cereal/types/utility.hpp>
|
||||||
|
|
||||||
|
#include "common/serialization.h"
|
||||||
#include "shader_recompiler/info.h"
|
#include "shader_recompiler/info.h"
|
||||||
|
|
||||||
namespace cereal {
|
namespace cereal {
|
||||||
|
|
||||||
// boost::small_vector
|
|
||||||
template<class Archive, class T, std::size_t N, class Alloc>
|
|
||||||
void save(Archive& ar, boost::container::small_vector<T, N, Alloc> const& smallVector) {
|
|
||||||
ar(static_cast<std::uint32_t>(smallVector.size()));
|
|
||||||
for (auto const& element : smallVector)
|
|
||||||
ar(element);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class Archive, class T, std::size_t N, class Alloc>
|
|
||||||
void load(Archive& ar, boost::container::small_vector<T, N, Alloc>& smallVector) {
|
|
||||||
std::uint32_t elementCount;
|
|
||||||
ar(elementCount);
|
|
||||||
smallVector.resize(elementCount);
|
|
||||||
for (auto& element : smallVector)
|
|
||||||
ar(element);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Shader::Info::UserDataMask
|
// Shader::Info::UserDataMask
|
||||||
template<class Archive>
|
template<class Archive>
|
||||||
void serialize(Archive& ar, Shader::Info::UserDataMask& mask) {
|
void serialize(Archive& ar, Shader::Info::UserDataMask& mask) {
|
||||||
@ -89,4 +74,10 @@ void serialize(Archive& ar, Shader::SamplerResource& sampler) {
|
|||||||
static_cast<u32>(sampler.disable_aniso));
|
static_cast<u32>(sampler.disable_aniso));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Shader::FMaskResource
|
||||||
|
template<class Archive>
|
||||||
|
void serialize(Archive& ar, Shader::FMaskResource& fmask) {
|
||||||
|
cereal::binary_data(reinterpret_cast<uint8_t*>(&fmask), sizeof(fmask));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -516,13 +516,13 @@ vk::ShaderModule PipelineCache::CompileModule(Shader::Info& info, Shader::Runtim
|
|||||||
std::vector<u32> spv;
|
std::vector<u32> spv;
|
||||||
std::string shader_id = std::to_string(::ShaderCache::CalculateSpecializationHash(spec));
|
std::string shader_id = std::to_string(::ShaderCache::CalculateSpecializationHash(spec));
|
||||||
if (::ShaderCache::CheckShaderCache(shader_id)) {
|
if (::ShaderCache::CheckShaderCache(shader_id)) {
|
||||||
LOG_INFO(Render_Vulkan, "Loaded shader {} {:#x} {} from cache", info.stage, info.pgm_hash,
|
LOG_INFO(Render_Vulkan, "Loaded shader {} {:#x} {}from cache", info.stage, info.pgm_hash,
|
||||||
perm_idx != 0 ? "(permutation)" : "");
|
perm_idx != 0 ? "(permutation) " : "");
|
||||||
::ShaderCache::GetShader(shader_id, info, spv);
|
::ShaderCache::GetShader(shader_id, info, spv);
|
||||||
info.RefreshFlatBuf();
|
info.RefreshFlatBuf();
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO(Render_Vulkan, "Shader {} {:#x} {} not in cache", info.stage,
|
LOG_INFO(Render_Vulkan, "Shader {} {:#x} {}not in cache", info.stage,
|
||||||
info.pgm_hash, perm_idx != 0 ? "(permutation)" : "");
|
info.pgm_hash, perm_idx != 0 ? "(permutation) " : "");
|
||||||
const auto ir_program = Shader::TranslateProgram(code, pools, info, runtime_info, profile);
|
const auto ir_program = Shader::TranslateProgram(code, pools, info, runtime_info, profile);
|
||||||
spv = Shader::Backend::SPIRV::EmitSPIRV(profile, runtime_info, ir_program, binding);
|
spv = Shader::Backend::SPIRV::EmitSPIRV(profile, runtime_info, ir_program, binding);
|
||||||
std::ostringstream info_serialized;
|
std::ostringstream info_serialized;
|
||||||
@ -533,8 +533,8 @@ vk::ShaderModule PipelineCache::CompileModule(Shader::Info& info, Shader::Runtim
|
|||||||
DumpShader(spv, info.pgm_hash, info.stage, perm_idx, "spv");
|
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,
|
LOG_INFO(Render_Vulkan, "Compiled shader {} {:#x} {}and saved it to cache", info.stage, info.pgm_hash,
|
||||||
perm_idx != 0 ? "(permutation)" : "");
|
perm_idx != 0 ? "(permutation) " : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
vk::ShaderModule module;
|
vk::ShaderModule module;
|
||||||
|
Loading…
Reference in New Issue
Block a user