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