-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Backend-agnostic GPGPU on Nodes #25273
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
Conversation
|
I think I've managed to create a prototype of |
|
WebGLBuffer works when used as a srcBuffer but fails for some reason when used as an outBuffer... Not sure why. |
|
|
||
| } | ||
|
|
||
| dispose() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should also add a WebGPUBuffer.dispose() (and maybe BufferNode.dispose()) functions.
Also, when this function should be called?
|
|
||
| generate( builder, output ) { | ||
|
|
||
| this.construct( builder ); // this is required for some reason? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really sure why...
|
I think I almost done fixing that error -- and also making a good API (nothing really user-facing except |
|
For some reason in the shader appear mistakenly generated |
|
|
||
| const result = [ remainder( mul( index, 2 ), 256 ), remainder( mul( index, 3 ), 256 ), remainder( mul( index, 5 ), 256 ) ]; | ||
| stack.assign( element( storage( outAttribute ), index ), params.backend === 'WebGL' ? color( ...result ) : uvec4( ...result, uint( 255 ) ) ); | ||
| return stack; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These return stacks should not be needed ideally...
| this.setBuildStage( 'construct' ); | ||
| node.build( this ); | ||
| this.setBuildStage( currentBuildStage ); | ||
| return node.build( this ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this is a little bit overcomplicated (but at least works)...
| import WebGPU from 'three/addons/capabilities/WebGPU.js'; | ||
| import WebGPURenderer from 'three/addons/renderers/webgpu/WebGPURenderer.js'; | ||
|
|
||
| import { nodeFrame } from 'three/addons/renderers/webgl/nodes/WebGLNodes.js'; |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class
|
|
||
| const TypedArray = params.backend === 'WebGL' ? Uint8Array : Uint32Array; // WebGPU can only work with uint32 | ||
|
|
||
| const index = instanceIndex; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe make index an alias to instanceIndex in ShaderNodeBaseElements?
|
I think I fixed that problem -- now Multiplication and Random examples render (although something is completely wrong with Multiplication colors -- maybe a problem somewhere in encodings or |
|
Closing because #27367 provides the same support. |
Related issue: #23905 (comment)
Description
A port of my ComputationRenderers from https://github.com/LeviPesin/THREE.js-PathTracing-Renderer/tree/webgpu/js/pathtracing/utils (originally made as a part of the unfinished port of erichlof's Three.js' pathtracing renderer).
API
See the example's code. Mainly just new functions
WebGLRenderer.compute( ...computeNodes ),WebGLRenderer.deuploadBufferAttrribute( bufferAtrribute ), andWebGPURenderer.deuploadBufferAtrribute( bufferAtrribute, overwrite = false )are introduced.Original TODO
API Modification
I don't really like the current API of ComputationRenderers -- I think @sunag's approach ofWebGPURenderer.compute()andComputeNodesis better...ComputationRenderers mainly consist of setting up stuff needed for WebGL computations (this can be safely moved to a
WebGLRenderer.compute()function and a thing likeWebGLStorageBufferto be able to useStorageNode), dealing withTypedBuffer.getBufferElement()andTypedBuffer.setBufferElement()(first can theoretically be moved toArrayElementNode), and auto-transferring data from GPU back to CPU (this can also be moved toWebGLRenderer.compute()andWebGPURenderer.compute()).Problems are in details -- for example,
ComputeNodeisn't really useful for WebGL computations -- they are not going for a specific number of iterations, they go for each pixel in the outBuffer. outBuffer is also the only buffer that we can write to in WebGL -- and even with it dealing withTypedBuffer.setBufferElement()is quite tricky...API was changed.
Example (
misc_nodes_gpgpu)I made an example for testing WebGL and WebGPU computations, including some basic performance measuring.
Options
backend-- selects which backend will be used for doing computations.example-- which example of a simple ShaderNode computation will be shown (Passthrough,AntiPassthrough,PassthroughColor-- outBuffer is 4-channeled instead of 1,ElementManipulation-- a srcBuffer is used,Multiplication,Random-- generates white noise based on PCG algorithm).warmUps-- how many iterations of computations to perform; useful for performance measurements.logBuffersandlogPerformance-- whether to log data buffers (defaultfalse) and performance (defaulttrue).refresh-- press to dispose renderer and clear caches.clearConsole-- press to clear console.Performance Problems