Permalink
Browse files

Fixed wrong translation of 2x2 and 3x3 matrix initializers from a sca…

…lar (e.g. float3x3 m = 0.0)
  • Loading branch information...
1 parent 203660f commit 2690acb9c3499ba3ad3aac9045975d5ead220fcc @aras-p committed Feb 25, 2014
View
@@ -1,6 +1,13 @@
hlsl2glsl Change Log
=========================
+2014 02
+-------
+
+Fixes:
+
+* Fixed wrong translation of 2x2 and 3x3 matrix initializers from a scalar (e.g. float3x3 m = 0.0).
+
2013 11
-------
@@ -1114,6 +1114,25 @@ static TOperator getMatrixConstructOp(const TIntermTyped& intermediate, TParseCo
return EOpNull;
}
+static TOperator getMatrixConstructOpWithRHS(const TIntermTyped& intermediate, const TType& rhsType, TParseContext& ctx)
+{
+ // If RHS is scalar and we're targeting old GLSL version, then
+ // no need to treat operator as "create small matrix from a 4x4 one";
+ // we can create it from scalar directly.
+ if (rhsType.isScalar() && ctx.targetVersion < ETargetGLSL_120)
+ {
+ const int c = intermediate.getColsCount();
+ const int r = intermediate.getRowsCount();
+ if (c == 2 && r == 2)
+ return EOpConstructMat2x2;
+ if (c == 3 && r == 3)
+ return EOpConstructMat3x3;
+ if (c == 4 && r == 4)
+ return EOpConstructMat4x4;
+ }
+ return getMatrixConstructOp(intermediate, ctx);
+}
+
//
// Establishes the type of the resultant operation, as well as
@@ -1439,7 +1458,7 @@ bool TIntermBinary::promote(TParseContext& ctx)
if (left->isMatrix() )
{
- convert = getMatrixConstructOp(*left, ctx);
+ convert = getMatrixConstructOpWithRHS(*left, *right->getTypePointer(), ctx);
if (convert == EOpNull)
return false;
}
@@ -2,6 +2,8 @@
float4 main (float4 pos : POSITION) : POSITION
{
float4 v = 0;
+
+ // 2x2 matrices
float2x2 m2 = float2x2(
1, 2,
3, 4
@@ -10,8 +12,14 @@ float4 main (float4 pos : POSITION) : POSITION
float2 (1,2),
float2 (3,4)
);
+ float2x2 m2c = float2x2(1.0);
+ float2x2 m2d = 1.0;
v.xy += mul (m2, pos.xy);
v.xy += mul (m2b, pos.xy);
+ v.xy += mul (m2c, pos.xy);
+ v.xy += mul (m2d, pos.xy);
+
+ // 3x3 matrices
float3x3 m3 = float3x3(
1, 2, 3,
4, 5, 6,
@@ -27,9 +35,15 @@ float4 main (float4 pos : POSITION) : POSITION
float3(4, 5, 6),
pos.xyz
);
+ float3x3 m3d = float3x3(1.0);
+ float3x3 m3e = 1.0;
v.xyz += mul (m3, pos.xyz);
v.xyz += mul (m3b, pos.xyz);
v.xyz += mul (m3c, pos.xyz);
+ v.xyz += mul (m3d, pos.xyz);
+ v.xyz += mul (m3e, pos.xyz);
+
+ // 4x4 matrices
float4x4 m4 = float4x4(
1, 2, 3, 4,
5, 6, 7, 8,
@@ -42,7 +56,11 @@ float4 main (float4 pos : POSITION) : POSITION
float4(9, 10, 11, 12),
float4(13, 14, 15, 16)
);
+ float4x4 m4c = float4x4(1.0);
+ float4x4 m4d = 1.0;
v.xyzw += mul (m4, pos.xyzw);
v.xyzw += mul (m4b, pos.xyzw);
+ v.xyzw += mul (m4c, pos.xyzw);
+ v.xyzw += mul (m4d, pos.xyzw);
return v;
}
@@ -17,26 +17,43 @@ vec4 xlat_main( in vec4 pos ) {
#line 3
vec4 v = vec4( 0.0);
mat2 m2 = mat2( 1.0, 3.0, 2.0, 4.0);
- #line 8
+ #line 10
mat2 m2b = xll_transpose_mf2x2(mat2( vec2( 1.0, 2.0), vec2( 3.0, 4.0)));
- #line 12
+ #line 14
+ mat2 m2c = mat2( 1.0);
+ mat2 m2d = mat2( 1.0);
v.xy += (m2 * pos.xy);
v.xy += (m2b * pos.xy);
+ #line 18
+ v.xy += (m2c * pos.xy);
+ v.xy += (m2d * pos.xy);
+ #line 22
mat3 m3 = mat3( 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0);
- #line 19
+ #line 27
mat3 m3b = xll_transpose_mf3x3(mat3( vec3( 1.0, 2.0, 3.0), vec3( 4.0, 5.0, 6.0), vec3( 7.0, 8.0, 9.0)));
- #line 24
+ #line 32
mat3 m3c = xll_transpose_mf3x3(mat3( vec3( 1.0, 2.0, 3.0), vec3( 4.0, 5.0, 6.0), pos.xyz));
- #line 29
+ #line 37
+ mat3 m3d = mat3( 1.0);
+ mat3 m3e = mat3( 1.0);
v.xyz += (m3 * pos.xyz);
v.xyz += (m3b * pos.xyz);
+ #line 41
v.xyz += (m3c * pos.xyz);
+ v.xyz += (m3d * pos.xyz);
+ v.xyz += (m3e * pos.xyz);
+ #line 46
mat4 m4 = mat4( 1.0, 5.0, 9.0, 13.0, 2.0, 6.0, 10.0, 14.0, 3.0, 7.0, 11.0, 15.0, 4.0, 8.0, 12.0, 16.0);
- #line 38
+ #line 52
mat4 m4b = xll_transpose_mf4x4(mat4( vec4( 1.0, 2.0, 3.0, 4.0), vec4( 5.0, 6.0, 7.0, 8.0), vec4( 9.0, 10.0, 11.0, 12.0), vec4( 13.0, 14.0, 15.0, 16.0)));
- #line 44
+ #line 58
+ mat4 m4c = mat4( 1.0);
+ mat4 m4d = mat4( 1.0);
v.xyzw += (m4 * pos.xyzw);
v.xyzw += (m4b * pos.xyzw);
+ #line 62
+ v.xyzw += (m4c * pos.xyzw);
+ v.xyzw += (m4d * pos.xyzw);
return v;
}
void main() {
@@ -17,26 +17,43 @@ highp vec4 xlat_main( in highp vec4 pos ) {
#line 3
highp vec4 v = vec4( 0.0);
highp mat2 m2 = mat2( 1.0, 3.0, 2.0, 4.0);
- #line 8
+ #line 10
highp mat2 m2b = xll_transpose_mf2x2(mat2( vec2( 1.0, 2.0), vec2( 3.0, 4.0)));
- #line 12
+ #line 14
+ highp mat2 m2c = mat2( 1.0);
+ highp mat2 m2d = mat2( 1.0);
v.xy += (m2 * pos.xy);
v.xy += (m2b * pos.xy);
+ #line 18
+ v.xy += (m2c * pos.xy);
+ v.xy += (m2d * pos.xy);
+ #line 22
highp mat3 m3 = mat3( 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0);
- #line 19
+ #line 27
highp mat3 m3b = xll_transpose_mf3x3(mat3( vec3( 1.0, 2.0, 3.0), vec3( 4.0, 5.0, 6.0), vec3( 7.0, 8.0, 9.0)));
- #line 24
+ #line 32
highp mat3 m3c = xll_transpose_mf3x3(mat3( vec3( 1.0, 2.0, 3.0), vec3( 4.0, 5.0, 6.0), pos.xyz));
- #line 29
+ #line 37
+ highp mat3 m3d = mat3( 1.0);
+ highp mat3 m3e = mat3( 1.0);
v.xyz += (m3 * pos.xyz);
v.xyz += (m3b * pos.xyz);
+ #line 41
v.xyz += (m3c * pos.xyz);
+ v.xyz += (m3d * pos.xyz);
+ v.xyz += (m3e * pos.xyz);
+ #line 46
highp mat4 m4 = mat4( 1.0, 5.0, 9.0, 13.0, 2.0, 6.0, 10.0, 14.0, 3.0, 7.0, 11.0, 15.0, 4.0, 8.0, 12.0, 16.0);
- #line 38
+ #line 52
highp mat4 m4b = xll_transpose_mf4x4(mat4( vec4( 1.0, 2.0, 3.0, 4.0), vec4( 5.0, 6.0, 7.0, 8.0), vec4( 9.0, 10.0, 11.0, 12.0), vec4( 13.0, 14.0, 15.0, 16.0)));
- #line 44
+ #line 58
+ highp mat4 m4c = mat4( 1.0);
+ highp mat4 m4d = mat4( 1.0);
v.xyzw += (m4 * pos.xyzw);
v.xyzw += (m4b * pos.xyzw);
+ #line 62
+ v.xyzw += (m4c * pos.xyzw);
+ v.xyzw += (m4d * pos.xyzw);
return v;
}
attribute highp vec4 xlat_attrib_POSITION;
@@ -17,26 +17,43 @@ highp vec4 xlat_main( in highp vec4 pos ) {
#line 3
highp vec4 v = vec4( 0.0);
highp mat2 m2 = mat2( 1.0, 3.0, 2.0, 4.0);
- #line 8
+ #line 10
highp mat2 m2b = xll_transpose_mf2x2(mat2( vec2( 1.0, 2.0), vec2( 3.0, 4.0)));
- #line 12
+ #line 14
+ highp mat2 m2c = mat2( 1.0);
+ highp mat2 m2d = mat2( 1.0);
v.xy += (m2 * pos.xy);
v.xy += (m2b * pos.xy);
+ #line 18
+ v.xy += (m2c * pos.xy);
+ v.xy += (m2d * pos.xy);
+ #line 22
highp mat3 m3 = mat3( 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0);
- #line 19
+ #line 27
highp mat3 m3b = xll_transpose_mf3x3(mat3( vec3( 1.0, 2.0, 3.0), vec3( 4.0, 5.0, 6.0), vec3( 7.0, 8.0, 9.0)));
- #line 24
+ #line 32
highp mat3 m3c = xll_transpose_mf3x3(mat3( vec3( 1.0, 2.0, 3.0), vec3( 4.0, 5.0, 6.0), pos.xyz));
- #line 29
+ #line 37
+ highp mat3 m3d = mat3( 1.0);
+ highp mat3 m3e = mat3( 1.0);
v.xyz += (m3 * pos.xyz);
v.xyz += (m3b * pos.xyz);
+ #line 41
v.xyz += (m3c * pos.xyz);
+ v.xyz += (m3d * pos.xyz);
+ v.xyz += (m3e * pos.xyz);
+ #line 46
highp mat4 m4 = mat4( 1.0, 5.0, 9.0, 13.0, 2.0, 6.0, 10.0, 14.0, 3.0, 7.0, 11.0, 15.0, 4.0, 8.0, 12.0, 16.0);
- #line 38
+ #line 52
highp mat4 m4b = xll_transpose_mf4x4(mat4( vec4( 1.0, 2.0, 3.0, 4.0), vec4( 5.0, 6.0, 7.0, 8.0), vec4( 9.0, 10.0, 11.0, 12.0), vec4( 13.0, 14.0, 15.0, 16.0)));
- #line 44
+ #line 58
+ highp mat4 m4c = mat4( 1.0);
+ highp mat4 m4d = mat4( 1.0);
v.xyzw += (m4 * pos.xyzw);
v.xyzw += (m4b * pos.xyzw);
+ #line 62
+ v.xyzw += (m4c * pos.xyzw);
+ v.xyzw += (m4d * pos.xyzw);
return v;
}
in highp vec4 xlat_attrib_POSITION;

0 comments on commit 2690acb

Please sign in to comment.