Move stencil mask validation to before the draw.

ANGLE (and WebGL) restrict the back and front stencil masks
on draw, due to D3D restrictions. We would previously only
validate this if the stencil was enabled in D3D9. In D3D11
we would validate the stencil masks even if the stencil is
disabled, which is the behaviour the spec suggests.

Moving the error check to before the draw also prevents any
issue with interrupting a draw call mid-way through.

BUG=angle:571
BUG=378754

Change-Id: If7651c2be559eef64a872082e144dafa3b2c524b
Reviewed-on: https://chromium-review.googlesource.com/203299
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Shannon Woods <shannonwoods@chromium.org>
diff --git a/src/libGLESv2/validationES.cpp b/src/libGLESv2/validationES.cpp
index 6fec360..dba2231 100644
--- a/src/libGLESv2/validationES.cpp
+++ b/src/libGLESv2/validationES.cpp
@@ -1302,6 +1302,18 @@
         return gl::error(GL_INVALID_OPERATION, false);
     }
 
+    const gl::DepthStencilState &depthStencilState = context->getDepthStencilState();
+    if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask ||
+        context->getStencilRef() != context->getStencilBackRef() ||
+        depthStencilState.stencilMask != depthStencilState.stencilBackMask)
+    {
+        // Note: these separate values are not supported in WebGL, due to D3D's limitations.
+        // See Section 6.10 of the WebGL 1.0 spec
+        ERR("This ANGLE implementation does not support separate front/back stencil "
+            "writemasks, reference values, or stencil mask values.");
+        return gl::error(GL_INVALID_OPERATION, false);
+    }
+
     // No-op if zero count
     return (count > 0);
 }