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

Code before:
        } else if (depthFormat == wgpu::TextureFormat::Depth24PlusStencil8) {
            descriptor.format = wgpu::TextureFormat::Depth24Plus;
        } else {
            descriptor.format = depthFormat;
        }
    }
    wgpu::TextureView depthTextureView = depthTexture.CreateView(&descriptor);
    FILAMENT_CHECK_POSTCONDITION(depthTextureView) << "Failed to create depth texture view";
    return depthTextureView;
}

}// namespace

WebGPUSwapChain::WebGPUSwapChain(wgpu::Surface&& surface, wgpu::Extent2D const& extent,
        wgpu::Adapter const& adapter, wgpu::Device const& device, uint64_t flags)
    : mDevice(device),
      mSurface(surface),
      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::SURFACE),
      mHeadlessWidth(0),
      mHeadlessHeight(0) {

    wgpu::SurfaceCapabilities capabilities = {};
    if (!mSurface.GetCapabilities(adapter, &capabilities)) {
        FWGPU_LOGW << "Failed to get WebGPU surface capabilities";
    } else {
#if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM)
        printSurfaceCapabilitiesDetails(capabilities);
#endif
    }
    const bool useSRGBColorSpace = (flags & SWAP_CHAIN_CONFIG_SRGB_COLORSPACE) != 0;

    initConfig(mConfig, device, capabilities, extent, useSRGBColorSpace);
    mDepthFormat = selectDepthFormat(device.HasFeature(wgpu::FeatureName::Depth32FloatStencil8),
            mNeedStencil);
#if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM)
    printSurfaceConfiguration(mConfig, mDepthFormat);
#endif
    mSurface.Configure(&mConfig);
}

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)},

Review comment (suggestion):
not sure if outside of the PR but we've been initializing values with `{}` and not `()`
it may be worth updating the ones under `WebGPUSwapChain`

Code after:
        } else if (depthFormat == wgpu::TextureFormat::Depth24PlusStencil8) {
            descriptor.format = wgpu::TextureFormat::Depth24Plus;
        } else {
            descriptor.format = depthFormat;
        }
    }
    wgpu::TextureView depthTextureView = depthTexture.CreateView(&descriptor);
    FILAMENT_CHECK_POSTCONDITION(depthTextureView) << "Failed to create depth texture view";
    return depthTextureView;
}

}// namespace

WebGPUSwapChain::WebGPUSwapChain(wgpu::Surface&& surface, wgpu::Extent2D const& extent,
        wgpu::Adapter const& adapter, wgpu::Device const& device, uint64_t flags)
    : mDevice{device},
      mSurface{surface},
      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::SURFACE},
      mHeadlessWidth{0},
      mHeadlessHeight{0} {

    wgpu::SurfaceCapabilities capabilities = {};
    if (!mSurface.GetCapabilities(adapter, &capabilities)) {
        FWGPU_LOGW << "Failed to get WebGPU surface capabilities";
    } else {
#if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM)
        printSurfaceCapabilitiesDetails(capabilities);
#endif
    }
    const bool useSRGBColorSpace = (flags & SWAP_CHAIN_CONFIG_SRGB_COLORSPACE) != 0;

    initConfig(mConfig, device, capabilities, extent, useSRGBColorSpace);
    mDepthFormat = selectDepthFormat(device.HasFeature(wgpu::FeatureName::Depth32FloatStencil8),
            mNeedStencil);
#if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM)
    printSurfaceConfiguration(mConfig, mDepthFormat);
#endif
    mSurface.Configure(&mConfig);
}

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)},