From c08fb8ab9c0d3aeafe11a8eeeed177c882ef76a9 Mon Sep 17 00:00:00 2001
From: John Kessenich <cepheus@frii.com>
Date: Tue, 14 Mar 2017 16:45:30 -0600
Subject: [PATCH] Full stack: properly implement GL_EXT_device_group and
 GL_EXT_multiview.

---
 Test/140.vert                             | 20 ++++++
 Test/310.comp                             | 16 +++++
 Test/310.frag                             | 20 ++++++
 Test/400.tesc                             | 20 ++++++
 Test/400.tese                             | 20 ++++++
 Test/baseResults/140.vert.out             | 18 +++++-
 Test/baseResults/150.tesc.out             | 36 ++++++++++-
 Test/baseResults/310.comp.out             | 17 ++++-
 Test/baseResults/310.frag.out             | 18 +++++-
 Test/baseResults/400.tesc.out             | 18 +++++-
 Test/baseResults/400.tese.out             | 18 +++++-
 Test/baseResults/spv.310.comp.out         | 21 ++++---
 Test/baseResults/spv.deviceGroup.frag.out |  7 ++-
 Test/baseResults/spv.multiView.frag.out   |  7 ++-
 Test/spv.310.comp                         |  3 +
 glslang/Include/BaseTypes.h               |  4 ++
 glslang/Include/revision.h                |  2 +-
 glslang/MachineIndependent/Initialize.cpp | 76 ++++++++++++++++++++---
 glslang/MachineIndependent/Versions.cpp   |  8 +++
 19 files changed, 319 insertions(+), 30 deletions(-)

diff --git a/Test/140.vert b/Test/140.vert
index 380d30e7c..914e672d8 100644
--- a/Test/140.vert
+++ b/Test/140.vert
@@ -57,3 +57,23 @@ void foo()
     v += textureProjGradOffset(s2dr, tloc4, ivec2(0.0), ivec2(0.0), ivec2(1,2));
     v += textureProjGradOffset(s2drs, tloc4, ivec2(0.0), ivec2(0.0), ivec2(1,2));
 }
+
+void devi()
+{
+    gl_DeviceIndex; // ERROR, no extension
+    gl_ViewIndex;   // ERROR, no extension
+}
+
+#ifdef GL_EXT_device_group
+#extension GL_EXT_device_group : enable
+#endif
+
+#ifdef GL_EXT_device_group
+#extension GL_EXT_multiview : enable
+#endif
+
+void devie()
+{
+    gl_DeviceIndex;
+    gl_ViewIndex;
+}
diff --git a/Test/310.comp b/Test/310.comp
index 3252728c8..9575b6f9d 100644
--- a/Test/310.comp
+++ b/Test/310.comp
@@ -238,3 +238,19 @@ float t__;  // ERROR, no __ until revision 310
 #define __D
 
 shared vec4 arr[2][3][4];
+
+void devi()
+{
+    gl_DeviceIndex; // ERROR, no extension
+    gl_ViewIndex;   // ERROR, never this stage
+}
+
+#ifdef GL_EXT_device_group
+#extension GL_EXT_device_group : enable
+#endif
+
+void devie()
+{
+    gl_DeviceIndex;
+    gl_ViewIndex;   // ERROR, never this stage
+}
diff --git a/Test/310.frag b/Test/310.frag
index e9f039500..6814e6c53 100644
--- a/Test/310.frag
+++ b/Test/310.frag
@@ -429,3 +429,23 @@ void blendFoo(layout(blend_support_hsl_luminosity) vec3 v) { } // ERROR, only on
 layout(blend_support_flizbit) out;                             // ERROR, no flizbit
 
 out vec4 outAA[2][2];  // ERROR
+
+void devi()
+{
+    gl_DeviceIndex; // ERROR, no extension
+    gl_ViewIndex;   // ERROR, no extension
+}
+
+#ifdef GL_EXT_device_group
+#extension GL_EXT_device_group : enable
+#endif
+
+#ifdef GL_EXT_device_group
+#extension GL_EXT_multiview : enable
+#endif
+
+void devie()
+{
+    gl_DeviceIndex;
+    gl_ViewIndex;
+}
diff --git a/Test/400.tesc b/Test/400.tesc
index d01bd3ea1..415d7f7d7 100644
--- a/Test/400.tesc
+++ b/Test/400.tesc
@@ -103,3 +103,23 @@ patch out pinbn {
 
 invariant precise out vec4 badOrder[]; // ERROR, precise must appear first
 void badp(out precise float f);        // ERROR, precise must appear first
+
+void devi()
+{
+    gl_DeviceIndex; // ERROR, no extension
+    gl_ViewIndex;   // ERROR, no extension
+}
+
+#ifdef GL_EXT_device_group
+#extension GL_EXT_device_group : enable
+#endif
+
+#ifdef GL_EXT_device_group
+#extension GL_EXT_multiview : enable
+#endif
+
+void devie()
+{
+    gl_DeviceIndex;
+    gl_ViewIndex;
+}
diff --git a/Test/400.tese b/Test/400.tese
index a1d3ed828..aea454651 100644
--- a/Test/400.tese
+++ b/Test/400.tese
@@ -103,3 +103,23 @@ in float gl_TessLevelOuter[4];           // ERROR, can't redeclare
 patch in pinbn {
     int a;
 } pinbi;
+
+void devi()
+{
+    gl_DeviceIndex; // ERROR, no extension
+    gl_ViewIndex;   // ERROR, no extension
+}
+
+#ifdef GL_EXT_device_group
+#extension GL_EXT_device_group : enable
+#endif
+
+#ifdef GL_EXT_device_group
+#extension GL_EXT_multiview : enable
+#endif
+
+void devie()
+{
+    gl_DeviceIndex;
+    gl_ViewIndex;
+}
diff --git a/Test/baseResults/140.vert.out b/Test/baseResults/140.vert.out
index e7f88e320..0f2a06322 100644
--- a/Test/baseResults/140.vert.out
+++ b/Test/baseResults/140.vert.out
@@ -9,12 +9,16 @@ ERROR: 0:38: 'gl_ClipVertex' : cannot redeclare after use
 ERROR: 0:39: 'gl_FogFragCoord' : cannot redeclare after use 
 ERROR: 0:51: 'texelFetch' : no matching overloaded function found 
 ERROR: 0:53: 'texture' : no matching overloaded function found 
-ERROR: 10 compilation errors.  No code generated.
+ERROR: 0:63: 'gl_DeviceIndex' : required extension not requested: GL_EXT_device_group
+ERROR: 0:64: 'gl_ViewIndex' : required extension not requested: GL_EXT_multiview
+ERROR: 12 compilation errors.  No code generated.
 
 
 Shader version: 140
 Requested GL_ARB_explicit_attrib_location
 Requested GL_ARB_separate_shader_objects
+Requested GL_EXT_device_group
+Requested GL_EXT_multiview
 ERROR: node is still EOpNull!
 0:9  Function Definition: main( (global void)
 0:9    Function Parameters: 
@@ -116,6 +120,16 @@ ERROR: node is still EOpNull!
 0:58          Constant:
 0:58            1 (const int)
 0:58            2 (const int)
+0:61  Function Definition: devi( (global void)
+0:61    Function Parameters: 
+0:63    Sequence
+0:63      'gl_DeviceIndex' (in int DeviceIndex)
+0:64      'gl_ViewIndex' (in int ViewIndex)
+0:75  Function Definition: devie( (global void)
+0:75    Function Parameters: 
+0:77    Sequence
+0:77      'gl_DeviceIndex' (in int DeviceIndex)
+0:78      'gl_ViewIndex' (in int ViewIndex)
 0:?   Linker Objects
 0:?     'sbuf' (uniform isamplerBuffer)
 0:?     'anon@0' (layout(column_major std140 ) uniform block{layout(column_major std140 offset=0 ) uniform int anonMem})
@@ -142,6 +156,8 @@ Linked vertex stage:
 Shader version: 140
 Requested GL_ARB_explicit_attrib_location
 Requested GL_ARB_separate_shader_objects
+Requested GL_EXT_device_group
+Requested GL_EXT_multiview
 ERROR: node is still EOpNull!
 0:9  Function Definition: main( (global void)
 0:9    Function Parameters: 
diff --git a/Test/baseResults/150.tesc.out b/Test/baseResults/150.tesc.out
index 21fade77b..40bf08024 100644
--- a/Test/baseResults/150.tesc.out
+++ b/Test/baseResults/150.tesc.out
@@ -232,11 +232,15 @@ ERROR: 0:87: 'location' : overlapping use of location 4
 ERROR: 0:104: '' : precise qualifier must appear first 
 ERROR: 0:105: '' : precise qualifier must appear first 
 ERROR: 0:105: '' : precise qualifier must appear first 
-ERROR: 21 compilation errors.  No code generated.
+ERROR: 0:109: 'gl_DeviceIndex' : required extension not requested: GL_EXT_device_group
+ERROR: 0:110: 'gl_ViewIndex' : required extension not requested: GL_EXT_multiview
+ERROR: 23 compilation errors.  No code generated.
 
 
 Shader version: 400
 Requested GL_ARB_separate_shader_objects
+Requested GL_EXT_device_group
+Requested GL_EXT_multiview
 vertices = 4
 ERROR: node is still EOpNull!
 0:13  Function Definition: main( (global void)
@@ -408,6 +412,16 @@ ERROR: node is still EOpNull!
 0:97          'd' (noContraction temp double)
 0:97          'd' (noContraction temp double)
 0:97          'd' (noContraction temp double)
+0:107  Function Definition: devi( (global void)
+0:107    Function Parameters: 
+0:109    Sequence
+0:109      'gl_DeviceIndex' (in int DeviceIndex)
+0:110      'gl_ViewIndex' (in int ViewIndex)
+0:121  Function Definition: devie( (global void)
+0:121    Function Parameters: 
+0:123    Sequence
+0:123      'gl_DeviceIndex' (in int DeviceIndex)
+0:124      'gl_ViewIndex' (in int ViewIndex)
 0:?   Linker Objects
 0:?     'gl_out' (out 4-element array of block{out 4-component vector of float Position gl_Position, out float PointSize gl_PointSize, out implicitly-sized array of float ClipDistance gl_ClipDistance})
 0:?     'outa' (global 4-element array of int)
@@ -459,11 +473,15 @@ ERROR: 0:86: '[]' : tessellation input array size must be gl_MaxPatchVertices or
 ERROR: 0:96: 'location' : overlapping use of location 24
 ERROR: 0:99: 'location' : overlapping use of location 24
 ERROR: 0:101: 'gl_TessLevelOuter' : identifiers starting with "gl_" are reserved 
-ERROR: 30 compilation errors.  No code generated.
+ERROR: 0:109: 'gl_DeviceIndex' : required extension not requested: GL_EXT_device_group
+ERROR: 0:110: 'gl_ViewIndex' : required extension not requested: GL_EXT_multiview
+ERROR: 32 compilation errors.  No code generated.
 
 
 Shader version: 400
 Requested GL_ARB_separate_shader_objects
+Requested GL_EXT_device_group
+Requested GL_EXT_multiview
 input primitive = quads
 vertex spacing = fractional_odd_spacing
 triangle order = cw
@@ -559,6 +577,16 @@ ERROR: node is still EOpNull!
 0:44          Constant:
 0:44            2 (const int)
 0:44        'cd' (temp float)
+0:107  Function Definition: devi( (global void)
+0:107    Function Parameters: 
+0:109    Sequence
+0:109      'gl_DeviceIndex' (in int DeviceIndex)
+0:110      'gl_ViewIndex' (in int ViewIndex)
+0:121  Function Definition: devie( (global void)
+0:121    Function Parameters: 
+0:123    Sequence
+0:123      'gl_DeviceIndex' (in int DeviceIndex)
+0:124      'gl_ViewIndex' (in int ViewIndex)
 0:?   Linker Objects
 0:?     'patchIn' (patch in 4-component vector of float)
 0:?     'patchOut' (patch out 4-component vector of float)
@@ -952,6 +980,8 @@ ERROR: Linking tessellation evaluation stage: Multiple function bodies in multip
 Shader version: 420
 Requested GL_ARB_separate_shader_objects
 Requested GL_ARB_tessellation_shader
+Requested GL_EXT_device_group
+Requested GL_EXT_multiview
 vertices = 4
 0:? Sequence
 0:10  Function Definition: main( (global void)
@@ -1277,6 +1307,8 @@ vertices = 4
 Shader version: 420
 Requested GL_ARB_separate_shader_objects
 Requested GL_ARB_tessellation_shader
+Requested GL_EXT_device_group
+Requested GL_EXT_multiview
 input primitive = quads
 vertex spacing = fractional_odd_spacing
 triangle order = cw
diff --git a/Test/baseResults/310.comp.out b/Test/baseResults/310.comp.out
index e063626dd..2ff29f174 100644
--- a/Test/baseResults/310.comp.out
+++ b/Test/baseResults/310.comp.out
@@ -81,10 +81,14 @@ ERROR: 0:227: 'input block' : not supported in this stage: compute
 ERROR: 0:231: 'output block' : not supported in this stage: compute
 WARNING: 0:235: 't__' : identifiers containing consecutive underscores ("__") are reserved 
 WARNING: 0:238: '#define' : names containing consecutive underscores are reserved: __D
-ERROR: 79 compilation errors.  No code generated.
+ERROR: 0:244: 'gl_DeviceIndex' : required extension not requested: GL_EXT_device_group
+ERROR: 0:245: 'gl_ViewIndex' : undeclared identifier 
+ERROR: 0:255: 'gl_ViewIndex' : undeclared identifier 
+ERROR: 82 compilation errors.  No code generated.
 
 
 Shader version: 310
+Requested GL_EXT_device_group
 local_size = (2, 1, 4096)
 ERROR: node is still EOpNull!
 0:27  Function Definition: main( (global void)
@@ -443,6 +447,16 @@ ERROR: node is still EOpNull!
 0:224            0 (const int)
 0:224        Constant:
 0:224          2 (const int)
+0:242  Function Definition: devi( (global void)
+0:242    Function Parameters: 
+0:244    Sequence
+0:244      'gl_DeviceIndex' (in highp int DeviceIndex)
+0:245      'gl_ViewIndex' (temp float)
+0:252  Function Definition: devie( (global void)
+0:252    Function Parameters: 
+0:254    Sequence
+0:254      'gl_DeviceIndex' (in highp int DeviceIndex)
+0:255      'gl_ViewIndex' (temp float)
 0:?   Linker Objects
 0:?     'gl_WorkGroupSize' (const highp 3-component vector of uint WorkGroupSize)
 0:?       2 (const uint)
@@ -512,6 +526,7 @@ Linked compute stage:
 
 
 Shader version: 310
+Requested GL_EXT_device_group
 local_size = (2, 1, 4096)
 ERROR: node is still EOpNull!
 0:27  Function Definition: main( (global void)
diff --git a/Test/baseResults/310.frag.out b/Test/baseResults/310.frag.out
index 7033d4f3f..25c96156e 100644
--- a/Test/baseResults/310.frag.out
+++ b/Test/baseResults/310.frag.out
@@ -133,10 +133,14 @@ ERROR: 0:427: 'blend equation' : can only apply to a standalone qualifier
 ERROR: 0:428: 'blend equation' : can only apply to a standalone qualifier 
 ERROR: 0:429: 'blend_support' : unknown blend equation 
 ERROR: 0:431: 'fragment-shader array-of-array output' : not supported with this profile: es
-ERROR: 125 compilation errors.  No code generated.
+ERROR: 0:435: 'gl_DeviceIndex' : required extension not requested: GL_EXT_device_group
+ERROR: 0:436: 'gl_ViewIndex' : required extension not requested: GL_EXT_multiview
+ERROR: 127 compilation errors.  No code generated.
 
 
 Shader version: 310
+Requested GL_EXT_device_group
+Requested GL_EXT_multiview
 Requested GL_EXT_shader_io_blocks
 Requested GL_EXT_texture_cube_map_array
 Requested GL_KHR_blend_equation_advanced
@@ -916,6 +920,16 @@ ERROR: node is still EOpNull!
 0:428  Function Definition: blendFoo(vf3; (global void)
 0:428    Function Parameters: 
 0:428      'v' (in mediump 3-component vector of float)
+0:433  Function Definition: devi( (global void)
+0:433    Function Parameters: 
+0:435    Sequence
+0:435      'gl_DeviceIndex' (flat in highp int DeviceIndex)
+0:436      'gl_ViewIndex' (flat in highp int ViewIndex)
+0:447  Function Definition: devie( (global void)
+0:447    Function Parameters: 
+0:449    Sequence
+0:449      'gl_DeviceIndex' (flat in highp int DeviceIndex)
+0:450      'gl_ViewIndex' (flat in highp int ViewIndex)
 0:?   Linker Objects
 0:?     'gl_FragCoord' (smooth in mediump 4-component vector of float)
 0:?     'v3' (layout(location=2 ) smooth in mediump 3-component vector of float)
@@ -1017,6 +1031,8 @@ Linked fragment stage:
 ERROR: Linking fragment stage: when more than one fragment shader output, all must have location qualifiers
 
 Shader version: 310
+Requested GL_EXT_device_group
+Requested GL_EXT_multiview
 Requested GL_EXT_shader_io_blocks
 Requested GL_EXT_texture_cube_map_array
 Requested GL_KHR_blend_equation_advanced
diff --git a/Test/baseResults/400.tesc.out b/Test/baseResults/400.tesc.out
index f3e7b8bb6..027d58f86 100644
--- a/Test/baseResults/400.tesc.out
+++ b/Test/baseResults/400.tesc.out
@@ -21,11 +21,15 @@ ERROR: 0:87: 'location' : overlapping use of location 4
 ERROR: 0:104: '' : precise qualifier must appear first 
 ERROR: 0:105: '' : precise qualifier must appear first 
 ERROR: 0:105: '' : precise qualifier must appear first 
-ERROR: 21 compilation errors.  No code generated.
+ERROR: 0:109: 'gl_DeviceIndex' : required extension not requested: GL_EXT_device_group
+ERROR: 0:110: 'gl_ViewIndex' : required extension not requested: GL_EXT_multiview
+ERROR: 23 compilation errors.  No code generated.
 
 
 Shader version: 400
 Requested GL_ARB_separate_shader_objects
+Requested GL_EXT_device_group
+Requested GL_EXT_multiview
 vertices = 4
 ERROR: node is still EOpNull!
 0:13  Function Definition: main( (global void)
@@ -197,6 +201,16 @@ ERROR: node is still EOpNull!
 0:97          'd' (noContraction temp double)
 0:97          'd' (noContraction temp double)
 0:97          'd' (noContraction temp double)
+0:107  Function Definition: devi( (global void)
+0:107    Function Parameters: 
+0:109    Sequence
+0:109      'gl_DeviceIndex' (in int DeviceIndex)
+0:110      'gl_ViewIndex' (in int ViewIndex)
+0:121  Function Definition: devie( (global void)
+0:121    Function Parameters: 
+0:123    Sequence
+0:123      'gl_DeviceIndex' (in int DeviceIndex)
+0:124      'gl_ViewIndex' (in int ViewIndex)
 0:?   Linker Objects
 0:?     'gl_out' (out 4-element array of block{out 4-component vector of float Position gl_Position, out float PointSize gl_PointSize, out implicitly-sized array of float ClipDistance gl_ClipDistance})
 0:?     'outa' (global 4-element array of int)
@@ -222,6 +236,8 @@ Linked tessellation control stage:
 
 Shader version: 400
 Requested GL_ARB_separate_shader_objects
+Requested GL_EXT_device_group
+Requested GL_EXT_multiview
 vertices = 4
 ERROR: node is still EOpNull!
 0:13  Function Definition: main( (global void)
diff --git a/Test/baseResults/400.tese.out b/Test/baseResults/400.tese.out
index 324dbaa30..363ad96d7 100644
--- a/Test/baseResults/400.tese.out
+++ b/Test/baseResults/400.tese.out
@@ -30,11 +30,15 @@ ERROR: 0:86: '[]' : tessellation input array size must be gl_MaxPatchVertices or
 ERROR: 0:96: 'location' : overlapping use of location 24
 ERROR: 0:99: 'location' : overlapping use of location 24
 ERROR: 0:101: 'gl_TessLevelOuter' : identifiers starting with "gl_" are reserved 
-ERROR: 30 compilation errors.  No code generated.
+ERROR: 0:109: 'gl_DeviceIndex' : required extension not requested: GL_EXT_device_group
+ERROR: 0:110: 'gl_ViewIndex' : required extension not requested: GL_EXT_multiview
+ERROR: 32 compilation errors.  No code generated.
 
 
 Shader version: 400
 Requested GL_ARB_separate_shader_objects
+Requested GL_EXT_device_group
+Requested GL_EXT_multiview
 input primitive = quads
 vertex spacing = fractional_odd_spacing
 triangle order = cw
@@ -130,6 +134,16 @@ ERROR: node is still EOpNull!
 0:44          Constant:
 0:44            2 (const int)
 0:44        'cd' (temp float)
+0:107  Function Definition: devi( (global void)
+0:107    Function Parameters: 
+0:109    Sequence
+0:109      'gl_DeviceIndex' (in int DeviceIndex)
+0:110      'gl_ViewIndex' (in int ViewIndex)
+0:121  Function Definition: devie( (global void)
+0:121    Function Parameters: 
+0:123    Sequence
+0:123      'gl_DeviceIndex' (in int DeviceIndex)
+0:124      'gl_ViewIndex' (in int ViewIndex)
 0:?   Linker Objects
 0:?     'patchIn' (patch in 4-component vector of float)
 0:?     'patchOut' (patch out 4-component vector of float)
@@ -160,6 +174,8 @@ Linked tessellation evaluation stage:
 
 Shader version: 400
 Requested GL_ARB_separate_shader_objects
+Requested GL_EXT_device_group
+Requested GL_EXT_multiview
 input primitive = quads
 vertex spacing = fractional_odd_spacing
 triangle order = cw
diff --git a/Test/baseResults/spv.310.comp.out b/Test/baseResults/spv.310.comp.out
index 095bf39fc..4b47c7d76 100644
--- a/Test/baseResults/spv.310.comp.out
+++ b/Test/baseResults/spv.310.comp.out
@@ -3,14 +3,17 @@ Warning, version 310 is not yet complete; most version-specific features are pre
 
 // Module Version 10000
 // Generated by (magic number): 80001
-// Id's are bound by 67
+// Id's are bound by 69
 
                               Capability Shader
+                              Capability DeviceGroup
+                              Extension  "SPV_KHR_device_group"
                1:             ExtInstImport  "GLSL.std.450"
                               MemoryModel Logical GLSL450
-                              EntryPoint GLCompute 4  "main" 53
+                              EntryPoint GLCompute 4  "main" 53 64
                               ExecutionMode 4 LocalSize 16 32 4
                               Source ESSL 310
+                              SourceExtension  "GL_EXT_device_group"
                               Name 4  "main"
                               Name 13  "outb"
                               MemberName 13(outb) 0  "f"
@@ -29,6 +32,7 @@ Warning, version 310 is not yet complete; most version-specific features are pre
                               MemberName 48(outs) 1  "va"
                               Name 50  "outnames"
                               Name 53  "gl_LocalInvocationID"
+                              Name 64  "gl_DeviceIndex"
                               Decorate 12 ArrayStride 16
                               MemberDecorate 13(outb) 0 Offset 0
                               MemberDecorate 13(outb) 1 Offset 4
@@ -46,7 +50,8 @@ Warning, version 310 is not yet complete; most version-specific features are pre
                               Decorate 48(outs) BufferBlock
                               Decorate 50(outnames) DescriptorSet 0
                               Decorate 53(gl_LocalInvocationID) BuiltIn LocalInvocationId
-                              Decorate 66 BuiltIn WorkgroupSize
+                              Decorate 64(gl_DeviceIndex) BuiltIn DeviceIndex
+                              Decorate 68 BuiltIn WorkgroupSize
                2:             TypeVoid
                3:             TypeFunction 2
                6:             TypeInt 32 0
@@ -87,10 +92,12 @@ Warning, version 310 is not yet complete; most version-specific features are pre
 53(gl_LocalInvocationID):     52(ptr) Variable Input
               54:             TypePointer Input 6(int)
               61:             TypePointer Uniform 16(int)
-              63:      6(int) Constant 16
-              64:      6(int) Constant 32
-              65:      6(int) Constant 4
-              66:   51(ivec3) ConstantComposite 63 64 65
+              63:             TypePointer Input 16(int)
+64(gl_DeviceIndex):     63(ptr) Variable Input
+              65:      6(int) Constant 16
+              66:      6(int) Constant 32
+              67:      6(int) Constant 4
+              68:   51(ivec3) ConstantComposite 65 66 67
          4(main):           2 Function None 3
                5:             Label
                               ControlBarrier 7 8 9
diff --git a/Test/baseResults/spv.deviceGroup.frag.out b/Test/baseResults/spv.deviceGroup.frag.out
index 9c2344361..42e045b3c 100755
--- a/Test/baseResults/spv.deviceGroup.frag.out
+++ b/Test/baseResults/spv.deviceGroup.frag.out
@@ -10,13 +10,14 @@ Warning, version 450 is not yet complete; most version-specific features are pre
                               Extension  "SPV_KHR_device_group"
                1:             ExtInstImport  "GLSL.std.450"
                               MemoryModel Logical GLSL450
-                              EntryPoint Fragment 4  "main" 9
+                              EntryPoint Fragment 4  "main" 9 12
                               ExecutionMode 4 OriginUpperLeft
                               Source GLSL 450
                               SourceExtension  "GL_EXT_device_group"
                               Name 4  "main"
                               Name 9  "color"
                               Name 12  "gl_DeviceIndex"
+                              Decorate 12(gl_DeviceIndex) Flat
                               Decorate 12(gl_DeviceIndex) BuiltIn DeviceIndex
                2:             TypeVoid
                3:             TypeFunction 2
@@ -25,8 +26,8 @@ Warning, version 450 is not yet complete; most version-specific features are pre
                8:             TypePointer Output 7(fvec4)
         9(color):      8(ptr) Variable Output
               10:             TypeInt 32 1
-              11:             TypePointer UniformConstant 10(int)
-12(gl_DeviceIndex):     11(ptr) Variable UniformConstant
+              11:             TypePointer Input 10(int)
+12(gl_DeviceIndex):     11(ptr) Variable Input
               15:    6(float) Constant 0
          4(main):           2 Function None 3
                5:             Label
diff --git a/Test/baseResults/spv.multiView.frag.out b/Test/baseResults/spv.multiView.frag.out
index 957161727..de2a54960 100755
--- a/Test/baseResults/spv.multiView.frag.out
+++ b/Test/baseResults/spv.multiView.frag.out
@@ -10,13 +10,14 @@ Warning, version 450 is not yet complete; most version-specific features are pre
                               Extension  "SPV_KHR_multiview"
                1:             ExtInstImport  "GLSL.std.450"
                               MemoryModel Logical GLSL450
-                              EntryPoint Fragment 4  "main" 9
+                              EntryPoint Fragment 4  "main" 9 12
                               ExecutionMode 4 OriginUpperLeft
                               Source GLSL 450
                               SourceExtension  "GL_EXT_multiview"
                               Name 4  "main"
                               Name 9  "color"
                               Name 12  "gl_ViewIndex"
+                              Decorate 12(gl_ViewIndex) Flat
                               Decorate 12(gl_ViewIndex) BuiltIn ViewIndex
                2:             TypeVoid
                3:             TypeFunction 2
@@ -25,8 +26,8 @@ Warning, version 450 is not yet complete; most version-specific features are pre
                8:             TypePointer Output 7(fvec4)
         9(color):      8(ptr) Variable Output
               10:             TypeInt 32 1
-              11:             TypePointer UniformConstant 10(int)
-12(gl_ViewIndex):     11(ptr) Variable UniformConstant
+              11:             TypePointer Input 10(int)
+12(gl_ViewIndex):     11(ptr) Variable Input
               15:    6(float) Constant 0
          4(main):           2 Function None 3
                5:             Label
diff --git a/Test/spv.310.comp b/Test/spv.310.comp
index bd183e042..6cbb0430f 100644
--- a/Test/spv.310.comp
+++ b/Test/spv.310.comp
@@ -24,6 +24,8 @@ buffer outs {
     vec4 va[];
 } outnames;
 
+#extension GL_EXT_device_group : enable
+
 void main()
 {
     barrier();
@@ -34,4 +36,5 @@ void main()
     outbname.uns[i] = vec3(s);
     outnames.va[gl_LocalInvocationID.x] = vec4(s);
     outnames.s = outbname.uns.length();
+    gl_DeviceIndex;
 }
diff --git a/glslang/Include/BaseTypes.h b/glslang/Include/BaseTypes.h
index e9a6ac1bb..230a6b9cb 100644
--- a/glslang/Include/BaseTypes.h
+++ b/glslang/Include/BaseTypes.h
@@ -328,6 +328,10 @@ __inline const char* GetBuiltInVariableString(TBuiltInVariable v)
     case EbvBaryCoordSmoothSample:      return "BaryCoordSmoothSample";
     case EbvBaryCoordPullModel:         return "BaryCoordPullModel";
 #endif
+
+    case EbvViewIndex:                  return "ViewIndex";
+    case EbvDeviceIndex:                return "DeviceIndex";
+
 #ifdef NV_EXTENSIONS
     case EbvViewportMaskNV:             return "ViewportMaskNV";
     case EbvSecondaryPositionNV:        return "SecondaryPositionNV";
diff --git a/glslang/Include/revision.h b/glslang/Include/revision.h
index cba202264..4f419c0b8 100644
--- a/glslang/Include/revision.h
+++ b/glslang/Include/revision.h
@@ -2,5 +2,5 @@
 // For the version, it uses the latest git tag followed by the number of commits.
 // For the date, it uses the current date (when then script is run).
 
-#define GLSLANG_REVISION "Overload400-PrecQual.1908"
+#define GLSLANG_REVISION "Overload400-PrecQual.1909"
 #define GLSLANG_DATE "14-Mar-2017"
diff --git a/glslang/MachineIndependent/Initialize.cpp b/glslang/MachineIndependent/Initialize.cpp
index 60cff6012..f2cba1a10 100644
--- a/glslang/MachineIndependent/Initialize.cpp
+++ b/glslang/MachineIndependent/Initialize.cpp
@@ -3125,6 +3125,13 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
             "\n");
     }
 
+    if ((profile != EEsProfile && version >= 140) ||
+        (profile == EEsProfile && version >= 310)) {
+        stageBuiltins[EShLangCompute].append(
+            "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
+            "\n");
+    }
+
     //============================================================================
     //
     // Define the interface to the vertex shader.
@@ -3290,6 +3297,15 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
         }
     }
 
+    if ((profile != EEsProfile && version >= 140) ||
+        (profile == EEsProfile && version >= 310)) {
+        stageBuiltins[EShLangVertex].append(
+            "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
+            "in highp int gl_ViewIndex;"       // GL_EXT_multiview
+            "\n");
+    }
+
+
     //============================================================================
     //
     // Define the interface to the geometry shader.
@@ -3398,6 +3414,14 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
             );
     }
 
+    if ((profile != EEsProfile && version >= 140) ||
+        (profile == EEsProfile && version >= 310)) {
+        stageBuiltins[EShLangGeometry].append(
+            "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
+            "in highp int gl_ViewIndex;"       // GL_EXT_multiview
+            "\n");
+    }
+
     //============================================================================
     //
     // Define the interface to the tessellation control shader.
@@ -3469,6 +3493,14 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
             "\n");
     }
 
+    if ((profile != EEsProfile && version >= 140) ||
+        (profile == EEsProfile && version >= 310)) {
+        stageBuiltins[EShLangTessControl].append(
+            "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
+            "in highp int gl_ViewIndex;"       // GL_EXT_multiview
+            "\n");
+    }
+
     //============================================================================
     //
     // Define the interface to the tessellation evaluation shader.
@@ -3544,6 +3576,14 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
             "\n");
     }
 
+    if ((profile != EEsProfile && version >= 140) ||
+        (profile == EEsProfile && version >= 310)) {
+        stageBuiltins[EShLangTessEvaluation].append(
+            "in highp int gl_DeviceIndex;"     // GL_EXT_device_group
+            "in highp int gl_ViewIndex;"       // GL_EXT_multiview
+            "\n");
+    }
+
     //============================================================================
     //
     // Define the interface to the fragment shader.
@@ -3701,9 +3741,12 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
             "\n");
     }
 
-    if (profile != EEsProfile) {
-        commonBuiltins.append("uniform int gl_ViewIndex;");
-        commonBuiltins.append("uniform int gl_DeviceIndex;");  // GL_EXT_device_group
+    if ((profile != EEsProfile && version >= 140) ||
+        (profile == EEsProfile && version >= 310)) {
+        stageBuiltins[EShLangFragment].append(
+            "flat in highp int gl_DeviceIndex;"     // GL_EXT_device_group
+            "flat in highp int gl_ViewIndex;"       // GL_EXT_multiview
+            "\n");
     }
 
     // printf("%s\n", commonBuiltins.c_str());
@@ -5120,6 +5163,14 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion
         //        symbolTable.setVariableExtensions("gl_PointSize", Num_AEP_tessellation_point_size, AEP_tessellation_point_size);
         //}
 
+        if ((profile != EEsProfile && version >= 140) ||
+            (profile == EEsProfile && version >= 310)) {
+            symbolTable.setVariableExtensions("gl_DeviceIndex",  1, &E_GL_EXT_device_group);
+            BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
+            symbolTable.setVariableExtensions("gl_ViewIndex", 1, &E_GL_EXT_multiview);
+            BuiltInVariable("gl_ViewIndex", EbvViewIndex, symbolTable);
+        }
+
         break;
 
     case EShLangFragment:
@@ -5317,12 +5368,10 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion
             symbolTable.setFunctionExtensions("imageAtomicCompSwap", 1, &E_GL_OES_shader_image_atomic);
         }
 
-        if (profile != EEsProfile) {
-            symbolTable.setFunctionExtensions("gl_DeviceIndex",  1, &E_GL_EXT_device_group);
-            BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
-            symbolTable.setFunctionExtensions("gl_ViewIndex", 1, &E_GL_EXT_multiview);
-            BuiltInVariable("gl_ViewIndex", EbvViewIndex, symbolTable);
-        }
+        symbolTable.setVariableExtensions("gl_DeviceIndex",  1, &E_GL_EXT_device_group);
+        BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
+        symbolTable.setVariableExtensions("gl_ViewIndex", 1, &E_GL_EXT_multiview);
+        BuiltInVariable("gl_ViewIndex", EbvViewIndex, symbolTable);
         break;
 
     case EShLangCompute:
@@ -5356,6 +5405,15 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion
             symbolTable.setFunctionExtensions("memoryBarrierShared",        1, &E_GL_ARB_compute_shader);
             symbolTable.setFunctionExtensions("groupMemoryBarrier",         1, &E_GL_ARB_compute_shader);
         }
+
+        if ((profile != EEsProfile && version >= 140) ||
+            (profile == EEsProfile && version >= 310)) {
+            symbolTable.setVariableExtensions("gl_DeviceIndex",  1, &E_GL_EXT_device_group);
+            BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
+            symbolTable.setVariableExtensions("gl_ViewIndex", 1, &E_GL_EXT_multiview);
+            BuiltInVariable("gl_ViewIndex", EbvViewIndex, symbolTable);
+        }
+
         break;
 
     default:
diff --git a/glslang/MachineIndependent/Versions.cpp b/glslang/MachineIndependent/Versions.cpp
index 4bc5bdc68..528333f46 100644
--- a/glslang/MachineIndependent/Versions.cpp
+++ b/glslang/MachineIndependent/Versions.cpp
@@ -334,6 +334,14 @@ void TParseVersions::getPreamble(std::string& preamble)
         }
     }
 
+    if ((profile != EEsProfile && version >= 140) ||
+        (profile == EEsProfile && version >= 310)) {
+        preamble += 
+            "#define GL_EXT_device_group 1\n"
+            "#define GL_EXT_multiview 1\n"
+            ;
+    }
+
     // #line and #include
     preamble +=
             "#define GL_GOOGLE_cpp_style_line_directive 1\n"
-- 
GitLab