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

Code before:
WebGPUSwapChain::WebGPUSwapChain(wgpu::Extent2D const& extent,
        wgpu::Adapter const& adapter, wgpu::Device const& device, uint64_t flags)
    : mDevice(device),
      mNeedStencil((flags & SWAP_CHAIN_HAS_STENCIL_BUFFER) != 0),
      mDepthFormat{selectDepthFormat(device.HasFeature(wgpu::FeatureName::Depth32FloatStencil8),
            mNeedStencil)},
      mDepthTexture{createDepthTexture(device, extent, mDepthFormat)},
      mDepthTextureView{createDepthTextureView(mDepthTexture, mDepthFormat, mNeedStencil)},
      mType(SwapChainType::HEADLESS),
      mHeadlessWidth(extent.width),
      mHeadlessHeight(extent.height){

    mConfig.format = wgpu::TextureFormat::RGBA8Unorm;
    mConfig.device = device;
    mConfig.usage = wgpu::TextureUsage::RenderAttachment;
    mConfig.width = extent.width;
    mConfig.height = extent.height;
    mConfig.presentMode = wgpu::PresentMode::Fifo;
    mConfig.alphaMode = wgpu::CompositeAlphaMode::Auto;

    mDepthFormat = selectDepthFormat(device.HasFeature(wgpu::FeatureName::Depth32FloatStencil8),
                mNeedStencil);
    const wgpu::TextureDescriptor textureDescriptor = {
        .usage = wgpu::TextureUsage::RenderAttachment | wgpu::TextureUsage::CopySrc,
        .dimension = wgpu::TextureDimension::e2D,
        .size = { mHeadlessWidth, mHeadlessHeight, 1 },
        .format = wgpu::TextureFormat::RGBA8Unorm,
        .mipLevelCount = 1,
        .sampleCount = 1,
    };

    for (size_t i = 0; i < mHeadlessBufferCount; ++i) {
        mRenderTargetTextures[i] = device.CreateTexture(&textureDescriptor);
        wgpu::TextureViewDescriptor viewDesc{};
        viewDesc.format = textureDescriptor.format;
        viewDesc.dimension = wgpu::TextureViewDimension::e2D;
        viewDesc.baseMipLevel = 0;
        viewDesc.mipLevelCount = 1;
        viewDesc.baseArrayLayer = 0;
        viewDesc.arrayLayerCount = 1;
        viewDesc.aspect = wgpu::TextureAspect::All;
        mRenderTargetViews[i] = mRenderTargetTextures[i].CreateView(&viewDesc);
        FILAMENT_CHECK_POSTCONDITION( mRenderTargetViews[i]) << "Failed to create headless texture with width "
                                               << extent.width << " and height " << extent.height;
    }
}

WebGPUSwapChain::~WebGPUSwapChain() {
    if (!isHeadless()) {
        mSurface.Unconfigure();
    }

Review comment (suggestion):
same comment as @AndyHovingh you could change it to 
```suggestion
        .size = { .width = mHeadlessWidth, .height = mHeadlessHeight, .depthOrArrayLayers = 1 },
```

Code after:
WebGPUSwapChain::WebGPUSwapChain(wgpu::Extent2D const& extent,
        wgpu::Adapter const& adapter, wgpu::Device const& device, uint64_t flags)
    : mDevice{device},
      mNeedStencil{(flags & SWAP_CHAIN_HAS_STENCIL_BUFFER) != 0},
      mDepthFormat{selectDepthFormat(device.HasFeature(wgpu::FeatureName::Depth32FloatStencil8),
            mNeedStencil)},
      mDepthTexture{createDepthTexture(device, extent, mDepthFormat)},
      mDepthTextureView{createDepthTextureView(mDepthTexture, mDepthFormat, mNeedStencil)},
      mType{SwapChainType::HEADLESS},
      mHeadlessWidth{extent.width},
      mHeadlessHeight{extent.height}{

    mConfig.format = wgpu::TextureFormat::RGBA8Unorm;
    mConfig.device = device;
    mConfig.usage = wgpu::TextureUsage::RenderAttachment;
    mConfig.width = extent.width;
    mConfig.height = extent.height;
    mConfig.presentMode = wgpu::PresentMode::Fifo;
    mConfig.alphaMode = wgpu::CompositeAlphaMode::Auto;

    mDepthFormat = selectDepthFormat(device.HasFeature(wgpu::FeatureName::Depth32FloatStencil8),
                mNeedStencil);
    const wgpu::TextureDescriptor textureDescriptor = {
        .usage = wgpu::TextureUsage::RenderAttachment | wgpu::TextureUsage::CopySrc,
        .dimension = wgpu::TextureDimension::e2D,
        .size = { .width = mHeadlessWidth, .height = mHeadlessHeight, .depthOrArrayLayers = 1 },
        .format = wgpu::TextureFormat::RGBA8Unorm,
        .mipLevelCount = 1,
        .sampleCount = 1,
    };

    const wgpu::TextureViewDescriptor viewDesc = {
        .format = textureDescriptor.format,
        .dimension = wgpu::TextureViewDimension::e2D,
        .baseMipLevel = 0,
        .mipLevelCount = 1,
        .baseArrayLayer = 0,
        .arrayLayerCount = 1,
        .aspect = wgpu::TextureAspect::All,
    };

    for (size_t i = 0; i < mHeadlessBufferCount; ++i) {
        mRenderTargetTextures[i] = device.CreateTexture(&textureDescriptor);
        mRenderTargetViews[i] = mRenderTargetTextures[i].CreateView(&viewDesc);
        FILAMENT_CHECK_POSTCONDITION( mRenderTargetViews[i]) << "Failed to create headless texture with width "
                                               << extent.width << " and height " << extent.height;
    }
}

WebGPUSwapChain::~WebGPUSwapChain() {
    if (!isHeadless()) {