-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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
Examples: Prefix Sum Compute Example #29940
base: dev
Are you sure you want to change the base?
Conversation
b1c7c62
to
7112f50
Compare
@@ -0,0 +1,325 @@ | |||
import * as THREE from 'three'; | |||
import { storageObject, If, vec3, uniform, uv, uint, float, Fn, vec2, uvec2, floor, instanceIndex, workgroupBarrier, atomicAdd, atomicStore, workgroupId, storage } from 'three/tsl'; |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note test
const numElements = 16384; | ||
|
||
|
||
const computePrefixSklanskyFn = Fn( ( currentElements, uniformStorage ) => { |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note test
gui.add( effectController, 'Right Display Algo', algorithms ); | ||
|
||
// Allow Workgroup Array Swaps | ||
init( false, 'Fake Prefix' ); |
Check warning
Code scanning / CodeQL
Superfluous trailing arguments Warning test
function init
init( false, 'Fake Prefix' ); | ||
|
||
// Global Swaps Only | ||
init( true, 'Incorrect' ); |
Check warning
Code scanning / CodeQL
Superfluous trailing arguments Warning test
function init
const currentElementsBuffer = new THREE.StorageInstancedBufferAttribute( array, 1 ); | ||
const currentElementsStorage = storage( currentElementsBuffer, 'uint', currentElementsBuffer.count ).label( 'Elements' ); | ||
const infoBuffer = new THREE.StorageInstancedBufferAttribute( infoArray, 1 ); | ||
const infoStorage = storage( infoBuffer, 'uint', infoBuffer.count ); |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note test
|
||
const LoopThroughWorkgroup = ( callback ) => { | ||
|
||
const WORKGROUP_SIZE = uint( 64 ).toVar( 'WORKGROUP_SIZE' ); |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note
|
||
case 'Validate': { | ||
|
||
const currentElements = new Uint32Array( await renderer.getArrayBufferAsync( currentElementsBuffer ) ); |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
I think there's an issue with how performance is being measured. Using the renderer.info method used in the bitonic sort and storage buffer examples, it doesn't seem as if the performance is changing at all based on the selected compute shader. Is there perhaps a way to use the timestamp queries within WebGPU to more accurately measure performance, or is compute.info already using that functionality. Additionally, I'm not sure if there's a way to revert my commit to specifically ignore the build files that were erroneously pushed in. |
/ping @RenaudRohlinger |
Thanks for this super useful example! It helped me identify a very tricky issue with timestamp queries. I’ve submitted a PR (#29970) that should resolve the issues you encountered. I tested it using your example, and the logs now appear accurate, providing both render and compute timestamp information as expected. PS: When using timestamp queries, please ensure you refer to |
7112f50
to
783220d
Compare
Related issue: #XXXX
Description
Creates an example demonstrating various prefix sum algorithms written using the TSL node system. Also measures the performance of the algorithms against each other. Ideally, this is an expanding example where different versions and increasingly performant versions of the prefix sum can be added over time, in a syntax that is hopefully much more familiar and accessible to Javascript programmers than equivalent examples in CUDA or other GPGPU languages.
As demonstrated in this visualization, validated elements of a prefix sum are highlighted in green, while incorrect elements are highlighted in red. The image below demonstrates a correct implementation of a Sklansky prefix sum against the reverse of the expected elements (i.e maxElements to 1 instead of 1 to maxElements).
Currently, I'd like to implement a few more algorithms before this is pulled in.