Commit 72e8f447 by jbauman@chromium.org

Avoid unnecessarily copying uniforms

Transpose and expand matrices and float vectors when copied on setUniform (and getUniform) to avoid allocating an array and doing that on applyUniform. Then use straight D3D calls, not D3DX, to possibly avoid another copy. Gets NaCl donuts test from 19->25 fps. BUG= TEST=webgl conformance tests Review URL: http://codereview.appspot.com/5229056 git-svn-id: https://angleproject.googlecode.com/svn/trunk@800 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 3442c2bb
#define MAJOR_VERSION 0 #define MAJOR_VERSION 0
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 799 #define BUILD_REVISION 800
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -42,9 +42,15 @@ struct Uniform ...@@ -42,9 +42,15 @@ struct Uniform
unsigned char *data; unsigned char *data;
bool dirty; bool dirty;
D3DXHANDLE vsHandle; struct RegisterInfo
D3DXHANDLE psHandle; {
bool handlesSet; int registerSet;
int registerIndex;
int registerCount;
};
RegisterInfo ps;
RegisterInfo vs;
}; };
// Struct used for correlating uniforms/elements of uniform arrays to handles // Struct used for correlating uniforms/elements of uniform arrays to handles
...@@ -150,23 +156,15 @@ class Program ...@@ -150,23 +156,15 @@ class Program
bool defineUniform(const D3DXHANDLE &constantHandle, const D3DXCONSTANT_DESC &constantDescription, std::string name = ""); bool defineUniform(const D3DXHANDLE &constantHandle, const D3DXCONSTANT_DESC &constantDescription, std::string name = "");
bool defineUniform(const D3DXCONSTANT_DESC &constantDescription, std::string &name); bool defineUniform(const D3DXCONSTANT_DESC &constantDescription, std::string &name);
Uniform *createUniform(const D3DXCONSTANT_DESC &constantDescription, std::string &name); Uniform *createUniform(const D3DXCONSTANT_DESC &constantDescription, std::string &name);
bool applyUniform1bv(Uniform *targetUniform, GLsizei count, const GLboolean *v); bool applyUniformnfv(Uniform *targetUniform, const GLfloat *v);
bool applyUniform2bv(Uniform *targetUniform, GLsizei count, const GLboolean *v);
bool applyUniform3bv(Uniform *targetUniform, GLsizei count, const GLboolean *v);
bool applyUniform4bv(Uniform *targetUniform, GLsizei count, const GLboolean *v);
bool applyUniform1fv(Uniform *targetUniform, GLsizei count, const GLfloat *v);
bool applyUniform2fv(Uniform *targetUniform, GLsizei count, const GLfloat *v);
bool applyUniform3fv(Uniform *targetUniform, GLsizei count, const GLfloat *v);
bool applyUniform4fv(Uniform *targetUniform, GLsizei count, const GLfloat *v);
bool applyUniformMatrix2fv(Uniform *targetUniform, GLsizei count, const GLfloat *value);
bool applyUniformMatrix3fv(Uniform *targetUniform, GLsizei count, const GLfloat *value);
bool applyUniformMatrix4fv(Uniform *targetUniform, GLsizei count, const GLfloat *value);
bool applyUniform1iv(Uniform *targetUniform, GLsizei count, const GLint *v); bool applyUniform1iv(Uniform *targetUniform, GLsizei count, const GLint *v);
bool applyUniform2iv(Uniform *targetUniform, GLsizei count, const GLint *v); bool applyUniform2iv(Uniform *targetUniform, GLsizei count, const GLint *v);
bool applyUniform3iv(Uniform *targetUniform, GLsizei count, const GLint *v); bool applyUniform3iv(Uniform *targetUniform, GLsizei count, const GLint *v);
bool applyUniform4iv(Uniform *targetUniform, GLsizei count, const GLint *v); bool applyUniform4iv(Uniform *targetUniform, GLsizei count, const GLint *v);
void applyUniformniv(Uniform *targetUniform, GLsizei count, const D3DXVECTOR4 *vector);
void applyUniformnbv(Uniform *targetUniform, GLsizei count, int width, const GLboolean *v);
void getConstantHandles(Uniform *targetUniform, D3DXHANDLE *constantPS, D3DXHANDLE *constantVS); void initializeConstantHandles(Uniform *targetUniform, Uniform::RegisterInfo *rs, ID3DXConstantTable *constantTable);
void appendToInfoLogSanitized(const char *message); void appendToInfoLogSanitized(const char *message);
void appendToInfoLog(const char *info, ...); void appendToInfoLog(const char *info, ...);
......
...@@ -54,6 +54,42 @@ int UniformComponentCount(GLenum type) ...@@ -54,6 +54,42 @@ int UniformComponentCount(GLenum type)
return 0; return 0;
} }
// This is how much data we actually store for a uniform
int UniformInternalComponentCount(GLenum type)
{
switch (type)
{
case GL_BOOL:
case GL_INT:
case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE:
return 1;
case GL_BOOL_VEC2:
case GL_INT_VEC2:
return 2;
case GL_INT_VEC3:
case GL_BOOL_VEC3:
return 3;
case GL_FLOAT:
case GL_FLOAT_VEC2:
case GL_FLOAT_VEC3:
case GL_BOOL_VEC4:
case GL_FLOAT_VEC4:
case GL_INT_VEC4:
return 4;
case GL_FLOAT_MAT2:
return 8;
case GL_FLOAT_MAT3:
return 12;
case GL_FLOAT_MAT4:
return 16;
default:
UNREACHABLE();
}
return 0;
}
GLenum UniformComponentType(GLenum type) GLenum UniformComponentType(GLenum type)
{ {
switch(type) switch(type)
...@@ -85,16 +121,22 @@ GLenum UniformComponentType(GLenum type) ...@@ -85,16 +121,22 @@ GLenum UniformComponentType(GLenum type)
return GL_NONE; return GL_NONE;
} }
size_t UniformTypeSize(GLenum type) size_t UniformComponentSize(GLenum type)
{ {
switch(type) switch(type)
{ {
case GL_BOOL: return sizeof(GLboolean); case GL_BOOL: return sizeof(GLboolean);
case GL_FLOAT: return sizeof(GLfloat); case GL_FLOAT: return sizeof(GLfloat);
case GL_INT: return sizeof(GLint); case GL_INT: return sizeof(GLint);
default: UNREACHABLE();
} }
return UniformTypeSize(UniformComponentType(type)) * UniformComponentCount(type); return 0;
}
size_t UniformTypeSize(GLenum type)
{
return UniformComponentSize(UniformComponentType(type)) * UniformInternalComponentCount(type);
} }
int VariableRowCount(GLenum type) int VariableRowCount(GLenum type)
......
...@@ -22,6 +22,7 @@ namespace gl ...@@ -22,6 +22,7 @@ namespace gl
struct Color; struct Color;
int UniformComponentCount(GLenum type); int UniformComponentCount(GLenum type);
int UniformInternalComponentCount(GLenum type);
GLenum UniformComponentType(GLenum type); GLenum UniformComponentType(GLenum type);
size_t UniformTypeSize(GLenum type); size_t UniformTypeSize(GLenum type);
int VariableRowCount(GLenum type); int VariableRowCount(GLenum type);
......
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