Skip to content

Commit d4430cb

Browse files
committed
Merge changes from The Witness for iOS.
- Added better support for out and inout arguments in the MSL generator. Instead of passing these by reference, output arguments are wrapped in a temporary structure that's passed as return value. To make this work, the corresponding function call arguments need to be flattened and transformed into a list of statements. - Added support for sample_id semantic. - Added support for half, with an option to treat half as float in MSL. Support for half required better handling of type casts, since in many cases casts were not implicit as in HLSL. - Added support for treating integers as 16 bit integers (int -> short, uint->usrhot). - The generated MSL output is a bit cleaner and some unnecessary parenthesis have been removed. - Fixed support for some const declarations. - There's some work in progress to add support for static if and some new hlsl features that didn't make it for the iOS release.
1 parent 6d321de commit d4430cb

10 files changed

+1518
-306
lines changed

src/GLSLGenerator.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ void GLSLGenerator::OutputExpressionList(HLSLExpression* expression, HLSLArgumen
447447

448448
const HLSLType* commonScalarType(const HLSLType& lhs, const HLSLType& rhs)
449449
{
450-
if (!isScalarType(lhs) || !isScalarType(rhs))
450+
if (!IsScalarType(lhs) || !IsScalarType(rhs))
451451
return NULL;
452452

453453
if (lhs.baseType == HLSLBaseType_Float || lhs.baseType == HLSLBaseType_Half ||
@@ -571,8 +571,8 @@ void GLSLGenerator::OutputExpression(HLSLExpression* expression, const HLSLType*
571571
const HLSLType* dstType2 = NULL;
572572

573573
//
574-
bool vectorExpression = isVectorType( binaryExpression->expression1->expressionType ) || isVectorType( binaryExpression->expression2->expressionType );
575-
if( vectorExpression && isCompareOp( binaryExpression->binaryOp ))
574+
bool vectorExpression = IsVectorType( binaryExpression->expression1->expressionType ) || IsVectorType( binaryExpression->expression2->expressionType );
575+
if( vectorExpression && IsCompareOp( binaryExpression->binaryOp ))
576576
{
577577
switch (binaryExpression->binaryOp)
578578
{
@@ -586,9 +586,9 @@ void GLSLGenerator::OutputExpression(HLSLExpression* expression, const HLSLType*
586586
ASSERT(0); // is so, check isCompareOp
587587
}
588588

589-
if( isVectorType( binaryExpression->expression1->expressionType ) && isScalarType( binaryExpression->expression2->expressionType ) )
589+
if( IsVectorType( binaryExpression->expression1->expressionType ) && IsScalarType( binaryExpression->expression2->expressionType ) )
590590
dstType2 = &binaryExpression->expression1->expressionType;
591-
else if( isScalarType( binaryExpression->expression1->expressionType ) && isVectorType( binaryExpression->expression2->expressionType ) )
591+
else if( IsScalarType( binaryExpression->expression1->expressionType ) && IsVectorType( binaryExpression->expression2->expressionType ) )
592592
dstType1 = &binaryExpression->expression2->expressionType;
593593
// TODO if both expressions are vector but with different dimension handle it here or in parser?
594594

@@ -619,8 +619,8 @@ void GLSLGenerator::OutputExpression(HLSLExpression* expression, const HLSLType*
619619
case HLSLBinaryOp_And: op = " && "; dstType1 = dstType2 = &binaryExpression->expressionType; break;
620620
case HLSLBinaryOp_Or: op = " || "; dstType1 = dstType2 = &binaryExpression->expressionType; break;
621621
case HLSLBinaryOp_BitAnd: op = " & "; dstType1 = dstType2 = commonScalarType(binaryExpression->expression1->expressionType, binaryExpression->expression2->expressionType); break;
622-
case HLSLBinaryOp_BitOr: op = " | "; dstType1 = dstType2 = commonScalarType(binaryExpression->expression1->expressionType, binaryExpression->expression2->expressionType); break;
623-
case HLSLBinaryOp_BitXor: op = " ^ "; dstType1 = dstType2 = commonScalarType(binaryExpression->expression1->expressionType, binaryExpression->expression2->expressionType); break;
622+
case HLSLBinaryOp_BitOr: op = " | "; dstType1 = dstType2 = commonScalarType(binaryExpression->expression1->expressionType, binaryExpression->expression2->expressionType); break;
623+
case HLSLBinaryOp_BitXor: op = " ^ "; dstType1 = dstType2 = commonScalarType(binaryExpression->expression1->expressionType, binaryExpression->expression2->expressionType); break;
624624
default:
625625
ASSERT(0);
626626
}
@@ -634,7 +634,7 @@ void GLSLGenerator::OutputExpression(HLSLExpression* expression, const HLSLType*
634634
else if (expression->nodeType == HLSLNodeType_ConditionalExpression)
635635
{
636636
HLSLConditionalExpression* conditionalExpression = static_cast<HLSLConditionalExpression*>(expression);
637-
if( isVectorType( conditionalExpression->condition->expressionType ) )
637+
if( IsVectorType( conditionalExpression->condition->expressionType ) )
638638
{
639639
m_writer.Write( "%s", m_bvecTernary );
640640
m_writer.Write( "( " );

src/HLSLGenerator.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ static const char* GetTypeName(const HLSLType& type)
3232
case HLSLBaseType_Float4x4: return "float4x4";
3333
case HLSLBaseType_Float4x3: return "float4x3";
3434
case HLSLBaseType_Float4x2: return "float4x2";
35-
case HLSLBaseType_Half: return "half";
36-
case HLSLBaseType_Half2: return "half2";
37-
case HLSLBaseType_Half3: return "half3";
38-
case HLSLBaseType_Half4: return "half4";
39-
case HLSLBaseType_Half2x2: return "half2x2";
40-
case HLSLBaseType_Half3x3: return "half3x3";
41-
case HLSLBaseType_Half4x4: return "half4x4";
42-
case HLSLBaseType_Half4x3: return "half4x3";
43-
case HLSLBaseType_Half4x2: return "half4x2";
35+
case HLSLBaseType_Half: return "float";
36+
case HLSLBaseType_Half2: return "float2";
37+
case HLSLBaseType_Half3: return "float3";
38+
case HLSLBaseType_Half4: return "float4";
39+
case HLSLBaseType_Half2x2: return "float2x2";
40+
case HLSLBaseType_Half3x3: return "float3x3";
41+
case HLSLBaseType_Half4x4: return "float4x4";
42+
case HLSLBaseType_Half4x3: return "float4x3";
43+
case HLSLBaseType_Half4x2: return "float4x2";
4444
case HLSLBaseType_Bool: return "bool";
4545
case HLSLBaseType_Bool2: return "bool2";
4646
case HLSLBaseType_Bool3: return "bool3";
@@ -750,6 +750,8 @@ void HLSLGenerator::OutputArguments(HLSLArgument* argument)
750750
case HLSLArgumentModifier_Uniform:
751751
m_writer.Write("uniform ");
752752
break;
753+
default:
754+
break;
753755
}
754756

755757
const char * semantic = argument->sv_semantic ? argument->sv_semantic : argument->semantic;

0 commit comments

Comments
 (0)