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

TSL: Introduce pointer | WGSL ptr support #29552

Merged
merged 1 commit into from
Oct 5, 2024
Merged

Conversation

sunag
Copy link
Collaborator

@sunag sunag commented Oct 5, 2024

Related issue: Closes #29401

Description

Introduces pointer support, below is an example of how to use it for storage buffers, although it has many other applications.

// buffer

const particleBuffer = new THREE.StorageInstancedBufferAttribute( particleNum, 2 );

// function

const getElement = wgslFn( `
fn main_vertex( vertexBuffer: ptr<storage, array<vec2<f32>>, read_write>, index: u32 ) -> vec2f {

	return vertexBuffer[ index ];

}
` );

// function call

const particle = getElement( particleBufferNode, instanceIndex );

@sunag sunag added this to the r170 milestone Oct 5, 2024
Copy link

github-actions bot commented Oct 5, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 688.13
170.5
688.13
170.5
+0 B
+0 B
WebGPU 808.1
217.67
808.2
217.71
+99 B
+47 B
WebGPU Nodes 807.61
217.53
807.71
217.58
+99 B
+47 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 462.85
111.78
462.85
111.78
+0 B
+0 B
WebGPU 536.53
144.8
536.63
144.86
+99 B
+53 B
WebGPU Nodes 492.61
134.53
492.71
134.59
+99 B
+53 B

@sunag sunag marked this pull request as ready for review October 5, 2024 01:52
@sunag sunag merged commit e395c1a into mrdoob:dev Oct 5, 2024
12 checks passed
@sunag sunag deleted the dev-pointer branch October 5, 2024 03:11
@Spiri0
Copy link
Contributor

Spiri0 commented Oct 5, 2024

As usual, your solution is much more elegant. More efficient and shorter.
I tested it straight away and it worked as expected

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.

StorageBuffer access in wgslFn and tslFn vertex shaders
2 participants