Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f6e7313

Browse files
lexaknyazevCommit Bot
authored andcommitted
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>
1 parent f87fac5 commit f6e7313

File tree

12 files changed

+69
-60
lines changed

12 files changed

+69
-60
lines changed

src/libANGLE/State.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ State::State(ContextID contextIn,
293293
mDepthClearValue(0),
294294
mStencilClearValue(0),
295295
mScissorTest(false),
296+
mSampleAlphaToCoverage(false),
296297
mSampleCoverage(false),
297298
mSampleCoverageValue(0),
298299
mSampleCoverageInvert(false),
@@ -838,7 +839,7 @@ void State::setPolygonOffsetParams(GLfloat factor, GLfloat units)
838839

839840
void State::setSampleAlphaToCoverage(bool enabled)
840841
{
841-
mBlend.sampleAlphaToCoverage = enabled;
842+
mSampleAlphaToCoverage = enabled;
842843
mDirtyBits.set(DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED);
843844
}
844845

@@ -1885,7 +1886,7 @@ void State::getBooleanv(GLenum pname, GLboolean *params)
18851886
*params = mRasterizer.polygonOffsetFill;
18861887
break;
18871888
case GL_SAMPLE_ALPHA_TO_COVERAGE:
1888-
*params = mBlend.sampleAlphaToCoverage;
1889+
*params = mSampleAlphaToCoverage;
18891890
break;
18901891
case GL_SAMPLE_COVERAGE:
18911892
*params = mSampleCoverage;

src/libANGLE/State.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class State : angle::NonCopyable
175175
void setPolygonOffsetParams(GLfloat factor, GLfloat units);
176176

177177
// Multisample coverage state manipulation
178-
bool isSampleAlphaToCoverageEnabled() const { return mBlend.sampleAlphaToCoverage; }
178+
bool isSampleAlphaToCoverageEnabled() const { return mSampleAlphaToCoverage; }
179179
void setSampleAlphaToCoverage(bool enabled);
180180
bool isSampleCoverageEnabled() const { return mSampleCoverage; }
181181
void setSampleCoverage(bool enabled);
@@ -808,6 +808,7 @@ class State : angle::NonCopyable
808808

809809
BlendState mBlend;
810810
ColorF mBlendColor;
811+
bool mSampleAlphaToCoverage;
811812
bool mSampleCoverage;
812813
GLfloat mSampleCoverageValue;
813814
bool mSampleCoverageInvert;

src/libANGLE/angletypes.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,17 @@ BlendState::BlendState()
4949
{
5050
memset(this, 0, sizeof(BlendState));
5151

52-
blend = false;
53-
sourceBlendRGB = GL_ONE;
54-
sourceBlendAlpha = GL_ONE;
55-
destBlendRGB = GL_ZERO;
56-
destBlendAlpha = GL_ZERO;
57-
blendEquationRGB = GL_FUNC_ADD;
58-
blendEquationAlpha = GL_FUNC_ADD;
59-
sampleAlphaToCoverage = false;
60-
colorMaskRed = true;
61-
colorMaskGreen = true;
62-
colorMaskBlue = true;
63-
colorMaskAlpha = true;
52+
blend = false;
53+
sourceBlendRGB = GL_ONE;
54+
sourceBlendAlpha = GL_ONE;
55+
destBlendRGB = GL_ZERO;
56+
destBlendAlpha = GL_ZERO;
57+
blendEquationRGB = GL_FUNC_ADD;
58+
blendEquationAlpha = GL_FUNC_ADD;
59+
colorMaskRed = true;
60+
colorMaskGreen = true;
61+
colorMaskBlue = true;
62+
colorMaskAlpha = true;
6463
}
6564

6665
BlendState::BlendState(const BlendState &other)

src/libANGLE/angletypes.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ struct BlendState final
168168
bool colorMaskGreen;
169169
bool colorMaskBlue;
170170
bool colorMaskAlpha;
171-
172-
bool sampleAlphaToCoverage;
173171
};
174172

175173
bool operator==(const BlendState &a, const BlendState &b);

src/libANGLE/renderer/d3d/d3d11/Clear11.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,13 @@ angle::Result Clear11::ensureResourcesInitialized(const gl::Context *context)
287287
mDepthStencilStateKey.stencilBackFunc = GL_ALWAYS;
288288

289289
// Initialize BlendStateKey with defaults
290-
mBlendStateKey.blendState.blend = false;
291-
mBlendStateKey.blendState.sourceBlendRGB = GL_ONE;
292-
mBlendStateKey.blendState.sourceBlendAlpha = GL_ONE;
293-
mBlendStateKey.blendState.destBlendRGB = GL_ZERO;
294-
mBlendStateKey.blendState.destBlendAlpha = GL_ZERO;
295-
mBlendStateKey.blendState.blendEquationRGB = GL_FUNC_ADD;
296-
mBlendStateKey.blendState.blendEquationAlpha = GL_FUNC_ADD;
297-
mBlendStateKey.blendState.sampleAlphaToCoverage = false;
290+
mBlendStateKey.blendState.blend = false;
291+
mBlendStateKey.blendState.sourceBlendRGB = GL_ONE;
292+
mBlendStateKey.blendState.sourceBlendAlpha = GL_ONE;
293+
mBlendStateKey.blendState.destBlendRGB = GL_ZERO;
294+
mBlendStateKey.blendState.destBlendAlpha = GL_ZERO;
295+
mBlendStateKey.blendState.blendEquationRGB = GL_FUNC_ADD;
296+
mBlendStateKey.blendState.blendEquationAlpha = GL_FUNC_ADD;
298297

299298
mResourcesInitialized = true;
300299
return angle::Result::Continue;
@@ -646,7 +645,7 @@ angle::Result Clear11::clearFramebuffer(const gl::Context *context,
646645
mBlendStateKey.blendState.colorMaskGreen = clearParams.colorMaskGreen;
647646
mBlendStateKey.blendState.colorMaskBlue = clearParams.colorMaskBlue;
648647
mBlendStateKey.blendState.colorMaskAlpha = clearParams.colorMaskAlpha;
649-
mBlendStateKey.rtvMax = numRtvs;
648+
mBlendStateKey.rtvMax = static_cast<uint8_t>(numRtvs);
650649
memcpy(mBlendStateKey.rtvMasks, &rtvMasks[0], sizeof(mBlendStateKey.rtvMasks));
651650

652651
// Get BlendState

src/libANGLE/renderer/d3d/d3d11/RenderStateCache.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,25 @@ void RenderStateCache::clear()
4545
// static
4646
d3d11::BlendStateKey RenderStateCache::GetBlendStateKey(const gl::Context *context,
4747
Framebuffer11 *framebuffer11,
48-
const gl::BlendState &blendState)
48+
const gl::BlendState &blendState,
49+
bool sampleAlphaToCoverage)
4950
{
5051
d3d11::BlendStateKey key;
5152
const gl::AttachmentList &colorbuffers = framebuffer11->getColorAttachmentsForRender(context);
5253
const UINT8 blendStateMask =
5354
gl_d3d11::ConvertColorMask(blendState.colorMaskRed, blendState.colorMaskGreen,
5455
blendState.colorMaskBlue, blendState.colorMaskAlpha);
5556

56-
key.blendState = blendState;
57+
key.blendState = blendState;
58+
key.sampleAlphaToCoverage = sampleAlphaToCoverage;
5759

5860
for (size_t i = 0; i < colorbuffers.size(); i++)
5961
{
6062
const gl::FramebufferAttachment *attachment = colorbuffers[i];
6163

6264
if (attachment)
6365
{
64-
key.rtvMax = static_cast<uint32_t>(i) + 1;
66+
key.rtvMax = static_cast<uint8_t>(i) + 1;
6567
key.rtvMasks[i] =
6668
(gl_d3d11::GetColorMask(*attachment->getFormat().info)) & blendStateMask;
6769
}
@@ -89,7 +91,7 @@ angle::Result RenderStateCache::getBlendState(const gl::Context *context,
8991
D3D11_RENDER_TARGET_BLEND_DESC &rtDesc0 = blendDesc.RenderTarget[0];
9092
const gl::BlendState &blendState = key.blendState;
9193

92-
blendDesc.AlphaToCoverageEnable = blendState.sampleAlphaToCoverage;
94+
blendDesc.AlphaToCoverageEnable = key.sampleAlphaToCoverage;
9395
blendDesc.IndependentBlendEnable = key.rtvMax > 1 ? TRUE : FALSE;
9496

9597
rtDesc0 = {};

src/libANGLE/renderer/d3d/d3d11/RenderStateCache.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ class RenderStateCache : angle::NonCopyable
6969

7070
static d3d11::BlendStateKey GetBlendStateKey(const gl::Context *context,
7171
Framebuffer11 *framebuffer11,
72-
const gl::BlendState &blendState);
72+
const gl::BlendState &blendState,
73+
bool sampleAlphaToCoverage);
7374
angle::Result getBlendState(const gl::Context *context,
7475
Renderer11 *renderer,
7576
const d3d11::BlendStateKey &key,

src/libANGLE/renderer/d3d/d3d11/StateManager11.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ angle::Result ShaderConstants11::updateBuffer(const gl::Context *context,
665665
StateManager11::StateManager11(Renderer11 *renderer)
666666
: mRenderer(renderer),
667667
mInternalDirtyBits(),
668+
mCurSampleAlphaToCoverage(false),
668669
mCurBlendColor(0, 0, 0, 0),
669670
mCurSampleMask(0),
670671
mCurStencilRef(0),
@@ -699,18 +700,17 @@ StateManager11::StateManager11(Renderer11 *renderer)
699700
mVertexArray11(nullptr),
700701
mFramebuffer11(nullptr)
701702
{
702-
mCurBlendState.blend = false;
703-
mCurBlendState.sourceBlendRGB = GL_ONE;
704-
mCurBlendState.destBlendRGB = GL_ZERO;
705-
mCurBlendState.sourceBlendAlpha = GL_ONE;
706-
mCurBlendState.destBlendAlpha = GL_ZERO;
707-
mCurBlendState.blendEquationRGB = GL_FUNC_ADD;
708-
mCurBlendState.blendEquationAlpha = GL_FUNC_ADD;
709-
mCurBlendState.colorMaskRed = true;
710-
mCurBlendState.colorMaskBlue = true;
711-
mCurBlendState.colorMaskGreen = true;
712-
mCurBlendState.colorMaskAlpha = true;
713-
mCurBlendState.sampleAlphaToCoverage = false;
703+
mCurBlendState.blend = false;
704+
mCurBlendState.sourceBlendRGB = GL_ONE;
705+
mCurBlendState.destBlendRGB = GL_ZERO;
706+
mCurBlendState.sourceBlendAlpha = GL_ONE;
707+
mCurBlendState.destBlendAlpha = GL_ZERO;
708+
mCurBlendState.blendEquationRGB = GL_FUNC_ADD;
709+
mCurBlendState.blendEquationAlpha = GL_FUNC_ADD;
710+
mCurBlendState.colorMaskRed = true;
711+
mCurBlendState.colorMaskBlue = true;
712+
mCurBlendState.colorMaskGreen = true;
713+
mCurBlendState.colorMaskAlpha = true;
714714

715715
mCurDepthStencilState.depthTest = false;
716716
mCurDepthStencilState.depthFunc = GL_LESS;
@@ -986,8 +986,7 @@ void StateManager11::syncState(const gl::Context *context, const gl::State::Dirt
986986
}
987987
break;
988988
case gl::State::DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED:
989-
if (state.getBlendState().sampleAlphaToCoverage !=
990-
mCurBlendState.sampleAlphaToCoverage)
989+
if (state.isSampleAlphaToCoverageEnabled() != mCurSampleAlphaToCoverage)
991990
{
992991
mInternalDirtyBits.set(DIRTY_BIT_BLEND_STATE);
993992
}
@@ -1232,11 +1231,12 @@ void StateManager11::handleMultiviewDrawFramebufferChange(const gl::Context *con
12321231
angle::Result StateManager11::syncBlendState(const gl::Context *context,
12331232
const gl::BlendState &blendState,
12341233
const gl::ColorF &blendColor,
1235-
unsigned int sampleMask)
1234+
unsigned int sampleMask,
1235+
bool sampleAlphaToCoverage)
12361236
{
12371237
const d3d11::BlendState *dxBlendState = nullptr;
1238-
const d3d11::BlendStateKey &key =
1239-
RenderStateCache::GetBlendStateKey(context, mFramebuffer11, blendState);
1238+
const d3d11::BlendStateKey &key = RenderStateCache::GetBlendStateKey(
1239+
context, mFramebuffer11, blendState, sampleAlphaToCoverage);
12401240

12411241
ANGLE_TRY(mRenderer->getBlendState(context, key, &dxBlendState));
12421242

@@ -1263,9 +1263,10 @@ angle::Result StateManager11::syncBlendState(const gl::Context *context,
12631263

12641264
mRenderer->getDeviceContext()->OMSetBlendState(dxBlendState->get(), blendColors, sampleMask);
12651265

1266-
mCurBlendState = blendState;
1267-
mCurBlendColor = blendColor;
1268-
mCurSampleMask = sampleMask;
1266+
mCurBlendState = blendState;
1267+
mCurBlendColor = blendColor;
1268+
mCurSampleMask = sampleMask;
1269+
mCurSampleAlphaToCoverage = sampleAlphaToCoverage;
12691270

12701271
return angle::Result::Continue;
12711272
}
@@ -2248,7 +2249,7 @@ angle::Result StateManager11::updateState(const gl::Context *context,
22482249
break;
22492250
case DIRTY_BIT_BLEND_STATE:
22502251
ANGLE_TRY(syncBlendState(context, glState.getBlendState(), glState.getBlendColor(),
2251-
sampleMask));
2252+
sampleMask, glState.isSampleAlphaToCoverageEnabled()));
22522253
break;
22532254
case DIRTY_BIT_DEPTH_STENCIL_STATE:
22542255
ANGLE_TRY(syncDepthStencilState(context));

src/libANGLE/renderer/d3d/d3d11/StateManager11.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ class StateManager11 final : angle::NonCopyable
315315
angle::Result syncBlendState(const gl::Context *context,
316316
const gl::BlendState &blendState,
317317
const gl::ColorF &blendColor,
318-
unsigned int sampleMask);
318+
unsigned int sampleMask,
319+
bool sampleAlphaToCoverage);
319320

320321
angle::Result syncDepthStencilState(const gl::Context *context);
321322

@@ -461,6 +462,8 @@ class StateManager11 final : angle::NonCopyable
461462
DirtyBits mGraphicsDirtyBitsMask;
462463
DirtyBits mComputeDirtyBitsMask;
463464

465+
bool mCurSampleAlphaToCoverage;
466+
464467
// Blend State
465468
gl::BlendState mCurBlendState;
466469
gl::ColorF mCurBlendColor;

src/libANGLE/renderer/d3d/d3d11/renderer11_utils.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,11 @@ struct BlendStateKey final
149149

150150
gl::BlendState blendState;
151151

152-
// An int so struct size rounds nicely.
153-
uint32_t rtvMax;
154-
155152
uint8_t rtvMasks[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
153+
154+
// Keep two 1-byte values at the end, so struct size rounds nicely.
155+
uint8_t rtvMax;
156+
bool sampleAlphaToCoverage;
156157
};
157158

158159
bool operator==(const BlendStateKey &a, const BlendStateKey &b);

0 commit comments

Comments
 (0)