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

Code before:

#include <webgpu/webgpu_cpp.h>

#include <cstdint>

namespace filament::backend {

class WebGPUTexture : public HwTexture {
public:
    enum class MipmapGenerationStrategy : uint8_t {
        RENDER_PASS,
        SPD_COMPUTE_PASS,
        NONE,
    };

    WebGPUTexture(SamplerType, uint8_t levels, TextureFormat, uint8_t samples, uint32_t width,
            uint32_t height, uint32_t depth, TextureUsage, wgpu::Device const&) noexcept;

    WebGPUTexture(WebGPUTexture const* src, uint8_t baseLevel, uint8_t levelCount) noexcept;

    WebGPUTexture(WebGPUTexture const* source, wgpu::TextureView textureView) noexcept;

    [[nodiscard]] wgpu::TextureAspect getAspect() const { return mAspect; }

    [[nodiscard]] size_t getBlockWidth() const { return mBlockWidth; }

    [[nodiscard]] size_t getBlockHeight() const { return mBlockHeight; }

    [[nodiscard]] wgpu::Texture const& getTexture() const { return mTexture; }

    [[nodiscard]] wgpu::Texture const& getMsaaSidecarTexture(uint8_t sampleCount) const;

    [[nodiscard]] wgpu::TextureView const& getDefaultTextureView() const {
        return mDefaultTextureView;
    }

    [[nodiscard]] wgpu::TextureView makeAttachmentTextureView(uint8_t mipLevel, uint32_t arrayLayer,
            uint32_t layerCount);

    [[nodiscard]] wgpu::TextureViewDimension getViewDimension() const { return mDimension; }
    [[nodiscard]] wgpu::TextureFormat getViewFormat() const { return mViewFormat; }

    [[nodiscard]] uint32_t getArrayLayerCount() const { return mArrayLayerCount; }

    [[nodiscard]] MipmapGenerationStrategy getMipmapGenerationStrategy() const {
        return mMipmapGenerationStrategy;
    }

    /**
     * Creates the MSAA sidecar texture if it has not already been created.
     * If the sidecar already exists with a different number of samples this will panic

Review comment (suggestion):
I think we could add a comment on this constructor calling it out as a "Filament Texture View", where the underlying texture is the same as the source, but the view elements differ. Similarly, we could comment on the new constructor as the "Filament Swizzle Texture View". 

Code after:

#include <webgpu/webgpu_cpp.h>

#include <cstdint>

namespace filament::backend {

class WebGPUTexture : public HwTexture {
public:
    enum class MipmapGenerationStrategy : uint8_t {
        RENDER_PASS,
        SPD_COMPUTE_PASS,
        NONE,
    };

    /**
     * Creates a Filament texture and a texture view
     */
    WebGPUTexture(SamplerType, uint8_t levels, TextureFormat, uint8_t samples, uint32_t width,
            uint32_t height, uint32_t depth, TextureUsage, wgpu::Device const&) noexcept;

    /**
     * Creates a "Filament Texture View", where the underlying texture is the same as the source,
     * but the view elements differ
     */
    WebGPUTexture(WebGPUTexture const* src, uint8_t baseLevel, uint8_t levelCount) noexcept;

    /**
     * @param textureView texture view to use for the respective texture. e.g. it can be a
     *                    swizzled Texture view for that filament texture
     *
     * Associates the underlying texture with the given texture view
     */
    WebGPUTexture(WebGPUTexture const* source, wgpu::TextureView textureView) noexcept;

    [[nodiscard]] wgpu::TextureAspect getAspect() const { return mAspect; }

    [[nodiscard]] size_t getBlockWidth() const { return mBlockWidth; }

    [[nodiscard]] size_t getBlockHeight() const { return mBlockHeight; }

    [[nodiscard]] wgpu::Texture const& getTexture() const { return mTexture; }

    [[nodiscard]] wgpu::Texture const& getMsaaSidecarTexture(uint8_t sampleCount) const;

    [[nodiscard]] wgpu::TextureView const& getDefaultTextureView() const {
        return mDefaultTextureView;
    }

    [[nodiscard]] wgpu::TextureView makeAttachmentTextureView(uint8_t mipLevel, uint32_t arrayLayer,
            uint32_t layerCount);