Commit 399d1a17 by Geoff Lang

Revert "Program: clamp the number of uniforms to be copied"

This reverts commit 9863a3ef. Change-Id: I840a735b49bc4f2319c8af5f620d7f52bb7eecf1 Reviewed-on: https://chromium-review.googlesource.com/411470Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 94177fba
...@@ -2848,18 +2848,12 @@ void Program::setUniformInternal(GLint location, GLsizei count, const T *v) ...@@ -2848,18 +2848,12 @@ void Program::setUniformInternal(GLint location, GLsizei count, const T *v)
LinkedUniform *linkedUniform = &mState.mUniforms[locationInfo.index]; LinkedUniform *linkedUniform = &mState.mUniforms[locationInfo.index];
uint8_t *destPointer = linkedUniform->getDataPtrToElement(locationInfo.element); uint8_t *destPointer = linkedUniform->getDataPtrToElement(locationInfo.element);
// OpenGL ES 3.0.4 spec pg 67: "Values for any array element that exceeds the highest array
// element index used, as reported by GetActiveUniform, will be ignored by the GL."
unsigned int remainingElements = linkedUniform->elementCount() - locationInfo.element;
GLsizei clampedCount = std::min(
count, static_cast<GLsizei>(remainingElements * linkedUniform->getElementComponents()));
if (VariableComponentType(linkedUniform->type) == GL_BOOL) if (VariableComponentType(linkedUniform->type) == GL_BOOL)
{ {
// Do a cast conversion for boolean types. From the spec: // Do a cast conversion for boolean types. From the spec:
// "The uniform is set to FALSE if the input value is 0 or 0.0f, and set to TRUE otherwise." // "The uniform is set to FALSE if the input value is 0 or 0.0f, and set to TRUE otherwise."
GLint *destAsInt = reinterpret_cast<GLint *>(destPointer); GLint *destAsInt = reinterpret_cast<GLint *>(destPointer);
for (GLsizei component = 0; component < clampedCount; ++component) for (GLsizei component = 0; component < count; ++component)
{ {
destAsInt[component] = (v[component] != static_cast<T>(0) ? GL_TRUE : GL_FALSE); destAsInt[component] = (v[component] != static_cast<T>(0) ? GL_TRUE : GL_FALSE);
} }
...@@ -2867,12 +2861,12 @@ void Program::setUniformInternal(GLint location, GLsizei count, const T *v) ...@@ -2867,12 +2861,12 @@ void Program::setUniformInternal(GLint location, GLsizei count, const T *v)
else else
{ {
// Invalide the validation cache if we modify the sampler data. // Invalide the validation cache if we modify the sampler data.
if (linkedUniform->isSampler() && memcmp(destPointer, v, sizeof(T) * clampedCount) != 0) if (linkedUniform->isSampler() && memcmp(destPointer, v, sizeof(T) * count) != 0)
{ {
mCachedValidateSamplersResult.reset(); mCachedValidateSamplersResult.reset();
} }
memcpy(destPointer, v, sizeof(T) * clampedCount); memcpy(destPointer, v, sizeof(T) * count);
} }
} }
...@@ -2892,13 +2886,7 @@ void Program::setMatrixUniformInternal(GLint location, ...@@ -2892,13 +2886,7 @@ void Program::setMatrixUniformInternal(GLint location,
const VariableLocation &locationInfo = mState.mUniformLocations[location]; const VariableLocation &locationInfo = mState.mUniformLocations[location];
LinkedUniform *linkedUniform = &mState.mUniforms[locationInfo.index]; LinkedUniform *linkedUniform = &mState.mUniforms[locationInfo.index];
T *destPtr = reinterpret_cast<T *>(linkedUniform->getDataPtrToElement(locationInfo.element)); T *destPtr = reinterpret_cast<T *>(linkedUniform->getDataPtrToElement(locationInfo.element));
for (GLsizei element = 0; element < count; ++element)
// OpenGL ES 3.0.4 spec pg 67: "Values for any array element that exceeds the highest array
// element index used, as reported by GetActiveUniform, will be ignored by the GL."
unsigned int remainingElements = linkedUniform->elementCount() - locationInfo.element;
GLsizei clampedCount = std::min(count, static_cast<GLsizei>(remainingElements));
for (GLsizei element = 0; element < clampedCount; ++element)
{ {
size_t elementOffset = element * rows * cols; size_t elementOffset = element * rows * cols;
......
...@@ -109,11 +109,6 @@ size_t LinkedUniform::getElementSize() const ...@@ -109,11 +109,6 @@ size_t LinkedUniform::getElementSize() const
return VariableExternalSize(type); return VariableExternalSize(type);
} }
size_t LinkedUniform::getElementComponents() const
{
return VariableComponentCount(type);
}
uint8_t *LinkedUniform::getDataPtrToElement(size_t elementIndex) uint8_t *LinkedUniform::getDataPtrToElement(size_t elementIndex)
{ {
ASSERT((!isArray() && elementIndex == 0) || (isArray() && elementIndex < arraySize)); ASSERT((!isArray() && elementIndex == 0) || (isArray() && elementIndex < arraySize));
......
...@@ -36,7 +36,6 @@ struct LinkedUniform : public sh::Uniform ...@@ -36,7 +36,6 @@ struct LinkedUniform : public sh::Uniform
bool isInDefaultBlock() const; bool isInDefaultBlock() const;
bool isField() const; bool isField() const;
size_t getElementSize() const; size_t getElementSize() const;
size_t getElementComponents() const;
uint8_t *getDataPtrToElement(size_t elementIndex); uint8_t *getDataPtrToElement(size_t elementIndex);
const uint8_t *getDataPtrToElement(size_t elementIndex) const; const uint8_t *getDataPtrToElement(size_t elementIndex) const;
......
...@@ -459,54 +459,6 @@ TEST_P(UniformTestES3, TranposedMatrixArrayUniformStateQuery) ...@@ -459,54 +459,6 @@ TEST_P(UniformTestES3, TranposedMatrixArrayUniformStateQuery)
} }
} }
// Check that trying setting too many elements of an array doesn't overflow
TEST_P(UniformTestES3, OverflowArray)
{
const std::string &vertexShader =
"#version 300 es\n"
"void main() { gl_Position = vec4(1); }";
const std::string &fragShader =
"#version 300 es\n"
"precision mediump float;\n"
"uniform float uniF[5];\n"
"uniform mat3x2 uniMat3x2[5];\n"
"out vec4 color;\n"
"void main() {\n"
" color = vec4(uniMat3x2[0][0][0] + uniF[0]);\n"
"}";
mProgram = CompileProgram(vertexShader, fragShader);
ASSERT_NE(mProgram, 0u);
glUseProgram(mProgram);
const size_t kOverflowSize = 10000;
std::vector<GLfloat> values(10000 * 6);
// Setting as a clump
GLint floatLocation = glGetUniformLocation(mProgram, "uniF");
ASSERT_NE(-1, floatLocation);
GLint matLocation = glGetUniformLocation(mProgram, "uniMat3x2");
ASSERT_NE(-1, matLocation);
// Set too many float uniforms
glUniform1fv(floatLocation, kOverflowSize, &values[0]);
// Set too many matrix uniforms, transposed or not
glUniformMatrix3x2fv(matLocation, kOverflowSize, GL_FALSE, &values[0]);
glUniformMatrix3x2fv(matLocation, kOverflowSize, GL_TRUE, &values[0]);
// Same checks but with offsets
GLint floatLocationOffset = glGetUniformLocation(mProgram, "uniF[3]");
ASSERT_NE(-1, floatLocationOffset);
GLint matLocationOffset = glGetUniformLocation(mProgram, "uniMat3x2[3]");
ASSERT_NE(-1, matLocationOffset);
glUniform1fv(floatLocationOffset, kOverflowSize, &values[0]);
glUniformMatrix3x2fv(matLocationOffset, kOverflowSize, GL_FALSE, &values[0]);
glUniformMatrix3x2fv(matLocationOffset, kOverflowSize, GL_TRUE, &values[0]);
}
// Check that sampler uniforms only show up one time in the list // Check that sampler uniforms only show up one time in the list
TEST_P(UniformTest, SamplerUniformsAppearOnce) TEST_P(UniformTest, SamplerUniformsAppearOnce)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment