Commit 921d315f by John Kessenich Committed by GitHub

Merge pull request #555 from steve-lunarg/promotion-fixes

HLSL: Fix unary and binary operator type conversion issues
parents 720e89b3 6cb1637f
struct PS_OUTPUT
{
float4 Color : SV_Target0;
};
uniform int ival;
uniform int4 ival4;
uniform float fval;
uniform float4 fval4;
PS_OUTPUT main()
{
if (ival && fval);
if (ival || fval);
PS_OUTPUT psout;
psout.Color = 1.0;
return psout;
}
struct PS_OUTPUT
{
float4 Color : SV_Target0;
};
uniform int ival;
uniform int4 ival4;
uniform float fval;
uniform float4 fval4;
PS_OUTPUT main()
{
!ival; // scalar int
!ival4; // vector int
!fval; // scalar float
!fval4; // vector float
if (ival);
if (fval);
if (!ival);
if (!fval);
PS_OUTPUT psout;
psout.Color = 1.0;
return psout;
}
struct PS_OUTPUT
{
float4 Color : SV_Target0;
};
uniform bool bval;
uniform bool4 bval4;
uniform int ival;
uniform int4 ival4;
uniform float fval;
uniform float4 fval4;
PS_OUTPUT main()
{
ival % fval;
ival4 % fval4;
bval % fval;
bval4 % fval4;
int l_int = 1;
l_int %= fval;
PS_OUTPUT psout;
psout.Color = 0;
return psout;
}
...@@ -52,6 +52,8 @@ ...@@ -52,6 +52,8 @@
namespace glslang { namespace glslang {
class TIntermediate;
// //
// Operators used by the high-level (parse tree) representation. // Operators used by the high-level (parse tree) representation.
// //
...@@ -845,7 +847,7 @@ public: ...@@ -845,7 +847,7 @@ public:
virtual TIntermOperator* getAsOperator() { return this; } virtual TIntermOperator* getAsOperator() { return this; }
virtual const TIntermOperator* getAsOperator() const { return this; } virtual const TIntermOperator* getAsOperator() const { return this; }
TOperator getOp() const { return op; } TOperator getOp() const { return op; }
virtual bool promote() { return true; } void setOp(TOperator newOp) { op = newOp; }
bool modifiesState() const; bool modifiesState() const;
bool isConstructor() const; bool isConstructor() const;
bool isTexture() const { return op > EOpTextureGuardBegin && op < EOpTextureGuardEnd; } bool isTexture() const { return op > EOpTextureGuardBegin && op < EOpTextureGuardEnd; }
...@@ -1024,7 +1026,6 @@ public: ...@@ -1024,7 +1026,6 @@ public:
virtual TIntermTyped* getRight() const { return right; } virtual TIntermTyped* getRight() const { return right; }
virtual TIntermBinary* getAsBinaryNode() { return this; } virtual TIntermBinary* getAsBinaryNode() { return this; }
virtual const TIntermBinary* getAsBinaryNode() const { return this; } virtual const TIntermBinary* getAsBinaryNode() const { return this; }
virtual bool promote();
virtual void updatePrecision(); virtual void updatePrecision();
protected: protected:
TIntermTyped* left; TIntermTyped* left;
...@@ -1044,7 +1045,6 @@ public: ...@@ -1044,7 +1045,6 @@ public:
virtual const TIntermTyped* getOperand() const { return operand; } virtual const TIntermTyped* getOperand() const { return operand; }
virtual TIntermUnary* getAsUnaryNode() { return this; } virtual TIntermUnary* getAsUnaryNode() { return this; }
virtual const TIntermUnary* getAsUnaryNode() const { return this; } virtual const TIntermUnary* getAsUnaryNode() const { return this; }
virtual bool promote();
virtual void updatePrecision(); virtual void updatePrecision();
protected: protected:
TIntermTyped* operand; TIntermTyped* operand;
......
...@@ -246,6 +246,9 @@ public: ...@@ -246,6 +246,9 @@ public:
TIntermUnary* addUnaryNode(TOperator op, TIntermTyped* child, TSourceLoc) const; TIntermUnary* addUnaryNode(TOperator op, TIntermTyped* child, TSourceLoc) const;
TIntermUnary* addUnaryNode(TOperator op, TIntermTyped* child, TSourceLoc, const TType&) const; TIntermUnary* addUnaryNode(TOperator op, TIntermTyped* child, TSourceLoc, const TType&) const;
// Add conversion from node's type to given basic type.
TIntermTyped* convertToBasicType(TOperator op, TBasicType basicType, TIntermTyped* node) const;
// Constant folding (in Constant.cpp) // Constant folding (in Constant.cpp)
TIntermTyped* fold(TIntermAggregate* aggrNode); TIntermTyped* fold(TIntermAggregate* aggrNode);
TIntermTyped* foldConstructor(TIntermAggregate* aggrNode); TIntermTyped* foldConstructor(TIntermAggregate* aggrNode);
...@@ -390,6 +393,9 @@ protected: ...@@ -390,6 +393,9 @@ protected:
bool userOutputUsed() const; bool userOutputUsed() const;
static int getBaseAlignmentScalar(const TType&, int& size); static int getBaseAlignmentScalar(const TType&, int& size);
bool isSpecializationOperation(const TIntermOperator&) const; bool isSpecializationOperation(const TIntermOperator&) const;
bool promote(TIntermOperator*);
bool promoteUnary(TIntermUnary&);
bool promoteBinary(TIntermBinary&);
const EShLanguage language; // stage, known at construction time const EShLanguage language; // stage, known at construction time
EShSource source; // source language, known a bit later EShSource source; // source language, known a bit later
......
...@@ -142,6 +142,8 @@ INSTANTIATE_TEST_CASE_P( ...@@ -142,6 +142,8 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.load.rwtexture.array.dx10.frag", "main"}, {"hlsl.load.rwtexture.array.dx10.frag", "main"},
{"hlsl.load.offset.dx10.frag", "main"}, {"hlsl.load.offset.dx10.frag", "main"},
{"hlsl.load.offsetarray.dx10.frag", "main"}, {"hlsl.load.offsetarray.dx10.frag", "main"},
{"hlsl.logical.unary.frag", "main"},
{"hlsl.logical.binary.frag", "main"},
{"hlsl.multiEntry.vert", "RealEntrypoint"}, {"hlsl.multiEntry.vert", "RealEntrypoint"},
{"hlsl.multiReturn.frag", "main"}, {"hlsl.multiReturn.frag", "main"},
{"hlsl.matrixindex.frag", "main"}, {"hlsl.matrixindex.frag", "main"},
...@@ -149,6 +151,7 @@ INSTANTIATE_TEST_CASE_P( ...@@ -149,6 +151,7 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.overload.frag", "PixelShaderFunction"}, {"hlsl.overload.frag", "PixelShaderFunction"},
{"hlsl.pp.line.frag", "main"}, {"hlsl.pp.line.frag", "main"},
{"hlsl.precise.frag", "main"}, {"hlsl.precise.frag", "main"},
{"hlsl.promote.binary.frag", "main"},
{"hlsl.promotions.frag", "main"}, {"hlsl.promotions.frag", "main"},
{"hlsl.rw.bracket.frag", "main"}, {"hlsl.rw.bracket.frag", "main"},
{"hlsl.rw.scalar.bracket.frag", "main"}, {"hlsl.rw.scalar.bracket.frag", "main"},
...@@ -179,7 +182,7 @@ INSTANTIATE_TEST_CASE_P( ...@@ -179,7 +182,7 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.samplelevel.basic.dx10.vert", "main"}, {"hlsl.samplelevel.basic.dx10.vert", "main"},
{"hlsl.samplelevel.offset.dx10.frag", "main"}, {"hlsl.samplelevel.offset.dx10.frag", "main"},
{"hlsl.samplelevel.offsetarray.dx10.frag", "main"}, {"hlsl.samplelevel.offsetarray.dx10.frag", "main"},
{ "hlsl.sample.sub-vec4.dx10.frag", "main"}, {"hlsl.sample.sub-vec4.dx10.frag", "main"},
{"hlsl.semicolons.frag", "main"}, {"hlsl.semicolons.frag", "main"},
{"hlsl.shapeConv.frag", "main"}, {"hlsl.shapeConv.frag", "main"},
{"hlsl.shapeConvRet.frag", "main"}, {"hlsl.shapeConvRet.frag", "main"},
......
...@@ -1935,6 +1935,9 @@ bool HlslGrammar::acceptUnaryExpression(TIntermTyped*& node) ...@@ -1935,6 +1935,9 @@ bool HlslGrammar::acceptUnaryExpression(TIntermTyped*& node)
return true; return true;
node = intermediate.addUnaryMath(unaryOp, node, loc); node = intermediate.addUnaryMath(unaryOp, node, loc);
// These unary ops require lvalues
if (unaryOp == EOpPreIncrement || unaryOp == EOpPreDecrement)
node = parseContext.handleLvalue(loc, "unary operator", node); node = parseContext.handleLvalue(loc, "unary operator", node);
return node != nullptr; return node != nullptr;
......
...@@ -245,7 +245,6 @@ glslang::TString& AppendTypeName(glslang::TString& s, const char* argOrder, cons ...@@ -245,7 +245,6 @@ glslang::TString& AppendTypeName(glslang::TString& s, const char* argOrder, cons
char order = *argOrder; char order = *argOrder;
if (UseHlslTypes) { if (UseHlslTypes) {
// TODO: handle sub-vec4 returns
switch (type) { switch (type) {
case '-': s += "void"; break; case '-': s += "void"; break;
case 'F': s += "float"; break; case 'F': s += "float"; break;
...@@ -832,8 +831,6 @@ void TBuiltInParseablesHlsl::initialize(int /*version*/, EProfile /*profile*/, c ...@@ -832,8 +831,6 @@ void TBuiltInParseablesHlsl::initialize(int /*version*/, EProfile /*profile*/, c
{ "GatherCmpAlpha", /* O-4 */ "V4", nullptr, "%@,S,V,S,V,,,", "FIU,s,F,,I,,,", EShLangAll }, { "GatherCmpAlpha", /* O-4 */ "V4", nullptr, "%@,S,V,S,V,,,", "FIU,s,F,,I,,,", EShLangAll },
{ "GatherCmpAlpha", /* O-4, status */"V4", nullptr, "%@,S,V,S,V,,,,S","FIU,s,F,,I,,,,U",EShLangAll }, { "GatherCmpAlpha", /* O-4, status */"V4", nullptr, "%@,S,V,S,V,,,,S","FIU,s,F,,I,,,,U",EShLangAll },
// TODO: Cmp forms
// Mark end of list, since we want to avoid a range-based for, as some compilers don't handle it yet. // Mark end of list, since we want to avoid a range-based for, as some compilers don't handle it yet.
{ nullptr, nullptr, nullptr, nullptr, nullptr, 0 }, { nullptr, nullptr, nullptr, nullptr, nullptr, 0 },
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment