glslang and SPIR-V: Some basic turn on for doubles (previously untested but existed code). Partly from a submission, partly addressing bug 13772.

git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@30794 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
John Kessenich 2015-04-17 21:47:07 +00:00
parent 87a5e2a84b
commit edd181944e
10 changed files with 335 additions and 16 deletions

View File

@ -441,7 +441,8 @@ Id Builder::findScalarConstant(Op typeClass, Id typeId, unsigned value) const
Instruction* constant;
for (int i = 0; i < (int)groupedConstants[typeClass].size(); ++i) {
constant = groupedConstants[typeClass][i];
if (constant->getTypeId() == typeId &&
if (constant->getNumOperands() == 1 &&
constant->getTypeId() == typeId &&
constant->getImmediateOperand(0) == value)
return constant->getResultId();
}
@ -449,6 +450,22 @@ Id Builder::findScalarConstant(Op typeClass, Id typeId, unsigned value) const
return 0;
}
// Version findScalarConstant (see above) for scalars that take two operands (e.g. a 'double').
Id Builder::findScalarConstant(Op typeClass, Id typeId, unsigned v1, unsigned v2) const
{
Instruction* constant;
for (int i = 0; i < (int)groupedConstants[typeClass].size(); ++i) {
constant = groupedConstants[typeClass][i];
if (constant->getNumOperands() == 2 &&
constant->getTypeId() == typeId &&
constant->getImmediateOperand(0) == v1 &&
constant->getImmediateOperand(1) == v2)
return constant->getResultId();
}
return 0;
}
Id Builder::makeBoolConstant(bool b)
{
Id typeId = makeBoolType();
@ -510,9 +527,22 @@ Id Builder::makeFloatConstant(float f)
Id Builder::makeDoubleConstant(double d)
{
// TODO
MissingFunctionality("double constant");
return NoResult;
Id typeId = makeFloatType(64);
unsigned long long value = *(unsigned long long*)&d;
unsigned op1 = value & 0xFFFFFFFF;
unsigned op2 = value >> 32;
Id existing = findScalarConstant(OpTypeFloat, typeId, op1, op2);
if (existing)
return existing;
Instruction* c = new Instruction(getUniqueId(), typeId, OpConstant);
c->addImmediateOperand(op1);
c->addImmediateOperand(op2);
constantsTypesGlobals.push_back(c);
groupedConstants[OpTypeFloat].push_back(c);
module.mapInstruction(c);
return c->getResultId();
}
Id Builder::findCompositeConstant(Op typeClass, std::vector<Id>& comps) const

View File

@ -462,6 +462,7 @@ public:
protected:
Id findScalarConstant(Op typeClass, Id typeId, unsigned value) const;
Id findScalarConstant(Op typeClass, Id typeId, unsigned v1, unsigned v2) const;
Id findCompositeConstant(Op typeClass, std::vector<Id>& comps) const;
Id collapseAccessChain();
void simplifyAccessChainSwizzle();

View File

@ -1,4 +1,4 @@
#version 400 core
#version 420 core
#extension GL_ARB_separate_shader_objects : enable
@ -27,3 +27,15 @@ void main()
}
out float outf; // ERROR, no array
layout (location = 0) in dmat2x4 vs_tcs_first[];
layout (location = 12) in dmat2x4 vs_tcs_last[];
void foo()
{
if ((dmat2x4(dvec4(-0.625, -0.5, -0.375, -0.25), dvec4(-0.375, -0.25, -0.125, 0)) != vs_tcs_first[0]) ||
(dmat2x4(dvec4(0.375, 0.5, 0.625, 0.75), dvec4(0.625, 0.75, 0.875, -0.625)) != vs_tcs_last[0]))
{
;
}
}

View File

@ -66,3 +66,14 @@ void foo()
ro.values.length();
barrier();
}
uniform double roll;
uniform writeonly image2D destTex;
void fooaoeu() {
ivec2 storePos = ivec2(gl_GlobalInvocationID.xy);
double localCoef = length(vec2(ivec2(gl_LocalInvocationID.xy)-8)/8.0);
dvec4 aa = dvec4(0.4, 0.2, 0.3, 0.4);
double globalCoef = 1.0;
int i = globalCoef; // ERROR, can't convert from double to int
double di = i;
}

View File

@ -603,7 +603,7 @@ ERROR: node is still EOpNull!
0:? 'patchOut' (patch out 4-component vector of float)
420.tesc
Warning, version 400 is not yet complete; most version-specific features are present, but some are missing.
Warning, version 420 is not yet complete; most version-specific features are present, but some are missing.
ERROR: 0:7: 'vertices' : inconsistent output number of vertices for array size of gl_out
ERROR: 0:11: 'vertices' : inconsistent output number of vertices for array size of a
ERROR: 0:12: 'vertices' : inconsistent output number of vertices for array size of outb
@ -613,7 +613,7 @@ ERROR: 0:29: 'out' : type must be an array: outf
ERROR: 6 compilation errors. No code generated.
Shader version: 400
Shader version: 420
Requested GL_ARB_separate_shader_objects
vertices = 4
ERROR: node is still EOpNull!
@ -678,12 +678,49 @@ ERROR: node is still EOpNull!
0:26 'gl_out' (out 3-element array of block{out 4-component vector of float gl_Position})
0:26 Constant:
0:26 1 (const int)
0:34 Function Definition: foo( (void)
0:34 Function Parameters:
0:36 Sequence
0:36 Test condition and select (void)
0:36 Condition
0:36 logical-or (bool)
0:36 Compare Not Equal (bool)
0:36 Constant:
0:36 -0.625000
0:36 -0.500000
0:36 -0.375000
0:36 -0.250000
0:36 -0.375000
0:36 -0.250000
0:36 -0.125000
0:36 0.000000
0:36 direct index (layout(location=0 ) 2X4 matrix of double)
0:36 'vs_tcs_first' (layout(location=0 ) in 32-element array of 2X4 matrix of double)
0:36 Constant:
0:36 0 (const int)
0:37 Compare Not Equal (bool)
0:37 Constant:
0:37 0.375000
0:37 0.500000
0:37 0.625000
0:37 0.750000
0:37 0.625000
0:37 0.750000
0:37 0.875000
0:37 -0.625000
0:37 direct index (layout(location=12 ) 2X4 matrix of double)
0:37 'vs_tcs_last' (layout(location=12 ) in 32-element array of 2X4 matrix of double)
0:37 Constant:
0:37 0 (const int)
0:36 true case is null
0:? Linker Objects
0:? 'gl_out' (out 3-element array of block{out 4-component vector of float gl_Position})
0:? 'a' (out 3-element array of int)
0:? 'outb' (out 5-element array of int)
0:? 'outc' (out 4-element array of int)
0:? 'outf' (out float)
0:? 'vs_tcs_first' (layout(location=0 ) in 32-element array of 2X4 matrix of double)
0:? 'vs_tcs_last' (layout(location=12 ) in 32-element array of 2X4 matrix of double)
420.tese
Warning, version 420 is not yet complete; most version-specific features are present, but some are missing.
@ -866,6 +903,8 @@ ERROR: Linking tessellation control stage: Multiple function bodies in multiple
main(
ERROR: Linking tessellation control stage: Multiple function bodies in multiple compilation units for the same signature in the same stage:
main(
ERROR: Linking tessellation control stage: Multiple function bodies in multiple compilation units for the same signature in the same stage:
foo(
ERROR: Linking tessellation control stage: Multiple function bodies in multiple compilation units for the same signature in the same stage:
main(
ERROR: Linking tessellation control stage: Types must match:
@ -883,7 +922,7 @@ ERROR: Linking tessellation evaluation stage: Multiple function bodies in multip
ERROR: Linking tessellation evaluation stage: Multiple function bodies in multiple compilation units for the same signature in the same stage:
main(
Shader version: 400
Shader version: 420
Requested GL_ARB_separate_shader_objects
Requested GL_ARB_tessellation_shader
vertices = 4
@ -1221,6 +1260,41 @@ vertices = 4
0:26 'gl_out' (out 3-element array of block{out 4-component vector of float gl_Position})
0:26 Constant:
0:26 1 (const int)
0:34 Function Definition: foo( (void)
0:34 Function Parameters:
0:36 Sequence
0:36 Test condition and select (void)
0:36 Condition
0:36 logical-or (bool)
0:36 Compare Not Equal (bool)
0:36 Constant:
0:36 -0.625000
0:36 -0.500000
0:36 -0.375000
0:36 -0.250000
0:36 -0.375000
0:36 -0.250000
0:36 -0.125000
0:36 0.000000
0:36 direct index (layout(location=0 ) 2X4 matrix of double)
0:36 'vs_tcs_first' (layout(location=0 ) in 32-element array of 2X4 matrix of double)
0:36 Constant:
0:36 0 (const int)
0:37 Compare Not Equal (bool)
0:37 Constant:
0:37 0.375000
0:37 0.500000
0:37 0.625000
0:37 0.750000
0:37 0.625000
0:37 0.750000
0:37 0.875000
0:37 -0.625000
0:37 direct index (layout(location=12 ) 2X4 matrix of double)
0:37 'vs_tcs_last' (layout(location=12 ) in 32-element array of 2X4 matrix of double)
0:37 Constant:
0:37 0 (const int)
0:36 true case is null
0:? Linker Objects
0:? 'gl_out' (out 4-element array of block{out 4-component vector of float gl_Position, out float gl_PointSize, out 1-element array of float gl_ClipDistance})
0:? 'outa' (4-element array of int)
@ -1242,6 +1316,8 @@ vertices = 4
0:? 'outb' (out 5-element array of int)
0:? 'outc' (out 4-element array of int)
0:? 'outf' (out float)
0:? 'vs_tcs_first' (layout(location=0 ) in 32-element array of 2X4 matrix of double)
0:? 'vs_tcs_last' (layout(location=12 ) in 32-element array of 2X4 matrix of double)
Shader version: 420
Requested GL_ARB_separate_shader_objects
Requested GL_ARB_tessellation_shader

View File

@ -1,5 +1,5 @@
420.tesc
Warning, version 400 is not yet complete; most version-specific features are present, but some are missing.
Warning, version 420 is not yet complete; most version-specific features are present, but some are missing.
ERROR: 0:7: 'vertices' : inconsistent output number of vertices for array size of gl_out
ERROR: 0:11: 'vertices' : inconsistent output number of vertices for array size of a
ERROR: 0:12: 'vertices' : inconsistent output number of vertices for array size of outb
@ -9,7 +9,7 @@ ERROR: 0:29: 'out' : type must be an array: outf
ERROR: 6 compilation errors. No code generated.
Shader version: 400
Shader version: 420
Requested GL_ARB_separate_shader_objects
vertices = 4
ERROR: node is still EOpNull!
@ -74,18 +74,55 @@ ERROR: node is still EOpNull!
0:26 'gl_out' (out 3-element array of block{out 4-component vector of float gl_Position})
0:26 Constant:
0:26 1 (const int)
0:34 Function Definition: foo( (void)
0:34 Function Parameters:
0:36 Sequence
0:36 Test condition and select (void)
0:36 Condition
0:36 logical-or (bool)
0:36 Compare Not Equal (bool)
0:36 Constant:
0:36 -0.625000
0:36 -0.500000
0:36 -0.375000
0:36 -0.250000
0:36 -0.375000
0:36 -0.250000
0:36 -0.125000
0:36 0.000000
0:36 direct index (layout(location=0 ) 2X4 matrix of double)
0:36 'vs_tcs_first' (layout(location=0 ) in 32-element array of 2X4 matrix of double)
0:36 Constant:
0:36 0 (const int)
0:37 Compare Not Equal (bool)
0:37 Constant:
0:37 0.375000
0:37 0.500000
0:37 0.625000
0:37 0.750000
0:37 0.625000
0:37 0.750000
0:37 0.875000
0:37 -0.625000
0:37 direct index (layout(location=12 ) 2X4 matrix of double)
0:37 'vs_tcs_last' (layout(location=12 ) in 32-element array of 2X4 matrix of double)
0:37 Constant:
0:37 0 (const int)
0:36 true case is null
0:? Linker Objects
0:? 'gl_out' (out 3-element array of block{out 4-component vector of float gl_Position})
0:? 'a' (out 3-element array of int)
0:? 'outb' (out 5-element array of int)
0:? 'outc' (out 4-element array of int)
0:? 'outf' (out float)
0:? 'vs_tcs_first' (layout(location=0 ) in 32-element array of 2X4 matrix of double)
0:? 'vs_tcs_last' (layout(location=12 ) in 32-element array of 2X4 matrix of double)
Linked tessellation control stage:
Shader version: 400
Shader version: 420
Requested GL_ARB_separate_shader_objects
vertices = 4
ERROR: node is still EOpNull!
@ -150,10 +187,47 @@ ERROR: node is still EOpNull!
0:26 'gl_out' (out 3-element array of block{out 4-component vector of float gl_Position})
0:26 Constant:
0:26 1 (const int)
0:34 Function Definition: foo( (void)
0:34 Function Parameters:
0:36 Sequence
0:36 Test condition and select (void)
0:36 Condition
0:36 logical-or (bool)
0:36 Compare Not Equal (bool)
0:36 Constant:
0:36 -0.625000
0:36 -0.500000
0:36 -0.375000
0:36 -0.250000
0:36 -0.375000
0:36 -0.250000
0:36 -0.125000
0:36 0.000000
0:36 direct index (layout(location=0 ) 2X4 matrix of double)
0:36 'vs_tcs_first' (layout(location=0 ) in 32-element array of 2X4 matrix of double)
0:36 Constant:
0:36 0 (const int)
0:37 Compare Not Equal (bool)
0:37 Constant:
0:37 0.375000
0:37 0.500000
0:37 0.625000
0:37 0.750000
0:37 0.625000
0:37 0.750000
0:37 0.875000
0:37 -0.625000
0:37 direct index (layout(location=12 ) 2X4 matrix of double)
0:37 'vs_tcs_last' (layout(location=12 ) in 32-element array of 2X4 matrix of double)
0:37 Constant:
0:37 0 (const int)
0:36 true case is null
0:? Linker Objects
0:? 'gl_out' (out 3-element array of block{out 4-component vector of float gl_Position})
0:? 'a' (out 3-element array of int)
0:? 'outb' (out 5-element array of int)
0:? 'outc' (out 4-element array of int)
0:? 'outf' (out float)
0:? 'vs_tcs_first' (layout(location=0 ) in 32-element array of 2X4 matrix of double)
0:? 'vs_tcs_last' (layout(location=12 ) in 32-element array of 2X4 matrix of double)

View File

@ -14,7 +14,8 @@ ERROR: 0:51: 'local_size' : can only apply to 'in'
ERROR: 0:51: 'local_size' : can only apply to 'in'
ERROR: 0:51: 'local_size' : can only apply to 'in'
ERROR: 0:65: 'assign' : l-value required "ro" (can't modify a readonly buffer)
ERROR: 14 compilation errors. No code generated.
ERROR: 0:77: '=' : cannot convert from 'double' to 'int'
ERROR: 15 compilation errors. No code generated.
Shader version: 430
@ -69,6 +70,58 @@ ERROR: node is still EOpNull!
0:66 Constant:
0:66 1 (const int)
0:67 Barrier (void)
0:72 Function Definition: fooaoeu( (void)
0:72 Function Parameters:
0:73 Sequence
0:73 Sequence
0:73 move second child to first child (2-component vector of int)
0:73 'storePos' (2-component vector of int)
0:73 Convert uint to int (2-component vector of int)
0:73 vector swizzle (2-component vector of uint)
0:73 'gl_GlobalInvocationID' (in 3-component vector of uint)
0:73 Sequence
0:73 Constant:
0:73 0 (const int)
0:73 Constant:
0:73 1 (const int)
0:74 Sequence
0:74 move second child to first child (double)
0:74 'localCoef' (double)
0:74 Convert float to double (double)
0:74 length (float)
0:74 divide (2-component vector of float)
0:74 Convert int to float (2-component vector of float)
0:74 subtract (2-component vector of int)
0:74 Convert uint to int (2-component vector of int)
0:74 vector swizzle (2-component vector of uint)
0:74 'gl_LocalInvocationID' (in 3-component vector of uint)
0:74 Sequence
0:74 Constant:
0:74 0 (const int)
0:74 Constant:
0:74 1 (const int)
0:74 Constant:
0:74 8 (const int)
0:74 Constant:
0:74 8.000000
0:75 Sequence
0:75 move second child to first child (4-component vector of double)
0:75 'aa' (4-component vector of double)
0:75 Constant:
0:75 0.400000
0:75 0.200000
0:75 0.300000
0:75 0.400000
0:76 Sequence
0:76 move second child to first child (double)
0:76 'globalCoef' (double)
0:76 Constant:
0:76 1.000000
0:78 Sequence
0:78 move second child to first child (double)
0:78 'di' (double)
0:78 Convert int to double (double)
0:78 'i' (int)
0:? Linker Objects
0:? 'gl_WorkGroupSize' (const 3-component vector of uint)
0:? 2 (const uint)
@ -88,6 +141,8 @@ ERROR: node is still EOpNull!
0:? 'arrY' (1-element array of int)
0:? 'arrZ' (4096-element array of int)
0:? 'ro' (layout(column_major shared ) readonly buffer block{layout(column_major shared ) buffer int value, layout(column_major shared ) buffer implicitly-sized array of float values})
0:? 'roll' (uniform double)
0:? 'destTex' (writeonly uniform image2D)
Linked compute stage:
@ -145,6 +200,58 @@ ERROR: node is still EOpNull!
0:66 Constant:
0:66 1 (const int)
0:67 Barrier (void)
0:72 Function Definition: fooaoeu( (void)
0:72 Function Parameters:
0:73 Sequence
0:73 Sequence
0:73 move second child to first child (2-component vector of int)
0:73 'storePos' (2-component vector of int)
0:73 Convert uint to int (2-component vector of int)
0:73 vector swizzle (2-component vector of uint)
0:73 'gl_GlobalInvocationID' (in 3-component vector of uint)
0:73 Sequence
0:73 Constant:
0:73 0 (const int)
0:73 Constant:
0:73 1 (const int)
0:74 Sequence
0:74 move second child to first child (double)
0:74 'localCoef' (double)
0:74 Convert float to double (double)
0:74 length (float)
0:74 divide (2-component vector of float)
0:74 Convert int to float (2-component vector of float)
0:74 subtract (2-component vector of int)
0:74 Convert uint to int (2-component vector of int)
0:74 vector swizzle (2-component vector of uint)
0:74 'gl_LocalInvocationID' (in 3-component vector of uint)
0:74 Sequence
0:74 Constant:
0:74 0 (const int)
0:74 Constant:
0:74 1 (const int)
0:74 Constant:
0:74 8 (const int)
0:74 Constant:
0:74 8.000000
0:75 Sequence
0:75 move second child to first child (4-component vector of double)
0:75 'aa' (4-component vector of double)
0:75 Constant:
0:75 0.400000
0:75 0.200000
0:75 0.300000
0:75 0.400000
0:76 Sequence
0:76 move second child to first child (double)
0:76 'globalCoef' (double)
0:76 Constant:
0:76 1.000000
0:78 Sequence
0:78 move second child to first child (double)
0:78 'di' (double)
0:78 Convert int to double (double)
0:78 'i' (int)
0:? Linker Objects
0:? 'gl_WorkGroupSize' (const 3-component vector of uint)
0:? 2 (const uint)
@ -164,4 +271,6 @@ ERROR: node is still EOpNull!
0:? 'arrY' (1-element array of int)
0:? 'arrZ' (4096-element array of int)
0:? 'ro' (layout(column_major shared ) readonly buffer block{layout(column_major shared ) buffer int value, layout(column_major shared ) buffer implicitly-sized array of float values})
0:? 'roll' (uniform double)
0:? 'destTex' (writeonly uniform image2D)

View File

@ -426,6 +426,9 @@ TIntermTyped* TIntermediate::addConversion(TOperator op, const TType& type, TInt
case EOpConstructFloat:
promoteTo = EbtFloat;
break;
case EOpConstructDouble:
promoteTo = EbtDouble;
break;
case EOpConstructInt:
promoteTo = EbtInt;
break;
@ -1482,7 +1485,7 @@ TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermC
leftUnionArray[i] = rightUnionArray[i];
break;
case EbtDouble:
leftUnionArray[i].setDConst(static_cast<double>(rightUnionArray[i].getBConst()));
leftUnionArray[i].setDConst(static_cast<double>(rightUnionArray[i].getDConst()));
break;
default:
return node;

View File

@ -298,6 +298,7 @@ bool TOutputTraverser::visitAggregate(TVisit /* visit */, TIntermAggregate* node
case EOpParameters: out.debug << "Function Parameters: "; break;
case EOpConstructFloat: out.debug << "Construct float"; break;
case EOpConstructDouble:out.debug << "Construct double"; break;
case EOpConstructVec2: out.debug << "Construct vec2"; break;
case EOpConstructVec3: out.debug << "Construct vec3"; break;
case EOpConstructVec4: out.debug << "Construct vec4"; break;

View File

@ -134,12 +134,14 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken)
declen++;
if (len > 0 || ch != '0') {
str[len] = ch;
len++;str_len++;
len++;
str_len++;
}
ch = getChar();
} else {
parseContext.error(ppToken->loc, "float literal too long", "", "");
len = 1,str_len=1;
len = 1;
str_len = 1;
}
}
}