Skip to content

Commit d5fa6ea

Browse files
lexaknyazevCommit Bot
authored andcommitted
Vulkan: Implement OES_draw_buffers_indexed
Bug: angleproject:4394 Change-Id: I7db9c695c233b2daf740acc654b1b2e546a8b681 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2172739 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>
1 parent 385fb40 commit d5fa6ea

File tree

9 files changed

+108
-80
lines changed

9 files changed

+108
-80
lines changed

src/libANGLE/renderer/vulkan/ContextVk.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,6 @@ ContextVk::ContextVk(const gl::State &state, gl::ErrorSet *errorSet, RendererVk
647647
mCurrentDrawElementsType(gl::DrawElementsType::InvalidEnum),
648648
mXfbBaseVertex(0),
649649
mXfbVertexCountPerInstance(0),
650-
mClearColorMask(kAllColorChannelsMask),
651650
mFlipYForCurrentSurface(false),
652651
mIsAnyHostVisibleBufferWritten(false),
653652
mEmulateSeamfulCubeMapSampling(false),
@@ -669,6 +668,10 @@ ContextVk::ContextVk(const gl::State &state, gl::ErrorSet *errorSet, RendererVk
669668
memset(&mClearColorValue, 0, sizeof(mClearColorValue));
670669
memset(&mClearDepthStencilValue, 0, sizeof(mClearDepthStencilValue));
671670

671+
mClearColorMasks = gl::BlendStateExt::ColorMaskStorage::GetReplicatedValue(
672+
kAllColorChannelsMask,
673+
gl::BlendStateExt::ColorMaskStorage::GetMask(getCaps().maxDrawBuffers));
674+
672675
mNonIndexedDirtyBitsMask.set();
673676
mNonIndexedDirtyBitsMask.reset(DIRTY_BIT_INDEX_BUFFER);
674677

@@ -2706,15 +2709,14 @@ SurfaceRotation ContextVk::getRotationReadFramebuffer() const
27062709
return mCurrentRotationReadFramebuffer;
27072710
}
27082711

2709-
void ContextVk::updateColorMask(const gl::BlendState &blendState)
2712+
void ContextVk::updateColorMasks(const gl::BlendStateExt &blendStateExt)
27102713
{
2711-
mClearColorMask =
2712-
gl_vk::GetColorComponentFlags(blendState.colorMaskRed, blendState.colorMaskGreen,
2713-
blendState.colorMaskBlue, blendState.colorMaskAlpha);
2714+
mClearColorMasks = blendStateExt.mColorMask;
2715+
27142716
FramebufferVk *framebufferVk = vk::GetImpl(mState.getDrawFramebuffer());
2715-
mGraphicsPipelineDesc->updateColorWriteMask(&mGraphicsPipelineTransition, mClearColorMask,
2716-
framebufferVk->getEmulatedAlphaAttachmentMask(),
2717-
framebufferVk->getState().getEnabledDrawBuffers());
2717+
mGraphicsPipelineDesc->updateColorWriteMasks(&mGraphicsPipelineTransition, mClearColorMasks,
2718+
framebufferVk->getEmulatedAlphaAttachmentMask(),
2719+
framebufferVk->getState().getEnabledDrawBuffers());
27182720
}
27192721

27202722
void ContextVk::updateSampleMask(const gl::State &glState)
@@ -2937,22 +2939,22 @@ angle::Result ContextVk::syncState(const gl::Context *context,
29372939
break;
29382940
case gl::State::DIRTY_BIT_BLEND_ENABLED:
29392941
mGraphicsPipelineDesc->updateBlendEnabled(&mGraphicsPipelineTransition,
2940-
glState.isBlendEnabled());
2942+
glState.getBlendStateExt().mEnabledMask);
29412943
break;
29422944
case gl::State::DIRTY_BIT_BLEND_COLOR:
29432945
mGraphicsPipelineDesc->updateBlendColor(&mGraphicsPipelineTransition,
29442946
glState.getBlendColor());
29452947
break;
29462948
case gl::State::DIRTY_BIT_BLEND_FUNCS:
29472949
mGraphicsPipelineDesc->updateBlendFuncs(&mGraphicsPipelineTransition,
2948-
glState.getBlendState());
2950+
glState.getBlendStateExt());
29492951
break;
29502952
case gl::State::DIRTY_BIT_BLEND_EQUATIONS:
29512953
mGraphicsPipelineDesc->updateBlendEquations(&mGraphicsPipelineTransition,
2952-
glState.getBlendState());
2954+
glState.getBlendStateExt());
29532955
break;
29542956
case gl::State::DIRTY_BIT_COLOR_MASK:
2955-
updateColorMask(glState.getBlendState());
2957+
updateColorMasks(glState.getBlendStateExt());
29562958
break;
29572959
case gl::State::DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED:
29582960
mGraphicsPipelineDesc->updateAlphaToCoverageEnable(
@@ -3107,7 +3109,7 @@ angle::Result ContextVk::syncState(const gl::Context *context,
31073109
updateSurfaceRotationDrawFramebuffer(glState);
31083110
updateViewport(mDrawFramebuffer, glState.getViewport(), glState.getNearPlane(),
31093111
glState.getFarPlane(), isViewportFlipEnabledForDrawFBO());
3110-
updateColorMask(glState.getBlendState());
3112+
updateColorMasks(glState.getBlendStateExt());
31113113
updateSampleMask(glState);
31123114
mGraphicsPipelineDesc->updateRasterizationSamples(&mGraphicsPipelineTransition,
31133115
mDrawFramebuffer->getSamples());
@@ -3739,9 +3741,9 @@ const VkClearValue &ContextVk::getClearDepthStencilValue() const
37393741
return mClearDepthStencilValue;
37403742
}
37413743

3742-
VkColorComponentFlags ContextVk::getClearColorMask() const
3744+
gl::BlendStateExt::ColorMaskStorage::Type ContextVk::getClearColorMasks() const
37433745
{
3744-
return mClearColorMask;
3746+
return mClearColorMasks;
37453747
}
37463748

37473749
void ContextVk::writeAtomicCounterBufferDriverUniformOffsets(uint32_t *offsetsOut,

src/libANGLE/renderer/vulkan/ContextVk.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,11 @@ class ContextVk : public ContextImpl, public vk::Context
382382

383383
const VkClearValue &getClearColorValue() const;
384384
const VkClearValue &getClearDepthStencilValue() const;
385-
VkColorComponentFlags getClearColorMask() const;
385+
gl::BlendStateExt::ColorMaskStorage::Type getClearColorMasks() const;
386386
angle::Result getIncompleteTexture(const gl::Context *context,
387387
gl::TextureType type,
388388
gl::Texture **textureOut);
389-
void updateColorMask(const gl::BlendState &blendState);
389+
void updateColorMasks(const gl::BlendStateExt &blendStateExt);
390390
void updateSampleMask(const gl::State &glState);
391391

392392
void handleError(VkResult errorCode,
@@ -1021,7 +1021,7 @@ class ContextVk : public ContextImpl, public vk::Context
10211021
// Cached clear value/mask for color and depth/stencil.
10221022
VkClearValue mClearColorValue;
10231023
VkClearValue mClearDepthStencilValue;
1024-
VkColorComponentFlags mClearColorMask;
1024+
gl::BlendStateExt::ColorMaskStorage::Type mClearColorMasks;
10251025

10261026
IncompleteTextureSet mIncompleteTextures;
10271027

src/libANGLE/renderer/vulkan/FramebufferVk.cpp

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ FramebufferVk::FramebufferVk(RendererVk *renderer,
308308
: FramebufferImpl(state),
309309
mBackbuffer(backbuffer),
310310
mFramebuffer(nullptr),
311-
mActiveColorComponents(0),
311+
mActiveColorComponentMasksForClear(0),
312312
mReadOnlyDepthFeedbackLoopMode(false)
313313
{
314314
mReadPixelBuffer.init(renderer, VK_BUFFER_USAGE_TRANSFER_DST_BIT, kReadPixelsBufferAlignment,
@@ -433,8 +433,8 @@ angle::Result FramebufferVk::clearImpl(const gl::Context *context,
433433
// Adjust clear behavior based on whether the respective attachments are present; if asked to
434434
// clear a non-existent attachment, don't attempt to clear it.
435435

436-
VkColorComponentFlags colorMaskFlags = contextVk->getClearColorMask();
437-
bool clearColor = clearColorBuffers.any();
436+
gl::BlendStateExt::ColorMaskStorage::Type colorMasks = contextVk->getClearColorMasks();
437+
bool clearColor = clearColorBuffers.any();
438438

439439
const gl::FramebufferAttachment *depthAttachment = mState.getDepthAttachment();
440440
clearDepth = clearDepth && depthAttachment;
@@ -448,7 +448,7 @@ angle::Result FramebufferVk::clearImpl(const gl::Context *context,
448448
static_cast<uint8_t>(contextVk->getState().getDepthStencilState().stencilWritemask);
449449

450450
// The front-end should ensure we don't attempt to clear color if all channels are masked.
451-
ASSERT(!clearColor || colorMaskFlags != 0);
451+
ASSERT(!clearColor || colorMasks != 0);
452452
// The front-end should ensure we don't attempt to clear depth if depth write is disabled.
453453
ASSERT(!clearDepth || contextVk->getState().getDepthStencilState().depthMask);
454454
// The front-end should ensure we don't attempt to clear stencil if all bits are masked.
@@ -465,8 +465,8 @@ angle::Result FramebufferVk::clearImpl(const gl::Context *context,
465465

466466
// We can use render pass load ops if clearing depth, unmasked color or unmasked stencil. If
467467
// there's a depth mask, depth clearing is already disabled.
468-
bool maskedClearColor =
469-
clearColor && (mActiveColorComponents & colorMaskFlags) != mActiveColorComponents;
468+
bool maskedClearColor = clearColor && (mActiveColorComponentMasksForClear & colorMasks) !=
469+
mActiveColorComponentMasksForClear;
470470
bool maskedClearStencil = clearStencil && stencilMask != 0xFF;
471471

472472
bool clearColorWithRenderPassLoadOp = clearColor && !maskedClearColor && !scissoredClear;
@@ -559,7 +559,7 @@ angle::Result FramebufferVk::clearImpl(const gl::Context *context,
559559
// The most costly clear mode is when we need to mask out specific color channels or stencil
560560
// bits. This can only be done with a draw call.
561561
return clearWithDraw(contextVk, scissoredRenderArea, clearColorBuffers, clearDepth,
562-
clearStencil, colorMaskFlags, stencilMask, clearColorValue,
562+
clearStencil, colorMasks, stencilMask, clearColorValue,
563563
clearDepthStencilValue);
564564
}
565565

@@ -1551,7 +1551,7 @@ angle::Result FramebufferVk::updateColorAttachment(const gl::Context *context,
15511551
mEmulatedAlphaAttachmentMask.set(colorIndexGL,
15521552
sourceFormat.alphaBits == 0 && actualFormat.alphaBits > 0);
15531553

1554-
contextVk->updateColorMask(context->getState().getBlendState());
1554+
contextVk->updateColorMasks(context->getState().getBlendStateExt());
15551555

15561556
if (deferClears && mState.getEnabledDrawBuffers().test(colorIndexGL))
15571557
{
@@ -1722,7 +1722,7 @@ angle::Result FramebufferVk::syncState(const gl::Context *context,
17221722

17231723
if (shouldUpdateColorMask)
17241724
{
1725-
contextVk->updateColorMask(context->getState().getBlendState());
1725+
contextVk->updateColorMasks(context->getState().getBlendStateExt());
17261726
}
17271727

17281728
// In some cases we'll need to force a flush of deferred clears. When we're syncing the read
@@ -1752,10 +1752,6 @@ angle::Result FramebufferVk::syncState(const gl::Context *context,
17521752
const gl::State &glState = context->getState();
17531753
ANGLE_TRY(contextVk->updateScissor(glState));
17541754

1755-
mActiveColorComponents = gl_vk::GetColorComponentFlags(
1756-
mActiveColorComponentMasksForClear[0].any(), mActiveColorComponentMasksForClear[1].any(),
1757-
mActiveColorComponentMasksForClear[2].any(), mActiveColorComponentMasksForClear[3].any());
1758-
17591755
if (command != gl::Command::Blit)
17601756
{
17611757
// Don't end the render pass when handling a blit to resolve, since we may be able to
@@ -2011,7 +2007,7 @@ angle::Result FramebufferVk::clearWithDraw(ContextVk *contextVk,
20112007
gl::DrawBufferMask clearColorBuffers,
20122008
bool clearDepth,
20132009
bool clearStencil,
2014-
VkColorComponentFlags colorMaskFlags,
2010+
gl::BlendStateExt::ColorMaskStorage::Type colorMasks,
20152011
uint8_t stencilMask,
20162012
const VkClearColorValue &clearColorValue,
20172013
const VkClearDepthStencilValue &clearDepthStencilValue)
@@ -2048,7 +2044,8 @@ angle::Result FramebufferVk::clearWithDraw(ContextVk *contextVk,
20482044
params.colorFormat =
20492045
&colorRenderTarget->getImageForRenderPass().getFormat().actualImageFormat();
20502046
params.colorAttachmentIndexGL = static_cast<uint32_t>(colorIndexGL);
2051-
params.colorMaskFlags = colorMaskFlags;
2047+
params.colorMaskFlags =
2048+
gl::BlendStateExt::ColorMaskStorage::GetValueIndexed(colorIndexGL, colorMasks);
20522049
if (mEmulatedAlphaAttachmentMask[colorIndexGL])
20532050
{
20542051
params.colorMaskFlags &= ~VK_COLOR_COMPONENT_A_BIT;
@@ -2535,10 +2532,9 @@ void FramebufferVk::restoreDepthStencilDefinedContents()
25352532

25362533
void FramebufferVk::updateActiveColorMasks(size_t colorIndexGL, bool r, bool g, bool b, bool a)
25372534
{
2538-
mActiveColorComponentMasksForClear[0].set(colorIndexGL, r);
2539-
mActiveColorComponentMasksForClear[1].set(colorIndexGL, g);
2540-
mActiveColorComponentMasksForClear[2].set(colorIndexGL, b);
2541-
mActiveColorComponentMasksForClear[3].set(colorIndexGL, a);
2535+
gl::BlendStateExt::ColorMaskStorage::SetValueIndexed(
2536+
colorIndexGL, gl::BlendStateExt::PackColorMask(r, g, b, a),
2537+
&mActiveColorComponentMasksForClear);
25422538
}
25432539

25442540
const gl::DrawBufferMask &FramebufferVk::getEmulatedAlphaAttachmentMask() const

src/libANGLE/renderer/vulkan/FramebufferVk.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class FramebufferVk : public FramebufferImpl
187187
gl::DrawBufferMask clearColorBuffers,
188188
bool clearDepth,
189189
bool clearStencil,
190-
VkColorComponentFlags colorMaskFlags,
190+
gl::BlendStateExt::ColorMaskStorage::Type colorMasks,
191191
uint8_t stencilMask,
192192
const VkClearColorValue &clearColorValue,
193193
const VkClearDepthStencilValue &clearDepthStencilValue);
@@ -235,11 +235,10 @@ class FramebufferVk : public FramebufferImpl
235235
vk::FramebufferHelper *mFramebuffer;
236236
RenderTargetCache<RenderTargetVk> mRenderTargetCache;
237237

238-
// These two variables are used to quickly compute if we need to do a masked clear. If a color
238+
// This variable is used to quickly compute if we need to do a masked clear. If a color
239239
// channel is masked out, we check against the Framebuffer Attachments (RenderTargets) to see
240240
// if the masked out channel is present in any of the attachments.
241-
VkColorComponentFlags mActiveColorComponents;
242-
gl::DrawBufferMask mActiveColorComponentMasksForClear[4];
241+
gl::BlendStateExt::ColorMaskStorage::Type mActiveColorComponentMasksForClear;
243242
vk::DynamicBuffer mReadPixelBuffer;
244243

245244
// When we draw to the framebuffer, and the real format has an alpha channel but the format of

src/libANGLE/renderer/vulkan/UtilsVk.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ angle::Result UtilsVk::clearFramebuffer(ContextVk *contextVk,
14221422
vk::GraphicsPipelineDesc pipelineDesc;
14231423
pipelineDesc.initDefaults();
14241424
pipelineDesc.setCullMode(VK_CULL_MODE_NONE);
1425-
pipelineDesc.setColorWriteMask(0, gl::DrawBufferMask(), gl::DrawBufferMask());
1425+
pipelineDesc.setColorWriteMasks(0, gl::DrawBufferMask(), gl::DrawBufferMask());
14261426
pipelineDesc.setSingleColorWriteMask(params.colorAttachmentIndexGL, params.colorMaskFlags);
14271427
pipelineDesc.setRasterizationSamples(framebuffer->getSamples());
14281428
pipelineDesc.setRenderPassDesc(framebuffer->getRenderPassDesc());
@@ -1639,13 +1639,15 @@ angle::Result UtilsVk::blitResolveImpl(ContextVk *contextVk,
16391639
pipelineDesc.initDefaults();
16401640
if (blitColor)
16411641
{
1642-
pipelineDesc.setColorWriteMask(kAllColorComponents,
1643-
framebuffer->getEmulatedAlphaAttachmentMask(),
1644-
~gl::DrawBufferMask());
1642+
pipelineDesc.setColorWriteMasks(
1643+
gl::BlendStateExt::ColorMaskStorage::GetReplicatedValue(
1644+
kAllColorComponents, gl::BlendStateExt::ColorMaskStorage::GetMask(
1645+
framebuffer->getRenderPassDesc().colorAttachmentRange())),
1646+
framebuffer->getEmulatedAlphaAttachmentMask(), ~gl::DrawBufferMask());
16451647
}
16461648
else
16471649
{
1648-
pipelineDesc.setColorWriteMask(0, gl::DrawBufferMask(), gl::DrawBufferMask());
1650+
pipelineDesc.setColorWriteMasks(0, gl::DrawBufferMask(), gl::DrawBufferMask());
16491651
}
16501652
pipelineDesc.setCullMode(VK_CULL_MODE_NONE);
16511653
pipelineDesc.setRenderPassDesc(framebuffer->getRenderPassDesc());

0 commit comments

Comments
 (0)