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

Code before:

#include <utils/Panic.h>

#include <tsl/robin_map.h>
#include <webgpu/webgpu_cpp.h>

#include <cstdint>
#include <string_view>

namespace filament::backend {

/**
 * A utility class for generating mipmaps for a texture using a series of render passes.
 * This approach is used for formats that do not support storage bindings, which are required
 * for the compute-based mipmap generation.
 */
class WebGPURenderPassMipmapGenerator final {
public:
    struct FormatCompatibility final {
        bool compatible{ false };
        std::string_view reason;
    };

    /**
     * Checks if a given texture format is compatible with render pass-based mipmap generation.
     * @param format The texture format.
     * @param dimension The texture dimension.
     * @param sampleCount The number of samples.
     * @return A FormatCompatibility struct indicating whether the format is compatible and a reason if not.
     */
    [[nodiscard]] static FormatCompatibility getCompatibilityFor(wgpu::TextureFormat,
            wgpu::TextureDimension, uint32_t sampleCount);

    explicit WebGPURenderPassMipmapGenerator(wgpu::Device const&);

    /**
     * IMPORTANT NOTE: when reusing a command encoder and/or textures make sure to flush/submit
     * pending commands (draws, etc.) to the GPU prior to calling this call, because texture updates
     * may otherwise (unintentionally) happen after draw commands encoded in the encoder.
     * Submitting any commands up to this point ensures the calls happen in the expected
     * sequence.
     */
    void generateMipmaps(wgpu::Queue const&, wgpu::Texture const&);

private:
    enum class ScalarSampleType : uint8_t {
        F32,
        I32,
        U32,
    };


Review comment (suggestion):
I think the `@param...` and `@return...` lines can be removed, as they don't add meaningful/helpful value

Code after:

#include <utils/Panic.h>

#include <tsl/robin_map.h>
#include <webgpu/webgpu_cpp.h>

#include <cstdint>
#include <string_view>

namespace filament::backend {

/**
 * A utility class for generating mipmaps for a texture using a series of render passes.
 */
class WebGPURenderPassMipmapGenerator final {
public:
    struct FormatCompatibility final {
        bool compatible{ false };
        std::string_view reason;
    };

    /**
     * Checks if a given texture format is compatible with render pass-based mipmap generation.
     * @return A FormatCompatibility struct indicating whether the format is compatible
     *         and a reason if not.
     */
    [[nodiscard]] static FormatCompatibility getCompatibilityFor(wgpu::TextureFormat,
            wgpu::TextureDimension, uint32_t sampleCount);

    explicit WebGPURenderPassMipmapGenerator(wgpu::Device const&);

    /**
     * IMPORTANT NOTE: when reusing a command encoder and/or textures make sure to flush/submit
     * pending commands (draws, etc.) to the GPU prior to calling this call, because texture updates
     * may otherwise (unintentionally) happen after draw commands encoded in the encoder.
     * Submitting any commands up to this point ensures the calls happen in the expected
     * sequence.
     */
    void generateMipmaps(wgpu::Queue const&, wgpu::Texture const&);

private:
    enum class ScalarSampleType : uint8_t {
        F32,
        I32,
        U32,
    };

    [[nodiscard]] constexpr static ScalarSampleType getScalarSampleTypeFrom(
            wgpu::TextureFormat format);

    [[nodiscard]] wgpu::RenderPipeline& getOrCreatePipelineFor(wgpu::TextureFormat);