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
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"
loopTerminal
.
push
(
node
->
getTerminal
());
auto
blocks
=
builder
.
makeNewLoop
();
if
(
node
->
testFirst
()
&&
node
->
getTest
())
{
spv
::
Block
&
head
=
builder
.
makeNewBlock
();
builder
.
createBranch
(
&
head
);
builder
.
makeNewLoop
(
node
->
testFirst
());
if
(
node
->
getTest
())
{
builder
.
setBuildPoint
(
&
head
);
node
->
getTest
()
->
traverse
(
this
);
// the AST only contained the test computation, not the branch, we have to add it
spv
::
Id
condition
=
builder
.
accessChainLoad
(
convertGlslangToSpvType
(
node
->
getTest
()
->
getType
()));
builder
.
createLoopTestBranch
(
condition
);
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
);
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
{
builder
.
createBranchToBody
();
}
if
(
node
->
getBody
())
{
breakForLoop
.
push
(
true
);
node
->
getBody
()
->
traverse
(
this
);
breakForLoop
.
pop
();
builder
.
createBranch
(
&
blocks
.
body
);
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
);
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
())
loopTerminal
.
top
()
->
traverse
(
this
);
builder
.
closeLoop
();
loopTerminal
.
pop
();
builder
.
setBuildPoint
(
&
blocks
.
merge
);
return
false
;
}
...
...
SPIRV/SpvBuilder.cpp
View file @
9c6734c8
...
...
@@ -1753,6 +1753,19 @@ void Builder::endSwitch(std::vector<Block*>& /*segmentBlock*/)
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
void
Builder
::
makeNewLoop
(
bool
loopTestFirst
)
{
...
...
SPIRV/SpvBuilder.h
View file @
9c6734c8
...
...
@@ -378,6 +378,13 @@ public:
// The loopTestFirst parameter is true when the loop test executes before
// the body. (It is false for do-while loops.)
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.
// The true branch goes to the first block in the loop body, and
...
...
@@ -494,7 +501,11 @@ public:
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
findScalarConstant
(
Op
typeClass
,
Op
opcode
,
Id
typeId
,
unsigned
value
)
const
;
Id
findScalarConstant
(
Op
typeClass
,
Op
opcode
,
Id
typeId
,
unsigned
v1
,
unsigned
v2
)
const
;
...
...
@@ -503,10 +514,7 @@ protected:
void
transferAccessChainSwizzle
(
bool
dynamic
);
void
simplifyAccessChainSwizzle
();
void
createAndSetNoPredecessorBlock
(
const
char
*
);
void
createBranch
(
Block
*
block
);
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
;
struct
Loop
;
// Defined below.
...
...
Test/baseResults/spv.for-simple.vert.out
View file @
9c6734c8
...
...
@@ -5,49 +5,51 @@ Linked vertex stage:
// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 2
5
// Id's are bound by 2
6
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Vertex 4 "main" 2
3 24
EntryPoint Vertex 4 "main" 2
4 25
Source ESSL 300
Name 4 "main"
Name 8 "i"
Name 1
7
"j"
Name 2
3
"gl_VertexID"
Name 2
4
"gl_InstanceID"
Decorate 2
3
(gl_VertexID) BuiltIn VertexId
Decorate 2
4
(gl_InstanceID) BuiltIn InstanceId
Name 1
8
"j"
Name 2
4
"gl_VertexID"
Name 2
5
"gl_InstanceID"
Decorate 2
4
(gl_VertexID) BuiltIn VertexId
Decorate 2
5
(gl_InstanceID) BuiltIn InstanceId
2: TypeVoid
3: TypeFunction 2
6: TypeInt 32 1
7: TypePointer Function 6(int)
9: 6(int) Constant 0
1
4
: 6(int) Constant 10
1
5
: TypeBool
1
8
: 6(int) Constant 12
2
0
: 6(int) Constant 1
2
2
: TypePointer Input 6(int)
2
3(gl_VertexID): 22
(ptr) Variable Input
2
4(gl_InstanceID): 22
(ptr) Variable Input
1
5
: 6(int) Constant 10
1
6
: TypeBool
1
9
: 6(int) Constant 12
2
1
: 6(int) Constant 1
2
3
: TypePointer Input 6(int)
2
4(gl_VertexID): 23
(ptr) Variable Input
2
5(gl_InstanceID): 23
(ptr) Variable Input
4(main): 2 Function None 3
5: Label
8(i): 7(ptr) Variable Function
1
7
(j): 7(ptr) Variable Function
1
8
(j): 7(ptr) Variable Function
Store 8(i) 9
Branch 1
0
Branch 1
3
10: Label
13: 6(int) Load 8(i)
16: 15(bool) SLessThan 13 14
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
Store 18(j) 19
Branch 12
11: Label
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
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