-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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: Introduced .toConst()
, Const()
, Var()
#30251
WebGPURenderer: Introduced .toConst()
, Const()
, Var()
#30251
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
I suggest renaming it to
|
We need So I would suggest that we keep declarationType and introduce in another PR 'const' along 'let'. |
|
The example below shows how it would look in the API. We don't need to worry about declaring const uniformValue = uniform( 1 );
const primitiveValue = float( 1 );
const val1 = primitiveValue.add( primitiveValue ).toConst(); // it will use `const` in WGSL/GLSL
const val2 = uniformValue.add( uniformValue ).toConst(); // it will use `let` in WGSL and keep as default in GLSL
const val3 = uniformValue.add( primitiveValue ).toConst(); // it will use `let` in WGSL and keep as default in GLSL |
@sunag I made some updates implementing Feel free to push into this PR if you have something in mind, or it would be great if you could guide me more on these topics. |
var.toConst()
I made some small changes and added a function to detect if the code flow is deterministic. deterministic flow// tsl
const myConst = vec3( 1, 0, 1 ).add( 0 ).normalize().toConst();
// wgsl
const nodeVar0 = normalize( ( vec3<f32>( 1.0, 0.0, 1.0 ) + vec3<f32>( 0.0 ) ) );
// glsl
const vec3 nodeVar0 = normalize( ( vec3( 1.0, 0.0, 1.0 ) + vec3( 0.0 ) ) ); non-deterministic flow// tsl
const myUniform = uniform( vec3( 0, 0, 1 ) );
const myConst = vec3( 1, 0, 1 ).add( 0 ).normalize().add( myUniform ).toConst();
// wgsl
let nodeVar0 = ( normalize( ( vec3<f32>( 1.0, 0.0, 1.0 ) + vec3<f32>( 0.0 ) ) ) + object.nodeUniform0 );
// glsl
vec3 nodeVar0;
nodeVar0 = ( normalize( ( vec3( 1.0, 0.0, 1.0 ) + vec3( 0.0 ) ) ) + f_nodeUniform0 ); |
Thanks @sunag! I still have two cases not handled: WorkgroupArray and similar not properly converted (ConvertNode?): Error while parsing WGSL: :55:20 error: cannot assign 'u32' to 'vec2<u32>':
sharedData[ lid ] = NodeBuffer_538.nodeUniform0[ gid ].x; and when having Error while parsing WGSL: 151:8 error: redeclaration of 'nodeVar4'
let nodeVar4 = NodeBuffer_538.nodeUniform9[ ( k ) ].x;
^^^^^^^^
Error while parsing WGSL: 150:8 note: 'nodeVar4' previously declared here
let nodeVar4 = NodeBuffer_538.nodeUniform9[ ( k ) ].y; |
This issue is actually smaller than I thought, the auto attribution of name is failing: const a = buffers.indices.element(k).x.toConst('');
const b = buffers.indices.element(k).y.toConst(''); breaks since 2 let nodeVar4_readOnly = NodeBuffer_538.nodeUniform9[ ( k ) ].x;
let nodeVar4_readOnly = NodeBuffer_538.nodeUniform9[ ( k ) ].y; const a = buffers.indices.element(k).x.toConst('a');
const b = buffers.indices.element(k).y.toConst('b'); works --> let a_readOnly = NodeBuffer_538.nodeUniform9[ ( k ) ].x;
let b_readOnly = NodeBuffer_538.nodeUniform9[ ( k ) ].y; /cc @sunag |
Related reading 👀 |
@RenaudRohlinger Would it be possible to reproduce the type conversion problem in some existing example? I tried in |
var.toConst()
node.toConst()
Happy new year everyone ! I hope you had a wonderful time @RenaudRohlinger @sunag ! I'm catching up with all the commit & updates! Is toConst() integrated in the Also as the user point of view, I agree with @sunag, I don't plane to use Thanks for your involvement to make our creative coding life easier and able to focus on rendering only ! Wish you a productive year with lot of loves & success! Best, |
I'm not quite sure whether this could be considered off-topic, or whether it has already been discussed. The chaining tends to push the top-level functions towards the back of an expression. I often find myself forgetting adding Example:
The same concept could be extended to other existing or future functions:
In a more iconoclastic context, what about using
This might be consistent with things like |
Thanks @RenaudRohlinger @mrdoob @Makio64 @boytchev. The Var/Const idea sounds great, updated. |
node.toConst()
.toConst()
, Const()
, Var()
Description
Currently it's only possible to create
var
inWGSL
. This PR introduces the ability to generatelet
andconst
variables viaconst a = node.toConst('a')
Using
let
instead ofvar
in TSL ensures immutability, improves code safety, allows better optimization, and clarifies developer intent by preventing unintended modifications.I also took the opportunity to replace
id
byglobalId
inWGSL
as it was confusing andglobalId
can be very useful, so I exposed it to userland.This contribution is funded by Utsubo