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
5022d681
Commit
5022d681
authored
Jun 08, 2016
by
John Kessenich
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #333 from dneto0/defer-capabilities-for-some-struct-members-until-used
SPV: Defer capability decl for ClipDistance, CullDistance, PointSize until…
parents
95d85ce0
a901ffed
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
25 deletions
+47
-25
GlslangToSpv.cpp
SPIRV/GlslangToSpv.cpp
+46
-24
spv.430.vert.out
Test/baseResults/spv.430.vert.out
+1
-0
spv.precise.tese.out
Test/baseResults/spv.precise.tese.out
+0
-1
No files found.
SPIRV/GlslangToSpv.cpp
View file @
5022d681
...
@@ -109,7 +109,7 @@ public:
...
@@ -109,7 +109,7 @@ public:
protected
:
protected
:
spv
::
Decoration
TranslateAuxiliaryStorageDecoration
(
const
glslang
::
TQualifier
&
qualifier
);
spv
::
Decoration
TranslateAuxiliaryStorageDecoration
(
const
glslang
::
TQualifier
&
qualifier
);
spv
::
BuiltIn
TranslateBuiltInDecoration
(
glslang
::
TBuiltInVariable
,
bool
member
);
spv
::
BuiltIn
TranslateBuiltInDecoration
(
glslang
::
TBuiltInVariable
,
bool
member
Declaration
);
spv
::
ImageFormat
TranslateImageFormat
(
const
glslang
::
TType
&
type
);
spv
::
ImageFormat
TranslateImageFormat
(
const
glslang
::
TType
&
type
);
spv
::
Id
createSpvVariable
(
const
glslang
::
TIntermSymbol
*
);
spv
::
Id
createSpvVariable
(
const
glslang
::
TIntermSymbol
*
);
spv
::
Id
getSampledType
(
const
glslang
::
TSampler
&
);
spv
::
Id
getSampledType
(
const
glslang
::
TSampler
&
);
...
@@ -122,7 +122,7 @@ protected:
...
@@ -122,7 +122,7 @@ protected:
int
getArrayStride
(
const
glslang
::
TType
&
arrayType
,
glslang
::
TLayoutPacking
,
glslang
::
TLayoutMatrix
);
int
getArrayStride
(
const
glslang
::
TType
&
arrayType
,
glslang
::
TLayoutPacking
,
glslang
::
TLayoutMatrix
);
int
getMatrixStride
(
const
glslang
::
TType
&
matrixType
,
glslang
::
TLayoutPacking
,
glslang
::
TLayoutMatrix
);
int
getMatrixStride
(
const
glslang
::
TType
&
matrixType
,
glslang
::
TLayoutPacking
,
glslang
::
TLayoutMatrix
);
void
updateMemberOffset
(
const
glslang
::
TType
&
structType
,
const
glslang
::
TType
&
memberType
,
int
&
currentOffset
,
int
&
nextOffset
,
glslang
::
TLayoutPacking
,
glslang
::
TLayoutMatrix
);
void
updateMemberOffset
(
const
glslang
::
TType
&
structType
,
const
glslang
::
TType
&
memberType
,
int
&
currentOffset
,
int
&
nextOffset
,
glslang
::
TLayoutPacking
,
glslang
::
TLayoutMatrix
);
void
declare
ClipCullCapability
(
const
glslang
::
TTypeList
&
members
,
int
m
ember
);
void
declare
UseOfStructMember
(
const
glslang
::
TTypeList
&
members
,
int
glslangM
ember
);
bool
isShaderEntrypoint
(
const
glslang
::
TIntermAggregate
*
node
);
bool
isShaderEntrypoint
(
const
glslang
::
TIntermAggregate
*
node
);
void
makeFunctions
(
const
glslang
::
TIntermSequence
&
);
void
makeFunctions
(
const
glslang
::
TIntermSequence
&
);
...
@@ -401,11 +401,17 @@ spv::Decoration TranslateNoContractionDecoration(const glslang::TQualifier& qual
...
@@ -401,11 +401,17 @@ spv::Decoration TranslateNoContractionDecoration(const glslang::TQualifier& qual
return
(
spv
::
Decoration
)
spv
::
BadValue
;
return
(
spv
::
Decoration
)
spv
::
BadValue
;
}
}
// Translate glslang built-in variable to SPIR-V built in decoration.
// Translate a glslang built-in variable to a SPIR-V built in decoration. Also generate
spv
::
BuiltIn
TGlslangToSpvTraverser
::
TranslateBuiltInDecoration
(
glslang
::
TBuiltInVariable
builtIn
,
bool
member
)
// associated capabilities when required. For some built-in variables, a capability
// is generated only when using the variable in an executable instruction, but not when
// just declaring a struct member variable with it. This is true for PointSize,
// ClipDistance, and CullDistance.
spv
::
BuiltIn
TGlslangToSpvTraverser
::
TranslateBuiltInDecoration
(
glslang
::
TBuiltInVariable
builtIn
,
bool
memberDeclaration
)
{
{
switch
(
builtIn
)
{
switch
(
builtIn
)
{
case
glslang
:
:
EbvPointSize
:
case
glslang
:
:
EbvPointSize
:
// Defer adding the capability until the built-in is actually used.
if
(
!
memberDeclaration
)
{
switch
(
glslangIntermediate
->
getStage
())
{
switch
(
glslangIntermediate
->
getStage
())
{
case
EShLangGeometry
:
case
EShLangGeometry
:
builder
.
addCapability
(
spv
::
CapabilityGeometryPointSize
);
builder
.
addCapability
(
spv
::
CapabilityGeometryPointSize
);
...
@@ -417,6 +423,7 @@ spv::BuiltIn TGlslangToSpvTraverser::TranslateBuiltInDecoration(glslang::TBuiltI
...
@@ -417,6 +423,7 @@ spv::BuiltIn TGlslangToSpvTraverser::TranslateBuiltInDecoration(glslang::TBuiltI
default
:
default
:
break
;
break
;
}
}
}
return
spv
::
BuiltInPointSize
;
return
spv
::
BuiltInPointSize
;
// These *Distance capabilities logically belong here, but if the member is declared and
// These *Distance capabilities logically belong here, but if the member is declared and
...
@@ -426,12 +433,12 @@ spv::BuiltIn TGlslangToSpvTraverser::TranslateBuiltInDecoration(glslang::TBuiltI
...
@@ -426,12 +433,12 @@ spv::BuiltIn TGlslangToSpvTraverser::TranslateBuiltInDecoration(glslang::TBuiltI
// use needed is to trigger the capability.
// use needed is to trigger the capability.
//
//
case
glslang
:
:
EbvClipDistance
:
case
glslang
:
:
EbvClipDistance
:
if
(
!
member
)
if
(
!
memberDeclaration
)
builder
.
addCapability
(
spv
::
CapabilityClipDistance
);
builder
.
addCapability
(
spv
::
CapabilityClipDistance
);
return
spv
::
BuiltInClipDistance
;
return
spv
::
BuiltInClipDistance
;
case
glslang
:
:
EbvCullDistance
:
case
glslang
:
:
EbvCullDistance
:
if
(
!
member
)
if
(
!
memberDeclaration
)
builder
.
addCapability
(
spv
::
CapabilityCullDistance
);
builder
.
addCapability
(
spv
::
CapabilityCullDistance
);
return
spv
::
BuiltInCullDistance
;
return
spv
::
BuiltInCullDistance
;
...
@@ -923,30 +930,34 @@ bool TGlslangToSpvTraverser::visitBinary(glslang::TVisit /* visit */, glslang::T
...
@@ -923,30 +930,34 @@ bool TGlslangToSpvTraverser::visitBinary(glslang::TVisit /* visit */, glslang::T
// Add the next element in the chain
// Add the next element in the chain
int
index
=
node
->
getRight
()
->
getAsConstantUnion
()
->
getConstArray
()[
0
].
getIConst
();
const
int
glslangIndex
=
node
->
getRight
()
->
getAsConstantUnion
()
->
getConstArray
()[
0
].
getIConst
();
if
(
node
->
getLeft
()
->
getBasicType
()
==
glslang
::
EbtBlock
&&
node
->
getOp
()
==
glslang
::
EOpIndexDirectStruct
)
{
// This may be, e.g., an anonymous block-member selection, which generally need
// index remapping due to hidden members in anonymous blocks.
std
::
vector
<
int
>&
remapper
=
memberRemapper
[
node
->
getLeft
()
->
getType
().
getStruct
()];
assert
(
remapper
.
size
()
>
0
);
index
=
remapper
[
index
];
}
if
(
!
node
->
getLeft
()
->
getType
().
isArray
()
&&
if
(
!
node
->
getLeft
()
->
getType
().
isArray
()
&&
node
->
getLeft
()
->
getType
().
isVector
()
&&
node
->
getLeft
()
->
getType
().
isVector
()
&&
node
->
getOp
()
==
glslang
::
EOpIndexDirect
)
{
node
->
getOp
()
==
glslang
::
EOpIndexDirect
)
{
// This is essentially a hard-coded vector swizzle of size 1,
// This is essentially a hard-coded vector swizzle of size 1,
// so short circuit the access-chain stuff with a swizzle.
// so short circuit the access-chain stuff with a swizzle.
std
::
vector
<
unsigned
>
swizzle
;
std
::
vector
<
unsigned
>
swizzle
;
swizzle
.
push_back
(
node
->
getRight
()
->
getAsConstantUnion
()
->
getConstArray
()[
0
].
getIConst
()
);
swizzle
.
push_back
(
glslangIndex
);
builder
.
accessChainPushSwizzle
(
swizzle
,
convertGlslangToSpvType
(
node
->
getLeft
()
->
getType
()));
builder
.
accessChainPushSwizzle
(
swizzle
,
convertGlslangToSpvType
(
node
->
getLeft
()
->
getType
()));
}
else
{
}
else
{
int
spvIndex
=
glslangIndex
;
if
(
node
->
getLeft
()
->
getBasicType
()
==
glslang
::
EbtBlock
&&
node
->
getOp
()
==
glslang
::
EOpIndexDirectStruct
)
{
// This may be, e.g., an anonymous block-member selection, which generally need
// index remapping due to hidden members in anonymous blocks.
std
::
vector
<
int
>&
remapper
=
memberRemapper
[
node
->
getLeft
()
->
getType
().
getStruct
()];
assert
(
remapper
.
size
()
>
0
);
spvIndex
=
remapper
[
glslangIndex
];
}
// normal case for indexing array or structure or block
// normal case for indexing array or structure or block
builder
.
accessChainPush
(
builder
.
makeIntConstant
(
i
ndex
));
builder
.
accessChainPush
(
builder
.
makeIntConstant
(
spvI
ndex
));
// Add capabilities here for accessing clip/cull distance
// Add capabilities here for accessing PointSize and clip/cull distance.
// We have deferred generation of associated capabilities until now.
if
(
node
->
getLeft
()
->
getType
().
isStruct
()
&&
!
node
->
getLeft
()
->
getType
().
isArray
())
if
(
node
->
getLeft
()
->
getType
().
isStruct
()
&&
!
node
->
getLeft
()
->
getType
().
isArray
())
declare
ClipCullCapability
(
*
node
->
getLeft
()
->
getType
().
getStruct
(),
i
ndex
);
declare
UseOfStructMember
(
*
(
node
->
getLeft
()
->
getType
().
getStruct
()),
glslangI
ndex
);
}
}
}
}
return
false
;
return
false
;
...
@@ -2203,12 +2214,23 @@ void TGlslangToSpvTraverser::updateMemberOffset(const glslang::TType& /*structTy
...
@@ -2203,12 +2214,23 @@ void TGlslangToSpvTraverser::updateMemberOffset(const glslang::TType& /*structTy
nextOffset
=
currentOffset
+
memberSize
;
nextOffset
=
currentOffset
+
memberSize
;
}
}
void
TGlslangToSpvTraverser
::
declare
ClipCullCapability
(
const
glslang
::
TTypeList
&
members
,
int
m
ember
)
void
TGlslangToSpvTraverser
::
declare
UseOfStructMember
(
const
glslang
::
TTypeList
&
members
,
int
glslangM
ember
)
{
{
if
(
members
[
member
].
type
->
getQualifier
().
builtIn
==
glslang
::
EbvClipDistance
)
const
glslang
::
TBuiltInVariable
glslangBuiltIn
=
members
[
glslangMember
].
type
->
getQualifier
().
builtIn
;
builder
.
addCapability
(
spv
::
CapabilityClipDistance
);
switch
(
glslangBuiltIn
)
if
(
members
[
member
].
type
->
getQualifier
().
builtIn
==
glslang
::
EbvCullDistance
)
{
builder
.
addCapability
(
spv
::
CapabilityCullDistance
);
case
glslang
:
:
EbvClipDistance
:
case
glslang
:
:
EbvCullDistance
:
case
glslang
:
:
EbvPointSize
:
// Generate the associated capability. Delegate to TranslateBuiltInDecoration.
// Alternately, we could just call this for any glslang built-in, since the
// capability already guards against duplicates.
TranslateBuiltInDecoration
(
glslangBuiltIn
,
false
);
break
;
default
:
// Capabilities were already generated when the struct was declared.
break
;
}
}
}
bool
TGlslangToSpvTraverser
::
isShaderEntrypoint
(
const
glslang
::
TIntermAggregate
*
node
)
bool
TGlslangToSpvTraverser
::
isShaderEntrypoint
(
const
glslang
::
TIntermAggregate
*
node
)
...
...
Test/baseResults/spv.430.vert.out
View file @
5022d681
...
@@ -10,6 +10,7 @@ Linked vertex stage:
...
@@ -10,6 +10,7 @@ Linked vertex stage:
// Id's are bound by 66
// Id's are bound by 66
Capability Shader
Capability Shader
Capability ClipDistance
1: ExtInstImport "GLSL.std.450"
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
MemoryModel Logical GLSL450
EntryPoint Vertex 4 "main" 12 23 34 38 41 42 62 65
EntryPoint Vertex 4 "main" 12 23 34 38 41 42 62 65
...
...
Test/baseResults/spv.precise.tese.out
View file @
5022d681
...
@@ -10,7 +10,6 @@ Linked tessellation evaluation stage:
...
@@ -10,7 +10,6 @@ Linked tessellation evaluation stage:
// Id's are bound by 119
// Id's are bound by 119
Capability Tessellation
Capability Tessellation
Capability TessellationPointSize
1: ExtInstImport "GLSL.std.450"
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
MemoryModel Logical GLSL450
EntryPoint TessellationEvaluation 4 "main" 12 21 62 112
EntryPoint TessellationEvaluation 4 "main" 12 21 62 112
...
...
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