mirror of
https://github.com/KhronosGroup/glslang
synced 2024-11-08 11:30:06 +00:00
Added constant folding for relational (e.g. lessThan) built-ins, relational built-ins for uints, and bitwise ops for mixed scalars and vectors.
Also, allow comments to precede "#version 100". git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@23974 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
parent
0876a58203
commit
77d908af8a
Binary file not shown.
@ -1,5 +1,5 @@
|
||||
// okay
|
||||
#version 100
|
||||
|
||||
int a[3] = { 2, 3, 4, }; // ERROR
|
||||
|
||||
int uint;
|
||||
|
@ -43,4 +43,25 @@ vec4 gl_Color; // ERROR, storage
|
||||
void bar2()
|
||||
{
|
||||
vec4 s = textureGather(sampC, vec3(0.2));
|
||||
|
||||
uvec3 uv3;
|
||||
bvec3 b3;
|
||||
b3 = lessThan(uv3, uv3);
|
||||
b3 = equal(uv3, uv3);
|
||||
const bvec2 bl1 = greaterThanEqual(uvec2(2, 3), uvec2(3,3));
|
||||
const bvec2 bl2 = equal(uvec2(2, 3), uvec2(3,3));
|
||||
const bvec2 bl3 = equal(bl1, bl2); // yes, equal
|
||||
int a1[int(bl3.x)];
|
||||
int a2[int(bl3.y)];
|
||||
a1[0]; // size 1
|
||||
a2[0]; // size 1
|
||||
const bvec4 bl4 = notEqual(greaterThan(uvec4(1,2,3,4), uvec4(0,2,0,6)), lessThanEqual(uvec4(7,8,9,10), uvec4(6, 8, 0, 11))); // compare (t,f,t,f) with (f,t,f,t)
|
||||
int a3[int(bl4.x)+int(bl4.y)+int(bl4.z)+int(bl4.w)];
|
||||
a3[3]; // size 4
|
||||
b3 != b3;
|
||||
b3 < b3; // ERROR
|
||||
uv3 > uv3; // ERROR
|
||||
uvec2(2, 3) >= uvec2(3,3); // ERROR
|
||||
int(bl4) <= int(bl4); // true
|
||||
int(bl4.x) > int(bl4.y); // false
|
||||
}
|
||||
|
@ -81,8 +81,8 @@ void main()
|
||||
a >> u;
|
||||
iv3 >> iv4;
|
||||
|
||||
i & u;
|
||||
u ^ uv3;
|
||||
i & u;
|
||||
u &= uv3;
|
||||
i | uv3;
|
||||
u & f;
|
||||
m2 | m2;
|
||||
@ -125,5 +125,11 @@ void main()
|
||||
i & i;
|
||||
u | u;
|
||||
iv3 ^ iv3;
|
||||
|
||||
u & uv3;
|
||||
uv3 | u;
|
||||
uv3 &= u;
|
||||
int arr[0x222 & 0xf];
|
||||
arr[1]; // size 2
|
||||
int arr2[(uvec2(0, 0x2) | 0x1u).y];
|
||||
arr2[2]; // size 3
|
||||
}
|
||||
|
@ -4,7 +4,10 @@ ERROR: 0:35: 'redeclaration' : cannot change the type of gl_Color
|
||||
ERROR: 0:38: 'gl_Color' : redeclaring non-array as array
|
||||
ERROR: 0:39: 'redeclaration' : cannot change storage, memory, or auxiliary qualification of gl_Color
|
||||
WARNING: 0:45: extension GL_ARB_texture_gather is being used for texture gather function
|
||||
ERROR: 4 compilation errors. No code generated.
|
||||
ERROR: 0:62: '<' : wrong operand types: no operation '<' exists that takes a left-hand operand of type '3-component vector of bool' and a right operand of type '3-component vector of bool' (or there is no acceptable conversion)
|
||||
ERROR: 0:63: '>' : wrong operand types: no operation '>' exists that takes a left-hand operand of type '3-component vector of uint' and a right operand of type '3-component vector of uint' (or there is no acceptable conversion)
|
||||
ERROR: 0:64: '>=' : wrong operand types: no operation '>=' exists that takes a left-hand operand of type 'const 2-component vector of uint' and a right operand of type 'const 2-component vector of uint' (or there is no acceptable conversion)
|
||||
ERROR: 7 compilation errors. No code generated.
|
||||
|
||||
ERROR: node is still EOpNull!
|
||||
0:16 Function Definition: main( (void)
|
||||
@ -53,6 +56,41 @@ ERROR: node is still EOpNull!
|
||||
0:45 0.200000
|
||||
0:45 0.200000
|
||||
0:45 0.200000
|
||||
0:49 move second child to first child (3-component vector of bool)
|
||||
0:49 'b3' (3-component vector of bool)
|
||||
0:49 Compare Less Than (3-component vector of bool)
|
||||
0:49 'uv3' (3-component vector of uint)
|
||||
0:49 'uv3' (3-component vector of uint)
|
||||
0:50 move second child to first child (3-component vector of bool)
|
||||
0:50 'b3' (3-component vector of bool)
|
||||
0:50 Equal (3-component vector of bool)
|
||||
0:50 'uv3' (3-component vector of uint)
|
||||
0:50 'uv3' (3-component vector of uint)
|
||||
0:56 direct index (int)
|
||||
0:56 'a1' (1-element array of int)
|
||||
0:56 Constant:
|
||||
0:56 0 (const int)
|
||||
0:57 direct index (int)
|
||||
0:57 'a2' (1-element array of int)
|
||||
0:57 Constant:
|
||||
0:57 0 (const int)
|
||||
0:60 direct index (int)
|
||||
0:60 'a3' (4-element array of int)
|
||||
0:60 Constant:
|
||||
0:60 3 (const int)
|
||||
0:61 Compare Not Equal (bool)
|
||||
0:61 'b3' (3-component vector of bool)
|
||||
0:61 'b3' (3-component vector of bool)
|
||||
0:62 Constant:
|
||||
0:62 false (const bool)
|
||||
0:63 Constant:
|
||||
0:63 false (const bool)
|
||||
0:64 Constant:
|
||||
0:64 false (const bool)
|
||||
0:65 Constant:
|
||||
0:65 true (const bool)
|
||||
0:66 Constant:
|
||||
0:66 false (const bool)
|
||||
0:? Linker Objects
|
||||
0:? 'a' (3-component vector of float)
|
||||
0:? 'b' (float)
|
||||
|
@ -48,7 +48,7 @@ ERROR: 0:80: '>>' : wrong operand types: no operation '>>' exists that takes a
|
||||
ERROR: 0:81: '>>' : wrong operand types: no operation '>>' exists that takes a left-hand operand of type '5-element array of mediump float' and a right operand of type 'mediump uint' (or there is no acceptable conversion)
|
||||
ERROR: 0:82: '>>' : wrong operand types: no operation '>>' exists that takes a left-hand operand of type 'mediump 3-component vector of int' and a right operand of type 'mediump 4-component vector of int' (or there is no acceptable conversion)
|
||||
ERROR: 0:84: '&' : wrong operand types: no operation '&' exists that takes a left-hand operand of type 'mediump int' and a right operand of type 'mediump uint' (or there is no acceptable conversion)
|
||||
ERROR: 0:85: '^' : wrong operand types: no operation '^' exists that takes a left-hand operand of type 'mediump uint' and a right operand of type 'mediump 3-component vector of uint' (or there is no acceptable conversion)
|
||||
ERROR: 0:85: 'assign' : cannot convert from 'mediump 3-component vector of uint' to 'mediump uint'
|
||||
ERROR: 0:86: '|' : wrong operand types: no operation '|' exists that takes a left-hand operand of type 'mediump int' and a right operand of type 'mediump 3-component vector of uint' (or there is no acceptable conversion)
|
||||
ERROR: 0:87: '&' : wrong operand types: no operation '&' exists that takes a left-hand operand of type 'mediump uint' and a right operand of type 'mediump float' (or there is no acceptable conversion)
|
||||
ERROR: 0:88: '|' : wrong operand types: no operation '|' exists that takes a left-hand operand of type 'mediump 2X2 matrix of float' and a right operand of type 'mediump 2X2 matrix of float' (or there is no acceptable conversion)
|
||||
@ -211,6 +211,23 @@ ERROR: node is still EOpNull!
|
||||
0:127 exclusive-or (mediump 3-component vector of int)
|
||||
0:127 'iv3' (mediump 3-component vector of int)
|
||||
0:127 'iv3' (mediump 3-component vector of int)
|
||||
0:128 bitwise and (mediump 3-component vector of uint)
|
||||
0:128 'u' (mediump uint)
|
||||
0:128 'uv3' (mediump 3-component vector of uint)
|
||||
0:129 inclusive-or (mediump 3-component vector of uint)
|
||||
0:129 'uv3' (mediump 3-component vector of uint)
|
||||
0:129 'u' (mediump uint)
|
||||
0:130 and second child into first child (mediump 3-component vector of uint)
|
||||
0:130 'uv3' (mediump 3-component vector of uint)
|
||||
0:130 'u' (mediump uint)
|
||||
0:132 direct index (mediump int)
|
||||
0:132 'arr' (2-element array of mediump int)
|
||||
0:132 Constant:
|
||||
0:132 1 (const int)
|
||||
0:134 direct index (mediump int)
|
||||
0:134 'arr2' (3-element array of mediump int)
|
||||
0:134 Constant:
|
||||
0:134 2 (const int)
|
||||
0:? Linker Objects
|
||||
0:? 'instanceName' (layout(column_major shared ) uniform block{f})
|
||||
0:? 's' (structure{i})
|
||||
|
@ -551,6 +551,12 @@ TIntermTyped* TIntermediate::fold(TIntermAggregate* aggrNode)
|
||||
case EOpMax:
|
||||
case EOpMix:
|
||||
case EOpClamp:
|
||||
case EOpLessThan:
|
||||
case EOpGreaterThan:
|
||||
case EOpLessThanEqual:
|
||||
case EOpGreaterThanEqual:
|
||||
case EOpVectorEqual:
|
||||
case EOpVectorNotEqual:
|
||||
componentwise = true;
|
||||
objectSize = children[0]->getAsConstantUnion()->getType().getObjectSize();
|
||||
break;
|
||||
@ -638,6 +644,24 @@ TIntermTyped* TIntermediate::fold(TIntermAggregate* aggrNode)
|
||||
newConstArray[comp].setUConst(std::min(std::max(childConstUnions[0][arg0comp].getUConst(), childConstUnions[1][arg1comp].getUConst()),
|
||||
childConstUnions[2][arg2comp].getUConst()));
|
||||
break;
|
||||
case EOpLessThan:
|
||||
newConstArray[comp].setBConst(childConstUnions[0][arg0comp] < childConstUnions[1][arg1comp]);
|
||||
break;
|
||||
case EOpGreaterThan:
|
||||
newConstArray[comp].setBConst(childConstUnions[0][arg0comp] > childConstUnions[1][arg1comp]);
|
||||
break;
|
||||
case EOpLessThanEqual:
|
||||
newConstArray[comp].setBConst(! (childConstUnions[0][arg0comp] > childConstUnions[1][arg1comp]));
|
||||
break;
|
||||
case EOpGreaterThanEqual:
|
||||
newConstArray[comp].setBConst(! (childConstUnions[0][arg0comp] < childConstUnions[1][arg1comp]));
|
||||
break;
|
||||
case EOpVectorEqual:
|
||||
newConstArray[comp].setBConst(childConstUnions[0][arg0comp] == childConstUnions[1][arg1comp]);
|
||||
break;
|
||||
case EOpVectorNotEqual:
|
||||
newConstArray[comp].setBConst(childConstUnions[0][arg0comp] != childConstUnions[1][arg1comp]);
|
||||
break;
|
||||
case EOpMix:
|
||||
if (children[2]->getAsTyped()->getBasicType() == EbtBool)
|
||||
newConstArray[comp].setDConst(childConstUnions[2][arg2comp].getBConst() ? childConstUnions[1][arg1comp].getDConst() :
|
||||
|
@ -616,6 +616,35 @@ void TBuiltIns::initialize(int version, EProfile profile)
|
||||
|
||||
"\n");
|
||||
|
||||
if (version >= 130) {
|
||||
commonBuiltins.append(
|
||||
"bvec2 lessThan(uvec2 x, uvec2 y);"
|
||||
"bvec3 lessThan(uvec3 x, uvec3 y);"
|
||||
"bvec4 lessThan(uvec4 x, uvec4 y);"
|
||||
|
||||
"bvec2 lessThanEqual(uvec2 x, uvec2 y);"
|
||||
"bvec3 lessThanEqual(uvec3 x, uvec3 y);"
|
||||
"bvec4 lessThanEqual(uvec4 x, uvec4 y);"
|
||||
|
||||
"bvec2 greaterThan(uvec2 x, uvec2 y);"
|
||||
"bvec3 greaterThan(uvec3 x, uvec3 y);"
|
||||
"bvec4 greaterThan(uvec4 x, uvec4 y);"
|
||||
|
||||
"bvec2 greaterThanEqual(uvec2 x, uvec2 y);"
|
||||
"bvec3 greaterThanEqual(uvec3 x, uvec3 y);"
|
||||
"bvec4 greaterThanEqual(uvec4 x, uvec4 y);"
|
||||
|
||||
"bvec2 equal(uvec2 x, uvec2 y);"
|
||||
"bvec3 equal(uvec3 x, uvec3 y);"
|
||||
"bvec4 equal(uvec4 x, uvec4 y);"
|
||||
|
||||
"bvec2 notEqual(uvec2 x, uvec2 y);"
|
||||
"bvec3 notEqual(uvec3 x, uvec3 y);"
|
||||
"bvec4 notEqual(uvec4 x, uvec4 y);"
|
||||
|
||||
"\n");
|
||||
}
|
||||
|
||||
//
|
||||
// Original-style texture functions existing in both stages.
|
||||
// (Per-stage functions below.)
|
||||
|
@ -571,7 +571,7 @@ TIntermTyped* TIntermediate::addConversion(TOperator op, const TType& type, TInt
|
||||
bool TIntermediate::canImplicitlyPromote(TBasicType from, TBasicType to)
|
||||
{
|
||||
if (profile == EEsProfile || version == 110)
|
||||
return 0;
|
||||
return false;
|
||||
|
||||
switch (to) {
|
||||
case EbtDouble:
|
||||
@ -596,6 +596,7 @@ bool TIntermediate::canImplicitlyPromote(TBasicType from, TBasicType to)
|
||||
case EbtUint:
|
||||
switch (from) {
|
||||
case EbtInt:
|
||||
return version >= 400;
|
||||
case EbtUint:
|
||||
return true;
|
||||
default:
|
||||
@ -1084,7 +1085,7 @@ bool TIntermBinary::promote()
|
||||
case EOpLessThanEqual:
|
||||
case EOpGreaterThanEqual:
|
||||
// Relational comparisons need matching numeric types and will promote to scalar Boolean.
|
||||
if (left->getBasicType() == EbtBool || left->getType().isMatrix())
|
||||
if (left->getBasicType() == EbtBool || left->getType().isVector() || left->getType().isMatrix())
|
||||
return false;
|
||||
|
||||
// Fall through
|
||||
@ -1294,10 +1295,16 @@ bool TIntermBinary::promote()
|
||||
case EOpSub:
|
||||
case EOpDiv:
|
||||
case EOpMod:
|
||||
case EOpAnd:
|
||||
case EOpInclusiveOr:
|
||||
case EOpExclusiveOr:
|
||||
case EOpAddAssign:
|
||||
case EOpSubAssign:
|
||||
case EOpDivAssign:
|
||||
case EOpModAssign:
|
||||
case EOpAndAssign:
|
||||
case EOpInclusiveOrAssign:
|
||||
case EOpExclusiveOrAssign:
|
||||
if ((left->isMatrix() && right->isVector()) ||
|
||||
(left->isVector() && right->isMatrix()) ||
|
||||
left->getBasicType() != right->getBasicType())
|
||||
|
@ -457,7 +457,7 @@ bool CompileDeferred(
|
||||
bool versionNotFirst = userInput.scanVersion(version, profile);
|
||||
bool versionNotFound = version == 0;
|
||||
bool goodVersion = DeduceVersionProfile(compiler->infoSink, compiler->getLanguage(), versionNotFirst, defaultVersion, version, profile);
|
||||
bool versionWillBeError = (versionNotFound || (profile == EEsProfile && versionNotFirst));
|
||||
bool versionWillBeError = (versionNotFound || (profile == EEsProfile && version >= 300 && versionNotFirst));
|
||||
|
||||
intermediate.setVersion(version);
|
||||
intermediate.setProfile(profile);
|
||||
|
Loading…
Reference in New Issue
Block a user