Move more draw call validation to the API.
The GL expects us to reject invalid draw calls before we start
doing any work, so we can prevent internal unnecessary state
changes.
Also update the program binary's cached sampler data when we
validate. The previous patch was breaking draw calls in Google
Earth WebGL.
BUG=angle:571
BUG=390412
Change-Id: I1c4e204ae2467afc36b76af975a3a49e26349639
Reviewed-on: https://chromium-review.googlesource.com/206482
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/libGLESv2/ProgramBinary.cpp b/src/libGLESv2/ProgramBinary.cpp
index 2efe8b7..5a22500 100644
--- a/src/libGLESv2/ProgramBinary.cpp
+++ b/src/libGLESv2/ProgramBinary.cpp
@@ -150,6 +150,7 @@
mUsedPixelSamplerRange(0),
mUsesPointSize(false),
mShaderVersion(100),
+ mDirtySamplerMapping(true),
mVertexUniformStorage(NULL),
mFragmentUniformStorage(NULL),
mValidated(false),
@@ -765,6 +766,13 @@
}
}
else UNREACHABLE();
+
+ // Set a special flag if we change a sampler uniform
+ if (IsSampler(targetUniform->type) &&
+ (memcmp(targetUniform->data, v, sizeof(GLint)) != 0))
+ {
+ mDirtySamplerMapping = true;
+ }
}
void ProgramBinary::setUniform2iv(GLint location, GLsizei count, const GLint *v)
@@ -909,9 +917,15 @@
}
}
-// Applies all the uniforms set for this program object to the renderer
-void ProgramBinary::applyUniforms()
+void ProgramBinary::updateSamplerMapping()
{
+ if (!mDirtySamplerMapping)
+ {
+ return;
+ }
+
+ mDirtySamplerMapping = false;
+
// Retrieve sampler uniform values
for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); uniformIndex++)
{
@@ -922,7 +936,7 @@
if (IsSampler(targetUniform->type))
{
int count = targetUniform->elementCount();
- GLint (*v)[4] = (GLint(*)[4])targetUniform->data;
+ GLint (*v)[4] = reinterpret_cast<GLint(*)[4]>(targetUniform->data);
if (targetUniform->isReferencedByFragmentShader())
{
@@ -958,6 +972,12 @@
}
}
}
+}
+
+// Applies all the uniforms set for this program object to the renderer
+void ProgramBinary::applyUniforms()
+{
+ updateSamplerMapping();
mRenderer->applyUniforms(*this);
@@ -2615,6 +2635,7 @@
// if any two active samplers in a program are of different types, but refer to the same
// texture image unit, and this is the current program, then ValidateProgram will fail, and
// DrawArrays and DrawElements will issue the INVALID_OPERATION error.
+ updateSamplerMapping();
const unsigned int maxCombinedTextureImageUnits = mRenderer->getMaxCombinedTextureImageUnits();
TextureType textureUnitType[IMPLEMENTATION_MAX_COMBINED_TEXTURE_IMAGE_UNITS];
@@ -2800,6 +2821,7 @@
mUsedPixelSamplerRange = 0;
mUsesPointSize = false;
mShaderVersion = 0;
+ mDirtySamplerMapping = true;
SafeDeleteContainer(mUniforms);
SafeDeleteContainer(mUniformBlocks);