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

Code before:
    wgpu::RenderPassColorAttachment renderPassColorAttachment = {};
    renderPassColorAttachment.view = mTextureView;
    renderPassColorAttachment.resolveTarget = nullptr;

    // TODO: remove this code once WebGPU Pipeline is implemented with render targets, pipeline and buffers.
    renderPassColorAttachment.loadOp = wgpu::LoadOp::Clear;
    renderPassColorAttachment.storeOp = wgpu::StoreOp::Store;
    static float red = 1.0f;
    if (red - 0.01 > 0) {
        red -= 0.01;
    } else {
        red = 1.0f;
    }
    renderPassColorAttachment.clearValue = wgpu::Color{red, 0 , 0 , 1};
    renderPassColorAttachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;

    // TODO: This needs to be updated proper color and depth attachments
    wgpu::RenderPassDescriptor renderPassDescriptor = {};
    renderPassDescriptor.nextInChain = nullptr;
    renderPassDescriptor.colorAttachmentCount = 1;
    renderPassDescriptor.colorAttachments = &renderPassColorAttachment;
    renderPassDescriptor.depthStencilAttachment = nullptr;
    renderPassDescriptor.timestampWrites = nullptr;

    mRenderPassEncoder = mCommandEncoder.BeginRenderPass(&renderPassDescriptor);
    mRenderPassEncoder.SetViewport((float)params.viewport.left, (float)params.viewport.bottom,
            (float) params.viewport.width, (float) params.viewport.height, params.depthRange.near, params.depthRange.far);
}

void WebGPUDriver::endRenderPass(int) {
    mRenderPassEncoder.End();
    mRenderPassEncoder = nullptr;
}

void WebGPUDriver::nextSubpass(int) {
}

void WebGPUDriver::makeCurrent(Handle<HwSwapChain> drawSch, Handle<HwSwapChain> readSch) {
}

void WebGPUDriver::commit(Handle<HwSwapChain> sch) {
    wgpu::CommandBufferDescriptor commandBufferDescriptor = {};
    commandBufferDescriptor.nextInChain = nullptr;
    commandBufferDescriptor.label = "webgpu_command_buffer";
    mCommandBuffer = mCommandEncoder.Finish(&commandBufferDescriptor);
}

void WebGPUDriver::setPushConstant(backend::ShaderStage stage, uint8_t index,
        backend::PushConstantVariant value) {
}


Review comment (suggestion):
Please avoid c-style casts whenever possible. See https://google.github.io/styleguide/cppguide.html#Casting for more detail as to the rationale.
In this case, I would recommend `static_cast` for these, e.g. `static_cast<float>(params.viewport.left)`.

Code after:
        red -= 0.01;
    } else {
        red = 1.0f;
    }

    wgpu::RenderPassColorAttachment renderPassColorAttachment = {
        .view = mTextureView,
        // TODO: remove this code once WebGPU Pipeline is implemented with render targets, pipeline and buffers.
        .depthSlice = wgpu::kDepthSliceUndefined,
        .loadOp = wgpu::LoadOp::Clear,
        .storeOp = wgpu::StoreOp::Store,
        .clearValue = wgpu::Color{red, 0 , 0 , 1},
    };

    wgpu::RenderPassDescriptor renderPassDescriptor = {
        .colorAttachmentCount = 1,
        .colorAttachments = &renderPassColorAttachment,
        .depthStencilAttachment = nullptr,
        .timestampWrites = nullptr,
    };

    mRenderPassEncoder = mCommandEncoder.BeginRenderPass(&renderPassDescriptor);
    mRenderPassEncoder.SetViewport(params.viewport.left, params.viewport.bottom,
            params.viewport.width, params.viewport.height, params.depthRange.near, params.depthRange.far);
}

void WebGPUDriver::endRenderPass(int) {
    mRenderPassEncoder.End();
    mRenderPassEncoder = nullptr;
    wgpu::CommandBufferDescriptor commandBufferDescriptor {
        .label = "command_buffer",
    };
    mCommandBuffer = mCommandEncoder.Finish(&commandBufferDescriptor);
    assert_invariant(mCommandBuffer);
}

void WebGPUDriver::nextSubpass(int) {
}

void WebGPUDriver::makeCurrent(Handle<HwSwapChain> drawSch, Handle<HwSwapChain> readSch) {
}

void WebGPUDriver::commit(Handle<HwSwapChain> sch) {
    mCommandEncoder = nullptr;
    mQueue.Submit(1, &mCommandBuffer);
    mCommandBuffer = nullptr;
    mTextureView = nullptr;
    mSwapChain->present();
}

void WebGPUDriver::setPushConstant(backend::ShaderStage stage, uint8_t index,