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

Commit 0f55e3e

Browse files
lexaknyazevCommit Bot
authored andcommitted
Reland "Remove redundant BlendStateArray tracking"
Rebase the original CL and update capture/replay state serialization Original CL reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2169093 Bug: angleproject:4394 Bug: chromium:1085996 Bug: chromium:1086582 Bug: chromium:1086585 Bug: chromium:1086586 Change-Id: If0fba8b6e185540aed57d22eaf0ff79ec142209e Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2404442 Commit-Queue: Jamie Madill <[email protected]> Reviewed-by: Jamie Madill <[email protected]> Reviewed-by: Geoff Lang <[email protected]>
1 parent 30d067c commit 0f55e3e

File tree

5 files changed

+79
-123
lines changed

5 files changed

+79
-123
lines changed

src/libANGLE/Context.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,10 @@ bool IsClearBufferEnabled(const FramebufferState &mState, GLenum buffer, GLint d
264264
return buffer != GL_COLOR || mState.getEnabledDrawBuffers()[drawbuffer];
265265
}
266266

267-
bool IsColorMaskedOut(const BlendState &blend)
267+
bool IsColorMaskedOut(const BlendStateExt &blendStateExt, const GLint drawbuffer)
268268
{
269-
return (!blend.colorMaskRed && !blend.colorMaskGreen && !blend.colorMaskBlue &&
270-
!blend.colorMaskAlpha);
269+
ASSERT(static_cast<size_t>(drawbuffer) < blendStateExt.mMaxDrawBuffers);
270+
return blendStateExt.getColorMaskIndexed(static_cast<size_t>(drawbuffer)) == 0;
271271
}
272272
} // anonymous namespace
273273

@@ -3816,8 +3816,7 @@ bool Context::isClearBufferMaskedOut(GLenum buffer, GLint drawbuffer) const
38163816
switch (buffer)
38173817
{
38183818
case GL_COLOR:
3819-
ASSERT(static_cast<size_t>(drawbuffer) < mState.getBlendStateArray().size());
3820-
return IsColorMaskedOut(mState.getBlendStateArray()[drawbuffer]);
3819+
return IsColorMaskedOut(mState.getBlendStateExt(), drawbuffer);
38213820
case GL_DEPTH:
38223821
return mState.getDepthStencilState().isDepthMaskedOut();
38233822
case GL_STENCIL:

src/libANGLE/State.cpp

Lines changed: 59 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -698,56 +698,35 @@ void State::setStencilClearValue(int stencil)
698698

699699
void State::setColorMask(bool red, bool green, bool blue, bool alpha)
700700
{
701-
for (BlendState &blendState : mBlendStateArray)
702-
{
703-
blendState.colorMaskRed = red;
704-
blendState.colorMaskGreen = green;
705-
blendState.colorMaskBlue = blue;
706-
blendState.colorMaskAlpha = alpha;
707-
}
701+
mBlendState.colorMaskRed = red;
702+
mBlendState.colorMaskGreen = green;
703+
mBlendState.colorMaskBlue = blue;
704+
mBlendState.colorMaskAlpha = alpha;
708705

709706
mBlendStateExt.setColorMask(red, green, blue, alpha);
710707
mDirtyBits.set(DIRTY_BIT_COLOR_MASK);
711708
}
712709

713710
void State::setColorMaskIndexed(bool red, bool green, bool blue, bool alpha, GLuint index)
714711
{
715-
ASSERT(index < mBlendStateArray.size());
716-
mBlendStateArray[index].colorMaskRed = red;
717-
mBlendStateArray[index].colorMaskGreen = green;
718-
mBlendStateArray[index].colorMaskBlue = blue;
719-
mBlendStateArray[index].colorMaskAlpha = alpha;
720-
721712
mBlendStateExt.setColorMaskIndexed(index, red, green, blue, alpha);
722713
mDirtyBits.set(DIRTY_BIT_COLOR_MASK);
723714
}
724715

725716
bool State::allActiveDrawBufferChannelsMasked() const
726717
{
727-
for (size_t drawBufferIndex : mDrawFramebuffer->getDrawBufferMask())
728-
{
729-
const BlendState &blendState = mBlendStateArray[drawBufferIndex];
730-
if (blendState.colorMaskRed || blendState.colorMaskGreen || blendState.colorMaskBlue ||
731-
blendState.colorMaskAlpha)
732-
{
733-
return false;
734-
}
735-
}
736-
return true;
718+
// Compare current color mask with all-disabled color mask, while ignoring disabled draw
719+
// buffers.
720+
return (mBlendStateExt.compareColorMask(0) & mDrawFramebuffer->getDrawBufferMask()).none();
737721
}
738722

739723
bool State::anyActiveDrawBufferChannelMasked() const
740724
{
741-
for (size_t drawBufferIndex : mDrawFramebuffer->getDrawBufferMask())
742-
{
743-
const BlendState &blendState = mBlendStateArray[drawBufferIndex];
744-
if (!(blendState.colorMaskRed && blendState.colorMaskGreen && blendState.colorMaskBlue &&
745-
blendState.colorMaskAlpha))
746-
{
747-
return true;
748-
}
749-
}
750-
return false;
725+
// Compare current color mask with all-enabled color mask, while ignoring disabled draw
726+
// buffers.
727+
return (mBlendStateExt.compareColorMask(mBlendStateExt.mMaxColorMask) &
728+
mDrawFramebuffer->getDrawBufferMask())
729+
.any();
751730
}
752731

753732
void State::setDepthMask(bool mask)
@@ -813,31 +792,25 @@ void State::setDepthRange(float zNear, float zFar)
813792

814793
void State::setBlend(bool enabled)
815794
{
816-
for (BlendState &blendState : mBlendStateArray)
817-
{
818-
blendState.blend = enabled;
819-
}
795+
mBlendState.blend = enabled;
796+
820797
mBlendStateExt.setEnabled(enabled);
821798
mDirtyBits.set(DIRTY_BIT_BLEND_ENABLED);
822799
}
823800

824801
void State::setBlendIndexed(bool enabled, GLuint index)
825802
{
826-
ASSERT(index < mBlendStateArray.size());
827-
mBlendStateArray[index].blend = enabled;
828803
mBlendStateExt.setEnabledIndexed(index, enabled);
829804
mDirtyBits.set(DIRTY_BIT_BLEND_ENABLED);
830805
}
831806

832807
void State::setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha)
833808
{
834-
for (BlendState &blendState : mBlendStateArray)
835-
{
836-
blendState.sourceBlendRGB = sourceRGB;
837-
blendState.destBlendRGB = destRGB;
838-
blendState.sourceBlendAlpha = sourceAlpha;
839-
blendState.destBlendAlpha = destAlpha;
840-
}
809+
810+
mBlendState.sourceBlendRGB = sourceRGB;
811+
mBlendState.destBlendRGB = destRGB;
812+
mBlendState.sourceBlendAlpha = sourceAlpha;
813+
mBlendState.destBlendAlpha = destAlpha;
841814

842815
if (mNoSimultaneousConstantColorAndAlphaBlendFunc)
843816
{
@@ -870,12 +843,6 @@ void State::setBlendFactorsIndexed(GLenum sourceRGB,
870843
GLenum destAlpha,
871844
GLuint index)
872845
{
873-
ASSERT(index < mBlendStateArray.size());
874-
mBlendStateArray[index].sourceBlendRGB = sourceRGB;
875-
mBlendStateArray[index].destBlendRGB = destRGB;
876-
mBlendStateArray[index].sourceBlendAlpha = sourceAlpha;
877-
mBlendStateArray[index].destBlendAlpha = destAlpha;
878-
879846
if (mNoSimultaneousConstantColorAndAlphaBlendFunc)
880847
{
881848
mBlendFuncConstantColorDrawBuffers.set(index, hasConstantColor(sourceRGB, destRGB));
@@ -911,22 +878,15 @@ void State::setBlendColor(float red, float green, float blue, float alpha)
911878

912879
void State::setBlendEquation(GLenum rgbEquation, GLenum alphaEquation)
913880
{
914-
for (BlendState &blendState : mBlendStateArray)
915-
{
916-
blendState.blendEquationRGB = rgbEquation;
917-
blendState.blendEquationAlpha = alphaEquation;
918-
}
881+
mBlendState.blendEquationRGB = rgbEquation;
882+
mBlendState.blendEquationAlpha = alphaEquation;
919883

920884
mBlendStateExt.setEquations(rgbEquation, alphaEquation);
921885
mDirtyBits.set(DIRTY_BIT_BLEND_EQUATIONS);
922886
}
923887

924888
void State::setBlendEquationIndexed(GLenum rgbEquation, GLenum alphaEquation, GLuint index)
925889
{
926-
ASSERT(index < mBlendStateArray.size());
927-
mBlendStateArray[index].blendEquationRGB = rgbEquation;
928-
mBlendStateArray[index].blendEquationAlpha = alphaEquation;
929-
930890
mBlendStateExt.setEquationsIndexed(index, rgbEquation, alphaEquation);
931891
mDirtyBits.set(DIRTY_BIT_BLEND_EQUATIONS);
932892
}
@@ -2232,12 +2192,16 @@ void State::getBooleanv(GLenum pname, GLboolean *params) const
22322192
*params = mDepthStencil.depthMask;
22332193
break;
22342194
case GL_COLOR_WRITEMASK:
2195+
{
22352196
// non-indexed get returns the state of draw buffer zero
2236-
params[0] = mBlendStateArray[0].colorMaskRed;
2237-
params[1] = mBlendStateArray[0].colorMaskGreen;
2238-
params[2] = mBlendStateArray[0].colorMaskBlue;
2239-
params[3] = mBlendStateArray[0].colorMaskAlpha;
2197+
bool r, g, b, a;
2198+
mBlendStateExt.getColorMaskIndexed(0, &r, &g, &b, &a);
2199+
params[0] = r;
2200+
params[1] = g;
2201+
params[2] = b;
2202+
params[3] = a;
22402203
break;
2204+
}
22412205
case GL_CULL_FACE:
22422206
*params = mRasterizer.cullFace;
22432207
break;
@@ -2264,7 +2228,7 @@ void State::getBooleanv(GLenum pname, GLboolean *params) const
22642228
break;
22652229
case GL_BLEND:
22662230
// non-indexed get returns the state of draw buffer zero
2267-
*params = mBlendStateArray[0].blend;
2231+
*params = mBlendStateExt.mEnabledMask.test(0);
22682232
break;
22692233
case GL_DITHER:
22702234
*params = mRasterizer.dither;
@@ -2579,22 +2543,22 @@ angle::Result State::getIntegerv(const Context *context, GLenum pname, GLint *pa
25792543
break;
25802544
case GL_BLEND_SRC_RGB:
25812545
// non-indexed get returns the state of draw buffer zero
2582-
*params = mBlendStateArray[0].sourceBlendRGB;
2546+
*params = mBlendStateExt.getSrcColorIndexed(0);
25832547
break;
25842548
case GL_BLEND_SRC_ALPHA:
2585-
*params = mBlendStateArray[0].sourceBlendAlpha;
2549+
*params = mBlendStateExt.getSrcAlphaIndexed(0);
25862550
break;
25872551
case GL_BLEND_DST_RGB:
2588-
*params = mBlendStateArray[0].destBlendRGB;
2552+
*params = mBlendStateExt.getDstColorIndexed(0);
25892553
break;
25902554
case GL_BLEND_DST_ALPHA:
2591-
*params = mBlendStateArray[0].destBlendAlpha;
2555+
*params = mBlendStateExt.getDstAlphaIndexed(0);
25922556
break;
25932557
case GL_BLEND_EQUATION_RGB:
2594-
*params = mBlendStateArray[0].blendEquationRGB;
2558+
*params = mBlendStateExt.getEquationColorIndexed(0);
25952559
break;
25962560
case GL_BLEND_EQUATION_ALPHA:
2597-
*params = mBlendStateArray[0].blendEquationAlpha;
2561+
*params = mBlendStateExt.getEquationAlphaIndexed(0);
25982562
break;
25992563
case GL_STENCIL_WRITEMASK:
26002564
*params = CastMaskValue(mDepthStencil.stencilWritemask);
@@ -2852,10 +2816,10 @@ angle::Result State::getIntegerv(const Context *context, GLenum pname, GLint *pa
28522816
break;
28532817
case GL_BLEND_SRC:
28542818
// non-indexed get returns the state of draw buffer zero
2855-
*params = mBlendStateArray[0].sourceBlendRGB;
2819+
*params = mBlendStateExt.getSrcColorIndexed(0);
28562820
break;
28572821
case GL_BLEND_DST:
2858-
*params = mBlendStateArray[0].destBlendRGB;
2822+
*params = mBlendStateExt.getDstColorIndexed(0);
28592823
break;
28602824
case GL_PERSPECTIVE_CORRECTION_HINT:
28612825
case GL_POINT_SMOOTH_HINT:
@@ -2921,28 +2885,28 @@ void State::getIntegeri_v(GLenum target, GLuint index, GLint *data) const
29212885
switch (target)
29222886
{
29232887
case GL_BLEND_SRC_RGB:
2924-
ASSERT(static_cast<size_t>(index) < mBlendStateArray.size());
2925-
*data = mBlendStateArray[index].sourceBlendRGB;
2888+
ASSERT(static_cast<size_t>(index) < mBlendStateExt.mMaxDrawBuffers);
2889+
*data = mBlendStateExt.getSrcColorIndexed(index);
29262890
break;
29272891
case GL_BLEND_SRC_ALPHA:
2928-
ASSERT(static_cast<size_t>(index) < mBlendStateArray.size());
2929-
*data = mBlendStateArray[index].sourceBlendAlpha;
2892+
ASSERT(static_cast<size_t>(index) < mBlendStateExt.mMaxDrawBuffers);
2893+
*data = mBlendStateExt.getSrcAlphaIndexed(index);
29302894
break;
29312895
case GL_BLEND_DST_RGB:
2932-
ASSERT(static_cast<size_t>(index) < mBlendStateArray.size());
2933-
*data = mBlendStateArray[index].destBlendRGB;
2896+
ASSERT(static_cast<size_t>(index) < mBlendStateExt.mMaxDrawBuffers);
2897+
*data = mBlendStateExt.getDstColorIndexed(index);
29342898
break;
29352899
case GL_BLEND_DST_ALPHA:
2936-
ASSERT(static_cast<size_t>(index) < mBlendStateArray.size());
2937-
*data = mBlendStateArray[index].destBlendAlpha;
2900+
ASSERT(static_cast<size_t>(index) < mBlendStateExt.mMaxDrawBuffers);
2901+
*data = mBlendStateExt.getDstAlphaIndexed(index);
29382902
break;
29392903
case GL_BLEND_EQUATION_RGB:
2940-
ASSERT(static_cast<size_t>(index) < mBlendStateArray.size());
2941-
*data = mBlendStateArray[index].blendEquationRGB;
2904+
ASSERT(static_cast<size_t>(index) < mBlendStateExt.mMaxDrawBuffers);
2905+
*data = mBlendStateExt.getEquationColorIndexed(index);
29422906
break;
29432907
case GL_BLEND_EQUATION_ALPHA:
2944-
ASSERT(static_cast<size_t>(index) < mBlendStateArray.size());
2945-
*data = mBlendStateArray[index].blendEquationAlpha;
2908+
ASSERT(static_cast<size_t>(index) < mBlendStateExt.mMaxDrawBuffers);
2909+
*data = mBlendStateExt.getEquationAlphaIndexed(index);
29462910
break;
29472911
case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
29482912
ASSERT(static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount());
@@ -3053,12 +3017,16 @@ void State::getBooleani_v(GLenum target, GLuint index, GLboolean *data) const
30533017
switch (target)
30543018
{
30553019
case GL_COLOR_WRITEMASK:
3056-
ASSERT(static_cast<size_t>(index) < mBlendStateArray.size());
3057-
data[0] = mBlendStateArray[index].colorMaskRed;
3058-
data[1] = mBlendStateArray[index].colorMaskGreen;
3059-
data[2] = mBlendStateArray[index].colorMaskBlue;
3060-
data[3] = mBlendStateArray[index].colorMaskAlpha;
3020+
{
3021+
ASSERT(static_cast<size_t>(index) < mBlendStateExt.mMaxDrawBuffers);
3022+
bool r, g, b, a;
3023+
mBlendStateExt.getColorMaskIndexed(index, &r, &g, &b, &a);
3024+
data[0] = r;
3025+
data[1] = g;
3026+
data[2] = b;
3027+
data[3] = a;
30613028
break;
3029+
}
30623030
case GL_IMAGE_BINDING_LAYERED:
30633031
ASSERT(static_cast<size_t>(index) < mImageUnits.size());
30643032
*data = mImageUnits[index].layered;

src/libANGLE/State.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ class State : angle::NonCopyable
134134
bool allActiveDrawBufferChannelsMasked() const;
135135
bool anyActiveDrawBufferChannelMasked() const;
136136
const RasterizerState &getRasterizerState() const;
137-
const BlendState &getBlendState() const { return mBlendStateArray[0]; }
138-
const BlendStateArray &getBlendStateArray() const { return mBlendStateArray; }
137+
const BlendState &getBlendState() const { return mBlendState; }
138+
const BlendStateExt &getBlendStateExt() const { return mBlendStateExt; }
139139
const DepthStencilState &getDepthStencilState() const;
140140

141141
// Clear behavior setters & state parameter block generation function
@@ -176,11 +176,11 @@ class State : angle::NonCopyable
176176
float getFarPlane() const { return mFarZ; }
177177

178178
// Blend state manipulation
179-
bool isBlendEnabled() const { return mBlendStateArray[0].blend; }
179+
bool isBlendEnabled() const { return mBlendStateExt.mEnabledMask.test(0); }
180180
bool isBlendEnabledIndexed(GLuint index) const
181181
{
182-
ASSERT(index < mBlendStateArray.size());
183-
return mBlendStateArray[index].blend;
182+
ASSERT(static_cast<size_t>(index) < mBlendStateExt.mMaxDrawBuffers);
183+
return mBlendStateExt.mEnabledMask.test(index);
184184
}
185185
DrawBufferMask getBlendEnabledDrawBufferMask() const { return mBlendStateExt.mEnabledMask; }
186186
void setBlend(bool enabled);
@@ -858,8 +858,6 @@ class State : angle::NonCopyable
858858

859859
const std::vector<ImageUnit> getImageUnits() const { return mImageUnits; }
860860

861-
const BlendStateExt &getBlendStateExt() const { return mBlendStateExt; }
862-
863861
private:
864862
friend class Context;
865863

@@ -957,7 +955,7 @@ class State : angle::NonCopyable
957955
bool mScissorTest;
958956
Rectangle mScissor;
959957

960-
BlendStateArray mBlendStateArray;
958+
BlendState mBlendState; // Buffer zero blend state legacy struct
961959
BlendStateExt mBlendStateExt;
962960
ColorF mBlendColor;
963961
bool mSampleAlphaToCoverage;

src/libANGLE/angletypes.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ struct BlendState final
189189
bool operator==(const BlendState &a, const BlendState &b);
190190
bool operator!=(const BlendState &a, const BlendState &b);
191191

192-
using BlendStateArray = std::array<BlendState, IMPLEMENTATION_MAX_DRAW_BUFFERS>;
193-
194192
struct DepthStencilState final
195193
{
196194
// This will zero-initialize the struct, including padding.

src/libANGLE/frame_capture_utils.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -235,19 +235,16 @@ void SerializeRectangle(gl::BinaryOutputStream *bos, const gl::Rectangle &rectan
235235
bos->writeInt(rectangle.height);
236236
}
237237

238-
void SerializeBlendState(gl::BinaryOutputStream *bos, const gl::BlendState &blendState)
238+
void SerializeBlendStateExt(gl::BinaryOutputStream *bos, const gl::BlendStateExt &blendStateExt)
239239
{
240-
bos->writeInt(blendState.blend);
241-
bos->writeInt(blendState.sourceBlendRGB);
242-
bos->writeInt(blendState.destBlendRGB);
243-
bos->writeInt(blendState.sourceBlendAlpha);
244-
bos->writeInt(blendState.destBlendAlpha);
245-
bos->writeInt(blendState.blendEquationRGB);
246-
bos->writeInt(blendState.blendEquationAlpha);
247-
bos->writeInt(blendState.colorMaskRed);
248-
bos->writeInt(blendState.colorMaskGreen);
249-
bos->writeInt(blendState.colorMaskBlue);
250-
bos->writeInt(blendState.colorMaskAlpha);
240+
bos->writeInt(blendStateExt.mEnabledMask.bits());
241+
bos->writeInt(blendStateExt.mDstColor);
242+
bos->writeInt(blendStateExt.mDstAlpha);
243+
bos->writeInt(blendStateExt.mSrcColor);
244+
bos->writeInt(blendStateExt.mSrcAlpha);
245+
bos->writeInt(blendStateExt.mEquationColor);
246+
bos->writeInt(blendStateExt.mEquationAlpha);
247+
bos->writeInt(blendStateExt.mColorMask);
251248
}
252249

253250
void SerializeDepthStencilState(gl::BinaryOutputStream *bos,
@@ -346,11 +343,7 @@ void SerializeGLContextStates(gl::BinaryOutputStream *bos, const gl::State &stat
346343
SerializeRasterizerState(bos, state.getRasterizerState());
347344
bos->writeInt(state.isScissorTestEnabled());
348345
SerializeRectangle(bos, state.getScissor());
349-
const gl::BlendStateArray &blendStateArray = state.getBlendStateArray();
350-
for (size_t i = 0; i < blendStateArray.size(); i++)
351-
{
352-
SerializeBlendState(bos, blendStateArray[i]);
353-
}
346+
SerializeBlendStateExt(bos, state.getBlendStateExt());
354347
SerializeColor(bos, state.getBlendColor());
355348
bos->writeInt(state.isSampleAlphaToCoverageEnabled());
356349
bos->writeInt(state.isSampleCoverageEnabled());

0 commit comments

Comments
 (0)