Archived
1
Fork 0

Re-add support for MSL shaders

This commit is contained in:
Joshua Goins 2022-02-15 12:32:42 -05:00
parent c5713938ca
commit fcbf526615
2 changed files with 28 additions and 4 deletions

View file

@ -102,9 +102,21 @@ std::optional<ShaderSource> ShaderCompiler::compile(const ShaderLanguage from_la
switch(to_language) {
case ShaderLanguage::SPIRV:
return ShaderSource(spirv);
case ShaderLanguage::MSL:
prism::log("Unimplemented shader language: MSL");
return ShaderSource(spirv);
case ShaderLanguage::MSL: {
spirv_cross::CompilerMSL msl(std::move(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:
prism::log("Unimplemented shader language: HLSL");
return ShaderSource(spirv);

View file

@ -40,7 +40,13 @@ int main(int argc, char* argv[]) {
ShaderLanguage language;
CompileOptions options;
#ifdef PLATFORM_MACOS
options.is_apple_mobile = (bool)argv[3];
language = ShaderLanguage::MSL;
#else
language = ShaderLanguage::SPIRV;
#endif
const auto compiled_source = shader_compiler.compile(ShaderLanguage::GLSL, stage, ShaderSource(buffer.str()), language, options);
if(!compiled_source.has_value()) {
@ -53,10 +59,16 @@ int main(int argc, char* argv[]) {
{
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));
}
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:
break;
}