Commit 6ae40ea5 by Dian Xiang

Using dirty bits notification for D3D9 depth stencil state

BUG=angleproject:1249 This is a continuation of the D3D dirty bit refactor for D3D9 for performance enhancements Change-Id: I8690d47999b73483c47f4994dc46cd97f4ced63d Reviewed-on: https://chromium-review.googlesource.com/316449 Tryjob-Request: Dian Xiang <dianx@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarDian Xiang <dianx@google.com>
parent c660ba8e
...@@ -913,29 +913,26 @@ gl::Error Renderer9::updateState(const gl::Data &data, GLenum drawMode) ...@@ -913,29 +913,26 @@ gl::Error Renderer9::updateState(const gl::Data &data, GLenum drawMode)
// Setting scissors state // Setting scissors state
setScissorRectangle(data.state->getScissor(), data.state->isScissorTestEnabled()); setScissorRectangle(data.state->getScissor(), data.state->isScissorTestEnabled());
// Setting rasterizer state // Setting blend, depth stencil, and rasterizer states
int samples = framebufferObject->getSamples(data); int samples = framebufferObject->getSamples(data);
gl::RasterizerState rasterizer = data.state->getRasterizerState(); gl::RasterizerState rasterizer = data.state->getRasterizerState();
rasterizer.pointDrawMode = (drawMode == GL_POINTS); rasterizer.pointDrawMode = (drawMode == GL_POINTS);
rasterizer.multiSample = (samples != 0); rasterizer.multiSample = (samples != 0);
unsigned int mask = GetBlendSampleMask(data, samples); unsigned int mask = GetBlendSampleMask(data, samples);
error = setBlendAndRasterizerState(data, mask); error = setBlendDepthRasterStates(data, mask);
if (error.isError()) if (error.isError())
{ {
return error; return error;
} }
// Setting depth stencil state
error = setDepthStencilState(*data.state);
mStateManager.resetDirtyBits(); mStateManager.resetDirtyBits();
return error; return error;
} }
gl::Error Renderer9::setBlendAndRasterizerState(const gl::Data &glData, GLenum drawMode) gl::Error Renderer9::setBlendDepthRasterStates(const gl::Data &glData, GLenum drawMode)
{ {
int samples = glData.state->getDrawFramebuffer()->getSamples(glData); int samples = glData.state->getDrawFramebuffer()->getSamples(glData);
gl::RasterizerState rasterizer = glData.state->getRasterizerState(); gl::RasterizerState rasterizer = glData.state->getRasterizerState();
...@@ -943,107 +940,7 @@ gl::Error Renderer9::setBlendAndRasterizerState(const gl::Data &glData, GLenum d ...@@ -943,107 +940,7 @@ gl::Error Renderer9::setBlendAndRasterizerState(const gl::Data &glData, GLenum d
rasterizer.multiSample = (samples != 0); rasterizer.multiSample = (samples != 0);
unsigned int mask = GetBlendSampleMask(glData, samples); unsigned int mask = GetBlendSampleMask(glData, samples);
return mStateManager.setBlendAndRasterizerState(*glData.state, mask); return mStateManager.setBlendDepthRasterStates(*glData.state, mask);
}
gl::Error Renderer9::setDepthStencilState(const gl::State &glState)
{
const auto &depthStencilState = glState.getDepthStencilState();
int stencilRef = glState.getStencilRef();
int stencilBackRef = glState.getStencilBackRef();
bool frontFaceCCW = (glState.getRasterizerState().frontFace == GL_CCW);
bool depthStencilStateChanged = mForceSetDepthStencilState ||
memcmp(&depthStencilState, &mCurDepthStencilState, sizeof(gl::DepthStencilState)) != 0;
bool stencilRefChanged = mForceSetDepthStencilState || stencilRef != mCurStencilRef ||
stencilBackRef != mCurStencilBackRef;
bool frontFaceCCWChanged = mForceSetDepthStencilState || frontFaceCCW != mCurFrontFaceCCW;
if (depthStencilStateChanged)
{
if (depthStencilState.depthTest)
{
mDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
mDevice->SetRenderState(D3DRS_ZFUNC, gl_d3d9::ConvertComparison(depthStencilState.depthFunc));
}
else
{
mDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
}
mCurDepthStencilState = depthStencilState;
}
if (depthStencilStateChanged || stencilRefChanged || frontFaceCCWChanged)
{
if (depthStencilState.stencilTest && mCurStencilSize > 0)
{
mDevice->SetRenderState(D3DRS_STENCILENABLE, TRUE);
mDevice->SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, TRUE);
// FIXME: Unsupported by D3D9
const D3DRENDERSTATETYPE D3DRS_CCW_STENCILREF = D3DRS_STENCILREF;
const D3DRENDERSTATETYPE D3DRS_CCW_STENCILMASK = D3DRS_STENCILMASK;
const D3DRENDERSTATETYPE D3DRS_CCW_STENCILWRITEMASK = D3DRS_STENCILWRITEMASK;
// get the maximum size of the stencil ref
unsigned int maxStencil = (1 << mCurStencilSize) - 1;
ASSERT((depthStencilState.stencilWritemask & maxStencil) ==
(depthStencilState.stencilBackWritemask & maxStencil));
ASSERT(stencilRef == stencilBackRef);
ASSERT((depthStencilState.stencilMask & maxStencil) ==
(depthStencilState.stencilBackMask & maxStencil));
mDevice->SetRenderState(frontFaceCCW ? D3DRS_STENCILWRITEMASK : D3DRS_CCW_STENCILWRITEMASK,
depthStencilState.stencilWritemask);
mDevice->SetRenderState(frontFaceCCW ? D3DRS_STENCILFUNC : D3DRS_CCW_STENCILFUNC,
gl_d3d9::ConvertComparison(depthStencilState.stencilFunc));
mDevice->SetRenderState(frontFaceCCW ? D3DRS_STENCILREF : D3DRS_CCW_STENCILREF,
(stencilRef < (int)maxStencil) ? stencilRef : maxStencil);
mDevice->SetRenderState(frontFaceCCW ? D3DRS_STENCILMASK : D3DRS_CCW_STENCILMASK,
depthStencilState.stencilMask);
mDevice->SetRenderState(frontFaceCCW ? D3DRS_STENCILFAIL : D3DRS_CCW_STENCILFAIL,
gl_d3d9::ConvertStencilOp(depthStencilState.stencilFail));
mDevice->SetRenderState(frontFaceCCW ? D3DRS_STENCILZFAIL : D3DRS_CCW_STENCILZFAIL,
gl_d3d9::ConvertStencilOp(depthStencilState.stencilPassDepthFail));
mDevice->SetRenderState(frontFaceCCW ? D3DRS_STENCILPASS : D3DRS_CCW_STENCILPASS,
gl_d3d9::ConvertStencilOp(depthStencilState.stencilPassDepthPass));
mDevice->SetRenderState(!frontFaceCCW ? D3DRS_STENCILWRITEMASK : D3DRS_CCW_STENCILWRITEMASK,
depthStencilState.stencilBackWritemask);
mDevice->SetRenderState(!frontFaceCCW ? D3DRS_STENCILFUNC : D3DRS_CCW_STENCILFUNC,
gl_d3d9::ConvertComparison(depthStencilState.stencilBackFunc));
mDevice->SetRenderState(!frontFaceCCW ? D3DRS_STENCILREF : D3DRS_CCW_STENCILREF,
(stencilBackRef < (int)maxStencil) ? stencilBackRef : maxStencil);
mDevice->SetRenderState(!frontFaceCCW ? D3DRS_STENCILMASK : D3DRS_CCW_STENCILMASK,
depthStencilState.stencilBackMask);
mDevice->SetRenderState(!frontFaceCCW ? D3DRS_STENCILFAIL : D3DRS_CCW_STENCILFAIL,
gl_d3d9::ConvertStencilOp(depthStencilState.stencilBackFail));
mDevice->SetRenderState(!frontFaceCCW ? D3DRS_STENCILZFAIL : D3DRS_CCW_STENCILZFAIL,
gl_d3d9::ConvertStencilOp(depthStencilState.stencilBackPassDepthFail));
mDevice->SetRenderState(!frontFaceCCW ? D3DRS_STENCILPASS : D3DRS_CCW_STENCILPASS,
gl_d3d9::ConvertStencilOp(depthStencilState.stencilBackPassDepthPass));
}
else
{
mDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE);
}
mDevice->SetRenderState(D3DRS_ZWRITEENABLE, depthStencilState.depthMask ? TRUE : FALSE);
mCurStencilRef = stencilRef;
mCurStencilBackRef = stencilBackRef;
mCurFrontFaceCCW = frontFaceCCW;
}
mForceSetDepthStencilState = false;
return gl::Error(GL_NO_ERROR);
} }
void Renderer9::setScissorRectangle(const gl::Rectangle &scissor, bool enabled) void Renderer9::setScissorRectangle(const gl::Rectangle &scissor, bool enabled)
...@@ -1334,11 +1231,7 @@ gl::Error Renderer9::applyRenderTarget(const gl::FramebufferAttachment *colorAtt ...@@ -1334,11 +1231,7 @@ gl::Error Renderer9::applyRenderTarget(const gl::FramebufferAttachment *colorAtt
mStateManager.updateDepthSizeIfChanged(mDepthStencilInitialized, depthSize); mStateManager.updateDepthSizeIfChanged(mDepthStencilInitialized, depthSize);
if (!mDepthStencilInitialized || stencilSize != mCurStencilSize) mStateManager.updateStencilSizeIfChanged(mDepthStencilInitialized, stencilSize);
{
mCurStencilSize = stencilSize;
mForceSetDepthStencilState = true;
}
mAppliedDepthStencilSerial = depthStencilSerial; mAppliedDepthStencilSerial = depthStencilSerial;
mDepthStencilInitialized = true; mDepthStencilInitialized = true;
...@@ -2192,10 +2085,10 @@ void Renderer9::markAllStateDirty() ...@@ -2192,10 +2085,10 @@ void Renderer9::markAllStateDirty()
mDepthStencilInitialized = false; mDepthStencilInitialized = false;
mRenderTargetDescInitialized = false; mRenderTargetDescInitialized = false;
mForceSetDepthStencilState = true;
mForceSetScissor = true; mForceSetScissor = true;
mForceSetViewport = true; mForceSetViewport = true;
mStateManager.forceSetRasterState(); mStateManager.forceSetRasterState();
mStateManager.forceSetDepthStencilState();
mStateManager.forceSetBlendState(); mStateManager.forceSetBlendState();
ASSERT(mCurVertexSamplerStates.size() == mCurVertexTextures.size()); ASSERT(mCurVertexSamplerStates.size() == mCurVertexTextures.size());
......
...@@ -275,8 +275,7 @@ class Renderer9 : public RendererD3D ...@@ -275,8 +275,7 @@ class Renderer9 : public RendererD3D
WorkaroundsD3D generateWorkarounds() const override; WorkaroundsD3D generateWorkarounds() const override;
gl::Error setBlendAndRasterizerState(const gl::Data &glData, GLenum drawMode); gl::Error setBlendDepthRasterStates(const gl::Data &glData, GLenum drawMode);
gl::Error setDepthStencilState(const gl::State &glState);
void release(); void release();
...@@ -332,7 +331,6 @@ class Renderer9 : public RendererD3D ...@@ -332,7 +331,6 @@ class Renderer9 : public RendererD3D
unsigned int mAppliedDepthStencilSerial; unsigned int mAppliedDepthStencilSerial;
bool mDepthStencilInitialized; bool mDepthStencilInitialized;
bool mRenderTargetDescInitialized; bool mRenderTargetDescInitialized;
unsigned int mCurStencilSize;
struct RenderTargetDesc struct RenderTargetDesc
{ {
...@@ -346,13 +344,6 @@ class Renderer9 : public RendererD3D ...@@ -346,13 +344,6 @@ class Renderer9 : public RendererD3D
StateManager9 mStateManager; StateManager9 mStateManager;
// previously set render states
bool mForceSetDepthStencilState;
gl::DepthStencilState mCurDepthStencilState;
int mCurStencilRef;
int mCurStencilBackRef;
bool mCurFrontFaceCCW;
bool mForceSetScissor; bool mForceSetScissor;
gl::Rectangle mCurScissor; gl::Rectangle mCurScissor;
bool mScissorEnabled; bool mScissorEnabled;
......
...@@ -26,29 +26,29 @@ class StateManager9 final : angle::NonCopyable ...@@ -26,29 +26,29 @@ class StateManager9 final : angle::NonCopyable
void syncState(const gl::State &state, const gl::State::DirtyBits &dirtyBits); void syncState(const gl::State &state, const gl::State::DirtyBits &dirtyBits);
gl::Error setBlendAndRasterizerState(const gl::State &glState, unsigned int sampleMask); gl::Error setBlendDepthRasterStates(const gl::State &glState, unsigned int sampleMask);
void forceSetBlendState(); void forceSetBlendState();
void forceSetRasterState(); void forceSetRasterState();
void forceSetDepthStencilState();
void updateDepthSizeIfChanged(bool depthStencilInitialized, unsigned int depthSize); void updateDepthSizeIfChanged(bool depthStencilInitialized, unsigned int depthSize);
void updateStencilSizeIfChanged(bool depthStencilInitialized, unsigned int stencilSize);
void resetDirtyBits() { mDirtyBits.reset(); } void resetDirtyBits() { mDirtyBits.reset(); }
private: private:
// Blend state functions
void setBlendEnabled(bool enabled); void setBlendEnabled(bool enabled);
void setBlendColor(const gl::BlendState &blendState, const gl::ColorF &blendColor); void setBlendColor(const gl::BlendState &blendState, const gl::ColorF &blendColor);
void setBlendFuncsEquations(const gl::BlendState &blendState); void setBlendFuncsEquations(const gl::BlendState &blendState);
void setColorMask(const gl::Framebuffer *framebuffer, void setColorMask(const gl::Framebuffer *framebuffer,
bool red, bool red,
bool blue, bool blue,
bool green, bool green,
bool alpha); bool alpha);
void setSampleAlphaToCoverage(bool enabled); void setSampleAlphaToCoverage(bool enabled);
void setDither(bool dither); void setDither(bool dither);
void setSampleMask(unsigned int sampleMask); void setSampleMask(unsigned int sampleMask);
// Current raster state functions // Current raster state functions
...@@ -57,8 +57,34 @@ class StateManager9 final : angle::NonCopyable ...@@ -57,8 +57,34 @@ class StateManager9 final : angle::NonCopyable
GLfloat polygonOffsetFactor, GLfloat polygonOffsetFactor,
GLfloat polygonOffsetUnits); GLfloat polygonOffsetUnits);
// Depth stencil state functions
void setStencilOpsFront(GLenum stencilFail,
GLenum stencilPassDepthFail,
GLenum stencilPassDepthPass,
bool frontFaceCCW);
void setStencilOpsBack(GLenum stencilBackFail,
GLenum stencilBackPassDepthFail,
GLenum stencilBackPassDepthPass,
bool frontFaceCCW);
void setStencilBackWriteMask(GLuint stencilBackWriteMask, bool frontFaceCCW);
void setDepthFunc(bool depthTest, GLenum depthFunc);
void setStencilTestEnabled(bool enabled);
void setDepthMask(bool depthMask);
void setStencilFuncsFront(GLenum stencilFunc,
GLuint stencilMask,
GLint stencilRef,
bool frontFaceCCW,
unsigned int maxStencil);
void setStencilFuncsBack(GLenum stencilBackFunc,
GLuint stencilBackMask,
GLint stencilBackRef,
bool frontFaceCCW,
unsigned int maxStencil);
void setStencilWriteMask(GLuint stencilWriteMask, bool frontFaceCCW);
enum DirtyBitType enum DirtyBitType
{ {
// Blend dirty bits
DIRTY_BIT_BLEND_ENABLED, DIRTY_BIT_BLEND_ENABLED,
DIRTY_BIT_BLEND_COLOR, DIRTY_BIT_BLEND_COLOR,
DIRTY_BIT_BLEND_FUNCS_EQUATIONS, DIRTY_BIT_BLEND_FUNCS_EQUATIONS,
...@@ -67,9 +93,21 @@ class StateManager9 final : angle::NonCopyable ...@@ -67,9 +93,21 @@ class StateManager9 final : angle::NonCopyable
DIRTY_BIT_DITHER, DIRTY_BIT_DITHER,
DIRTY_BIT_SAMPLE_MASK, DIRTY_BIT_SAMPLE_MASK,
// Rasterizer dirty bits
DIRTY_BIT_CULL_MODE, DIRTY_BIT_CULL_MODE,
DIRTY_BIT_DEPTH_BIAS, DIRTY_BIT_DEPTH_BIAS,
// Depth stencil dirty bits
DIRTY_BIT_STENCIL_DEPTH_MASK,
DIRTY_BIT_STENCIL_DEPTH_FUNC,
DIRTY_BIT_STENCIL_TEST_ENABLED,
DIRTY_BIT_STENCIL_FUNCS_FRONT,
DIRTY_BIT_STENCIL_FUNCS_BACK,
DIRTY_BIT_STENCIL_WRITEMASK_FRONT,
DIRTY_BIT_STENCIL_WRITEMASK_BACK,
DIRTY_BIT_STENCIL_OPS_FRONT,
DIRTY_BIT_STENCIL_OPS_BACK,
DIRTY_BIT_MAX DIRTY_BIT_MAX
}; };
...@@ -86,6 +124,19 @@ class StateManager9 final : angle::NonCopyable ...@@ -86,6 +124,19 @@ class StateManager9 final : angle::NonCopyable
unsigned int mCurDepthSize; unsigned int mCurDepthSize;
DirtyBits mRasterizerStateDirtyBits; DirtyBits mRasterizerStateDirtyBits;
// Currently applied depth stencil state
gl::DepthStencilState mCurDepthStencilState;
int mCurStencilRef;
int mCurStencilBackRef;
bool mCurFrontFaceCCW;
unsigned int mCurStencilSize;
DirtyBits mDepthStencilStateDirtyBits;
// FIXME: Unsupported by D3D9
static const D3DRENDERSTATETYPE D3DRS_CCW_STENCILREF = D3DRS_STENCILREF;
static const D3DRENDERSTATETYPE D3DRS_CCW_STENCILMASK = D3DRS_STENCILMASK;
static const D3DRENDERSTATETYPE D3DRS_CCW_STENCILWRITEMASK = D3DRS_STENCILWRITEMASK;
Renderer9 *mRenderer9; Renderer9 *mRenderer9;
DirtyBits mDirtyBits; DirtyBits mDirtyBits;
}; };
......
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