ES31: Implement bindImageTexture binds a single layer on D3D backend

Dynamically generate image2D variables' declaration and function
definition in libANGLE.

Bug: angleproject:1987
TEST=angle_end2end_tests.ComputeShaderTest.*

Change-Id: Idacc756f7bd15f22eccb1d689e18e997f3e74159
Reviewed-on: https://chromium-review.googlesource.com/c/1142885
Commit-Queue: Xinghua Cao <xinghua.cao@intel.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/OutputHLSL.cpp b/src/compiler/translator/OutputHLSL.cpp
index cd15daa..84e32dd 100644
--- a/src/compiler/translator/OutputHLSL.cpp
+++ b/src/compiler/translator/OutputHLSL.cpp
@@ -35,6 +35,8 @@
 namespace
 {
 
+constexpr const char kImage2DFunctionString[] = "// @@ IMAGE2D DECLARATION FUNCTION STRING @@";
+
 TString ArrayHelperFunctionName(const char *prefix, const TType &type)
 {
     TStringStream fnName;
@@ -382,6 +384,21 @@
     return mResourcesHLSL->getUniformRegisterMap();
 }
 
+unsigned int OutputHLSL::getReadonlyImage2DRegisterIndex() const
+{
+    return mResourcesHLSL->getReadonlyImage2DRegisterIndex();
+}
+
+unsigned int OutputHLSL::getImage2DRegisterIndex() const
+{
+    return mResourcesHLSL->getImage2DRegisterIndex();
+}
+
+const std::set<std::string> &OutputHLSL::getUsedImage2DFunctionNames() const
+{
+    return mImageFunctionHLSL->getUsedImage2DFunctionNames();
+}
+
 TString OutputHLSL::structInitializerString(int indent,
                                             const TType &type,
                                             const TString &name) const
@@ -717,7 +734,7 @@
 
             if (mOutputType == SH_HLSL_4_1_OUTPUT)
             {
-                mResourcesHLSL->samplerMetadataUniforms(out, "c4");
+                mResourcesHLSL->samplerMetadataUniforms(out, 4);
             }
 
             out << "};\n";
@@ -829,7 +846,7 @@
 
             if (mOutputType == SH_HLSL_4_1_OUTPUT)
             {
-                mResourcesHLSL->samplerMetadataUniforms(out, "c4");
+                mResourcesHLSL->samplerMetadataUniforms(out, 4);
             }
 
             out << "};\n"
@@ -865,9 +882,15 @@
             out << "    uint3 gl_NumWorkGroups : packoffset(c0);\n";
         }
         ASSERT(mOutputType == SH_HLSL_4_1_OUTPUT);
-        mResourcesHLSL->samplerMetadataUniforms(out, "c1");
+        unsigned int registerIndex = 1;
+        mResourcesHLSL->samplerMetadataUniforms(out, registerIndex);
+        // Sampler metadata struct must be two 4-vec, 32 bytes.
+        registerIndex += mResourcesHLSL->getSamplerCount() * 2;
+        mResourcesHLSL->imageMetadataUniforms(out, registerIndex);
         out << "};\n";
 
+        out << kImage2DFunctionString << "\n";
+
         std::ostringstream systemValueDeclaration;
         std::ostringstream glBuiltinInitialization;