From be42f20b70ea72acb47e32335ea142fdd3a6375a Mon Sep 17 00:00:00 2001 From: Matthew Denton Date: Fri, 22 Mar 2024 05:45:46 -0700 Subject: [PATCH] Start implementing glClear Currently, because both SurfaceWgpu::getAttachmentRenderTarget() and TextureWgpu::getAttachmentRenderTarget() are unimplemented, there is no actual RenderTargetWgpu in the RenderTargetCache to clear. Bug: angleproject:8582 Change-Id: I9ad33c57d533d81178d7d2a802d35b106ece5848 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5388076 Reviewed-by: Shahbaz Youssefi Reviewed-by: Liza Burakova Commit-Queue: Matthew Denton --- .../renderer/wgpu/FramebufferWgpu.cpp | 34 +++++++++++++++++++ src/libANGLE/renderer/wgpu/SurfaceWgpu.cpp | 10 ++++++ src/libANGLE/renderer/wgpu/SurfaceWgpu.h | 6 ++++ 3 files changed, 50 insertions(+) diff --git a/src/libANGLE/renderer/wgpu/FramebufferWgpu.cpp b/src/libANGLE/renderer/wgpu/FramebufferWgpu.cpp index 6ca2b05346f..64ad148796b 100644 --- a/src/libANGLE/renderer/wgpu/FramebufferWgpu.cpp +++ b/src/libANGLE/renderer/wgpu/FramebufferWgpu.cpp @@ -47,6 +47,40 @@ angle::Result FramebufferWgpu::invalidateSub(const gl::Context *context, angle::Result FramebufferWgpu::clear(const gl::Context *context, GLbitfield mask) { + bool clearColor = IsMaskFlagSet(mask, static_cast(GL_COLOR_BUFFER_BIT)); + bool clearDepth = IsMaskFlagSet(mask, static_cast(GL_DEPTH_BUFFER_BIT)); + bool clearStencil = IsMaskFlagSet(mask, static_cast(GL_STENCIL_BUFFER_BIT)); + // TODO(anglebug.com/8582): support clearing depth and stencil buffers. + ASSERT(!clearDepth && !clearStencil && clearColor); + + ContextWgpu *contextWgpu = GetImplAs(context); + gl::ColorF colorClearValue = context->getState().getColorClearValue(); + + std::vector colorAttachments( + mState.getEnabledDrawBuffers().count()); + for (size_t enabledDrawBuffer : mState.getEnabledDrawBuffers()) + { + wgpu::RenderPassColorAttachment colorAttachment; + colorAttachment.view = + mRenderTargetCache.getColorDraw(mState, enabledDrawBuffer)->getTexture(); + colorAttachment.depthSlice = wgpu::kDepthSliceUndefined; + colorAttachment.loadOp = wgpu::LoadOp::Clear; + colorAttachment.storeOp = wgpu::StoreOp::Store; + colorAttachment.clearValue.r = colorClearValue.red; + colorAttachment.clearValue.g = colorClearValue.green; + colorAttachment.clearValue.b = colorClearValue.blue; + colorAttachment.clearValue.a = colorClearValue.alpha; + colorAttachments.push_back(colorAttachment); + } + + wgpu::RenderPassDescriptor renderPassDesc; + renderPassDesc.colorAttachmentCount = colorAttachments.size(); + renderPassDesc.colorAttachments = colorAttachments.data(); + + // TODO(anglebug.com/8582): optimize this implementation. + ANGLE_TRY(contextWgpu->ensureRenderPassStarted(renderPassDesc)); + ANGLE_TRY(contextWgpu->endRenderPass(webgpu::RenderPassClosureReason::NewRenderPass)); + ANGLE_TRY(contextWgpu->flush()); return angle::Result::Continue; } diff --git a/src/libANGLE/renderer/wgpu/SurfaceWgpu.cpp b/src/libANGLE/renderer/wgpu/SurfaceWgpu.cpp index b3909188114..fdb5135054d 100644 --- a/src/libANGLE/renderer/wgpu/SurfaceWgpu.cpp +++ b/src/libANGLE/renderer/wgpu/SurfaceWgpu.cpp @@ -112,4 +112,14 @@ egl::Error SurfaceWgpu::detachFromFramebuffer(const gl::Context *context, return egl::NoError(); } +angle::Result SurfaceWgpu::getAttachmentRenderTarget(const gl::Context *context, + GLenum binding, + const gl::ImageIndex &imageIndex, + GLsizei samples, + FramebufferAttachmentRenderTarget **rtOut) +{ + UNIMPLEMENTED(); + return angle::Result::Stop; +} + } // namespace rx diff --git a/src/libANGLE/renderer/wgpu/SurfaceWgpu.h b/src/libANGLE/renderer/wgpu/SurfaceWgpu.h index 945938b84ee..89edf374bfb 100644 --- a/src/libANGLE/renderer/wgpu/SurfaceWgpu.h +++ b/src/libANGLE/renderer/wgpu/SurfaceWgpu.h @@ -52,6 +52,12 @@ class SurfaceWgpu : public SurfaceImpl gl::Framebuffer *framebuffer) override; egl::Error detachFromFramebuffer(const gl::Context *context, gl::Framebuffer *framebuffer) override; + + angle::Result getAttachmentRenderTarget(const gl::Context *context, + GLenum binding, + const gl::ImageIndex &imageIndex, + GLsizei samples, + FramebufferAttachmentRenderTarget **rtOut) override; }; } // namespace rx