Commit b05f3659 by Jamie Madill Committed by Commit Bot

D3D11: Consolidate Blend State application.

This will make it easier to implement fast state switching on Context change. BUG=angleproject:2052 Change-Id: I045cc2164200a93215629a2746068e686d7c99ff Reviewed-on: https://chromium-review.googlesource.com/659234Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 518f5d55
......@@ -1087,7 +1087,7 @@ gl::Error Blit11::swizzleTexture(const gl::Context *context,
stateManager->setPixelConstantBuffer(0, &mSwizzleCB);
// Apply state
deviceContext->OMSetBlendState(nullptr, nullptr, 0xFFFFFFF);
stateManager->setSimpleBlendState(nullptr);
stateManager->setDepthStencilState(nullptr, 0xFFFFFFFF);
deviceContext->RSSetState(mScissorDisabledRasterizerState.get());
......@@ -1200,12 +1200,11 @@ gl::Error Blit11::copyTexture(const gl::Context *context,
if (maskOffAlpha)
{
ANGLE_TRY(mAlphaMaskBlendState.resolve(mRenderer));
ID3D11BlendState *blendState = mAlphaMaskBlendState.get();
deviceContext->OMSetBlendState(blendState, nullptr, 0xFFFFFFF);
stateManager->setSimpleBlendState(&mAlphaMaskBlendState.getObj());
}
else
{
deviceContext->OMSetBlendState(nullptr, nullptr, 0xFFFFFFF);
stateManager->setSimpleBlendState(nullptr);
}
stateManager->setDepthStencilState(nullptr, 0xFFFFFFFF);
......@@ -1333,7 +1332,7 @@ gl::Error Blit11::copyDepth(const gl::Context *context,
stateManager->setSingleVertexBuffer(&mVertexBuffer, stride, 0);
// Apply state
deviceContext->OMSetBlendState(nullptr, nullptr, 0xFFFFFFF);
stateManager->setSimpleBlendState(nullptr);
stateManager->setDepthStencilState(&mDepthStencilState, 0xFFFFFFFF);
if (scissor)
......@@ -2021,7 +2020,7 @@ gl::ErrorOrResult<TextureHelper11> Blit11::resolveDepth(const gl::Context *conte
deviceContext->RSSetState(nullptr);
stateManager->setDepthStencilState(&mDepthStencilState, 0xFFFFFFFF);
stateManager->setRenderTargets(nullptr, 0, mResolvedDepthDSView.get());
deviceContext->OMSetBlendState(nullptr, nullptr, 0xFFFFFFF);
stateManager->setSimpleBlendState(nullptr);
// Set the viewport
D3D11_VIEWPORT viewport;
......@@ -2191,7 +2190,7 @@ gl::ErrorOrResult<TextureHelper11> Blit11::resolveStencil(const gl::Context *con
deviceContext->RSSetState(nullptr);
stateManager->setDepthStencilState(nullptr, 0xFFFFFFFF);
stateManager->setRenderTarget(mResolvedDepthStencilRTView.get(), nullptr);
deviceContext->OMSetBlendState(nullptr, nullptr, 0xFFFFFFF);
stateManager->setSimpleBlendState(nullptr);
// Set the viewport
D3D11_VIEWPORT viewport;
......
......@@ -702,7 +702,7 @@ gl::Error Clear11::clearFramebuffer(const gl::Context *context,
memcpy(mBlendStateKey.rtvMasks, &rtvMasks[0], sizeof(mBlendStateKey.rtvMasks));
// Get BlendState
ID3D11BlendState *blendState = nullptr;
const d3d11::BlendState *blendState = nullptr;
ANGLE_TRY(mRenderer->getBlendState(mBlendStateKey, &blendState));
const d3d11::DepthStencilState *dsState = nullptr;
......@@ -774,7 +774,7 @@ gl::Error Clear11::clearFramebuffer(const gl::Context *context,
deviceContext->RSSetViewports(1, &viewport);
// Apply state
deviceContext->OMSetBlendState(blendState, nullptr, 0xFFFFFFFF);
stateManager->setSimpleBlendState(blendState);
const UINT stencilValue = clearParams.stencilValue & 0xFF;
stateManager->setDepthStencilState(dsState, stencilValue);
......
......@@ -195,7 +195,7 @@ gl::Error PixelTransfer11::copyBufferToTexture(const gl::Context *context,
stateManager->setPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
stateManager->setSingleVertexBuffer(nullptr, 0, 0);
deviceContext->OMSetBlendState(nullptr, nullptr, 0xFFFFFFF);
stateManager->setSimpleBlendState(nullptr);
stateManager->setDepthStencilState(&mCopyDepthStencilState, 0xFFFFFFFF);
deviceContext->RSSetState(mCopyRasterizerState.get());
......
......@@ -88,12 +88,12 @@ d3d11::BlendStateKey RenderStateCache::GetBlendStateKey(const gl::Context *conte
gl::Error RenderStateCache::getBlendState(Renderer11 *renderer,
const d3d11::BlendStateKey &key,
ID3D11BlendState **outBlendState)
const d3d11::BlendState **outBlendState)
{
auto keyIter = mBlendStateCache.Get(key);
if (keyIter != mBlendStateCache.end())
{
*outBlendState = keyIter->second.get();
*outBlendState = &keyIter->second;
return gl::NoError();
}
......@@ -130,8 +130,9 @@ gl::Error RenderStateCache::getBlendState(Renderer11 *renderer,
d3d11::BlendState d3dBlendState;
ANGLE_TRY(renderer->allocateResource(blendDesc, &d3dBlendState));
*outBlendState = d3dBlendState.get();
mBlendStateCache.Put(key, std::move(d3dBlendState));
const auto &iter = mBlendStateCache.Put(key, std::move(d3dBlendState));
*outBlendState = &iter->second;
return gl::NoError();
}
......
......@@ -76,7 +76,7 @@ class RenderStateCache : angle::NonCopyable
const gl::BlendState &blendState);
gl::Error getBlendState(Renderer11 *renderer,
const d3d11::BlendStateKey &key,
ID3D11BlendState **outBlendState);
const d3d11::BlendState **outBlendState);
gl::Error getRasterizerState(Renderer11 *renderer,
const gl::RasterizerState &rasterState,
bool scissorEnabled,
......
......@@ -4005,7 +4005,7 @@ gl::Error Renderer11::allocateTexture(const D3D11_TEXTURE3D_DESC &desc,
}
gl::Error Renderer11::getBlendState(const d3d11::BlendStateKey &key,
ID3D11BlendState **outBlendState)
const d3d11::BlendState **outBlendState)
{
return mStateCache.getBlendState(this, key, outBlendState);
}
......
......@@ -308,7 +308,8 @@ class Renderer11 : public RendererD3D
ID3D11DeviceContext1 *getDeviceContext1IfSupported() { return mDeviceContext1; };
IDXGIFactory *getDxgiFactory() { return mDxgiFactory; };
gl::Error getBlendState(const d3d11::BlendStateKey &key, ID3D11BlendState **outBlendState);
gl::Error getBlendState(const d3d11::BlendStateKey &key,
const d3d11::BlendState **outBlendState);
gl::Error getRasterizerState(const gl::RasterizerState &rasterState,
bool scissorEnabled,
ID3D11RasterizerState **outRasterizerState);
......
......@@ -983,7 +983,7 @@ gl::Error StateManager11::syncBlendState(const gl::Context *context,
const gl::ColorF &blendColor,
unsigned int sampleMask)
{
ID3D11BlendState *dxBlendState = nullptr;
const d3d11::BlendState *dxBlendState = nullptr;
const d3d11::BlendStateKey &key =
RenderStateCache::GetBlendStateKey(context, framebuffer, blendState);
......@@ -1010,7 +1010,7 @@ gl::Error StateManager11::syncBlendState(const gl::Context *context,
blendColors[3] = blendColor.alpha;
}
mRenderer->getDeviceContext()->OMSetBlendState(dxBlendState, blendColors, sampleMask);
mRenderer->getDeviceContext()->OMSetBlendState(dxBlendState->get(), blendColors, sampleMask);
mCurBlendState = blendState;
mCurBlendColor = blendColor;
......@@ -2049,6 +2049,22 @@ void StateManager11::setDepthStencilState(const d3d11::DepthStencilState *depthS
mInternalDirtyBits.set(DIRTY_BIT_DEPTH_STENCIL_STATE);
}
void StateManager11::setSimpleBlendState(const d3d11::BlendState *blendState)
{
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
if (blendState)
{
deviceContext->OMSetBlendState(blendState->get(), nullptr, 0xFFFFFFFF);
}
else
{
deviceContext->OMSetBlendState(nullptr, nullptr, 0xFFFFFFFF);
}
mInternalDirtyBits.set(DIRTY_BIT_BLEND_STATE);
}
// For each Direct3D sampler of either the pixel or vertex stage,
// looks up the corresponding OpenGL texture image unit and texture type,
// and sets the texture and its addressing/filtering state (or NULL when inactive).
......
......@@ -212,6 +212,7 @@ class StateManager11 final : angle::NonCopyable
void setVertexConstantBuffer(unsigned int slot, const d3d11::Buffer *buffer);
void setPixelConstantBuffer(unsigned int slot, const d3d11::Buffer *buffer);
void setDepthStencilState(const d3d11::DepthStencilState *depthStencilState, UINT stencilRef);
void setSimpleBlendState(const d3d11::BlendState *blendState);
// Not handled by an internal dirty bit because of the extra draw parameters.
gl::Error applyVertexBuffer(const gl::Context *context,
......
......@@ -828,10 +828,7 @@ EGLint SwapChain11::copyOffscreenToBackbuffer(const gl::Context *context,
// Apply state
stateManager->setDepthStencilState(nullptr, 0xFFFFFFFF);
static const float blendFactor[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
deviceContext->OMSetBlendState(nullptr, blendFactor, 0xFFFFFFF);
stateManager->setSimpleBlendState(nullptr);
deviceContext->RSSetState(mPassThroughRS.get());
// Apply shaders
......
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