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

Code before:
    if (width < 1 || height < 1) {
        PANIC_LOG("WebGPUSwapChain::GetCurrentTexture: Invalid width and/or height requested.");
        return;
    }
    if (mConfig.width != width || mConfig.height != height || !mConfigured) {
        mConfig.width = width;
        mConfig.height = height;
#if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM)
        printSurfaceConfiguration(mConfig);
#endif
        mSurface.Configure(&mConfig);
        mConfigured = true;
    }

    mSurface.GetCurrentTexture(texture);
}

wgpu::TextureView WebGPUSwapChain::GetNextSurfaceTextureView(uint32_t width, uint32_t height) {
    wgpu::SurfaceTexture surfaceTexture;
    GetCurrentTexture(width, height, &surfaceTexture);
    if (surfaceTexture.status != wgpu::SurfaceGetCurrentTextureStatus::SuccessOptimal) {
        return nullptr;
    }

    // Create a view for this surface texture
    wgpu::TextureViewDescriptor textureViewDescriptor;
    textureViewDescriptor.nextInChain = nullptr;
    textureViewDescriptor.label = "webgpu_texture_view";
    textureViewDescriptor.format = surfaceTexture.texture.GetFormat();
    textureViewDescriptor.dimension = wgpu::TextureViewDimension::e2D;
    textureViewDescriptor.baseMipLevel = 0;
    textureViewDescriptor.mipLevelCount = 1;
    textureViewDescriptor.baseArrayLayer = 0;
    textureViewDescriptor.arrayLayerCount = 1;
    textureViewDescriptor.aspect = wgpu::TextureAspect::All;
    wgpu::TextureView textureView = surfaceTexture.texture.CreateView(&textureViewDescriptor);

    return textureView;
}

void WebGPUSwapChain::Present() {
    assert_invariant(mSurface);
    mSurface.Present();
}

}// namespace filament::backend


Review comment (suggestion):
please consider: 
```cpp
wgpu::TextureViewDescriptor textureViewDescriptor = {
    .label = "texture_view",
    .format = surfaceTexture.texture.GetFormat(),
    .dimension = wgpu::TextureViewDimension::e2D,
    .baseMipLevel = 0,
    .mipLevelCount = 1,
    .baseArrayLayer = 0,
    .arrayLayerCount = 1,
    .aspect = wgpu::TextureAspect::All
};
```

Code after:
    if (width < 1 || height < 1) {
        PANIC_LOG("WebGPUSwapChain::GetCurrentTexture: Invalid width and/or height requested.");
        return;
    }
    if (mConfig.width != width || mConfig.height != height || !mConfigured) {
        mConfig.width = width;
        mConfig.height = height;
#if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM)
        printSurfaceConfiguration(mConfig);
#endif
        mSurface.Configure(&mConfig);
        mConfigured = true;
    }

    mSurface.GetCurrentTexture(texture);
}

wgpu::TextureView WebGPUSwapChain::getNextSurfaceTextureView(uint32_t width, uint32_t height) {
    wgpu::SurfaceTexture surfaceTexture;
    getCurrentTexture(width, height, &surfaceTexture);
    if (surfaceTexture.status != wgpu::SurfaceGetCurrentTextureStatus::SuccessOptimal) {
        return nullptr;
    }

    // Create a view for this surface texture
    //TODO: review these initiliazations as webgpu pipeline gets mature
    wgpu::TextureViewDescriptor textureViewDescriptor = {
        .label = "texture_view",
        .format = surfaceTexture.texture.GetFormat(),
        .dimension = wgpu::TextureViewDimension::e2D,
        .baseMipLevel = 0,
        .mipLevelCount = 1,
        .baseArrayLayer = 0,
        .arrayLayerCount = 1
    };
    return surfaceTexture.texture.CreateView(&textureViewDescriptor);
}

void WebGPUSwapChain::present() {
    assert_invariant(mSurface);
    mSurface.Present();
}

}// namespace filament::backend