Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
angle
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
angle
Commits
41159326
Commit
41159326
authored
Aug 22, 2013
by
Zhenyao Mo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add static_use to shader variable info query.
BUG=249018 ANGLEBUG=465 R=kbr@chromium.org Review URL:
https://codereview.appspot.com/13158043
parent
827fb6ad
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
131 additions
and
66 deletions
+131
-66
ShaderLang.h
include/GLSLANG/ShaderLang.h
+6
-1
version.h
src/common/version.h
+1
-1
Compiler.cpp
src/compiler/Compiler.cpp
+1
-0
ShaderLang.cpp
src/compiler/ShaderLang.cpp
+3
-1
VariableInfo.cpp
src/compiler/VariableInfo.cpp
+115
-57
VariableInfo.h
src/compiler/VariableInfo.h
+5
-6
No files found.
include/GLSLANG/ShaderLang.h
View file @
41159326
...
@@ -37,7 +37,7 @@ extern "C" {
...
@@ -37,7 +37,7 @@ extern "C" {
// Version number for shader translation API.
// Version number for shader translation API.
// It is incremented everytime the API changes.
// It is incremented everytime the API changes.
#define ANGLE_SH_VERSION 11
1
#define ANGLE_SH_VERSION 11
2
//
//
// The names of the following enums have been derived by replacing GL prefix
// The names of the following enums have been derived by replacing GL prefix
...
@@ -378,6 +378,10 @@ COMPILER_EXPORT void ShGetObjectCode(const ShHandle handle, char* objCode);
...
@@ -378,6 +378,10 @@ COMPILER_EXPORT void ShGetObjectCode(const ShHandle handle, char* objCode);
// size: Returns the size of the variable.
// size: Returns the size of the variable.
// type: Returns the data type of the variable.
// type: Returns the data type of the variable.
// precision: Returns the precision of the variable.
// precision: Returns the precision of the variable.
// staticUse: Returns 1 if the variable is accessed in a statement after
// pre-processing, whether or not run-time flow of control will
// cause that statement to be executed.
// Returns 0 otherwise.
// name: Returns a null terminated string containing the name of the
// name: Returns a null terminated string containing the name of the
// variable. It is assumed that name has enough memory to accormodate
// variable. It is assumed that name has enough memory to accormodate
// the variable name. The size of the buffer required to store the
// the variable name. The size of the buffer required to store the
...
@@ -396,6 +400,7 @@ COMPILER_EXPORT void ShGetVariableInfo(const ShHandle handle,
...
@@ -396,6 +400,7 @@ COMPILER_EXPORT void ShGetVariableInfo(const ShHandle handle,
int
*
size
,
int
*
size
,
ShDataType
*
type
,
ShDataType
*
type
,
ShPrecisionType
*
precision
,
ShPrecisionType
*
precision
,
int
*
staticUse
,
char
*
name
,
char
*
name
,
char
*
mappedName
);
char
*
mappedName
);
...
...
src/common/version.h
View file @
41159326
#define MAJOR_VERSION 1
#define MAJOR_VERSION 1
#define MINOR_VERSION 2
#define MINOR_VERSION 2
#define BUILD_VERSION 0
#define BUILD_VERSION 0
#define BUILD_REVISION 244
0
#define BUILD_REVISION 244
1
#define STRINGIFY(x) #x
#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)
#define MACRO_STRINGIFY(x) STRINGIFY(x)
...
...
src/compiler/Compiler.cpp
View file @
41159326
...
@@ -271,6 +271,7 @@ void TCompiler::clearResults()
...
@@ -271,6 +271,7 @@ void TCompiler::clearResults()
attribs
.
clear
();
attribs
.
clear
();
uniforms
.
clear
();
uniforms
.
clear
();
varyings
.
clear
();
builtInFunctionEmulator
.
Cleanup
();
builtInFunctionEmulator
.
Cleanup
();
...
...
src/compiler/ShaderLang.cpp
View file @
41159326
...
@@ -248,10 +248,11 @@ void ShGetVariableInfo(const ShHandle handle,
...
@@ -248,10 +248,11 @@ void ShGetVariableInfo(const ShHandle handle,
int
*
size
,
int
*
size
,
ShDataType
*
type
,
ShDataType
*
type
,
ShPrecisionType
*
precision
,
ShPrecisionType
*
precision
,
int
*
staticUse
,
char
*
name
,
char
*
name
,
char
*
mappedName
)
char
*
mappedName
)
{
{
if
(
!
handle
||
!
size
||
!
type
||
!
name
)
if
(
!
handle
||
!
size
||
!
type
||
!
precision
||
!
staticUse
||
!
name
)
return
;
return
;
ASSERT
((
varType
==
SH_ACTIVE_ATTRIBUTES
)
||
ASSERT
((
varType
==
SH_ACTIVE_ATTRIBUTES
)
||
(
varType
==
SH_ACTIVE_UNIFORMS
)
||
(
varType
==
SH_ACTIVE_UNIFORMS
)
||
...
@@ -288,6 +289,7 @@ void ShGetVariableInfo(const ShHandle handle,
...
@@ -288,6 +289,7 @@ void ShGetVariableInfo(const ShHandle handle,
*
precision
=
SH_PRECISION_UNDEFINED
;
*
precision
=
SH_PRECISION_UNDEFINED
;
break
;
break
;
}
}
*
staticUse
=
varInfo
.
staticUse
?
1
:
0
;
// This size must match that queried by
// This size must match that queried by
// SH_ACTIVE_UNIFORM_MAX_LENGTH, SH_ACTIVE_ATTRIBUTE_MAX_LENGTH, SH_VARYING_MAX_LENGTH
// SH_ACTIVE_UNIFORM_MAX_LENGTH, SH_ACTIVE_ATTRIBUTE_MAX_LENGTH, SH_VARYING_MAX_LENGTH
...
...
src/compiler/VariableInfo.cpp
View file @
41159326
...
@@ -6,15 +6,17 @@
...
@@ -6,15 +6,17 @@
#include "compiler/VariableInfo.h"
#include "compiler/VariableInfo.h"
static
TString
arrayBrackets
(
int
index
)
namespace
{
TString
arrayBrackets
(
int
index
)
{
{
TStringStream
stream
;
TStringStream
stream
;
stream
<<
"["
<<
index
<<
"]"
;
stream
<<
"["
<<
index
<<
"]"
;
return
stream
.
str
();
return
stream
.
str
();
}
}
// Returns the data type for an attribute
or uniform
.
// Returns the data type for an attribute
, uniform, or varying
.
static
ShDataType
getVariableDataType
(
const
TType
&
type
)
ShDataType
getVariableDataType
(
const
TType
&
type
)
{
{
switch
(
type
.
getBasicType
())
{
switch
(
type
.
getBasicType
())
{
case
EbtFloat
:
case
EbtFloat
:
...
@@ -70,22 +72,22 @@ static ShDataType getVariableDataType(const TType& type)
...
@@ -70,22 +72,22 @@ static ShDataType getVariableDataType(const TType& type)
return
SH_NONE
;
return
SH_NONE
;
}
}
static
void
getBuiltInVariableInfo
(
const
TType
&
type
,
void
getBuiltInVariableInfo
(
const
TType
&
type
,
const
TString
&
name
,
const
TString
&
mappedName
,
TVariableInfoList
&
infoList
);
static
void
getUserDefinedVariableInfo
(
const
TType
&
type
,
const
TString
&
name
,
const
TString
&
mappedName
,
TVariableInfoList
&
infoList
,
ShHashFunction64
hashFunction
);
// Returns info for an attribute or uniform.
static
void
getVariableInfo
(
const
TType
&
type
,
const
TString
&
name
,
const
TString
&
name
,
const
TString
&
mappedName
,
const
TString
&
mappedName
,
TVariableInfoList
&
infoList
,
TVariableInfoList
&
infoList
);
ShHashFunction64
hashFunction
)
void
getUserDefinedVariableInfo
(
const
TType
&
type
,
const
TString
&
name
,
const
TString
&
mappedName
,
TVariableInfoList
&
infoList
,
ShHashFunction64
hashFunction
);
// Returns info for an attribute, uniform, or varying.
void
getVariableInfo
(
const
TType
&
type
,
const
TString
&
name
,
const
TString
&
mappedName
,
TVariableInfoList
&
infoList
,
ShHashFunction64
hashFunction
)
{
{
if
(
type
.
getBasicType
()
==
EbtStruct
)
{
if
(
type
.
getBasicType
()
==
EbtStruct
)
{
if
(
type
.
isArray
())
{
if
(
type
.
isArray
())
{
...
@@ -144,13 +146,37 @@ void getUserDefinedVariableInfo(const TType& type,
...
@@ -144,13 +146,37 @@ void getUserDefinedVariableInfo(const TType& type,
}
}
}
}
TVariableInfo
*
findVariable
(
const
TType
&
type
,
const
TString
&
name
,
TVariableInfoList
&
infoList
)
{
// TODO(zmo): optimize this function.
TString
myName
=
name
;
if
(
type
.
isArray
())
myName
+=
"[0]"
;
for
(
size_t
ii
=
0
;
ii
<
infoList
.
size
();
++
ii
)
{
if
(
infoList
[
ii
].
name
.
c_str
()
==
myName
)
return
&
(
infoList
[
ii
]);
}
return
NULL
;
}
}
// namespace anonymous
TVariableInfo
::
TVariableInfo
()
TVariableInfo
::
TVariableInfo
()
:
type
(
SH_NONE
),
size
(
0
),
precision
(
EbpUndefined
),
staticUse
(
false
)
{
{
}
}
TVariableInfo
::
TVariableInfo
(
ShDataType
type
,
int
size
)
TVariableInfo
::
TVariableInfo
(
ShDataType
type
,
int
size
)
:
type
(
type
),
:
type
(
type
),
size
(
size
)
size
(
size
),
precision
(
EbpUndefined
),
staticUse
(
false
)
{
{
}
}
...
@@ -161,44 +187,85 @@ CollectVariables::CollectVariables(TVariableInfoList& attribs,
...
@@ -161,44 +187,85 @@ CollectVariables::CollectVariables(TVariableInfoList& attribs,
:
mAttribs
(
attribs
),
:
mAttribs
(
attribs
),
mUniforms
(
uniforms
),
mUniforms
(
uniforms
),
mVaryings
(
varyings
),
mVaryings
(
varyings
),
mPointCoordAdded
(
false
),
mFrontFacingAdded
(
false
),
mFragCoordAdded
(
false
),
mHashFunction
(
hashFunction
)
mHashFunction
(
hashFunction
)
{
{
}
}
// We are only interested in attribute and uniform variable declaration.
// We want to check whether a uniform/varying is statically used
void
CollectVariables
::
visitSymbol
(
TIntermSymbol
*
)
// because we only count the used ones in packing computing.
{
// Also, gl_FragCoord, gl_PointCoord, and gl_FrontFacing count
}
// toward varying counting if they are statically used in a fragment
// shader.
void
CollectVariables
::
visitConstantUnion
(
TIntermConstantUnion
*
)
void
CollectVariables
::
visitSymbol
(
TIntermSymbol
*
symbol
)
{
}
bool
CollectVariables
::
visitBinary
(
Visit
,
TIntermBinary
*
)
{
{
return
false
;
ASSERT
(
symbol
!=
NULL
);
}
TVariableInfo
*
var
=
NULL
;
switch
(
symbol
->
getQualifier
())
bool
CollectVariables
::
visitUnary
(
Visit
,
TIntermUnary
*
)
{
{
case
EvqVaryingOut
:
return
false
;
case
EvqInvariantVaryingOut
:
}
case
EvqVaryingIn
:
case
EvqInvariantVaryingIn
:
bool
CollectVariables
::
visitSelection
(
Visit
,
TIntermSelection
*
)
var
=
findVariable
(
symbol
->
getType
(),
symbol
->
getSymbol
(),
mVaryings
);
{
break
;
return
false
;
case
EvqUniform
:
var
=
findVariable
(
symbol
->
getType
(),
symbol
->
getSymbol
(),
mUniforms
);
break
;
case
EvqFragCoord
:
if
(
!
mFragCoordAdded
)
{
TVariableInfo
info
;
info
.
name
=
"gl_FragCoord"
;
info
.
mappedName
=
"gl_FragCoord"
;
info
.
type
=
SH_FLOAT_VEC4
;
info
.
size
=
1
;
info
.
precision
=
EbpMedium
;
// Use mediump as it doesn't really matter.
info
.
staticUse
=
true
;
mVaryings
.
push_back
(
info
);
mFragCoordAdded
=
true
;
}
return
;
case
EvqFrontFacing
:
if
(
!
mFrontFacingAdded
)
{
TVariableInfo
info
;
info
.
name
=
"gl_FrontFacing"
;
info
.
mappedName
=
"gl_FrontFacing"
;
info
.
type
=
SH_BOOL
;
info
.
size
=
1
;
info
.
precision
=
EbpUndefined
;
info
.
staticUse
=
true
;
mVaryings
.
push_back
(
info
);
mFrontFacingAdded
=
true
;
}
return
;
case
EvqPointCoord
:
if
(
!
mPointCoordAdded
)
{
TVariableInfo
info
;
info
.
name
=
"gl_PointCoord"
;
info
.
mappedName
=
"gl_PointCoord"
;
info
.
type
=
SH_FLOAT_VEC2
;
info
.
size
=
1
;
info
.
precision
=
EbpMedium
;
// Use mediump as it doesn't really matter.
info
.
staticUse
=
true
;
mVaryings
.
push_back
(
info
);
mPointCoordAdded
=
true
;
}
return
;
default
:
break
;
}
if
(
var
)
var
->
staticUse
=
true
;
}
}
bool
CollectVariables
::
visitAggregate
(
Visit
,
TIntermAggregate
*
node
)
bool
CollectVariables
::
visitAggregate
(
Visit
,
TIntermAggregate
*
node
)
{
{
bool
visitChildren
=
fals
e
;
bool
visitChildren
=
tru
e
;
switch
(
node
->
getOp
())
switch
(
node
->
getOp
())
{
{
case
EOpSequence
:
// We need to visit sequence children to get to variable declarations.
visitChildren
=
true
;
break
;
case
EOpDeclaration
:
{
case
EOpDeclaration
:
{
const
TIntermSequence
&
sequence
=
node
->
getSequence
();
const
TIntermSequence
&
sequence
=
node
->
getSequence
();
TQualifier
qualifier
=
sequence
.
front
()
->
getAsTyped
()
->
getQualifier
();
TQualifier
qualifier
=
sequence
.
front
()
->
getAsTyped
()
->
getQualifier
();
...
@@ -214,9 +281,9 @@ bool CollectVariables::visitAggregate(Visit, TIntermAggregate* node)
...
@@ -214,9 +281,9 @@ bool CollectVariables::visitAggregate(Visit, TIntermAggregate* node)
const
TIntermSymbol
*
variable
=
(
*
i
)
->
getAsSymbolNode
();
const
TIntermSymbol
*
variable
=
(
*
i
)
->
getAsSymbolNode
();
// The only case in which the sequence will not contain a
// The only case in which the sequence will not contain a
// TIntermSymbol node is initialization. It will contain a
// TIntermSymbol node is initialization. It will contain a
// TInterBinary node in that case. Since attributes
and unifroms
// TInterBinary node in that case. Since attributes
, uniforms,
//
cannot be initialized in a shader, we must have only
//
and varyings cannot be initialized in a shader, we must have
// TIntermSymbol nodes in the sequence.
//
only
TIntermSymbol nodes in the sequence.
ASSERT
(
variable
!=
NULL
);
ASSERT
(
variable
!=
NULL
);
TString
processedSymbol
;
TString
processedSymbol
;
if
(
mHashFunction
==
NULL
)
if
(
mHashFunction
==
NULL
)
...
@@ -228,6 +295,7 @@ bool CollectVariables::visitAggregate(Visit, TIntermAggregate* node)
...
@@ -228,6 +295,7 @@ bool CollectVariables::visitAggregate(Visit, TIntermAggregate* node)
processedSymbol
,
processedSymbol
,
infoList
,
infoList
,
mHashFunction
);
mHashFunction
);
visitChildren
=
false
;
}
}
}
}
break
;
break
;
...
@@ -238,13 +306,3 @@ bool CollectVariables::visitAggregate(Visit, TIntermAggregate* node)
...
@@ -238,13 +306,3 @@ bool CollectVariables::visitAggregate(Visit, TIntermAggregate* node)
return
visitChildren
;
return
visitChildren
;
}
}
bool
CollectVariables
::
visitLoop
(
Visit
,
TIntermLoop
*
)
{
return
false
;
}
bool
CollectVariables
::
visitBranch
(
Visit
,
TIntermBranch
*
)
{
return
false
;
}
src/compiler/VariableInfo.h
View file @
41159326
...
@@ -21,6 +21,7 @@ struct TVariableInfo {
...
@@ -21,6 +21,7 @@ struct TVariableInfo {
ShDataType
type
;
ShDataType
type
;
int
size
;
int
size
;
TPrecision
precision
;
TPrecision
precision
;
bool
staticUse
;
};
};
typedef
std
::
vector
<
TVariableInfo
>
TVariableInfoList
;
typedef
std
::
vector
<
TVariableInfo
>
TVariableInfoList
;
...
@@ -33,19 +34,17 @@ public:
...
@@ -33,19 +34,17 @@ public:
ShHashFunction64
hashFunction
);
ShHashFunction64
hashFunction
);
virtual
void
visitSymbol
(
TIntermSymbol
*
);
virtual
void
visitSymbol
(
TIntermSymbol
*
);
virtual
void
visitConstantUnion
(
TIntermConstantUnion
*
);
virtual
bool
visitBinary
(
Visit
,
TIntermBinary
*
);
virtual
bool
visitUnary
(
Visit
,
TIntermUnary
*
);
virtual
bool
visitSelection
(
Visit
,
TIntermSelection
*
);
virtual
bool
visitAggregate
(
Visit
,
TIntermAggregate
*
);
virtual
bool
visitAggregate
(
Visit
,
TIntermAggregate
*
);
virtual
bool
visitLoop
(
Visit
,
TIntermLoop
*
);
virtual
bool
visitBranch
(
Visit
,
TIntermBranch
*
);
private
:
private
:
TVariableInfoList
&
mAttribs
;
TVariableInfoList
&
mAttribs
;
TVariableInfoList
&
mUniforms
;
TVariableInfoList
&
mUniforms
;
TVariableInfoList
&
mVaryings
;
TVariableInfoList
&
mVaryings
;
bool
mPointCoordAdded
;
bool
mFrontFacingAdded
;
bool
mFragCoordAdded
;
ShHashFunction64
mHashFunction
;
ShHashFunction64
mHashFunction
;
};
};
...
...
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