support metal shaders in graphics packs

This commit is contained in:
Samuliak 2025-01-16 18:31:09 +01:00
parent 3d84b78362
commit ec2410222c
No known key found for this signature in database
3 changed files with 30 additions and 22 deletions

View file

@ -683,12 +683,15 @@ void GraphicPack2::LoadShaders()
wchar_t shader_type[256]{}; wchar_t shader_type[256]{};
if (filename.size() < 256 && swscanf(filename.c_str(), L"%" SCNx64 "_%" SCNx64 "_%ls", &shader_base_hash, &shader_aux_hash, shader_type) == 3) if (filename.size() < 256 && swscanf(filename.c_str(), L"%" SCNx64 "_%" SCNx64 "_%ls", &shader_base_hash, &shader_aux_hash, shader_type) == 3)
{ {
bool isMetalShader = (shader_type[2] == '_' && shader_type[3] == 'm' && shader_type[4] == 's' && shader_type[5] == 'l');
printf("IS METAL SHADER: %u\n", isMetalShader);
if (shader_type[0] == 'p' && shader_type[1] == 's') if (shader_type[0] == 'p' && shader_type[1] == 's')
m_custom_shaders.emplace_back(LoadShader(p, shader_base_hash, shader_aux_hash, GP_SHADER_TYPE::PIXEL)); m_custom_shaders.emplace_back(LoadShader(p, shader_base_hash, shader_aux_hash, GP_SHADER_TYPE::PIXEL, isMetalShader));
else if (shader_type[0] == 'v' && shader_type[1] == 's') else if (shader_type[0] == 'v' && shader_type[1] == 's')
m_custom_shaders.emplace_back(LoadShader(p, shader_base_hash, shader_aux_hash, GP_SHADER_TYPE::VERTEX)); m_custom_shaders.emplace_back(LoadShader(p, shader_base_hash, shader_aux_hash, GP_SHADER_TYPE::VERTEX, isMetalShader));
else if (shader_type[0] == 'g' && shader_type[1] == 's') else if (shader_type[0] == 'g' && shader_type[1] == 's')
m_custom_shaders.emplace_back(LoadShader(p, shader_base_hash, shader_aux_hash, GP_SHADER_TYPE::GEOMETRY)); m_custom_shaders.emplace_back(LoadShader(p, shader_base_hash, shader_aux_hash, GP_SHADER_TYPE::GEOMETRY, isMetalShader));
} }
else if (filename == L"output.glsl") else if (filename == L"output.glsl")
{ {
@ -1047,7 +1050,7 @@ bool GraphicPack2::Deactivate()
return true; return true;
} }
const std::string* GraphicPack2::FindCustomShaderSource(uint64 shaderBaseHash, uint64 shaderAuxHash, GP_SHADER_TYPE type, bool isVulkanRenderer) const std::string* GraphicPack2::FindCustomShaderSource(uint64 shaderBaseHash, uint64 shaderAuxHash, GP_SHADER_TYPE type, bool isVulkanRenderer, bool isMetalRenderer)
{ {
for (const auto& gp : GraphicPack2::GetActiveGraphicPacks()) for (const auto& gp : GraphicPack2::GetActiveGraphicPacks())
{ {
@ -1060,6 +1063,9 @@ const std::string* GraphicPack2::FindCustomShaderSource(uint64 shaderBaseHash, u
if (isVulkanRenderer && (*it).isPreVulkanShader) if (isVulkanRenderer && (*it).isPreVulkanShader)
continue; continue;
if (isMetalRenderer != (*it).isMetalShader)
continue;
return &it->source; return &it->source;
} }
return nullptr; return nullptr;
@ -1217,7 +1223,7 @@ void GraphicPack2::ApplyShaderPresets(std::string& shader_source) const
} }
} }
GraphicPack2::CustomShader GraphicPack2::LoadShader(const fs::path& path, uint64 shader_base_hash, uint64 shader_aux_hash, GP_SHADER_TYPE shader_type) const GraphicPack2::CustomShader GraphicPack2::LoadShader(const fs::path& path, uint64 shader_base_hash, uint64 shader_aux_hash, GP_SHADER_TYPE shader_type, bool isMetalShader) const
{ {
CustomShader shader; CustomShader shader;
@ -1236,6 +1242,7 @@ GraphicPack2::CustomShader GraphicPack2::LoadShader(const fs::path& path, uint64
shader.shader_aux_hash = shader_aux_hash; shader.shader_aux_hash = shader_aux_hash;
shader.type = shader_type; shader.type = shader_type;
shader.isPreVulkanShader = this->m_version <= 3; shader.isPreVulkanShader = this->m_version <= 3;
shader.isMetalShader = isMetalShader;
return shader; return shader;
} }

View file

@ -67,6 +67,7 @@ public:
uint64 shader_aux_hash; uint64 shader_aux_hash;
GP_SHADER_TYPE type; GP_SHADER_TYPE type;
bool isPreVulkanShader{}; // set to true for V3 packs since the shaders are not compatible with the Vulkan renderer bool isPreVulkanShader{}; // set to true for V3 packs since the shaders are not compatible with the Vulkan renderer
bool isMetalShader{}; // set to true if the shader is written in Metal Shading Language
}; };
enum VarType enum VarType
@ -148,7 +149,7 @@ public:
bool HasShaders() const; bool HasShaders() const;
const std::vector<CustomShader>& GetCustomShaders() const { return m_custom_shaders; } const std::vector<CustomShader>& GetCustomShaders() const { return m_custom_shaders; }
static const std::string* FindCustomShaderSource(uint64 shaderBaseHash, uint64 shaderAuxHash, GP_SHADER_TYPE type, bool isVulkanRenderer); static const std::string* FindCustomShaderSource(uint64 shaderBaseHash, uint64 shaderAuxHash, GP_SHADER_TYPE type, bool isVulkanRenderer, bool isMetalRenderer);
const std::string& GetOutputShaderSource() const { return m_output_shader_source; } const std::string& GetOutputShaderSource() const { return m_output_shader_source; }
const std::string& GetDownscalingShaderSource() const { return m_downscaling_shader_source; } const std::string& GetDownscalingShaderSource() const { return m_downscaling_shader_source; }
@ -257,7 +258,7 @@ private:
std::vector<uint64> ParseTitleIds(IniParser& rules, const char* option_name) const; std::vector<uint64> ParseTitleIds(IniParser& rules, const char* option_name) const;
CustomShader LoadShader(const fs::path& path, uint64 shader_base_hash, uint64 shader_aux_hash, GP_SHADER_TYPE shader_type) const; CustomShader LoadShader(const fs::path& path, uint64 shader_base_hash, uint64 shader_aux_hash, GP_SHADER_TYPE shader_type, bool isMetalShader) const;
void ApplyShaderPresets(std::string& shader_source) const; void ApplyShaderPresets(std::string& shader_source) const;
void LoadReplacedFiles(); void LoadReplacedFiles();
void _iterateReplacedFiles(const fs::path& currentPath, bool isAOC); void _iterateReplacedFiles(const fs::path& currentPath, bool isAOC);

View file

@ -339,7 +339,7 @@ void LatteShader_CreateRendererShader(LatteDecompilerShader* shader, bool compil
// check if a custom shader is present // check if a custom shader is present
std::string shaderSrc; std::string shaderSrc;
const std::string* customShaderSrc = GraphicPack2::FindCustomShaderSource(shader->baseHash, shader->auxHash, gpShaderType, g_renderer->GetType() == RendererAPI::Vulkan); const std::string* customShaderSrc = GraphicPack2::FindCustomShaderSource(shader->baseHash, shader->auxHash, gpShaderType, g_renderer->GetType() == RendererAPI::Vulkan, g_renderer->GetType() == RendererAPI::Metal);
if (customShaderSrc) if (customShaderSrc)
{ {
shaderSrc.assign(*customShaderSrc); shaderSrc.assign(*customShaderSrc);