Commit ea19b4ac by Jamie Madill Committed by Commit Bot

Don't store Renderer in RenderStateCache.

Instead pass it around via methods. This makes the code a bit nicer. BUG=angleproject:2044 Change-Id: I721e190a2ecde2b1a65e57debf419ee06a5dce29 Reviewed-on: https://chromium-review.googlesource.com/516385 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 9216a6e2
...@@ -605,7 +605,7 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, ...@@ -605,7 +605,7 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
memcpy(mBlendStateKey.rtvMasks, &rtvMasks[0], sizeof(mBlendStateKey.rtvMasks)); memcpy(mBlendStateKey.rtvMasks, &rtvMasks[0], sizeof(mBlendStateKey.rtvMasks));
// Get BlendState // Get BlendState
ANGLE_TRY(mRenderer->getStateCache().getBlendState(mBlendStateKey, &blendState)); ANGLE_TRY(mRenderer->getBlendState(mBlendStateKey, &blendState));
} }
const UINT stencilValue = clearParams.stencilValue & 0xFF; const UINT stencilValue = clearParams.stencilValue & 0xFF;
...@@ -621,7 +621,7 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, ...@@ -621,7 +621,7 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
mDepthStencilStateKey.stencilTest = clearParams.clearStencil; mDepthStencilStateKey.stencilTest = clearParams.clearStencil;
// Get DepthStencilState // Get DepthStencilState
ANGLE_TRY(mRenderer->getStateCache().getDepthStencilState(mDepthStencilStateKey, &dsState)); ANGLE_TRY(mRenderer->getDepthStencilState(mDepthStencilStateKey, &dsState));
zValue = clearParams.clearDepth ? &clearParams.depthValue : nullptr; zValue = clearParams.clearDepth ? &clearParams.depthValue : nullptr;
} }
......
...@@ -54,9 +54,8 @@ template std::size_t ComputeGenericHash(const rx::d3d11::RasterizerStateKey &); ...@@ -54,9 +54,8 @@ template std::size_t ComputeGenericHash(const rx::d3d11::RasterizerStateKey &);
template std::size_t ComputeGenericHash(const gl::DepthStencilState &); template std::size_t ComputeGenericHash(const gl::DepthStencilState &);
template std::size_t ComputeGenericHash(const gl::SamplerState &); template std::size_t ComputeGenericHash(const gl::SamplerState &);
RenderStateCache::RenderStateCache(Renderer11 *renderer) RenderStateCache::RenderStateCache()
: mRenderer(renderer), : mBlendStateCache(kMaxStates),
mBlendStateCache(kMaxStates),
mRasterizerStateCache(kMaxStates), mRasterizerStateCache(kMaxStates),
mDepthStencilStateCache(kMaxStates), mDepthStencilStateCache(kMaxStates),
mSamplerStateCache(kMaxStates) mSamplerStateCache(kMaxStates)
...@@ -117,7 +116,8 @@ d3d11::BlendStateKey RenderStateCache::GetBlendStateKey(const gl::Framebuffer *f ...@@ -117,7 +116,8 @@ d3d11::BlendStateKey RenderStateCache::GetBlendStateKey(const gl::Framebuffer *f
return key; return key;
} }
gl::Error RenderStateCache::getBlendState(const d3d11::BlendStateKey &key, gl::Error RenderStateCache::getBlendState(Renderer11 *renderer,
const d3d11::BlendStateKey &key,
ID3D11BlendState **outBlendState) ID3D11BlendState **outBlendState)
{ {
auto keyIter = mBlendStateCache.Get(key); auto keyIter = mBlendStateCache.Get(key);
...@@ -159,14 +159,16 @@ gl::Error RenderStateCache::getBlendState(const d3d11::BlendStateKey &key, ...@@ -159,14 +159,16 @@ gl::Error RenderStateCache::getBlendState(const d3d11::BlendStateKey &key,
} }
d3d11::BlendState d3dBlendState; d3d11::BlendState d3dBlendState;
ANGLE_TRY(mRenderer->allocateResource(blendDesc, &d3dBlendState)); ANGLE_TRY(renderer->allocateResource(blendDesc, &d3dBlendState));
*outBlendState = d3dBlendState.get(); *outBlendState = d3dBlendState.get();
mBlendStateCache.Put(key, std::move(d3dBlendState)); mBlendStateCache.Put(key, std::move(d3dBlendState));
return gl::NoError(); return gl::NoError();
} }
gl::Error RenderStateCache::getRasterizerState(const gl::RasterizerState &rasterState, bool scissorEnabled, gl::Error RenderStateCache::getRasterizerState(Renderer11 *renderer,
const gl::RasterizerState &rasterState,
bool scissorEnabled,
ID3D11RasterizerState **outRasterizerState) ID3D11RasterizerState **outRasterizerState)
{ {
d3d11::RasterizerStateKey key; d3d11::RasterizerStateKey key;
...@@ -214,14 +216,15 @@ gl::Error RenderStateCache::getRasterizerState(const gl::RasterizerState &raster ...@@ -214,14 +216,15 @@ gl::Error RenderStateCache::getRasterizerState(const gl::RasterizerState &raster
} }
d3d11::RasterizerState dx11RasterizerState; d3d11::RasterizerState dx11RasterizerState;
ANGLE_TRY(mRenderer->allocateResource(rasterDesc, &dx11RasterizerState)); ANGLE_TRY(renderer->allocateResource(rasterDesc, &dx11RasterizerState));
*outRasterizerState = dx11RasterizerState.get(); *outRasterizerState = dx11RasterizerState.get();
mRasterizerStateCache.Put(key, std::move(dx11RasterizerState)); mRasterizerStateCache.Put(key, std::move(dx11RasterizerState));
return gl::NoError(); return gl::NoError();
} }
gl::Error RenderStateCache::getDepthStencilState(const gl::DepthStencilState &glState, gl::Error RenderStateCache::getDepthStencilState(Renderer11 *renderer,
const gl::DepthStencilState &glState,
ID3D11DepthStencilState **outDSState) ID3D11DepthStencilState **outDSState)
{ {
auto keyIter = mDepthStencilStateCache.Get(glState); auto keyIter = mDepthStencilStateCache.Get(glState);
...@@ -250,14 +253,16 @@ gl::Error RenderStateCache::getDepthStencilState(const gl::DepthStencilState &gl ...@@ -250,14 +253,16 @@ gl::Error RenderStateCache::getDepthStencilState(const gl::DepthStencilState &gl
dsDesc.BackFace.StencilFunc = ConvertComparison(glState.stencilBackFunc); dsDesc.BackFace.StencilFunc = ConvertComparison(glState.stencilBackFunc);
d3d11::DepthStencilState dx11DepthStencilState; d3d11::DepthStencilState dx11DepthStencilState;
ANGLE_TRY(mRenderer->allocateResource(dsDesc, &dx11DepthStencilState)); ANGLE_TRY(renderer->allocateResource(dsDesc, &dx11DepthStencilState));
*outDSState = dx11DepthStencilState.get(); *outDSState = dx11DepthStencilState.get();
mDepthStencilStateCache.Put(glState, std::move(dx11DepthStencilState)); mDepthStencilStateCache.Put(glState, std::move(dx11DepthStencilState));
return gl::NoError(); return gl::NoError();
} }
gl::Error RenderStateCache::getSamplerState(const gl::SamplerState &samplerState, ID3D11SamplerState **outSamplerState) gl::Error RenderStateCache::getSamplerState(Renderer11 *renderer,
const gl::SamplerState &samplerState,
ID3D11SamplerState **outSamplerState)
{ {
auto keyIter = mSamplerStateCache.Get(samplerState); auto keyIter = mSamplerStateCache.Get(samplerState);
if (keyIter != mSamplerStateCache.end()) if (keyIter != mSamplerStateCache.end())
...@@ -268,7 +273,7 @@ gl::Error RenderStateCache::getSamplerState(const gl::SamplerState &samplerState ...@@ -268,7 +273,7 @@ gl::Error RenderStateCache::getSamplerState(const gl::SamplerState &samplerState
TrimCache(kMaxStates, kGCLimit, "sampler stencil", &mSamplerStateCache); TrimCache(kMaxStates, kGCLimit, "sampler stencil", &mSamplerStateCache);
const auto &featureLevel = mRenderer->getRenderer11DeviceCaps().featureLevel; const auto &featureLevel = renderer->getRenderer11DeviceCaps().featureLevel;
D3D11_SAMPLER_DESC samplerDesc; D3D11_SAMPLER_DESC samplerDesc;
samplerDesc.Filter = samplerDesc.Filter =
...@@ -288,7 +293,7 @@ gl::Error RenderStateCache::getSamplerState(const gl::SamplerState &samplerState ...@@ -288,7 +293,7 @@ gl::Error RenderStateCache::getSamplerState(const gl::SamplerState &samplerState
samplerDesc.MinLOD = samplerState.minLod; samplerDesc.MinLOD = samplerState.minLod;
samplerDesc.MaxLOD = samplerState.maxLod; samplerDesc.MaxLOD = samplerState.maxLod;
if (mRenderer->getRenderer11DeviceCaps().featureLevel <= D3D_FEATURE_LEVEL_9_3) if (featureLevel <= D3D_FEATURE_LEVEL_9_3)
{ {
// Check that maxLOD is nearly FLT_MAX (1000.0f is the default), since 9_3 doesn't support // Check that maxLOD is nearly FLT_MAX (1000.0f is the default), since 9_3 doesn't support
// anything other than FLT_MAX. Note that Feature Level 9_* only supports GL ES 2.0, so the // anything other than FLT_MAX. Note that Feature Level 9_* only supports GL ES 2.0, so the
...@@ -301,7 +306,7 @@ gl::Error RenderStateCache::getSamplerState(const gl::SamplerState &samplerState ...@@ -301,7 +306,7 @@ gl::Error RenderStateCache::getSamplerState(const gl::SamplerState &samplerState
} }
d3d11::SamplerState dx11SamplerState; d3d11::SamplerState dx11SamplerState;
ANGLE_TRY(mRenderer->allocateResource(samplerDesc, &dx11SamplerState)); ANGLE_TRY(renderer->allocateResource(samplerDesc, &dx11SamplerState));
*outSamplerState = dx11SamplerState.get(); *outSamplerState = dx11SamplerState.get();
mSamplerStateCache.Put(samplerState, std::move(dx11SamplerState)); mSamplerStateCache.Put(samplerState, std::move(dx11SamplerState));
......
...@@ -72,22 +72,28 @@ class Renderer11; ...@@ -72,22 +72,28 @@ class Renderer11;
class RenderStateCache : angle::NonCopyable class RenderStateCache : angle::NonCopyable
{ {
public: public:
RenderStateCache(Renderer11 *renderer); RenderStateCache();
virtual ~RenderStateCache(); virtual ~RenderStateCache();
void clear(); void clear();
static d3d11::BlendStateKey GetBlendStateKey(const gl::Framebuffer *framebuffer, static d3d11::BlendStateKey GetBlendStateKey(const gl::Framebuffer *framebuffer,
const gl::BlendState &blendState); const gl::BlendState &blendState);
gl::Error getBlendState(const d3d11::BlendStateKey &key, ID3D11BlendState **outBlendState); gl::Error getBlendState(Renderer11 *renderer,
gl::Error getRasterizerState(const gl::RasterizerState &rasterState, bool scissorEnabled, ID3D11RasterizerState **outRasterizerState); const d3d11::BlendStateKey &key,
gl::Error getDepthStencilState(const gl::DepthStencilState &dsState, ID3D11BlendState **outBlendState);
gl::Error getRasterizerState(Renderer11 *renderer,
const gl::RasterizerState &rasterState,
bool scissorEnabled,
ID3D11RasterizerState **outRasterizerState);
gl::Error getDepthStencilState(Renderer11 *renderer,
const gl::DepthStencilState &dsState,
ID3D11DepthStencilState **outDSState); ID3D11DepthStencilState **outDSState);
gl::Error getSamplerState(const gl::SamplerState &samplerState, ID3D11SamplerState **outSamplerState); gl::Error getSamplerState(Renderer11 *renderer,
const gl::SamplerState &samplerState,
ID3D11SamplerState **outSamplerState);
private: private:
Renderer11 *mRenderer;
// MSDN's documentation of ID3D11Device::CreateBlendState, ID3D11Device::CreateRasterizerState, // MSDN's documentation of ID3D11Device::CreateBlendState, ID3D11Device::CreateRasterizerState,
// ID3D11Device::CreateDepthStencilState and ID3D11Device::CreateSamplerState claims the maximum // ID3D11Device::CreateDepthStencilState and ID3D11Device::CreateSamplerState claims the maximum
// number of unique states of each type an application can create is 4096 // number of unique states of each type an application can create is 4096
......
...@@ -381,7 +381,7 @@ const uint32_t ScratchMemoryBufferLifetime = 1000; ...@@ -381,7 +381,7 @@ const uint32_t ScratchMemoryBufferLifetime = 1000;
Renderer11::Renderer11(egl::Display *display) Renderer11::Renderer11(egl::Display *display)
: RendererD3D(display), : RendererD3D(display),
mStateCache(this), mStateCache(),
mStateManager(this), mStateManager(this),
mLastHistogramUpdateTime( mLastHistogramUpdateTime(
ANGLEPlatformCurrent()->monotonicallyIncreasingTime(ANGLEPlatformCurrent())), ANGLEPlatformCurrent()->monotonicallyIncreasingTime(ANGLEPlatformCurrent())),
...@@ -1445,7 +1445,7 @@ gl::Error Renderer11::setSamplerState(gl::SamplerType type, ...@@ -1445,7 +1445,7 @@ gl::Error Renderer11::setSamplerState(gl::SamplerType type,
memcmp(&samplerState, &mCurPixelSamplerStates[index], sizeof(gl::SamplerState)) != 0) memcmp(&samplerState, &mCurPixelSamplerStates[index], sizeof(gl::SamplerState)) != 0)
{ {
ID3D11SamplerState *dxSamplerState = nullptr; ID3D11SamplerState *dxSamplerState = nullptr;
ANGLE_TRY(mStateCache.getSamplerState(samplerState, &dxSamplerState)); ANGLE_TRY(mStateCache.getSamplerState(this, samplerState, &dxSamplerState));
ASSERT(dxSamplerState != nullptr); ASSERT(dxSamplerState != nullptr);
mDeviceContext->PSSetSamplers(index, 1, &dxSamplerState); mDeviceContext->PSSetSamplers(index, 1, &dxSamplerState);
...@@ -1465,7 +1465,7 @@ gl::Error Renderer11::setSamplerState(gl::SamplerType type, ...@@ -1465,7 +1465,7 @@ gl::Error Renderer11::setSamplerState(gl::SamplerType type,
memcmp(&samplerState, &mCurVertexSamplerStates[index], sizeof(gl::SamplerState)) != 0) memcmp(&samplerState, &mCurVertexSamplerStates[index], sizeof(gl::SamplerState)) != 0)
{ {
ID3D11SamplerState *dxSamplerState = nullptr; ID3D11SamplerState *dxSamplerState = nullptr;
ANGLE_TRY(mStateCache.getSamplerState(samplerState, &dxSamplerState)); ANGLE_TRY(mStateCache.getSamplerState(this, samplerState, &dxSamplerState));
ASSERT(dxSamplerState != nullptr); ASSERT(dxSamplerState != nullptr);
mDeviceContext->VSSetSamplers(index, 1, &dxSamplerState); mDeviceContext->VSSetSamplers(index, 1, &dxSamplerState);
...@@ -1485,7 +1485,7 @@ gl::Error Renderer11::setSamplerState(gl::SamplerType type, ...@@ -1485,7 +1485,7 @@ gl::Error Renderer11::setSamplerState(gl::SamplerType type,
memcmp(&samplerState, &mCurComputeSamplerStates[index], sizeof(gl::SamplerState)) != 0) memcmp(&samplerState, &mCurComputeSamplerStates[index], sizeof(gl::SamplerState)) != 0)
{ {
ID3D11SamplerState *dxSamplerState = nullptr; ID3D11SamplerState *dxSamplerState = nullptr;
ANGLE_TRY(mStateCache.getSamplerState(samplerState, &dxSamplerState)); ANGLE_TRY(mStateCache.getSamplerState(this, samplerState, &dxSamplerState));
ASSERT(dxSamplerState != nullptr); ASSERT(dxSamplerState != nullptr);
mDeviceContext->CSSetSamplers(index, 1, &dxSamplerState); mDeviceContext->CSSetSamplers(index, 1, &dxSamplerState);
...@@ -5015,4 +5015,29 @@ gl::Error Renderer11::allocateTexture(const D3D11_TEXTURE3D_DESC &desc, ...@@ -5015,4 +5015,29 @@ gl::Error Renderer11::allocateTexture(const D3D11_TEXTURE3D_DESC &desc,
return gl::NoError(); return gl::NoError();
} }
gl::Error Renderer11::getBlendState(const d3d11::BlendStateKey &key,
ID3D11BlendState **outBlendState)
{
return mStateCache.getBlendState(this, key, outBlendState);
}
gl::Error Renderer11::getRasterizerState(const gl::RasterizerState &rasterState,
bool scissorEnabled,
ID3D11RasterizerState **outRasterizerState)
{
return mStateCache.getRasterizerState(this, rasterState, scissorEnabled, outRasterizerState);
}
gl::Error Renderer11::getDepthStencilState(const gl::DepthStencilState &dsState,
ID3D11DepthStencilState **outDSState)
{
return mStateCache.getDepthStencilState(this, dsState, outDSState);
}
gl::Error Renderer11::getSamplerState(const gl::SamplerState &samplerState,
ID3D11SamplerState **outSamplerState)
{
return mStateCache.getSamplerState(this, samplerState, outSamplerState);
}
} // namespace rx } // namespace rx
...@@ -314,7 +314,14 @@ class Renderer11 : public RendererD3D ...@@ -314,7 +314,14 @@ class Renderer11 : public RendererD3D
ID3D11DeviceContext1 *getDeviceContext1IfSupported() { return mDeviceContext1; }; ID3D11DeviceContext1 *getDeviceContext1IfSupported() { return mDeviceContext1; };
IDXGIFactory *getDxgiFactory() { return mDxgiFactory; }; IDXGIFactory *getDxgiFactory() { return mDxgiFactory; };
RenderStateCache &getStateCache() { return mStateCache; } gl::Error getBlendState(const d3d11::BlendStateKey &key, ID3D11BlendState **outBlendState);
gl::Error getRasterizerState(const gl::RasterizerState &rasterState,
bool scissorEnabled,
ID3D11RasterizerState **outRasterizerState);
gl::Error getDepthStencilState(const gl::DepthStencilState &dsState,
ID3D11DepthStencilState **outDSState);
gl::Error getSamplerState(const gl::SamplerState &samplerState,
ID3D11SamplerState **outSamplerState);
Blit11 *getBlitter() { return mBlit; } Blit11 *getBlitter() { return mBlit; }
Clear11 *getClearer() { return mClear; } Clear11 *getClearer() { return mClear; }
......
...@@ -505,7 +505,7 @@ gl::Error StateManager11::setBlendState(const gl::Framebuffer *framebuffer, ...@@ -505,7 +505,7 @@ gl::Error StateManager11::setBlendState(const gl::Framebuffer *framebuffer,
ID3D11BlendState *dxBlendState = nullptr; ID3D11BlendState *dxBlendState = nullptr;
const d3d11::BlendStateKey &key = RenderStateCache::GetBlendStateKey(framebuffer, blendState); const d3d11::BlendStateKey &key = RenderStateCache::GetBlendStateKey(framebuffer, blendState);
ANGLE_TRY(mRenderer->getStateCache().getBlendState(key, &dxBlendState)); ANGLE_TRY(mRenderer->getBlendState(key, &dxBlendState));
ASSERT(dxBlendState != nullptr); ASSERT(dxBlendState != nullptr);
...@@ -593,7 +593,7 @@ gl::Error StateManager11::setDepthStencilState(const gl::State &glState) ...@@ -593,7 +593,7 @@ gl::Error StateManager11::setDepthStencilState(const gl::State &glState)
dsStateKey.stencilTest = false; dsStateKey.stencilTest = false;
} }
ANGLE_TRY(mRenderer->getStateCache().getDepthStencilState(dsStateKey, &dxDepthStencilState)); ANGLE_TRY(mRenderer->getDepthStencilState(dsStateKey, &dxDepthStencilState));
ASSERT(dxDepthStencilState); ASSERT(dxDepthStencilState);
...@@ -642,13 +642,12 @@ gl::Error StateManager11::setRasterizerState(const gl::RasterizerState &rasterSt ...@@ -642,13 +642,12 @@ gl::Error StateManager11::setRasterizerState(const gl::RasterizerState &rasterSt
modifiedRasterState.frontFace = GL_CCW; modifiedRasterState.frontFace = GL_CCW;
} }
ANGLE_TRY(mRenderer->getStateCache().getRasterizerState( ANGLE_TRY(
modifiedRasterState, mCurScissorEnabled, &dxRasterState)); mRenderer->getRasterizerState(modifiedRasterState, mCurScissorEnabled, &dxRasterState));
} }
else else
{ {
ANGLE_TRY(mRenderer->getStateCache().getRasterizerState(rasterState, mCurScissorEnabled, ANGLE_TRY(mRenderer->getRasterizerState(rasterState, mCurScissorEnabled, &dxRasterState));
&dxRasterState));
} }
mRenderer->getDeviceContext()->RSSetState(dxRasterState); mRenderer->getDeviceContext()->RSSetState(dxRasterState);
......
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