Metal: Restore load actions after attachment updates
Framebuffer invalidation sets attachment load actions
to MTLLoadActionDontCare. Restore them to MTLLoadActionLoad
after content changes, which may be caused by texSubImage uploads.
Fixes:
* SimpleStateChangeTestES3.InvalidateThenSubUploadThenBlend
* conformance2/renderbuffers/invalidate-framebuffer.html
Bug: angleproject:7397
Change-Id: I8a1b223c92b1fd082f4961161efafaf6b60f8698
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4001808
Reviewed-by: Kyle Piddington <kpiddington@apple.com>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Commit-Queue: Alexey Knyazev <lexa.knyazev@gmail.com>
diff --git a/src/libANGLE/renderer/metal/FrameBufferMtl.mm b/src/libANGLE/renderer/metal/FrameBufferMtl.mm
index 6f5c419..f4db0b3 100644
--- a/src/libANGLE/renderer/metal/FrameBufferMtl.mm
+++ b/src/libANGLE/renderer/metal/FrameBufferMtl.mm
@@ -654,8 +654,14 @@
ANGLE_TRY(updateStencilRenderTarget(context));
break;
case gl::Framebuffer::DIRTY_BIT_DEPTH_BUFFER_CONTENTS:
+ // Restore depth attachment load action as its content may have been updated
+ // after framebuffer invalidation.
+ mRenderPassDesc.depthAttachment.loadAction = MTLLoadActionLoad;
+ break;
case gl::Framebuffer::DIRTY_BIT_STENCIL_BUFFER_CONTENTS:
- // NOTE(hqle): What are we supposed to do?
+ // Restore stencil attachment load action as its content may have been updated
+ // after framebuffer invalidation.
+ mRenderPassDesc.stencilAttachment.loadAction = MTLLoadActionLoad;
break;
case gl::Framebuffer::DIRTY_BIT_DRAW_BUFFERS:
mustNotifyContext = true;
@@ -680,6 +686,12 @@
ASSERT(dirtyBit >= gl::Framebuffer::DIRTY_BIT_COLOR_BUFFER_CONTENTS_0 &&
dirtyBit < gl::Framebuffer::DIRTY_BIT_COLOR_BUFFER_CONTENTS_MAX);
// NOTE: might need to notify context.
+
+ // Restore color attachment load action as its content may have been updated
+ // after framebuffer invalidation.
+ size_t colorIndexGL = static_cast<size_t>(
+ dirtyBit - gl::Framebuffer::DIRTY_BIT_COLOR_BUFFER_CONTENTS_0);
+ mRenderPassDesc.colorAttachments[colorIndexGL].loadAction = MTLLoadActionLoad;
}
break;
}