Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
glslang
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
glslang
Commits
61c47a95
Commit
61c47a95
authored
Dec 14, 2015
by
John Kessenich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Constant folding: Correct result type of non-square matrix folding.
This also made the function easier to read by identifying left and right operands more clearly.
parent
ea0cb2eb
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
106 additions
and
47 deletions
+106
-47
GlslangToSpv.cpp
SPIRV/GlslangToSpv.cpp
+1
-1
constFold.frag.out
Test/baseResults/constFold.frag.out
+50
-0
constFold.frag
Test/constFold.frag
+8
-0
revision.h
glslang/Include/revision.h
+2
-2
Constant.cpp
glslang/MachineIndependent/Constant.cpp
+45
-44
No files found.
SPIRV/GlslangToSpv.cpp
View file @
61c47a95
...
...
@@ -229,7 +229,7 @@ spv::Dim TranslateDimensionality(const glslang::TSampler& sampler)
spv
::
Decoration
TranslatePrecisionDecoration
(
const
glslang
::
TType
&
type
)
{
switch
(
type
.
getQualifier
().
precision
)
{
case
glslang
:
:
EpqLow
:
return
spv
::
DecorationRelaxedPrecision
;
// TODO: Map instead to 16-bit types?
case
glslang
:
:
EpqLow
:
return
spv
::
DecorationRelaxedPrecision
;
case
glslang
:
:
EpqMedium
:
return
spv
::
DecorationRelaxedPrecision
;
case
glslang
:
:
EpqHigh
:
return
spv
::
NoPrecision
;
default
:
...
...
Test/baseResults/constFold.frag.out
View file @
61c47a95
...
...
@@ -257,6 +257,19 @@ 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:? Linker Objects
0:? 'a' (const int)
0:? 1 (const int)
...
...
@@ -331,6 +344,18 @@ ERROR: node is still EOpNull!
0:? 4.000000
0:? 5.000000
0:? 'a4' (global 2-element array of float)
0:? 'mm2' (const 2X2 matrix of float)
0:? 1.000000
0:? 2.000000
0:? 3.000000
0:? 4.000000
0:? 'mm32' (const 3X2 matrix of float)
0:? 10.000000
0:? 11.000000
0:? 12.000000
0:? 13.000000
0:? 14.000000
0:? 15.000000
Linked fragment stage:
...
...
@@ -584,6 +609,19 @@ 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:? Linker Objects
0:? 'a' (const int)
0:? 1 (const int)
...
...
@@ -658,4 +696,16 @@ ERROR: node is still EOpNull!
0:? 4.000000
0:? 5.000000
0:? 'a4' (global 2-element array of float)
0:? 'mm2' (const 2X2 matrix of float)
0:? 1.000000
0:? 2.000000
0:? 3.000000
0:? 4.000000
0:? 'mm32' (const 3X2 matrix of float)
0:? 10.000000
0:? 11.000000
0:? 12.000000
0:? 13.000000
0:? 14.000000
0:? 15.000000
Test/constFold.frag
View file @
61c47a95
...
...
@@ -119,3 +119,11 @@ void foo2()
float
f
=
vec4
(
7
.
8
<
2
.
4
?
-
1
.
333
:
1
.
444
).
a
;
f
=
vec4
(
inv
.
x
<
2
.
4
?
-
1
.
0
:
1
.
0
).
a
;
// not folded, ensuring no propagation
}
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
);
void
foo3
()
{
mat3x2
r32
=
mm2
*
mm32
;
}
glslang/Include/revision.h
View file @
61c47a95
...
...
@@ -2,5 +2,5 @@
// For the version, it uses the latest git tag followed by the number of commits.
// For the date, it uses the current date (when then script is run).
#define GLSLANG_REVISION "SPIRV99.84
5
"
#define GLSLANG_DATE "1
3
-Dec-2015"
#define GLSLANG_REVISION "SPIRV99.84
9
"
#define GLSLANG_DATE "1
6
-Dec-2015"
glslang/MachineIndependent/Constant.cpp
View file @
61c47a95
...
...
@@ -81,11 +81,12 @@ namespace glslang {
//
//
// Do folding between a pair of nodes
// Do folding between a pair of nodes.
// 'this' is the left-hand operand and 'rightConstantNode' is the right-hand operand.
//
// Returns a new node representing the result.
//
TIntermTyped
*
TIntermConstantUnion
::
fold
(
TOperator
op
,
const
TIntermTyped
*
c
onstantNode
)
const
TIntermTyped
*
TIntermConstantUnion
::
fold
(
TOperator
op
,
const
TIntermTyped
*
rightC
onstantNode
)
const
{
// For most cases, the return type matches the argument type, so set that
// up and just code to exceptions below.
...
...
@@ -96,37 +97,37 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TIntermTyped* const
// A pair of nodes is to be folded together
//
const
TIntermConstantUnion
*
node
=
c
onstantNode
->
getAsConstantUnion
();
TConstUnionArray
u
nionArray
=
getConstArray
();
TConstUnionArray
rightUnionArray
=
n
ode
->
getConstArray
();
const
TIntermConstantUnion
*
rightNode
=
rightC
onstantNode
->
getAsConstantUnion
();
TConstUnionArray
leftU
nionArray
=
getConstArray
();
TConstUnionArray
rightUnionArray
=
rightN
ode
->
getConstArray
();
// Figure out the size of the result
int
newComps
;
int
constComps
;
switch
(
op
)
{
case
EOpMatrixTimesMatrix
:
newComps
=
getMatrixRows
()
*
node
->
getMatrixCol
s
();
newComps
=
rightNode
->
getMatrixCols
()
*
getMatrixRow
s
();
break
;
case
EOpMatrixTimesVector
:
newComps
=
getMatrixRows
();
break
;
case
EOpVectorTimesMatrix
:
newComps
=
n
ode
->
getMatrixCols
();
newComps
=
rightN
ode
->
getMatrixCols
();
break
;
default
:
newComps
=
getType
().
computeNumComponents
();
constComps
=
c
onstantNode
->
getType
().
computeNumComponents
();
constComps
=
rightC
onstantNode
->
getType
().
computeNumComponents
();
if
(
constComps
==
1
&&
newComps
>
1
)
{
// for a case like vec4 f = vec4(2,3,4,5) + 1.2;
TConstUnionArray
smearedArray
(
newComps
,
n
ode
->
getConstArray
()[
0
]);
TConstUnionArray
smearedArray
(
newComps
,
rightN
ode
->
getConstArray
()[
0
]);
rightUnionArray
=
smearedArray
;
}
else
if
(
constComps
>
1
&&
newComps
==
1
)
{
// for a case like vec4 f = 1.2 + vec4(2,3,4,5);
newComps
=
constComps
;
rightUnionArray
=
n
ode
->
getConstArray
();
rightUnionArray
=
rightN
ode
->
getConstArray
();
TConstUnionArray
smearedArray
(
newComps
,
getConstArray
()[
0
]);
u
nionArray
=
smearedArray
;
returnType
.
shallowCopy
(
n
ode
->
getType
());
leftU
nionArray
=
smearedArray
;
returnType
.
shallowCopy
(
rightN
ode
->
getType
());
}
break
;
}
...
...
@@ -137,52 +138,52 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TIntermTyped* const
switch
(
op
)
{
case
EOpAdd
:
for
(
int
i
=
0
;
i
<
newComps
;
i
++
)
newConstArray
[
i
]
=
u
nionArray
[
i
]
+
rightUnionArray
[
i
];
newConstArray
[
i
]
=
leftU
nionArray
[
i
]
+
rightUnionArray
[
i
];
break
;
case
EOpSub
:
for
(
int
i
=
0
;
i
<
newComps
;
i
++
)
newConstArray
[
i
]
=
u
nionArray
[
i
]
-
rightUnionArray
[
i
];
newConstArray
[
i
]
=
leftU
nionArray
[
i
]
-
rightUnionArray
[
i
];
break
;
case
EOpMul
:
case
EOpVectorTimesScalar
:
case
EOpMatrixTimesScalar
:
for
(
int
i
=
0
;
i
<
newComps
;
i
++
)
newConstArray
[
i
]
=
u
nionArray
[
i
]
*
rightUnionArray
[
i
];
newConstArray
[
i
]
=
leftU
nionArray
[
i
]
*
rightUnionArray
[
i
];
break
;
case
EOpMatrixTimesMatrix
:
for
(
int
row
=
0
;
row
<
getMatrixRows
();
row
++
)
{
for
(
int
column
=
0
;
column
<
n
ode
->
getMatrixCols
();
column
++
)
{
for
(
int
column
=
0
;
column
<
rightN
ode
->
getMatrixCols
();
column
++
)
{
double
sum
=
0.0
f
;
for
(
int
i
=
0
;
i
<
n
ode
->
getMatrixRows
();
i
++
)
sum
+=
unionArray
[
i
*
getMatrixRows
()
+
row
].
getDConst
()
*
rightUnionArray
[
column
*
n
ode
->
getMatrixRows
()
+
i
].
getDConst
();
for
(
int
i
=
0
;
i
<
rightN
ode
->
getMatrixRows
();
i
++
)
sum
+=
leftUnionArray
[
i
*
getMatrixRows
()
+
row
].
getDConst
()
*
rightUnionArray
[
column
*
rightN
ode
->
getMatrixRows
()
+
i
].
getDConst
();
newConstArray
[
column
*
getMatrixRows
()
+
row
].
setDConst
(
sum
);
}
}
returnType
.
shallowCopy
(
TType
(
getType
().
getBasicType
(),
EvqConst
,
0
,
getMatrixRows
(),
node
->
getMatrixCol
s
()));
returnType
.
shallowCopy
(
TType
(
getType
().
getBasicType
(),
EvqConst
,
0
,
rightNode
->
getMatrixCols
(),
getMatrixRow
s
()));
break
;
case
EOpDiv
:
for
(
int
i
=
0
;
i
<
newComps
;
i
++
)
{
switch
(
getType
().
getBasicType
())
{
case
EbtDouble
:
case
EbtFloat
:
newConstArray
[
i
].
setDConst
(
u
nionArray
[
i
].
getDConst
()
/
rightUnionArray
[
i
].
getDConst
());
newConstArray
[
i
].
setDConst
(
leftU
nionArray
[
i
].
getDConst
()
/
rightUnionArray
[
i
].
getDConst
());
break
;
case
EbtInt
:
if
(
rightUnionArray
[
i
]
==
0
)
newConstArray
[
i
].
setIConst
(
0x7FFFFFFF
);
else
if
(
rightUnionArray
[
i
].
getIConst
()
==
-
1
&&
u
nionArray
[
i
].
getIConst
()
==
0x80000000
)
else
if
(
rightUnionArray
[
i
].
getIConst
()
==
-
1
&&
leftU
nionArray
[
i
].
getIConst
()
==
0x80000000
)
newConstArray
[
i
].
setIConst
(
0x80000000
);
else
newConstArray
[
i
].
setIConst
(
u
nionArray
[
i
].
getIConst
()
/
rightUnionArray
[
i
].
getIConst
());
newConstArray
[
i
].
setIConst
(
leftU
nionArray
[
i
].
getIConst
()
/
rightUnionArray
[
i
].
getIConst
());
break
;
case
EbtUint
:
if
(
rightUnionArray
[
i
]
==
0
)
{
newConstArray
[
i
].
setUConst
(
0xFFFFFFFF
);
}
else
newConstArray
[
i
].
setUConst
(
u
nionArray
[
i
].
getUConst
()
/
rightUnionArray
[
i
].
getUConst
());
newConstArray
[
i
].
setUConst
(
leftU
nionArray
[
i
].
getUConst
()
/
rightUnionArray
[
i
].
getUConst
());
break
;
default
:
return
0
;
...
...
@@ -193,8 +194,8 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TIntermTyped* const
case
EOpMatrixTimesVector
:
for
(
int
i
=
0
;
i
<
getMatrixRows
();
i
++
)
{
double
sum
=
0.0
f
;
for
(
int
j
=
0
;
j
<
n
ode
->
getVectorSize
();
j
++
)
{
sum
+=
u
nionArray
[
j
*
getMatrixRows
()
+
i
].
getDConst
()
*
rightUnionArray
[
j
].
getDConst
();
for
(
int
j
=
0
;
j
<
rightN
ode
->
getVectorSize
();
j
++
)
{
sum
+=
leftU
nionArray
[
j
*
getMatrixRows
()
+
i
].
getDConst
()
*
rightUnionArray
[
j
].
getDConst
();
}
newConstArray
[
i
].
setDConst
(
sum
);
}
...
...
@@ -203,89 +204,89 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TIntermTyped* const
break
;
case
EOpVectorTimesMatrix
:
for
(
int
i
=
0
;
i
<
n
ode
->
getMatrixCols
();
i
++
)
{
for
(
int
i
=
0
;
i
<
rightN
ode
->
getMatrixCols
();
i
++
)
{
double
sum
=
0.0
f
;
for
(
int
j
=
0
;
j
<
getVectorSize
();
j
++
)
sum
+=
unionArray
[
j
].
getDConst
()
*
rightUnionArray
[
i
*
n
ode
->
getMatrixRows
()
+
j
].
getDConst
();
sum
+=
leftUnionArray
[
j
].
getDConst
()
*
rightUnionArray
[
i
*
rightN
ode
->
getMatrixRows
()
+
j
].
getDConst
();
newConstArray
[
i
].
setDConst
(
sum
);
}
returnType
.
shallowCopy
(
TType
(
getBasicType
(),
EvqConst
,
n
ode
->
getMatrixCols
()));
returnType
.
shallowCopy
(
TType
(
getBasicType
(),
EvqConst
,
rightN
ode
->
getMatrixCols
()));
break
;
case
EOpMod
:
for
(
int
i
=
0
;
i
<
newComps
;
i
++
)
{
if
(
rightUnionArray
[
i
]
==
0
)
newConstArray
[
i
]
=
u
nionArray
[
i
];
newConstArray
[
i
]
=
leftU
nionArray
[
i
];
else
newConstArray
[
i
]
=
u
nionArray
[
i
]
%
rightUnionArray
[
i
];
newConstArray
[
i
]
=
leftU
nionArray
[
i
]
%
rightUnionArray
[
i
];
}
break
;
case
EOpRightShift
:
for
(
int
i
=
0
;
i
<
newComps
;
i
++
)
newConstArray
[
i
]
=
u
nionArray
[
i
]
>>
rightUnionArray
[
i
];
newConstArray
[
i
]
=
leftU
nionArray
[
i
]
>>
rightUnionArray
[
i
];
break
;
case
EOpLeftShift
:
for
(
int
i
=
0
;
i
<
newComps
;
i
++
)
newConstArray
[
i
]
=
u
nionArray
[
i
]
<<
rightUnionArray
[
i
];
newConstArray
[
i
]
=
leftU
nionArray
[
i
]
<<
rightUnionArray
[
i
];
break
;
case
EOpAnd
:
for
(
int
i
=
0
;
i
<
newComps
;
i
++
)
newConstArray
[
i
]
=
u
nionArray
[
i
]
&
rightUnionArray
[
i
];
newConstArray
[
i
]
=
leftU
nionArray
[
i
]
&
rightUnionArray
[
i
];
break
;
case
EOpInclusiveOr
:
for
(
int
i
=
0
;
i
<
newComps
;
i
++
)
newConstArray
[
i
]
=
u
nionArray
[
i
]
|
rightUnionArray
[
i
];
newConstArray
[
i
]
=
leftU
nionArray
[
i
]
|
rightUnionArray
[
i
];
break
;
case
EOpExclusiveOr
:
for
(
int
i
=
0
;
i
<
newComps
;
i
++
)
newConstArray
[
i
]
=
u
nionArray
[
i
]
^
rightUnionArray
[
i
];
newConstArray
[
i
]
=
leftU
nionArray
[
i
]
^
rightUnionArray
[
i
];
break
;
case
EOpLogicalAnd
:
// this code is written for possible future use, will not get executed currently
for
(
int
i
=
0
;
i
<
newComps
;
i
++
)
newConstArray
[
i
]
=
u
nionArray
[
i
]
&&
rightUnionArray
[
i
];
newConstArray
[
i
]
=
leftU
nionArray
[
i
]
&&
rightUnionArray
[
i
];
break
;
case
EOpLogicalOr
:
// this code is written for possible future use, will not get executed currently
for
(
int
i
=
0
;
i
<
newComps
;
i
++
)
newConstArray
[
i
]
=
u
nionArray
[
i
]
||
rightUnionArray
[
i
];
newConstArray
[
i
]
=
leftU
nionArray
[
i
]
||
rightUnionArray
[
i
];
break
;
case
EOpLogicalXor
:
for
(
int
i
=
0
;
i
<
newComps
;
i
++
)
{
switch
(
getType
().
getBasicType
())
{
case
EbtBool
:
newConstArray
[
i
].
setBConst
((
u
nionArray
[
i
]
==
rightUnionArray
[
i
])
?
false
:
true
);
break
;
case
EbtBool
:
newConstArray
[
i
].
setBConst
((
leftU
nionArray
[
i
]
==
rightUnionArray
[
i
])
?
false
:
true
);
break
;
default
:
assert
(
false
&&
"Default missing"
);
}
}
break
;
case
EOpLessThan
:
newConstArray
[
0
].
setBConst
(
u
nionArray
[
0
]
<
rightUnionArray
[
0
]);
newConstArray
[
0
].
setBConst
(
leftU
nionArray
[
0
]
<
rightUnionArray
[
0
]);
returnType
.
shallowCopy
(
constBool
);
break
;
case
EOpGreaterThan
:
newConstArray
[
0
].
setBConst
(
u
nionArray
[
0
]
>
rightUnionArray
[
0
]);
newConstArray
[
0
].
setBConst
(
leftU
nionArray
[
0
]
>
rightUnionArray
[
0
]);
returnType
.
shallowCopy
(
constBool
);
break
;
case
EOpLessThanEqual
:
newConstArray
[
0
].
setBConst
(
!
(
u
nionArray
[
0
]
>
rightUnionArray
[
0
]));
newConstArray
[
0
].
setBConst
(
!
(
leftU
nionArray
[
0
]
>
rightUnionArray
[
0
]));
returnType
.
shallowCopy
(
constBool
);
break
;
case
EOpGreaterThanEqual
:
newConstArray
[
0
].
setBConst
(
!
(
u
nionArray
[
0
]
<
rightUnionArray
[
0
]));
newConstArray
[
0
].
setBConst
(
!
(
leftU
nionArray
[
0
]
<
rightUnionArray
[
0
]));
returnType
.
shallowCopy
(
constBool
);
break
;
case
EOpEqual
:
newConstArray
[
0
].
setBConst
(
node
->
getConstArray
()
==
u
nionArray
);
newConstArray
[
0
].
setBConst
(
rightNode
->
getConstArray
()
==
leftU
nionArray
);
returnType
.
shallowCopy
(
constBool
);
break
;
case
EOpNotEqual
:
newConstArray
[
0
].
setBConst
(
node
->
getConstArray
()
!=
u
nionArray
);
newConstArray
[
0
].
setBConst
(
rightNode
->
getConstArray
()
!=
leftU
nionArray
);
returnType
.
shallowCopy
(
constBool
);
break
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment