1 // 2 // Copyright 2024 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 // FramebufferWgpu.h: 7 // Defines the class interface for FramebufferWgpu, implementing FramebufferImpl. 8 // 9 10 #ifndef LIBANGLE_RENDERER_WGPU_FRAMEBUFFERWGPU_H_ 11 #define LIBANGLE_RENDERER_WGPU_FRAMEBUFFERWGPU_H_ 12 13 #include "libANGLE/renderer/FramebufferImpl.h" 14 #include "libANGLE/renderer/RenderTargetCache.h" 15 #include "libANGLE/renderer/wgpu/RenderTargetWgpu.h" 16 17 namespace rx 18 { 19 20 class FramebufferWgpu : public FramebufferImpl 21 { 22 public: 23 FramebufferWgpu(const gl::FramebufferState &state); 24 ~FramebufferWgpu() override; 25 26 angle::Result discard(const gl::Context *context, 27 size_t count, 28 const GLenum *attachments) override; 29 angle::Result invalidate(const gl::Context *context, 30 size_t count, 31 const GLenum *attachments) override; 32 angle::Result invalidateSub(const gl::Context *context, 33 size_t count, 34 const GLenum *attachments, 35 const gl::Rectangle &area) override; 36 37 angle::Result clear(const gl::Context *context, GLbitfield mask) override; 38 angle::Result clearBufferfv(const gl::Context *context, 39 GLenum buffer, 40 GLint drawbuffer, 41 const GLfloat *values) override; 42 angle::Result clearBufferuiv(const gl::Context *context, 43 GLenum buffer, 44 GLint drawbuffer, 45 const GLuint *values) override; 46 angle::Result clearBufferiv(const gl::Context *context, 47 GLenum buffer, 48 GLint drawbuffer, 49 const GLint *values) override; 50 angle::Result clearBufferfi(const gl::Context *context, 51 GLenum buffer, 52 GLint drawbuffer, 53 GLfloat depth, 54 GLint stencil) override; 55 56 angle::Result readPixels(const gl::Context *context, 57 const gl::Rectangle &area, 58 GLenum format, 59 GLenum type, 60 const gl::PixelPackState &pack, 61 gl::Buffer *packBuffer, 62 void *pixels) override; 63 64 angle::Result blit(const gl::Context *context, 65 const gl::Rectangle &sourceArea, 66 const gl::Rectangle &destArea, 67 GLbitfield mask, 68 GLenum filter) override; 69 70 gl::FramebufferStatus checkStatus(const gl::Context *context) const override; 71 72 angle::Result syncState(const gl::Context *context, 73 GLenum binding, 74 const gl::Framebuffer::DirtyBits &dirtyBits, 75 gl::Command command) override; 76 77 angle::Result getSamplePosition(const gl::Context *context, 78 size_t index, 79 GLfloat *xy) const override; 80 81 RenderTargetWgpu *getReadPixelsRenderTarget() const; 82 83 void addNewColorAttachments(std::vector<wgpu::RenderPassColorAttachment> newColorAttachments); 84 85 void updateDepthStencilAttachment( 86 wgpu::RenderPassDepthStencilAttachment newRenderPassDepthStencilAttachment); 87 88 angle::Result flushOneColorAttachmentUpdate(const gl::Context *context, 89 bool deferClears, 90 uint32_t colorIndexGL); 91 92 angle::Result flushAttachmentUpdates(const gl::Context *context, 93 gl::DrawBufferMask dirtyColorAttachments, 94 bool dirtyDepthStencilAttachment, 95 bool deferColorClears, 96 bool deferDepthStencilClears); 97 98 angle::Result flushDeferredClears(ContextWgpu *contextWgpu); 99 100 // Starts a new render pass iff there are new color and/or depth/stencil attachments. 101 angle::Result startRenderPassNewAttachments(ContextWgpu *contextWgpu); 102 103 angle::Result startNewRenderPass(ContextWgpu *contextWgpu); 104 105 void setUpForRenderPass(ContextWgpu *contextWgpu, 106 bool depthOrStencil, 107 std::vector<wgpu::RenderPassColorAttachment> colorAttachments, 108 wgpu::RenderPassDepthStencilAttachment depthStencilAttachment); 109 getCurrentColorAttachmentFormats()110 const gl::DrawBuffersArray<wgpu::TextureFormat> &getCurrentColorAttachmentFormats() const 111 { 112 return mCurrentColorAttachmentFormats; 113 } 114 getCurrentDepthStencilAttachmentFormat()115 wgpu::TextureFormat getCurrentDepthStencilAttachmentFormat() const 116 { 117 return mCurrentDepthStencilFormat; 118 } 119 120 private: 121 void mergeClearWithDeferredClears(wgpu::Color clearValue, 122 gl::DrawBufferMask clearColorBuffers, 123 float depthValue, 124 uint32_t stencilValue, 125 bool clearColor, 126 bool clearDepth, 127 bool clearStencil); 128 129 RenderTargetCache<RenderTargetWgpu> mRenderTargetCache; 130 wgpu::RenderPassDescriptor mCurrentRenderPassDesc; 131 wgpu::RenderPassDepthStencilAttachment mCurrentDepthStencilAttachment; 132 std::vector<wgpu::RenderPassColorAttachment> mCurrentColorAttachments; 133 gl::DrawBuffersArray<wgpu::TextureFormat> mCurrentColorAttachmentFormats; 134 wgpu::TextureFormat mCurrentDepthStencilFormat = wgpu::TextureFormat::Undefined; 135 136 // Secondary vector to track new clears that are added and should be run in a new render pass 137 // during flushColorAttachmentUpdates. 138 std::vector<wgpu::RenderPassColorAttachment> mNewColorAttachments; 139 wgpu::RenderPassDepthStencilAttachment mNewDepthStencilAttachment; 140 bool mAddedNewDepthStencilAttachment = false; 141 142 webgpu::ClearValuesArray mDeferredClears; 143 }; 144 145 } // namespace rx 146 147 #endif // LIBANGLE_RENDERER_WGPU_FRAMEBUFFERWGPU_H_ 148