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

Code before:

#include <webgpu/webgpu_cpp.h>

#include "DriverBase.h"
#include <backend/Platform.h>

#include <cstdint>

namespace filament::backend {

class WebGPUSwapChain final : public Platform::SwapChain, HwSwapChain {
public:
    WebGPUSwapChain(wgpu::Surface&& surface, wgpu::Extent2D const& extent,
            wgpu::Adapter const& adapter, wgpu::Device const& device, uint64_t flags);

    WebGPUSwapChain( wgpu::Extent2D const& extent,
            wgpu::Adapter const& adapter, wgpu::Device const& device, uint64_t flags);

    ~WebGPUSwapChain();

    [[nodiscard]] wgpu::TextureFormat getColorFormat() const { return mConfig.format; }

    [[nodiscard]] wgpu::TextureFormat getDepthFormat() const { return mDepthFormat; }

    [[nodiscard]] wgpu::TextureView getCurrentTextureView(wgpu::Extent2D const& extent);
    [[nodiscard]] wgpu::TextureView getCurrentTextureView();

    [[nodiscard]] wgpu::TextureView getDepthTextureView() const { return mDepthTextureView; }

    [[nodiscard]] bool isHeadless() const { return mType == SwapChainType::HEADLESS; }

    void present();

private:

    void setExtent(wgpu::Extent2D const&);

    wgpu::Device mDevice = nullptr;
    enum class SwapChainType {
        HEADLESS,
        SURFACE
    };

    wgpu::Surface mSurface = {};
    wgpu::SurfaceConfiguration mConfig = {};
    bool mNeedStencil = false;
    wgpu::TextureFormat mDepthFormat = wgpu::TextureFormat::Undefined;
    wgpu::Texture mDepthTexture = nullptr;
    wgpu::TextureView mDepthTextureView = nullptr;
    const SwapChainType mType;
    const uint32_t mHeadlessWidth;

Review comment (suggestion):
nit: I am wondering if it would help to indicate the purpose of this overload, such as calling it something like `getCurrentHeadlessTextureView()` or something; that might be more helpful and clear. Something to consider... your call.

Code after:

#include <webgpu/webgpu_cpp.h>

#include "DriverBase.h"
#include <backend/Platform.h>

#include <cstdint>

namespace filament::backend {

class WebGPUSwapChain final : public Platform::SwapChain, HwSwapChain {
public:
    WebGPUSwapChain(wgpu::Surface&& surface, wgpu::Extent2D const& extent,
            wgpu::Adapter const& adapter, wgpu::Device const& device, uint64_t flags);

    WebGPUSwapChain( wgpu::Extent2D const& extent,
            wgpu::Adapter const& adapter, wgpu::Device const& device, uint64_t flags);

    ~WebGPUSwapChain();

    [[nodiscard]] wgpu::TextureFormat getColorFormat() const { return mConfig.format; }

    [[nodiscard]] wgpu::TextureFormat getDepthFormat() const { return mDepthFormat; }

    [[nodiscard]] wgpu::TextureView getCurrentTextureView(wgpu::Extent2D const& extent);
    [[nodiscard]] wgpu::TextureView getCurrentHeadlessTextureView();

    [[nodiscard]] wgpu::TextureView getDepthTextureView() const { return mDepthTextureView; }

    [[nodiscard]] bool isHeadless() const { return mType == SwapChainType::HEADLESS; }

    void present();

private:

    void setExtent(wgpu::Extent2D const&);

    wgpu::Device mDevice = nullptr;
    enum class SwapChainType {
        HEADLESS,
        SURFACE
    };

    wgpu::Surface mSurface = {};
    wgpu::SurfaceConfiguration mConfig = {};
    bool mNeedStencil = false;
    wgpu::TextureFormat mDepthFormat = wgpu::TextureFormat::Undefined;
    wgpu::Texture mDepthTexture = nullptr;
    wgpu::TextureView mDepthTextureView = nullptr;
    const SwapChainType mType;
    const uint32_t mHeadlessWidth;