Separate Msl target into Msl_macOS and Msl_iOS, fix the resource bindings

Related work item: Github #44
This commit is contained in:
Minmin Gong 2019-04-22 22:13:48 -07:00
Родитель ab97dabc78
Коммит 73b4941aaf
4 изменённых файлов: 44 добавлений и 17 удалений

Просмотреть файл

@ -74,7 +74,8 @@ namespace ShaderConductor
Hlsl,
Glsl,
Essl,
Msl,
Msl_macOS,
Msl_iOS,
NumShadingLanguages,
};

Просмотреть файл

@ -441,7 +441,8 @@ namespace
case ShadingLanguage::Hlsl:
case ShadingLanguage::Glsl:
case ShadingLanguage::Essl:
case ShadingLanguage::Msl:
case ShadingLanguage::Msl_macOS:
case ShadingLanguage::Msl_iOS:
dxcArgStrings.push_back(L"-spirv");
break;
@ -558,7 +559,8 @@ namespace
buildDummySampler = true;
break;
case ShadingLanguage::Msl:
case ShadingLanguage::Msl_macOS:
case ShadingLanguage::Msl_iOS:
if (source.stage == ShaderStage::GeometryShader)
{
AppendError(ret, "MSL doesn't have GS.");
@ -642,7 +644,7 @@ namespace
hlslCompiler->set_hlsl_options(hlslOpts);
}
else if (target.language == ShadingLanguage::Msl)
else if ((target.language == ShadingLanguage::Msl_macOS) || (target.language == ShadingLanguage::Msl_iOS))
{
auto* mslCompiler = static_cast<spirv_cross::CompilerMSL*>(compiler.get());
auto mslOpts = mslCompiler->get_msl_options();
@ -651,7 +653,26 @@ namespace
mslOpts.msl_version = opts.version;
}
mslOpts.swizzle_texture_samples = false;
mslOpts.platform = (target.language == ShadingLanguage::Msl_iOS) ? spirv_cross::CompilerMSL::Options::iOS
: spirv_cross::CompilerMSL::Options::macOS;
mslCompiler->set_msl_options(mslOpts);
const auto& resources = mslCompiler->get_shader_resources();
uint32_t textureBinding = 0;
for (const auto& image : resources.separate_images)
{
mslCompiler->set_decoration(image.id, spv::DecorationBinding, textureBinding);
++textureBinding;
}
uint32_t samplerBinding = 0;
for (const auto& sampler : resources.separate_samplers)
{
mslCompiler->set_decoration(sampler.id, spv::DecorationBinding, samplerBinding);
++samplerBinding;
}
}
if (buildDummySampler)
@ -787,7 +808,8 @@ namespace ShaderConductor
case ShadingLanguage::Hlsl:
case ShadingLanguage::Glsl:
case ShadingLanguage::Essl:
case ShadingLanguage::Msl:
case ShadingLanguage::Msl_macOS:
case ShadingLanguage::Msl_iOS:
results[i] = ConvertBinary(binaryResult, sourceOverride, targets[i]);
break;

Просмотреть файл

@ -80,7 +80,7 @@ namespace
void HlslToAnyTest(const std::string& name, const Compiler::SourceDesc& source, const Compiler::Options& options,
const std::vector<Compiler::TargetDesc>& targets, const std::vector<bool>& expectSuccessFlags)
{
static const std::string extMap[] = { "dxil", "spv", "hlsl", "glsl", "essl", "msl" };
static const std::string extMap[] = { "dxil", "spv", "hlsl", "glsl", "essl", "msl", "msl" };
static_assert(sizeof(extMap) / sizeof(extMap[0]) == static_cast<uint32_t>(ShadingLanguage::NumShadingLanguages),
"extMap doesn't match with the number of shading languages.");
@ -176,7 +176,7 @@ namespace
{ ShadingLanguage::Essl, "300" },
{ ShadingLanguage::Essl, "310" },
{ ShadingLanguage::Msl },
{ ShadingLanguage::Msl_macOS },
};
// clang-format on
@ -385,7 +385,7 @@ namespace
TEST_F(VertexShaderTest, ToMsl)
{
RunTests(ShadingLanguage::Msl);
RunTests(ShadingLanguage::Msl_macOS);
}
@ -406,7 +406,7 @@ namespace
TEST_F(PixelShaderTest, ToMsl)
{
RunTests(ShadingLanguage::Msl);
RunTests(ShadingLanguage::Msl_macOS);
}
@ -427,7 +427,7 @@ namespace
TEST_F(GeometryShaderTest, ToMsl)
{
RunTests(ShadingLanguage::Msl);
RunTests(ShadingLanguage::Msl_macOS);
}
@ -448,7 +448,7 @@ namespace
TEST_F(HullShaderTest, ToMsl)
{
RunTests(ShadingLanguage::Msl);
RunTests(ShadingLanguage::Msl_macOS);
}
@ -469,7 +469,7 @@ namespace
TEST_F(DomainShaderTest, ToMsl)
{
RunTests(ShadingLanguage::Msl);
RunTests(ShadingLanguage::Msl_macOS);
}
@ -490,7 +490,7 @@ namespace
TEST_F(ComputeShaderTest, ToMsl)
{
RunTests(ShadingLanguage::Msl);
RunTests(ShadingLanguage::Msl_macOS);
}
TEST(IncludeTest, IncludeExist)

Просмотреть файл

@ -47,7 +47,7 @@ int main(int argc, char** argv)
("E,entry", "Entry point of the shader", cxxopts::value<std::string>()->default_value("main"))
("I,input", "Input file name", cxxopts::value<std::string>())("O,output", "Output file name", cxxopts::value<std::string>())
("S,stage", "Shader stage: vs, ps, gs, hs, ds, cs", cxxopts::value<std::string>())
("T,target", "Target shading language: dxil, spirv, hlsl, glsl, essl, msl", cxxopts::value<std::string>()->default_value("dxil"))
("T,target", "Target shading language: dxil, spirv, hlsl, glsl, essl, msl_macos, msl_ios", cxxopts::value<std::string>()->default_value("dxil"))
("V,version", "The version of target shading language", cxxopts::value<std::string>()->default_value(""));
// clang-format on
@ -126,9 +126,13 @@ int main(int argc, char** argv)
{
targetDesc.language = ShadingLanguage::Essl;
}
else if (targetName == "msl")
else if (targetName == "msl_macos")
{
targetDesc.language = ShadingLanguage::Msl;
targetDesc.language = ShadingLanguage::Msl_macOS;
}
else if (targetName == "msl_ios")
{
targetDesc.language = ShadingLanguage::Msl_iOS;
}
else
{
@ -139,7 +143,7 @@ int main(int argc, char** argv)
std::string outputName;
if (opts.count("output") == 0)
{
static const std::string extMap[] = { "dxil", "spv", "hlsl", "glsl", "essl", "msl" };
static const std::string extMap[] = { "dxil", "spv", "hlsl", "glsl", "essl", "msl", "msl" };
static_assert(sizeof(extMap) / sizeof(extMap[0]) == static_cast<uint32_t>(ShadingLanguage::NumShadingLanguages),
"extMap doesn't match with the number of shading languages.");
outputName = fileName + "." + extMap[static_cast<uint32_t>(targetDesc.language)];