Moved applied texture and sampler caching from Context into the Renderers.

TRAC #22248 Signed-off-by: Nicolas Capens Signed-off-by: Daniel Koch Author: Geoff Lang git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1698 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 1e1b5e91
...@@ -307,16 +307,6 @@ void Context::makeCurrent(egl::Surface *surface) ...@@ -307,16 +307,6 @@ void Context::makeCurrent(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++)
{
mAppliedTextureSerialPS[t] = 0;
}
for (int t = 0; t < MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF; t++)
{
mAppliedTextureSerialVS[t] = 0;
}
mDxUniformsDirty = true; mDxUniformsDirty = true;
} }
...@@ -1795,7 +1785,6 @@ void Context::applyTextures(SamplerType type) ...@@ -1795,7 +1785,6 @@ void Context::applyTextures(SamplerType type)
ProgramBinary *programBinary = getCurrentProgramBinary(); ProgramBinary *programBinary = getCurrentProgramBinary();
int samplerCount = (type == SAMPLER_PIXEL) ? MAX_TEXTURE_IMAGE_UNITS : MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF; // Range of Direct3D 9 samplers of given sampler 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 samplerRange = programBinary->getUsedSamplerRange(type); int samplerRange = programBinary->getUsedSamplerRange(type);
for (int samplerIndex = 0; samplerIndex < samplerRange; samplerIndex++) for (int samplerIndex = 0; samplerIndex < samplerRange; samplerIndex++)
...@@ -1805,53 +1794,32 @@ void Context::applyTextures(SamplerType type) ...@@ -1805,53 +1794,32 @@ void Context::applyTextures(SamplerType type)
if (textureUnit != -1) if (textureUnit != -1)
{ {
TextureType textureType = programBinary->getSamplerTextureType(type, samplerIndex); TextureType textureType = programBinary->getSamplerTextureType(type, samplerIndex);
Texture *texture = getSamplerTexture(textureUnit, textureType); Texture *texture = getSamplerTexture(textureUnit, textureType);
unsigned int texSerial = texture->getTextureSerial();
if (appliedTextureSerial[samplerIndex] != texSerial || texture->hasDirtyParameters() || texture->hasDirtyImages())
{
if (texture->isSamplerComplete()) if (texture->isSamplerComplete())
{ {
if (appliedTextureSerial[samplerIndex] != texSerial || texture->hasDirtyParameters())
{
SamplerState samplerState; SamplerState samplerState;
texture->getSamplerState(&samplerState); texture->getSamplerState(&samplerState);
mRenderer->setSamplerState(type, samplerIndex, samplerState); mRenderer->setSamplerState(type, samplerIndex, samplerState);
}
if (appliedTextureSerial[samplerIndex] != texSerial || texture->hasDirtyImages())
{
mRenderer->setTexture(type, samplerIndex, texture); mRenderer->setTexture(type, samplerIndex, texture);
}
texture->resetDirty();
} }
else else
{ {
mRenderer->setTexture(type, samplerIndex, getIncompleteTexture(textureType)); mRenderer->setTexture(type, samplerIndex, getIncompleteTexture(textureType));
} }
appliedTextureSerial[samplerIndex] = texSerial;
texture->resetDirty();
}
} }
else else
{ {
if (appliedTextureSerial[samplerIndex] != 0)
{
mRenderer->setTexture(type, samplerIndex, NULL); mRenderer->setTexture(type, samplerIndex, NULL);
appliedTextureSerial[samplerIndex] = 0;
}
} }
} }
for (int samplerIndex = samplerRange; samplerIndex < samplerCount; samplerIndex++) for (int samplerIndex = samplerRange; samplerIndex < samplerCount; samplerIndex++)
{ {
if (appliedTextureSerial[samplerIndex] != 0)
{
mRenderer->setTexture(type, samplerIndex, NULL); mRenderer->setTexture(type, samplerIndex, NULL);
appliedTextureSerial[samplerIndex] = 0;
}
} }
} }
......
...@@ -485,8 +485,6 @@ class Context ...@@ -485,8 +485,6 @@ class Context
GLenum mResetStrategy; GLenum mResetStrategy;
bool mRobustAccess; bool mRobustAccess;
unsigned int mAppliedTextureSerialPS[MAX_TEXTURE_IMAGE_UNITS];
unsigned int mAppliedTextureSerialVS[MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF];
bool mDxUniformsDirty; bool mDxUniformsDirty;
BindingPointer<ProgramBinary> mCurrentProgramBinary; BindingPointer<ProgramBinary> mCurrentProgramBinary;
Framebuffer *mBoundDrawFramebuffer; Framebuffer *mBoundDrawFramebuffer;
......
...@@ -325,6 +325,8 @@ void Renderer11::setSamplerState(gl::SamplerType type, int index, const gl::Samp ...@@ -325,6 +325,8 @@ void Renderer11::setSamplerState(gl::SamplerType type, int index, const gl::Samp
void Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *texture) void Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *texture)
{ {
ID3D11ShaderResourceView *textureSRV = NULL; ID3D11ShaderResourceView *textureSRV = NULL;
unsigned int serial = 0;
bool forceSetTexture = false;
if (texture) if (texture)
{ {
...@@ -338,6 +340,9 @@ void Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *textur ...@@ -338,6 +340,9 @@ void Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *textur
// If we get NULL back from getSRV here, something went wrong in the texture class and we're unexpectedly // If we get NULL back from getSRV here, something went wrong in the texture class and we're unexpectedly
// missing the shader resource view // missing the shader resource view
ASSERT(textureSRV != NULL); ASSERT(textureSRV != NULL);
serial = texture->getTextureSerial();
forceSetTexture = texture->hasDirtyImages();
} }
if (type == gl::SAMPLER_PIXEL) if (type == gl::SAMPLER_PIXEL)
...@@ -348,8 +353,13 @@ void Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *textur ...@@ -348,8 +353,13 @@ void Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *textur
return; return;
} }
if (forceSetTexture || mCurPixelTextureSerials[index] != serial)
{
mDeviceContext->PSSetShaderResources(index, 1, &textureSRV); mDeviceContext->PSSetShaderResources(index, 1, &textureSRV);
} }
mCurPixelTextureSerials[index] = serial;
}
else if (type == gl::SAMPLER_VERTEX) else if (type == gl::SAMPLER_VERTEX)
{ {
if (index < 0 || index >= gl::MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF) if (index < 0 || index >= gl::MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF)
...@@ -358,8 +368,13 @@ void Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *textur ...@@ -358,8 +368,13 @@ void Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *textur
return; return;
} }
if (forceSetTexture || mCurVertexTextureSerials[index] != serial)
{
mDeviceContext->VSSetShaderResources(index, 1, &textureSRV); mDeviceContext->VSSetShaderResources(index, 1, &textureSRV);
} }
mCurVertexTextureSerials[index] = serial;
}
else UNREACHABLE(); else UNREACHABLE();
} }
...@@ -1160,10 +1175,12 @@ void Renderer11::markAllStateDirty() ...@@ -1160,10 +1175,12 @@ void Renderer11::markAllStateDirty()
for (int i = 0; i < gl::MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF; i++) for (int i = 0; i < gl::MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF; i++)
{ {
mForceSetVertexSamplerStates[i] = true; mForceSetVertexSamplerStates[i] = true;
mCurVertexTextureSerials[i] = 0;
} }
for (int i = 0; i < gl::MAX_TEXTURE_IMAGE_UNITS; i++) for (int i = 0; i < gl::MAX_TEXTURE_IMAGE_UNITS; i++)
{ {
mForceSetPixelSamplerStates[i] = true; mForceSetPixelSamplerStates[i] = true;
mCurPixelTextureSerials[i] = 0;
} }
mForceSetBlendState = true; mForceSetBlendState = true;
......
...@@ -191,6 +191,10 @@ class Renderer11 : public Renderer ...@@ -191,6 +191,10 @@ class Renderer11 : public Renderer
bool mForceSetPixelSamplerStates[gl::MAX_TEXTURE_IMAGE_UNITS]; bool mForceSetPixelSamplerStates[gl::MAX_TEXTURE_IMAGE_UNITS];
gl::SamplerState mCurPixelSamplerStates[gl::MAX_TEXTURE_IMAGE_UNITS]; gl::SamplerState mCurPixelSamplerStates[gl::MAX_TEXTURE_IMAGE_UNITS];
// Currently applied textures
unsigned int mCurVertexTextureSerials[gl::MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF];
unsigned int mCurPixelTextureSerials[gl::MAX_TEXTURE_IMAGE_UNITS];
// Currently applied blend state // Currently applied blend state
bool mForceSetBlendState; bool mForceSetBlendState;
gl::BlendState mCurBlendState; gl::BlendState mCurBlendState;
......
...@@ -706,6 +706,11 @@ IndexBuffer *Renderer9::createIndexBuffer() ...@@ -706,6 +706,11 @@ IndexBuffer *Renderer9::createIndexBuffer()
void Renderer9::setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &samplerState) void Renderer9::setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &samplerState)
{ {
bool *forceSetSamplers = (type == gl::SAMPLER_PIXEL) ? mForceSetPixelSamplerStates : mForceSetVertexSamplerStates;
gl::SamplerState *appliedSamplers = (type == gl::SAMPLER_PIXEL) ? mCurPixelSamplerStates: mCurVertexSamplerStates;
if (forceSetSamplers[index] || memcmp(&samplerState, &appliedSamplers[index], sizeof(gl::SamplerState)) != 0)
{
int d3dSamplerOffset = (type == gl::SAMPLER_PIXEL) ? 0 : D3DVERTEXTEXTURESAMPLER0; int d3dSamplerOffset = (type == gl::SAMPLER_PIXEL) ? 0 : D3DVERTEXTEXTURESAMPLER0;
int d3dSampler = index + d3dSamplerOffset; int d3dSampler = index + d3dSamplerOffset;
...@@ -722,6 +727,10 @@ void Renderer9::setSamplerState(gl::SamplerType type, int index, const gl::Sampl ...@@ -722,6 +727,10 @@ void Renderer9::setSamplerState(gl::SamplerType type, int index, const gl::Sampl
{ {
mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAXANISOTROPY, (DWORD)samplerState.maxAnisotropy); mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAXANISOTROPY, (DWORD)samplerState.maxAnisotropy);
} }
}
forceSetSamplers[index] = false;
appliedSamplers[index] = samplerState;
} }
void Renderer9::setTexture(gl::SamplerType type, int index, gl::Texture *texture) void Renderer9::setTexture(gl::SamplerType type, int index, gl::Texture *texture)
...@@ -729,6 +738,10 @@ void Renderer9::setTexture(gl::SamplerType type, int index, gl::Texture *texture ...@@ -729,6 +738,10 @@ void Renderer9::setTexture(gl::SamplerType type, int index, gl::Texture *texture
int d3dSamplerOffset = (type == gl::SAMPLER_PIXEL) ? 0 : D3DVERTEXTEXTURESAMPLER0; int d3dSamplerOffset = (type == gl::SAMPLER_PIXEL) ? 0 : D3DVERTEXTEXTURESAMPLER0;
int d3dSampler = index + d3dSamplerOffset; int d3dSampler = index + d3dSamplerOffset;
IDirect3DBaseTexture9 *d3dTexture = NULL; IDirect3DBaseTexture9 *d3dTexture = NULL;
unsigned int serial = 0;
bool forceSetTexture = false;
unsigned int *appliedSerials = (type == gl::SAMPLER_PIXEL) ? mCurPixelTextureSerials : mCurVertexTextureSerials;
if (texture) if (texture)
{ {
...@@ -741,9 +754,17 @@ void Renderer9::setTexture(gl::SamplerType type, int index, gl::Texture *texture ...@@ -741,9 +754,17 @@ void Renderer9::setTexture(gl::SamplerType type, int index, gl::Texture *texture
// If we get NULL back from getBaseTexture here, something went wrong // If we get NULL back from getBaseTexture here, something went wrong
// in the texture class and we're unexpectedly missing the d3d texture // in the texture class and we're unexpectedly missing the d3d texture
ASSERT(d3dTexture != NULL); ASSERT(d3dTexture != NULL);
serial = texture->getTextureSerial();
forceSetTexture = texture->hasDirtyImages();
} }
if (forceSetTexture || appliedSerials[index] != serial)
{
mDevice->SetTexture(d3dSampler, d3dTexture); mDevice->SetTexture(d3dSampler, d3dTexture);
}
appliedSerials[index] = serial;
} }
void Renderer9::setRasterizerState(const gl::RasterizerState &rasterState) void Renderer9::setRasterizerState(const gl::RasterizerState &rasterState)
...@@ -1902,6 +1923,17 @@ void Renderer9::markAllStateDirty() ...@@ -1902,6 +1923,17 @@ void Renderer9::markAllStateDirty()
mForceSetViewport = true; mForceSetViewport = true;
mForceSetBlendState = true; mForceSetBlendState = true;
for (unsigned int i = 0; i < gl::MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF; i++)
{
mForceSetVertexSamplerStates[i] = true;
mCurVertexTextureSerials[i] = 0;
}
for (unsigned int i = 0; i < gl::MAX_TEXTURE_IMAGE_UNITS; i++)
{
mForceSetPixelSamplerStates[i] = true;
mCurPixelTextureSerials[i] = 0;
}
mAppliedIBSerial = 0; mAppliedIBSerial = 0;
mAppliedProgramBinarySerial = 0; mAppliedProgramBinarySerial = 0;
......
...@@ -294,6 +294,17 @@ class Renderer9 : public Renderer ...@@ -294,6 +294,17 @@ class Renderer9 : public Renderer
gl::Color mCurBlendColor; gl::Color mCurBlendColor;
GLuint mCurSampleMask; GLuint mCurSampleMask;
// Currently applied sampler states
bool mForceSetVertexSamplerStates[gl::MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF];
gl::SamplerState mCurVertexSamplerStates[gl::MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF];
bool mForceSetPixelSamplerStates[gl::MAX_TEXTURE_IMAGE_UNITS];
gl::SamplerState mCurPixelSamplerStates[gl::MAX_TEXTURE_IMAGE_UNITS];
// Currently applied textures
unsigned int mCurVertexTextureSerials[gl::MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF];
unsigned int mCurPixelTextureSerials[gl::MAX_TEXTURE_IMAGE_UNITS];
unsigned int mAppliedIBSerial; unsigned int mAppliedIBSerial;
unsigned int mAppliedProgramBinarySerial; unsigned int mAppliedProgramBinarySerial;
......
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