D3D11: Store Buffer SRVs in native storage.

This allows us to not store std::pairs to identify SRVs. Instead
we can release the cached SRVs directly when we re-create the
native buffer.

BUG=angleproject:1513

Change-Id: I6f6d5edc659aa843c9439b97661073415f1a772b
Reviewed-on: https://chromium-review.googlesource.com/385818
Commit-Queue: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/tests/gl_tests/TextureTest.cpp b/src/tests/gl_tests/TextureTest.cpp
index 7ef6641..ba045af 100644
--- a/src/tests/gl_tests/TextureTest.cpp
+++ b/src/tests/gl_tests/TextureTest.cpp
@@ -3566,7 +3566,7 @@
     std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
 
     // Pull in the color data from the unpack buffer.
-    angle::GLBuffer unpackBuffer;
+    GLBuffer unpackBuffer;
     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
     glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
     glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
@@ -3581,12 +3581,51 @@
 
     // Draw with the alpha texture and verify.
     drawQuad(mProgram, "position", 0.5f);
-    swapBuffers();
 
     ASSERT_GL_NO_ERROR();
     EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
 }
 
+// Ensure stale unpack data doesn't propagate in D3D11.
+TEST_P(Texture2DTestES3, StaleUnpackData)
+{
+    // Init unpack buffer.
+    GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
+    std::vector<GLColor> pixels(pixelCount, GLColor::red);
+
+    GLBuffer unpackBuffer;
+    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+    glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
+    GLsizei bufferSize = pixelCount * sizeof(GLColor);
+    glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
+
+    // Create from unpack buffer.
+    glBindTexture(GL_TEXTURE_2D, mTexture2D);
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
+                 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+
+    drawQuad(mProgram, "position", 0.5f);
+
+    ASSERT_GL_NO_ERROR();
+    EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
+
+    // Fill unpack with green, recreating buffer.
+    pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
+    GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
+    glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
+
+    // Reinit texture with green.
+    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
+                    GL_UNSIGNED_BYTE, nullptr);
+
+    drawQuad(mProgram, "position", 0.5f);
+
+    ASSERT_GL_NO_ERROR();
+    EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
+}
+
 // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
 // TODO(oetuaho): Enable all below tests on OpenGL. Requires a fix for ANGLE bug 1278.
 ANGLE_INSTANTIATE_TEST(Texture2DTest,