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
9c6734c8
Commit
9c6734c8
authored
Jan 10, 2016
by
Dejan Mircevski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First cut at new loop codegen.
Change-Id: Id3bdf8b7a5606e7ce5d856ef225d5ddbe59a584b
parent
c92e370e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
93 additions
and
52 deletions
+93
-52
GlslangToSpv.cpp
SPIRV/GlslangToSpv.cpp
+40
-22
SpvBuilder.cpp
SPIRV/SpvBuilder.cpp
+13
-0
SpvBuilder.h
SPIRV/SpvBuilder.h
+12
-4
spv.for-simple.vert.out
Test/baseResults/spv.for-simple.vert.out
+28
-26
No files found.
SPIRV/GlslangToSpv.cpp
View file @
9c6734c8
...
@@ -1342,33 +1342,51 @@ void TGlslangToSpvTraverser::visitConstantUnion(glslang::TIntermConstantUnion* n
...
@@ -1342,33 +1342,51 @@ void TGlslangToSpvTraverser::visitConstantUnion(glslang::TIntermConstantUnion* n
bool
TGlslangToSpvTraverser
::
visitLoop
(
glslang
::
TVisit
/* visit */
,
glslang
::
TIntermLoop
*
node
)
bool
TGlslangToSpvTraverser
::
visitLoop
(
glslang
::
TVisit
/* visit */
,
glslang
::
TIntermLoop
*
node
)
{
{
// body emission needs to know what the for-loop terminal is when it sees a "continue"
auto
blocks
=
builder
.
makeNewLoop
();
loopTerminal
.
push
(
node
->
getTerminal
());
if
(
node
->
testFirst
()
&&
node
->
getTest
())
{
spv
::
Block
&
head
=
builder
.
makeNewBlock
();
builder
.
createBranch
(
&
head
);
builder
.
makeNewLoop
(
node
->
testFirst
());
builder
.
setBuildPoint
(
&
head
);
if
(
node
->
getTest
())
{
node
->
getTest
()
->
traverse
(
this
);
node
->
getTest
()
->
traverse
(
this
);
// the AST only contained the test computation, not the branch, we have to add it
spv
::
Id
condition
=
spv
::
Id
condition
=
builder
.
accessChainLoad
(
convertGlslangToSpvType
(
node
->
getTest
()
->
getType
()));
builder
.
accessChainLoad
(
convertGlslangToSpvType
(
node
->
getTest
()
->
getType
()));
builder
.
createLoopTestBranch
(
condition
);
builder
.
createLoopMerge
(
&
blocks
.
merge
,
&
blocks
.
continue_target
,
spv
::
LoopControlMaskNone
);
builder
.
createConditionalBranch
(
condition
,
&
blocks
.
body
,
&
blocks
.
merge
);
builder
.
setBuildPoint
(
&
blocks
.
body
);
if
(
node
->
getBody
())
node
->
getBody
()
->
traverse
(
this
);
// continue->cont, break->exit
builder
.
createBranch
(
&
blocks
.
continue_target
);
builder
.
setBuildPoint
(
&
blocks
.
continue_target
);
if
(
node
->
getTerminal
())
node
->
getTerminal
()
->
traverse
(
this
);
builder
.
createBranch
(
&
head
);
}
else
{
}
else
{
builder
.
createBranchToBody
();
builder
.
createBranch
(
&
blocks
.
body
);
}
builder
.
setBuildPoint
(
&
blocks
.
body
);
if
(
node
->
getBody
())
{
if
(
node
->
getBody
())
breakForLoop
.
push
(
true
);
node
->
getBody
()
->
traverse
(
this
);
// continue->cont, break->exit
node
->
getBody
()
->
traverse
(
this
);
builder
.
createBranch
(
&
blocks
.
continue_target
);
breakForLoop
.
pop
();
builder
.
setBuildPoint
(
&
blocks
.
continue_target
);
if
(
node
->
getTerminal
())
node
->
getTerminal
()
->
traverse
(
this
);
if
(
node
->
getTest
())
{
node
->
getTest
()
->
traverse
(
this
);
spv
::
Id
condition
=
builder
.
accessChainLoad
(
convertGlslangToSpvType
(
node
->
getTest
()
->
getType
()));
builder
.
createLoopMerge
(
&
blocks
.
merge
,
&
blocks
.
continue_target
,
spv
::
LoopControlMaskNone
);
builder
.
createConditionalBranch
(
condition
,
&
blocks
.
body
,
&
blocks
.
merge
);
}
else
{
builder
.
createBranch
(
&
blocks
.
body
);
}
}
}
if
(
loopTerminal
.
top
())
builder
.
setBuildPoint
(
&
blocks
.
merge
);
loopTerminal
.
top
()
->
traverse
(
this
);
builder
.
closeLoop
();
loopTerminal
.
pop
();
return
false
;
return
false
;
}
}
...
...
SPIRV/SpvBuilder.cpp
View file @
9c6734c8
...
@@ -1753,6 +1753,19 @@ void Builder::endSwitch(std::vector<Block*>& /*segmentBlock*/)
...
@@ -1753,6 +1753,19 @@ void Builder::endSwitch(std::vector<Block*>& /*segmentBlock*/)
switchMerges
.
pop
();
switchMerges
.
pop
();
}
}
Block
&
Builder
::
makeNewBlock
()
{
Function
&
function
=
buildPoint
->
getParent
();
auto
block
=
new
Block
(
getUniqueId
(),
function
);
function
.
addBlock
(
block
);
return
*
block
;
}
Builder
::
LoopBlocks
Builder
::
makeNewLoop
()
{
return
{
makeNewBlock
(),
makeNewBlock
(),
makeNewBlock
()};
}
// Comments in header
// Comments in header
void
Builder
::
makeNewLoop
(
bool
loopTestFirst
)
void
Builder
::
makeNewLoop
(
bool
loopTestFirst
)
{
{
...
...
SPIRV/SpvBuilder.h
View file @
9c6734c8
...
@@ -378,6 +378,13 @@ public:
...
@@ -378,6 +378,13 @@ public:
// The loopTestFirst parameter is true when the loop test executes before
// The loopTestFirst parameter is true when the loop test executes before
// the body. (It is false for do-while loops.)
// the body. (It is false for do-while loops.)
void
makeNewLoop
(
bool
loopTestFirst
);
void
makeNewLoop
(
bool
loopTestFirst
);
struct
LoopBlocks
{
Block
&
body
,
&
merge
,
&
continue_target
;
};
LoopBlocks
makeNewLoop
();
// Create a new block in the function containing the build point.
Block
&
makeNewBlock
();
// Add the branch for the loop test, based on the given condition.
// Add the branch for the loop test, based on the given condition.
// The true branch goes to the first block in the loop body, and
// The true branch goes to the first block in the loop body, and
...
@@ -494,7 +501,11 @@ public:
...
@@ -494,7 +501,11 @@ public:
void
dump
(
std
::
vector
<
unsigned
int
>&
)
const
;
void
dump
(
std
::
vector
<
unsigned
int
>&
)
const
;
protected
:
void
createBranch
(
Block
*
block
);
void
createConditionalBranch
(
Id
condition
,
Block
*
thenBlock
,
Block
*
elseBlock
);
void
createLoopMerge
(
Block
*
mergeBlock
,
Block
*
continueBlock
,
unsigned
int
control
);
protected
:
Id
makeIntConstant
(
Id
typeId
,
unsigned
value
,
bool
specConstant
);
Id
makeIntConstant
(
Id
typeId
,
unsigned
value
,
bool
specConstant
);
Id
findScalarConstant
(
Op
typeClass
,
Op
opcode
,
Id
typeId
,
unsigned
value
)
const
;
Id
findScalarConstant
(
Op
typeClass
,
Op
opcode
,
Id
typeId
,
unsigned
value
)
const
;
Id
findScalarConstant
(
Op
typeClass
,
Op
opcode
,
Id
typeId
,
unsigned
v1
,
unsigned
v2
)
const
;
Id
findScalarConstant
(
Op
typeClass
,
Op
opcode
,
Id
typeId
,
unsigned
v1
,
unsigned
v2
)
const
;
...
@@ -503,10 +514,7 @@ protected:
...
@@ -503,10 +514,7 @@ protected:
void
transferAccessChainSwizzle
(
bool
dynamic
);
void
transferAccessChainSwizzle
(
bool
dynamic
);
void
simplifyAccessChainSwizzle
();
void
simplifyAccessChainSwizzle
();
void
createAndSetNoPredecessorBlock
(
const
char
*
);
void
createAndSetNoPredecessorBlock
(
const
char
*
);
void
createBranch
(
Block
*
block
);
void
createSelectionMerge
(
Block
*
mergeBlock
,
unsigned
int
control
);
void
createSelectionMerge
(
Block
*
mergeBlock
,
unsigned
int
control
);
void
createLoopMerge
(
Block
*
mergeBlock
,
Block
*
continueBlock
,
unsigned
int
control
);
void
createConditionalBranch
(
Id
condition
,
Block
*
thenBlock
,
Block
*
elseBlock
);
void
dumpInstructions
(
std
::
vector
<
unsigned
int
>&
,
const
std
::
vector
<
Instruction
*>&
)
const
;
void
dumpInstructions
(
std
::
vector
<
unsigned
int
>&
,
const
std
::
vector
<
Instruction
*>&
)
const
;
struct
Loop
;
// Defined below.
struct
Loop
;
// Defined below.
...
...
Test/baseResults/spv.for-simple.vert.out
View file @
9c6734c8
...
@@ -5,49 +5,51 @@ Linked vertex stage:
...
@@ -5,49 +5,51 @@ Linked vertex stage:
// Module Version 10000
// Module Version 10000
// Generated by (magic number): 80001
// Generated by (magic number): 80001
// Id's are bound by 2
5
// Id's are bound by 2
6
Capability Shader
Capability Shader
1: ExtInstImport "GLSL.std.450"
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
MemoryModel Logical GLSL450
EntryPoint Vertex 4 "main" 2
3 24
EntryPoint Vertex 4 "main" 2
4 25
Source ESSL 300
Source ESSL 300
Name 4 "main"
Name 4 "main"
Name 8 "i"
Name 8 "i"
Name 1
7
"j"
Name 1
8
"j"
Name 2
3
"gl_VertexID"
Name 2
4
"gl_VertexID"
Name 2
4
"gl_InstanceID"
Name 2
5
"gl_InstanceID"
Decorate 2
3
(gl_VertexID) BuiltIn VertexId
Decorate 2
4
(gl_VertexID) BuiltIn VertexId
Decorate 2
4
(gl_InstanceID) BuiltIn InstanceId
Decorate 2
5
(gl_InstanceID) BuiltIn InstanceId
2: TypeVoid
2: TypeVoid
3: TypeFunction 2
3: TypeFunction 2
6: TypeInt 32 1
6: TypeInt 32 1
7: TypePointer Function 6(int)
7: TypePointer Function 6(int)
9: 6(int) Constant 0
9: 6(int) Constant 0
1
4
: 6(int) Constant 10
1
5
: 6(int) Constant 10
1
5
: TypeBool
1
6
: TypeBool
1
8
: 6(int) Constant 12
1
9
: 6(int) Constant 12
2
0
: 6(int) Constant 1
2
1
: 6(int) Constant 1
2
2
: TypePointer Input 6(int)
2
3
: TypePointer Input 6(int)
2
3(gl_VertexID): 22
(ptr) Variable Input
2
4(gl_VertexID): 23
(ptr) Variable Input
2
4(gl_InstanceID): 22
(ptr) Variable Input
2
5(gl_InstanceID): 23
(ptr) Variable Input
4(main): 2 Function None 3
4(main): 2 Function None 3
5: Label
5: Label
8(i): 7(ptr) Variable Function
8(i): 7(ptr) Variable Function
1
7
(j): 7(ptr) Variable Function
1
8
(j): 7(ptr) Variable Function
Store 8(i) 9
Store 8(i) 9
Branch 1
0
Branch 1
3
10: Label
10: Label
13: 6(int) Load 8(i)
Store 18(j) 19
16: 15(bool) SLessThan 13 14
Branch 12
LoopMerge 11 10 None
BranchConditional 16 12 11
12: Label
Store 17(j) 18
19: 6(int) Load 8(i)
21: 6(int) IAdd 19 20
Store 8(i) 21
Branch 10
11: Label
11: Label
Return
Return
12: Label
20: 6(int) Load 8(i)
22: 6(int) IAdd 20 21
Store 8(i) 22
Branch 13
13: Label
14: 6(int) Load 8(i)
17: 16(bool) SLessThan 14 15
LoopMerge 11 12 None
BranchConditional 17 10 11
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