Commit 518f5d55 by Jamie Madill Committed by Commit Bot

D3D11: Consolidate Depth Stencil State application.

This will make it easier to do state update on context switch. BUG=angleproject:2052 Change-Id: Ia73cfd07ced40a9e22d6b34a5619250ede9e8844 Reviewed-on: https://chromium-review.googlesource.com/659233Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 85b63c8e
......@@ -1088,7 +1088,7 @@ gl::Error Blit11::swizzleTexture(const gl::Context *context,
// Apply state
deviceContext->OMSetBlendState(nullptr, nullptr, 0xFFFFFFF);
deviceContext->OMSetDepthStencilState(nullptr, 0xFFFFFFFF);
stateManager->setDepthStencilState(nullptr, 0xFFFFFFFF);
deviceContext->RSSetState(mScissorDisabledRasterizerState.get());
// Apply shaders
......@@ -1207,7 +1207,7 @@ gl::Error Blit11::copyTexture(const gl::Context *context,
{
deviceContext->OMSetBlendState(nullptr, nullptr, 0xFFFFFFF);
}
deviceContext->OMSetDepthStencilState(nullptr, 0xFFFFFFFF);
stateManager->setDepthStencilState(nullptr, 0xFFFFFFFF);
if (scissor)
{
......@@ -1334,7 +1334,7 @@ gl::Error Blit11::copyDepth(const gl::Context *context,
// Apply state
deviceContext->OMSetBlendState(nullptr, nullptr, 0xFFFFFFF);
deviceContext->OMSetDepthStencilState(mDepthStencilState.get(), 0xFFFFFFFF);
stateManager->setDepthStencilState(&mDepthStencilState, 0xFFFFFFFF);
if (scissor)
{
......@@ -2019,7 +2019,7 @@ gl::ErrorOrResult<TextureHelper11> Blit11::resolveDepth(const gl::Context *conte
stateManager->setDrawShaders(&mResolveDepthStencilVS.getObj(), nullptr,
&mResolveDepthPS.getObj());
deviceContext->RSSetState(nullptr);
deviceContext->OMSetDepthStencilState(mDepthStencilState.get(), 0xFFFFFFFF);
stateManager->setDepthStencilState(&mDepthStencilState, 0xFFFFFFFF);
stateManager->setRenderTargets(nullptr, 0, mResolvedDepthDSView.get());
deviceContext->OMSetBlendState(nullptr, nullptr, 0xFFFFFFF);
......@@ -2189,7 +2189,7 @@ gl::ErrorOrResult<TextureHelper11> Blit11::resolveStencil(const gl::Context *con
stateManager->setPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
stateManager->setDrawShaders(&mResolveDepthStencilVS.getObj(), nullptr, pixelShader);
deviceContext->RSSetState(nullptr);
deviceContext->OMSetDepthStencilState(nullptr, 0xFFFFFFFF);
stateManager->setDepthStencilState(nullptr, 0xFFFFFFFF);
stateManager->setRenderTarget(mResolvedDepthStencilRTView.get(), nullptr);
deviceContext->OMSetBlendState(nullptr, nullptr, 0xFFFFFFF);
......
......@@ -705,7 +705,7 @@ gl::Error Clear11::clearFramebuffer(const gl::Context *context,
ID3D11BlendState *blendState = nullptr;
ANGLE_TRY(mRenderer->getBlendState(mBlendStateKey, &blendState));
ID3D11DepthStencilState *dsState = nullptr;
const d3d11::DepthStencilState *dsState = nullptr;
const float *zValue = nullptr;
if (dsv)
......@@ -761,6 +761,8 @@ gl::Error Clear11::clearFramebuffer(const gl::Context *context,
deviceContext->Unmap(mConstantBuffer.get(), 0);
}
auto *stateManager = mRenderer->getStateManager();
// Set the viewport to be the same size as the framebuffer.
D3D11_VIEWPORT viewport;
viewport.TopLeftX = 0;
......@@ -775,7 +777,7 @@ gl::Error Clear11::clearFramebuffer(const gl::Context *context,
deviceContext->OMSetBlendState(blendState, nullptr, 0xFFFFFFFF);
const UINT stencilValue = clearParams.stencilValue & 0xFF;
deviceContext->OMSetDepthStencilState(dsState, stencilValue);
stateManager->setDepthStencilState(dsState, stencilValue);
if (needScissoredClear)
{
......@@ -786,8 +788,6 @@ gl::Error Clear11::clearFramebuffer(const gl::Context *context,
deviceContext->RSSetState(mScissorDisabledRasterizerState.get());
}
auto *stateManager = mRenderer->getStateManager();
// Get Shaders
const d3d11::VertexShader *vs = nullptr;
const d3d11::GeometryShader *gs = nullptr;
......
......@@ -196,7 +196,7 @@ gl::Error PixelTransfer11::copyBufferToTexture(const gl::Context *context,
stateManager->setSingleVertexBuffer(nullptr, 0, 0);
deviceContext->OMSetBlendState(nullptr, nullptr, 0xFFFFFFF);
deviceContext->OMSetDepthStencilState(mCopyDepthStencilState.get(), 0xFFFFFFFF);
stateManager->setDepthStencilState(&mCopyDepthStencilState, 0xFFFFFFFF);
deviceContext->RSSetState(mCopyRasterizerState.get());
stateManager->setRenderTarget(textureRTV.get(), nullptr);
......
......@@ -195,12 +195,12 @@ gl::Error RenderStateCache::getRasterizerState(Renderer11 *renderer,
gl::Error RenderStateCache::getDepthStencilState(Renderer11 *renderer,
const gl::DepthStencilState &glState,
ID3D11DepthStencilState **outDSState)
const d3d11::DepthStencilState **outDSState)
{
auto keyIter = mDepthStencilStateCache.Get(glState);
if (keyIter != mDepthStencilStateCache.end())
{
*outDSState = keyIter->second.get();
*outDSState = &keyIter->second;
return gl::NoError();
}
......@@ -224,8 +224,9 @@ gl::Error RenderStateCache::getDepthStencilState(Renderer11 *renderer,
d3d11::DepthStencilState dx11DepthStencilState;
ANGLE_TRY(renderer->allocateResource(dsDesc, &dx11DepthStencilState));
*outDSState = dx11DepthStencilState.get();
mDepthStencilStateCache.Put(glState, std::move(dx11DepthStencilState));
const auto &iter = mDepthStencilStateCache.Put(glState, std::move(dx11DepthStencilState));
*outDSState = &iter->second;
return gl::NoError();
}
......
......@@ -83,7 +83,7 @@ class RenderStateCache : angle::NonCopyable
ID3D11RasterizerState **outRasterizerState);
gl::Error getDepthStencilState(Renderer11 *renderer,
const gl::DepthStencilState &dsState,
ID3D11DepthStencilState **outDSState);
const d3d11::DepthStencilState **outDSState);
gl::Error getSamplerState(Renderer11 *renderer,
const gl::SamplerState &samplerState,
ID3D11SamplerState **outSamplerState);
......
......@@ -4018,7 +4018,7 @@ gl::Error Renderer11::getRasterizerState(const gl::RasterizerState &rasterState,
}
gl::Error Renderer11::getDepthStencilState(const gl::DepthStencilState &dsState,
ID3D11DepthStencilState **outDSState)
const d3d11::DepthStencilState **outDSState)
{
return mStateCache.getDepthStencilState(this, dsState, outDSState);
}
......
......@@ -313,7 +313,7 @@ class Renderer11 : public RendererD3D
bool scissorEnabled,
ID3D11RasterizerState **outRasterizerState);
gl::Error getDepthStencilState(const gl::DepthStencilState &dsState,
ID3D11DepthStencilState **outDSState);
const d3d11::DepthStencilState **outDSState);
gl::Error getSamplerState(const gl::SamplerState &samplerState,
ID3D11SamplerState **outSamplerState);
......
......@@ -1054,7 +1054,7 @@ gl::Error StateManager11::syncDepthStencilState(const gl::State &glState)
modifiedGLState.stencilTest = false;
}
ID3D11DepthStencilState *d3dState = nullptr;
const d3d11::DepthStencilState *d3dState = nullptr;
ANGLE_TRY(mRenderer->getDepthStencilState(modifiedGLState, &d3dState));
ASSERT(d3dState);
......@@ -1068,7 +1068,7 @@ gl::Error StateManager11::syncDepthStencilState(const gl::State &glState)
"Unexpected value of D3D11_DEFAULT_STENCIL_WRITE_MASK");
UINT dxStencilRef = std::min<UINT>(mCurStencilRef, 0xFFu);
mRenderer->getDeviceContext()->OMSetDepthStencilState(d3dState, dxStencilRef);
mRenderer->getDeviceContext()->OMSetDepthStencilState(d3dState->get(), dxStencilRef);
return gl::NoError();
}
......@@ -2032,6 +2032,23 @@ void StateManager11::setPixelConstantBuffer(unsigned int slot, const d3d11::Buff
}
}
void StateManager11::setDepthStencilState(const d3d11::DepthStencilState *depthStencilState,
UINT stencilRef)
{
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
if (depthStencilState)
{
deviceContext->OMSetDepthStencilState(depthStencilState->get(), stencilRef);
}
else
{
deviceContext->OMSetDepthStencilState(nullptr, stencilRef);
}
mInternalDirtyBits.set(DIRTY_BIT_DEPTH_STENCIL_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).
......
......@@ -211,6 +211,7 @@ class StateManager11 final : angle::NonCopyable
void setComputeShader(const d3d11::ComputeShader *shader);
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);
// Not handled by an internal dirty bit because of the extra draw parameters.
gl::Error applyVertexBuffer(const gl::Context *context,
......
......@@ -827,7 +827,7 @@ EGLint SwapChain11::copyOffscreenToBackbuffer(const gl::Context *context,
stateManager->setSingleVertexBuffer(&mQuadVB, stride, 0);
// Apply state
deviceContext->OMSetDepthStencilState(nullptr, 0xFFFFFFFF);
stateManager->setDepthStencilState(nullptr, 0xFFFFFFFF);
static const float blendFactor[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
deviceContext->OMSetBlendState(nullptr, blendFactor, 0xFFFFFFF);
......
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