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

Code before:
    uint32_t width = wgpuTexture.GetWidth();
    uint32_t height = wgpuTexture.GetHeight();
    // For 3D textures, depth is > 1. For 2D/Cube/Array, effectively 1 for mip-level copies.
    uint32_t depth =
            (texture->target == SamplerType::SAMPLER_3D) ? wgpuTexture.GetDepthOrArrayLayers() : 1;

    for (uint32_t mipLevel = 0; mipLevel < mipLevelCount - 1; ++mipLevel) {
        wgpu::TexelCopyTextureInfo sourceCopyInfo{
            .texture = wgpuTexture,
            .mipLevel = mipLevel,
            .aspect = texture->getAspect(),
        };

        wgpu::TexelCopyTextureInfo destinationCopyInfo{
            .texture = wgpuTexture,
            .mipLevel = mipLevel + 1,
            .aspect = texture->getAspect(),
        };

        uint32_t dstWidth = std::max(1u, width >> 1);
        uint32_t dstHeight = std::max(1u, height >> 1);
        uint32_t dstDepth = std::max(1u, depth >> 1);

        wgpu::Extent3D copySize = { dstWidth, dstHeight,
            (texture->target == SamplerType::SAMPLER_3D) ? dstDepth
                                                         : texture->getArrayLayerCount() };

        mCommandEncoder.CopyTextureToTexture(&sourceCopyInfo, &destinationCopyInfo, &copySize);

        width = dstWidth;
        height = dstHeight;
        depth = dstDepth;
    }
}

void WebGPUDriver::compilePrograms(CompilerPriorityQueue priority,
        CallbackHandler* handler, CallbackHandler::Callback callback, void* user) {
    if (callback) {
        scheduleCallback(handler, user, callback);
    }
}

void WebGPUDriver::beginRenderPass(Handle<HwRenderTarget> rth, RenderPassParams const& params) {
    assert_invariant(mCommandEncoder);
    auto* renderTarget = handleCast<WGPURenderTarget>(rth);

    wgpu::TextureView defaultColorView = nullptr;
    wgpu::TextureView defaultDepthStencilView = nullptr;

    std::array<wgpu::TextureView, MRT::MAX_SUPPORTED_RENDER_TARGET_COUNT> customColorViews{};
    uint32_t customColorViewCount = 0;

Review comment (suggestion):
for consistency I would change this to 
```
 wgpu::Extent3D{ .width = dstWidth, .height = dstHeight, .depthOrArrayLayers = (texture->target == SamplerType::SAMPLER_3D) ? dstDepth
                                                         : texture->getArrayLayerCount() };
```

Code after:
    uint32_t height = wgpuTexture.GetHeight();
    // For 3D textures, depth is > 1. For 2D/Cube/Array, effectively 1 for mip-level copies.
    uint32_t depth =
            (texture->target == SamplerType::SAMPLER_3D) ? wgpuTexture.GetDepthOrArrayLayers() : 1;

    for (uint32_t mipLevel = 0; mipLevel < mipLevelCount - 1; ++mipLevel) {
        wgpu::TexelCopyTextureInfo sourceCopyInfo{
            .texture = wgpuTexture,
            .mipLevel = mipLevel,
            .aspect = texture->getAspect(),
        };

        wgpu::TexelCopyTextureInfo destinationCopyInfo{
            .texture = wgpuTexture,
            .mipLevel = mipLevel + 1,
            .aspect = texture->getAspect(),
        };

        uint32_t dstWidth = std::max(1u, width >> 1);
        uint32_t dstHeight = std::max(1u, height >> 1);
        uint32_t dstDepth = std::max(1u, depth >> 1);

        wgpu::Extent3D copySize{ .width = dstWidth,
            .height = dstHeight,
            .depthOrArrayLayers = (texture->target == SamplerType::SAMPLER_3D)
                                          ? dstDepth
                                          : texture->getArrayLayerCount() };
        mCommandEncoder.CopyTextureToTexture(&sourceCopyInfo, &destinationCopyInfo, &copySize);

        width = dstWidth;
        height = dstHeight;
        depth = dstDepth;
    }
}

void WebGPUDriver::compilePrograms(CompilerPriorityQueue priority,
        CallbackHandler* handler, CallbackHandler::Callback callback, void* user) {
    if (callback) {
        scheduleCallback(handler, user, callback);
    }
}

void WebGPUDriver::beginRenderPass(Handle<HwRenderTarget> rth, RenderPassParams const& params) {
    assert_invariant(mCommandEncoder);
    auto* renderTarget = handleCast<WGPURenderTarget>(rth);

    wgpu::TextureView defaultColorView = nullptr;
    wgpu::TextureView defaultDepthStencilView = nullptr;

    std::array<wgpu::TextureView, MRT::MAX_SUPPORTED_RENDER_TARGET_COUNT> customColorViews{};
    uint32_t customColorViewCount = 0;