spirv: Support initializers on uniforms (#1588)

If a uniform has an initializer it will now be given as the optional
initializer operand to the OpVariable instruction.

Fixes: https://github.com/KhronosGroup/glslang/issues/1259

Signed-off-by: Neil Roberts <nroberts@igalia.com> (the code)
Signed-off-by: Alejandro Piñeiro <apinheiro@igalia.com> (the tests)
Signed-off-by: Arcady Goldmints-Orlov <agoldmints@igalia.com>

Co-authored-by: Neil Roberts <nroberts@igalia.com>
diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp
index 9c4d88e..3e420aa 100644
--- a/SPIRV/GlslangToSpv.cpp
+++ b/SPIRV/GlslangToSpv.cpp
@@ -3525,7 +3525,18 @@
     if (glslang::IsAnonymous(name))
         name = "";
 
-    return builder.createVariable(storageClass, spvType, name);
+    spv::Id initializer = spv::NoResult;
+
+    if (node->getType().getQualifier().storage == glslang::EvqUniform &&
+        !node->getConstArray().empty()) {
+            int nextConst = 0;
+            initializer = createSpvConstantFromConstUnionArray(node->getType(),
+                                                               node->getConstArray(),
+                                                               nextConst,
+                                                               false /* specConst */);
+    }
+
+    return builder.createVariable(storageClass, spvType, name, initializer);
 }
 
 // Return type Id of the sampled type.