Commit f6e73131 by Alexey Knyazev Committed by Commit Bot

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/+/2057063Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent f87fac56
...@@ -293,6 +293,7 @@ State::State(ContextID contextIn, ...@@ -293,6 +293,7 @@ State::State(ContextID contextIn,
mDepthClearValue(0), mDepthClearValue(0),
mStencilClearValue(0), mStencilClearValue(0),
mScissorTest(false), mScissorTest(false),
mSampleAlphaToCoverage(false),
mSampleCoverage(false), mSampleCoverage(false),
mSampleCoverageValue(0), mSampleCoverageValue(0),
mSampleCoverageInvert(false), mSampleCoverageInvert(false),
...@@ -838,7 +839,7 @@ void State::setPolygonOffsetParams(GLfloat factor, GLfloat units) ...@@ -838,7 +839,7 @@ void State::setPolygonOffsetParams(GLfloat factor, GLfloat units)
void State::setSampleAlphaToCoverage(bool enabled) void State::setSampleAlphaToCoverage(bool enabled)
{ {
mBlend.sampleAlphaToCoverage = enabled; mSampleAlphaToCoverage = enabled;
mDirtyBits.set(DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED); mDirtyBits.set(DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED);
} }
...@@ -1885,7 +1886,7 @@ void State::getBooleanv(GLenum pname, GLboolean *params) ...@@ -1885,7 +1886,7 @@ void State::getBooleanv(GLenum pname, GLboolean *params)
*params = mRasterizer.polygonOffsetFill; *params = mRasterizer.polygonOffsetFill;
break; break;
case GL_SAMPLE_ALPHA_TO_COVERAGE: case GL_SAMPLE_ALPHA_TO_COVERAGE:
*params = mBlend.sampleAlphaToCoverage; *params = mSampleAlphaToCoverage;
break; break;
case GL_SAMPLE_COVERAGE: case GL_SAMPLE_COVERAGE:
*params = mSampleCoverage; *params = mSampleCoverage;
......
...@@ -175,7 +175,7 @@ class State : angle::NonCopyable ...@@ -175,7 +175,7 @@ class State : angle::NonCopyable
void setPolygonOffsetParams(GLfloat factor, GLfloat units); void setPolygonOffsetParams(GLfloat factor, GLfloat units);
// Multisample coverage state manipulation // Multisample coverage state manipulation
bool isSampleAlphaToCoverageEnabled() const { return mBlend.sampleAlphaToCoverage; } bool isSampleAlphaToCoverageEnabled() const { return mSampleAlphaToCoverage; }
void setSampleAlphaToCoverage(bool enabled); void setSampleAlphaToCoverage(bool enabled);
bool isSampleCoverageEnabled() const { return mSampleCoverage; } bool isSampleCoverageEnabled() const { return mSampleCoverage; }
void setSampleCoverage(bool enabled); void setSampleCoverage(bool enabled);
...@@ -808,6 +808,7 @@ class State : angle::NonCopyable ...@@ -808,6 +808,7 @@ class State : angle::NonCopyable
BlendState mBlend; BlendState mBlend;
ColorF mBlendColor; ColorF mBlendColor;
bool mSampleAlphaToCoverage;
bool mSampleCoverage; bool mSampleCoverage;
GLfloat mSampleCoverageValue; GLfloat mSampleCoverageValue;
bool mSampleCoverageInvert; bool mSampleCoverageInvert;
......
...@@ -49,18 +49,17 @@ BlendState::BlendState() ...@@ -49,18 +49,17 @@ BlendState::BlendState()
{ {
memset(this, 0, sizeof(BlendState)); memset(this, 0, sizeof(BlendState));
blend = false; blend = false;
sourceBlendRGB = GL_ONE; sourceBlendRGB = GL_ONE;
sourceBlendAlpha = GL_ONE; sourceBlendAlpha = GL_ONE;
destBlendRGB = GL_ZERO; destBlendRGB = GL_ZERO;
destBlendAlpha = GL_ZERO; destBlendAlpha = GL_ZERO;
blendEquationRGB = GL_FUNC_ADD; blendEquationRGB = GL_FUNC_ADD;
blendEquationAlpha = GL_FUNC_ADD; blendEquationAlpha = GL_FUNC_ADD;
sampleAlphaToCoverage = false; colorMaskRed = true;
colorMaskRed = true; colorMaskGreen = true;
colorMaskGreen = true; colorMaskBlue = true;
colorMaskBlue = true; colorMaskAlpha = true;
colorMaskAlpha = true;
} }
BlendState::BlendState(const BlendState &other) BlendState::BlendState(const BlendState &other)
......
...@@ -168,8 +168,6 @@ struct BlendState final ...@@ -168,8 +168,6 @@ struct BlendState final
bool colorMaskGreen; bool colorMaskGreen;
bool colorMaskBlue; bool colorMaskBlue;
bool colorMaskAlpha; bool colorMaskAlpha;
bool sampleAlphaToCoverage;
}; };
bool operator==(const BlendState &a, const BlendState &b); bool operator==(const BlendState &a, const BlendState &b);
......
...@@ -287,14 +287,13 @@ angle::Result Clear11::ensureResourcesInitialized(const gl::Context *context) ...@@ -287,14 +287,13 @@ angle::Result Clear11::ensureResourcesInitialized(const gl::Context *context)
mDepthStencilStateKey.stencilBackFunc = GL_ALWAYS; mDepthStencilStateKey.stencilBackFunc = GL_ALWAYS;
// Initialize BlendStateKey with defaults // Initialize BlendStateKey with defaults
mBlendStateKey.blendState.blend = false; mBlendStateKey.blendState.blend = false;
mBlendStateKey.blendState.sourceBlendRGB = GL_ONE; mBlendStateKey.blendState.sourceBlendRGB = GL_ONE;
mBlendStateKey.blendState.sourceBlendAlpha = GL_ONE; mBlendStateKey.blendState.sourceBlendAlpha = GL_ONE;
mBlendStateKey.blendState.destBlendRGB = GL_ZERO; mBlendStateKey.blendState.destBlendRGB = GL_ZERO;
mBlendStateKey.blendState.destBlendAlpha = GL_ZERO; mBlendStateKey.blendState.destBlendAlpha = GL_ZERO;
mBlendStateKey.blendState.blendEquationRGB = GL_FUNC_ADD; mBlendStateKey.blendState.blendEquationRGB = GL_FUNC_ADD;
mBlendStateKey.blendState.blendEquationAlpha = GL_FUNC_ADD; mBlendStateKey.blendState.blendEquationAlpha = GL_FUNC_ADD;
mBlendStateKey.blendState.sampleAlphaToCoverage = false;
mResourcesInitialized = true; mResourcesInitialized = true;
return angle::Result::Continue; return angle::Result::Continue;
...@@ -646,7 +645,7 @@ angle::Result Clear11::clearFramebuffer(const gl::Context *context, ...@@ -646,7 +645,7 @@ angle::Result Clear11::clearFramebuffer(const gl::Context *context,
mBlendStateKey.blendState.colorMaskGreen = clearParams.colorMaskGreen; mBlendStateKey.blendState.colorMaskGreen = clearParams.colorMaskGreen;
mBlendStateKey.blendState.colorMaskBlue = clearParams.colorMaskBlue; mBlendStateKey.blendState.colorMaskBlue = clearParams.colorMaskBlue;
mBlendStateKey.blendState.colorMaskAlpha = clearParams.colorMaskAlpha; mBlendStateKey.blendState.colorMaskAlpha = clearParams.colorMaskAlpha;
mBlendStateKey.rtvMax = numRtvs; mBlendStateKey.rtvMax = static_cast<uint8_t>(numRtvs);
memcpy(mBlendStateKey.rtvMasks, &rtvMasks[0], sizeof(mBlendStateKey.rtvMasks)); memcpy(mBlendStateKey.rtvMasks, &rtvMasks[0], sizeof(mBlendStateKey.rtvMasks));
// Get BlendState // Get BlendState
......
...@@ -45,7 +45,8 @@ void RenderStateCache::clear() ...@@ -45,7 +45,8 @@ void RenderStateCache::clear()
// static // static
d3d11::BlendStateKey RenderStateCache::GetBlendStateKey(const gl::Context *context, d3d11::BlendStateKey RenderStateCache::GetBlendStateKey(const gl::Context *context,
Framebuffer11 *framebuffer11, Framebuffer11 *framebuffer11,
const gl::BlendState &blendState) const gl::BlendState &blendState,
bool sampleAlphaToCoverage)
{ {
d3d11::BlendStateKey key; d3d11::BlendStateKey key;
const gl::AttachmentList &colorbuffers = framebuffer11->getColorAttachmentsForRender(context); const gl::AttachmentList &colorbuffers = framebuffer11->getColorAttachmentsForRender(context);
...@@ -53,7 +54,8 @@ d3d11::BlendStateKey RenderStateCache::GetBlendStateKey(const gl::Context *conte ...@@ -53,7 +54,8 @@ d3d11::BlendStateKey RenderStateCache::GetBlendStateKey(const gl::Context *conte
gl_d3d11::ConvertColorMask(blendState.colorMaskRed, blendState.colorMaskGreen, gl_d3d11::ConvertColorMask(blendState.colorMaskRed, blendState.colorMaskGreen,
blendState.colorMaskBlue, blendState.colorMaskAlpha); blendState.colorMaskBlue, blendState.colorMaskAlpha);
key.blendState = blendState; key.blendState = blendState;
key.sampleAlphaToCoverage = sampleAlphaToCoverage;
for (size_t i = 0; i < colorbuffers.size(); i++) for (size_t i = 0; i < colorbuffers.size(); i++)
{ {
...@@ -61,7 +63,7 @@ d3d11::BlendStateKey RenderStateCache::GetBlendStateKey(const gl::Context *conte ...@@ -61,7 +63,7 @@ d3d11::BlendStateKey RenderStateCache::GetBlendStateKey(const gl::Context *conte
if (attachment) if (attachment)
{ {
key.rtvMax = static_cast<uint32_t>(i) + 1; key.rtvMax = static_cast<uint8_t>(i) + 1;
key.rtvMasks[i] = key.rtvMasks[i] =
(gl_d3d11::GetColorMask(*attachment->getFormat().info)) & blendStateMask; (gl_d3d11::GetColorMask(*attachment->getFormat().info)) & blendStateMask;
} }
...@@ -89,7 +91,7 @@ angle::Result RenderStateCache::getBlendState(const gl::Context *context, ...@@ -89,7 +91,7 @@ angle::Result RenderStateCache::getBlendState(const gl::Context *context,
D3D11_RENDER_TARGET_BLEND_DESC &rtDesc0 = blendDesc.RenderTarget[0]; D3D11_RENDER_TARGET_BLEND_DESC &rtDesc0 = blendDesc.RenderTarget[0];
const gl::BlendState &blendState = key.blendState; const gl::BlendState &blendState = key.blendState;
blendDesc.AlphaToCoverageEnable = blendState.sampleAlphaToCoverage; blendDesc.AlphaToCoverageEnable = key.sampleAlphaToCoverage;
blendDesc.IndependentBlendEnable = key.rtvMax > 1 ? TRUE : FALSE; blendDesc.IndependentBlendEnable = key.rtvMax > 1 ? TRUE : FALSE;
rtDesc0 = {}; rtDesc0 = {};
......
...@@ -69,7 +69,8 @@ class RenderStateCache : angle::NonCopyable ...@@ -69,7 +69,8 @@ class RenderStateCache : angle::NonCopyable
static d3d11::BlendStateKey GetBlendStateKey(const gl::Context *context, static d3d11::BlendStateKey GetBlendStateKey(const gl::Context *context,
Framebuffer11 *framebuffer11, Framebuffer11 *framebuffer11,
const gl::BlendState &blendState); const gl::BlendState &blendState,
bool sampleAlphaToCoverage);
angle::Result getBlendState(const gl::Context *context, angle::Result getBlendState(const gl::Context *context,
Renderer11 *renderer, Renderer11 *renderer,
const d3d11::BlendStateKey &key, const d3d11::BlendStateKey &key,
......
...@@ -665,6 +665,7 @@ angle::Result ShaderConstants11::updateBuffer(const gl::Context *context, ...@@ -665,6 +665,7 @@ angle::Result ShaderConstants11::updateBuffer(const gl::Context *context,
StateManager11::StateManager11(Renderer11 *renderer) StateManager11::StateManager11(Renderer11 *renderer)
: mRenderer(renderer), : mRenderer(renderer),
mInternalDirtyBits(), mInternalDirtyBits(),
mCurSampleAlphaToCoverage(false),
mCurBlendColor(0, 0, 0, 0), mCurBlendColor(0, 0, 0, 0),
mCurSampleMask(0), mCurSampleMask(0),
mCurStencilRef(0), mCurStencilRef(0),
...@@ -699,18 +700,17 @@ StateManager11::StateManager11(Renderer11 *renderer) ...@@ -699,18 +700,17 @@ StateManager11::StateManager11(Renderer11 *renderer)
mVertexArray11(nullptr), mVertexArray11(nullptr),
mFramebuffer11(nullptr) mFramebuffer11(nullptr)
{ {
mCurBlendState.blend = false; mCurBlendState.blend = false;
mCurBlendState.sourceBlendRGB = GL_ONE; mCurBlendState.sourceBlendRGB = GL_ONE;
mCurBlendState.destBlendRGB = GL_ZERO; mCurBlendState.destBlendRGB = GL_ZERO;
mCurBlendState.sourceBlendAlpha = GL_ONE; mCurBlendState.sourceBlendAlpha = GL_ONE;
mCurBlendState.destBlendAlpha = GL_ZERO; mCurBlendState.destBlendAlpha = GL_ZERO;
mCurBlendState.blendEquationRGB = GL_FUNC_ADD; mCurBlendState.blendEquationRGB = GL_FUNC_ADD;
mCurBlendState.blendEquationAlpha = GL_FUNC_ADD; mCurBlendState.blendEquationAlpha = GL_FUNC_ADD;
mCurBlendState.colorMaskRed = true; mCurBlendState.colorMaskRed = true;
mCurBlendState.colorMaskBlue = true; mCurBlendState.colorMaskBlue = true;
mCurBlendState.colorMaskGreen = true; mCurBlendState.colorMaskGreen = true;
mCurBlendState.colorMaskAlpha = true; mCurBlendState.colorMaskAlpha = true;
mCurBlendState.sampleAlphaToCoverage = false;
mCurDepthStencilState.depthTest = false; mCurDepthStencilState.depthTest = false;
mCurDepthStencilState.depthFunc = GL_LESS; mCurDepthStencilState.depthFunc = GL_LESS;
...@@ -986,8 +986,7 @@ void StateManager11::syncState(const gl::Context *context, const gl::State::Dirt ...@@ -986,8 +986,7 @@ void StateManager11::syncState(const gl::Context *context, const gl::State::Dirt
} }
break; break;
case gl::State::DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED: case gl::State::DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED:
if (state.getBlendState().sampleAlphaToCoverage != if (state.isSampleAlphaToCoverageEnabled() != mCurSampleAlphaToCoverage)
mCurBlendState.sampleAlphaToCoverage)
{ {
mInternalDirtyBits.set(DIRTY_BIT_BLEND_STATE); mInternalDirtyBits.set(DIRTY_BIT_BLEND_STATE);
} }
...@@ -1232,11 +1231,12 @@ void StateManager11::handleMultiviewDrawFramebufferChange(const gl::Context *con ...@@ -1232,11 +1231,12 @@ void StateManager11::handleMultiviewDrawFramebufferChange(const gl::Context *con
angle::Result StateManager11::syncBlendState(const gl::Context *context, angle::Result StateManager11::syncBlendState(const gl::Context *context,
const gl::BlendState &blendState, const gl::BlendState &blendState,
const gl::ColorF &blendColor, const gl::ColorF &blendColor,
unsigned int sampleMask) unsigned int sampleMask,
bool sampleAlphaToCoverage)
{ {
const d3d11::BlendState *dxBlendState = nullptr; const d3d11::BlendState *dxBlendState = nullptr;
const d3d11::BlendStateKey &key = const d3d11::BlendStateKey &key = RenderStateCache::GetBlendStateKey(
RenderStateCache::GetBlendStateKey(context, mFramebuffer11, blendState); context, mFramebuffer11, blendState, sampleAlphaToCoverage);
ANGLE_TRY(mRenderer->getBlendState(context, key, &dxBlendState)); ANGLE_TRY(mRenderer->getBlendState(context, key, &dxBlendState));
...@@ -1263,9 +1263,10 @@ angle::Result StateManager11::syncBlendState(const gl::Context *context, ...@@ -1263,9 +1263,10 @@ angle::Result StateManager11::syncBlendState(const gl::Context *context,
mRenderer->getDeviceContext()->OMSetBlendState(dxBlendState->get(), blendColors, sampleMask); mRenderer->getDeviceContext()->OMSetBlendState(dxBlendState->get(), blendColors, sampleMask);
mCurBlendState = blendState; mCurBlendState = blendState;
mCurBlendColor = blendColor; mCurBlendColor = blendColor;
mCurSampleMask = sampleMask; mCurSampleMask = sampleMask;
mCurSampleAlphaToCoverage = sampleAlphaToCoverage;
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -2248,7 +2249,7 @@ angle::Result StateManager11::updateState(const gl::Context *context, ...@@ -2248,7 +2249,7 @@ angle::Result StateManager11::updateState(const gl::Context *context,
break; break;
case DIRTY_BIT_BLEND_STATE: case DIRTY_BIT_BLEND_STATE:
ANGLE_TRY(syncBlendState(context, glState.getBlendState(), glState.getBlendColor(), ANGLE_TRY(syncBlendState(context, glState.getBlendState(), glState.getBlendColor(),
sampleMask)); sampleMask, glState.isSampleAlphaToCoverageEnabled()));
break; break;
case DIRTY_BIT_DEPTH_STENCIL_STATE: case DIRTY_BIT_DEPTH_STENCIL_STATE:
ANGLE_TRY(syncDepthStencilState(context)); ANGLE_TRY(syncDepthStencilState(context));
......
...@@ -315,7 +315,8 @@ class StateManager11 final : angle::NonCopyable ...@@ -315,7 +315,8 @@ class StateManager11 final : angle::NonCopyable
angle::Result syncBlendState(const gl::Context *context, angle::Result syncBlendState(const gl::Context *context,
const gl::BlendState &blendState, const gl::BlendState &blendState,
const gl::ColorF &blendColor, const gl::ColorF &blendColor,
unsigned int sampleMask); unsigned int sampleMask,
bool sampleAlphaToCoverage);
angle::Result syncDepthStencilState(const gl::Context *context); angle::Result syncDepthStencilState(const gl::Context *context);
...@@ -461,6 +462,8 @@ class StateManager11 final : angle::NonCopyable ...@@ -461,6 +462,8 @@ class StateManager11 final : angle::NonCopyable
DirtyBits mGraphicsDirtyBitsMask; DirtyBits mGraphicsDirtyBitsMask;
DirtyBits mComputeDirtyBitsMask; DirtyBits mComputeDirtyBitsMask;
bool mCurSampleAlphaToCoverage;
// Blend State // Blend State
gl::BlendState mCurBlendState; gl::BlendState mCurBlendState;
gl::ColorF mCurBlendColor; gl::ColorF mCurBlendColor;
......
...@@ -149,10 +149,11 @@ struct BlendStateKey final ...@@ -149,10 +149,11 @@ struct BlendStateKey final
gl::BlendState blendState; gl::BlendState blendState;
// An int so struct size rounds nicely.
uint32_t rtvMax;
uint8_t rtvMasks[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT]; uint8_t rtvMasks[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
// Keep two 1-byte values at the end, so struct size rounds nicely.
uint8_t rtvMax;
bool sampleAlphaToCoverage;
}; };
bool operator==(const BlendStateKey &a, const BlendStateKey &b); bool operator==(const BlendStateKey &a, const BlendStateKey &b);
......
...@@ -19,6 +19,7 @@ namespace rx ...@@ -19,6 +19,7 @@ namespace rx
StateManager9::StateManager9(Renderer9 *renderer9) StateManager9::StateManager9(Renderer9 *renderer9)
: mUsingZeroColorMaskWorkaround(false), : mUsingZeroColorMaskWorkaround(false),
mCurSampleAlphaToCoverage(false),
mCurBlendState(), mCurBlendState(),
mCurBlendColor(0, 0, 0, 0), mCurBlendColor(0, 0, 0, 0),
mCurSampleMask(0), mCurSampleMask(0),
...@@ -174,8 +175,7 @@ void StateManager9::syncState(const gl::State &state, const gl::State::DirtyBits ...@@ -174,8 +175,7 @@ void StateManager9::syncState(const gl::State &state, const gl::State::DirtyBits
break; break;
} }
case gl::State::DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED: case gl::State::DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED:
if (state.getBlendState().sampleAlphaToCoverage != if (state.isSampleAlphaToCoverageEnabled() != mCurSampleAlphaToCoverage)
mCurBlendState.sampleAlphaToCoverage)
{ {
mDirtyBits.set(DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE); mDirtyBits.set(DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE);
} }
...@@ -354,7 +354,7 @@ void StateManager9::setBlendDepthRasterStates(const gl::State &glState, unsigned ...@@ -354,7 +354,7 @@ void StateManager9::setBlendDepthRasterStates(const gl::State &glState, unsigned
setBlendFuncsEquations(blendState); setBlendFuncsEquations(blendState);
break; break;
case DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE: case DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE:
setSampleAlphaToCoverage(blendState.sampleAlphaToCoverage); setSampleAlphaToCoverage(glState.isSampleAlphaToCoverageEnabled());
break; break;
case DIRTY_BIT_COLOR_MASK: case DIRTY_BIT_COLOR_MASK:
setColorMask(framebuffer, blendState.colorMaskRed, blendState.colorMaskBlue, setColorMask(framebuffer, blendState.colorMaskRed, blendState.colorMaskBlue,
...@@ -692,7 +692,8 @@ void StateManager9::setSampleAlphaToCoverage(bool enabled) ...@@ -692,7 +692,8 @@ void StateManager9::setSampleAlphaToCoverage(bool enabled)
{ {
if (enabled) if (enabled)
{ {
UNREACHABLE(); // D3D9 support for alpha-to-coverage is vendor-specific.
UNIMPLEMENTED();
} }
} }
......
...@@ -159,6 +159,8 @@ class StateManager9 final : angle::NonCopyable ...@@ -159,6 +159,8 @@ class StateManager9 final : angle::NonCopyable
bool mUsingZeroColorMaskWorkaround; bool mUsingZeroColorMaskWorkaround;
bool mCurSampleAlphaToCoverage;
// Currently applied blend state // Currently applied blend state
gl::BlendState mCurBlendState; gl::BlendState mCurBlendState;
gl::ColorF mCurBlendColor; 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