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
b7946d16
Commit
b7946d16
authored
Jan 18, 2016
by
Andrew Woloszyn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Free memory associated with SPIR-V generation.
parent
863aa667
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
109 additions
and
93 deletions
+109
-93
SpvBuilder.cpp
SPIRV/SpvBuilder.cpp
+69
-67
SpvBuilder.h
SPIRV/SpvBuilder.h
+14
-10
spvIR.h
SPIRV/spvIR.h
+16
-14
intermediate.h
glslang/Include/intermediate.h
+3
-1
Intermediate.cpp
glslang/MachineIndependent/Intermediate.cpp
+7
-1
No files found.
SPIRV/SpvBuilder.cpp
View file @
b7946d16
...
@@ -77,7 +77,7 @@ Id Builder::import(const char* name)
...
@@ -77,7 +77,7 @@ Id Builder::import(const char* name)
Instruction
*
import
=
new
Instruction
(
getUniqueId
(),
NoType
,
OpExtInstImport
);
Instruction
*
import
=
new
Instruction
(
getUniqueId
(),
NoType
,
OpExtInstImport
);
import
->
addStringOperand
(
name
);
import
->
addStringOperand
(
name
);
imports
.
push_back
(
import
);
imports
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
import
)
);
return
import
->
getResultId
();
return
import
->
getResultId
();
}
}
...
@@ -88,7 +88,7 @@ Id Builder::makeVoidType()
...
@@ -88,7 +88,7 @@ Id Builder::makeVoidType()
if
(
groupedTypes
[
OpTypeVoid
].
size
()
==
0
)
{
if
(
groupedTypes
[
OpTypeVoid
].
size
()
==
0
)
{
type
=
new
Instruction
(
getUniqueId
(),
NoType
,
OpTypeVoid
);
type
=
new
Instruction
(
getUniqueId
(),
NoType
,
OpTypeVoid
);
groupedTypes
[
OpTypeVoid
].
push_back
(
type
);
groupedTypes
[
OpTypeVoid
].
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
type
)
);
module
.
mapInstruction
(
type
);
module
.
mapInstruction
(
type
);
}
else
}
else
type
=
groupedTypes
[
OpTypeVoid
].
back
();
type
=
groupedTypes
[
OpTypeVoid
].
back
();
...
@@ -102,7 +102,7 @@ Id Builder::makeBoolType()
...
@@ -102,7 +102,7 @@ Id Builder::makeBoolType()
if
(
groupedTypes
[
OpTypeBool
].
size
()
==
0
)
{
if
(
groupedTypes
[
OpTypeBool
].
size
()
==
0
)
{
type
=
new
Instruction
(
getUniqueId
(),
NoType
,
OpTypeBool
);
type
=
new
Instruction
(
getUniqueId
(),
NoType
,
OpTypeBool
);
groupedTypes
[
OpTypeBool
].
push_back
(
type
);
groupedTypes
[
OpTypeBool
].
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
type
)
);
module
.
mapInstruction
(
type
);
module
.
mapInstruction
(
type
);
}
else
}
else
type
=
groupedTypes
[
OpTypeBool
].
back
();
type
=
groupedTypes
[
OpTypeBool
].
back
();
...
@@ -116,7 +116,7 @@ Id Builder::makeSamplerType()
...
@@ -116,7 +116,7 @@ Id Builder::makeSamplerType()
if
(
groupedTypes
[
OpTypeSampler
].
size
()
==
0
)
{
if
(
groupedTypes
[
OpTypeSampler
].
size
()
==
0
)
{
type
=
new
Instruction
(
getUniqueId
(),
NoType
,
OpTypeSampler
);
type
=
new
Instruction
(
getUniqueId
(),
NoType
,
OpTypeSampler
);
groupedTypes
[
OpTypeSampler
].
push_back
(
type
);
groupedTypes
[
OpTypeSampler
].
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
type
)
);
module
.
mapInstruction
(
type
);
module
.
mapInstruction
(
type
);
}
else
}
else
type
=
groupedTypes
[
OpTypeSampler
].
back
();
type
=
groupedTypes
[
OpTypeSampler
].
back
();
...
@@ -140,7 +140,7 @@ Id Builder::makePointer(StorageClass storageClass, Id pointee)
...
@@ -140,7 +140,7 @@ Id Builder::makePointer(StorageClass storageClass, Id pointee)
type
->
addImmediateOperand
(
storageClass
);
type
->
addImmediateOperand
(
storageClass
);
type
->
addIdOperand
(
pointee
);
type
->
addIdOperand
(
pointee
);
groupedTypes
[
OpTypePointer
].
push_back
(
type
);
groupedTypes
[
OpTypePointer
].
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
type
)
);
module
.
mapInstruction
(
type
);
module
.
mapInstruction
(
type
);
return
type
->
getResultId
();
return
type
->
getResultId
();
...
@@ -162,7 +162,7 @@ Id Builder::makeIntegerType(int width, bool hasSign)
...
@@ -162,7 +162,7 @@ Id Builder::makeIntegerType(int width, bool hasSign)
type
->
addImmediateOperand
(
width
);
type
->
addImmediateOperand
(
width
);
type
->
addImmediateOperand
(
hasSign
?
1
:
0
);
type
->
addImmediateOperand
(
hasSign
?
1
:
0
);
groupedTypes
[
OpTypeInt
].
push_back
(
type
);
groupedTypes
[
OpTypeInt
].
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
type
)
);
module
.
mapInstruction
(
type
);
module
.
mapInstruction
(
type
);
return
type
->
getResultId
();
return
type
->
getResultId
();
...
@@ -182,7 +182,7 @@ Id Builder::makeFloatType(int width)
...
@@ -182,7 +182,7 @@ Id Builder::makeFloatType(int width)
type
=
new
Instruction
(
getUniqueId
(),
NoType
,
OpTypeFloat
);
type
=
new
Instruction
(
getUniqueId
(),
NoType
,
OpTypeFloat
);
type
->
addImmediateOperand
(
width
);
type
->
addImmediateOperand
(
width
);
groupedTypes
[
OpTypeFloat
].
push_back
(
type
);
groupedTypes
[
OpTypeFloat
].
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
type
)
);
module
.
mapInstruction
(
type
);
module
.
mapInstruction
(
type
);
return
type
->
getResultId
();
return
type
->
getResultId
();
...
@@ -202,7 +202,7 @@ Id Builder::makeStructType(std::vector<Id>& members, const char* name)
...
@@ -202,7 +202,7 @@ Id Builder::makeStructType(std::vector<Id>& members, const char* name)
for
(
int
op
=
0
;
op
<
(
int
)
members
.
size
();
++
op
)
for
(
int
op
=
0
;
op
<
(
int
)
members
.
size
();
++
op
)
type
->
addIdOperand
(
members
[
op
]);
type
->
addIdOperand
(
members
[
op
]);
groupedTypes
[
OpTypeStruct
].
push_back
(
type
);
groupedTypes
[
OpTypeStruct
].
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
type
)
);
module
.
mapInstruction
(
type
);
module
.
mapInstruction
(
type
);
addName
(
type
->
getResultId
(),
name
);
addName
(
type
->
getResultId
(),
name
);
...
@@ -249,7 +249,7 @@ Id Builder::makeVectorType(Id component, int size)
...
@@ -249,7 +249,7 @@ Id Builder::makeVectorType(Id component, int size)
type
->
addIdOperand
(
component
);
type
->
addIdOperand
(
component
);
type
->
addImmediateOperand
(
size
);
type
->
addImmediateOperand
(
size
);
groupedTypes
[
OpTypeVector
].
push_back
(
type
);
groupedTypes
[
OpTypeVector
].
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
type
)
);
module
.
mapInstruction
(
type
);
module
.
mapInstruction
(
type
);
return
type
->
getResultId
();
return
type
->
getResultId
();
...
@@ -275,7 +275,7 @@ Id Builder::makeMatrixType(Id component, int cols, int rows)
...
@@ -275,7 +275,7 @@ Id Builder::makeMatrixType(Id component, int cols, int rows)
type
->
addIdOperand
(
column
);
type
->
addIdOperand
(
column
);
type
->
addImmediateOperand
(
cols
);
type
->
addImmediateOperand
(
cols
);
groupedTypes
[
OpTypeMatrix
].
push_back
(
type
);
groupedTypes
[
OpTypeMatrix
].
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
type
)
);
module
.
mapInstruction
(
type
);
module
.
mapInstruction
(
type
);
return
type
->
getResultId
();
return
type
->
getResultId
();
...
@@ -305,7 +305,7 @@ Id Builder::makeArrayType(Id element, unsigned size, int stride)
...
@@ -305,7 +305,7 @@ Id Builder::makeArrayType(Id element, unsigned size, int stride)
type
->
addIdOperand
(
element
);
type
->
addIdOperand
(
element
);
type
->
addIdOperand
(
sizeId
);
type
->
addIdOperand
(
sizeId
);
groupedTypes
[
OpTypeArray
].
push_back
(
type
);
groupedTypes
[
OpTypeArray
].
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
type
)
);
module
.
mapInstruction
(
type
);
module
.
mapInstruction
(
type
);
return
type
->
getResultId
();
return
type
->
getResultId
();
...
@@ -315,7 +315,7 @@ Id Builder::makeRuntimeArray(Id element)
...
@@ -315,7 +315,7 @@ Id Builder::makeRuntimeArray(Id element)
{
{
Instruction
*
type
=
new
Instruction
(
getUniqueId
(),
NoType
,
OpTypeRuntimeArray
);
Instruction
*
type
=
new
Instruction
(
getUniqueId
(),
NoType
,
OpTypeRuntimeArray
);
type
->
addIdOperand
(
element
);
type
->
addIdOperand
(
element
);
constantsTypesGlobals
.
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
type
)
);
module
.
mapInstruction
(
type
);
module
.
mapInstruction
(
type
);
return
type
->
getResultId
();
return
type
->
getResultId
();
...
@@ -346,7 +346,7 @@ Id Builder::makeFunctionType(Id returnType, std::vector<Id>& paramTypes)
...
@@ -346,7 +346,7 @@ Id Builder::makeFunctionType(Id returnType, std::vector<Id>& paramTypes)
for
(
int
p
=
0
;
p
<
(
int
)
paramTypes
.
size
();
++
p
)
for
(
int
p
=
0
;
p
<
(
int
)
paramTypes
.
size
();
++
p
)
type
->
addIdOperand
(
paramTypes
[
p
]);
type
->
addIdOperand
(
paramTypes
[
p
]);
groupedTypes
[
OpTypeFunction
].
push_back
(
type
);
groupedTypes
[
OpTypeFunction
].
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
type
)
);
module
.
mapInstruction
(
type
);
module
.
mapInstruction
(
type
);
return
type
->
getResultId
();
return
type
->
getResultId
();
...
@@ -379,7 +379,7 @@ Id Builder::makeImageType(Id sampledType, Dim dim, bool depth, bool arrayed, boo
...
@@ -379,7 +379,7 @@ Id Builder::makeImageType(Id sampledType, Dim dim, bool depth, bool arrayed, boo
type
->
addImmediateOperand
((
unsigned
int
)
format
);
type
->
addImmediateOperand
((
unsigned
int
)
format
);
groupedTypes
[
OpTypeImage
].
push_back
(
type
);
groupedTypes
[
OpTypeImage
].
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
type
)
);
module
.
mapInstruction
(
type
);
module
.
mapInstruction
(
type
);
return
type
->
getResultId
();
return
type
->
getResultId
();
...
@@ -400,7 +400,7 @@ Id Builder::makeSampledImageType(Id imageType)
...
@@ -400,7 +400,7 @@ Id Builder::makeSampledImageType(Id imageType)
type
->
addIdOperand
(
imageType
);
type
->
addIdOperand
(
imageType
);
groupedTypes
[
OpTypeSampledImage
].
push_back
(
type
);
groupedTypes
[
OpTypeSampledImage
].
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
type
);
constantsTypesGlobals
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
type
)
);
module
.
mapInstruction
(
type
);
module
.
mapInstruction
(
type
);
return
type
->
getResultId
();
return
type
->
getResultId
();
...
@@ -594,7 +594,7 @@ Id Builder::makeBoolConstant(bool b, bool specConstant)
...
@@ -594,7 +594,7 @@ Id Builder::makeBoolConstant(bool b, bool specConstant)
// Make it
// Make it
Instruction
*
c
=
new
Instruction
(
getUniqueId
(),
typeId
,
opcode
);
Instruction
*
c
=
new
Instruction
(
getUniqueId
(),
typeId
,
opcode
);
constantsTypesGlobals
.
push_back
(
c
);
constantsTypesGlobals
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
c
)
);
groupedConstants
[
OpTypeBool
].
push_back
(
c
);
groupedConstants
[
OpTypeBool
].
push_back
(
c
);
module
.
mapInstruction
(
c
);
module
.
mapInstruction
(
c
);
...
@@ -610,7 +610,7 @@ Id Builder::makeIntConstant(Id typeId, unsigned value, bool specConstant)
...
@@ -610,7 +610,7 @@ Id Builder::makeIntConstant(Id typeId, unsigned value, bool specConstant)
Instruction
*
c
=
new
Instruction
(
getUniqueId
(),
typeId
,
opcode
);
Instruction
*
c
=
new
Instruction
(
getUniqueId
(),
typeId
,
opcode
);
c
->
addImmediateOperand
(
value
);
c
->
addImmediateOperand
(
value
);
constantsTypesGlobals
.
push_back
(
c
);
constantsTypesGlobals
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
c
)
);
groupedConstants
[
OpTypeInt
].
push_back
(
c
);
groupedConstants
[
OpTypeInt
].
push_back
(
c
);
module
.
mapInstruction
(
c
);
module
.
mapInstruction
(
c
);
...
@@ -628,7 +628,7 @@ Id Builder::makeFloatConstant(float f, bool specConstant)
...
@@ -628,7 +628,7 @@ Id Builder::makeFloatConstant(float f, bool specConstant)
Instruction
*
c
=
new
Instruction
(
getUniqueId
(),
typeId
,
opcode
);
Instruction
*
c
=
new
Instruction
(
getUniqueId
(),
typeId
,
opcode
);
c
->
addImmediateOperand
(
value
);
c
->
addImmediateOperand
(
value
);
constantsTypesGlobals
.
push_back
(
c
);
constantsTypesGlobals
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
c
)
);
groupedConstants
[
OpTypeFloat
].
push_back
(
c
);
groupedConstants
[
OpTypeFloat
].
push_back
(
c
);
module
.
mapInstruction
(
c
);
module
.
mapInstruction
(
c
);
...
@@ -649,7 +649,7 @@ Id Builder::makeDoubleConstant(double d, bool specConstant)
...
@@ -649,7 +649,7 @@ Id Builder::makeDoubleConstant(double d, bool specConstant)
Instruction
*
c
=
new
Instruction
(
getUniqueId
(),
typeId
,
opcode
);
Instruction
*
c
=
new
Instruction
(
getUniqueId
(),
typeId
,
opcode
);
c
->
addImmediateOperand
(
op1
);
c
->
addImmediateOperand
(
op1
);
c
->
addImmediateOperand
(
op2
);
c
->
addImmediateOperand
(
op2
);
constantsTypesGlobals
.
push_back
(
c
);
constantsTypesGlobals
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
c
)
);
groupedConstants
[
OpTypeFloat
].
push_back
(
c
);
groupedConstants
[
OpTypeFloat
].
push_back
(
c
);
module
.
mapInstruction
(
c
);
module
.
mapInstruction
(
c
);
...
@@ -708,7 +708,7 @@ Id Builder::makeCompositeConstant(Id typeId, std::vector<Id>& members)
...
@@ -708,7 +708,7 @@ Id Builder::makeCompositeConstant(Id typeId, std::vector<Id>& members)
Instruction
*
c
=
new
Instruction
(
getUniqueId
(),
typeId
,
OpConstantComposite
);
Instruction
*
c
=
new
Instruction
(
getUniqueId
(),
typeId
,
OpConstantComposite
);
for
(
int
op
=
0
;
op
<
(
int
)
members
.
size
();
++
op
)
for
(
int
op
=
0
;
op
<
(
int
)
members
.
size
();
++
op
)
c
->
addIdOperand
(
members
[
op
]);
c
->
addIdOperand
(
members
[
op
]);
constantsTypesGlobals
.
push_back
(
c
);
constantsTypesGlobals
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
c
)
);
groupedConstants
[
typeClass
].
push_back
(
c
);
groupedConstants
[
typeClass
].
push_back
(
c
);
module
.
mapInstruction
(
c
);
module
.
mapInstruction
(
c
);
...
@@ -722,7 +722,7 @@ Instruction* Builder::addEntryPoint(ExecutionModel model, Function* function, co
...
@@ -722,7 +722,7 @@ Instruction* Builder::addEntryPoint(ExecutionModel model, Function* function, co
entryPoint
->
addIdOperand
(
function
->
getId
());
entryPoint
->
addIdOperand
(
function
->
getId
());
entryPoint
->
addStringOperand
(
name
);
entryPoint
->
addStringOperand
(
name
);
entryPoints
.
push_back
(
entryPoint
);
entryPoints
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
entryPoint
)
);
return
entryPoint
;
return
entryPoint
;
}
}
...
@@ -740,7 +740,7 @@ void Builder::addExecutionMode(Function* entryPoint, ExecutionMode mode, int val
...
@@ -740,7 +740,7 @@ void Builder::addExecutionMode(Function* entryPoint, ExecutionMode mode, int val
if
(
value3
>=
0
)
if
(
value3
>=
0
)
instr
->
addImmediateOperand
(
value3
);
instr
->
addImmediateOperand
(
value3
);
executionModes
.
push_back
(
instr
);
executionModes
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
instr
)
);
}
}
void
Builder
::
addName
(
Id
id
,
const
char
*
string
)
void
Builder
::
addName
(
Id
id
,
const
char
*
string
)
...
@@ -749,7 +749,7 @@ void Builder::addName(Id id, const char* string)
...
@@ -749,7 +749,7 @@ void Builder::addName(Id id, const char* string)
name
->
addIdOperand
(
id
);
name
->
addIdOperand
(
id
);
name
->
addStringOperand
(
string
);
name
->
addStringOperand
(
string
);
names
.
push_back
(
name
);
names
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
name
)
);
}
}
void
Builder
::
addMemberName
(
Id
id
,
int
memberNumber
,
const
char
*
string
)
void
Builder
::
addMemberName
(
Id
id
,
int
memberNumber
,
const
char
*
string
)
...
@@ -759,7 +759,7 @@ void Builder::addMemberName(Id id, int memberNumber, const char* string)
...
@@ -759,7 +759,7 @@ void Builder::addMemberName(Id id, int memberNumber, const char* string)
name
->
addImmediateOperand
(
memberNumber
);
name
->
addImmediateOperand
(
memberNumber
);
name
->
addStringOperand
(
string
);
name
->
addStringOperand
(
string
);
names
.
push_back
(
name
);
names
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
name
)
);
}
}
void
Builder
::
addLine
(
Id
target
,
Id
fileName
,
int
lineNum
,
int
column
)
void
Builder
::
addLine
(
Id
target
,
Id
fileName
,
int
lineNum
,
int
column
)
...
@@ -770,7 +770,7 @@ void Builder::addLine(Id target, Id fileName, int lineNum, int column)
...
@@ -770,7 +770,7 @@ void Builder::addLine(Id target, Id fileName, int lineNum, int column)
line
->
addImmediateOperand
(
lineNum
);
line
->
addImmediateOperand
(
lineNum
);
line
->
addImmediateOperand
(
column
);
line
->
addImmediateOperand
(
column
);
lines
.
push_back
(
line
);
lines
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
line
)
);
}
}
void
Builder
::
addDecoration
(
Id
id
,
Decoration
decoration
,
int
num
)
void
Builder
::
addDecoration
(
Id
id
,
Decoration
decoration
,
int
num
)
...
@@ -783,7 +783,7 @@ void Builder::addDecoration(Id id, Decoration decoration, int num)
...
@@ -783,7 +783,7 @@ void Builder::addDecoration(Id id, Decoration decoration, int num)
if
(
num
>=
0
)
if
(
num
>=
0
)
dec
->
addImmediateOperand
(
num
);
dec
->
addImmediateOperand
(
num
);
decorations
.
push_back
(
dec
);
decorations
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
dec
)
);
}
}
void
Builder
::
addMemberDecoration
(
Id
id
,
unsigned
int
member
,
Decoration
decoration
,
int
num
)
void
Builder
::
addMemberDecoration
(
Id
id
,
unsigned
int
member
,
Decoration
decoration
,
int
num
)
...
@@ -795,7 +795,7 @@ void Builder::addMemberDecoration(Id id, unsigned int member, Decoration decorat
...
@@ -795,7 +795,7 @@ void Builder::addMemberDecoration(Id id, unsigned int member, Decoration decorat
if
(
num
>=
0
)
if
(
num
>=
0
)
dec
->
addImmediateOperand
(
num
);
dec
->
addImmediateOperand
(
num
);
decorations
.
push_back
(
dec
);
decorations
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
dec
)
);
}
}
// Comments in header
// Comments in header
...
@@ -827,6 +827,8 @@ Function* Builder::makeFunctionEntry(Id returnType, const char* name, std::vecto
...
@@ -827,6 +827,8 @@ Function* Builder::makeFunctionEntry(Id returnType, const char* name, std::vecto
if
(
name
)
if
(
name
)
addName
(
function
->
getId
(),
name
);
addName
(
function
->
getId
(),
name
);
functions
.
push_back
(
std
::
unique_ptr
<
Function
>
(
function
));
return
function
;
return
function
;
}
}
...
@@ -836,9 +838,9 @@ void Builder::makeReturn(bool implicit, Id retVal)
...
@@ -836,9 +838,9 @@ void Builder::makeReturn(bool implicit, Id retVal)
if
(
retVal
)
{
if
(
retVal
)
{
Instruction
*
inst
=
new
Instruction
(
NoResult
,
NoType
,
OpReturnValue
);
Instruction
*
inst
=
new
Instruction
(
NoResult
,
NoType
,
OpReturnValue
);
inst
->
addIdOperand
(
retVal
);
inst
->
addIdOperand
(
retVal
);
buildPoint
->
addInstruction
(
inst
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
inst
)
);
}
else
}
else
buildPoint
->
addInstruction
(
new
Instruction
(
NoResult
,
NoType
,
OpReturn
));
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
new
Instruction
(
NoResult
,
NoType
,
OpReturn
)
));
if
(
!
implicit
)
if
(
!
implicit
)
createAndSetNoPredecessorBlock
(
"post-return"
);
createAndSetNoPredecessorBlock
(
"post-return"
);
...
@@ -878,7 +880,7 @@ void Builder::leaveFunction()
...
@@ -878,7 +880,7 @@ void Builder::leaveFunction()
// Comments in header
// Comments in header
void
Builder
::
makeDiscard
()
void
Builder
::
makeDiscard
()
{
{
buildPoint
->
addInstruction
(
new
Instruction
(
OpKill
));
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
new
Instruction
(
OpKill
)
));
createAndSetNoPredecessorBlock
(
"post-discard"
);
createAndSetNoPredecessorBlock
(
"post-discard"
);
}
}
...
@@ -892,11 +894,11 @@ Id Builder::createVariable(StorageClass storageClass, Id type, const char* name)
...
@@ -892,11 +894,11 @@ Id Builder::createVariable(StorageClass storageClass, Id type, const char* name)
switch
(
storageClass
)
{
switch
(
storageClass
)
{
case
StorageClassFunction
:
case
StorageClassFunction
:
// Validation rules require the declaration in the entry block
// Validation rules require the declaration in the entry block
buildPoint
->
getParent
().
addLocalVariable
(
inst
);
buildPoint
->
getParent
().
addLocalVariable
(
std
::
unique_ptr
<
Instruction
>
(
inst
)
);
break
;
break
;
default
:
default
:
constantsTypesGlobals
.
push_back
(
inst
);
constantsTypesGlobals
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
inst
)
);
module
.
mapInstruction
(
inst
);
module
.
mapInstruction
(
inst
);
break
;
break
;
}
}
...
@@ -911,7 +913,7 @@ Id Builder::createVariable(StorageClass storageClass, Id type, const char* name)
...
@@ -911,7 +913,7 @@ Id Builder::createVariable(StorageClass storageClass, Id type, const char* name)
Id
Builder
::
createUndefined
(
Id
type
)
Id
Builder
::
createUndefined
(
Id
type
)
{
{
Instruction
*
inst
=
new
Instruction
(
getUniqueId
(),
type
,
OpUndef
);
Instruction
*
inst
=
new
Instruction
(
getUniqueId
(),
type
,
OpUndef
);
buildPoint
->
addInstruction
(
inst
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
inst
)
);
return
inst
->
getResultId
();
return
inst
->
getResultId
();
}
}
...
@@ -921,7 +923,7 @@ void Builder::createStore(Id rValue, Id lValue)
...
@@ -921,7 +923,7 @@ void Builder::createStore(Id rValue, Id lValue)
Instruction
*
store
=
new
Instruction
(
OpStore
);
Instruction
*
store
=
new
Instruction
(
OpStore
);
store
->
addIdOperand
(
lValue
);
store
->
addIdOperand
(
lValue
);
store
->
addIdOperand
(
rValue
);
store
->
addIdOperand
(
rValue
);
buildPoint
->
addInstruction
(
st
ore
);
buildPoint
->
addInstruction
(
st
d
::
unique_ptr
<
Instruction
>
(
store
)
);
}
}
// Comments in header
// Comments in header
...
@@ -929,7 +931,7 @@ Id Builder::createLoad(Id lValue)
...
@@ -929,7 +931,7 @@ Id Builder::createLoad(Id lValue)
{
{
Instruction
*
load
=
new
Instruction
(
getUniqueId
(),
getDerefTypeId
(
lValue
),
OpLoad
);
Instruction
*
load
=
new
Instruction
(
getUniqueId
(),
getDerefTypeId
(
lValue
),
OpLoad
);
load
->
addIdOperand
(
lValue
);
load
->
addIdOperand
(
lValue
);
buildPoint
->
addInstruction
(
load
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
load
)
);
return
load
->
getResultId
();
return
load
->
getResultId
();
}
}
...
@@ -955,7 +957,7 @@ Id Builder::createAccessChain(StorageClass storageClass, Id base, std::vector<Id
...
@@ -955,7 +957,7 @@ Id Builder::createAccessChain(StorageClass storageClass, Id base, std::vector<Id
chain
->
addIdOperand
(
base
);
chain
->
addIdOperand
(
base
);
for
(
int
i
=
0
;
i
<
(
int
)
offsets
.
size
();
++
i
)
for
(
int
i
=
0
;
i
<
(
int
)
offsets
.
size
();
++
i
)
chain
->
addIdOperand
(
offsets
[
i
]);
chain
->
addIdOperand
(
offsets
[
i
]);
buildPoint
->
addInstruction
(
chain
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
chain
)
);
return
chain
->
getResultId
();
return
chain
->
getResultId
();
}
}
...
@@ -965,7 +967,7 @@ Id Builder::createArrayLength(Id base, unsigned int member)
...
@@ -965,7 +967,7 @@ Id Builder::createArrayLength(Id base, unsigned int member)
Instruction
*
length
=
new
Instruction
(
getUniqueId
(),
makeIntType
(
32
),
OpArrayLength
);
Instruction
*
length
=
new
Instruction
(
getUniqueId
(),
makeIntType
(
32
),
OpArrayLength
);
length
->
addIdOperand
(
base
);
length
->
addIdOperand
(
base
);
length
->
addImmediateOperand
(
member
);
length
->
addImmediateOperand
(
member
);
buildPoint
->
addInstruction
(
length
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
length
)
);
return
length
->
getResultId
();
return
length
->
getResultId
();
}
}
...
@@ -975,7 +977,7 @@ Id Builder::createCompositeExtract(Id composite, Id typeId, unsigned index)
...
@@ -975,7 +977,7 @@ Id Builder::createCompositeExtract(Id composite, Id typeId, unsigned index)
Instruction
*
extract
=
new
Instruction
(
getUniqueId
(),
typeId
,
OpCompositeExtract
);
Instruction
*
extract
=
new
Instruction
(
getUniqueId
(),
typeId
,
OpCompositeExtract
);
extract
->
addIdOperand
(
composite
);
extract
->
addIdOperand
(
composite
);
extract
->
addImmediateOperand
(
index
);
extract
->
addImmediateOperand
(
index
);
buildPoint
->
addInstruction
(
extract
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
extract
)
);
return
extract
->
getResultId
();
return
extract
->
getResultId
();
}
}
...
@@ -986,7 +988,7 @@ Id Builder::createCompositeExtract(Id composite, Id typeId, std::vector<unsigned
...
@@ -986,7 +988,7 @@ Id Builder::createCompositeExtract(Id composite, Id typeId, std::vector<unsigned
extract
->
addIdOperand
(
composite
);
extract
->
addIdOperand
(
composite
);
for
(
int
i
=
0
;
i
<
(
int
)
indexes
.
size
();
++
i
)
for
(
int
i
=
0
;
i
<
(
int
)
indexes
.
size
();
++
i
)
extract
->
addImmediateOperand
(
indexes
[
i
]);
extract
->
addImmediateOperand
(
indexes
[
i
]);
buildPoint
->
addInstruction
(
extract
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
extract
)
);
return
extract
->
getResultId
();
return
extract
->
getResultId
();
}
}
...
@@ -997,7 +999,7 @@ Id Builder::createCompositeInsert(Id object, Id composite, Id typeId, unsigned i
...
@@ -997,7 +999,7 @@ Id Builder::createCompositeInsert(Id object, Id composite, Id typeId, unsigned i
insert
->
addIdOperand
(
object
);
insert
->
addIdOperand
(
object
);
insert
->
addIdOperand
(
composite
);
insert
->
addIdOperand
(
composite
);
insert
->
addImmediateOperand
(
index
);
insert
->
addImmediateOperand
(
index
);
buildPoint
->
addInstruction
(
insert
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
insert
)
);
return
insert
->
getResultId
();
return
insert
->
getResultId
();
}
}
...
@@ -1009,7 +1011,7 @@ Id Builder::createCompositeInsert(Id object, Id composite, Id typeId, std::vecto
...
@@ -1009,7 +1011,7 @@ Id Builder::createCompositeInsert(Id object, Id composite, Id typeId, std::vecto
insert
->
addIdOperand
(
composite
);
insert
->
addIdOperand
(
composite
);
for
(
int
i
=
0
;
i
<
(
int
)
indexes
.
size
();
++
i
)
for
(
int
i
=
0
;
i
<
(
int
)
indexes
.
size
();
++
i
)
insert
->
addImmediateOperand
(
indexes
[
i
]);
insert
->
addImmediateOperand
(
indexes
[
i
]);
buildPoint
->
addInstruction
(
insert
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
insert
)
);
return
insert
->
getResultId
();
return
insert
->
getResultId
();
}
}
...
@@ -1019,7 +1021,7 @@ Id Builder::createVectorExtractDynamic(Id vector, Id typeId, Id componentIndex)
...
@@ -1019,7 +1021,7 @@ Id Builder::createVectorExtractDynamic(Id vector, Id typeId, Id componentIndex)
Instruction
*
extract
=
new
Instruction
(
getUniqueId
(),
typeId
,
OpVectorExtractDynamic
);
Instruction
*
extract
=
new
Instruction
(
getUniqueId
(),
typeId
,
OpVectorExtractDynamic
);
extract
->
addIdOperand
(
vector
);
extract
->
addIdOperand
(
vector
);
extract
->
addIdOperand
(
componentIndex
);
extract
->
addIdOperand
(
componentIndex
);
buildPoint
->
addInstruction
(
extract
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
extract
)
);
return
extract
->
getResultId
();
return
extract
->
getResultId
();
}
}
...
@@ -1030,7 +1032,7 @@ Id Builder::createVectorInsertDynamic(Id vector, Id typeId, Id component, Id com
...
@@ -1030,7 +1032,7 @@ Id Builder::createVectorInsertDynamic(Id vector, Id typeId, Id component, Id com
insert
->
addIdOperand
(
vector
);
insert
->
addIdOperand
(
vector
);
insert
->
addIdOperand
(
component
);
insert
->
addIdOperand
(
component
);
insert
->
addIdOperand
(
componentIndex
);
insert
->
addIdOperand
(
componentIndex
);
buildPoint
->
addInstruction
(
insert
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
insert
)
);
return
insert
->
getResultId
();
return
insert
->
getResultId
();
}
}
...
@@ -1039,7 +1041,7 @@ Id Builder::createVectorInsertDynamic(Id vector, Id typeId, Id component, Id com
...
@@ -1039,7 +1041,7 @@ Id Builder::createVectorInsertDynamic(Id vector, Id typeId, Id component, Id com
void
Builder
::
createNoResultOp
(
Op
opCode
)
void
Builder
::
createNoResultOp
(
Op
opCode
)
{
{
Instruction
*
op
=
new
Instruction
(
opCode
);
Instruction
*
op
=
new
Instruction
(
opCode
);
buildPoint
->
addInstruction
(
op
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
op
)
);
}
}
// An opcode that has one operand, no result id, and no type
// An opcode that has one operand, no result id, and no type
...
@@ -1047,7 +1049,7 @@ void Builder::createNoResultOp(Op opCode, Id operand)
...
@@ -1047,7 +1049,7 @@ void Builder::createNoResultOp(Op opCode, Id operand)
{
{
Instruction
*
op
=
new
Instruction
(
opCode
);
Instruction
*
op
=
new
Instruction
(
opCode
);
op
->
addIdOperand
(
operand
);
op
->
addIdOperand
(
operand
);
buildPoint
->
addInstruction
(
op
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
op
)
);
}
}
// An opcode that has one operand, no result id, and no type
// An opcode that has one operand, no result id, and no type
...
@@ -1056,7 +1058,7 @@ void Builder::createNoResultOp(Op opCode, const std::vector<Id>& operands)
...
@@ -1056,7 +1058,7 @@ void Builder::createNoResultOp(Op opCode, const std::vector<Id>& operands)
Instruction
*
op
=
new
Instruction
(
opCode
);
Instruction
*
op
=
new
Instruction
(
opCode
);
for
(
auto
operand
:
operands
)
for
(
auto
operand
:
operands
)
op
->
addIdOperand
(
operand
);
op
->
addIdOperand
(
operand
);
buildPoint
->
addInstruction
(
op
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
op
)
);
}
}
void
Builder
::
createControlBarrier
(
Scope
execution
,
Scope
memory
,
MemorySemanticsMask
semantics
)
void
Builder
::
createControlBarrier
(
Scope
execution
,
Scope
memory
,
MemorySemanticsMask
semantics
)
...
@@ -1065,7 +1067,7 @@ void Builder::createControlBarrier(Scope execution, Scope memory, MemorySemantic
...
@@ -1065,7 +1067,7 @@ void Builder::createControlBarrier(Scope execution, Scope memory, MemorySemantic
op
->
addImmediateOperand
(
makeUintConstant
(
execution
));
op
->
addImmediateOperand
(
makeUintConstant
(
execution
));
op
->
addImmediateOperand
(
makeUintConstant
(
memory
));
op
->
addImmediateOperand
(
makeUintConstant
(
memory
));
op
->
addImmediateOperand
(
makeUintConstant
(
semantics
));
op
->
addImmediateOperand
(
makeUintConstant
(
semantics
));
buildPoint
->
addInstruction
(
op
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
op
)
);
}
}
void
Builder
::
createMemoryBarrier
(
unsigned
executionScope
,
unsigned
memorySemantics
)
void
Builder
::
createMemoryBarrier
(
unsigned
executionScope
,
unsigned
memorySemantics
)
...
@@ -1073,7 +1075,7 @@ void Builder::createMemoryBarrier(unsigned executionScope, unsigned memorySemant
...
@@ -1073,7 +1075,7 @@ void Builder::createMemoryBarrier(unsigned executionScope, unsigned memorySemant
Instruction
*
op
=
new
Instruction
(
OpMemoryBarrier
);
Instruction
*
op
=
new
Instruction
(
OpMemoryBarrier
);
op
->
addImmediateOperand
(
makeUintConstant
(
executionScope
));
op
->
addImmediateOperand
(
makeUintConstant
(
executionScope
));
op
->
addImmediateOperand
(
makeUintConstant
(
memorySemantics
));
op
->
addImmediateOperand
(
makeUintConstant
(
memorySemantics
));
buildPoint
->
addInstruction
(
op
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
op
)
);
}
}
// An opcode that has one operands, a result id, and a type
// An opcode that has one operands, a result id, and a type
...
@@ -1081,7 +1083,7 @@ Id Builder::createUnaryOp(Op opCode, Id typeId, Id operand)
...
@@ -1081,7 +1083,7 @@ Id Builder::createUnaryOp(Op opCode, Id typeId, Id operand)
{
{
Instruction
*
op
=
new
Instruction
(
getUniqueId
(),
typeId
,
opCode
);
Instruction
*
op
=
new
Instruction
(
getUniqueId
(),
typeId
,
opCode
);
op
->
addIdOperand
(
operand
);
op
->
addIdOperand
(
operand
);
buildPoint
->
addInstruction
(
op
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
op
)
);
return
op
->
getResultId
();
return
op
->
getResultId
();
}
}
...
@@ -1091,7 +1093,7 @@ Id Builder::createBinOp(Op opCode, Id typeId, Id left, Id right)
...
@@ -1091,7 +1093,7 @@ Id Builder::createBinOp(Op opCode, Id typeId, Id left, Id right)
Instruction
*
op
=
new
Instruction
(
getUniqueId
(),
typeId
,
opCode
);
Instruction
*
op
=
new
Instruction
(
getUniqueId
(),
typeId
,
opCode
);
op
->
addIdOperand
(
left
);
op
->
addIdOperand
(
left
);
op
->
addIdOperand
(
right
);
op
->
addIdOperand
(
right
);
buildPoint
->
addInstruction
(
op
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
op
)
);
return
op
->
getResultId
();
return
op
->
getResultId
();
}
}
...
@@ -1102,7 +1104,7 @@ Id Builder::createTriOp(Op opCode, Id typeId, Id op1, Id op2, Id op3)
...
@@ -1102,7 +1104,7 @@ Id Builder::createTriOp(Op opCode, Id typeId, Id op1, Id op2, Id op3)
op
->
addIdOperand
(
op1
);
op
->
addIdOperand
(
op1
);
op
->
addIdOperand
(
op2
);
op
->
addIdOperand
(
op2
);
op
->
addIdOperand
(
op3
);
op
->
addIdOperand
(
op3
);
buildPoint
->
addInstruction
(
op
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
op
)
);
return
op
->
getResultId
();
return
op
->
getResultId
();
}
}
...
@@ -1112,7 +1114,7 @@ Id Builder::createOp(Op opCode, Id typeId, const std::vector<Id>& operands)
...
@@ -1112,7 +1114,7 @@ Id Builder::createOp(Op opCode, Id typeId, const std::vector<Id>& operands)
Instruction
*
op
=
new
Instruction
(
getUniqueId
(),
typeId
,
opCode
);
Instruction
*
op
=
new
Instruction
(
getUniqueId
(),
typeId
,
opCode
);
for
(
auto
operand
:
operands
)
for
(
auto
operand
:
operands
)
op
->
addIdOperand
(
operand
);
op
->
addIdOperand
(
operand
);
buildPoint
->
addInstruction
(
op
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
op
)
);
return
op
->
getResultId
();
return
op
->
getResultId
();
}
}
...
@@ -1123,7 +1125,7 @@ Id Builder::createFunctionCall(spv::Function* function, std::vector<spv::Id>& ar
...
@@ -1123,7 +1125,7 @@ Id Builder::createFunctionCall(spv::Function* function, std::vector<spv::Id>& ar
op
->
addIdOperand
(
function
->
getId
());
op
->
addIdOperand
(
function
->
getId
());
for
(
int
a
=
0
;
a
<
(
int
)
args
.
size
();
++
a
)
for
(
int
a
=
0
;
a
<
(
int
)
args
.
size
();
++
a
)
op
->
addIdOperand
(
args
[
a
]);
op
->
addIdOperand
(
args
[
a
]);
buildPoint
->
addInstruction
(
op
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
op
)
);
return
op
->
getResultId
();
return
op
->
getResultId
();
}
}
...
@@ -1140,7 +1142,7 @@ Id Builder::createRvalueSwizzle(Id typeId, Id source, std::vector<unsigned>& cha
...
@@ -1140,7 +1142,7 @@ Id Builder::createRvalueSwizzle(Id typeId, Id source, std::vector<unsigned>& cha
swizzle
->
addIdOperand
(
source
);
swizzle
->
addIdOperand
(
source
);
for
(
int
i
=
0
;
i
<
(
int
)
channels
.
size
();
++
i
)
for
(
int
i
=
0
;
i
<
(
int
)
channels
.
size
();
++
i
)
swizzle
->
addImmediateOperand
(
channels
[
i
]);
swizzle
->
addImmediateOperand
(
channels
[
i
]);
buildPoint
->
addInstruction
(
s
wizzle
);
buildPoint
->
addInstruction
(
s
td
::
unique_ptr
<
Instruction
>
(
swizzle
)
);
return
swizzle
->
getResultId
();
return
swizzle
->
getResultId
();
}
}
...
@@ -1171,7 +1173,7 @@ Id Builder::createLvalueSwizzle(Id typeId, Id target, Id source, std::vector<uns
...
@@ -1171,7 +1173,7 @@ Id Builder::createLvalueSwizzle(Id typeId, Id target, Id source, std::vector<uns
// finish the instruction with these components selectors
// finish the instruction with these components selectors
for
(
int
i
=
0
;
i
<
numTargetComponents
;
++
i
)
for
(
int
i
=
0
;
i
<
numTargetComponents
;
++
i
)
swizzle
->
addImmediateOperand
(
components
[
i
]);
swizzle
->
addImmediateOperand
(
components
[
i
]);
buildPoint
->
addInstruction
(
s
wizzle
);
buildPoint
->
addInstruction
(
s
td
::
unique_ptr
<
Instruction
>
(
swizzle
)
);
return
swizzle
->
getResultId
();
return
swizzle
->
getResultId
();
}
}
...
@@ -1202,7 +1204,7 @@ Id Builder::smearScalar(Decoration /*precision*/, Id scalar, Id vectorType)
...
@@ -1202,7 +1204,7 @@ Id Builder::smearScalar(Decoration /*precision*/, Id scalar, Id vectorType)
Instruction
*
smear
=
new
Instruction
(
getUniqueId
(),
vectorType
,
OpCompositeConstruct
);
Instruction
*
smear
=
new
Instruction
(
getUniqueId
(),
vectorType
,
OpCompositeConstruct
);
for
(
int
c
=
0
;
c
<
numComponents
;
++
c
)
for
(
int
c
=
0
;
c
<
numComponents
;
++
c
)
smear
->
addIdOperand
(
scalar
);
smear
->
addIdOperand
(
scalar
);
buildPoint
->
addInstruction
(
s
mear
);
buildPoint
->
addInstruction
(
s
td
::
unique_ptr
<
Instruction
>
(
smear
)
);
return
smear
->
getResultId
();
return
smear
->
getResultId
();
}
}
...
@@ -1216,7 +1218,7 @@ Id Builder::createBuiltinCall(Decoration /*precision*/, Id resultType, Id builti
...
@@ -1216,7 +1218,7 @@ Id Builder::createBuiltinCall(Decoration /*precision*/, Id resultType, Id builti
for
(
int
arg
=
0
;
arg
<
(
int
)
args
.
size
();
++
arg
)
for
(
int
arg
=
0
;
arg
<
(
int
)
args
.
size
();
++
arg
)
inst
->
addIdOperand
(
args
[
arg
]);
inst
->
addIdOperand
(
args
[
arg
]);
buildPoint
->
addInstruction
(
inst
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
inst
)
);
return
inst
->
getResultId
();
return
inst
->
getResultId
();
}
}
...
@@ -1344,7 +1346,7 @@ Id Builder::createTextureCall(Decoration precision, Id resultType, bool fetch, b
...
@@ -1344,7 +1346,7 @@ Id Builder::createTextureCall(Decoration precision, Id resultType, bool fetch, b
for
(
int
op
=
optArgNum
+
1
;
op
<
numArgs
;
++
op
)
for
(
int
op
=
optArgNum
+
1
;
op
<
numArgs
;
++
op
)
textureInst
->
addIdOperand
(
texArgs
[
op
]);
textureInst
->
addIdOperand
(
texArgs
[
op
]);
setPrecision
(
textureInst
->
getResultId
(),
precision
);
setPrecision
(
textureInst
->
getResultId
(),
precision
);
buildPoint
->
addInstruction
(
textureInst
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
textureInst
)
);
Id
resultId
=
textureInst
->
getResultId
();
Id
resultId
=
textureInst
->
getResultId
();
...
@@ -1412,7 +1414,7 @@ Id Builder::createTextureQueryCall(Op opCode, const TextureParameters& parameter
...
@@ -1412,7 +1414,7 @@ Id Builder::createTextureQueryCall(Op opCode, const TextureParameters& parameter
query
->
addIdOperand
(
parameters
.
coords
);
query
->
addIdOperand
(
parameters
.
coords
);
if
(
parameters
.
lod
)
if
(
parameters
.
lod
)
query
->
addIdOperand
(
parameters
.
lod
);
query
->
addIdOperand
(
parameters
.
lod
);
buildPoint
->
addInstruction
(
query
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
query
)
);
return
query
->
getResultId
();
return
query
->
getResultId
();
}
}
...
@@ -1494,7 +1496,7 @@ Id Builder::createCompositeConstruct(Id typeId, std::vector<Id>& constituents)
...
@@ -1494,7 +1496,7 @@ Id Builder::createCompositeConstruct(Id typeId, std::vector<Id>& constituents)
Instruction
*
op
=
new
Instruction
(
getUniqueId
(),
typeId
,
OpCompositeConstruct
);
Instruction
*
op
=
new
Instruction
(
getUniqueId
(),
typeId
,
OpCompositeConstruct
);
for
(
int
c
=
0
;
c
<
(
int
)
constituents
.
size
();
++
c
)
for
(
int
c
=
0
;
c
<
(
int
)
constituents
.
size
();
++
c
)
op
->
addIdOperand
(
constituents
[
c
]);
op
->
addIdOperand
(
constituents
[
c
]);
buildPoint
->
addInstruction
(
op
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
op
)
);
return
op
->
getResultId
();
return
op
->
getResultId
();
}
}
...
@@ -1710,7 +1712,7 @@ void Builder::makeSwitch(Id selector, int numSegments, std::vector<int>& caseVal
...
@@ -1710,7 +1712,7 @@ void Builder::makeSwitch(Id selector, int numSegments, std::vector<int>& caseVal
switchInst
->
addImmediateOperand
(
caseValues
[
i
]);
switchInst
->
addImmediateOperand
(
caseValues
[
i
]);
switchInst
->
addIdOperand
(
segmentBlocks
[
valueIndexToSegment
[
i
]]
->
getId
());
switchInst
->
addIdOperand
(
segmentBlocks
[
valueIndexToSegment
[
i
]]
->
getId
());
}
}
buildPoint
->
addInstruction
(
s
witchInst
);
buildPoint
->
addInstruction
(
s
td
::
unique_ptr
<
Instruction
>
(
switchInst
)
);
// push the merge block
// push the merge block
switchMerges
.
push
(
mergeBlock
);
switchMerges
.
push
(
mergeBlock
);
...
@@ -1781,7 +1783,7 @@ void Builder::makeNewLoop(bool loopTestFirst)
...
@@ -1781,7 +1783,7 @@ void Builder::makeNewLoop(bool loopTestFirst)
// but we don't yet know where they will come from.
// but we don't yet know where they will come from.
loop
.
isFirstIteration
->
addIdOperand
(
makeBoolConstant
(
true
));
loop
.
isFirstIteration
->
addIdOperand
(
makeBoolConstant
(
true
));
loop
.
isFirstIteration
->
addIdOperand
(
preheader
->
getId
());
loop
.
isFirstIteration
->
addIdOperand
(
preheader
->
getId
());
getBuildPoint
()
->
addInstruction
(
loop
.
isFirstIteration
);
getBuildPoint
()
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
loop
.
isFirstIteration
)
);
// Mark the end of the structured loop. This must exist in the loop header block.
// Mark the end of the structured loop. This must exist in the loop header block.
createLoopMerge
(
loop
.
merge
,
loop
.
header
,
LoopControlMaskNone
);
createLoopMerge
(
loop
.
merge
,
loop
.
header
,
LoopControlMaskNone
);
...
@@ -2203,7 +2205,7 @@ void Builder::createBranch(Block* block)
...
@@ -2203,7 +2205,7 @@ void Builder::createBranch(Block* block)
{
{
Instruction
*
branch
=
new
Instruction
(
OpBranch
);
Instruction
*
branch
=
new
Instruction
(
OpBranch
);
branch
->
addIdOperand
(
block
->
getId
());
branch
->
addIdOperand
(
block
->
getId
());
buildPoint
->
addInstruction
(
branch
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
branch
)
);
block
->
addPredecessor
(
buildPoint
);
block
->
addPredecessor
(
buildPoint
);
}
}
...
@@ -2212,7 +2214,7 @@ void Builder::createSelectionMerge(Block* mergeBlock, unsigned int control)
...
@@ -2212,7 +2214,7 @@ void Builder::createSelectionMerge(Block* mergeBlock, unsigned int control)
Instruction
*
merge
=
new
Instruction
(
OpSelectionMerge
);
Instruction
*
merge
=
new
Instruction
(
OpSelectionMerge
);
merge
->
addIdOperand
(
mergeBlock
->
getId
());
merge
->
addIdOperand
(
mergeBlock
->
getId
());
merge
->
addImmediateOperand
(
control
);
merge
->
addImmediateOperand
(
control
);
buildPoint
->
addInstruction
(
merge
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
merge
)
);
}
}
void
Builder
::
createLoopMerge
(
Block
*
mergeBlock
,
Block
*
continueBlock
,
unsigned
int
control
)
void
Builder
::
createLoopMerge
(
Block
*
mergeBlock
,
Block
*
continueBlock
,
unsigned
int
control
)
...
@@ -2221,7 +2223,7 @@ void Builder::createLoopMerge(Block* mergeBlock, Block* continueBlock, unsigned
...
@@ -2221,7 +2223,7 @@ void Builder::createLoopMerge(Block* mergeBlock, Block* continueBlock, unsigned
merge
->
addIdOperand
(
mergeBlock
->
getId
());
merge
->
addIdOperand
(
mergeBlock
->
getId
());
merge
->
addIdOperand
(
continueBlock
->
getId
());
merge
->
addIdOperand
(
continueBlock
->
getId
());
merge
->
addImmediateOperand
(
control
);
merge
->
addImmediateOperand
(
control
);
buildPoint
->
addInstruction
(
merge
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
merge
)
);
}
}
void
Builder
::
createConditionalBranch
(
Id
condition
,
Block
*
thenBlock
,
Block
*
elseBlock
)
void
Builder
::
createConditionalBranch
(
Id
condition
,
Block
*
thenBlock
,
Block
*
elseBlock
)
...
@@ -2230,12 +2232,12 @@ void Builder::createConditionalBranch(Id condition, Block* thenBlock, Block* els
...
@@ -2230,12 +2232,12 @@ void Builder::createConditionalBranch(Id condition, Block* thenBlock, Block* els
branch
->
addIdOperand
(
condition
);
branch
->
addIdOperand
(
condition
);
branch
->
addIdOperand
(
thenBlock
->
getId
());
branch
->
addIdOperand
(
thenBlock
->
getId
());
branch
->
addIdOperand
(
elseBlock
->
getId
());
branch
->
addIdOperand
(
elseBlock
->
getId
());
buildPoint
->
addInstruction
(
branch
);
buildPoint
->
addInstruction
(
std
::
unique_ptr
<
Instruction
>
(
branch
)
);
thenBlock
->
addPredecessor
(
buildPoint
);
thenBlock
->
addPredecessor
(
buildPoint
);
elseBlock
->
addPredecessor
(
buildPoint
);
elseBlock
->
addPredecessor
(
buildPoint
);
}
}
void
Builder
::
dumpInstructions
(
std
::
vector
<
unsigned
int
>&
out
,
const
std
::
vector
<
Instruction
*
>&
instructions
)
const
void
Builder
::
dumpInstructions
(
std
::
vector
<
unsigned
int
>&
out
,
const
std
::
vector
<
std
::
unique_ptr
<
Instruction
>
>&
instructions
)
const
{
{
for
(
int
i
=
0
;
i
<
(
int
)
instructions
.
size
();
++
i
)
{
for
(
int
i
=
0
;
i
<
(
int
)
instructions
.
size
();
++
i
)
{
instructions
[
i
]
->
dump
(
out
);
instructions
[
i
]
->
dump
(
out
);
...
...
SPIRV/SpvBuilder.h
View file @
b7946d16
...
@@ -52,6 +52,7 @@
...
@@ -52,6 +52,7 @@
#include "spvIR.h"
#include "spvIR.h"
#include <algorithm>
#include <algorithm>
#include <memory>
#include <stack>
#include <stack>
#include <map>
#include <map>
...
@@ -201,11 +202,13 @@ public:
...
@@ -201,11 +202,13 @@ public:
void
setBuildPoint
(
Block
*
bp
)
{
buildPoint
=
bp
;
}
void
setBuildPoint
(
Block
*
bp
)
{
buildPoint
=
bp
;
}
Block
*
getBuildPoint
()
const
{
return
buildPoint
;
}
Block
*
getBuildPoint
()
const
{
return
buildPoint
;
}
// Make the main function.
// Make the main function. The returned pointer is only valid
// for the lifetime of this builder.
Function
*
makeMain
();
Function
*
makeMain
();
// Make a shader-style function, and create its entry block if entry is non-zero.
// Make a shader-style function, and create its entry block if entry is non-zero.
// Return the function, pass back the entry.
// Return the function, pass back the entry.
// The returned pointer is only valid for the lifetime of this builder.
Function
*
makeFunctionEntry
(
Id
returnType
,
const
char
*
name
,
std
::
vector
<
Id
>&
paramTypes
,
Block
**
entry
=
0
);
Function
*
makeFunctionEntry
(
Id
returnType
,
const
char
*
name
,
std
::
vector
<
Id
>&
paramTypes
,
Block
**
entry
=
0
);
// Create a return. An 'implicit' return is one not appearing in the source
// Create a return. An 'implicit' return is one not appearing in the source
...
@@ -516,7 +519,7 @@ protected:
...
@@ -516,7 +519,7 @@ protected:
void
createSelectionMerge
(
Block
*
mergeBlock
,
unsigned
int
control
);
void
createSelectionMerge
(
Block
*
mergeBlock
,
unsigned
int
control
);
void
createLoopMerge
(
Block
*
mergeBlock
,
Block
*
continueBlock
,
unsigned
int
control
);
void
createLoopMerge
(
Block
*
mergeBlock
,
Block
*
continueBlock
,
unsigned
int
control
);
void
createConditionalBranch
(
Id
condition
,
Block
*
thenBlock
,
Block
*
elseBlock
);
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
<
std
::
unique_ptr
<
Instruction
>
>&
)
const
;
struct
Loop
;
// Defined below.
struct
Loop
;
// Defined below.
void
createBranchToLoopHeaderFromInside
(
const
Loop
&
loop
);
void
createBranchToLoopHeaderFromInside
(
const
Loop
&
loop
);
...
@@ -535,14 +538,15 @@ protected:
...
@@ -535,14 +538,15 @@ protected:
AccessChain
accessChain
;
AccessChain
accessChain
;
// special blocks of instructions for output
// special blocks of instructions for output
std
::
vector
<
Instruction
*>
imports
;
std
::
vector
<
std
::
unique_ptr
<
Instruction
>
>
imports
;
std
::
vector
<
Instruction
*>
entryPoints
;
std
::
vector
<
std
::
unique_ptr
<
Instruction
>
>
entryPoints
;
std
::
vector
<
Instruction
*>
executionModes
;
std
::
vector
<
std
::
unique_ptr
<
Instruction
>
>
executionModes
;
std
::
vector
<
Instruction
*>
names
;
std
::
vector
<
std
::
unique_ptr
<
Instruction
>
>
names
;
std
::
vector
<
Instruction
*>
lines
;
std
::
vector
<
std
::
unique_ptr
<
Instruction
>
>
lines
;
std
::
vector
<
Instruction
*>
decorations
;
std
::
vector
<
std
::
unique_ptr
<
Instruction
>
>
decorations
;
std
::
vector
<
Instruction
*>
constantsTypesGlobals
;
std
::
vector
<
std
::
unique_ptr
<
Instruction
>
>
constantsTypesGlobals
;
std
::
vector
<
Instruction
*>
externals
;
std
::
vector
<
std
::
unique_ptr
<
Instruction
>
>
externals
;
std
::
vector
<
std
::
unique_ptr
<
Function
>
>
functions
;
// not output, internally used for quick & dirty canonical (unique) creation
// not output, internally used for quick & dirty canonical (unique) creation
std
::
vector
<
Instruction
*>
groupedConstants
[
OpConstant
];
// all types appear before OpConstant
std
::
vector
<
Instruction
*>
groupedConstants
[
OpConstant
];
// all types appear before OpConstant
...
...
SPIRV/spvIR.h
View file @
b7946d16
...
@@ -54,6 +54,7 @@
...
@@ -54,6 +54,7 @@
#include <vector>
#include <vector>
#include <iostream>
#include <iostream>
#include <memory>
#include <assert.h>
#include <assert.h>
namespace
spv
{
namespace
spv
{
...
@@ -155,15 +156,14 @@ public:
...
@@ -155,15 +156,14 @@ public:
Block
(
Id
id
,
Function
&
parent
);
Block
(
Id
id
,
Function
&
parent
);
virtual
~
Block
()
virtual
~
Block
()
{
{
// TODO: free instructions
}
}
Id
getId
()
{
return
instructions
.
front
()
->
getResultId
();
}
Id
getId
()
{
return
instructions
.
front
()
->
getResultId
();
}
Function
&
getParent
()
const
{
return
parent
;
}
Function
&
getParent
()
const
{
return
parent
;
}
void
addInstruction
(
Instruction
*
inst
);
void
addInstruction
(
std
::
unique_ptr
<
Instruction
>
inst
);
void
addPredecessor
(
Block
*
pred
)
{
predecessors
.
push_back
(
pred
);
}
void
addPredecessor
(
Block
*
pred
)
{
predecessors
.
push_back
(
pred
);
}
void
addLocalVariable
(
Instruction
*
inst
)
{
localVariables
.
push_back
(
inst
);
}
void
addLocalVariable
(
std
::
unique_ptr
<
Instruction
>
inst
)
{
localVariables
.
push_back
(
std
::
move
(
inst
)
);
}
int
getNumPredecessors
()
const
{
return
(
int
)
predecessors
.
size
();
}
int
getNumPredecessors
()
const
{
return
(
int
)
predecessors
.
size
();
}
void
setUnreachable
()
{
unreachable
=
true
;
}
void
setUnreachable
()
{
unreachable
=
true
;
}
bool
isUnreachable
()
const
{
return
unreachable
;
}
bool
isUnreachable
()
const
{
return
unreachable
;
}
...
@@ -205,9 +205,9 @@ protected:
...
@@ -205,9 +205,9 @@ protected:
// To enforce keeping parent and ownership in sync:
// To enforce keeping parent and ownership in sync:
friend
Function
;
friend
Function
;
std
::
vector
<
Instruction
*
>
instructions
;
std
::
vector
<
std
::
unique_ptr
<
Instruction
>
>
instructions
;
std
::
vector
<
Block
*>
predecessors
;
std
::
vector
<
Block
*>
predecessors
;
std
::
vector
<
Instruction
*
>
localVariables
;
std
::
vector
<
std
::
unique_ptr
<
Instruction
>
>
localVariables
;
Function
&
parent
;
Function
&
parent
;
// track whether this block is known to be uncreachable (not necessarily
// track whether this block is known to be uncreachable (not necessarily
...
@@ -240,7 +240,7 @@ public:
...
@@ -240,7 +240,7 @@ public:
Module
&
getParent
()
const
{
return
parent
;
}
Module
&
getParent
()
const
{
return
parent
;
}
Block
*
getEntryBlock
()
const
{
return
blocks
.
front
();
}
Block
*
getEntryBlock
()
const
{
return
blocks
.
front
();
}
Block
*
getLastBlock
()
const
{
return
blocks
.
back
();
}
Block
*
getLastBlock
()
const
{
return
blocks
.
back
();
}
void
addLocalVariable
(
Instruction
*
inst
);
void
addLocalVariable
(
std
::
unique_ptr
<
Instruction
>
inst
);
Id
getReturnType
()
const
{
return
functionInstruction
.
getTypeId
();
}
Id
getReturnType
()
const
{
return
functionInstruction
.
getTypeId
();
}
void
dump
(
std
::
vector
<
unsigned
int
>&
out
)
const
void
dump
(
std
::
vector
<
unsigned
int
>&
out
)
const
{
{
...
@@ -341,22 +341,24 @@ __inline Function::Function(Id id, Id resultType, Id functionType, Id firstParam
...
@@ -341,22 +341,24 @@ __inline Function::Function(Id id, Id resultType, Id functionType, Id firstParam
}
}
}
}
__inline
void
Function
::
addLocalVariable
(
Instruction
*
inst
)
__inline
void
Function
::
addLocalVariable
(
std
::
unique_ptr
<
Instruction
>
inst
)
{
{
blocks
[
0
]
->
addLocalVariable
(
inst
);
Instruction
*
raw_instruction
=
inst
.
get
();
parent
.
mapInstruction
(
inst
);
blocks
[
0
]
->
addLocalVariable
(
std
::
move
(
inst
));
parent
.
mapInstruction
(
raw_instruction
);
}
}
__inline
Block
::
Block
(
Id
id
,
Function
&
parent
)
:
parent
(
parent
),
unreachable
(
false
)
__inline
Block
::
Block
(
Id
id
,
Function
&
parent
)
:
parent
(
parent
),
unreachable
(
false
)
{
{
instructions
.
push_back
(
new
Instruction
(
id
,
NoType
,
OpLabel
));
instructions
.
push_back
(
std
::
unique_ptr
<
Instruction
>
(
new
Instruction
(
id
,
NoType
,
OpLabel
)
));
}
}
__inline
void
Block
::
addInstruction
(
Instruction
*
inst
)
__inline
void
Block
::
addInstruction
(
std
::
unique_ptr
<
Instruction
>
inst
)
{
{
instructions
.
push_back
(
inst
);
Instruction
*
raw_instruction
=
inst
.
get
();
if
(
inst
->
getResultId
())
instructions
.
push_back
(
std
::
move
(
inst
));
parent
.
getParent
().
mapInstruction
(
inst
);
if
(
raw_instruction
->
getResultId
())
parent
.
getParent
().
mapInstruction
(
raw_instruction
);
}
}
};
// end spv namespace
};
// end spv namespace
...
...
glslang/Include/intermediate.h
View file @
b7946d16
...
@@ -784,7 +784,9 @@ class TIntermAggregate : public TIntermOperator {
...
@@ -784,7 +784,9 @@ class TIntermAggregate : public TIntermOperator {
public
:
public
:
TIntermAggregate
()
:
TIntermOperator
(
EOpNull
),
userDefined
(
false
),
pragmaTable
(
0
)
{
}
TIntermAggregate
()
:
TIntermOperator
(
EOpNull
),
userDefined
(
false
),
pragmaTable
(
0
)
{
}
TIntermAggregate
(
TOperator
o
)
:
TIntermOperator
(
o
),
pragmaTable
(
0
)
{
}
TIntermAggregate
(
TOperator
o
)
:
TIntermOperator
(
o
),
pragmaTable
(
0
)
{
}
~
TIntermAggregate
()
{
delete
pragmaTable
;
}
// Since pragmaTable is allocated with the PoolAllocator, we
// only want to destroy it, not free the associated memory.
~
TIntermAggregate
()
{
pragmaTable
->~
TPragmaTable
();
}
virtual
TIntermAggregate
*
getAsAggregate
()
{
return
this
;
}
virtual
TIntermAggregate
*
getAsAggregate
()
{
return
this
;
}
virtual
const
TIntermAggregate
*
getAsAggregate
()
const
{
return
this
;
}
virtual
const
TIntermAggregate
*
getAsAggregate
()
const
{
return
this
;
}
virtual
void
setOperator
(
TOperator
o
)
{
op
=
o
;
}
virtual
void
setOperator
(
TOperator
o
)
{
op
=
o
;
}
...
...
glslang/MachineIndependent/Intermediate.cpp
View file @
b7946d16
...
@@ -1613,7 +1613,13 @@ TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermC
...
@@ -1613,7 +1613,13 @@ TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermC
void
TIntermAggregate
::
addToPragmaTable
(
const
TPragmaTable
&
pTable
)
void
TIntermAggregate
::
addToPragmaTable
(
const
TPragmaTable
&
pTable
)
{
{
assert
(
!
pragmaTable
);
assert
(
!
pragmaTable
);
pragmaTable
=
new
TPragmaTable
();
// We allocate this with the thread-pool allocator because the destructors
// for TIntermNode's are never called. When TIntermNodes are no longer
// needed, the pool allocator destroys all memory at once without
// destruction.
void
*
memory
=
GetThreadPoolAllocator
().
allocate
(
sizeof
(
TPragmaTable
));
pragmaTable
=
new
(
memory
)
TPragmaTable
();
*
pragmaTable
=
pTable
;
*
pragmaTable
=
pTable
;
}
}
...
...
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