Commit 07830e80 by steve-lunarg

HLSL: phase 2d: minor cleanup, & allow operator[] on non-rw textures

Improve comments. A few tweaked lines allow [] on non-rw tx. Add test case for this. Improve VectorTimesScalar handling.
parent 0de16da2
...@@ -74,7 +74,7 @@ PS_OUTPUT main() ...@@ -74,7 +74,7 @@ PS_OUTPUT main()
// Test as L-values // Test as L-values
// 1D // 1D
g_tTex1df4[c1] = SomeValue(); // complex L-value g_tTex1df4[c1] = SomeValue(); // complex R-value
g_tTex1df4[c1] = lf4; g_tTex1df4[c1] = lf4;
g_tTex1di4[c1] = int4(2,2,3,4); g_tTex1di4[c1] = int4(2,2,3,4);
g_tTex1du4[c1] = uint4(3,2,3,4); g_tTex1du4[c1] = uint4(3,2,3,4);
...@@ -103,7 +103,7 @@ PS_OUTPUT main() ...@@ -103,7 +103,7 @@ PS_OUTPUT main()
g_tTex3di4[c3] = int4(8,6,7,8); g_tTex3di4[c3] = int4(8,6,7,8);
g_tTex3du4[c3] = uint4(9,2,3,4); g_tTex3du4[c3] = uint4(9,2,3,4);
// // Test function calling // Test function calling
Fn1(g_tTex1df4[c1]); // in Fn1(g_tTex1df4[c1]); // in
Fn1(g_tTex1di4[c1]); // in Fn1(g_tTex1di4[c1]); // in
Fn1(g_tTex1du4[c1]); // in Fn1(g_tTex1du4[c1]); // in
...@@ -131,6 +131,9 @@ PS_OUTPUT main() ...@@ -131,6 +131,9 @@ PS_OUTPUT main()
g_tTex1di4[c1]++; g_tTex1di4[c1]++;
g_tTex1du4[c1]--; g_tTex1du4[c1]--;
// read and write
g_tTex1df4[1] = g_tTex2df4[int2(2,3)];
psout.Color = 1.0; psout.Color = 1.0;
return psout; return psout;
......
SamplerState g_sSamp : register(s0);
Texture1D <float4> g_tTex1df4 : register(t0);
Texture1D <int4> g_tTex1di4;
Texture1D <uint4> g_tTex1du4;
Texture2D <float4> g_tTex2df4;
Texture2D <int4> g_tTex2di4;
Texture2D <uint4> g_tTex2du4;
Texture3D <float4> g_tTex3df4;
Texture3D <int4> g_tTex3di4;
Texture3D <uint4> g_tTex3du4;
Texture1DArray <float4> g_tTex1df4a;
Texture1DArray <int4> g_tTex1di4a;
Texture1DArray <uint4> g_tTex1du4a;
Texture2DArray <float4> g_tTex2df4a;
Texture2DArray <int4> g_tTex2di4a;
Texture2DArray <uint4> g_tTex2du4a;
struct PS_OUTPUT
{
float4 Color : SV_Target0;
};
uniform int c1;
uniform int2 c2;
uniform int3 c3;
uniform int4 c4;
uniform int o1;
uniform int2 o2;
uniform int3 o3;
uniform int4 o4;
int4 Fn1(in int4 x) { return x; }
uint4 Fn1(in uint4 x) { return x; }
float4 Fn1(in float4 x) { return x; }
float4 SomeValue() { return c4; }
PS_OUTPUT main()
{
PS_OUTPUT psout;
// 1D
g_tTex1df4[c1];
float4 r00 = g_tTex1df4[c1];
int4 r01 = g_tTex1di4[c1];
uint4 r02 = g_tTex1du4[c1];
// 2D
float4 r10 = g_tTex2df4[c2];
int4 r11 = g_tTex2di4[c2];
uint4 r12 = g_tTex2du4[c2];
// 3D
float4 r20 = g_tTex3df4[c3];
int4 r21 = g_tTex3di4[c3];
uint4 r22 = g_tTex3du4[c3];
// Test function calling
Fn1(g_tTex1df4[c1]); // in
Fn1(g_tTex1di4[c1]); // in
Fn1(g_tTex1du4[c1]); // in
psout.Color = 1.0;
return psout;
}
...@@ -2046,8 +2046,9 @@ bool TIntermBinary::promote() ...@@ -2046,8 +2046,9 @@ bool TIntermBinary::promote()
break; break;
case EOpVectorTimesScalarAssign: case EOpVectorTimesScalarAssign:
if (left->isVector() && right->isScalar()) if (!left->isVector() || !right->isScalar())
return true; return false;
break;
default: default:
return false; return false;
...@@ -2069,6 +2070,7 @@ bool TIntermBinary::promote() ...@@ -2069,6 +2070,7 @@ bool TIntermBinary::promote()
case EOpExclusiveOrAssign: case EOpExclusiveOrAssign:
case EOpLeftShiftAssign: case EOpLeftShiftAssign:
case EOpRightShiftAssign: case EOpRightShiftAssign:
case EOpVectorTimesScalarAssign:
if (getType() != left->getType()) if (getType() != left->getType())
return false; return false;
break; break;
......
...@@ -191,6 +191,7 @@ INSTANTIATE_TEST_CASE_P( ...@@ -191,6 +191,7 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.switch.frag", "PixelShaderFunction"}, {"hlsl.switch.frag", "PixelShaderFunction"},
{"hlsl.swizzle.frag", "PixelShaderFunction"}, {"hlsl.swizzle.frag", "PixelShaderFunction"},
{"hlsl.templatetypes.frag", "PixelShaderFunction"}, {"hlsl.templatetypes.frag", "PixelShaderFunction"},
{"hlsl.tx.bracket.frag", "main"},
{"hlsl.typedef.frag", "PixelShaderFunction"}, {"hlsl.typedef.frag", "PixelShaderFunction"},
{"hlsl.whileLoop.frag", "PixelShaderFunction"}, {"hlsl.whileLoop.frag", "PixelShaderFunction"},
{"hlsl.void.frag", "PixelShaderFunction"}, {"hlsl.void.frag", "PixelShaderFunction"},
......
...@@ -1948,7 +1948,7 @@ bool HlslGrammar::acceptUnaryExpression(TIntermTyped*& node) ...@@ -1948,7 +1948,7 @@ bool HlslGrammar::acceptUnaryExpression(TIntermTyped*& node)
return true; return true;
node = intermediate.addUnaryMath(unaryOp, node, loc); node = intermediate.addUnaryMath(unaryOp, node, loc);
node = parseContext.handleLvalue(loc, "", node); node = parseContext.handleLvalue(loc, "unary operator", node);
return node != nullptr; return node != nullptr;
} }
...@@ -2064,7 +2064,7 @@ bool HlslGrammar::acceptPostfixExpression(TIntermTyped*& node) ...@@ -2064,7 +2064,7 @@ bool HlslGrammar::acceptPostfixExpression(TIntermTyped*& node)
case EOpPostDecrement: case EOpPostDecrement:
// DEC_OP // DEC_OP
node = intermediate.addUnaryMath(postOp, node, loc); node = intermediate.addUnaryMath(postOp, node, loc);
node = parseContext.handleLvalue(loc, "", node); node = parseContext.handleLvalue(loc, "unary operator", node);
break; break;
default: default:
assert(0); assert(0);
......
...@@ -130,6 +130,10 @@ bool HlslParseContext::parseShaderStrings(TPpContext& ppContext, TInputScanner& ...@@ -130,6 +130,10 @@ bool HlslParseContext::parseShaderStrings(TPpContext& ppContext, TInputScanner&
return numErrors == 0; return numErrors == 0;
} }
//
// Return true if this l-value node should be converted in some manner.
// For instance: turning a load aggregate into a store in an l-value.
//
bool HlslParseContext::shouldConvertLValue(const TIntermNode* node) const bool HlslParseContext::shouldConvertLValue(const TIntermNode* node) const
{ {
if (node == nullptr) if (node == nullptr)
...@@ -177,6 +181,9 @@ bool HlslParseContext::lValueErrorCheck(const TSourceLoc& loc, const char* op, T ...@@ -177,6 +181,9 @@ bool HlslParseContext::lValueErrorCheck(const TSourceLoc& loc, const char* op, T
// //
TIntermTyped* HlslParseContext::handleLvalue(const TSourceLoc& loc, const char* op, TIntermTyped* node) TIntermTyped* HlslParseContext::handleLvalue(const TSourceLoc& loc, const char* op, TIntermTyped* node)
{ {
if (node == nullptr)
return nullptr;
TIntermBinary* nodeAsBinary = node->getAsBinaryNode(); TIntermBinary* nodeAsBinary = node->getAsBinaryNode();
TIntermUnary* nodeAsUnary = node->getAsUnaryNode(); TIntermUnary* nodeAsUnary = node->getAsUnaryNode();
TIntermAggregate* sequence = nullptr; TIntermAggregate* sequence = nullptr;
...@@ -571,12 +578,18 @@ TIntermTyped* HlslParseContext::handleBracketOperator(const TSourceLoc& loc, TIn ...@@ -571,12 +578,18 @@ TIntermTyped* HlslParseContext::handleBracketOperator(const TSourceLoc& loc, TIn
const TSampler& sampler = base->getType().getSampler(); const TSampler& sampler = base->getType().getSampler();
if (sampler.isImage() || sampler.isTexture()) { if (sampler.isImage() || sampler.isTexture()) {
const int vecSize = 4; // TODO: handle arbitrary sizes (get from qualifier) const int vecSize = 4; // TODO: handle arbitrary sizes (get from qualifier)
TIntermAggregate* load = new TIntermAggregate(EOpImageLoad); TIntermAggregate* load = new TIntermAggregate(sampler.isImage() ? EOpImageLoad : EOpTextureFetch);
load->setType(TType(sampler.type, EvqTemporary, vecSize)); load->setType(TType(sampler.type, EvqTemporary, vecSize));
load->setLoc(loc); load->setLoc(loc);
load->getSequence().push_back(base); load->getSequence().push_back(base);
load->getSequence().push_back(index); load->getSequence().push_back(index);
// Textures need a MIP. First indirection is always to mip 0. If there's another, we'll add it
// later.
if (sampler.isTexture())
load->getSequence().push_back(intermediate.addConstantUnion(0, loc, true));
return load; return load;
} }
} }
......
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