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: Improve ArrayCamera performance and fixes #30313

Merged
merged 13 commits into from
Jan 16, 2025

Conversation

sunag
Copy link
Collaborator

@sunag sunag commented Jan 13, 2025

Related issue: #28968 (comment)

Description

As discussed before the cameraViewMatrix is updated through an uniform array, I'm afraid this won't work on WebGPU because the process is executed at the end of the pass, this may make it difficult to update the index as imagined, so I'm not sure if this will perform well, what I'll try is to do it using an instances approach later. The example work in WebGL as expected.

The PR fix cameraViewMatrix of its subcameras, only the viewport were updated.

Copy link

github-actions bot commented Jan 13, 2025

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 339.53
79.09
339.53
79.09
+0 B
+0 B
WebGPU 491.02
136.44
492.98
137.03
+1.96 kB
+588 B
WebGPU Nodes 490.49
136.34
492.45
136.93
+1.96 kB
+593 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 465.39
112.16
465.41
112.16
+13 B
+2 B
WebGPU 561.56
152.15
563.51
152.7
+1.95 kB
+555 B
WebGPU Nodes 516.95
141.72
518.89
142.28
+1.95 kB
+563 B

@Mugen87
Copy link
Collaborator

Mugen87 commented Jan 13, 2025

I'm afraid this won't work on WebGPU because the process is executed at the end of the pass, this may make it difficult to update the index as imagined, so I'm not sure if this will perform well

Do you mind explain in more details why the current approach does not work with WebGPU? I'm afraid I don't understand yet.

@sunag
Copy link
Collaborator Author

sunag commented Jan 14, 2025

Do you mind explain in more details why the current approach does not work with WebGPU? I'm afraid I don't understand yet.

WebGPU does not update the buffer immediately to the GPU, at draw time, but it does so at submit time (end of pass), this explains why in the WebGPU version it is always the last value of the uniform that is being considered for all draws.

@sunag
Copy link
Collaborator Author

sunag commented Jan 15, 2025

  • PR approach

image

  • Moving ArrayCamera viewport logic to Backend at the time of the draw
  • Updating the uniform bufferData value.
  • Equivalent result in WebGLRenderer.

image

  • Moving ArrayCamera viewport logic to Backend at the time of the draw
  • Caching all camera indexes in new gpu-buffers.
  • Change the reference of gpu-buffer using bindBufferBase using the caches.
  • More performant than current approaches, it should work on WebGPU.

image

@sunag
Copy link
Collaborator Author

sunag commented Jan 15, 2025

Caching the indexes and changing their reference at draw time seems to be the best approach so far. It should theoretically work on WebGPU, but I still need to test it. Updating the cameraIndex value doesn't seem to bring much different results than what we currently have in WebGLRenderer. Approaches that use instances don't seem to be much more efficient when we need to change viewports, in addition to additional care with models that already have instances.

@sunag sunag changed the title WebGPURenderer: Improve ArrayCamera performance - WIP WebGPURenderer: Improve ArrayCamera performance Jan 16, 2025
@sunag sunag marked this pull request as ready for review January 16, 2025 00:49
@sunag
Copy link
Collaborator Author

sunag commented Jan 16, 2025

I would have to do the same array modification with the other camera nodes like cameraPosition but I'm leaving that for another PR. /cc @Mugen87

@sunag sunag added this to the r173 milestone Jan 16, 2025
@sunag sunag requested a review from Mugen87 January 16, 2025 02:48
@Mugen87
Copy link
Collaborator

Mugen87 commented Jan 16, 2025

Can't wait to test this with the new XRManager 😁 .

@sunag sunag changed the title WebGPURenderer: Improve ArrayCamera performance WebGPURenderer: Improve ArrayCamera performance and fixes Jan 16, 2025
@sunag sunag merged commit 0c1185d into mrdoob:dev Jan 16, 2025
12 checks passed
@sunag sunag deleted the dev-arraycamera branch January 16, 2025 12:14
@Mugen87
Copy link
Collaborator

Mugen87 commented Jan 16, 2025

It seems the demo webgpu_camera_array does work with WebGPU but not with a WebGL backend. I just get a black screen when forceWebGL is set to true (or when using Firefox).

There are no errors or warnings in the console.

@Mugen87
Copy link
Collaborator

Mugen87 commented Jan 16, 2025

It's strange that the CI did not catch the breakage of webgpu_camera_array 🤔 .

The example did fail in #30335 though.

@sunag
Copy link
Collaborator Author

sunag commented Jan 16, 2025

It's strange that the CI did not catch the breakage of webgpu_camera_array 🤔 .

It's broken after #30329

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