Commit 134f93d1 by Jamie Madill Committed by Commit Bot

D3D: Small optimizations to uniform updates.

Uses more of the type info table for updates. Also special-case clamping when uniform count == 1. Improves the speed of the d3d11 uniform stress test by ~20%. BUG=angleproject:1390 Change-Id: I6707c67db84c94a28b1519b0bbee5d28fe38b189 Reviewed-on: https://chromium-review.googlesource.com/646828Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent edd5981f
......@@ -2982,6 +2982,9 @@ GLsizei Program::clampUniformCount(const VariableLocation &locationInfo,
int vectorSize,
const T *v)
{
if (count == 1)
return 1;
const LinkedUniform &linkedUniform = mState.mUniforms[locationInfo.index];
// OpenGL ES 3.0.4 spec pg 67: "Values for any array element that exceeds the highest array
......
......@@ -1865,22 +1865,22 @@ void ProgramD3D::dirtyAllUniforms()
void ProgramD3D::setUniform1fv(GLint location, GLsizei count, const GLfloat *v)
{
setUniformInternal(location, count, v, GL_FLOAT);
setUniformInternal(location, count, v, gl::GetUniformTypeInfo(GL_FLOAT));
}
void ProgramD3D::setUniform2fv(GLint location, GLsizei count, const GLfloat *v)
{
setUniformInternal(location, count, v, GL_FLOAT_VEC2);
setUniformInternal(location, count, v, gl::GetUniformTypeInfo(GL_FLOAT_VEC2));
}
void ProgramD3D::setUniform3fv(GLint location, GLsizei count, const GLfloat *v)
{
setUniformInternal(location, count, v, GL_FLOAT_VEC3);
setUniformInternal(location, count, v, gl::GetUniformTypeInfo(GL_FLOAT_VEC3));
}
void ProgramD3D::setUniform4fv(GLint location, GLsizei count, const GLfloat *v)
{
setUniformInternal(location, count, v, GL_FLOAT_VEC4);
setUniformInternal(location, count, v, gl::GetUniformTypeInfo(GL_FLOAT_VEC4));
}
void ProgramD3D::setUniformMatrix2fv(GLint location,
......@@ -1957,42 +1957,42 @@ void ProgramD3D::setUniformMatrix4x3fv(GLint location,
void ProgramD3D::setUniform1iv(GLint location, GLsizei count, const GLint *v)
{
setUniformInternal(location, count, v, GL_INT);
setUniformInternal(location, count, v, gl::GetUniformTypeInfo(GL_INT));
}
void ProgramD3D::setUniform2iv(GLint location, GLsizei count, const GLint *v)
{
setUniformInternal(location, count, v, GL_INT_VEC2);
setUniformInternal(location, count, v, gl::GetUniformTypeInfo(GL_INT_VEC2));
}
void ProgramD3D::setUniform3iv(GLint location, GLsizei count, const GLint *v)
{
setUniformInternal(location, count, v, GL_INT_VEC3);
setUniformInternal(location, count, v, gl::GetUniformTypeInfo(GL_INT_VEC3));
}
void ProgramD3D::setUniform4iv(GLint location, GLsizei count, const GLint *v)
{
setUniformInternal(location, count, v, GL_INT_VEC4);
setUniformInternal(location, count, v, gl::GetUniformTypeInfo(GL_INT_VEC4));
}
void ProgramD3D::setUniform1uiv(GLint location, GLsizei count, const GLuint *v)
{
setUniformInternal(location, count, v, GL_UNSIGNED_INT);
setUniformInternal(location, count, v, gl::GetUniformTypeInfo(GL_UNSIGNED_INT));
}
void ProgramD3D::setUniform2uiv(GLint location, GLsizei count, const GLuint *v)
{
setUniformInternal(location, count, v, GL_UNSIGNED_INT_VEC2);
setUniformInternal(location, count, v, gl::GetUniformTypeInfo(GL_UNSIGNED_INT_VEC2));
}
void ProgramD3D::setUniform3uiv(GLint location, GLsizei count, const GLuint *v)
{
setUniformInternal(location, count, v, GL_UNSIGNED_INT_VEC3);
setUniformInternal(location, count, v, gl::GetUniformTypeInfo(GL_UNSIGNED_INT_VEC3));
}
void ProgramD3D::setUniform4uiv(GLint location, GLsizei count, const GLuint *v)
{
setUniformInternal(location, count, v, GL_UNSIGNED_INT_VEC4);
setUniformInternal(location, count, v, gl::GetUniformTypeInfo(GL_UNSIGNED_INT_VEC4));
}
void ProgramD3D::setUniformBlockBinding(GLuint /*uniformBlockIndex*/,
......@@ -2175,38 +2175,34 @@ void ProgramD3D::defineUniform(GLenum shaderType,
}
}
// Assume count is already clamped.
template <typename T>
void ProgramD3D::setUniformImpl(const gl::VariableLocation &locationInfo,
GLsizei countIn,
GLsizei count,
const T *v,
uint8_t *targetData,
GLenum targetUniformType)
const gl::UniformTypeInfo &uniformTypeInfo)
{
const int components = gl::VariableComponentCount(targetUniformType);
const GLenum targetBoolType = gl::VariableBoolVectorType(targetUniformType);
D3DUniform *targetUniform = mD3DUniforms[locationInfo.index];
unsigned int elementCount = targetUniform->elementCount();
const int components = uniformTypeInfo.componentCount;
unsigned int arrayElement = locationInfo.element;
unsigned int count = std::min(elementCount - arrayElement, static_cast<unsigned int>(countIn));
if (targetUniform->type == targetUniformType)
if (targetUniform->type == uniformTypeInfo.type)
{
T *target = reinterpret_cast<T *>(targetData) + arrayElement * 4;
for (unsigned int i = 0; i < count; i++)
for (GLint i = 0; i < count; i++)
{
T *dest = target + (i * 4);
const T *source = v + (i * components);
memcpy(dest, source, components * sizeof(T));
}
}
else if (targetUniform->type == targetBoolType)
else if (targetUniform->type == uniformTypeInfo.boolVectorType)
{
GLint *boolParams = reinterpret_cast<GLint *>(targetData) + arrayElement * 4;
for (unsigned int i = 0; i < count; i++)
for (GLint i = 0; i < count; i++)
{
GLint *dest = boolParams + (i * 4);
const T *source = v + (i * components);
......@@ -2225,7 +2221,7 @@ template <typename T>
void ProgramD3D::setUniformInternal(GLint location,
GLsizei count,
const T *v,
GLenum targetUniformType)
const gl::UniformTypeInfo &uniformTypeInfo)
{
const gl::VariableLocation &locationInfo = mState.getUniformLocations()[location];
D3DUniform *targetUniform = mD3DUniforms[locationInfo.index];
......@@ -2234,7 +2230,7 @@ void ProgramD3D::setUniformInternal(GLint location,
if (!targetUniform->mSamplerData.empty())
{
ASSERT(targetUniformType == GL_INT);
ASSERT(uniformTypeInfo.type == GL_INT);
memcpy(&targetUniform->mSamplerData[locationInfo.element], v, count * sizeof(T));
mDirtySamplerMapping = true;
return;
......@@ -2242,17 +2238,17 @@ void ProgramD3D::setUniformInternal(GLint location,
if (targetUniform->vsData)
{
setUniformImpl(locationInfo, count, v, targetUniform->vsData, targetUniformType);
setUniformImpl(locationInfo, count, v, targetUniform->vsData, uniformTypeInfo);
}
if (targetUniform->psData)
{
setUniformImpl(locationInfo, count, v, targetUniform->psData, targetUniformType);
setUniformImpl(locationInfo, count, v, targetUniform->psData, uniformTypeInfo);
}
if (targetUniform->csData)
{
setUniformImpl(locationInfo, count, v, targetUniform->csData, targetUniformType);
setUniformImpl(locationInfo, count, v, targetUniform->csData, uniformTypeInfo);
}
}
......
......@@ -383,10 +383,13 @@ class ProgramD3D : public ProgramImpl
GLsizei count,
const T *v,
uint8_t *targetData,
GLenum targetUniformType);
const gl::UniformTypeInfo &uniformTypeInfo);
template <typename T>
void setUniformInternal(GLint location, GLsizei count, const T *v, GLenum targetUniformType);
void setUniformInternal(GLint location,
GLsizei count,
const T *v,
const gl::UniformTypeInfo &uniformTypeInfo);
template <int cols, int rows>
void setUniformMatrixfvImpl(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