Re-add support for MSL shaders
This commit is contained in:
parent
c5713938ca
commit
fcbf526615
2 changed files with 28 additions and 4 deletions
|
@ -102,9 +102,21 @@ std::optional<ShaderSource> ShaderCompiler::compile(const ShaderLanguage from_la
|
||||||
switch(to_language) {
|
switch(to_language) {
|
||||||
case ShaderLanguage::SPIRV:
|
case ShaderLanguage::SPIRV:
|
||||||
return ShaderSource(spirv);
|
return ShaderSource(spirv);
|
||||||
case ShaderLanguage::MSL:
|
case ShaderLanguage::MSL: {
|
||||||
prism::log("Unimplemented shader language: MSL");
|
spirv_cross::CompilerMSL msl(std::move(spirv));
|
||||||
return ShaderSource(spirv);
|
|
||||||
|
spirv_cross::CompilerMSL::Options opts;
|
||||||
|
if(options.is_apple_mobile) {
|
||||||
|
opts.platform = spirv_cross::CompilerMSL::Options::Platform::iOS;
|
||||||
|
} else {
|
||||||
|
opts.platform = spirv_cross::CompilerMSL::Options::Platform::macOS;
|
||||||
|
}
|
||||||
|
opts.enable_decoration_binding = true;
|
||||||
|
|
||||||
|
msl.set_msl_options(opts);
|
||||||
|
|
||||||
|
return ShaderSource(msl.compile());
|
||||||
|
}
|
||||||
case ShaderLanguage::HLSL:
|
case ShaderLanguage::HLSL:
|
||||||
prism::log("Unimplemented shader language: HLSL");
|
prism::log("Unimplemented shader language: HLSL");
|
||||||
return ShaderSource(spirv);
|
return ShaderSource(spirv);
|
||||||
|
|
|
@ -40,7 +40,13 @@ int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
ShaderLanguage language;
|
ShaderLanguage language;
|
||||||
CompileOptions options;
|
CompileOptions options;
|
||||||
|
#ifdef PLATFORM_MACOS
|
||||||
|
options.is_apple_mobile = (bool)argv[3];
|
||||||
|
|
||||||
|
language = ShaderLanguage::MSL;
|
||||||
|
#else
|
||||||
language = ShaderLanguage::SPIRV;
|
language = ShaderLanguage::SPIRV;
|
||||||
|
#endif
|
||||||
|
|
||||||
const auto compiled_source = shader_compiler.compile(ShaderLanguage::GLSL, stage, ShaderSource(buffer.str()), language, options);
|
const auto compiled_source = shader_compiler.compile(ShaderLanguage::GLSL, stage, ShaderSource(buffer.str()), language, options);
|
||||||
if(!compiled_source.has_value()) {
|
if(!compiled_source.has_value()) {
|
||||||
|
@ -53,10 +59,16 @@ int main(int argc, char* argv[]) {
|
||||||
{
|
{
|
||||||
const auto spirv = compiled_source->as_bytecode();
|
const auto spirv = compiled_source->as_bytecode();
|
||||||
|
|
||||||
std::ofstream out(destination_path, std::ios::binary); // remove .glsl
|
std::ofstream out(destination_path.replace_extension(destination_path.extension().string() + ".spv"), std::ios::binary); // remove .glsl
|
||||||
out.write((char*)spirv.data(), spirv.size() * sizeof(uint32_t));
|
out.write((char*)spirv.data(), spirv.size() * sizeof(uint32_t));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case ShaderLanguage::MSL:
|
||||||
|
{
|
||||||
|
std::ofstream out(destination_path.replace_extension(destination_path.extension().string() + ".msl")); // remove .glsl
|
||||||
|
out << compiled_source->as_string();
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue