Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGPURenderer: Introduce syncWithGPU #29686

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

RenaudRohlinger
Copy link
Collaborator

@RenaudRohlinger RenaudRohlinger commented Oct 18, 2024

Description

This pull request introduces a new syncWithGPU helper to our codebase, providing a unified method for synchronizing CPU operations with GPU processing in both WebGPU and WebGL contexts.

Example usage:

async loop() {

    await renderer.computeAsync(veryHeavyComputeProgram)
    await renderer.syncWithGPU() // wait for the GPU to resolve its operations
}

Note: syncWithGPU is not included in computeAsync and renderAsync because it may have performance implications and is applicable only in specific edge cases. Therefore, providing an API for users to handle synchronization themselves is more appropriate.

This contribution is funded by Utsubo

Copy link

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 690.8
171.12
690.8
171.12
+0 B
+0 B
WebGPU 816.46
220.09
816.63
220.15
+175 B
+60 B
WebGPU Nodes 815.97
219.96
816.14
220.02
+175 B
+60 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 463.45
111.9
463.45
111.9
+0 B
+0 B
WebGPU 538.64
145.42
538.81
145.47
+175 B
+59 B
WebGPU Nodes 494.75
135.28
494.93
135.35
+175 B
+62 B

@RenaudRohlinger RenaudRohlinger added this to the r170 milestone Oct 18, 2024
@Makio64
Copy link
Contributor

Makio64 commented Oct 18, 2024

Oh I though :
await renderer.computeAsync(veryHeavyComputeProgram) // is waiting gpu task to finish
renderer.computeAsync(veryHeavyComputeProgram) // is not waiting gpu task to finish

I suggest a more direct name : waitGPUCompleted

@RenaudRohlinger
Copy link
Collaborator Author

Oh I though :
await renderer.computeAsync(veryHeavyComputeProgram) // is waiting gpu task to finish
renderer.computeAsync(veryHeavyComputeProgram) // is not waiting gpu task to finish

I think in the end developers will always go for the async option, and calling the backend methods such as await this.device.queue.onSubmittedWorkDone(); in WebGPU and gl.fenceSync, gl.flush() in WebGL2 will impact the performances even if we don't specify that it's an await operation.

If we consider that computeAsync and renderAsync are more expensive operation that are really async and will potentially freeze the render/CPU I'm fine with this solution.

Also I agree with the name. Or maybe waitForGPUCompletion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants