Skip to content

Commit

Permalink
Fix #2132: constant matrix constructor from single non-scalar argument
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkslang committed Mar 18, 2020
1 parent 4b420b4 commit 8c21e0a
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 25 deletions.
88 changes: 67 additions & 21 deletions Test/baseResults/constFold.frag.out
Original file line number Diff line number Diff line change
Expand Up @@ -260,27 +260,27 @@ ERROR: node is still EOpNull!
0:120 1.000000
0:120 Constant:
0:120 3 (const int)
0:126 Function Definition: foo3( ( global void)
0:126 Function Parameters:
0:128 Sequence
0:128 Sequence
0:128 move second child to first child ( temp 3X2 matrix of float)
0:128 'r32' ( temp 3X2 matrix of float)
0:128 Constant:
0:128 43.000000
0:128 64.000000
0:128 51.000000
0:128 76.000000
0:128 59.000000
0:128 88.000000
0:138 Function Definition: foo4( ( global void)
0:138 Function Parameters:
0:140 Sequence
0:140 Sequence
0:140 move second child to first child ( temp int)
0:140 'a' ( temp int)
0:140 Constant:
0:140 9 (const int)
0:129 Function Definition: foo3( ( global void)
0:129 Function Parameters:
0:131 Sequence
0:131 Sequence
0:131 move second child to first child ( temp 3X2 matrix of float)
0:131 'r32' ( temp 3X2 matrix of float)
0:131 Constant:
0:131 43.000000
0:131 64.000000
0:131 51.000000
0:131 76.000000
0:131 59.000000
0:131 88.000000
0:141 Function Definition: foo4( ( global void)
0:141 Function Parameters:
0:143 Sequence
0:143 Sequence
0:143 move second child to first child ( temp int)
0:143 'a' ( temp int)
0:143 Constant:
0:143 9 (const int)
0:? Linker Objects
0:? 'a' ( const int)
0:? 1 (const int)
Expand Down Expand Up @@ -367,6 +367,29 @@ ERROR: node is still EOpNull!
0:? 13.000000
0:? 14.000000
0:? 15.000000
0:? 'm22' ( const 2X2 matrix of float)
0:? 1.000000
0:? 2.000000
0:? 3.000000
0:? 4.000000
0:? 'mm34' ( const 3X4 matrix of float)
0:? 7.000000
0:? 0.000000
0:? 0.000000
0:? 0.000000
0:? 0.000000
0:? 7.000000
0:? 0.000000
0:? 0.000000
0:? 0.000000
0:? 0.000000
0:? 7.000000
0:? 0.000000
0:? 'mv4' ( const 4-component vector of float)
0:? 1.000000
0:? 2.000000
0:? 3.000000
0:? 4.000000
0:? 'a0' ( const 3-element array of structure{ global int i, global float f, global bool b})
0:? 3 (const int)
0:? 2.000000
Expand Down Expand Up @@ -635,6 +658,29 @@ ERROR: node is still EOpNull!
0:? 13.000000
0:? 14.000000
0:? 15.000000
0:? 'm22' ( const 2X2 matrix of float)
0:? 1.000000
0:? 2.000000
0:? 3.000000
0:? 4.000000
0:? 'mm34' ( const 3X4 matrix of float)
0:? 7.000000
0:? 0.000000
0:? 0.000000
0:? 0.000000
0:? 0.000000
0:? 7.000000
0:? 0.000000
0:? 0.000000
0:? 0.000000
0:? 0.000000
0:? 7.000000
0:? 0.000000
0:? 'mv4' ( const 4-component vector of float)
0:? 1.000000
0:? 2.000000
0:? 3.000000
0:? 4.000000
0:? 'a0' ( const 3-element array of structure{ global int i, global float f, global bool b})
0:? 3 (const int)
0:? 2.000000
Expand Down
3 changes: 3 additions & 0 deletions Test/constFold.frag
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ void foo2()

const mat2 mm2 = mat2(1.0, 2.0, 3.0, 4.0);
const mat3x2 mm32 = mat3x2(10.0, 11.0, 12.0, 13.0, 14.0, 15.0);
const mat2 m22 = mat2(vec4(1.0, 2.0, 3.0, 4.0));
const mat3x4 mm34 = mat3x4(7.0);
const vec4 mv4 = vec4(m22);

void foo3()
{
Expand Down
18 changes: 14 additions & 4 deletions glslang/MachineIndependent/parseConst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,27 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node)
}
}
} else {
// matrix from vector
// matrix from vector or scalar
int count = 0;
const int startIndex = index;
int nodeComps = node->getType().computeNumComponents();
for (int i = startIndex; i < endIndex; i++) {
if (i >= instanceSize)
return;
if (i == startIndex || (i - startIndex) % (matrixRows + 1) == 0 )
if (nodeComps == 1) {
// If there is a single scalar parameter to a matrix
// constructor, it is used to initialize all the
// components on the matrix’s diagonal, with the

This comment has been minimized.

Copy link
@courtney-g

courtney-g Mar 19, 2020

Contributor

Something weird is going on here.
The Microsoft compiler is complaining about an illegal character. I think it's the single quote in matrix's.
Here's the error:
FAILED: obj/third_party/glslang/src/glslang_sources/parseConst.obj

../../third_party/glslang/src/glslang/MachineIndependent/parseConst.cpp(1): error C2220: the following warning is treated as an error
../../third_party/glslang/src/glslang/MachineIndependent/parseConst.cpp(1): warning C4828: The file contains a character starting at offset 0x19ce that is illegal in the current source character set (codepage 65001).

Logged at bug #2140.

// remaining components initialized to 0.0.
if (i == startIndex || (i - startIndex) % (matrixRows + 1) == 0 )
leftUnionArray[i] = rightUnionArray[count];
else
leftUnionArray[i].setDConst(0.0);
} else {
// construct the matrix in column-major order, from
// the components provided, in order
leftUnionArray[i] = rightUnionArray[count];
else
leftUnionArray[i].setDConst(0.0);
}

index++;

Expand Down

0 comments on commit 8c21e0a

Please sign in to comment.