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

Code before:
                    << "Requested Filament texture format RGB32UI but getting "
                       "wgpu::TextureFormat::RGBA32Uint (no direct mapping in wgpu without alpha)"
                    << utils::io::endl;
            return wgpu::TextureFormat::RGBA32Uint;
        case TextureFormat::RGB32I:
            FWGPU_LOGW
                    << "Requested Filament texture format RGB32I but getting "
                       "wgpu::TextureFormat::RGBA32Sint (no direct mapping in wgpu without alpha)"
                    << utils::io::endl;
            return wgpu::TextureFormat::RGBA32Sint;
        case TextureFormat::DXT1_RGB:                return wgpu::TextureFormat::BC1RGBAUnorm;
        case TextureFormat::DXT1_RGBA:               return wgpu::TextureFormat::BC1RGBAUnorm;
        case TextureFormat::DXT3_RGBA:               return wgpu::TextureFormat::BC2RGBAUnorm;
        case TextureFormat::DXT5_RGBA:               return wgpu::TextureFormat::BC3RGBAUnorm;
        case TextureFormat::DXT1_SRGB:               return wgpu::TextureFormat::BC1RGBAUnormSrgb;
        case TextureFormat::DXT1_SRGBA:              return wgpu::TextureFormat::BC1RGBAUnormSrgb;
        case TextureFormat::DXT3_SRGBA:              return wgpu::TextureFormat::BC2RGBAUnormSrgb;
        case TextureFormat::DXT5_SRGBA:              return wgpu::TextureFormat::BC3RGBAUnormSrgb;
    }
}

wgpu::TextureView WebGPUTexture::makeTextureView(const uint8_t& baseLevel,
        const uint8_t& levelCount, const uint32_t& baseArrayLayer, const uint32_t& arrayLayerCount,
        const SamplerType samplerType) const noexcept {
    if (baseLevel > 0 && !mSupportsMultipleMipLevels) {
        FWGPU_LOGW << "Trying to make a texture view into a level (" << baseLevel
                   << ") for which we cannot generate mip levels." << utils::io::endl;
    }
    const wgpu::TextureViewDescriptor textureViewDescriptor{
        .label = getUserTextureViewLabel(target),
        .format = mViewFormat,
        .dimension = toWebGPUTextureViewDimension(samplerType),
        .baseMipLevel = baseLevel,
        .mipLevelCount = levelCount,
        .baseArrayLayer = baseArrayLayer,
        .arrayLayerCount = arrayLayerCount,
        .aspect = mAspect,
        .usage = mViewUsage };
    wgpu::TextureView textureView = mTexture.CreateView(&textureViewDescriptor);
    FILAMENT_CHECK_POSTCONDITION(textureView)
            << "Failed to create texture view " << textureViewDescriptor.label;
    return textureView;
}

}// namespace filament::backend


Review comment (suggestion):
We discussed in chat, but noting here: IMO we can make this a verbose log of something. In the actual generate mippmap function we can check the usage at the time of use and panic if the bit didn't get set here.

Code after:

wgpu::TextureView WebGPUTexture::makeTextureView(const uint8_t& baseLevel,
        const uint8_t& levelCount, const uint32_t& baseArrayLayer, const uint32_t& arrayLayerCount,
        const SamplerType samplerType) const noexcept {
#if FWGPU_ENABLED(FWGPU_DEBUG_VALIDATION)
    if (baseLevel > 0 && !mSupportsMultipleMipLevels) {
        FWGPU_LOGW << "Trying to make a texture view into a level ("
                   << static_cast<uint32_t>(baseLevel)
                   << ") for which we cannot generate mip levels." << utils::io::endl;
    }
#endif
    const wgpu::TextureViewDescriptor textureViewDescriptor{
        .label = getUserTextureViewLabel(target),
        .format = mViewFormat,
        .dimension = toWebGPUTextureViewDimension(samplerType),
        .baseMipLevel = baseLevel,
        .mipLevelCount = levelCount,
        .baseArrayLayer = baseArrayLayer,
        .arrayLayerCount = arrayLayerCount,
        .aspect = mAspect,
        .usage = mViewUsage };
    wgpu::TextureView textureView = mTexture.CreateView(&textureViewDescriptor);
    FILAMENT_CHECK_POSTCONDITION(textureView)
            << "Failed to create texture view " << textureViewDescriptor.label;
    return textureView;
}

}// namespace filament::backend