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
diff --git a/SPIRV/SpvBuilder.cpp b/SPIRV/SpvBuilder.cpp
index c20202e..6b7f3d6 100644
--- a/SPIRV/SpvBuilder.cpp
+++ b/SPIRV/SpvBuilder.cpp
@@ -441,7 +441,8 @@
     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 @@
     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::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

diff --git a/SPIRV/SpvBuilder.h b/SPIRV/SpvBuilder.h
index be6abd9..b4417df 100644
--- a/SPIRV/SpvBuilder.h
+++ b/SPIRV/SpvBuilder.h
@@ -462,6 +462,7 @@
 

 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();

diff --git a/Test/420.tesc b/Test/420.tesc
index dcee3ca..432bb36 100644
--- a/Test/420.tesc
+++ b/Test/420.tesc
@@ -1,4 +1,4 @@
-#version 400 core

+#version 420 core

 

 #extension GL_ARB_separate_shader_objects : enable

 

@@ -27,3 +27,15 @@
 }

 

 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]))

+    {

+        ;

+    }

+}
\ No newline at end of file
diff --git a/Test/430.comp b/Test/430.comp
index 53b4617..93ecd1c 100644
--- a/Test/430.comp
+++ b/Test/430.comp
@@ -62,7 +62,18 @@
 

 void foo()

 {

-    ro.values[2] = 4.7;        // ERROR, readonly

+    ro.values[2] = 4.7;             // ERROR, readonly

     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;

+}

diff --git a/Test/baseResults/150.tesc.out b/Test/baseResults/150.tesc.out
index 1281be8..053cbdd 100644
--- a/Test/baseResults/150.tesc.out
+++ b/Test/baseResults/150.tesc.out
@@ -603,7 +603,7 @@
 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: 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 @@
 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.

@@ -867,6 +904,8 @@
 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:

     gl_out: "out 4-element array of block{out 4-component vector of float gl_Position, out float gl_PointSize, out implicitly-sized array of float gl_ClipDistance}" versus "out 3-element array of block{out 4-component vector of float gl_Position}"

@@ -883,7 +922,7 @@
 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 @@
 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 @@
 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

diff --git a/Test/baseResults/420.tesc.out b/Test/baseResults/420.tesc.out
index c7754a6..1aabe3e 100644
--- a/Test/baseResults/420.tesc.out
+++ b/Test/baseResults/420.tesc.out
@@ -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: 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 @@
 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 @@
 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)

 

diff --git a/Test/baseResults/430.comp.out b/Test/baseResults/430.comp.out
index 0453641..2e2e7e4 100644
--- a/Test/baseResults/430.comp.out
+++ b/Test/baseResults/430.comp.out
@@ -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: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 @@
 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 @@
 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 @@
 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 @@
 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)

 

diff --git a/glslang/MachineIndependent/Intermediate.cpp b/glslang/MachineIndependent/Intermediate.cpp
index 883337d..40da8d6 100644
--- a/glslang/MachineIndependent/Intermediate.cpp
+++ b/glslang/MachineIndependent/Intermediate.cpp
@@ -426,6 +426,9 @@
     case EOpConstructFloat:
         promoteTo = EbtFloat;
         break;
+    case EOpConstructDouble:
+        promoteTo = EbtDouble;
+        break;
     case EOpConstructInt:
         promoteTo = EbtInt;
         break;
@@ -1482,7 +1485,7 @@
                 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;
diff --git a/glslang/MachineIndependent/intermOut.cpp b/glslang/MachineIndependent/intermOut.cpp
index 9211b1e..681a9ee 100644
--- a/glslang/MachineIndependent/intermOut.cpp
+++ b/glslang/MachineIndependent/intermOut.cpp
@@ -298,6 +298,7 @@
     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;
diff --git a/glslang/MachineIndependent/preprocessor/PpScanner.cpp b/glslang/MachineIndependent/preprocessor/PpScanner.cpp
index afeff0f..e0f3b55 100644
--- a/glslang/MachineIndependent/preprocessor/PpScanner.cpp
+++ b/glslang/MachineIndependent/preprocessor/PpScanner.cpp
@@ -134,12 +134,14 @@
                 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;
             }
         }
     }