Keep track of applied textures and dirty state to minimize D3D calls.

TRAC #15703 Issue=86 Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@588 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 51887316
...@@ -319,11 +319,16 @@ void Context::makeCurrent(egl::Display *display, egl::Surface *surface) ...@@ -319,11 +319,16 @@ void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
// This function will set all of the state-related dirty flags, so that all state is set during next pre-draw. // This function will set all of the state-related dirty flags, so that all state is set during next pre-draw.
void Context::markAllStateDirty() void Context::markAllStateDirty()
{ {
for (int t = 0; t < MAX_TEXTURE_IMAGE_UNITS; t++)
{
mAppliedTexture[t] = 0;
}
mAppliedProgram = 0;
mAppliedRenderTargetSerial = 0; mAppliedRenderTargetSerial = 0;
mAppliedDepthbufferSerial = 0; mAppliedDepthbufferSerial = 0;
mAppliedStencilbufferSerial = 0; mAppliedStencilbufferSerial = 0;
mDepthStencilInitialized = false; mDepthStencilInitialized = false;
mAppliedProgram = 0;
mClearStateDirty = true; mClearStateDirty = true;
mCullStateDirty = true; mCullStateDirty = true;
...@@ -2005,7 +2010,6 @@ void Context::applyShaders() ...@@ -2005,7 +2010,6 @@ void Context::applyShaders()
if (programObject->getSerial() != mAppliedProgram) if (programObject->getSerial() != mAppliedProgram)
{ {
programObject->dirtyAllUniforms(); programObject->dirtyAllUniforms();
programObject->dirtyAllSamplers();
mAppliedProgram = programObject->getSerial(); mAppliedProgram = programObject->getSerial();
} }
...@@ -2027,9 +2031,11 @@ void Context::applyTextures() ...@@ -2027,9 +2031,11 @@ void Context::applyTextures()
Texture *texture = getSamplerTexture(textureUnit, textureType); Texture *texture = getSamplerTexture(textureUnit, textureType);
if (programObject->isSamplerDirty(sampler) || texture->isDirty()) if (mAppliedTexture[sampler] != texture->id() || texture->isDirty())
{ {
if (texture->isComplete()) IDirect3DBaseTexture9 *d3dTexture = texture->getTexture();
if (d3dTexture)
{ {
GLenum wrapS = texture->getWrapS(); GLenum wrapS = texture->getWrapS();
GLenum wrapT = texture->getWrapT(); GLenum wrapT = texture->getWrapT();
...@@ -2045,22 +2051,23 @@ void Context::applyTextures() ...@@ -2045,22 +2051,23 @@ void Context::applyTextures()
device->SetSamplerState(sampler, D3DSAMP_MINFILTER, d3dMinFilter); device->SetSamplerState(sampler, D3DSAMP_MINFILTER, d3dMinFilter);
device->SetSamplerState(sampler, D3DSAMP_MIPFILTER, d3dMipFilter); device->SetSamplerState(sampler, D3DSAMP_MIPFILTER, d3dMipFilter);
device->SetTexture(sampler, texture->getTexture()); device->SetTexture(sampler, d3dTexture);
} }
else else
{ {
device->SetTexture(sampler, getIncompleteTexture(textureType)->getTexture()); device->SetTexture(sampler, getIncompleteTexture(textureType)->getTexture());
} }
}
programObject->setSamplerDirty(sampler, false); mAppliedTexture[sampler] = texture->id();
texture->resetDirty();
}
} }
else else
{ {
if (programObject->isSamplerDirty(sampler)) if (mAppliedTexture[sampler] != 0)
{ {
device->SetTexture(sampler, NULL); device->SetTexture(sampler, NULL);
programObject->setSamplerDirty(sampler, false); mAppliedTexture[sampler] = 0;
} }
} }
} }
......
...@@ -483,6 +483,7 @@ class Context ...@@ -483,6 +483,7 @@ class Context
bool mHasBeenCurrent; bool mHasBeenCurrent;
unsigned int mAppliedTexture[MAX_TEXTURE_IMAGE_UNITS];
unsigned int mAppliedProgram; unsigned int mAppliedProgram;
unsigned int mAppliedRenderTargetSerial; unsigned int mAppliedRenderTargetSerial;
unsigned int mAppliedDepthbufferSerial; unsigned int mAppliedDepthbufferSerial;
......
...@@ -219,26 +219,6 @@ SamplerType Program::getSamplerType(unsigned int samplerIndex) ...@@ -219,26 +219,6 @@ SamplerType Program::getSamplerType(unsigned int samplerIndex)
return mSamplers[samplerIndex].type; return mSamplers[samplerIndex].type;
} }
bool Program::isSamplerDirty(unsigned int samplerIndex) const
{
if (samplerIndex < sizeof(mSamplers)/sizeof(mSamplers[0]))
{
return mSamplers[samplerIndex].dirty;
}
else UNREACHABLE();
return false;
}
void Program::setSamplerDirty(unsigned int samplerIndex, bool dirty)
{
if (samplerIndex < sizeof(mSamplers)/sizeof(mSamplers[0]))
{
mSamplers[samplerIndex].dirty = dirty;
}
else UNREACHABLE();
}
GLint Program::getUniformLocation(const char *name, bool decorated) GLint Program::getUniformLocation(const char *name, bool decorated)
{ {
std::string _name = decorated ? name : decorate(name); std::string _name = decorated ? name : decorate(name);
...@@ -904,14 +884,6 @@ void Program::dirtyAllUniforms() ...@@ -904,14 +884,6 @@ void Program::dirtyAllUniforms()
} }
} }
void Program::dirtyAllSamplers()
{
for (unsigned int index = 0; index < MAX_TEXTURE_IMAGE_UNITS; ++index)
{
mSamplers[index].dirty = true;
}
}
// Applies all the uniforms set for this program object to the Direct3D 9 device // Applies all the uniforms set for this program object to the Direct3D 9 device
void Program::applyUniforms() void Program::applyUniforms()
{ {
...@@ -1695,7 +1667,6 @@ bool Program::defineUniform(const D3DXHANDLE &constantHandle, const D3DXCONSTANT ...@@ -1695,7 +1667,6 @@ bool Program::defineUniform(const D3DXHANDLE &constantHandle, const D3DXCONSTANT
mSamplers[samplerIndex].active = true; mSamplers[samplerIndex].active = true;
mSamplers[samplerIndex].type = (constantDescription.Type == D3DXPT_SAMPLERCUBE) ? SAMPLER_CUBE : SAMPLER_2D; mSamplers[samplerIndex].type = (constantDescription.Type == D3DXPT_SAMPLERCUBE) ? SAMPLER_CUBE : SAMPLER_2D;
mSamplers[samplerIndex].logicalTextureUnit = 0; mSamplers[samplerIndex].logicalTextureUnit = 0;
mSamplers[samplerIndex].dirty = true;
} }
} }
...@@ -2263,7 +2234,6 @@ bool Program::applyUniform1iv(GLint location, GLsizei count, const GLint *v) ...@@ -2263,7 +2234,6 @@ bool Program::applyUniform1iv(GLint location, GLsizei count, const GLint *v)
{ {
ASSERT(mSamplers[samplerIndex].active); ASSERT(mSamplers[samplerIndex].active);
mSamplers[samplerIndex].logicalTextureUnit = v[i]; mSamplers[samplerIndex].logicalTextureUnit = v[i];
mSamplers[samplerIndex].dirty = true;
} }
} }
...@@ -2476,7 +2446,6 @@ void Program::unlink(bool destroy) ...@@ -2476,7 +2446,6 @@ void Program::unlink(bool destroy)
for (int index = 0; index < MAX_TEXTURE_IMAGE_UNITS; index++) for (int index = 0; index < MAX_TEXTURE_IMAGE_UNITS; index++)
{ {
mSamplers[index].active = false; mSamplers[index].active = false;
mSamplers[index].dirty = true;
} }
while (!mUniforms.empty()) while (!mUniforms.empty())
......
...@@ -71,12 +71,8 @@ class Program ...@@ -71,12 +71,8 @@ class Program
GLuint getAttributeLocation(const char *name); GLuint getAttributeLocation(const char *name);
int getSemanticIndex(int attributeIndex); int getSemanticIndex(int attributeIndex);
void dirtyAllSamplers();
GLint getSamplerMapping(unsigned int samplerIndex); GLint getSamplerMapping(unsigned int samplerIndex);
SamplerType getSamplerType(unsigned int samplerIndex); SamplerType getSamplerType(unsigned int samplerIndex);
bool isSamplerDirty(unsigned int samplerIndex) const;
void setSamplerDirty(unsigned int samplerIndex, bool dirty);
GLint getUniformLocation(const char *name, bool decorated); GLint getUniformLocation(const char *name, bool decorated);
bool setUniform1fv(GLint location, GLsizei count, const GLfloat *v); bool setUniform1fv(GLint location, GLsizei count, const GLfloat *v);
...@@ -192,7 +188,6 @@ class Program ...@@ -192,7 +188,6 @@ class Program
bool active; bool active;
GLint logicalTextureUnit; GLint logicalTextureUnit;
SamplerType type; SamplerType type;
bool dirty;
}; };
Sampler mSamplers[MAX_TEXTURE_IMAGE_UNITS]; Sampler mSamplers[MAX_TEXTURE_IMAGE_UNITS];
......
...@@ -44,7 +44,7 @@ Texture::Texture(GLuint id) : RefCountObject(id) ...@@ -44,7 +44,7 @@ Texture::Texture(GLuint id) : RefCountObject(id)
mMagFilter = GL_LINEAR; mMagFilter = GL_LINEAR;
mWrapS = GL_REPEAT; mWrapS = GL_REPEAT;
mWrapT = GL_REPEAT; mWrapT = GL_REPEAT;
mDirtyParameters = true; mDirty = true;
mIsRenderable = false; mIsRenderable = false;
} }
...@@ -74,7 +74,7 @@ bool Texture::setMinFilter(GLenum filter) ...@@ -74,7 +74,7 @@ bool Texture::setMinFilter(GLenum filter)
if (mMinFilter != filter) if (mMinFilter != filter)
{ {
mMinFilter = filter; mMinFilter = filter;
mDirtyParameters = true; mDirty = true;
} }
return true; return true;
} }
...@@ -94,7 +94,7 @@ bool Texture::setMagFilter(GLenum filter) ...@@ -94,7 +94,7 @@ bool Texture::setMagFilter(GLenum filter)
if (mMagFilter != filter) if (mMagFilter != filter)
{ {
mMagFilter = filter; mMagFilter = filter;
mDirtyParameters = true; mDirty = true;
} }
return true; return true;
} }
...@@ -115,7 +115,7 @@ bool Texture::setWrapS(GLenum wrap) ...@@ -115,7 +115,7 @@ bool Texture::setWrapS(GLenum wrap)
if (mWrapS != wrap) if (mWrapS != wrap)
{ {
mWrapS = wrap; mWrapS = wrap;
mDirtyParameters = true; mDirty = true;
} }
return true; return true;
} }
...@@ -136,7 +136,7 @@ bool Texture::setWrapT(GLenum wrap) ...@@ -136,7 +136,7 @@ bool Texture::setWrapT(GLenum wrap)
if (mWrapT != wrap) if (mWrapT != wrap)
{ {
mWrapT = wrap; mWrapT = wrap;
mDirtyParameters = true; mDirty = true;
} }
return true; return true;
} }
...@@ -846,6 +846,7 @@ void Texture::setImage(GLint unpackAlignment, const void *pixels, Image *image) ...@@ -846,6 +846,7 @@ void Texture::setImage(GLint unpackAlignment, const void *pixels, Image *image)
} }
image->dirty = true; image->dirty = true;
mDirty = true;
} }
} }
...@@ -869,6 +870,7 @@ void Texture::setCompressedImage(GLsizei imageSize, const void *pixels, Image *i ...@@ -869,6 +870,7 @@ void Texture::setCompressedImage(GLsizei imageSize, const void *pixels, Image *i
} }
image->dirty = true; image->dirty = true;
mDirty = true;
} }
} }
...@@ -902,6 +904,7 @@ bool Texture::subImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei heig ...@@ -902,6 +904,7 @@ bool Texture::subImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei heig
} }
image->dirty = true; image->dirty = true;
mDirty = true;
} }
return true; return true;
...@@ -948,6 +951,7 @@ bool Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GL ...@@ -948,6 +951,7 @@ bool Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GL
} }
image->dirty = true; image->dirty = true;
mDirty = true;
} }
return true; return true;
...@@ -1115,6 +1119,7 @@ void Texture::copyNonRenderable(Image *image, GLenum format, GLint xoffset, GLin ...@@ -1115,6 +1119,7 @@ void Texture::copyNonRenderable(Image *image, GLenum format, GLint xoffset, GLin
} }
image->dirty = true; image->dirty = true;
mDirty = true;
} }
image->surface->UnlockRect(); image->surface->UnlockRect();
...@@ -1146,7 +1151,12 @@ IDirect3DBaseTexture9 *Texture::getTexture() ...@@ -1146,7 +1151,12 @@ IDirect3DBaseTexture9 *Texture::getTexture()
bool Texture::isDirty() const bool Texture::isDirty() const
{ {
return true;//(mDirty || mDirtyMetaData || dirtyImageData()); return mDirty;
}
void Texture::resetDirty()
{
mDirty = false;
} }
GLint Texture::creationLevels(GLsizei width, GLsizei height, GLint maxlevel) const GLint Texture::creationLevels(GLsizei width, GLsizei height, GLint maxlevel) const
...@@ -1250,6 +1260,7 @@ void Texture2D::redefineTexture(GLint level, GLenum format, GLsizei width, GLsiz ...@@ -1250,6 +1260,7 @@ void Texture2D::redefineTexture(GLint level, GLenum format, GLsizei width, GLsiz
{ {
mTexture->Release(); mTexture->Release();
mTexture = NULL; mTexture = NULL;
mDirty = true;
mIsRenderable = false; mIsRenderable = false;
} }
} }
...@@ -1519,6 +1530,7 @@ void Texture2D::createTexture() ...@@ -1519,6 +1530,7 @@ void Texture2D::createTexture()
} }
mTexture = texture; mTexture = texture;
mDirty = true;
mIsRenderable = false; mIsRenderable = false;
} }
...@@ -1625,6 +1637,7 @@ void Texture2D::convertToRenderTarget() ...@@ -1625,6 +1637,7 @@ void Texture2D::convertToRenderTarget()
} }
mTexture = texture; mTexture = texture;
mDirty = true;
mIsRenderable = true; mIsRenderable = true;
} }
...@@ -1975,6 +1988,7 @@ void TextureCubeMap::createTexture() ...@@ -1975,6 +1988,7 @@ void TextureCubeMap::createTexture()
} }
mTexture = texture; mTexture = texture;
mDirty = true;
mIsRenderable = false; mIsRenderable = false;
} }
...@@ -2083,6 +2097,7 @@ void TextureCubeMap::convertToRenderTarget() ...@@ -2083,6 +2097,7 @@ void TextureCubeMap::convertToRenderTarget()
} }
mTexture = texture; mTexture = texture;
mDirty = true;
mIsRenderable = true; mIsRenderable = true;
} }
...@@ -2143,6 +2158,7 @@ void TextureCubeMap::redefineTexture(int face, GLint level, GLenum format, GLsiz ...@@ -2143,6 +2158,7 @@ void TextureCubeMap::redefineTexture(int face, GLint level, GLenum format, GLsiz
{ {
mTexture->Release(); mTexture->Release();
mTexture = NULL; mTexture = NULL;
mDirty = true;
mIsRenderable = false; mIsRenderable = false;
} }
} }
......
...@@ -74,6 +74,7 @@ class Texture : public RefCountObject ...@@ -74,6 +74,7 @@ class Texture : public RefCountObject
virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source) = 0; virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source) = 0;
bool isDirty() const; bool isDirty() const;
void resetDirty();
static const GLuint INCOMPLETE_TEXTURE_ID = static_cast<GLuint>(-1); // Every texture takes an id at creation time. The value is arbitrary because it is never registered with the resource manager. static const GLuint INCOMPLETE_TEXTURE_ID = static_cast<GLuint>(-1); // Every texture takes an id at creation time. The value is arbitrary because it is never registered with the resource manager.
...@@ -123,7 +124,7 @@ class Texture : public RefCountObject ...@@ -123,7 +124,7 @@ class Texture : public RefCountObject
GLenum mMagFilter; GLenum mMagFilter;
GLenum mWrapS; GLenum mWrapS;
GLenum mWrapT; GLenum mWrapT;
bool mDirtyParameters; bool mDirty;
bool mIsRenderable; bool mIsRenderable;
......
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