Vulkan: Implement depth_range dirty bit and enable tests

- Additional fix in GlslWrapper.cpp to remove the @@ markers for unused
attributes.
- Enables 28 dEQP gles2 tests in functional.depth_range.*

Bug: angleproject:2454
Change-Id: I1a6f72d846b476ba681140d4b242208d24e18b95
Reviewed-on: https://chromium-review.googlesource.com/1014262
Commit-Queue: Luc Ferron <lucferron@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/libANGLE/renderer/vulkan/ContextVk.cpp b/src/libANGLE/renderer/vulkan/ContextVk.cpp
index 1ca6820..6ac3628 100644
--- a/src/libANGLE/renderer/vulkan/ContextVk.cpp
+++ b/src/libANGLE/renderer/vulkan/ContextVk.cpp
@@ -390,7 +390,7 @@
                                               glState.getFarPlane());
                 break;
             case gl::State::DIRTY_BIT_DEPTH_RANGE:
-                WARN() << "DIRTY_BIT_DEPTH_RANGE unimplemented";
+                mPipelineDesc->updateDepthRange(glState.getNearPlane(), glState.getFarPlane());
                 break;
             case gl::State::DIRTY_BIT_BLEND_ENABLED:
                 mPipelineDesc->updateBlendEnabled(glState.isBlendEnabled());
diff --git a/src/libANGLE/renderer/vulkan/GlslangWrapper.cpp b/src/libANGLE/renderer/vulkan/GlslangWrapper.cpp
index ffb9662..c5c3bcb 100644
--- a/src/libANGLE/renderer/vulkan/GlslangWrapper.cpp
+++ b/src/libANGLE/renderer/vulkan/GlslangWrapper.cpp
@@ -120,19 +120,31 @@
     // Parse attribute locations and replace them in the vertex shader.
     // See corresponding code in OutputVulkanGLSL.cpp.
     // TODO(jmadill): Also do the same for ESSL 3 fragment outputs.
-    for (const auto &attribute : programState.getAttributes())
+    for (const sh::Attribute &attribute : programState.getAttributes())
     {
-        if (!attribute.active)
-        {
-            InsertQualifierSpecifierString(&vertexSource, attribute.name, "");
-            continue;
-        }
+        // Warning: If we endup supporting ES 3.0 shaders and up, Program::linkAttributes is going
+        // to bring us all attributes in this list instead of only the active ones.
+        ASSERT(attribute.active);
 
         std::string locationString = "location = " + Str(attribute.location);
         InsertLayoutSpecifierString(&vertexSource, attribute.name, locationString);
         InsertQualifierSpecifierString(&vertexSource, attribute.name, "in");
     }
 
+    // The attributes in the programState could have been filled with active attributes only
+    // depending on the shader version. If there is inactive attributes left, we have to remove
+    // their @@ QUALIFIER and @@ LAYOUT markers.
+    for (const sh::Attribute &attribute : glVertexShader->getAllAttributes(glContext))
+    {
+        if (attribute.active)
+        {
+            continue;
+        }
+
+        InsertLayoutSpecifierString(&vertexSource, attribute.name, "");
+        InsertQualifierSpecifierString(&vertexSource, attribute.name, "");
+    }
+
     // Assign varying locations.
     for (const gl::PackedVaryingRegister &varyingReg : resources.varyingPacking.getRegisterList())
     {
diff --git a/src/libANGLE/renderer/vulkan/vk_cache_utils.cpp b/src/libANGLE/renderer/vulkan/vk_cache_utils.cpp
index 12cc374..f680a0e 100644
--- a/src/libANGLE/renderer/vulkan/vk_cache_utils.cpp
+++ b/src/libANGLE/renderer/vulkan/vk_cache_utils.cpp
@@ -647,8 +647,15 @@
     mViewport.y        = static_cast<float>(viewport.y);
     mViewport.width    = static_cast<float>(viewport.width);
     mViewport.height   = static_cast<float>(viewport.height);
-    mViewport.minDepth = nearPlane;
-    mViewport.maxDepth = farPlane;
+    updateDepthRange(nearPlane, farPlane);
+}
+
+void PipelineDesc::updateDepthRange(float nearPlane, float farPlane)
+{
+    // GLES2.0 Section 2.12.1: Each of n and f are clamped to lie within [0, 1], as are all
+    // arguments of type clampf.
+    mViewport.minDepth = gl::clamp01(nearPlane);
+    mViewport.maxDepth = gl::clamp01(farPlane);
 }
 
 void PipelineDesc::updateVertexInputInfo(const VertexInputBindings &bindings,
diff --git a/src/libANGLE/renderer/vulkan/vk_cache_utils.h b/src/libANGLE/renderer/vulkan/vk_cache_utils.h
index 9ff4832..9b230a7 100644
--- a/src/libANGLE/renderer/vulkan/vk_cache_utils.h
+++ b/src/libANGLE/renderer/vulkan/vk_cache_utils.h
@@ -269,6 +269,7 @@
                              Pipeline *pipelineOut) const;
 
     void updateViewport(const gl::Rectangle &viewport, float nearPlane, float farPlane);
+    void updateDepthRange(float nearPlane, float farPlane);
 
     // Shader stage info
     const ShaderStageInfo &getShaderStageInfo() const;