Commit e0f059c5 by jbauman@chromium.org

Remove calls to new when modifying shader constants.

There were some unnecessary temporary copies we can remove, and the rest have a maximum size so we can allocate them on the stack. BUG=276 TEST= Review URL: https://codereview.appspot.com/5540071 git-svn-id: https://angleproject.googlecode.com/svn/trunk@961 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 9dc0a247
#define MAJOR_VERSION 1
#define MINOR_VERSION 0
#define BUILD_VERSION 0
#define BUILD_REVISION 960
#define BUILD_REVISION 961
#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)
......
......@@ -59,8 +59,12 @@ class Query;
enum
{
D3D9_MAX_FLOAT_CONSTANTS = 256,
D3D9_MAX_BOOL_CONSTANTS = 16,
D3D9_MAX_INT_CONSTANTS = 16,
MAX_VERTEX_ATTRIBS = 16,
MAX_VERTEX_UNIFORM_VECTORS = 256 - 2, // 256 is the minimum for SM2, and in practice the maximum for DX9. Reserve space for dx_HalfPixelSize and dx_DepthRange.
MAX_VERTEX_UNIFORM_VECTORS = D3D9_MAX_FLOAT_CONSTANTS - 2, // Reserve space for dx_HalfPixelSize and dx_DepthRange.
MAX_VARYING_VECTORS_SM2 = 8,
MAX_VARYING_VECTORS_SM3 = 10,
MAX_TEXTURE_IMAGE_UNITS = 16,
......
......@@ -333,7 +333,7 @@ bool Program::setUniform1fv(GLint location, GLsizei count, const GLfloat* v)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count);
GLboolean *boolParams = new GLboolean[count];
GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element;
for (int i = 0; i < count; ++i)
{
......@@ -346,11 +346,6 @@ bool Program::setUniform1fv(GLint location, GLsizei count, const GLfloat* v)
boolParams[i] = GL_TRUE;
}
}
memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLboolean),
boolParams, sizeof(GLboolean) * count);
delete [] boolParams;
}
else
{
......@@ -400,7 +395,7 @@ bool Program::setUniform2fv(GLint location, GLsizei count, const GLfloat *v)
count = std::min(arraySize - (int)mUniformIndex[location].element, count);
GLboolean *boolParams = new GLboolean[count * 2];
GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * 2;
for (int i = 0; i < count * 2; ++i)
{
......@@ -413,11 +408,6 @@ bool Program::setUniform2fv(GLint location, GLsizei count, const GLfloat *v)
boolParams[i] = GL_TRUE;
}
}
memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLboolean) * 2,
boolParams, 2 * sizeof(GLboolean) * count);
delete [] boolParams;
}
else
{
......@@ -466,7 +456,7 @@ bool Program::setUniform3fv(GLint location, GLsizei count, const GLfloat *v)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count);
GLboolean *boolParams = new GLboolean[count * 3];
GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * 3;
for (int i = 0; i < count * 3; ++i)
{
......@@ -479,11 +469,6 @@ bool Program::setUniform3fv(GLint location, GLsizei count, const GLfloat *v)
boolParams[i] = GL_TRUE;
}
}
memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLboolean) * 3,
boolParams, 3 * sizeof(GLboolean) * count);
delete [] boolParams;
}
else
{
......@@ -523,7 +508,7 @@ bool Program::setUniform4fv(GLint location, GLsizei count, const GLfloat *v)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count);
GLboolean *boolParams = new GLboolean[count * 4];
GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * 4;
for (int i = 0; i < count * 4; ++i)
{
......@@ -536,11 +521,6 @@ bool Program::setUniform4fv(GLint location, GLsizei count, const GLfloat *v)
boolParams[i] = GL_TRUE;
}
}
memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLboolean) * 4,
boolParams, 4 * sizeof(GLboolean) * count);
delete [] boolParams;
}
else
{
......@@ -713,7 +693,7 @@ bool Program::setUniform1iv(GLint location, GLsizei count, const GLint *v)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count);
GLboolean *boolParams = new GLboolean[count];
GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element;
for (int i = 0; i < count; ++i)
{
......@@ -726,11 +706,6 @@ bool Program::setUniform1iv(GLint location, GLsizei count, const GLint *v)
boolParams[i] = GL_TRUE;
}
}
memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLboolean),
boolParams, sizeof(GLboolean) * count);
delete [] boolParams;
}
else
{
......@@ -770,7 +745,7 @@ bool Program::setUniform2iv(GLint location, GLsizei count, const GLint *v)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count);
GLboolean *boolParams = new GLboolean[count * 2];
GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * 2;
for (int i = 0; i < count * 2; ++i)
{
......@@ -783,11 +758,6 @@ bool Program::setUniform2iv(GLint location, GLsizei count, const GLint *v)
boolParams[i] = GL_TRUE;
}
}
memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLboolean) * 2,
boolParams, 2 * sizeof(GLboolean) * count);
delete [] boolParams;
}
else
{
......@@ -827,7 +797,7 @@ bool Program::setUniform3iv(GLint location, GLsizei count, const GLint *v)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count);
GLboolean *boolParams = new GLboolean[count * 3];
GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * 3;
for (int i = 0; i < count * 3; ++i)
{
......@@ -840,11 +810,6 @@ bool Program::setUniform3iv(GLint location, GLsizei count, const GLint *v)
boolParams[i] = GL_TRUE;
}
}
memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLboolean) * 3,
boolParams, 3 * sizeof(GLboolean) * count);
delete [] boolParams;
}
else
{
......@@ -884,7 +849,7 @@ bool Program::setUniform4iv(GLint location, GLsizei count, const GLint *v)
return false; // attempting to write an array to a non-array uniform is an INVALID_OPERATION
count = std::min(arraySize - (int)mUniformIndex[location].element, count);
GLboolean *boolParams = new GLboolean[count * 4];
GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * 4;
for (int i = 0; i < count * 4; ++i)
{
......@@ -897,11 +862,6 @@ bool Program::setUniform4iv(GLint location, GLsizei count, const GLint *v)
boolParams[i] = GL_TRUE;
}
}
memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLboolean) * 4,
boolParams, 4 * sizeof(GLboolean) * count);
delete [] boolParams;
}
else
{
......@@ -2085,14 +2045,13 @@ std::string Program::undecorateUniform(const std::string &_name)
void Program::applyUniformnbv(Uniform *targetUniform, GLsizei count, int width, const GLboolean *v)
{
float *vector = NULL;
BOOL *boolVector = NULL;
float vector[D3D9_MAX_FLOAT_CONSTANTS * 4];
BOOL boolVector[D3D9_MAX_BOOL_CONSTANTS];
if (targetUniform->ps.registerCount && targetUniform->ps.registerSet == D3DXRS_FLOAT4 ||
targetUniform->vs.registerCount && targetUniform->vs.registerSet == D3DXRS_FLOAT4)
{
vector = new float[4 * count];
ASSERT(count <= D3D9_MAX_FLOAT_CONSTANTS);
for (int i = 0; i < count; i++)
{
for (int j = 0; j < 4; j++)
......@@ -2112,8 +2071,11 @@ void Program::applyUniformnbv(Uniform *targetUniform, GLsizei count, int width,
if (targetUniform->ps.registerCount && targetUniform->ps.registerSet == D3DXRS_BOOL ||
targetUniform->vs.registerCount && targetUniform->vs.registerSet == D3DXRS_BOOL)
{
boolVector = new BOOL[count * width];
for (int i = 0; i < count * width; i++)
int psCount = targetUniform->ps.registerSet == D3DXRS_BOOL ? targetUniform->ps.registerCount : 0;
int vsCount = targetUniform->vs.registerSet == D3DXRS_BOOL ? targetUniform->vs.registerCount : 0;
int copyCount = std::min(count * width, std::max(psCount, vsCount));
ASSERT(copyCount <= D3D9_MAX_BOOL_CONSTANTS);
for (int i = 0; i < copyCount; i++)
{
boolVector[i] = v[i] != GL_FALSE;
}
......@@ -2144,9 +2106,6 @@ void Program::applyUniformnbv(Uniform *targetUniform, GLsizei count, int width,
}
else UNREACHABLE();
}
delete [] vector;
delete [] boolVector;
}
bool Program::applyUniformnfv(Uniform *targetUniform, const GLfloat *v)
......@@ -2166,7 +2125,8 @@ bool Program::applyUniformnfv(Uniform *targetUniform, const GLfloat *v)
bool Program::applyUniform1iv(Uniform *targetUniform, GLsizei count, const GLint *v)
{
D3DXVECTOR4 *vector = new D3DXVECTOR4[count];
ASSERT(count <= D3D9_MAX_FLOAT_CONSTANTS);
D3DXVECTOR4 vector[D3D9_MAX_FLOAT_CONSTANTS];
for (int i = 0; i < count; i++)
{
......@@ -2221,14 +2181,13 @@ bool Program::applyUniform1iv(Uniform *targetUniform, GLsizei count, const GLint
}
}
delete [] vector;
return true;
}
bool Program::applyUniform2iv(Uniform *targetUniform, GLsizei count, const GLint *v)
{
D3DXVECTOR4 *vector = new D3DXVECTOR4[count];
ASSERT(count <= D3D9_MAX_FLOAT_CONSTANTS);
D3DXVECTOR4 vector[D3D9_MAX_FLOAT_CONSTANTS];
for (int i = 0; i < count; i++)
{
......@@ -2239,14 +2198,13 @@ bool Program::applyUniform2iv(Uniform *targetUniform, GLsizei count, const GLint
applyUniformniv(targetUniform, count, vector);
delete[] vector;
return true;
}
bool Program::applyUniform3iv(Uniform *targetUniform, GLsizei count, const GLint *v)
{
D3DXVECTOR4 *vector = new D3DXVECTOR4[count];
ASSERT(count <= D3D9_MAX_FLOAT_CONSTANTS);
D3DXVECTOR4 vector[D3D9_MAX_FLOAT_CONSTANTS];
for (int i = 0; i < count; i++)
{
......@@ -2257,14 +2215,13 @@ bool Program::applyUniform3iv(Uniform *targetUniform, GLsizei count, const GLint
applyUniformniv(targetUniform, count, vector);
delete[] vector;
return true;
}
bool Program::applyUniform4iv(Uniform *targetUniform, GLsizei count, const GLint *v)
{
D3DXVECTOR4 *vector = new D3DXVECTOR4[count];
ASSERT(count <= D3D9_MAX_FLOAT_CONSTANTS);
D3DXVECTOR4 vector[D3D9_MAX_FLOAT_CONSTANTS];
for (int i = 0; i < count; i++)
{
......@@ -2275,8 +2232,6 @@ bool Program::applyUniform4iv(Uniform *targetUniform, GLsizei count, const GLint
applyUniformniv(targetUniform, count, vector);
delete [] vector;
return true;
}
......
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