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

Code before:
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef TNT_FILAMENT_BACKEND_WEBGPUBLITTER_H
#define TNT_FILAMENT_BACKEND_WEBGPUBLITTER_H

#include <backend/DriverEnums.h>

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

#include <cstdint>

namespace filament::backend {

/**
 * A helper class for blitting textures.
 * This class provides a `blit` method that can copy a region from a source texture to a destination
 * texture. It handles different texture formats, and can perform filtering (nearest or linear).
 * It can also be used to resolve MSAA textures.
 *
 * The blitter maintains a cache of pipelines, pipeline layouts, and shader modules to avoid
 * creating them on every blit operation.
 */
class WebGPUBlitter final {
public:
    /**
     * A struct that contains the arguments for a blit operation.
     */
    struct BlitArgs final {
        /**
         * A struct that describes a texture attachment for a blit operation.
         */
        struct Attachment final {
            // The WebGPU texture to use for the attachment.
            wgpu::Texture const& texture;
            // The texture aspect to use (e.g., color, depth, stencil).
            wgpu::TextureAspect aspect{ wgpu::TextureAspect::Undefined };
            // The origin of the region to blit, in pixels.
            wgpu::Origin2D origin{};
            // The extent of the region to blit, in pixels.

Review comment (performance):
given my previous comments, how about?:

```cpp

/**
  * A blit essentially writes pixels to a region of one texture given a region of another texture.
  * Such a process can be a byte-by-byte copy when possible, while other scenarios involve various
  * transformations, such as pixel format conversion, image scaling, filtering/sampling
  * (such as down sampling), or even multi-sample resolves. Some blits can be faster than others,
  * depending on what is needed; for example, a byte-by-byte copy is generally faster than operations.
  *
  * This class is responsible for performing blits throughout the lifecycle of its owner/caller,
  * e.g. the WebGPU backend/driver, where it can leverage state to optimize such blit calls over time.
  */
```

Code after:
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef TNT_FILAMENT_BACKEND_WEBGPUBLITTER_H
#define TNT_FILAMENT_BACKEND_WEBGPUBLITTER_H

#include <backend/DriverEnums.h>

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

#include <cstdint>

namespace filament::backend {

/**
  * A blit essentially writes pixels to a region of one texture given a region of another texture.
  * Such a process can be a byte-by-byte copy when possible, while other scenarios involve various
  * transformations, such as pixel format conversion, image scaling, filtering/sampling
  * (such as down sampling), or even multi-sample resolves. Some blits can be faster than others,
  * depending on what is needed; for example, a byte-by-byte copy is generally faster than other
  * operations.
  *
  * This class is responsible for performing blits throughout the lifecycle of its owner/caller,
  * e.g. the WebGPU backend/driver, where it can leverage state to optimize such blit calls over time.
  */
class WebGPUBlitter final {
public:
    struct BlitArgs final {
        struct Attachment final {
            wgpu::Texture const& texture;
            wgpu::TextureAspect aspect{ wgpu::TextureAspect::Undefined };
            wgpu::Origin2D origin{};
            wgpu::Extent2D extent{};
            uint32_t mipLevel{ 0 };
            uint32_t layerOrDepth{ 0 };
        };

        Attachment source;
        Attachment destination;
        SamplerMagFilter filter;