Commit 3a36f306 by Jiacheng Lu Committed by Commit Bot

Always set matrix uniform to dirty when it updates

Remove the dirty checking of matrix uniform update at frontend and always let backend update whenever glUniformMatrix* is called. Profiled with UniformsBenchmark/* with vulkan backend, performance increases around 6% when data being updated is changing and performance increases around 2% when data being updated stays same. Bug: angleproject:3705 Change-Id: I8eaf6a1231e634b69c6dc540db1b9d3a312bf45d Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1709725 Commit-Queue: Jiacheng Lu <lujc@google.com> Reviewed-by: 's avatarTobin Ehlis <tobine@google.com>
parent bf3d9333
...@@ -2612,14 +2612,12 @@ void ProgramD3D::setUniformMatrixfvInternal(GLint location, ...@@ -2612,14 +2612,12 @@ void ProgramD3D::setUniformMatrixfvInternal(GLint location,
{ {
if (targetUniform->mShaderData[shaderType]) if (targetUniform->mShaderData[shaderType])
{ {
if (SetFloatUniformMatrixHLSL<cols, rows>::Run(arrayElementOffset, elementCount, SetFloatUniformMatrixHLSL<cols, rows>::Run(arrayElementOffset, elementCount, countIn,
countIn, transpose, value, transpose, value,
targetUniform->mShaderData[shaderType])) targetUniform->mShaderData[shaderType]);
{
mShaderUniformsDirty.set(shaderType); mShaderUniformsDirty.set(shaderType);
} }
} }
}
} }
void ProgramD3D::assignAllSamplerRegisters() void ProgramD3D::assignAllSamplerRegisters()
......
...@@ -121,7 +121,7 @@ template <typename T, ...@@ -121,7 +121,7 @@ template <typename T,
bool IsDstColumnMajor, bool IsDstColumnMajor,
int colsDst, int colsDst,
int rowsDst> int rowsDst>
bool ExpandMatrix(T *target, const GLfloat *value) void ExpandMatrix(T *target, const GLfloat *value)
{ {
static_assert(colsSrc <= colsDst && rowsSrc <= rowsDst, "Can only expand!"); static_assert(colsSrc <= colsDst && rowsSrc <= rowsDst, "Can only expand!");
...@@ -139,13 +139,7 @@ bool ExpandMatrix(T *target, const GLfloat *value) ...@@ -139,13 +139,7 @@ bool ExpandMatrix(T *target, const GLfloat *value)
} }
} }
if (memcmp(target, staging, kDstFlatSize * sizeof(T)) == 0)
{
return false;
}
memcpy(target, staging, kDstFlatSize * sizeof(T)); memcpy(target, staging, kDstFlatSize * sizeof(T));
return true;
} }
template <bool IsSrcColumMajor, template <bool IsSrcColumMajor,
...@@ -154,7 +148,7 @@ template <bool IsSrcColumMajor, ...@@ -154,7 +148,7 @@ template <bool IsSrcColumMajor,
bool IsDstColumnMajor, bool IsDstColumnMajor,
int colsDst, int colsDst,
int rowsDst> int rowsDst>
bool SetFloatUniformMatrix(unsigned int arrayElementOffset, void SetFloatUniformMatrix(unsigned int arrayElementOffset,
unsigned int elementCount, unsigned int elementCount,
GLsizei countIn, GLsizei countIn,
const GLfloat *value, const GLfloat *value,
...@@ -167,22 +161,17 @@ bool SetFloatUniformMatrix(unsigned int arrayElementOffset, ...@@ -167,22 +161,17 @@ bool SetFloatUniformMatrix(unsigned int arrayElementOffset,
GLfloat *target = reinterpret_cast<GLfloat *>( GLfloat *target = reinterpret_cast<GLfloat *>(
targetData + arrayElementOffset * sizeof(GLfloat) * targetMatrixStride); targetData + arrayElementOffset * sizeof(GLfloat) * targetMatrixStride);
bool dirty = false;
for (unsigned int i = 0; i < count; i++) for (unsigned int i = 0; i < count; i++)
{ {
dirty = ExpandMatrix<GLfloat, IsSrcColumMajor, colsSrc, rowsSrc, IsDstColumnMajor, colsDst, ExpandMatrix<GLfloat, IsSrcColumMajor, colsSrc, rowsSrc, IsDstColumnMajor, colsDst,
rowsDst>(target, value) || rowsDst>(target, value);
dirty;
target += targetMatrixStride; target += targetMatrixStride;
value += colsSrc * rowsSrc; value += colsSrc * rowsSrc;
} }
return dirty;
} }
bool SetFloatUniformMatrixFast(unsigned int arrayElementOffset, void SetFloatUniformMatrixFast(unsigned int arrayElementOffset,
unsigned int elementCount, unsigned int elementCount,
GLsizei countIn, GLsizei countIn,
size_t matrixSize, size_t matrixSize,
...@@ -195,13 +184,8 @@ bool SetFloatUniformMatrixFast(unsigned int arrayElementOffset, ...@@ -195,13 +184,8 @@ bool SetFloatUniformMatrixFast(unsigned int arrayElementOffset,
const uint8_t *valueData = reinterpret_cast<const uint8_t *>(value); const uint8_t *valueData = reinterpret_cast<const uint8_t *>(value);
targetData = targetData + arrayElementOffset * matrixSize; targetData = targetData + arrayElementOffset * matrixSize;
if (memcmp(targetData, valueData, matrixSize * count) == 0)
{
return false;
}
memcpy(targetData, valueData, matrixSize * count); memcpy(targetData, valueData, matrixSize * count);
return true;
} }
} // anonymous namespace } // anonymous namespace
...@@ -519,7 +503,7 @@ angle::Result IncompleteTextureSet::getIncompleteTexture( ...@@ -519,7 +503,7 @@ angle::Result IncompleteTextureSet::getIncompleteTexture(
} }
#define ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(api, cols, rows) \ #define ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(api, cols, rows) \
template bool SetFloatUniformMatrix##api<cols, rows>::Run( \ template void SetFloatUniformMatrix##api<cols, rows>::Run( \
unsigned int, unsigned int, GLsizei, GLboolean, const GLfloat *, uint8_t *) unsigned int, unsigned int, GLsizei, GLboolean, const GLfloat *, uint8_t *)
ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(GLSL, 2, 2); ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(GLSL, 2, 2);
...@@ -539,13 +523,13 @@ ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(HLSL, 3, 4); ...@@ -539,13 +523,13 @@ ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(HLSL, 3, 4);
#undef ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC #undef ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC
#define ANGLE_SPECIALIZATION_ROWS_SET_UNIFORM_MATRIX_FUNC(api, cols, rows) \ #define ANGLE_SPECIALIZATION_ROWS_SET_UNIFORM_MATRIX_FUNC(api, cols, rows) \
template bool SetFloatUniformMatrix##api<cols, 4>::Run(unsigned int, unsigned int, GLsizei, \ template void SetFloatUniformMatrix##api<cols, 4>::Run(unsigned int, unsigned int, GLsizei, \
GLboolean, const GLfloat *, uint8_t *) GLboolean, const GLfloat *, uint8_t *)
template <int cols> template <int cols>
struct SetFloatUniformMatrixGLSL<cols, 4> struct SetFloatUniformMatrixGLSL<cols, 4>
{ {
static bool Run(unsigned int arrayElementOffset, static void Run(unsigned int arrayElementOffset,
unsigned int elementCount, unsigned int elementCount,
GLsizei countIn, GLsizei countIn,
GLboolean transpose, GLboolean transpose,
...@@ -560,13 +544,13 @@ ANGLE_SPECIALIZATION_ROWS_SET_UNIFORM_MATRIX_FUNC(GLSL, 4, 4); ...@@ -560,13 +544,13 @@ ANGLE_SPECIALIZATION_ROWS_SET_UNIFORM_MATRIX_FUNC(GLSL, 4, 4);
#undef ANGLE_SPECIALIZATION_ROWS_SET_UNIFORM_MATRIX_FUNC #undef ANGLE_SPECIALIZATION_ROWS_SET_UNIFORM_MATRIX_FUNC
#define ANGLE_SPECIALIZATION_COLS_SET_UNIFORM_MATRIX_FUNC(api, cols, rows) \ #define ANGLE_SPECIALIZATION_COLS_SET_UNIFORM_MATRIX_FUNC(api, cols, rows) \
template bool SetFloatUniformMatrix##api<4, rows>::Run(unsigned int, unsigned int, GLsizei, \ template void SetFloatUniformMatrix##api<4, rows>::Run(unsigned int, unsigned int, GLsizei, \
GLboolean, const GLfloat *, uint8_t *) GLboolean, const GLfloat *, uint8_t *)
template <int rows> template <int rows>
struct SetFloatUniformMatrixHLSL<4, rows> struct SetFloatUniformMatrixHLSL<4, rows>
{ {
static bool Run(unsigned int arrayElementOffset, static void Run(unsigned int arrayElementOffset,
unsigned int elementCount, unsigned int elementCount,
GLsizei countIn, GLsizei countIn,
GLboolean transpose, GLboolean transpose,
...@@ -581,7 +565,7 @@ ANGLE_SPECIALIZATION_COLS_SET_UNIFORM_MATRIX_FUNC(HLSL, 4, 4); ...@@ -581,7 +565,7 @@ ANGLE_SPECIALIZATION_COLS_SET_UNIFORM_MATRIX_FUNC(HLSL, 4, 4);
#undef ANGLE_SPECIALIZATION_COLS_SET_UNIFORM_MATRIX_FUNC #undef ANGLE_SPECIALIZATION_COLS_SET_UNIFORM_MATRIX_FUNC
template <int cols> template <int cols>
bool SetFloatUniformMatrixGLSL<cols, 4>::Run(unsigned int arrayElementOffset, void SetFloatUniformMatrixGLSL<cols, 4>::Run(unsigned int arrayElementOffset,
unsigned int elementCount, unsigned int elementCount,
GLsizei countIn, GLsizei countIn,
GLboolean transpose, GLboolean transpose,
...@@ -594,19 +578,19 @@ bool SetFloatUniformMatrixGLSL<cols, 4>::Run(unsigned int arrayElementOffset, ...@@ -594,19 +578,19 @@ bool SetFloatUniformMatrixGLSL<cols, 4>::Run(unsigned int arrayElementOffset,
// Both src and dst matrixs are has same layout, // Both src and dst matrixs are has same layout,
// a single memcpy updates all the matrices // a single memcpy updates all the matrices
constexpr size_t srcMatrixSize = sizeof(GLfloat) * cols * 4; constexpr size_t srcMatrixSize = sizeof(GLfloat) * cols * 4;
return SetFloatUniformMatrixFast(arrayElementOffset, elementCount, countIn, srcMatrixSize, SetFloatUniformMatrixFast(arrayElementOffset, elementCount, countIn, srcMatrixSize, value,
value, targetData); targetData);
} }
else else
{ {
// fallback to general cases // fallback to general cases
return SetFloatUniformMatrix<false, cols, 4, true, cols, 4>( SetFloatUniformMatrix<false, cols, 4, true, cols, 4>(arrayElementOffset, elementCount,
arrayElementOffset, elementCount, countIn, value, targetData); countIn, value, targetData);
} }
} }
template <int cols, int rows> template <int cols, int rows>
bool SetFloatUniformMatrixGLSL<cols, rows>::Run(unsigned int arrayElementOffset, void SetFloatUniformMatrixGLSL<cols, rows>::Run(unsigned int arrayElementOffset,
unsigned int elementCount, unsigned int elementCount,
GLsizei countIn, GLsizei countIn,
GLboolean transpose, GLboolean transpose,
...@@ -617,18 +601,18 @@ bool SetFloatUniformMatrixGLSL<cols, rows>::Run(unsigned int arrayElementOffset, ...@@ -617,18 +601,18 @@ bool SetFloatUniformMatrixGLSL<cols, rows>::Run(unsigned int arrayElementOffset,
// GLSL expects matrix uniforms to be column-major, and each column is padded to 4 rows. // GLSL expects matrix uniforms to be column-major, and each column is padded to 4 rows.
if (isSrcColumnMajor) if (isSrcColumnMajor)
{ {
return SetFloatUniformMatrix<true, cols, rows, true, cols, 4>( SetFloatUniformMatrix<true, cols, rows, true, cols, 4>(arrayElementOffset, elementCount,
arrayElementOffset, elementCount, countIn, value, targetData); countIn, value, targetData);
} }
else else
{ {
return SetFloatUniformMatrix<false, cols, rows, true, cols, 4>( SetFloatUniformMatrix<false, cols, rows, true, cols, 4>(arrayElementOffset, elementCount,
arrayElementOffset, elementCount, countIn, value, targetData); countIn, value, targetData);
} }
} }
template <int rows> template <int rows>
bool SetFloatUniformMatrixHLSL<4, rows>::Run(unsigned int arrayElementOffset, void SetFloatUniformMatrixHLSL<4, rows>::Run(unsigned int arrayElementOffset,
unsigned int elementCount, unsigned int elementCount,
GLsizei countIn, GLsizei countIn,
GLboolean transpose, GLboolean transpose,
...@@ -641,19 +625,19 @@ bool SetFloatUniformMatrixHLSL<4, rows>::Run(unsigned int arrayElementOffset, ...@@ -641,19 +625,19 @@ bool SetFloatUniformMatrixHLSL<4, rows>::Run(unsigned int arrayElementOffset,
// Both src and dst matrixs are has same layout, // Both src and dst matrixs are has same layout,
// a single memcpy updates all the matrices // a single memcpy updates all the matrices
constexpr size_t srcMatrixSize = sizeof(GLfloat) * 4 * rows; constexpr size_t srcMatrixSize = sizeof(GLfloat) * 4 * rows;
return SetFloatUniformMatrixFast(arrayElementOffset, elementCount, countIn, srcMatrixSize, SetFloatUniformMatrixFast(arrayElementOffset, elementCount, countIn, srcMatrixSize, value,
value, targetData); targetData);
} }
else else
{ {
// fallback to general cases // fallback to general cases
return SetFloatUniformMatrix<true, 4, rows, false, 4, rows>( SetFloatUniformMatrix<true, 4, rows, false, 4, rows>(arrayElementOffset, elementCount,
arrayElementOffset, elementCount, countIn, value, targetData); countIn, value, targetData);
} }
} }
template <int cols, int rows> template <int cols, int rows>
bool SetFloatUniformMatrixHLSL<cols, rows>::Run(unsigned int arrayElementOffset, void SetFloatUniformMatrixHLSL<cols, rows>::Run(unsigned int arrayElementOffset,
unsigned int elementCount, unsigned int elementCount,
GLsizei countIn, GLsizei countIn,
GLboolean transpose, GLboolean transpose,
...@@ -665,13 +649,13 @@ bool SetFloatUniformMatrixHLSL<cols, rows>::Run(unsigned int arrayElementOffset, ...@@ -665,13 +649,13 @@ bool SetFloatUniformMatrixHLSL<cols, rows>::Run(unsigned int arrayElementOffset,
// padded to 4 columns. // padded to 4 columns.
if (!isSrcColumnMajor) if (!isSrcColumnMajor)
{ {
return SetFloatUniformMatrix<false, cols, rows, false, 4, rows>( SetFloatUniformMatrix<false, cols, rows, false, 4, rows>(arrayElementOffset, elementCount,
arrayElementOffset, elementCount, countIn, value, targetData); countIn, value, targetData);
} }
else else
{ {
return SetFloatUniformMatrix<true, cols, rows, false, 4, rows>( SetFloatUniformMatrix<true, cols, rows, false, 4, rows>(arrayElementOffset, elementCount,
arrayElementOffset, elementCount, countIn, value, targetData); countIn, value, targetData);
} }
} }
......
...@@ -269,7 +269,7 @@ class IncompleteTextureSet final : angle::NonCopyable ...@@ -269,7 +269,7 @@ class IncompleteTextureSet final : angle::NonCopyable
template <int cols, int rows> template <int cols, int rows>
struct SetFloatUniformMatrixGLSL struct SetFloatUniformMatrixGLSL
{ {
static bool Run(unsigned int arrayElementOffset, static void Run(unsigned int arrayElementOffset,
unsigned int elementCount, unsigned int elementCount,
GLsizei countIn, GLsizei countIn,
GLboolean transpose, GLboolean transpose,
...@@ -280,7 +280,7 @@ struct SetFloatUniformMatrixGLSL ...@@ -280,7 +280,7 @@ struct SetFloatUniformMatrixGLSL
template <int cols, int rows> template <int cols, int rows>
struct SetFloatUniformMatrixHLSL struct SetFloatUniformMatrixHLSL
{ {
static bool Run(unsigned int arrayElementOffset, static void Run(unsigned int arrayElementOffset,
unsigned int elementCount, unsigned int elementCount,
GLsizei countIn, GLsizei countIn,
GLboolean transpose, GLboolean transpose,
......
...@@ -930,18 +930,12 @@ void ProgramVk::setUniformMatrixfv(GLint location, ...@@ -930,18 +930,12 @@ void ProgramVk::setUniformMatrixfv(GLint location,
continue; continue;
} }
bool updated = SetFloatUniformMatrixGLSL<cols, rows>::Run( SetFloatUniformMatrixGLSL<cols, rows>::Run(
locationInfo.arrayIndex, linkedUniform.getArraySizeProduct(), count, transpose, value, locationInfo.arrayIndex, linkedUniform.getArraySizeProduct(), count, transpose, value,
uniformBlock.uniformData.data() + layoutInfo.offset); uniformBlock.uniformData.data() + layoutInfo.offset);
// If the uniformsDirty flag was true, we don't want to flip it to false here if the
// setter did not update any data. We still want the uniform to be included when we'll
// update the descriptor sets.
if (updated)
{
mDefaultUniformBlocksDirty.set(shaderType); mDefaultUniformBlocksDirty.set(shaderType);
} }
}
} }
void ProgramVk::setUniformMatrix2fv(GLint location, void ProgramVk::setUniformMatrix2fv(GLint location,
......
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