Commit 451cb838 by Dian Xiang

Using dirty bit notification for d3d11 blend state

BUG=angleproject:1161 This is a re-land for commit ff2ab571. Dirty bits didn't check for sampleMask, hence when sampleMask changed and nothing else, d3D states didn't update. This commit also focuses on blend state for d3d11 to make the cl change smaller and more manageable. This commit also some performance regression issues that were occuring in commit ff2ab571 Change-Id: I866066689911870a84125fa2150f9efbf1405ad0 Reviewed-on: https://chromium-review.googlesource.com/312468Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tryjob-Request: Dian Xiang <dianx@google.com> Tested-by: 's avatarDian Xiang <dianx@google.com>
parent d6dfe67d
......@@ -8,16 +8,13 @@
#include "libANGLE/renderer/d3d/RendererD3D.h"
#include "common/MemoryBuffer.h"
#include "common/debug.h"
#include "common/MemoryBuffer.h"
#include "common/utilities.h"
#include "libANGLE/Display.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/Framebuffer.h"
#include "libANGLE/FramebufferAttachment.h"
#include "libANGLE/ResourceManager.h"
#include "libANGLE/State.h"
#include "libANGLE/VertexArray.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/d3d/BufferD3D.h"
#include "libANGLE/renderer/d3d/CompilerD3D.h"
#include "libANGLE/renderer/d3d/DeviceD3D.h"
......@@ -25,6 +22,9 @@
#include "libANGLE/renderer/d3d/IndexDataManager.h"
#include "libANGLE/renderer/d3d/ProgramD3D.h"
#include "libANGLE/renderer/d3d/SamplerD3D.h"
#include "libANGLE/ResourceManager.h"
#include "libANGLE/State.h"
#include "libANGLE/VertexArray.h"
namespace rx
{
......@@ -415,7 +415,8 @@ gl::Error RendererD3D::applyState(const gl::Data &data, GLenum drawMode)
{
mask = 0xFFFFFFFF;
}
error = setBlendState(framebufferObject, data.state->getBlendState(), data.state->getBlendColor(), mask);
error = setBlendState(framebufferObject, data.state->getBlendState(),
data.state->getBlendColor(), mask);
if (error.isError())
{
return error;
......
......@@ -154,8 +154,11 @@ class RendererD3D : public Renderer, public BufferFactoryD3D
const std::vector<GLint> &fragmentUniformBuffers) = 0;
virtual gl::Error setRasterizerState(const gl::RasterizerState &rasterState) = 0;
virtual gl::Error setBlendState(const gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::ColorF &blendColor,
virtual gl::Error setBlendState(const gl::Framebuffer *framebuffer,
const gl::BlendState &blendState,
const gl::ColorF &blendColor,
unsigned int sampleMask) = 0;
virtual gl::Error setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
int stencilBackRef, bool frontFaceCCW) = 0;
......@@ -236,11 +239,6 @@ class RendererD3D : public Renderer, public BufferFactoryD3D
virtual gl::Error fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTargetD3D *destRenderTarget,
GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea) = 0;
void syncState(const gl::State & /*state*/, const gl::State::DirtyBits &bitmask) override
{
// TODO(jmadill): implement state sync for D3D renderers;
}
// Device lost
void notifyDeviceLost() override;
virtual bool resetDevice() = 0;
......
......@@ -21,7 +21,6 @@
#include "libANGLE/histogram_macros.h"
#include "libANGLE/Program.h"
#include "libANGLE/renderer/d3d/CompilerD3D.h"
#include "libANGLE/renderer/d3d/DeviceD3D.h"
#include "libANGLE/renderer/d3d/d3d11/Blit11.h"
#include "libANGLE/renderer/d3d/d3d11/Buffer11.h"
#include "libANGLE/renderer/d3d/d3d11/Clear11.h"
......@@ -42,6 +41,7 @@
#include "libANGLE/renderer/d3d/d3d11/Trim11.h"
#include "libANGLE/renderer/d3d/d3d11/VertexArray11.h"
#include "libANGLE/renderer/d3d/d3d11/VertexBuffer11.h"
#include "libANGLE/renderer/d3d/DeviceD3D.h"
#include "libANGLE/renderer/d3d/FramebufferD3D.h"
#include "libANGLE/renderer/d3d/IndexDataManager.h"
#include "libANGLE/renderer/d3d/ProgramD3D.h"
......@@ -471,6 +471,7 @@ Renderer11::Renderer11(egl::Display *display)
: RendererD3D(display),
mStateCache(this),
mCurStencilSize(0),
mStateManager(this),
mLastHistogramUpdateTime(ANGLEPlatformCurrent()->monotonicallyIncreasingTime()),
mDebug(nullptr)
{
......@@ -1378,50 +1379,17 @@ gl::Error Renderer11::setRasterizerState(const gl::RasterizerState &rasterState)
return gl::Error(GL_NO_ERROR);
}
gl::Error Renderer11::setBlendState(const gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::ColorF &blendColor,
unsigned int sampleMask)
void Renderer11::syncState(const gl::State &state, const gl::State::DirtyBits &bitmask)
{
if (mForceSetBlendState ||
memcmp(&blendState, &mCurBlendState, sizeof(gl::BlendState)) != 0 ||
memcmp(&blendColor, &mCurBlendColor, sizeof(gl::ColorF)) != 0 ||
sampleMask != mCurSampleMask)
{
ID3D11BlendState *dxBlendState = NULL;
gl::Error error = mStateCache.getBlendState(framebuffer, blendState, &dxBlendState);
if (error.isError())
{
return error;
}
ASSERT(dxBlendState != NULL);
float blendColors[4] = {0.0f};
if (blendState.sourceBlendRGB != GL_CONSTANT_ALPHA && blendState.sourceBlendRGB != GL_ONE_MINUS_CONSTANT_ALPHA &&
blendState.destBlendRGB != GL_CONSTANT_ALPHA && blendState.destBlendRGB != GL_ONE_MINUS_CONSTANT_ALPHA)
{
blendColors[0] = blendColor.red;
blendColors[1] = blendColor.green;
blendColors[2] = blendColor.blue;
blendColors[3] = blendColor.alpha;
}
else
{
blendColors[0] = blendColor.alpha;
blendColors[1] = blendColor.alpha;
blendColors[2] = blendColor.alpha;
blendColors[3] = blendColor.alpha;
}
mDeviceContext->OMSetBlendState(dxBlendState, blendColors, sampleMask);
mCurBlendState = blendState;
mCurBlendColor = blendColor;
mCurSampleMask = sampleMask;
}
mForceSetBlendState = false;
mStateManager.syncState(state, bitmask);
}
return gl::Error(GL_NO_ERROR);
gl::Error Renderer11::setBlendState(const gl::Framebuffer *framebuffer,
const gl::BlendState &blendState,
const gl::ColorF &blendColor,
unsigned int sampleMask)
{
return mStateManager.setBlendState(framebuffer, blendState, blendColor, sampleMask);
}
gl::Error Renderer11::setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
......@@ -1762,7 +1730,7 @@ gl::Error Renderer11::applyRenderTarget(const gl::Framebuffer *framebuffer)
mRenderTargetDesc.format = renderTargetFormat;
mForceSetViewport = true;
mForceSetScissor = true;
mForceSetBlendState = true;
mStateManager.forceSetBlendState();
if (!mDepthStencilInitialized)
{
......@@ -2555,7 +2523,7 @@ void Renderer11::markAllStateDirty()
mForceSetPixelSamplerStates[fsamplerId] = true;
}
mForceSetBlendState = true;
mStateManager.forceSetBlendState();
mForceSetRasterState = true;
mForceSetDepthStencilState = true;
mForceSetScissor = true;
......
......@@ -19,6 +19,7 @@
#include "libANGLE/renderer/d3d/d3d11/DebugAnnotator11.h"
#include "libANGLE/renderer/d3d/d3d11/InputLayoutCache.h"
#include "libANGLE/renderer/d3d/d3d11/RenderStateCache.h"
#include "libANGLE/renderer/d3d/d3d11/StateManager11.h"
namespace gl
{
......@@ -121,8 +122,11 @@ class Renderer11 : public RendererD3D
const std::vector<GLint> &fragmentUniformBuffers) override;
virtual gl::Error setRasterizerState(const gl::RasterizerState &rasterState);
gl::Error setBlendState(const gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::ColorF &blendColor,
gl::Error setBlendState(const gl::Framebuffer *framebuffer,
const gl::BlendState &blendState,
const gl::ColorF &blendColor,
unsigned int sampleMask) override;
virtual gl::Error setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
int stencilBackRef, bool frontFaceCCW);
......@@ -244,6 +248,8 @@ class Renderer11 : public RendererD3D
ID3D11DeviceContext1 *getDeviceContext1IfSupported() { return mDeviceContext1; };
DXGIFactory *getDxgiFactory() { return mDxgiFactory; };
RenderStateCache &getStateCache() { return mStateCache; }
Blit11 *getBlitter() { return mBlit; }
Clear11 *getClearer() { return mClear; }
......@@ -285,6 +291,8 @@ class Renderer11 : public RendererD3D
egl::Error initializeEGLDevice(DeviceD3D **outDevice) override;
void syncState(const gl::State &state, const gl::State::DirtyBits &bitmask) override;
private:
gl::Error drawArraysImpl(const gl::Data &data,
GLenum mode,
......@@ -402,11 +410,7 @@ class Renderer11 : public RendererD3D
// A block of NULL pointers, cached so we don't re-allocate every draw call
std::vector<ID3D11ShaderResourceView*> mNullSRVs;
// Currently applied blend state
bool mForceSetBlendState;
gl::BlendState mCurBlendState;
gl::ColorF mCurBlendColor;
unsigned int mCurSampleMask;
StateManager11 mStateManager;
// Currently applied rasterizer state
bool mForceSetRasterState;
......
//
// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// StateManager11.cpp: Defines a class for caching D3D11 state
#include "libANGLE/renderer/d3d/d3d11/StateManager11.h"
#include "common/BitSetIterator.h"
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
namespace rx
{
StateManager11::StateManager11(Renderer11 *renderer11)
: mBlendStateIsDirty(false),
mCurBlendColor(0, 0, 0, 0),
mCurSampleMask(0),
mRenderer11(renderer11)
{
mCurBlendState.blend = false;
mCurBlendState.sourceBlendRGB = GL_ONE;
mCurBlendState.destBlendRGB = GL_ZERO;
mCurBlendState.sourceBlendAlpha = GL_ONE;
mCurBlendState.destBlendAlpha = GL_ZERO;
mCurBlendState.blendEquationRGB = GL_FUNC_ADD;
mCurBlendState.blendEquationAlpha = GL_FUNC_ADD;
mCurBlendState.colorMaskRed = true;
mCurBlendState.colorMaskBlue = true;
mCurBlendState.colorMaskGreen = true;
mCurBlendState.colorMaskAlpha = true;
mCurBlendState.sampleAlphaToCoverage = false;
mCurBlendState.dither = false;
}
StateManager11::~StateManager11()
{
}
void StateManager11::syncState(const gl::State &state, const gl::State::DirtyBits &dirtyBits)
{
for (unsigned int dirtyBit : angle::IterateBitSet(dirtyBits))
{
switch (dirtyBit)
{
case gl::State::DIRTY_BIT_BLEND_EQUATIONS:
{
const gl::BlendState &blendState = state.getBlendState();
if (blendState.blendEquationRGB != mCurBlendState.blendEquationRGB ||
blendState.blendEquationAlpha != mCurBlendState.blendEquationAlpha)
{
mBlendStateIsDirty = true;
}
break;
}
case gl::State::DIRTY_BIT_BLEND_FUNCS:
{
const gl::BlendState &blendState = state.getBlendState();
if (blendState.sourceBlendRGB != mCurBlendState.sourceBlendRGB ||
blendState.destBlendRGB != mCurBlendState.destBlendRGB ||
blendState.sourceBlendAlpha != mCurBlendState.sourceBlendAlpha ||
blendState.destBlendAlpha != mCurBlendState.destBlendAlpha)
{
mBlendStateIsDirty = true;
}
break;
}
case gl::State::DIRTY_BIT_BLEND_ENABLED:
if (state.getBlendState().blend != mCurBlendState.blend)
{
mBlendStateIsDirty = true;
}
break;
case gl::State::DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED:
if (state.getBlendState().sampleAlphaToCoverage !=
mCurBlendState.sampleAlphaToCoverage)
{
mBlendStateIsDirty = true;
}
break;
case gl::State::DIRTY_BIT_DITHER_ENABLED:
if (state.getBlendState().dither != mCurBlendState.dither)
{
mBlendStateIsDirty = true;
}
break;
case gl::State::DIRTY_BIT_COLOR_MASK:
{
const gl::BlendState &blendState = state.getBlendState();
if (blendState.colorMaskRed != mCurBlendState.colorMaskRed ||
blendState.colorMaskGreen != mCurBlendState.colorMaskGreen ||
blendState.colorMaskBlue != mCurBlendState.colorMaskBlue ||
blendState.colorMaskAlpha != mCurBlendState.colorMaskAlpha)
{
mBlendStateIsDirty = true;
}
break;
}
case gl::State::DIRTY_BIT_BLEND_COLOR:
if (state.getBlendColor() != mCurBlendColor)
{
mBlendStateIsDirty = true;
}
break;
default:
break;
}
}
}
gl::Error StateManager11::setBlendState(const gl::Framebuffer *framebuffer,
const gl::BlendState &blendState,
const gl::ColorF &blendColor,
unsigned int sampleMask)
{
if (mBlendStateIsDirty || sampleMask != mCurSampleMask)
{
ID3D11BlendState *dxBlendState = nullptr;
gl::Error error =
mRenderer11->getStateCache().getBlendState(framebuffer, blendState, &dxBlendState);
if (error.isError())
{
return error;
}
ASSERT(dxBlendState != nullptr);
float blendColors[4] = {0.0f};
if (blendState.sourceBlendRGB != GL_CONSTANT_ALPHA &&
blendState.sourceBlendRGB != GL_ONE_MINUS_CONSTANT_ALPHA &&
blendState.destBlendRGB != GL_CONSTANT_ALPHA &&
blendState.destBlendRGB != GL_ONE_MINUS_CONSTANT_ALPHA)
{
blendColors[0] = blendColor.red;
blendColors[1] = blendColor.green;
blendColors[2] = blendColor.blue;
blendColors[3] = blendColor.alpha;
}
else
{
blendColors[0] = blendColor.alpha;
blendColors[1] = blendColor.alpha;
blendColors[2] = blendColor.alpha;
blendColors[3] = blendColor.alpha;
}
mRenderer11->getDeviceContext()->OMSetBlendState(dxBlendState, blendColors, sampleMask);
mCurBlendState = blendState;
mCurBlendColor = blendColor;
mCurSampleMask = sampleMask;
mBlendStateIsDirty = false;
}
return gl::Error(GL_NO_ERROR);
}
} // namespace rx
//
// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// StateManager11.h: Defines a class for caching D3D11 state
#ifndef LIBANGLE_RENDERER_D3D11_STATEMANAGER11_H_
#define LIBANGLE_RENDERER_D3D11_STATEMANAGER11_H_
#include "libANGLE/angletypes.h"
#include "libANGLE/Data.h"
#include "libANGLE/State.h"
#include "libANGLE/renderer/d3d/d3d11/RenderStateCache.h"
namespace rx
{
class Renderer11;
class StateManager11 final : angle::NonCopyable
{
public:
StateManager11(Renderer11 *renderer11);
~StateManager11();
void syncState(const gl::State &state, const gl::State::DirtyBits &dirtyBits);
gl::Error setBlendState(const gl::Framebuffer *framebuffer,
const gl::BlendState &blendState,
const gl::ColorF &blendColor,
unsigned int sampleMask);
void forceSetBlendState() { mBlendStateIsDirty = true; }
private:
// Blend State
bool mBlendStateIsDirty;
// TODO(dianx) temporary representation of a dirty bit. once we move enough states in,
// try experimenting with dirty bit instead of a bool
gl::BlendState mCurBlendState;
gl::ColorF mCurBlendColor;
unsigned int mCurSampleMask;
Renderer11 *mRenderer11;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_D3D11_STATEMANAGER11_H_
\ No newline at end of file
......@@ -8,50 +8,49 @@
#include "libANGLE/renderer/d3d/d3d9/Renderer9.h"
#include <sstream>
#include <EGL/eglext.h>
#include "common/utilities.h"
#include "libANGLE/angletypes.h"
#include "libANGLE/Buffer.h"
#include "libANGLE/Display.h"
#include "libANGLE/features.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/Framebuffer.h"
#include "libANGLE/FramebufferAttachment.h"
#include "libANGLE/Program.h"
#include "libANGLE/Renderbuffer.h"
#include "libANGLE/State.h"
#include "libANGLE/Surface.h"
#include "libANGLE/Texture.h"
#include "libANGLE/angletypes.h"
#include "libANGLE/features.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/d3d/DeviceD3D.h"
#include "libANGLE/renderer/d3d/FramebufferD3D.h"
#include "libANGLE/renderer/d3d/IndexDataManager.h"
#include "libANGLE/renderer/d3d/ProgramD3D.h"
#include "libANGLE/renderer/d3d/RenderbufferD3D.h"
#include "libANGLE/renderer/d3d/ShaderD3D.h"
#include "libANGLE/renderer/d3d/SurfaceD3D.h"
#include "libANGLE/renderer/d3d/TextureD3D.h"
#include "libANGLE/renderer/d3d/TransformFeedbackD3D.h"
#include "libANGLE/renderer/d3d/d3d9/Blit9.h"
#include "libANGLE/renderer/d3d/d3d9/Buffer9.h"
#include "libANGLE/renderer/d3d/d3d9/Fence9.h"
#include "libANGLE/renderer/d3d/d3d9/formatutils9.h"
#include "libANGLE/renderer/d3d/d3d9/Framebuffer9.h"
#include "libANGLE/renderer/d3d/d3d9/Image9.h"
#include "libANGLE/renderer/d3d/d3d9/IndexBuffer9.h"
#include "libANGLE/renderer/d3d/d3d9/Query9.h"
#include "libANGLE/renderer/d3d/d3d9/renderer9_utils.h"
#include "libANGLE/renderer/d3d/d3d9/RenderTarget9.h"
#include "libANGLE/renderer/d3d/d3d9/ShaderExecutable9.h"
#include "libANGLE/renderer/d3d/d3d9/SwapChain9.h"
#include "libANGLE/renderer/d3d/d3d9/TextureStorage9.h"
#include "libANGLE/renderer/d3d/d3d9/VertexArray9.h"
#include "libANGLE/renderer/d3d/d3d9/VertexBuffer9.h"
#include "libANGLE/renderer/d3d/d3d9/renderer9_utils.h"
#include "libANGLE/renderer/d3d/d3d9/formatutils9.h"
#include "libANGLE/renderer/d3d/DeviceD3D.h"
#include "libANGLE/renderer/d3d/FramebufferD3D.h"
#include "libANGLE/renderer/d3d/IndexDataManager.h"
#include "libANGLE/renderer/d3d/ProgramD3D.h"
#include "libANGLE/renderer/d3d/RenderbufferD3D.h"
#include "libANGLE/renderer/d3d/ShaderD3D.h"
#include "libANGLE/renderer/d3d/SurfaceD3D.h"
#include "libANGLE/renderer/d3d/TextureD3D.h"
#include "libANGLE/renderer/d3d/TransformFeedbackD3D.h"
#include "libANGLE/State.h"
#include "libANGLE/Surface.h"
#include "libANGLE/Texture.h"
#include "third_party/trace_event/trace_event.h"
#include <sstream>
#include <EGL/eglext.h>
#include <EGL/eglext.h>
#if !defined(ANGLE_COMPILE_OPTIMIZATION_LEVEL)
#define ANGLE_COMPILE_OPTIMIZATION_LEVEL D3DCOMPILE_OPTIMIZATION_LEVEL3
......@@ -924,7 +923,9 @@ gl::Error Renderer9::setRasterizerState(const gl::RasterizerState &rasterState)
return gl::Error(GL_NO_ERROR);
}
gl::Error Renderer9::setBlendState(const gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::ColorF &blendColor,
gl::Error Renderer9::setBlendState(const gl::Framebuffer *framebuffer,
const gl::BlendState &blendState,
const gl::ColorF &blendColor,
unsigned int sampleMask)
{
bool blendStateChanged = mForceSetBlendState || memcmp(&blendState, &mCurBlendState, sizeof(gl::BlendState)) != 0;
......
......@@ -97,7 +97,9 @@ class Renderer9 : public RendererD3D
const std::vector<GLint> &fragmentUniformBuffers) override;
virtual gl::Error setRasterizerState(const gl::RasterizerState &rasterState);
gl::Error setBlendState(const gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::ColorF &blendColor,
gl::Error setBlendState(const gl::Framebuffer *framebuffer,
const gl::BlendState &blendState,
const gl::ColorF &blendColor,
unsigned int sampleMask) override;
virtual gl::Error setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
int stencilBackRef, bool frontFaceCCW);
......@@ -230,6 +232,11 @@ class Renderer9 : public RendererD3D
virtual gl::Error fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTargetD3D *destRenderTarget,
GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea);
void syncState(const gl::State & /*state*/, const gl::State::DirtyBits &bitmask) override
{
// TODO(dianx) implement d3d9 dirty bits
}
// D3D9-renderer specific methods
gl::Error boxFilter(IDirect3DSurface9 *source, IDirect3DSurface9 *dest);
......
......@@ -373,6 +373,8 @@
'libANGLE/renderer/d3d/d3d11/shaders/compiled/swizzleui2darrayps.h',
'libANGLE/renderer/d3d/d3d11/shaders/compiled/swizzleui2dps.h',
'libANGLE/renderer/d3d/d3d11/shaders/compiled/swizzleui3dps.h',
'libANGLE/renderer/d3d/d3d11/StateManager11.cpp',
'libANGLE/renderer/d3d/d3d11/StateManager11.h',
'libANGLE/renderer/d3d/d3d11/SwapChain11.cpp',
'libANGLE/renderer/d3d/d3d11/SwapChain11.h',
'libANGLE/renderer/d3d/d3d11/swizzle_format_info.h',
......
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