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)
// This function will set all of the state-related dirty flags, so that all state is set during next pre-draw.
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;
}
......@@ -1795,7 +1785,6 @@ void Context::applyTextures(SamplerType type)
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
unsigned int *appliedTextureSerial = (type == SAMPLER_PIXEL) ? mAppliedTextureSerialPS : mAppliedTextureSerialVS;
int samplerRange = programBinary->getUsedSamplerRange(type);
for (int samplerIndex = 0; samplerIndex < samplerRange; samplerIndex++)
......@@ -1805,53 +1794,32 @@ void Context::applyTextures(SamplerType type)
if (textureUnit != -1)
{
TextureType textureType = programBinary->getSamplerTextureType(type, samplerIndex);
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;
texture->getSamplerState(&samplerState);
mRenderer->setSamplerState(type, samplerIndex, samplerState);
}
SamplerState samplerState;
texture->getSamplerState(&samplerState);
mRenderer->setSamplerState(type, samplerIndex, samplerState);
if (appliedTextureSerial[samplerIndex] != texSerial || texture->hasDirtyImages())
{
mRenderer->setTexture(type, samplerIndex, texture);
}
}
else
{
mRenderer->setTexture(type, samplerIndex, getIncompleteTexture(textureType));
}
mRenderer->setTexture(type, samplerIndex, texture);
appliedTextureSerial[samplerIndex] = texSerial;
texture->resetDirty();
}
else
{
mRenderer->setTexture(type, samplerIndex, getIncompleteTexture(textureType));
}
}
else
{
if (appliedTextureSerial[samplerIndex] != 0)
{
mRenderer->setTexture(type, samplerIndex, NULL);
appliedTextureSerial[samplerIndex] = 0;
}
mRenderer->setTexture(type, samplerIndex, NULL);
}
}
for (int samplerIndex = samplerRange; samplerIndex < samplerCount; samplerIndex++)
{
if (appliedTextureSerial[samplerIndex] != 0)
{
mRenderer->setTexture(type, samplerIndex, NULL);
appliedTextureSerial[samplerIndex] = 0;
}
mRenderer->setTexture(type, samplerIndex, NULL);
}
}
......
......@@ -485,8 +485,6 @@ class Context
GLenum mResetStrategy;
bool mRobustAccess;
unsigned int mAppliedTextureSerialPS[MAX_TEXTURE_IMAGE_UNITS];
unsigned int mAppliedTextureSerialVS[MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF];
bool mDxUniformsDirty;
BindingPointer<ProgramBinary> mCurrentProgramBinary;
Framebuffer *mBoundDrawFramebuffer;
......
......@@ -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)
{
ID3D11ShaderResourceView *textureSRV = NULL;
unsigned int serial = 0;
bool forceSetTexture = false;
if (texture)
{
......@@ -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
// missing the shader resource view
ASSERT(textureSRV != NULL);
serial = texture->getTextureSerial();
forceSetTexture = texture->hasDirtyImages();
}
if (type == gl::SAMPLER_PIXEL)
......@@ -348,7 +353,12 @@ void Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *textur
return;
}
mDeviceContext->PSSetShaderResources(index, 1, &textureSRV);
if (forceSetTexture || mCurPixelTextureSerials[index] != serial)
{
mDeviceContext->PSSetShaderResources(index, 1, &textureSRV);
}
mCurPixelTextureSerials[index] = serial;
}
else if (type == gl::SAMPLER_VERTEX)
{
......@@ -358,7 +368,12 @@ void Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *textur
return;
}
mDeviceContext->VSSetShaderResources(index, 1, &textureSRV);
if (forceSetTexture || mCurVertexTextureSerials[index] != serial)
{
mDeviceContext->VSSetShaderResources(index, 1, &textureSRV);
}
mCurVertexTextureSerials[index] = serial;
}
else UNREACHABLE();
}
......@@ -1160,10 +1175,12 @@ void Renderer11::markAllStateDirty()
for (int i = 0; i < gl::MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF; i++)
{
mForceSetVertexSamplerStates[i] = true;
mCurVertexTextureSerials[i] = 0;
}
for (int i = 0; i < gl::MAX_TEXTURE_IMAGE_UNITS; i++)
{
mForceSetPixelSamplerStates[i] = true;
mCurPixelTextureSerials[i] = 0;
}
mForceSetBlendState = true;
......
......@@ -191,6 +191,10 @@ class Renderer11 : public Renderer
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];
// Currently applied blend state
bool mForceSetBlendState;
gl::BlendState mCurBlendState;
......
......@@ -706,22 +706,31 @@ IndexBuffer *Renderer9::createIndexBuffer()
void Renderer9::setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &samplerState)
{
int d3dSamplerOffset = (type == gl::SAMPLER_PIXEL) ? 0 : D3DVERTEXTEXTURESAMPLER0;
int d3dSampler = index + d3dSamplerOffset;
mDevice->SetSamplerState(d3dSampler, D3DSAMP_ADDRESSU, gl_d3d9::ConvertTextureWrap(samplerState.wrapS));
mDevice->SetSamplerState(d3dSampler, D3DSAMP_ADDRESSV, gl_d3d9::ConvertTextureWrap(samplerState.wrapT));
bool *forceSetSamplers = (type == gl::SAMPLER_PIXEL) ? mForceSetPixelSamplerStates : mForceSetVertexSamplerStates;
gl::SamplerState *appliedSamplers = (type == gl::SAMPLER_PIXEL) ? mCurPixelSamplerStates: mCurVertexSamplerStates;
mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAGFILTER, gl_d3d9::ConvertMagFilter(samplerState.magFilter, samplerState.maxAnisotropy));
D3DTEXTUREFILTERTYPE d3dMinFilter, d3dMipFilter;
gl_d3d9::ConvertMinFilter(samplerState.minFilter, &d3dMinFilter, &d3dMipFilter, samplerState.maxAnisotropy);
mDevice->SetSamplerState(d3dSampler, D3DSAMP_MINFILTER, d3dMinFilter);
mDevice->SetSamplerState(d3dSampler, D3DSAMP_MIPFILTER, d3dMipFilter);
mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAXMIPLEVEL, samplerState.lodOffset);
if (mSupportsTextureFilterAnisotropy)
if (forceSetSamplers[index] || memcmp(&samplerState, &appliedSamplers[index], sizeof(gl::SamplerState)) != 0)
{
mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAXANISOTROPY, (DWORD)samplerState.maxAnisotropy);
int d3dSamplerOffset = (type == gl::SAMPLER_PIXEL) ? 0 : D3DVERTEXTEXTURESAMPLER0;
int d3dSampler = index + d3dSamplerOffset;
mDevice->SetSamplerState(d3dSampler, D3DSAMP_ADDRESSU, gl_d3d9::ConvertTextureWrap(samplerState.wrapS));
mDevice->SetSamplerState(d3dSampler, D3DSAMP_ADDRESSV, gl_d3d9::ConvertTextureWrap(samplerState.wrapT));
mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAGFILTER, gl_d3d9::ConvertMagFilter(samplerState.magFilter, samplerState.maxAnisotropy));
D3DTEXTUREFILTERTYPE d3dMinFilter, d3dMipFilter;
gl_d3d9::ConvertMinFilter(samplerState.minFilter, &d3dMinFilter, &d3dMipFilter, samplerState.maxAnisotropy);
mDevice->SetSamplerState(d3dSampler, D3DSAMP_MINFILTER, d3dMinFilter);
mDevice->SetSamplerState(d3dSampler, D3DSAMP_MIPFILTER, d3dMipFilter);
mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAXMIPLEVEL, samplerState.lodOffset);
if (mSupportsTextureFilterAnisotropy)
{
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)
......@@ -729,6 +738,10 @@ void Renderer9::setTexture(gl::SamplerType type, int index, gl::Texture *texture
int d3dSamplerOffset = (type == gl::SAMPLER_PIXEL) ? 0 : D3DVERTEXTEXTURESAMPLER0;
int d3dSampler = index + d3dSamplerOffset;
IDirect3DBaseTexture9 *d3dTexture = NULL;
unsigned int serial = 0;
bool forceSetTexture = false;
unsigned int *appliedSerials = (type == gl::SAMPLER_PIXEL) ? mCurPixelTextureSerials : mCurVertexTextureSerials;
if (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
// in the texture class and we're unexpectedly missing the d3d texture
ASSERT(d3dTexture != NULL);
serial = texture->getTextureSerial();
forceSetTexture = texture->hasDirtyImages();
}
mDevice->SetTexture(d3dSampler, d3dTexture);
if (forceSetTexture || appliedSerials[index] != serial)
{
mDevice->SetTexture(d3dSampler, d3dTexture);
}
appliedSerials[index] = serial;
}
void Renderer9::setRasterizerState(const gl::RasterizerState &rasterState)
......@@ -1902,6 +1923,17 @@ void Renderer9::markAllStateDirty()
mForceSetViewport = 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;
mAppliedProgramBinarySerial = 0;
......
......@@ -294,6 +294,17 @@ class Renderer9 : public Renderer
gl::Color mCurBlendColor;
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 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