Skip to content

Conversation

sunag
Copy link
Collaborator

@sunag sunag commented Mar 13, 2025

Fixes: #30634

Description

Add inline support for a.assign(b) and removed the redundant .storeNode.

@sunag sunag added this to the r175 milestone Mar 13, 2025
Copy link

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 336.02
78.26
336.02
78.26
+0 B
+0 B
WebGPU 520.73
145.18
520.52
145.15
-200 B
-29 B
WebGPU Nodes 520.19
145.07
519.99
145.04
-200 B
-30 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 465.06
112.14
465.06
112.14
+0 B
+0 B
WebGPU 591.12
160.82
591.01
160.79
-108 B
-25 B
WebGPU Nodes 546.24
150.25
546.13
150.23
-108 B
-26 B

@sunag sunag marked this pull request as ready for review March 13, 2025 00:18
@sunag sunag merged commit 1507e5a into mrdoob:dev Mar 13, 2025
12 checks passed
@sunag sunag deleted the dev-atomic-rev branch March 13, 2025 14:44
@RenaudRohlinger
Copy link
Collaborator

RenaudRohlinger commented Apr 9, 2025

I believe that with this PR we can't do:

The usual WGSL syntax:

const a = atomicAdd(buffer.element(0), 1).toConst('a')

nor:

const a = uint(0).toVar('a')
atomicAdd(buffer.element(0), 1, a)

/cc @sunag

@sunag
Copy link
Collaborator Author

sunag commented Apr 10, 2025

Hmm.. I think the usage of atomicAdd should keep the same with this PR or not?

atomicAdd( counterStorage.element( 0 ), 1 );
const temp = localStorage.element( idxBefore ).toVar();
localStorage.element( idxBefore ).assign( localStorage.element( idxAfter ) );
localStorage.element( idxAfter ).assign( temp );

@RenaudRohlinger
Copy link
Collaborator

Not really, in most case with atomic operations we need to access the value of the operation while doing it (see my syntax in my previous message), for example doing an operation in a loop while trying to access to that value updated.

It's currently not possible anymore, only vagabond operation which is very limiting.

@sunag
Copy link
Collaborator Author

sunag commented Apr 10, 2025

I still don't understand your example exactly, but I believe you are referring to the function call not being added to the Stack immediately?

@RenaudRohlinger
Copy link
Collaborator

RenaudRohlinger commented Apr 11, 2025

Ah sorry about that, I should have provided a better example. But basically from the specs:
https://www.w3.org/TR/WGSL/#atomic-rmw

Each function returns the original value stored in the atomic object before the operation.

For example:

fn atomicAdd(atomic_ptr: ptr<AS, atomic<T>, read_write>, v: T) -> T

Which means that any atomic operation will return a value, so it would be great to be able to easily read the returned value, for example:

The usual WGSL syntax:

const a = atomicAdd(buffer.element(0), 1).toConst('a')

nor:

const a = uint(0).toVar('a')
atomicAdd(buffer.element(0), 1, a)

This was possible to do before this PR via:

const a = uint(0).toVar('a')
atomicAdd(buffer.element(0), 1, a)

but not anymore.

@holtsetio
Copy link
Contributor

Seconding @RenaudRohlinger, this update broke some of my projects because I can't access the return value of the atomic operation anymore.

@sunag
Copy link
Collaborator Author

sunag commented Apr 16, 2025

I'm making a fix for this, just need to do a few more checks.

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.

Cannot use atomicStore with atomicLoad together
3 participants