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

Code before:
namespace filament::backend {

/**
 * WebGPU backend (driver) implementation
 */
class WebGPUDriver final : public DriverBase {
public:
    ~WebGPUDriver() noexcept override;

    [[nodiscard]] Dispatcher getDispatcher() const noexcept final;
    [[nodiscard]] static Driver* create(WebGPUPlatform& platform, const Platform::DriverConfig& driverConfig) noexcept;

private:
    explicit WebGPUDriver(WebGPUPlatform& platform, const Platform::DriverConfig& driverConfig) noexcept;
    [[nodiscard]] ShaderModel getShaderModel() const noexcept final;
    [[nodiscard]] ShaderLanguage getShaderLanguage() const noexcept final;

    // the platform (e.g. OS) specific aspects of the WebGPU backend are strictly only
    // handled in the WebGPUPlatform
    WebGPUPlatform& mPlatform;
    wgpu::Adapter mAdapter = nullptr;
    wgpu::Device mDevice = nullptr;
    wgpu::Queue mQueue = nullptr;
    // TODO consider moving to handle allocator when ready
    std::unique_ptr<WebGPUSwapChain> mSwapChain = nullptr;
    uint64_t mNextFakeHandle = 1;
    wgpu::CommandEncoder mCommandEncoder = nullptr;
    wgpu::TextureView mTextureView = nullptr;
    wgpu::RenderPassEncoder mRenderPassEncoder = nullptr;
    wgpu::CommandBuffer mCommandBuffer = nullptr;
    WGPURenderTarget* mDefaultRenderTarget = nullptr;
    /*
     * Driver interface
     */
    template<typename T>
    friend class ConcreteDispatcher;

#define DECL_DRIVER_API(methodName, paramsDecl, params)                                            \
    UTILS_ALWAYS_INLINE inline void methodName(paramsDecl);

#define DECL_DRIVER_API_SYNCHRONOUS(RetType, methodName, paramsDecl, params)                       \
    RetType methodName(paramsDecl) override;

#define DECL_DRIVER_API_RETURN(RetType, methodName, paramsDecl, params)                            \
    RetType methodName##S() noexcept override;                                                     \
    UTILS_ALWAYS_INLINE inline void methodName##R(RetType, paramsDecl);

#include "private/backend/DriverAPI.inc"

    /*
     * Memory management

Review comment (refactor):
This name is probably fine; concise but meaningful names are great. Just thinking out-loud, but I wonder if later we might want to add clarity that this is the surface texture view vs a view to an arbitrary texture of some kind. I wonder if `mSurfaceTextureView`, or even `mSurfaceColorTextureView` would be more helpful. Just a thought. Or maybe we just refactor when that becomes more obvious.

Code after:
/**
 * WebGPU backend (driver) implementation
 */
class WebGPUDriver final : public DriverBase {
public:
    ~WebGPUDriver() noexcept override;

    [[nodiscard]] Dispatcher getDispatcher() const noexcept final;
    [[nodiscard]] static Driver* create(WebGPUPlatform& platform, const Platform::DriverConfig& driverConfig) noexcept;

private:
    explicit WebGPUDriver(WebGPUPlatform& platform, const Platform::DriverConfig& driverConfig) noexcept;
    [[nodiscard]] ShaderModel getShaderModel() const noexcept final;
    [[nodiscard]] ShaderLanguage getShaderLanguage() const noexcept final;

    // the platform (e.g. OS) specific aspects of the WebGPU backend are strictly only
    // handled in the WebGPUPlatform
    WebGPUPlatform& mPlatform;
    wgpu::Adapter mAdapter = nullptr;
    wgpu::Device mDevice = nullptr;
    wgpu::Queue mQueue = nullptr;
    // TODO consider moving to handle allocator when ready
    std::unique_ptr<WebGPUSwapChain> mSwapChain = nullptr;
    uint64_t mNextFakeHandle = 1;
    wgpu::CommandEncoder mCommandEncoder = nullptr;
    wgpu::TextureView mTextureView = nullptr;
    wgpu::RenderPassEncoder mRenderPassEncoder = nullptr;
    wgpu::CommandBuffer mCommandBuffer = nullptr;
    WGPURenderTarget* mDefaultRenderTarget = nullptr;
    /*
     * Driver interface
     */
    template<typename T>
    friend class ConcreteDispatcher;

#define DECL_DRIVER_API(methodName, paramsDecl, params)                                            \
    UTILS_ALWAYS_INLINE inline void methodName(paramsDecl);

#define DECL_DRIVER_API_SYNCHRONOUS(RetType, methodName, paramsDecl, params)                       \
    RetType methodName(paramsDecl) override;

#define DECL_DRIVER_API_RETURN(RetType, methodName, paramsDecl, params)                            \
    RetType methodName##S() noexcept override;                                                     \
    UTILS_ALWAYS_INLINE inline void methodName##R(RetType, paramsDecl);

#include "private/backend/DriverAPI.inc"

    /*
     * Memory management
     */