Cast uses of Layer and ViewportIndex to the expected type.

This commit is contained in:
Chip Davis 2018-09-19 09:13:30 -05:00
parent 0e9ad14ba6
commit ec857f6778
5 changed files with 30 additions and 6 deletions

View File

@ -18,7 +18,7 @@ vertex main0_out main0(main0_in in [[stage_in]])
{
main0_out out = {};
out.gl_Position = in.coord;
out.gl_Layer = int(in.coord.z);
out.gl_Layer = uint(int(in.coord.z));
return out;
}

View File

@ -18,7 +18,7 @@ vertex main0_out main0(main0_in in [[stage_in]])
{
main0_out out = {};
out.gl_Position = in.coord;
out.gl_ViewportIndex = int(in.coord.z);
out.gl_ViewportIndex = uint(int(in.coord.z));
return out;
}

View File

@ -18,7 +18,7 @@ vertex main0_out main0(main0_in in [[stage_in]])
{
main0_out out = {};
out.gl_Position = in.coord;
out.gl_Layer = int(in.coord.z);
out.gl_Layer = uint(int(in.coord.z));
return out;
}

View File

@ -18,7 +18,7 @@ vertex main0_out main0(main0_in in [[stage_in]])
{
main0_out out = {};
out.gl_Position = in.coord;
out.gl_ViewportIndex = int(in.coord.z);
out.gl_ViewportIndex = uint(int(in.coord.z));
return out;
}

View File

@ -4714,6 +4714,8 @@ void CompilerMSL::bitcast_from_builtin_load(uint32_t source_id, std::string &exp
case BuiltInLocalInvocationIndex:
case BuiltInWorkgroupSize:
case BuiltInNumWorkgroups:
case BuiltInLayer:
case BuiltInViewportIndex:
expected_type = SPIRType::UInt;
break;
@ -4725,9 +4727,31 @@ void CompilerMSL::bitcast_from_builtin_load(uint32_t source_id, std::string &exp
expr = bitcast_expression(expr_type, expected_type, expr);
}
// MSL always declares output builtins with the SPIR-V type.
void CompilerMSL::bitcast_to_builtin_store(uint32_t, std::string &, const SPIRType &)
void CompilerMSL::bitcast_to_builtin_store(uint32_t target_id, std::string &expr, const SPIRType &expr_type)
{
// Only interested in standalone builtin variables.
if (!has_decoration(target_id, DecorationBuiltIn))
return;
auto builtin = static_cast<BuiltIn>(get_decoration(target_id, DecorationBuiltIn));
auto expected_type = expr_type.basetype;
switch (builtin)
{
case BuiltInLayer:
case BuiltInViewportIndex:
expected_type = SPIRType::UInt;
break;
default:
break;
}
if (expected_type != expr_type.basetype)
{
auto type = expr_type;
type.basetype = expected_type;
expr = bitcast_expression(type, expr_type.basetype, expr);
}
}
std::string CompilerMSL::to_initializer_expression(const SPIRVariable &var)