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
da39733f
Commit
da39733f
authored
Mar 09, 2016
by
qining
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove decoration of undefined IDs
Fix issue #185 by removing OpDecorate instructions whose target IDs are defined in unreachable blocks and thus not dumped in the generated SPIR-V code.
parent
f7497e28
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
0 deletions
+38
-0
GlslangToSpv.cpp
SPIRV/GlslangToSpv.cpp
+1
-0
SpvBuilder.cpp
SPIRV/SpvBuilder.cpp
+29
-0
SpvBuilder.h
SPIRV/SpvBuilder.h
+3
-0
spvIR.h
SPIRV/spvIR.h
+5
-0
No files found.
SPIRV/GlslangToSpv.cpp
View file @
da39733f
...
...
@@ -719,6 +719,7 @@ void TGlslangToSpvTraverser::dumpSpv(std::vector<unsigned int>& out)
for
(
auto
it
=
iOSet
.
cbegin
();
it
!=
iOSet
.
cend
();
++
it
)
entryPoint
->
addIdOperand
(
*
it
);
builder
.
eliminateDeadDecorations
();
builder
.
dump
(
out
);
}
...
...
SPIRV/SpvBuilder.cpp
View file @
da39733f
...
...
@@ -2130,6 +2130,35 @@ Id Builder::accessChainGetInferredType()
return
type
;
}
// comment in header
void
Builder
::
eliminateDeadDecorations
()
{
std
::
unordered_set
<
const
Block
*>
reachable_blocks
;
std
::
unordered_set
<
Id
>
unreachable_definitions
;
// Collect IDs defined in unreachable blocks. For each function, label the
// reachable blocks first. Then for each unreachable block, collect the
// result IDs of the instructions in it.
for
(
auto
&
f
:
module
.
getFunctions
())
{
Block
*
entry
=
f
->
getEntryBlock
();
inReadableOrder
(
entry
,
[
&
reachable_blocks
](
const
Block
*
b
)
{
reachable_blocks
.
insert
(
b
);
});
for
(
auto
&
b
:
f
->
getBlocks
())
{
if
(
!
reachable_blocks
.
count
(
b
))
{
for
(
auto
&
i
:
b
->
getInstructions
())
{
unreachable_definitions
.
insert
(
i
->
getResultId
());
}
}
}
}
decorations
.
erase
(
std
::
remove_if
(
decorations
.
begin
(),
decorations
.
end
(),
[
&
unreachable_definitions
](
std
::
unique_ptr
<
Instruction
>&
I
)
{
Instruction
*
inst
=
I
.
get
();
Id
decoration_id
=
inst
->
getIdOperand
(
0
);
return
unreachable_definitions
.
count
(
decoration_id
)
!=
0
;
}),
decorations
.
end
());
}
void
Builder
::
dump
(
std
::
vector
<
unsigned
int
>&
out
)
const
{
// Header, before first instructions:
...
...
SPIRV/SpvBuilder.h
View file @
da39733f
...
...
@@ -512,6 +512,9 @@ public:
// based on the type of the base and the chain of dereferences.
Id
accessChainGetInferredType
();
// Remove OpDecorate instructions whose operands are defined in unreachable
// blocks.
void
eliminateDeadDecorations
();
void
dump
(
std
::
vector
<
unsigned
int
>&
)
const
;
void
createBranch
(
Block
*
block
);
...
...
SPIRV/spvIR.h
View file @
da39733f
...
...
@@ -182,6 +182,9 @@ public:
void
addLocalVariable
(
std
::
unique_ptr
<
Instruction
>
inst
)
{
localVariables
.
push_back
(
std
::
move
(
inst
));
}
const
std
::
vector
<
Block
*>&
getPredecessors
()
const
{
return
predecessors
;
}
const
std
::
vector
<
Block
*>&
getSuccessors
()
const
{
return
successors
;
}
const
std
::
vector
<
std
::
unique_ptr
<
Instruction
>
>&
getInstructions
()
const
{
return
instructions
;
}
void
setUnreachable
()
{
unreachable
=
true
;
}
bool
isUnreachable
()
const
{
return
unreachable
;
}
// Returns the block's merge instruction, if one exists (otherwise null).
...
...
@@ -275,6 +278,7 @@ public:
Module
&
getParent
()
const
{
return
parent
;
}
Block
*
getEntryBlock
()
const
{
return
blocks
.
front
();
}
Block
*
getLastBlock
()
const
{
return
blocks
.
back
();
}
const
std
::
vector
<
Block
*>&
getBlocks
()
const
{
return
blocks
;
}
void
addLocalVariable
(
std
::
unique_ptr
<
Instruction
>
inst
);
Id
getReturnType
()
const
{
return
functionInstruction
.
getTypeId
();
}
void
dump
(
std
::
vector
<
unsigned
int
>&
out
)
const
...
...
@@ -326,6 +330,7 @@ public:
}
Instruction
*
getInstruction
(
Id
id
)
const
{
return
idToInstruction
[
id
];
}
const
std
::
vector
<
Function
*>&
getFunctions
()
const
{
return
functions
;
}
spv
::
Id
getTypeId
(
Id
resultId
)
const
{
return
idToInstruction
[
resultId
]
->
getTypeId
();
}
StorageClass
getStorageClass
(
Id
typeId
)
const
{
...
...
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