Commit 90707966 by steve-lunarg

HLSL: phase 2b: add l-value operator[] for RWTexture/RWBuffer

This commit adds l-value support for RW texture and buffer objects. Supported are: - pre and post inc/decrement - function out parameters - op-assignments, such as *=, +-, etc. - result values from op-assignments. e.g, val=(MyRwTex[loc] *= 2); Not supported are: - Function inout parameters - multiple post-inc/decrement operators. E.g, MyRWTex[loc]++++;
parent 6b43d274
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -35,6 +35,10 @@ uniform int2 o2;
uniform int3 o3;
uniform int4 o4;
uniform float4 uf4;
uniform int4 ui4;
uniform uint4 uu4;
int4 Fn1(in int4 x) { return x; }
uint4 Fn1(in uint4 x) { return x; }
float4 Fn1(in float4 x) { return x; }
......@@ -43,19 +47,19 @@ void Fn2(out int4 x) { x = int4(0); }
void Fn2(out uint4 x) { x = uint4(0); }
void Fn2(out float4 x) { x = float4(0); }
float4 SomeValue() { return c4; }
PS_OUTPUT main()
{
PS_OUTPUT psout;
// Test as R-values
// 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];
......@@ -66,47 +70,66 @@ PS_OUTPUT main()
int4 r21 = g_tTex3di4[c3];
uint4 r22 = g_tTex3du4[c3];
// // Test as L-values
// // 1D
// g_tTex1df4[c1] = float4(1,2,3,4);
// g_tTex1di4[c1] = int4(1,2,3,4);
// g_tTex1du4[c1] = uint4(1,2,3,4);
float4 lf4 = uf4;
// Test as L-values
// 1D
g_tTex1df4[c1] = SomeValue(); // complex L-value
g_tTex1df4[c1] = lf4;
g_tTex1di4[c1] = int4(2,2,3,4);
g_tTex1du4[c1] = uint4(3,2,3,4);
// Test some operator= things, which need to do both a load and a store.
float4 val1 = (g_tTex1df4[c1] *= 2.0);
g_tTex1df4[c1] -= 3.0;
g_tTex1df4[c1] += 4.0;
// // 2D
// g_tTex2df4[c2] = float4(1,2,3,4);
// g_tTex2di4[c2] = int4(1,2,3,4);
// g_tTex2du4[c2] = uint4(1,2,3,4);
g_tTex1di4[c1] /= 2;
g_tTex1di4[c1] %= 2;
g_tTex1di4[c1] &= 0xffff;
g_tTex1di4[c1] |= 0xf0f0;
g_tTex1di4[c1] <<= 2;
g_tTex1di4[c1] >>= 2;
// 2D
g_tTex2df4[c2] = SomeValue(); // complex L-value
g_tTex2df4[c2] = lf4;
g_tTex2di4[c2] = int4(5,2,3,4);
g_tTex2du4[c2] = uint4(6,2,3,4);
// // 3D
// g_tTex3df4[c3] = float4(1,2,3,4);
// g_tTex3di4[c3] = int4(1,2,3,4);
// g_tTex3du4[c3] = uint4(1,2,3,4);
// 3D
g_tTex3df4[c3] = SomeValue(); // complex L-value
g_tTex3df4[c3] = lf4;
g_tTex3di4[c3] = int4(8,6,7,8);
g_tTex3du4[c3] = uint4(9,2,3,4);
// // Test function calling
Fn1(g_tTex1df4[c1]); // in
Fn1(g_tTex1di4[c1]); // in
Fn1(g_tTex1du4[c1]); // in
// Fn2(g_tTex1df4[c1]); // out
// Fn2(g_tTex1di4[c1]); // out
// Fn2(g_tTex1du4[c1]); // out
Fn2(g_tTex1df4[c1]); // out
Fn2(g_tTex1di4[c1]); // out
Fn2(g_tTex1du4[c1]); // out
// // Test increment operators
// g_tTex1df4[c1]++;
// g_tTex1di4[c1]++;
// g_tTex1du4[c1]++;
// Test increment operators
// pre-ops
++g_tTex1df4[c1];
++g_tTex1di4[c1];
++g_tTex1du4[c1];
// g_tTex1df4[c1]--;
// g_tTex1di4[c1]--;
// g_tTex1du4[c1]--;
--g_tTex1df4[c1];
--g_tTex1di4[c1];
--g_tTex1du4[c1];
// ++g_tTex1df4[c1];
// ++g_tTex1di4[c1];
// ++g_tTex1du4[c1];
// post-ops
g_tTex1df4[c1]++;
g_tTex1du4[c1]--;
g_tTex1di4[c1]++;
// --g_tTex1df4[c1];
// --g_tTex1di4[c1];
// --g_tTex1du4[c1];
g_tTex1df4[c1]--;
g_tTex1di4[c1]++;
g_tTex1du4[c1]--;
psout.Color = 1.0;
......
......@@ -2045,6 +2045,10 @@ bool TIntermBinary::promote()
}
break;
case EOpVectorTimesScalarAssign:
if (left->isVector() && right->isScalar())
return true;
default:
return false;
}
......
......@@ -1783,6 +1783,8 @@ bool HlslGrammar::acceptAssignmentExpression(TIntermTyped*& node)
}
node = parseContext.handleAssign(loc, assignOp, node, rightNode);
node = parseContext.handleLvalue(loc, "assign", node);
if (node == nullptr) {
parseContext.error(loc, "could not create assignment", "", "");
return false;
......@@ -1946,6 +1948,7 @@ bool HlslGrammar::acceptUnaryExpression(TIntermTyped*& node)
return true;
node = intermediate.addUnaryMath(unaryOp, node, loc);
node = parseContext.handleLvalue(loc, "", node);
return node != nullptr;
}
......@@ -2061,6 +2064,7 @@ bool HlslGrammar::acceptPostfixExpression(TIntermTyped*& node)
case EOpPostDecrement:
// DEC_OP
node = intermediate.addUnaryMath(postOp, node, loc);
node = parseContext.handleLvalue(loc, "", node);
break;
default:
assert(0);
......
......@@ -81,7 +81,7 @@ public:
void decomposeSampleMethods(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments);
TIntermTyped* handleLengthMethod(const TSourceLoc&, TFunction*, TIntermNode*);
void addInputArgumentConversions(const TFunction&, TIntermNode*&) const;
TIntermTyped* addOutputArgumentConversions(const TFunction&, TIntermAggregate&) const;
TIntermTyped* addOutputArgumentConversions(const TFunction&, TIntermAggregate&);
void builtInOpCheck(const TSourceLoc&, const TFunction&, TIntermOperator&);
TFunction* handleConstructorCall(const TSourceLoc&, const TType&);
void handleSemantic(TSourceLoc, TQualifier&, const TString& semantic);
......@@ -152,6 +152,9 @@ public:
void pushSwitchSequence(TIntermSequence* sequence) { switchSequenceStack.push_back(sequence); }
void popSwitchSequence() { switchSequenceStack.pop_back(); }
// Apply L-value conversions. E.g, turning a write to a RWTexture into an ImageStore.
TIntermTyped* handleLvalue(const TSourceLoc&, const char* op, TIntermTyped* node);
protected:
void inheritGlobalDefaults(TQualifier& dst) const;
TVariable* makeInternalVariable(const char* name, const TType&) const;
......@@ -161,6 +164,9 @@ protected:
TIntermTyped* convertInitializerList(const TSourceLoc&, const TType&, TIntermTyped* initializer);
TOperator mapAtomicOp(const TSourceLoc& loc, TOperator op, bool isImage);
// Return true if this node requires L-value conversion (e.g, to an imageStore).
bool shouldConvertLValue(const TIntermNode*) const;
// Array and struct flattening
bool shouldFlatten(const TType& type) const { return shouldFlattenIO(type) || shouldFlattenUniform(type); }
TIntermTyped* flattenAccess(TIntermTyped* base, int member);
......
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