Commit b8c6521a by Alexey Knyazev Committed by Commit Bot

Reland "Move sampleAlphaToCoverage out of blendState"

This is a reland of f6e73131 Aligned BlendStateKey fields Original change's description: > Move sampleAlphaToCoverage out of blendState > > This is the second step towards exposing OES_draw_buffers_indexed (that defines independent blend state for each draw buffer). This flag is global in all graphics APIs, however D3D11 technically puts it in the blend state. > > D3D11: BlendStateKey was extended to keep existing D3D11 state caching semantics. > > D3D9: a comment was added explaining why this feature was never implemented there. > > Bug: angleproject:4394 > Change-Id: Ie6a294eeb6fcf4c868a1f1001c4f7efd61692ccd > Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2057063 > Reviewed-by: Jamie Madill <jmadill@chromium.org> > Reviewed-by: Geoff Lang <geofflang@chromium.org> > Commit-Queue: Geoff Lang <geofflang@chromium.org> Bug: angleproject:4394 Change-Id: Ia7aed863f0f9f6066daf1b02ecade3256f494062 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2066698 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 94ec1e5f
......@@ -293,6 +293,7 @@ State::State(ContextID contextIn,
mDepthClearValue(0),
mStencilClearValue(0),
mScissorTest(false),
mSampleAlphaToCoverage(false),
mSampleCoverage(false),
mSampleCoverageValue(0),
mSampleCoverageInvert(false),
......@@ -852,7 +853,7 @@ void State::setPolygonOffsetParams(GLfloat factor, GLfloat units)
void State::setSampleAlphaToCoverage(bool enabled)
{
mBlend.sampleAlphaToCoverage = enabled;
mSampleAlphaToCoverage = enabled;
mDirtyBits.set(DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED);
}
......@@ -1899,7 +1900,7 @@ void State::getBooleanv(GLenum pname, GLboolean *params) const
*params = mRasterizer.polygonOffsetFill;
break;
case GL_SAMPLE_ALPHA_TO_COVERAGE:
*params = mBlend.sampleAlphaToCoverage;
*params = mSampleAlphaToCoverage;
break;
case GL_SAMPLE_COVERAGE:
*params = mSampleCoverage;
......
......@@ -175,7 +175,7 @@ class State : angle::NonCopyable
void setPolygonOffsetParams(GLfloat factor, GLfloat units);
// Multisample coverage state manipulation
bool isSampleAlphaToCoverageEnabled() const { return mBlend.sampleAlphaToCoverage; }
bool isSampleAlphaToCoverageEnabled() const { return mSampleAlphaToCoverage; }
void setSampleAlphaToCoverage(bool enabled);
bool isSampleCoverageEnabled() const { return mSampleCoverage; }
void setSampleCoverage(bool enabled);
......@@ -808,6 +808,7 @@ class State : angle::NonCopyable
BlendState mBlend;
ColorF mBlendColor;
bool mSampleAlphaToCoverage;
bool mSampleCoverage;
GLfloat mSampleCoverageValue;
bool mSampleCoverageInvert;
......
......@@ -49,18 +49,17 @@ BlendState::BlendState()
{
memset(this, 0, sizeof(BlendState));
blend = false;
sourceBlendRGB = GL_ONE;
sourceBlendAlpha = GL_ONE;
destBlendRGB = GL_ZERO;
destBlendAlpha = GL_ZERO;
blendEquationRGB = GL_FUNC_ADD;
blendEquationAlpha = GL_FUNC_ADD;
sampleAlphaToCoverage = false;
colorMaskRed = true;
colorMaskGreen = true;
colorMaskBlue = true;
colorMaskAlpha = true;
blend = false;
sourceBlendRGB = GL_ONE;
sourceBlendAlpha = GL_ONE;
destBlendRGB = GL_ZERO;
destBlendAlpha = GL_ZERO;
blendEquationRGB = GL_FUNC_ADD;
blendEquationAlpha = GL_FUNC_ADD;
colorMaskRed = true;
colorMaskGreen = true;
colorMaskBlue = true;
colorMaskAlpha = true;
}
BlendState::BlendState(const BlendState &other)
......
......@@ -168,8 +168,6 @@ struct BlendState final
bool colorMaskGreen;
bool colorMaskBlue;
bool colorMaskAlpha;
bool sampleAlphaToCoverage;
};
bool operator==(const BlendState &a, const BlendState &b);
......
......@@ -287,14 +287,13 @@ angle::Result Clear11::ensureResourcesInitialized(const gl::Context *context)
mDepthStencilStateKey.stencilBackFunc = GL_ALWAYS;
// Initialize BlendStateKey with defaults
mBlendStateKey.blendState.blend = false;
mBlendStateKey.blendState.sourceBlendRGB = GL_ONE;
mBlendStateKey.blendState.sourceBlendAlpha = GL_ONE;
mBlendStateKey.blendState.destBlendRGB = GL_ZERO;
mBlendStateKey.blendState.destBlendAlpha = GL_ZERO;
mBlendStateKey.blendState.blendEquationRGB = GL_FUNC_ADD;
mBlendStateKey.blendState.blendEquationAlpha = GL_FUNC_ADD;
mBlendStateKey.blendState.sampleAlphaToCoverage = false;
mBlendStateKey.blendState.blend = false;
mBlendStateKey.blendState.sourceBlendRGB = GL_ONE;
mBlendStateKey.blendState.sourceBlendAlpha = GL_ONE;
mBlendStateKey.blendState.destBlendRGB = GL_ZERO;
mBlendStateKey.blendState.destBlendAlpha = GL_ZERO;
mBlendStateKey.blendState.blendEquationRGB = GL_FUNC_ADD;
mBlendStateKey.blendState.blendEquationAlpha = GL_FUNC_ADD;
mResourcesInitialized = true;
return angle::Result::Continue;
......@@ -646,7 +645,7 @@ angle::Result Clear11::clearFramebuffer(const gl::Context *context,
mBlendStateKey.blendState.colorMaskGreen = clearParams.colorMaskGreen;
mBlendStateKey.blendState.colorMaskBlue = clearParams.colorMaskBlue;
mBlendStateKey.blendState.colorMaskAlpha = clearParams.colorMaskAlpha;
mBlendStateKey.rtvMax = numRtvs;
mBlendStateKey.rtvMax = static_cast<uint16_t>(numRtvs);
memcpy(mBlendStateKey.rtvMasks, &rtvMasks[0], sizeof(mBlendStateKey.rtvMasks));
// Get BlendState
......
......@@ -45,7 +45,8 @@ void RenderStateCache::clear()
// static
d3d11::BlendStateKey RenderStateCache::GetBlendStateKey(const gl::Context *context,
Framebuffer11 *framebuffer11,
const gl::BlendState &blendState)
const gl::BlendState &blendState,
bool sampleAlphaToCoverage)
{
d3d11::BlendStateKey key;
const gl::AttachmentList &colorbuffers = framebuffer11->getColorAttachmentsForRender(context);
......@@ -53,7 +54,8 @@ d3d11::BlendStateKey RenderStateCache::GetBlendStateKey(const gl::Context *conte
gl_d3d11::ConvertColorMask(blendState.colorMaskRed, blendState.colorMaskGreen,
blendState.colorMaskBlue, blendState.colorMaskAlpha);
key.blendState = blendState;
key.blendState = blendState;
key.sampleAlphaToCoverage = sampleAlphaToCoverage ? 1 : 0;
for (size_t i = 0; i < colorbuffers.size(); i++)
{
......@@ -61,7 +63,7 @@ d3d11::BlendStateKey RenderStateCache::GetBlendStateKey(const gl::Context *conte
if (attachment)
{
key.rtvMax = static_cast<uint32_t>(i) + 1;
key.rtvMax = static_cast<uint16_t>(i) + 1;
key.rtvMasks[i] =
(gl_d3d11::GetColorMask(*attachment->getFormat().info)) & blendStateMask;
}
......@@ -89,7 +91,7 @@ angle::Result RenderStateCache::getBlendState(const gl::Context *context,
D3D11_RENDER_TARGET_BLEND_DESC &rtDesc0 = blendDesc.RenderTarget[0];
const gl::BlendState &blendState = key.blendState;
blendDesc.AlphaToCoverageEnable = blendState.sampleAlphaToCoverage;
blendDesc.AlphaToCoverageEnable = key.sampleAlphaToCoverage != 0 ? TRUE : FALSE;
blendDesc.IndependentBlendEnable = key.rtvMax > 1 ? TRUE : FALSE;
rtDesc0 = {};
......
......@@ -69,7 +69,8 @@ class RenderStateCache : angle::NonCopyable
static d3d11::BlendStateKey GetBlendStateKey(const gl::Context *context,
Framebuffer11 *framebuffer11,
const gl::BlendState &blendState);
const gl::BlendState &blendState,
bool sampleAlphaToCoverage);
angle::Result getBlendState(const gl::Context *context,
Renderer11 *renderer,
const d3d11::BlendStateKey &key,
......
......@@ -665,6 +665,7 @@ angle::Result ShaderConstants11::updateBuffer(const gl::Context *context,
StateManager11::StateManager11(Renderer11 *renderer)
: mRenderer(renderer),
mInternalDirtyBits(),
mCurSampleAlphaToCoverage(false),
mCurBlendColor(0, 0, 0, 0),
mCurSampleMask(0),
mCurStencilRef(0),
......@@ -699,18 +700,17 @@ StateManager11::StateManager11(Renderer11 *renderer)
mVertexArray11(nullptr),
mFramebuffer11(nullptr)
{
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.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;
mCurDepthStencilState.depthTest = false;
mCurDepthStencilState.depthFunc = GL_LESS;
......@@ -986,8 +986,7 @@ void StateManager11::syncState(const gl::Context *context, const gl::State::Dirt
}
break;
case gl::State::DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED:
if (state.getBlendState().sampleAlphaToCoverage !=
mCurBlendState.sampleAlphaToCoverage)
if (state.isSampleAlphaToCoverageEnabled() != mCurSampleAlphaToCoverage)
{
mInternalDirtyBits.set(DIRTY_BIT_BLEND_STATE);
}
......@@ -1232,11 +1231,12 @@ void StateManager11::handleMultiviewDrawFramebufferChange(const gl::Context *con
angle::Result StateManager11::syncBlendState(const gl::Context *context,
const gl::BlendState &blendState,
const gl::ColorF &blendColor,
unsigned int sampleMask)
unsigned int sampleMask,
bool sampleAlphaToCoverage)
{
const d3d11::BlendState *dxBlendState = nullptr;
const d3d11::BlendStateKey &key =
RenderStateCache::GetBlendStateKey(context, mFramebuffer11, blendState);
const d3d11::BlendStateKey &key = RenderStateCache::GetBlendStateKey(
context, mFramebuffer11, blendState, sampleAlphaToCoverage);
ANGLE_TRY(mRenderer->getBlendState(context, key, &dxBlendState));
......@@ -1263,9 +1263,10 @@ angle::Result StateManager11::syncBlendState(const gl::Context *context,
mRenderer->getDeviceContext()->OMSetBlendState(dxBlendState->get(), blendColors, sampleMask);
mCurBlendState = blendState;
mCurBlendColor = blendColor;
mCurSampleMask = sampleMask;
mCurBlendState = blendState;
mCurBlendColor = blendColor;
mCurSampleMask = sampleMask;
mCurSampleAlphaToCoverage = sampleAlphaToCoverage;
return angle::Result::Continue;
}
......@@ -2248,7 +2249,7 @@ angle::Result StateManager11::updateState(const gl::Context *context,
break;
case DIRTY_BIT_BLEND_STATE:
ANGLE_TRY(syncBlendState(context, glState.getBlendState(), glState.getBlendColor(),
sampleMask));
sampleMask, glState.isSampleAlphaToCoverageEnabled()));
break;
case DIRTY_BIT_DEPTH_STENCIL_STATE:
ANGLE_TRY(syncDepthStencilState(context));
......
......@@ -315,7 +315,8 @@ class StateManager11 final : angle::NonCopyable
angle::Result syncBlendState(const gl::Context *context,
const gl::BlendState &blendState,
const gl::ColorF &blendColor,
unsigned int sampleMask);
unsigned int sampleMask,
bool sampleAlphaToCoverage);
angle::Result syncDepthStencilState(const gl::Context *context);
......@@ -461,6 +462,8 @@ class StateManager11 final : angle::NonCopyable
DirtyBits mGraphicsDirtyBitsMask;
DirtyBits mComputeDirtyBitsMask;
bool mCurSampleAlphaToCoverage;
// Blend State
gl::BlendState mCurBlendState;
gl::ColorF mCurBlendColor;
......
......@@ -149,10 +149,11 @@ struct BlendStateKey final
gl::BlendState blendState;
// An int so struct size rounds nicely.
uint32_t rtvMax;
uint8_t rtvMasks[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
// Use two 16-bit ints to round the struct nicely.
uint16_t rtvMax;
uint16_t sampleAlphaToCoverage;
};
bool operator==(const BlendStateKey &a, const BlendStateKey &b);
......
......@@ -19,6 +19,7 @@ namespace rx
StateManager9::StateManager9(Renderer9 *renderer9)
: mUsingZeroColorMaskWorkaround(false),
mCurSampleAlphaToCoverage(false),
mCurBlendState(),
mCurBlendColor(0, 0, 0, 0),
mCurSampleMask(0),
......@@ -174,8 +175,7 @@ void StateManager9::syncState(const gl::State &state, const gl::State::DirtyBits
break;
}
case gl::State::DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED:
if (state.getBlendState().sampleAlphaToCoverage !=
mCurBlendState.sampleAlphaToCoverage)
if (state.isSampleAlphaToCoverageEnabled() != mCurSampleAlphaToCoverage)
{
mDirtyBits.set(DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE);
}
......@@ -354,7 +354,7 @@ void StateManager9::setBlendDepthRasterStates(const gl::State &glState, unsigned
setBlendFuncsEquations(blendState);
break;
case DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE:
setSampleAlphaToCoverage(blendState.sampleAlphaToCoverage);
setSampleAlphaToCoverage(glState.isSampleAlphaToCoverageEnabled());
break;
case DIRTY_BIT_COLOR_MASK:
setColorMask(framebuffer, blendState.colorMaskRed, blendState.colorMaskBlue,
......@@ -692,7 +692,8 @@ void StateManager9::setSampleAlphaToCoverage(bool enabled)
{
if (enabled)
{
UNREACHABLE();
// D3D9 support for alpha-to-coverage is vendor-specific.
UNIMPLEMENTED();
}
}
......
......@@ -159,6 +159,8 @@ class StateManager9 final : angle::NonCopyable
bool mUsingZeroColorMaskWorkaround;
bool mCurSampleAlphaToCoverage;
// Currently applied blend state
gl::BlendState mCurBlendState;
gl::ColorF mCurBlendColor;
......
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