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
7a53f76d
Commit
7a53f76d
authored
Jan 20, 2016
by
John Kessenich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SPV: Add unary-matrix operations, operating at vector level.
parent
dd1c2235
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
176 additions
and
132 deletions
+176
-132
GlslangToSpv.cpp
SPIRV/GlslangToSpv.cpp
+38
-2
spv.branch-return.vert.out
Test/baseResults/spv.branch-return.vert.out
+1
-1
spv.matrix2.frag.out
Test/baseResults/spv.matrix2.frag.out
+137
-129
No files found.
SPIRV/GlslangToSpv.cpp
View file @
7a53f76d
...
@@ -110,6 +110,7 @@ protected:
...
@@ -110,6 +110,7 @@ protected:
spv
::
Id
createBinaryOperation
(
glslang
::
TOperator
op
,
spv
::
Decoration
precision
,
spv
::
Id
typeId
,
spv
::
Id
left
,
spv
::
Id
right
,
glslang
::
TBasicType
typeProxy
,
bool
reduceComparison
=
true
);
spv
::
Id
createBinaryOperation
(
glslang
::
TOperator
op
,
spv
::
Decoration
precision
,
spv
::
Id
typeId
,
spv
::
Id
left
,
spv
::
Id
right
,
glslang
::
TBasicType
typeProxy
,
bool
reduceComparison
=
true
);
spv
::
Id
createBinaryMatrixOperation
(
spv
::
Op
,
spv
::
Decoration
precision
,
spv
::
Id
typeId
,
spv
::
Id
left
,
spv
::
Id
right
);
spv
::
Id
createBinaryMatrixOperation
(
spv
::
Op
,
spv
::
Decoration
precision
,
spv
::
Id
typeId
,
spv
::
Id
left
,
spv
::
Id
right
);
spv
::
Id
createUnaryOperation
(
glslang
::
TOperator
op
,
spv
::
Decoration
precision
,
spv
::
Id
typeId
,
spv
::
Id
operand
,
glslang
::
TBasicType
typeProxy
);
spv
::
Id
createUnaryOperation
(
glslang
::
TOperator
op
,
spv
::
Decoration
precision
,
spv
::
Id
typeId
,
spv
::
Id
operand
,
glslang
::
TBasicType
typeProxy
);
spv
::
Id
createUnaryMatrixOperation
(
spv
::
Op
,
spv
::
Decoration
precision
,
spv
::
Id
typeId
,
spv
::
Id
operand
,
glslang
::
TBasicType
typeProxy
);
spv
::
Id
createConversion
(
glslang
::
TOperator
op
,
spv
::
Decoration
precision
,
spv
::
Id
destTypeId
,
spv
::
Id
operand
);
spv
::
Id
createConversion
(
glslang
::
TOperator
op
,
spv
::
Decoration
precision
,
spv
::
Id
destTypeId
,
spv
::
Id
operand
);
spv
::
Id
makeSmearedConstant
(
spv
::
Id
constant
,
int
vectorSize
);
spv
::
Id
makeSmearedConstant
(
spv
::
Id
constant
,
int
vectorSize
);
spv
::
Id
createAtomicOperation
(
glslang
::
TOperator
op
,
spv
::
Decoration
precision
,
spv
::
Id
typeId
,
std
::
vector
<
spv
::
Id
>&
operands
,
glslang
::
TBasicType
typeProxy
);
spv
::
Id
createAtomicOperation
(
glslang
::
TOperator
op
,
spv
::
Decoration
precision
,
spv
::
Id
typeId
,
std
::
vector
<
spv
::
Id
>&
operands
,
glslang
::
TBasicType
typeProxy
);
...
@@ -2601,9 +2602,11 @@ spv::Id TGlslangToSpvTraverser::createUnaryOperation(glslang::TOperator op, spv:
...
@@ -2601,9 +2602,11 @@ spv::Id TGlslangToSpvTraverser::createUnaryOperation(glslang::TOperator op, spv:
switch
(
op
)
{
switch
(
op
)
{
case
glslang
:
:
EOpNegative
:
case
glslang
:
:
EOpNegative
:
if
(
isFloat
)
if
(
isFloat
)
{
unaryOp
=
spv
::
OpFNegate
;
unaryOp
=
spv
::
OpFNegate
;
else
if
(
builder
.
isMatrixType
(
typeId
))
return
createUnaryMatrixOperation
(
unaryOp
,
precision
,
typeId
,
operand
,
typeProxy
);
}
else
unaryOp
=
spv
::
OpSNegate
;
unaryOp
=
spv
::
OpSNegate
;
break
;
break
;
...
@@ -2862,6 +2865,39 @@ spv::Id TGlslangToSpvTraverser::createUnaryOperation(glslang::TOperator op, spv:
...
@@ -2862,6 +2865,39 @@ spv::Id TGlslangToSpvTraverser::createUnaryOperation(glslang::TOperator op, spv:
return
id
;
return
id
;
}
}
// Create a unary operation on a matrix
spv
::
Id
TGlslangToSpvTraverser
::
createUnaryMatrixOperation
(
spv
::
Op
op
,
spv
::
Decoration
precision
,
spv
::
Id
typeId
,
spv
::
Id
operand
,
glslang
::
TBasicType
/* typeProxy */
)
{
// Handle unary operations vector by vector.
// The result type is the same type as the original type.
// The algorithm is to:
// - break the matrix into vectors
// - apply the operation to each vector
// - make a matrix out the vector results
// get the types sorted out
int
numCols
=
builder
.
getNumColumns
(
operand
);
int
numRows
=
builder
.
getNumRows
(
operand
);
spv
::
Id
scalarType
=
builder
.
getScalarTypeId
(
typeId
);
spv
::
Id
vecType
=
builder
.
makeVectorType
(
scalarType
,
numRows
);
std
::
vector
<
spv
::
Id
>
results
;
// do each vector op
for
(
int
c
=
0
;
c
<
numCols
;
++
c
)
{
std
::
vector
<
unsigned
int
>
indexes
;
indexes
.
push_back
(
c
);
spv
::
Id
vec
=
builder
.
createCompositeExtract
(
operand
,
vecType
,
indexes
);
results
.
push_back
(
builder
.
createUnaryOp
(
op
,
vecType
,
vec
));
builder
.
setPrecision
(
results
.
back
(),
precision
);
}
// put the pieces together
spv
::
Id
id
=
builder
.
createCompositeConstruct
(
typeId
,
results
);
builder
.
setPrecision
(
id
,
precision
);
return
id
;
}
spv
::
Id
TGlslangToSpvTraverser
::
createConversion
(
glslang
::
TOperator
op
,
spv
::
Decoration
precision
,
spv
::
Id
destType
,
spv
::
Id
operand
)
spv
::
Id
TGlslangToSpvTraverser
::
createConversion
(
glslang
::
TOperator
op
,
spv
::
Decoration
precision
,
spv
::
Id
destType
,
spv
::
Id
operand
)
{
{
spv
::
Op
convOp
=
spv
::
OpNop
;
spv
::
Op
convOp
=
spv
::
OpNop
;
...
...
Test/baseResults/spv.branch-return.vert.out
View file @
7a53f76d
...
@@ -60,4 +60,4 @@ Linked vertex stage:
...
@@ -60,4 +60,4 @@ Linked vertex stage:
33: 29(ptr) AccessChain 19(gl_Position) 28
33: 29(ptr) AccessChain 19(gl_Position) 28
Store 33 32
Store 33 32
Return
Return
FunctionEnd
FunctionEnd
Test/baseResults/spv.matrix2.frag.out
View file @
7a53f76d
...
@@ -5,12 +5,12 @@ Linked fragment stage:
...
@@ -5,12 +5,12 @@ Linked fragment stage:
// Module Version 10000
// Module Version 10000
// Generated by (magic number): 80001
// Generated by (magic number): 80001
// Id's are bound by 2
13
// Id's are bound by 2
21
Capability Shader
Capability Shader
1: ExtInstImport "GLSL.std.450"
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 12 16 37 38 65 87 1
39 150 173 210 211 212
EntryPoint Fragment 4 "main" 12 16 37 38 65 87 1
47 158 181 218 219 220
ExecutionMode 4 OriginLowerLeft
ExecutionMode 4 OriginLowerLeft
Source GLSL 150
Source GLSL 150
Name 4 "main"
Name 4 "main"
...
@@ -22,15 +22,15 @@ Linked fragment stage:
...
@@ -22,15 +22,15 @@ Linked fragment stage:
Name 63 "m44"
Name 63 "m44"
Name 65 "un34"
Name 65 "un34"
Name 87 "um43"
Name 87 "um43"
Name 1
39
"um4"
Name 1
47
"um4"
Name 1
48
"inv"
Name 1
56
"inv"
Name 15
0
"um2"
Name 15
8
"um2"
Name 17
1
"inv3"
Name 17
9
"inv3"
Name 1
73
"um3"
Name 1
81
"um3"
Name 1
82
"inv4"
Name 1
90
"inv4"
Name 21
0
"colorTransform"
Name 21
8
"colorTransform"
Name 21
1
"m"
Name 21
9
"m"
Name 2
12
"n"
Name 2
20
"n"
2: TypeVoid
2: TypeVoid
3: TypeFunction 2
3: TypeFunction 2
6: TypeFloat 32
6: TypeFloat 32
...
@@ -62,35 +62,35 @@ Linked fragment stage:
...
@@ -62,35 +62,35 @@ Linked fragment stage:
85: TypeMatrix 14(fvec3) 4
85: TypeMatrix 14(fvec3) 4
86: TypePointer Input 85
86: TypePointer Input 85
87(um43): 86(ptr) Variable Input
87(um43): 86(ptr) Variable Input
1
38
: TypePointer Input 61
1
46
: TypePointer Input 61
1
39(um4): 138
(ptr) Variable Input
1
47(um4): 146
(ptr) Variable Input
1
45
: TypeVector 6(float) 2
1
53
: TypeVector 6(float) 2
1
46: TypeMatrix 145
(fvec2) 2
1
54: TypeMatrix 153
(fvec2) 2
1
47: TypePointer Function 146
1
55: TypePointer Function 154
1
49: TypePointer Input 146
1
57: TypePointer Input 154
15
0(um2): 149
(ptr) Variable Input
15
8(um2): 157
(ptr) Variable Input
1
53
: TypeInt 32 1
1
61
: TypeInt 32 1
1
54: 153
(int) Constant 0
1
62: 161
(int) Constant 0
1
55
: TypePointer Function 6(float)
1
63
: TypePointer Function 6(float)
1
58: 153
(int) Constant 1
1
66: 161
(int) Constant 1
16
1
: 54(int) Constant 1
16
9
: 54(int) Constant 1
1
69
: TypeMatrix 14(fvec3) 3
1
77
: TypeMatrix 14(fvec3) 3
17
0: TypePointer Function 169
17
8: TypePointer Function 177
1
72: TypePointer Input 169
1
80: TypePointer Input 177
1
73(um3): 172
(ptr) Variable Input
1
81(um3): 180
(ptr) Variable Input
1
76: 153
(int) Constant 2
1
84: 161
(int) Constant 2
2
02
: 54(int) Constant 3
2
10
: 54(int) Constant 3
2
03
: TypePointer Output 6(float)
2
11
: TypePointer Output 6(float)
21
0(colorTransform): 172
(ptr) Variable Input
21
8(colorTransform): 180
(ptr) Variable Input
21
1(m): 138
(ptr) Variable Input
21
9(m): 146
(ptr) Variable Input
2
12(n): 138
(ptr) Variable Input
2
20(n): 146
(ptr) Variable Input
4(main): 2 Function None 3
4(main): 2 Function None 3
5: Label
5: Label
10(m34): 9(ptr) Variable Function
10(m34): 9(ptr) Variable Function
63(m44): 62(ptr) Variable Function
63(m44): 62(ptr) Variable Function
1
48(inv): 147
(ptr) Variable Function
1
56(inv): 155
(ptr) Variable Function
17
1(inv3): 170
(ptr) Variable Function
17
9(inv3): 178
(ptr) Variable Function
1
82
(inv4): 62(ptr) Variable Function
1
90
(inv4): 62(ptr) Variable Function
13: 7(fvec4) Load 12(v)
13: 7(fvec4) Load 12(v)
17: 14(fvec3) Load 16(u)
17: 14(fvec3) Load 16(u)
18: 8 OuterProduct 13 17
18: 8 OuterProduct 13 17
...
@@ -166,100 +166,108 @@ Linked fragment stage:
...
@@ -166,100 +166,108 @@ Linked fragment stage:
103: 61 CompositeConstruct 93 96 99 102
103: 61 CompositeConstruct 93 96 99 102
Store 63(m44) 103
Store 63(m44) 103
104: 61 Load 63(m44)
104: 61 Load 63(m44)
105: 61 FNegate 104
105: 7(fvec4) CompositeExtract 104 0
106: 7(fvec4) Load 12(v)
106: 7(fvec4) FNegate 105
107: 7(fvec4) MatrixTimesVector 105 106
107: 7(fvec4) CompositeExtract 104 1
108: 7(fvec4) Load 37(FragColor)
108: 7(fvec4) FNegate 107
109: 7(fvec4) FAdd 108 107
109: 7(fvec4) CompositeExtract 104 2
Store 37(FragColor) 109
110: 7(fvec4) FNegate 109
110: 61 Load 63(m44)
111: 7(fvec4) CompositeExtract 104 3
111: 61 Load 63(m44)
112: 7(fvec4) FNegate 111
112: 7(fvec4) CompositeExtract 110 0
113: 61 CompositeConstruct 106 108 110 112
113: 7(fvec4) CompositeExtract 111 0
114: 7(fvec4) Load 12(v)
114: 7(fvec4) FMul 112 113
115: 7(fvec4) MatrixTimesVector 113 114
115: 7(fvec4) CompositeExtract 110 1
116: 7(fvec4) Load 37(FragColor)
116: 7(fvec4) CompositeExtract 111 1
117: 7(fvec4) FAdd 116 115
117: 7(fvec4) FMul 115 116
Store 37(FragColor) 117
118: 7(fvec4) CompositeExtract 110 2
118: 61 Load 63(m44)
119: 7(fvec4) CompositeExtract 111 2
119: 61 Load 63(m44)
120: 7(fvec4) FMul 118 119
120: 7(fvec4) CompositeExtract 118 0
121: 7(fvec4) CompositeExtract 110 3
121: 7(fvec4) CompositeExtract 119 0
122: 7(fvec4) CompositeExtract 111 3
122: 7(fvec4) FMul 120 121
123: 7(fvec4) FMul 121 122
123: 7(fvec4) CompositeExtract 118 1
124: 61 CompositeConstruct 114 117 120 123
124: 7(fvec4) CompositeExtract 119 1
125: 7(fvec4) Load 37(FragColor)
125: 7(fvec4) FMul 123 124
126: 7(fvec4) VectorTimesMatrix 125 124
126: 7(fvec4) CompositeExtract 118 2
Store 37(FragColor) 126
127: 7(fvec4) CompositeExtract 119 2
127: 85 Load 87(um43)
128: 7(fvec4) FMul 126 127
128: 8 Transpose 127
129: 7(fvec4) CompositeExtract 118 3
Store 10(m34) 128
130: 7(fvec4) CompositeExtract 119 3
129: 7(fvec4) Load 37(FragColor)
131: 7(fvec4) FMul 129 130
130: 8 Load 10(m34)
132: 61 CompositeConstruct 122 125 128 131
131: 14(fvec3) VectorTimesMatrix 129 130
133: 7(fvec4) Load 37(FragColor)
132: 6(float) CompositeExtract 131 0
134: 7(fvec4) VectorTimesMatrix 133 132
133: 6(float) CompositeExtract 131 1
Store 37(FragColor) 134
134: 6(float) CompositeExtract 131 2
135: 85 Load 87(um43)
135: 7(fvec4) CompositeConstruct 132 133 134 40
136: 8 Transpose 135
136: 7(fvec4) Load 37(FragColor)
Store 10(m34) 136
137: 7(fvec4) FMul 136 135
137: 7(fvec4) Load 37(FragColor)
Store 37(FragColor) 137
138: 8 Load 10(m34)
140: 61 Load 139(um4)
139: 14(fvec3) VectorTimesMatrix 137 138
141: 6(float) ExtInst 1(GLSL.std.450) 33(Determinant) 140
140: 6(float) CompositeExtract 139 0
142: 7(fvec4) CompositeConstruct 141 141 141 141
141: 6(float) CompositeExtract 139 1
143: 7(fvec4) Load 37(FragColor)
142: 6(float) CompositeExtract 139 2
144: 7(fvec4) FMul 143 142
143: 7(fvec4) CompositeConstruct 140 141 142 40
Store 37(FragColor) 144
144: 7(fvec4) Load 37(FragColor)
151: 146 Load 150(um2)
145: 7(fvec4) FMul 144 143
152: 146 ExtInst 1(GLSL.std.450) 34(MatrixInverse) 151
Store 37(FragColor) 145
Store 148(inv) 152
148: 61 Load 147(um4)
156: 155(ptr) AccessChain 148(inv) 154 55
149: 6(float) ExtInst 1(GLSL.std.450) 33(Determinant) 148
157: 6(float) Load 156
150: 7(fvec4) CompositeConstruct 149 149 149 149
159: 155(ptr) AccessChain 148(inv) 158 55
151: 7(fvec4) Load 37(FragColor)
160: 6(float) Load 159
152: 7(fvec4) FMul 151 150
162: 155(ptr) AccessChain 148(inv) 154 161
Store 37(FragColor) 152
163: 6(float) Load 162
159: 154 Load 158(um2)
164: 155(ptr) AccessChain 148(inv) 158 161
160: 154 ExtInst 1(GLSL.std.450) 34(MatrixInverse) 159
Store 156(inv) 160
164: 163(ptr) AccessChain 156(inv) 162 55
165: 6(float) Load 164
165: 6(float) Load 164
166: 7(fvec4) CompositeConstruct 157 160 163 165
167: 163(ptr) AccessChain 156(inv) 166 55
167: 7(fvec4) Load 37(FragColor)
168: 6(float) Load 167
168: 7(fvec4) FMul 167 166
170: 163(ptr) AccessChain 156(inv) 162 169
Store 37(FragColor) 168
171: 6(float) Load 170
174: 169 Load 173(um3)
172: 163(ptr) AccessChain 156(inv) 166 169
175: 169 ExtInst 1(GLSL.std.450) 34(MatrixInverse) 174
173: 6(float) Load 172
Store 171(inv3) 175
174: 7(fvec4) CompositeConstruct 165 168 171 173
177: 155(ptr) AccessChain 171(inv3) 176 161
175: 7(fvec4) Load 37(FragColor)
178: 6(float) Load 177
176: 7(fvec4) FMul 175 174
179: 7(fvec4) CompositeConstruct 178 178 178 178
Store 37(FragColor) 176
180: 7(fvec4) Load 37(FragColor)
182: 177 Load 181(um3)
181: 7(fvec4) FMul 180 179
183: 177 ExtInst 1(GLSL.std.450) 34(MatrixInverse) 182
Store 37(FragColor) 181
Store 179(inv3) 183
183: 61 Load 139(um4)
185: 163(ptr) AccessChain 179(inv3) 184 169
184: 61 ExtInst 1(GLSL.std.450) 34(MatrixInverse) 183
186: 6(float) Load 185
Store 182(inv4) 184
187: 7(fvec4) CompositeConstruct 186 186 186 186
185: 61 Load 182(inv4)
186: 7(fvec4) Load 37(FragColor)
187: 7(fvec4) VectorTimesMatrix 186 185
Store 37(FragColor) 187
188: 7(fvec4) Load 37(FragColor)
188: 7(fvec4) Load 37(FragColor)
189: 8 Load 65(un34)
189: 7(fvec4) FMul 188 187
190: 8 Load 65(un34)
Store 37(FragColor) 189
191: 7(fvec4) CompositeExtract 189 0
191: 61 Load 147(um4)
192: 7(fvec4) CompositeExtract 190 0
192: 61 ExtInst 1(GLSL.std.450) 34(MatrixInverse) 191
193: 7(fvec4) FMul 191 192
Store 190(inv4) 192
194: 7(fvec4) CompositeExtract 189 1
193: 61 Load 190(inv4)
195: 7(fvec4) CompositeExtract 190 1
194: 7(fvec4) Load 37(FragColor)
196: 7(fvec4) FMul 194 195
195: 7(fvec4) VectorTimesMatrix 194 193
197: 7(fvec4) CompositeExtract 189 2
Store 37(FragColor) 195
198: 7(fvec4) CompositeExtract 190 2
196: 7(fvec4) Load 37(FragColor)
199: 7(fvec4) FMul 197 198
197: 8 Load 65(un34)
200: 8 CompositeConstruct 193 196 199
198: 8 Load 65(un34)
201: 14(fvec3) VectorTimesMatrix 188 200
199: 7(fvec4) CompositeExtract 197 0
204: 203(ptr) AccessChain 37(FragColor) 202
200: 7(fvec4) CompositeExtract 198 0
205: 6(float) Load 204
201: 7(fvec4) FMul 199 200
206: 6(float) CompositeExtract 201 0
202: 7(fvec4) CompositeExtract 197 1
207: 6(float) CompositeExtract 201 1
203: 7(fvec4) CompositeExtract 198 1
208: 6(float) CompositeExtract 201 2
204: 7(fvec4) FMul 202 203
209: 7(fvec4) CompositeConstruct 206 207 208 205
205: 7(fvec4) CompositeExtract 197 2
Store 37(FragColor) 209
206: 7(fvec4) CompositeExtract 198 2
207: 7(fvec4) FMul 205 206
208: 8 CompositeConstruct 201 204 207
209: 14(fvec3) VectorTimesMatrix 196 208
212: 211(ptr) AccessChain 37(FragColor) 210
213: 6(float) Load 212
214: 6(float) CompositeExtract 209 0
215: 6(float) CompositeExtract 209 1
216: 6(float) CompositeExtract 209 2
217: 7(fvec4) CompositeConstruct 214 215 216 213
Store 37(FragColor) 217
Return
Return
FunctionEnd
FunctionEnd
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