Commit ae1990c8 by Geoff Lang

Track if uniform data has been updated to avoid extra Map calls.

Compare all uniform data to the values currently stored in the uniform and only mark the uniform as dirty if the data is new. This saves lots of buffer map calls when the same data is set on a uniform many times. BUG=260069 Change-Id: Ic4df8a276a81b074211712ff50e5cc4d0d9bb612 Reviewed-on: https://chromium-review.googlesource.com/199346Reviewed-by: 's avatarNicolas Capens <nicolascapens@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 64c83249
...@@ -474,6 +474,16 @@ GLenum ProgramBinary::getTransformFeedbackBufferMode() const ...@@ -474,6 +474,16 @@ GLenum ProgramBinary::getTransformFeedbackBufferMode() const
} }
template <typename T> template <typename T>
static inline void SetIfDirty(T *dest, const T& source, bool *dirtyFlag)
{
ASSERT(dest != NULL);
ASSERT(dirtyFlag != NULL);
*dirtyFlag = *dirtyFlag || (memcmp(dest, &source, sizeof(T)) != 0);
*dest = source;
}
template <typename T>
bool ProgramBinary::setUniform(GLint location, GLsizei count, const T* v, GLenum targetUniformType) bool ProgramBinary::setUniform(GLint location, GLsizei count, const T* v, GLenum targetUniformType)
{ {
if (location < 0 || location >= (int)mUniformIndex.size()) if (location < 0 || location >= (int)mUniformIndex.size())
...@@ -485,7 +495,6 @@ bool ProgramBinary::setUniform(GLint location, GLsizei count, const T* v, GLenum ...@@ -485,7 +495,6 @@ bool ProgramBinary::setUniform(GLint location, GLsizei count, const T* v, GLenum
const GLenum targetBoolType = UniformBoolVectorType(targetUniformType); const GLenum targetBoolType = UniformBoolVectorType(targetUniformType);
LinkedUniform *targetUniform = mUniforms[mUniformIndex[location].index]; LinkedUniform *targetUniform = mUniforms[mUniformIndex[location].index];
targetUniform->dirty = true;
int elementCount = targetUniform->elementCount(); int elementCount = targetUniform->elementCount();
...@@ -502,11 +511,11 @@ bool ProgramBinary::setUniform(GLint location, GLsizei count, const T* v, GLenum ...@@ -502,11 +511,11 @@ bool ProgramBinary::setUniform(GLint location, GLsizei count, const T* v, GLenum
{ {
for (int c = 0; c < components; c++) for (int c = 0; c < components; c++)
{ {
target[c] = v[c]; SetIfDirty(target + c, v[c], &targetUniform->dirty);
} }
for (int c = components; c < 4; c++) for (int c = components; c < 4; c++)
{ {
target[c] = 0; SetIfDirty(target + c, T(0), &targetUniform->dirty);
} }
target += 4; target += 4;
v += components; v += components;
...@@ -520,11 +529,11 @@ bool ProgramBinary::setUniform(GLint location, GLsizei count, const T* v, GLenum ...@@ -520,11 +529,11 @@ bool ProgramBinary::setUniform(GLint location, GLsizei count, const T* v, GLenum
{ {
for (int c = 0; c < components; c++) for (int c = 0; c < components; c++)
{ {
boolParams[c] = (v[c] == static_cast<T>(0)) ? GL_FALSE : GL_TRUE; SetIfDirty(boolParams + c, (v[c] == static_cast<T>(0)) ? GL_FALSE : GL_TRUE, &targetUniform->dirty);
} }
for (int c = components; c < 4; c++) for (int c = components; c < 4; c++)
{ {
boolParams[c] = GL_FALSE; SetIfDirty(boolParams + c, GL_FALSE, &targetUniform->dirty);
} }
boolParams += 4; boolParams += 4;
v += components; v += components;
...@@ -559,8 +568,9 @@ bool ProgramBinary::setUniform4fv(GLint location, GLsizei count, const GLfloat * ...@@ -559,8 +568,9 @@ bool ProgramBinary::setUniform4fv(GLint location, GLsizei count, const GLfloat *
} }
template<typename T> template<typename T>
void transposeMatrix(T *target, const GLfloat *value, int targetWidth, int targetHeight, int srcWidth, int srcHeight) bool transposeMatrix(T *target, const GLfloat *value, int targetWidth, int targetHeight, int srcWidth, int srcHeight)
{ {
bool dirty = false;
int copyWidth = std::min(targetHeight, srcWidth); int copyWidth = std::min(targetHeight, srcWidth);
int copyHeight = std::min(targetWidth, srcHeight); int copyHeight = std::min(targetWidth, srcHeight);
...@@ -568,7 +578,7 @@ void transposeMatrix(T *target, const GLfloat *value, int targetWidth, int targe ...@@ -568,7 +578,7 @@ void transposeMatrix(T *target, const GLfloat *value, int targetWidth, int targe
{ {
for (int y = 0; y < copyHeight; y++) for (int y = 0; y < copyHeight; y++)
{ {
target[x * targetWidth + y] = static_cast<T>(value[y * srcWidth + x]); SetIfDirty(target + (x * targetWidth + y), static_cast<T>(value[y * srcWidth + x]), &dirty);
} }
} }
// clear unfilled right side // clear unfilled right side
...@@ -576,7 +586,7 @@ void transposeMatrix(T *target, const GLfloat *value, int targetWidth, int targe ...@@ -576,7 +586,7 @@ void transposeMatrix(T *target, const GLfloat *value, int targetWidth, int targe
{ {
for (int x = copyHeight; x < targetWidth; x++) for (int x = copyHeight; x < targetWidth; x++)
{ {
target[y * targetWidth + x] = static_cast<T>(0); SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
} }
} }
// clear unfilled bottom. // clear unfilled bottom.
...@@ -584,14 +594,17 @@ void transposeMatrix(T *target, const GLfloat *value, int targetWidth, int targe ...@@ -584,14 +594,17 @@ void transposeMatrix(T *target, const GLfloat *value, int targetWidth, int targe
{ {
for (int x = 0; x < targetWidth; x++) for (int x = 0; x < targetWidth; x++)
{ {
target[y * targetWidth + x] = static_cast<T>(0); SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
} }
} }
return dirty;
} }
template<typename T> template<typename T>
void expandMatrix(T *target, const GLfloat *value, int targetWidth, int targetHeight, int srcWidth, int srcHeight) bool expandMatrix(T *target, const GLfloat *value, int targetWidth, int targetHeight, int srcWidth, int srcHeight)
{ {
bool dirty = false;
int copyWidth = std::min(targetWidth, srcWidth); int copyWidth = std::min(targetWidth, srcWidth);
int copyHeight = std::min(targetHeight, srcHeight); int copyHeight = std::min(targetHeight, srcHeight);
...@@ -599,7 +612,7 @@ void expandMatrix(T *target, const GLfloat *value, int targetWidth, int targetHe ...@@ -599,7 +612,7 @@ void expandMatrix(T *target, const GLfloat *value, int targetWidth, int targetHe
{ {
for (int x = 0; x < copyWidth; x++) for (int x = 0; x < copyWidth; x++)
{ {
target[y * targetWidth + x] = static_cast<T>(value[y * srcWidth + x]); SetIfDirty(target + (y * targetWidth + x), static_cast<T>(value[y * srcWidth + x]), &dirty);
} }
} }
// clear unfilled right side // clear unfilled right side
...@@ -607,7 +620,7 @@ void expandMatrix(T *target, const GLfloat *value, int targetWidth, int targetHe ...@@ -607,7 +620,7 @@ void expandMatrix(T *target, const GLfloat *value, int targetWidth, int targetHe
{ {
for (int x = copyWidth; x < targetWidth; x++) for (int x = copyWidth; x < targetWidth; x++)
{ {
target[y * targetWidth + x] = static_cast<T>(0); SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
} }
} }
// clear unfilled bottom. // clear unfilled bottom.
...@@ -615,9 +628,11 @@ void expandMatrix(T *target, const GLfloat *value, int targetWidth, int targetHe ...@@ -615,9 +628,11 @@ void expandMatrix(T *target, const GLfloat *value, int targetWidth, int targetHe
{ {
for (int x = 0; x < targetWidth; x++) for (int x = 0; x < targetWidth; x++)
{ {
target[y * targetWidth + x] = static_cast<T>(0); SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
} }
} }
return dirty;
} }
template <int cols, int rows> template <int cols, int rows>
...@@ -629,7 +644,6 @@ bool ProgramBinary::setUniformMatrixfv(GLint location, GLsizei count, GLboolean ...@@ -629,7 +644,6 @@ bool ProgramBinary::setUniformMatrixfv(GLint location, GLsizei count, GLboolean
} }
LinkedUniform *targetUniform = mUniforms[mUniformIndex[location].index]; LinkedUniform *targetUniform = mUniforms[mUniformIndex[location].index];
targetUniform->dirty = true;
if (targetUniform->type != targetUniformType) if (targetUniform->type != targetUniformType)
{ {
...@@ -650,11 +664,11 @@ bool ProgramBinary::setUniformMatrixfv(GLint location, GLsizei count, GLboolean ...@@ -650,11 +664,11 @@ bool ProgramBinary::setUniformMatrixfv(GLint location, GLsizei count, GLboolean
// Internally store matrices as transposed versions to accomodate HLSL matrix indexing // Internally store matrices as transposed versions to accomodate HLSL matrix indexing
if (transpose == GL_FALSE) if (transpose == GL_FALSE)
{ {
transposeMatrix<GLfloat>(target, value, 4, rows, rows, cols); targetUniform->dirty = transposeMatrix<GLfloat>(target, value, 4, rows, rows, cols) || targetUniform->dirty;
} }
else else
{ {
expandMatrix<GLfloat>(target, value, 4, rows, cols, rows); targetUniform->dirty = expandMatrix<GLfloat>(target, value, 4, rows, cols, rows) || targetUniform->dirty;
} }
target += targetMatrixStride; target += targetMatrixStride;
value += cols * rows; value += cols * rows;
...@@ -716,7 +730,6 @@ bool ProgramBinary::setUniform1iv(GLint location, GLsizei count, const GLint *v) ...@@ -716,7 +730,6 @@ bool ProgramBinary::setUniform1iv(GLint location, GLsizei count, const GLint *v)
} }
LinkedUniform *targetUniform = mUniforms[mUniformIndex[location].index]; LinkedUniform *targetUniform = mUniforms[mUniformIndex[location].index];
targetUniform->dirty = true;
int elementCount = targetUniform->elementCount(); int elementCount = targetUniform->elementCount();
...@@ -731,10 +744,10 @@ bool ProgramBinary::setUniform1iv(GLint location, GLsizei count, const GLint *v) ...@@ -731,10 +744,10 @@ bool ProgramBinary::setUniform1iv(GLint location, GLsizei count, const GLint *v)
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
target[0] = v[0]; SetIfDirty(target + 0, v[0], &targetUniform->dirty);
target[1] = 0; SetIfDirty(target + 1, 0, &targetUniform->dirty);
target[2] = 0; SetIfDirty(target + 2, 0, &targetUniform->dirty);
target[3] = 0; SetIfDirty(target + 3, 0, &targetUniform->dirty);
target += 4; target += 4;
v += 1; v += 1;
} }
...@@ -745,10 +758,10 @@ bool ProgramBinary::setUniform1iv(GLint location, GLsizei count, const GLint *v) ...@@ -745,10 +758,10 @@ bool ProgramBinary::setUniform1iv(GLint location, GLsizei count, const GLint *v)
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
boolParams[0] = (v[0] == 0) ? GL_FALSE : GL_TRUE; SetIfDirty(boolParams + 0, (v[0] == 0) ? GL_FALSE : GL_TRUE, &targetUniform->dirty);
boolParams[1] = GL_FALSE; SetIfDirty(boolParams + 1, GL_FALSE, &targetUniform->dirty);
boolParams[2] = GL_FALSE; SetIfDirty(boolParams + 2, GL_FALSE, &targetUniform->dirty);
boolParams[3] = GL_FALSE; SetIfDirty(boolParams + 3, GL_FALSE, &targetUniform->dirty);
boolParams += 4; boolParams += 4;
v += 1; v += 1;
} }
......
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