Commit b6e7222c by jbauman@chromium.org

Avoid iterating over unused samplers.

Keep track of the maximum used sampler to avoid expensive iterations in applyTextures and validateSamplers. BUG= TEST=webgl conformance tests Review URL: http://codereview.appspot.com/5246061 git-svn-id: https://angleproject.googlecode.com/svn/trunk@795 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 040c4db3
#define MAJOR_VERSION 0
#define MINOR_VERSION 0
#define BUILD_VERSION 0
#define BUILD_REVISION 794
#define BUILD_REVISION 795
#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)
......
......@@ -2117,8 +2117,9 @@ void Context::applyTextures(SamplerType type)
int samplerCount = (type == SAMPLER_PIXEL) ? MAX_TEXTURE_IMAGE_UNITS : MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF; // Range of Direct3D 9 samplers of given sampler type
unsigned int *appliedTextureSerial = (type == SAMPLER_PIXEL) ? mAppliedTextureSerialPS : mAppliedTextureSerialVS;
int d3dSamplerOffset = (type == SAMPLER_PIXEL) ? 0 : D3DVERTEXTEXTURESAMPLER0;
int samplerRange = programObject->getUsedSamplerRange(type);
for (int samplerIndex = 0; samplerIndex < samplerCount; samplerIndex++)
for (int samplerIndex = 0; samplerIndex < samplerRange; samplerIndex++)
{
int textureUnit = programObject->getSamplerMapping(type, samplerIndex); // OpenGL texture image unit index
int d3dSampler = samplerIndex + d3dSamplerOffset;
......@@ -2175,6 +2176,15 @@ void Context::applyTextures(SamplerType type)
}
}
}
for (int samplerIndex = samplerRange; samplerIndex < samplerCount; samplerIndex++)
{
if (appliedTextureSerial[samplerIndex] != 0)
{
device->SetTexture(samplerIndex + d3dSamplerOffset, NULL);
appliedTextureSerial[samplerIndex] = 0;
}
}
}
void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels)
......
......@@ -198,6 +198,21 @@ int Program::getSemanticIndex(int attributeIndex)
return mSemanticIndex[attributeIndex];
}
// Returns one more than the highest sampler index used.
GLint Program::getUsedSamplerRange(SamplerType type)
{
switch (type)
{
case SAMPLER_PIXEL:
return mUsedPixelSamplerRange;
case SAMPLER_VERTEX:
return mUsedVertexSamplerRange;
default:
UNREACHABLE();
return 0;
}
}
// Returns the index of the texture image unit (0-19) corresponding to a Direct3D 9 sampler
// index (0-15 for the pixel shader and 0-3 for the vertex shader).
GLint Program::getSamplerMapping(SamplerType type, unsigned int samplerIndex)
......@@ -1717,6 +1732,7 @@ bool Program::defineUniform(const D3DXHANDLE &constantHandle, const D3DXCONSTANT
mSamplersPS[samplerIndex].active = true;
mSamplersPS[samplerIndex].textureType = (constantDescription.Type == D3DXPT_SAMPLERCUBE) ? TEXTURE_CUBE : TEXTURE_2D;
mSamplersPS[samplerIndex].logicalTextureUnit = 0;
mUsedPixelSamplerRange = std::max(samplerIndex + 1, mUsedPixelSamplerRange);
}
else
{
......@@ -1732,6 +1748,7 @@ bool Program::defineUniform(const D3DXHANDLE &constantHandle, const D3DXCONSTANT
mSamplersVS[samplerIndex].active = true;
mSamplersVS[samplerIndex].textureType = (constantDescription.Type == D3DXPT_SAMPLERCUBE) ? TEXTURE_CUBE : TEXTURE_2D;
mSamplersVS[samplerIndex].logicalTextureUnit = 0;
mUsedVertexSamplerRange = std::max(samplerIndex + 1, mUsedVertexSamplerRange);
}
else
{
......@@ -2534,6 +2551,9 @@ void Program::unlink(bool destroy)
mSamplersVS[index].active = false;
}
mUsedVertexSamplerRange = 0;
mUsedPixelSamplerRange = 0;
while (!mUniforms.empty())
{
delete mUniforms.back();
......@@ -2861,7 +2881,7 @@ bool Program::validateSamplers(bool logErrors)
textureUnitType[i] = TEXTURE_UNKNOWN;
}
for (unsigned int i = 0; i < MAX_TEXTURE_IMAGE_UNITS; ++i)
for (unsigned int i = 0; i < mUsedPixelSamplerRange; ++i)
{
if (mSamplersPS[i].active)
{
......@@ -2896,7 +2916,7 @@ bool Program::validateSamplers(bool logErrors)
}
}
for (unsigned int i = 0; i < MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF; ++i)
for (unsigned int i = 0; i < mUsedVertexSamplerRange; ++i)
{
if (mSamplersVS[i].active)
{
......
......@@ -77,6 +77,7 @@ class Program
GLint getSamplerMapping(SamplerType type, unsigned int samplerIndex);
TextureType getSamplerTextureType(SamplerType type, unsigned int samplerIndex);
GLint getUsedSamplerRange(SamplerType type);
GLint getUniformLocation(std::string name);
bool setUniform1fv(GLint location, GLsizei count, const GLfloat *v);
......@@ -197,6 +198,8 @@ class Program
Sampler mSamplersPS[MAX_TEXTURE_IMAGE_UNITS];
Sampler mSamplersVS[MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF];
GLuint mUsedVertexSamplerRange;
GLuint mUsedPixelSamplerRange;
typedef std::vector<Uniform*> UniformArray;
UniformArray mUniforms;
......
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