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

Code before:
        destructHandle<WGPUBufferObject>(boh);
    }
}

void WebGPUDriver::destroyTexture(Handle<HwTexture> th) {
}

void WebGPUDriver::destroyProgram(Handle<HwProgram> ph) {
    if (ph) {
        destructHandle<WGPUProgram>(ph);
    }
}

void WebGPUDriver::destroyRenderTarget(Handle<HwRenderTarget> rth) {
}

void WebGPUDriver::destroySwapChain(Handle<HwSwapChain> sch) {
    if (sch) {
        destructHandle<WebGPUSwapChain>(sch);
    }
    mSwapChain = nullptr;
}

void WebGPUDriver::destroyStream(Handle<HwStream> sh) {
}

void WebGPUDriver::destroyTimerQuery(Handle<HwTimerQuery> tqh) {
}

void WebGPUDriver::destroyDescriptorSetLayout(Handle<HwDescriptorSetLayout> tqh) {
    if (tqh) {
        destructHandle<WebGPUDescriptorSetLayout>(tqh);
    }
}

void WebGPUDriver::destroyDescriptorSet(Handle<HwDescriptorSet> tqh) {
    if (tqh) {
        destructHandle<WebGPUDescriptorSet>(tqh);
    }
}

Handle<HwSwapChain> WebGPUDriver::createSwapChainS() noexcept {
    return allocHandle<WebGPUSwapChain>();
}

Handle<HwSwapChain> WebGPUDriver::createSwapChainHeadlessS() noexcept {
    return allocHandle<WebGPUSwapChain>();
}

Handle<HwTexture> WebGPUDriver::createTextureS() noexcept {
    return allocHandle<WGPUTexture>();

Review comment (bug):
nit: although a little more verbose, using a designated initializer can be safer in case we get the order wrong accidentally, e.g. `{ .width = width, .height = height }`

Code after:
}

void WebGPUDriver::createSwapChainR(Handle<HwSwapChain> sch, void* nativeWindow, uint64_t flags) {
    mNativeWindow = nativeWindow;
    assert_invariant(!mSwapChain);
    wgpu::Surface surface = mPlatform.createSurface(nativeWindow, flags);

    wgpu::Extent2D extent = mPlatform.getSurfaceExtent(mNativeWindow);
    mSwapChain = constructHandle<WebGPUSwapChain>(sch, std::move(surface), extent, mAdapter,
            mDevice, flags);
    assert_invariant(mSwapChain);

#if !FWGPU_ENABLED(FWGPU_PRINT_SYSTEM) && !defined(NDEBUG)
    char printSystemHex[16];
    snprintf(printSystemHex, sizeof(printSystemHex), "%#x", FWGPU_PRINT_SYSTEM);
    FWGPU_LOGI << "If the FILAMENT_BACKEND_DEBUG_FLAG variable were set with the " << printSystemHex
               << " bit flag on during build time the application would print system details "
                  "about the selected graphics device, surface, etc. To see this try "
                  "rebuilding Filament with that flag, e.g. ./build.sh -x "
               << FWGPU_PRINT_SYSTEM << " ...";
#endif
}

void WebGPUDriver::createSwapChainHeadlessR(Handle<HwSwapChain> sch, uint32_t width,
        uint32_t height, uint64_t flags) {
     wgpu::Extent2D extent = { .width = width, .height = height };
     mSwapChain = constructHandle<WebGPUSwapChain>(sch, extent, mAdapter,
            mDevice, flags);
     assert_invariant(mSwapChain);
}

void WebGPUDriver::createVertexBufferInfoR(Handle<HwVertexBufferInfo> vertexBufferInfoHandle,
        const uint8_t bufferCount, const uint8_t attributeCount, const AttributeArray attributes) {
    constructHandle<WebGPUVertexBufferInfo>(vertexBufferInfoHandle, bufferCount, attributeCount,
            attributes, mDeviceLimits);
}

void WebGPUDriver::createVertexBufferR(Handle<HwVertexBuffer> vertexBufferHandle,
        const uint32_t vertexCount, Handle<HwVertexBufferInfo> vertexBufferInfoHandle) {
    const auto vertexBufferInfo = handleCast<WebGPUVertexBufferInfo>(vertexBufferInfoHandle);
    constructHandle<WebGPUVertexBuffer>(vertexBufferHandle, vertexCount,
            vertexBufferInfo->bufferCount, vertexBufferInfoHandle);
}

void WebGPUDriver::createIndexBufferR(Handle<HwIndexBuffer> indexBufferHandle,
        const ElementType elementType, const uint32_t indexCount, const BufferUsage usage) {
    const auto elementSize = static_cast<uint8_t>(getElementTypeSize(elementType));
    constructHandle<WebGPUIndexBuffer>(indexBufferHandle, mDevice, elementSize, indexCount);
}

void WebGPUDriver::createBufferObjectR(Handle<HwBufferObject> bufferObjectHandle,