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
636b62db
Commit
636b62db
authored
Apr 11, 2017
by
John Kessenich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HLSL: Support vector 'cond ? :' -> EOpMix -> OpSelect.
parent
34718204
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
10 deletions
+31
-10
hlsl.conditional.frag.out
Test/baseResults/hlsl.conditional.frag.out
+0
-0
hlsl.conditional.frag
Test/hlsl.conditional.frag
+2
-2
Intermediate.cpp
glslang/MachineIndependent/Intermediate.cpp
+25
-4
hlslGrammar.cpp
hlsl/hlslGrammar.cpp
+1
-1
hlslParseHelper.cpp
hlsl/hlslParseHelper.cpp
+2
-2
hlslParseHelper.h
hlsl/hlslParseHelper.h
+1
-1
No files found.
Test/baseResults/hlsl.conditional.frag.out
View file @
636b62db
This diff is collapsed.
Click to expand it.
Test/hlsl.conditional.frag
View file @
636b62db
...
@@ -6,8 +6,8 @@ float f;
...
@@ -6,8 +6,8 @@ float f;
float4
vectorCond
()
float4
vectorCond
()
{
{
return
f4
;
// return
(c4 ? t4 : f4) +
return
(
c4
?
t4
:
f4
)
+
//
(c4 ? t : f );
(
c4
?
t
:
f
);
}
}
float4
PixelShaderFunction
(
float4
input
)
:
COLOR0
float4
PixelShaderFunction
(
float4
input
)
:
COLOR0
...
...
glslang/MachineIndependent/Intermediate.cpp
View file @
636b62db
...
@@ -1271,7 +1271,8 @@ TIntermTyped* TIntermediate::addMethod(TIntermTyped* object, const TType& type,
...
@@ -1271,7 +1271,8 @@ TIntermTyped* TIntermediate::addMethod(TIntermTyped* object, const TType& type,
//
//
// For "?:" test nodes. There are three children; a condition,
// For "?:" test nodes. There are three children; a condition,
// a true path, and a false path. The two paths are specified
// a true path, and a false path. The two paths are specified
// as separate parameters.
// as separate parameters. For vector 'cond', the true and false
// are not paths, but vectors to mix.
//
//
// Specialization constant operations include
// Specialization constant operations include
// - The ternary operator ( ? : )
// - The ternary operator ( ? : )
...
@@ -1304,10 +1305,30 @@ TIntermTyped* TIntermediate::addSelection(TIntermTyped* cond, TIntermTyped* true
...
@@ -1304,10 +1305,30 @@ TIntermTyped* TIntermediate::addSelection(TIntermTyped* cond, TIntermTyped* true
if
(
falseBlock
->
getType
()
!=
trueBlock
->
getType
())
if
(
falseBlock
->
getType
()
!=
trueBlock
->
getType
())
return
nullptr
;
return
nullptr
;
//
// Handle a vector condition as a mix
// See if all the operands are constant, then fold it otherwise not.
if
(
!
cond
->
getType
().
isScalarOrVec1
())
{
//
TType
targetVectorType
(
trueBlock
->
getType
().
getBasicType
(),
EvqTemporary
,
cond
->
getType
().
getVectorSize
());
// smear true/false operations if needed
if
(
trueBlock
->
getType
().
isScalarOrVec1
())
trueBlock
=
addShapeConversion
(
EOpAssign
,
targetVectorType
,
trueBlock
);
if
(
falseBlock
->
getType
().
isScalarOrVec1
())
falseBlock
=
addShapeConversion
(
EOpAssign
,
targetVectorType
,
falseBlock
);
// make the mix operation
TIntermAggregate
*
mix
=
makeAggregate
(
loc
);
mix
=
growAggregate
(
mix
,
falseBlock
);
mix
=
growAggregate
(
mix
,
trueBlock
);
mix
=
growAggregate
(
mix
,
cond
);
mix
->
setType
(
targetVectorType
);
mix
->
setOp
(
EOpMix
);
return
mix
;
}
// Now have a scalar condition...
// Eliminate the selection when the condition is a scalar and all operands are constant.
if
(
cond
->
getAsConstantUnion
()
&&
trueBlock
->
getAsConstantUnion
()
&&
falseBlock
->
getAsConstantUnion
())
{
if
(
cond
->
getAsConstantUnion
()
&&
trueBlock
->
getAsConstantUnion
()
&&
falseBlock
->
getAsConstantUnion
())
{
if
(
cond
->
getAsConstantUnion
()
->
getConstArray
()[
0
].
getBConst
())
if
(
cond
->
getAsConstantUnion
()
->
getConstArray
()[
0
].
getBConst
())
return
trueBlock
;
return
trueBlock
;
...
...
hlsl/hlslGrammar.cpp
View file @
636b62db
...
@@ -2536,7 +2536,7 @@ bool HlslGrammar::acceptConditionalExpression(TIntermTyped*& node)
...
@@ -2536,7 +2536,7 @@ bool HlslGrammar::acceptConditionalExpression(TIntermTyped*& node)
if
(
!
acceptTokenClass
(
EHTokQuestion
))
if
(
!
acceptTokenClass
(
EHTokQuestion
))
return
true
;
return
true
;
node
=
parseContext
.
convertConditionalExpression
(
token
.
loc
,
node
);
node
=
parseContext
.
convertConditionalExpression
(
token
.
loc
,
node
,
false
);
if
(
node
==
nullptr
)
if
(
node
==
nullptr
)
return
false
;
return
false
;
...
...
hlsl/hlslParseHelper.cpp
View file @
636b62db
...
@@ -4529,9 +4529,9 @@ void HlslParseContext::handleRegister(const TSourceLoc& loc, TQualifier& qualifi
...
@@ -4529,9 +4529,9 @@ void HlslParseContext::handleRegister(const TSourceLoc& loc, TQualifier& qualifi
// Convert to a scalar boolean, or if not allowed by HLSL semantics,
// Convert to a scalar boolean, or if not allowed by HLSL semantics,
// report an error and return nullptr.
// report an error and return nullptr.
TIntermTyped
*
HlslParseContext
::
convertConditionalExpression
(
const
TSourceLoc
&
loc
,
TIntermTyped
*
condition
)
TIntermTyped
*
HlslParseContext
::
convertConditionalExpression
(
const
TSourceLoc
&
loc
,
TIntermTyped
*
condition
,
bool
mustBeScalar
)
{
{
if
(
!
condition
->
getType
().
isScalarOrVec1
())
{
if
(
mustBeScalar
&&
!
condition
->
getType
().
isScalarOrVec1
())
{
error
(
loc
,
"requires a scalar"
,
"conditional expression"
,
""
);
error
(
loc
,
"requires a scalar"
,
"conditional expression"
,
""
);
return
nullptr
;
return
nullptr
;
}
}
...
...
hlsl/hlslParseHelper.h
View file @
636b62db
...
@@ -102,7 +102,7 @@ public:
...
@@ -102,7 +102,7 @@ public:
const
glslang
::
TString
*
component
);
const
glslang
::
TString
*
component
);
void
handleRegister
(
const
TSourceLoc
&
,
TQualifier
&
,
const
glslang
::
TString
*
profile
,
const
glslang
::
TString
&
desc
,
void
handleRegister
(
const
TSourceLoc
&
,
TQualifier
&
,
const
glslang
::
TString
*
profile
,
const
glslang
::
TString
&
desc
,
int
subComponent
,
const
glslang
::
TString
*
);
int
subComponent
,
const
glslang
::
TString
*
);
TIntermTyped
*
convertConditionalExpression
(
const
TSourceLoc
&
,
TIntermTyped
*
);
TIntermTyped
*
convertConditionalExpression
(
const
TSourceLoc
&
,
TIntermTyped
*
,
bool
mustBeScalar
=
true
);
TIntermAggregate
*
handleSamplerTextureCombine
(
const
TSourceLoc
&
loc
,
TIntermTyped
*
argTex
,
TIntermTyped
*
argSampler
);
TIntermAggregate
*
handleSamplerTextureCombine
(
const
TSourceLoc
&
loc
,
TIntermTyped
*
argTex
,
TIntermTyped
*
argSampler
);
bool
parseMatrixSwizzleSelector
(
const
TSourceLoc
&
,
const
TString
&
,
int
cols
,
int
rows
,
TSwizzleSelectors
<
TMatrixSelector
>&
);
bool
parseMatrixSwizzleSelector
(
const
TSourceLoc
&
,
const
TString
&
,
int
cols
,
int
rows
,
TSwizzleSelectors
<
TMatrixSelector
>&
);
...
...
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