Skip to content

Commit

Permalink
Start implementing glClear
Browse files Browse the repository at this point in the history
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 <syoussefi@chromium.org>
Reviewed-by: Liza Burakova <liza@chromium.org>
Commit-Queue: Matthew Denton <mpdenton@chromium.org>
  • Loading branch information
mdenton8 authored and Angle LUCI CQ committed Apr 5, 2024
1 parent 4a5d47d commit be42f20
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/libANGLE/renderer/wgpu/FramebufferWgpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<GLbitfield>(GL_COLOR_BUFFER_BIT));
bool clearDepth = IsMaskFlagSet(mask, static_cast<GLbitfield>(GL_DEPTH_BUFFER_BIT));
bool clearStencil = IsMaskFlagSet(mask, static_cast<GLbitfield>(GL_STENCIL_BUFFER_BIT));
// TODO(anglebug.com/8582): support clearing depth and stencil buffers.
ASSERT(!clearDepth && !clearStencil && clearColor);

ContextWgpu *contextWgpu = GetImplAs<ContextWgpu>(context);
gl::ColorF colorClearValue = context->getState().getColorClearValue();

std::vector<wgpu::RenderPassColorAttachment> 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;
}

Expand Down
10 changes: 10 additions & 0 deletions src/libANGLE/renderer/wgpu/SurfaceWgpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions src/libANGLE/renderer/wgpu/SurfaceWgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit be42f20

Please sign in to comment.