Commit b58e9bac by Corentin Wallez Committed by Commit Bot

ProgramD3D: optimize Transpose/ExpandMatrix

BUG=angleproject:1390 Change-Id: I7e8eb1f7924014bbde38269ef0fd0f7d65639083 Reviewed-on: https://chromium-review.googlesource.com/420518 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent b1d0a255
...@@ -199,84 +199,64 @@ static inline void SetIfDirty(T *dest, const T &source, bool *dirtyFlag) ...@@ -199,84 +199,64 @@ static inline void SetIfDirty(T *dest, const T &source, bool *dirtyFlag)
*dest = source; *dest = source;
} }
template <typename T> template <typename T, int cols, int rows>
bool TransposeMatrix(T *target, bool TransposeExpandMatrix(T *target, const GLfloat *value)
const GLfloat *value,
int targetWidth,
int targetHeight,
int srcWidth,
int srcHeight)
{ {
bool dirty = false; constexpr int targetWidth = 4;
int copyWidth = std::min(targetHeight, srcWidth); constexpr int targetHeight = rows;
int copyHeight = std::min(targetWidth, srcHeight); constexpr int srcWidth = rows;
constexpr int srcHeight = cols;
constexpr int copyWidth = std::min(targetHeight, srcWidth);
constexpr int copyHeight = std::min(targetWidth, srcHeight);
T staging[targetWidth * targetHeight] = {0};
for (int x = 0; x < copyWidth; x++) for (int x = 0; x < copyWidth; x++)
{ {
for (int y = 0; y < copyHeight; y++) for (int y = 0; y < copyHeight; y++)
{ {
SetIfDirty(target + (x * targetWidth + y), static_cast<T>(value[y * srcWidth + x]), staging[x * targetWidth + y] = static_cast<T>(value[y * srcWidth + x]);
&dirty);
}
}
// clear unfilled right side
for (int y = 0; y < copyWidth; y++)
{
for (int x = copyHeight; x < targetWidth; x++)
{
SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
} }
} }
// clear unfilled bottom.
for (int y = copyWidth; y < targetHeight; y++) if (memcmp(target, staging, targetWidth * targetHeight * sizeof(T)) == 0)
{ {
for (int x = 0; x < targetWidth; x++) return false;
{
SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
}
} }
return dirty; memcpy(target, staging, targetWidth * targetHeight * sizeof(T));
return true;
} }
template <typename T> template <typename T, int cols, int rows>
bool ExpandMatrix(T *target, bool ExpandMatrix(T *target, const GLfloat *value)
const GLfloat *value,
int targetWidth,
int targetHeight,
int srcWidth,
int srcHeight)
{ {
bool dirty = false; constexpr int targetWidth = 4;
int copyWidth = std::min(targetWidth, srcWidth); constexpr int targetHeight = rows;
int copyHeight = std::min(targetHeight, srcHeight); constexpr int srcWidth = cols;
constexpr int srcHeight = rows;
constexpr int copyWidth = std::min(targetWidth, srcWidth);
constexpr int copyHeight = std::min(targetHeight, srcHeight);
T staging[targetWidth * targetHeight] = {0};
for (int y = 0; y < copyHeight; y++) for (int y = 0; y < copyHeight; y++)
{ {
for (int x = 0; x < copyWidth; x++) for (int x = 0; x < copyWidth; x++)
{ {
SetIfDirty(target + (y * targetWidth + x), static_cast<T>(value[y * srcWidth + x]), staging[y * targetWidth + x] = static_cast<T>(value[y * srcWidth + x]);
&dirty);
}
}
// clear unfilled right side
for (int y = 0; y < copyHeight; y++)
{
for (int x = copyWidth; x < targetWidth; x++)
{
SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
} }
} }
// clear unfilled bottom.
for (int y = copyHeight; y < targetHeight; y++) if (memcmp(target, staging, targetWidth * targetHeight * sizeof(T)) == 0)
{ {
for (int x = 0; x < targetWidth; x++) return false;
{
SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
}
} }
return dirty; memcpy(target, staging, targetWidth * targetHeight * sizeof(T));
return true;
} }
gl::PrimitiveType GetGeometryShaderTypeFromDrawMode(GLenum drawMode) gl::PrimitiveType GetGeometryShaderTypeFromDrawMode(GLenum drawMode)
...@@ -2147,13 +2127,13 @@ void ProgramD3D::setUniformMatrixfv(GLint location, ...@@ -2147,13 +2127,13 @@ void ProgramD3D::setUniformMatrixfv(GLint location,
// 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)
{ {
targetUniform->dirty = TransposeMatrix<GLfloat>(target, value, 4, rows, rows, cols) || targetUniform->dirty =
targetUniform->dirty; TransposeExpandMatrix<GLfloat, cols, rows>(target, value) || targetUniform->dirty;
} }
else else
{ {
targetUniform->dirty = targetUniform->dirty =
ExpandMatrix<GLfloat>(target, value, 4, rows, cols, rows) || targetUniform->dirty; ExpandMatrix<GLfloat, cols, rows>(target, value) || targetUniform->dirty;
} }
target += targetMatrixStride; target += targetMatrixStride;
value += cols * rows; value += cols * rows;
......
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