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
aa0298bf
Commit
aa0298bf
authored
Apr 04, 2016
by
John Kessenich
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #220 from Qining/fix-built-in-spec-constants
Handle built-in constants redeclared with a specialization constant id.
parents
1c7e7076
4f4bb81c
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
128 additions
and
98 deletions
+128
-98
GlslangToSpv.cpp
SPIRV/GlslangToSpv.cpp
+16
-11
spv.specConstant.vert.out
Test/baseResults/spv.specConstant.vert.out
+100
-87
spv.specConstant.vert
Test/spv.specConstant.vert
+8
-0
ParseHelper.cpp
glslang/MachineIndependent/ParseHelper.cpp
+4
-0
No files found.
SPIRV/GlslangToSpv.cpp
View file @
aa0298bf
...
@@ -3744,6 +3744,7 @@ spv::Id TGlslangToSpvTraverser::createSpvConstant(const glslang::TIntermTyped& n
...
@@ -3744,6 +3744,7 @@ spv::Id TGlslangToSpvTraverser::createSpvConstant(const glslang::TIntermTyped& n
{
{
assert
(
node
.
getQualifier
().
isConstant
());
assert
(
node
.
getQualifier
().
isConstant
());
// Handle front-end constants first (non-specialization constants).
if
(
!
node
.
getQualifier
().
specConstant
)
{
if
(
!
node
.
getQualifier
().
specConstant
)
{
// hand off to the non-spec-constant path
// hand off to the non-spec-constant path
assert
(
node
.
getAsConstantUnion
()
!=
nullptr
||
node
.
getAsSymbolNode
()
!=
nullptr
);
assert
(
node
.
getAsConstantUnion
()
!=
nullptr
||
node
.
getAsSymbolNode
()
!=
nullptr
);
...
@@ -3754,12 +3755,6 @@ spv::Id TGlslangToSpvTraverser::createSpvConstant(const glslang::TIntermTyped& n
...
@@ -3754,12 +3755,6 @@ spv::Id TGlslangToSpvTraverser::createSpvConstant(const glslang::TIntermTyped& n
// We now know we have a specialization constant to build
// We now know we have a specialization constant to build
if
(
node
.
getAsSymbolNode
()
&&
node
.
getQualifier
().
hasSpecConstantId
())
{
// this is a direct literal assigned to a layout(constant_id=) declaration
int
nextConst
=
0
;
return
createSpvConstantFromConstUnionArray
(
node
.
getType
(),
node
.
getAsConstantUnion
()
?
node
.
getAsConstantUnion
()
->
getConstArray
()
:
node
.
getAsSymbolNode
()
->
getConstArray
(),
nextConst
,
true
);
}
else
{
// gl_WorkgroupSize is a special case until the front-end handles hierarchical specialization constants,
// gl_WorkgroupSize is a special case until the front-end handles hierarchical specialization constants,
// even then, it's specialization ids are handled by special case syntax in GLSL: layout(local_size_x = ...
// even then, it's specialization ids are handled by special case syntax in GLSL: layout(local_size_x = ...
if
(
node
.
getType
().
getQualifier
().
builtIn
==
glslang
::
EbvWorkGroupSize
)
{
if
(
node
.
getType
().
getQualifier
().
builtIn
==
glslang
::
EbvWorkGroupSize
)
{
...
@@ -3771,14 +3766,24 @@ spv::Id TGlslangToSpvTraverser::createSpvConstant(const glslang::TIntermTyped& n
...
@@ -3771,14 +3766,24 @@ spv::Id TGlslangToSpvTraverser::createSpvConstant(const glslang::TIntermTyped& n
addDecoration
(
dimConstId
.
back
(),
spv
::
DecorationSpecId
,
glslangIntermediate
->
getLocalSizeSpecId
(
dim
));
addDecoration
(
dimConstId
.
back
(),
spv
::
DecorationSpecId
,
glslangIntermediate
->
getLocalSizeSpecId
(
dim
));
}
}
return
builder
.
makeCompositeConstant
(
builder
.
makeVectorType
(
builder
.
makeUintType
(
32
),
3
),
dimConstId
,
true
);
return
builder
.
makeCompositeConstant
(
builder
.
makeVectorType
(
builder
.
makeUintType
(
32
),
3
),
dimConstId
,
true
);
}
else
if
(
auto
*
sn
=
node
.
getAsSymbolNode
()){
}
return
createSpvConstantFromConstSubTree
(
sn
->
getConstSubtree
());
}
else
{
// An AST node labelled as specialization constant should be a symbol node.
// Its initializer should either be a sub tree with constant nodes, or a constant union array.
if
(
auto
*
sn
=
node
.
getAsSymbolNode
())
{
if
(
auto
*
sub_tree
=
sn
->
getConstSubtree
())
{
return
createSpvConstantFromConstSubTree
(
sub_tree
);
}
else
if
(
auto
*
const_union_array
=
&
sn
->
getConstArray
()){
int
nextConst
=
0
;
return
createSpvConstantFromConstUnionArray
(
sn
->
getType
(),
*
const_union_array
,
nextConst
,
true
);
}
}
// Neither a front-end constant node, nor a specialization constant node with constant union array or
// constant sub tree as initializer.
spv
::
MissingFunctionality
(
"Neither a front-end constant nor a spec constant."
);
spv
::
MissingFunctionality
(
"Neither a front-end constant nor a spec constant."
);
exit
(
1
);
exit
(
1
);
return
spv
::
NoResult
;
return
spv
::
NoResult
;
}
}
}
}
// Use 'consts' as the flattened glslang source of scalar constants to recursively
// Use 'consts' as the flattened glslang source of scalar constants to recursively
...
...
Test/baseResults/spv.specConstant.vert.out
View file @
aa0298bf
...
@@ -7,32 +7,35 @@ Linked vertex stage:
...
@@ -7,32 +7,35 @@ Linked vertex stage:
// Module Version 10000
// Module Version 10000
// Generated by (magic number): 80001
// Generated by (magic number): 80001
// Id's are bound by
72
// Id's are bound by
81
Capability Shader
Capability Shader
Capability Float64
Capability Float64
1: ExtInstImport "GLSL.std.450"
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
MemoryModel Logical GLSL450
EntryPoint Vertex 4 "main"
17 19 25 50
EntryPoint Vertex 4 "main"
20 22 28 53
Source GLSL 400
Source GLSL 400
Name 4 "main"
Name 4 "main"
Name 14 "foo(vf4[s1498];"
Name 14 "foo(vf4[s1498];"
Name 13 "p"
Name 13 "p"
Name 17 "color"
Name 17 "builtin_spec_constant("
Name 19 "ucol"
Name 20 "color"
Name 25 "size"
Name 22 "ucol"
Name 44 "param"
Name 28 "size"
Name 50 "dupUcol"
Name 47 "param"
Name 53 "dupUcol"
Name 76 "result"
Decorate 9 SpecId 16
Decorate 9 SpecId 16
Decorate 27 SpecId 17
Decorate 30 SpecId 17
Decorate 31 SpecId 22
Decorate 34 SpecId 22
Decorate 36 SpecId 19
Decorate 39 SpecId 19
Decorate 37 SpecId 18
Decorate 40 SpecId 18
Decorate 47 SpecId 116
Decorate 50 SpecId 116
Decorate 57 SpecId 117
Decorate 60 SpecId 117
Decorate 60 SpecId 122
Decorate 63 SpecId 122
Decorate 64 SpecId 119
Decorate 67 SpecId 119
Decorate 65 SpecId 118
Decorate 68 SpecId 118
Decorate 77 SpecId 24
2: TypeVoid
2: TypeVoid
3: TypeFunction 2
3: TypeFunction 2
6: TypeFloat 32
6: TypeFloat 32
...
@@ -42,83 +45,93 @@ Linked vertex stage:
...
@@ -42,83 +45,93 @@ Linked vertex stage:
10: TypeArray 7(fvec4) 9
10: TypeArray 7(fvec4) 9
11: TypePointer Function 10
11: TypePointer Function 10
12: TypeFunction 2 11(ptr)
12: TypeFunction 2 11(ptr)
16: TypePointer Output 7(fvec4)
16: TypeFunction 8(int)
17(color): 16(ptr) Variable Output
19: TypePointer Output 7(fvec4)
18: TypePointer Input 10
20(color): 19(ptr) Variable Output
19(ucol): 18(ptr) Variable Input
21: TypePointer Input 10
20: 8(int) Constant 2
22(ucol): 21(ptr) Variable Input
21: TypePointer Input 7(fvec4)
23: 8(int) Constant 2
24: TypePointer Output 8(int)
24: TypePointer Input 7(fvec4)
25(size): 24(ptr) Variable Output
27: TypePointer Output 8(int)
26: TypeBool
28(size): 27(ptr) Variable Output
27: 26(bool) SpecConstantTrue
29: TypeBool
30: TypeInt 32 0
30: 29(bool) SpecConstantTrue
31: 30(int) SpecConstant 2
33: TypeInt 32 0
35: TypeFloat 64
34: 33(int) SpecConstant 2
36: 35(float) SpecConstant 1413754136 1074340347
38: TypeFloat 64
37: 6(float) SpecConstant 1078523331
39: 38(float) SpecConstant 1413754136 1074340347
47: 8(int) SpecConstant 12
40: 6(float) SpecConstant 1078523331
48: TypeArray 7(fvec4) 47
50: 8(int) SpecConstant 12
49: TypePointer Input 48
51: TypeArray 7(fvec4) 50
50(dupUcol): 49(ptr) Variable Input
52: TypePointer Input 51
57: 26(bool) SpecConstantTrue
53(dupUcol): 52(ptr) Variable Input
60: 30(int) SpecConstant 2
60: 29(bool) SpecConstantTrue
64: 35(float) SpecConstant 1413754136 1074340347
63: 33(int) SpecConstant 2
65: 6(float) SpecConstant 1078523331
67: 38(float) SpecConstant 1413754136 1074340347
68: 6(float) SpecConstant 1078523331
75: TypePointer Function 8(int)
77: 8(int) SpecConstant 8
4(main): 2 Function None 3
4(main): 2 Function None 3
5: Label
5: Label
4
4
(param): 11(ptr) Variable Function
4
7
(param): 11(ptr) Variable Function
2
2: 21(ptr) AccessChain 19(ucol) 20
2
5: 24(ptr) AccessChain 22(ucol) 23
2
3: 7(fvec4) Load 22
2
6: 7(fvec4) Load 25
Store
17(color) 23
Store
20(color) 26
Store 2
5
(size) 9
Store 2
8
(size) 9
SelectionMerge
29
None
SelectionMerge
32
None
BranchConditional
27 28 29
BranchConditional
30 31 32
28
: Label
31
: Label
3
2: 6(float) ConvertUToF 31
3
5: 6(float) ConvertUToF 34
3
3: 7(fvec4) Load 17
(color)
3
6: 7(fvec4) Load 20
(color)
3
4: 7(fvec4) VectorTimesScalar 33 32
3
7: 7(fvec4) VectorTimesScalar 36 35
Store
17(color) 34
Store
20(color) 37
Branch
29
Branch
32
29
: Label
32
: Label
38: 35(float) FConvert 37
41: 38(float) FConvert 40
39: 35(float) FDiv 36 38
42: 38(float) FDiv 39 41
4
0: 6(float) FConvert 39
4
3: 6(float) FConvert 42
4
1: 7(fvec4) Load 17
(color)
4
4: 7(fvec4) Load 20
(color)
4
2: 7(fvec4) CompositeConstruct 40 40 40 40
4
5: 7(fvec4) CompositeConstruct 43 43 43 43
4
3: 7(fvec4) FAdd 41 42
4
6: 7(fvec4) FAdd 44 45
Store
17(color) 43
Store
20(color) 46
4
5: 10 Load 19
(ucol)
4
8: 10 Load 22
(ucol)
Store 4
4(param) 45
Store 4
7(param) 48
4
6: 2 FunctionCall 14(foo(vf4[s1498];) 44
(param)
4
9: 2 FunctionCall 14(foo(vf4[s1498];) 47
(param)
Return
Return
FunctionEnd
FunctionEnd
14(foo(vf4[s1498];): 2 Function None 12
14(foo(vf4[s1498];): 2 Function None 12
13(p): 11(ptr) FunctionParameter
13(p): 11(ptr) FunctionParameter
15: Label
15: Label
5
1: 21(ptr) AccessChain 50(dupUcol) 20
5
4: 24(ptr) AccessChain 53(dupUcol) 23
5
2: 7(fvec4) Load 51
5
5: 7(fvec4) Load 54
5
3: 7(fvec4) Load 17
(color)
5
6: 7(fvec4) Load 20
(color)
5
4: 7(fvec4) FAdd 53 52
5
7: 7(fvec4) FAdd 56 55
Store
17(color) 54
Store
20(color) 57
5
5: 8(int) Load 25
(size)
5
8: 8(int) Load 28
(size)
5
6: 8(int) IAdd 55 47
5
9: 8(int) IAdd 58 50
Store 2
5(size) 56
Store 2
8(size) 59
SelectionMerge
59
None
SelectionMerge
62
None
BranchConditional
57 58 59
BranchConditional
60 61 62
58
: Label
61
: Label
6
1: 6(float) ConvertUToF 60
6
4: 6(float) ConvertUToF 63
6
2: 7(fvec4) Load 17
(color)
6
5: 7(fvec4) Load 20
(color)
6
3: 7(fvec4) VectorTimesScalar 62 61
6
6: 7(fvec4) VectorTimesScalar 65 64
Store
17(color) 63
Store
20(color) 66
Branch
59
Branch
62
59
: Label
62
: Label
6
6: 35(float) FConvert 65
6
9: 38(float) FConvert 68
67: 35(float) FDiv 64 66
70: 38(float) FDiv 67 69
68: 6(float) FConvert 67
71: 6(float) FConvert 70
69: 7(fvec4) Load 17
(color)
72: 7(fvec4) Load 20
(color)
7
0: 7(fvec4) CompositeConstruct 68 68 68 68
7
3: 7(fvec4) CompositeConstruct 71 71 71 71
7
1: 7(fvec4) FAdd 69 70
7
4: 7(fvec4) FAdd 72 73
Store
17(color) 71
Store
20(color) 74
Return
Return
FunctionEnd
FunctionEnd
17(builtin_spec_constant(): 8(int) Function None 16
18: Label
76(result): 75(ptr) Variable Function
Store 76(result) 77
78: 8(int) Load 76(result)
ReturnValue 78
FunctionEnd
Test/spv.specConstant.vert
View file @
aa0298bf
...
@@ -8,6 +8,8 @@ layout(constant_id = 18) const float spFloat = 3.14;
...
@@ -8,6 +8,8 @@ layout(constant_id = 18) const float spFloat = 3.14;
layout
(
constant_id
=
19
)
const
double
spDouble
=
3
.
1415926535897932384626433832795
;
layout
(
constant_id
=
19
)
const
double
spDouble
=
3
.
1415926535897932384626433832795
;
layout
(
constant_id
=
22
)
const
uint
scale
=
2
;
layout
(
constant_id
=
22
)
const
uint
scale
=
2
;
layout
(
constant_id
=
24
)
gl_MaxImageUnits
;
out
vec4
color
;
out
vec4
color
;
out
int
size
;
out
int
size
;
...
@@ -41,3 +43,9 @@ void foo(vec4 p[arraySize])
...
@@ -41,3 +43,9 @@ void foo(vec4 p[arraySize])
color
*=
dupScale
;
color
*=
dupScale
;
color
+=
float
(
spDupDouble
/
spDupFloat
);
color
+=
float
(
spDupDouble
/
spDupFloat
);
}
}
int
builtin_spec_constant
()
{
int
result
=
gl_MaxImageUnits
;
return
result
;
}
glslang/MachineIndependent/ParseHelper.cpp
View file @
aa0298bf
...
@@ -5714,6 +5714,10 @@ void TParseContext::addQualifierToExisting(const TSourceLoc& loc, TQualifier qua
...
@@ -5714,6 +5714,10 @@ void TParseContext::addQualifierToExisting(const TSourceLoc& loc, TQualifier qua
error
(
loc
,
"cannot change qualification after use"
,
"invariant"
,
""
);
error
(
loc
,
"cannot change qualification after use"
,
"invariant"
,
""
);
symbol
->
getWritableType
().
getQualifier
().
invariant
=
true
;
symbol
->
getWritableType
().
getQualifier
().
invariant
=
true
;
invariantCheck
(
loc
,
symbol
->
getType
().
getQualifier
());
invariantCheck
(
loc
,
symbol
->
getType
().
getQualifier
());
}
else
if
(
qualifier
.
specConstant
)
{
symbol
->
getWritableType
().
getQualifier
().
makeSpecConstant
();
if
(
qualifier
.
hasSpecConstantId
())
symbol
->
getWritableType
().
getQualifier
().
layoutSpecConstantId
=
qualifier
.
layoutSpecConstantId
;
}
else
}
else
warn
(
loc
,
"unknown requalification"
,
""
,
""
);
warn
(
loc
,
"unknown requalification"
,
""
,
""
);
}
}
...
...
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