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
4678ca9d
Commit
4678ca9d
authored
May 13, 2016
by
John Kessenich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HLSL: Add function call syntax and AST building.
parent
9db3117e
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
83 additions
and
25 deletions
+83
-25
hlsl.frag.out
Test/baseResults/hlsl.frag.out
+58
-11
hlsl.frag
Test/hlsl.frag
+4
-3
hlslGrammar.cpp
hlsl/hlslGrammar.cpp
+13
-6
hlslGrammar.h
hlsl/hlslGrammar.h
+1
-1
hlslParseHelper.cpp
hlsl/hlslParseHelper.cpp
+6
-3
hlslParseHelper.h
hlsl/hlslParseHelper.h
+1
-1
No files found.
Test/baseResults/hlsl.frag.out
View file @
4678ca9d
...
@@ -2,10 +2,27 @@ hlsl.frag
...
@@ -2,10 +2,27 @@ hlsl.frag
Shader version: 100
Shader version: 100
gl_FragCoord origin is upper left
gl_FragCoord origin is upper left
0:? Sequence
0:? Sequence
0:12 Function Definition: PixelShaderFunction(vf4; (temp 4-component vector of float)
0:1 move second child to first child (temp 4-component vector of float)
0:1 'AmbientColor' (temp 4-component vector of float)
0:? Constant:
0:? 1.000000
0:? 0.500000
0:? 0.000000
0:? 1.000000
0:2 move second child to first child (temp float)
0:2 'AmbientIntensity' (temp float)
0:2 Constant:
0:2 0.100000
0:13 Function Definition: PixelShaderFunction(vf4; (temp 4-component vector of float)
0:5 Function Parameters:
0:5 Function Parameters:
0:5 'input' (temp 4-component vector of float)
0:5 'input' (temp 4-component vector of float)
0:? Sequence
0:? Sequence
0:6 Branch: Return with expression
0:6 add (temp 4-component vector of float)
0:6 vector-scale (temp 4-component vector of float)
0:6 'input' (temp 4-component vector of float)
0:6 'AmbientIntensity' (temp float)
0:6 'AmbientColor' (temp 4-component vector of float)
0:7 Branch: Return with expression
0:7 Branch: Return with expression
0:7 add (temp 4-component vector of float)
0:7 add (temp 4-component vector of float)
0:7 component-wise multiply (temp 4-component vector of float)
0:7 component-wise multiply (temp 4-component vector of float)
...
@@ -36,7 +53,12 @@ gl_FragCoord origin is upper left
...
@@ -36,7 +53,12 @@ gl_FragCoord origin is upper left
0:10 'input' (temp 4-component vector of float)
0:10 'input' (temp 4-component vector of float)
0:10 Pre-Increment (temp 4-component vector of float)
0:10 Pre-Increment (temp 4-component vector of float)
0:10 'input' (temp 4-component vector of float)
0:10 'input' (temp 4-component vector of float)
0:11 Branch: Return with expression
0:11 sine (global 4-component vector of float)
0:11 'input' (temp 4-component vector of float)
0:? Linker Objects
0:? Linker Objects
0:? 'AmbientColor' (temp 4-component vector of float)
0:? 'AmbientIntensity' (temp float)
Linked fragment stage:
Linked fragment stage:
...
@@ -45,10 +67,27 @@ Linked fragment stage:
...
@@ -45,10 +67,27 @@ Linked fragment stage:
Shader version: 100
Shader version: 100
gl_FragCoord origin is upper left
gl_FragCoord origin is upper left
0:? Sequence
0:? Sequence
0:12 Function Definition: PixelShaderFunction(vf4; (temp 4-component vector of float)
0:1 move second child to first child (temp 4-component vector of float)
0:1 'AmbientColor' (temp 4-component vector of float)
0:? Constant:
0:? 1.000000
0:? 0.500000
0:? 0.000000
0:? 1.000000
0:2 move second child to first child (temp float)
0:2 'AmbientIntensity' (temp float)
0:2 Constant:
0:2 0.100000
0:13 Function Definition: PixelShaderFunction(vf4; (temp 4-component vector of float)
0:5 Function Parameters:
0:5 Function Parameters:
0:5 'input' (temp 4-component vector of float)
0:5 'input' (temp 4-component vector of float)
0:? Sequence
0:? Sequence
0:6 Branch: Return with expression
0:6 add (temp 4-component vector of float)
0:6 vector-scale (temp 4-component vector of float)
0:6 'input' (temp 4-component vector of float)
0:6 'AmbientIntensity' (temp float)
0:6 'AmbientColor' (temp 4-component vector of float)
0:7 Branch: Return with expression
0:7 Branch: Return with expression
0:7 add (temp 4-component vector of float)
0:7 add (temp 4-component vector of float)
0:7 component-wise multiply (temp 4-component vector of float)
0:7 component-wise multiply (temp 4-component vector of float)
...
@@ -79,11 +118,16 @@ gl_FragCoord origin is upper left
...
@@ -79,11 +118,16 @@ gl_FragCoord origin is upper left
0:10 'input' (temp 4-component vector of float)
0:10 'input' (temp 4-component vector of float)
0:10 Pre-Increment (temp 4-component vector of float)
0:10 Pre-Increment (temp 4-component vector of float)
0:10 'input' (temp 4-component vector of float)
0:10 'input' (temp 4-component vector of float)
0:11 Branch: Return with expression
0:11 sine (global 4-component vector of float)
0:11 'input' (temp 4-component vector of float)
0:? Linker Objects
0:? Linker Objects
0:? 'AmbientColor' (temp 4-component vector of float)
0:? 'AmbientIntensity' (temp float)
// Module Version 10000
// Module Version 10000
// Generated by (magic number): 80001
// Generated by (magic number): 80001
// Id's are bound by
45
// Id's are bound by
57
Capability Shader
Capability Shader
1: ExtInstImport "GLSL.std.450"
1: ExtInstImport "GLSL.std.450"
...
@@ -93,21 +137,24 @@ gl_FragCoord origin is upper left
...
@@ -93,21 +137,24 @@ gl_FragCoord origin is upper left
Source HLSL 100
Source HLSL 100
Name 4 "PixelShaderFunction"
Name 4 "PixelShaderFunction"
Name 9 "input"
Name 9 "input"
Name 12 "AmbientIntensity"
Name 15 "AmbientColor"
2: TypeVoid
2: TypeVoid
3: TypeFunction 2
3: TypeFunction 2
6: TypeFloat 32
6: TypeFloat 32
7: TypeVector 6(float) 4
7: TypeVector 6(float) 4
8: TypePointer Function 7(fvec4)
8: TypePointer Function 7(fvec4)
27: 6(float) Constant 1065353216
11: TypePointer Function 6(float)
36: 6(float) Constant 1065353216
4(PixelShaderFunction): 2 Function None 3
4(PixelShaderFunction): 2 Function None 3
5: Label
5: Label
9(input): 8(ptr) Variable Function
9(input): 8(ptr) Variable Function
12(AmbientIntensity): 11(ptr) Variable Function
15(AmbientColor): 8(ptr) Variable Function
10: 7(fvec4) Load 9(input)
10: 7(fvec4) Load 9(input)
11: 7(fvec4) Load 9(input)
13: 6(float) Load 12(AmbientIntensity)
12: 7(fvec4) FMul 10 11
14: 7(fvec4) VectorTimesScalar 10 13
13: 7(fvec4) Load 9(input)
16: 7(fvec4) Load 15(AmbientColor)
14: 7(fvec4) Load 9(input)
17: 7(fvec4) FAdd 14 16
15: 7(fvec4) FMul 13 14
ReturnValue 17
16: 7(fvec4) FAdd 12 15
ReturnValue 16
FunctionEnd
FunctionEnd
Test/hlsl.frag
View file @
4678ca9d
//
float4 AmbientColor = float4(1, 0.5, 0, 1);
float4
AmbientColor
=
float4
(
1
,
0
.
5
,
0
,
1
);
//
float AmbientIntensity = 0.1;
float
AmbientIntensity
=
0
.
1
;
float4
PixelShaderFunction
(
float4
input
)
:
COLOR0
float4
PixelShaderFunction
(
float4
input
)
:
COLOR0
{
{
//
return input * AmbientIntensity + AmbientColor;
return
input
*
AmbientIntensity
+
AmbientColor
;
return
input
*
input
+
input
*
input
;
return
input
*
input
+
input
*
input
;
return
input
+
input
*
input
+
input
;
return
input
+
input
*
input
+
input
;
return
++
input
*
-+-+--
input
;
return
++
input
*
-+-+--
input
;
return
input
++
+
++
input
;
return
input
++
+
++
input
;
return
sin
(
input
);
}
}
hlsl/hlslGrammar.cpp
View file @
4678ca9d
...
@@ -608,7 +608,7 @@ bool HlslGrammar::acceptConstructor(TIntermTyped*& node)
...
@@ -608,7 +608,7 @@ bool HlslGrammar::acceptConstructor(TIntermTyped*& node)
return
false
;
return
false
;
// arguments
// arguments
TInterm
Aggregate
*
arguments
=
nullptr
;
TInterm
Typed
*
arguments
=
nullptr
;
if
(
!
acceptArguments
(
constructorFunction
,
arguments
))
{
if
(
!
acceptArguments
(
constructorFunction
,
arguments
))
{
expected
(
"constructor arguments"
);
expected
(
"constructor arguments"
);
return
false
;
return
false
;
...
@@ -628,10 +628,17 @@ bool HlslGrammar::acceptConstructor(TIntermTyped*& node)
...
@@ -628,10 +628,17 @@ bool HlslGrammar::acceptConstructor(TIntermTyped*& node)
// function_call
// function_call
// : [idToken] arguments
// : [idToken] arguments
//
//
bool
HlslGrammar
::
acceptFunctionCall
(
HlslToken
idToken
,
TIntermTyped
*&
)
bool
HlslGrammar
::
acceptFunctionCall
(
HlslToken
idToken
,
TIntermTyped
*&
node
)
{
{
// todo
// arguments
return
false
;
TFunction
*
function
=
new
TFunction
(
idToken
.
string
,
TType
(
EbtVoid
));
TIntermTyped
*
arguments
=
nullptr
;
if
(
!
acceptArguments
(
function
,
arguments
))
return
false
;
node
=
parseContext
.
handleFunctionCall
(
idToken
.
loc
,
function
,
arguments
);
return
true
;
}
}
// arguments
// arguments
...
@@ -640,7 +647,7 @@ bool HlslGrammar::acceptFunctionCall(HlslToken idToken, TIntermTyped*&)
...
@@ -640,7 +647,7 @@ bool HlslGrammar::acceptFunctionCall(HlslToken idToken, TIntermTyped*&)
// The arguments are pushed onto the 'function' argument list and
// The arguments are pushed onto the 'function' argument list and
// onto the 'arguments' aggregate.
// onto the 'arguments' aggregate.
//
//
bool
HlslGrammar
::
acceptArguments
(
TFunction
*
function
,
TInterm
Aggregate
*&
arguments
)
bool
HlslGrammar
::
acceptArguments
(
TFunction
*
function
,
TInterm
Typed
*&
arguments
)
{
{
// LEFT_PAREN
// LEFT_PAREN
if
(
!
acceptTokenClass
(
EHTokLeftParen
))
if
(
!
acceptTokenClass
(
EHTokLeftParen
))
...
@@ -649,7 +656,7 @@ bool HlslGrammar::acceptArguments(TFunction* function, TIntermAggregate*& argume
...
@@ -649,7 +656,7 @@ bool HlslGrammar::acceptArguments(TFunction* function, TIntermAggregate*& argume
do
{
do
{
// expression
// expression
TIntermTyped
*
arg
;
TIntermTyped
*
arg
;
if
(
!
acceptExpression
(
arg
))
if
(
!
accept
Assignment
Expression
(
arg
))
break
;
break
;
// hook it up
// hook it up
...
...
hlsl/hlslGrammar.h
View file @
4678ca9d
...
@@ -71,7 +71,7 @@ namespace glslang {
...
@@ -71,7 +71,7 @@ namespace glslang {
bool
acceptPostfixExpression
(
TIntermTyped
*&
);
bool
acceptPostfixExpression
(
TIntermTyped
*&
);
bool
acceptConstructor
(
TIntermTyped
*&
);
bool
acceptConstructor
(
TIntermTyped
*&
);
bool
acceptFunctionCall
(
HlslToken
,
TIntermTyped
*&
);
bool
acceptFunctionCall
(
HlslToken
,
TIntermTyped
*&
);
bool
acceptArguments
(
TFunction
*
,
TInterm
Aggregate
*&
);
bool
acceptArguments
(
TFunction
*
,
TInterm
Typed
*&
);
bool
acceptLiteral
(
TIntermTyped
*&
);
bool
acceptLiteral
(
TIntermTyped
*&
);
bool
acceptCompoundStatement
(
TIntermAggregate
*&
);
bool
acceptCompoundStatement
(
TIntermAggregate
*&
);
bool
acceptStatement
(
TIntermNode
*&
);
bool
acceptStatement
(
TIntermNode
*&
);
...
...
hlsl/hlslParseHelper.cpp
View file @
4678ca9d
...
@@ -754,12 +754,15 @@ TIntermAggregate* HlslParseContext::handleFunctionDefinition(const TSourceLoc& l
...
@@ -754,12 +754,15 @@ TIntermAggregate* HlslParseContext::handleFunctionDefinition(const TSourceLoc& l
return
paramNodes
;
return
paramNodes
;
}
}
void
HlslParseContext
::
handleFunctionArgument
(
TFunction
*
function
,
TInterm
Aggregate
*&
arguments
,
TIntermTyped
*
a
rg
)
void
HlslParseContext
::
handleFunctionArgument
(
TFunction
*
function
,
TInterm
Typed
*&
arguments
,
TIntermTyped
*
newA
rg
)
{
{
TParameter
param
=
{
0
,
new
TType
};
TParameter
param
=
{
0
,
new
TType
};
param
.
type
->
shallowCopy
(
a
rg
->
getType
());
param
.
type
->
shallowCopy
(
newA
rg
->
getType
());
function
->
addParameter
(
param
);
function
->
addParameter
(
param
);
arguments
=
intermediate
.
growAggregate
(
arguments
,
arg
);
if
(
arguments
)
arguments
=
intermediate
.
growAggregate
(
arguments
,
newArg
);
else
arguments
=
newArg
;
}
}
//
//
...
...
hlsl/hlslParseHelper.h
View file @
4678ca9d
...
@@ -83,7 +83,7 @@ public:
...
@@ -83,7 +83,7 @@ public:
TIntermTyped
*
handleDotDereference
(
const
TSourceLoc
&
,
TIntermTyped
*
base
,
const
TString
&
field
);
TIntermTyped
*
handleDotDereference
(
const
TSourceLoc
&
,
TIntermTyped
*
base
,
const
TString
&
field
);
TFunction
*
handleFunctionDeclarator
(
const
TSourceLoc
&
,
TFunction
&
function
,
bool
prototype
);
TFunction
*
handleFunctionDeclarator
(
const
TSourceLoc
&
,
TFunction
&
function
,
bool
prototype
);
TIntermAggregate
*
handleFunctionDefinition
(
const
TSourceLoc
&
,
TFunction
&
);
TIntermAggregate
*
handleFunctionDefinition
(
const
TSourceLoc
&
,
TFunction
&
);
void
handleFunctionArgument
(
TFunction
*
,
TInterm
Aggregate
*&
,
TIntermTyped
*
);
void
handleFunctionArgument
(
TFunction
*
,
TInterm
Typed
*&
arguments
,
TIntermTyped
*
newArg
);
TIntermTyped
*
handleFunctionCall
(
const
TSourceLoc
&
,
TFunction
*
,
TIntermNode
*
);
TIntermTyped
*
handleFunctionCall
(
const
TSourceLoc
&
,
TFunction
*
,
TIntermNode
*
);
TIntermTyped
*
handleLengthMethod
(
const
TSourceLoc
&
,
TFunction
*
,
TIntermNode
*
);
TIntermTyped
*
handleLengthMethod
(
const
TSourceLoc
&
,
TFunction
*
,
TIntermNode
*
);
void
addInputArgumentConversions
(
const
TFunction
&
,
TIntermNode
*&
)
const
;
void
addInputArgumentConversions
(
const
TFunction
&
,
TIntermNode
*&
)
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