Repository: google/filament
File: filament/backend/src/webgpu/WebGPURenderTarget.h (C/C++)

Code before:
            wgpu::TextureView const* customColorTextureViews,            // Array of views
            wgpu::TextureView const* customColorMsaaSidecarTextureViews, // nullptrs if N/A
            uint32_t customColorTextureViewCount,
            wgpu::TextureView const& customDepthStencilTextureView,
            wgpu::TextureView const& customDepthStencilMsaaSidecarTextureView /* nullptr if N/A */);

    [[nodiscard]] bool isDefaultRenderTarget() const { return mDefaultRenderTarget; }
    [[nodiscard]] uint8_t getSamples() const { return mSamples; }
    [[nodiscard]] uint8_t getSampleCountPerAttachment() const { return mSampleCountPerAttachment; }
    [[nodiscard]] uint8_t getLayerCount() const { return mLayerCount; }

    [[nodiscard]] MRT const& getColorAttachmentInfos() const { return mColorAttachments; }
    [[nodiscard]] Attachment const& getDepthAttachmentInfo() const { return mDepthAttachment; }
    [[nodiscard]] Attachment const& getStencilAttachmentInfo() const { return mStencilAttachment; }

    [[nodiscard]] static wgpu::LoadOp getLoadOperation(RenderPassParams const& params,
            TargetBufferFlags buffer);
    [[nodiscard]] static wgpu::StoreOp getStoreOperation(RenderPassParams const& params,
            TargetBufferFlags buffer);

    [[nodiscard]] TargetBufferFlags getTargetFlags() const { return mTargetFlags; }
    void setTargetFlags( TargetBufferFlags value) { mTargetFlags = value; }

private:
    bool mDefaultRenderTarget = false;
    TargetBufferFlags mTargetFlags = TargetBufferFlags::NONE;
    uint8_t mSamples = 1;
    uint8_t mLayerCount = 1;

    MRT mColorAttachments{};
    // WebGPU only supports a single depth/stencil attachment.
    Attachment mDepthAttachment{};
    Attachment mStencilAttachment{};

    uint8_t mSampleCountPerAttachment = 0;

    // Cached descriptors for the render pass
    std::vector<wgpu::RenderPassColorAttachment> mColorAttachmentDesc;
    wgpu::RenderPassDepthStencilAttachment mDepthStencilAttachmentDesc{};
    bool mHasDepthStencilAttachment = false;
};

}// namespace filament::backend

#endif// TNT_FILAMENT_BACKEND_WEBGPUHANDLES_H


Review comment (suggestion):
I would keep the original comment, as it gets more to the relevant point. Should we still have 2 attributes here, `mDepthAttachment` and `mStencilAttachment` or should we consolidate to `mDepthStencilAttachment` due to how WebGPU works? I'm not sure, but it we might have an opportunity here to simplfy things if possible.

Code after:
            wgpu::TextureView const* customColorTextureViews,            // Array of views
            wgpu::TextureView const* customColorMsaaSidecarTextureViews, // nullptrs if N/A
            uint32_t customColorTextureViewCount,
            wgpu::TextureView const& customDepthStencilTextureView,
            wgpu::TextureView const& customDepthStencilMsaaSidecarTextureView /* nullptr if N/A */);

    [[nodiscard]] bool isDefaultRenderTarget() const { return mDefaultRenderTarget; }
    [[nodiscard]] uint8_t getSamples() const { return mSamples; }
    [[nodiscard]] uint8_t getSampleCountPerAttachment() const { return mSampleCountPerAttachment; }
    [[nodiscard]] uint8_t getLayerCount() const { return mLayerCount; }

    [[nodiscard]] MRT const& getColorAttachmentInfos() const { return mColorAttachments; }
    [[nodiscard]] Attachment const& getDepthAttachmentInfo() const { return mDepthAttachment; }
    [[nodiscard]] Attachment const& getStencilAttachmentInfo() const { return mStencilAttachment; }

    [[nodiscard]] static wgpu::LoadOp getLoadOperation(RenderPassParams const& params,
            TargetBufferFlags buffer);
    [[nodiscard]] static wgpu::StoreOp getStoreOperation(RenderPassParams const& params,
            TargetBufferFlags buffer);

    [[nodiscard]] TargetBufferFlags getTargetFlags() const { return mTargetFlags; }
    void setTargetFlags( TargetBufferFlags value) { mTargetFlags = value; }

private:
    bool mDefaultRenderTarget = false;
    TargetBufferFlags mTargetFlags = TargetBufferFlags::NONE;
    uint8_t mSamples = 1;
    uint8_t mLayerCount = 1;

    MRT mColorAttachments{};
    // TODO WebGPU only supports a DepthStencil attachment, should this be just
    // mDepthStencilAttachment?
    Attachment mDepthAttachment{};
    Attachment mStencilAttachment{};

    uint8_t mSampleCountPerAttachment = 0;

    // Cached descriptors for the render pass
    std::vector<wgpu::RenderPassColorAttachment> mColorAttachmentDesc;
    wgpu::RenderPassDepthStencilAttachment mDepthStencilAttachmentDesc{};
    bool mHasDepthStencilAttachment = false;
};

}// namespace filament::backend

#endif// TNT_FILAMENT_BACKEND_WEBGPUHANDLES_H