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

Nodes: Introduce NodeBuilder.formatOperation #27954

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

LeviPesin
Copy link
Contributor

Related issue: #27512

Description

This is (finally) the first PR of #27512 -- I started with this one because I think this is the most useful and simple feature of all included (I hope I will file other PRs soon).

This PR introduces a new NodeBuilder method for formatting operations and functions. This allows to not worry about enclosing operations in brackets anymore (as it was done in OperatorNode previously and caused many unneeded ones), allows to simplify polyfilling of missing in GLSL/WGSL operators and functions (now it can be done in basically one line; .getMethod() and .getFunctionOperator() are also not needed now), and as a bonus also allows auto-building something like node.addAssign( node2 ) to node += node2 (on the shader code generation step instead of node graph building, but I think in this case this is enough). I also removed equals element because it seems to be just a duplicate of already existing equal.

Signed-off-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com>
Signed-off-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com>
@LeviPesin
Copy link
Contributor Author

No idea why the CI-3 job fails... Examples work fine locally.

Signed-off-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com>
Signed-off-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com>
@LeviPesin
Copy link
Contributor Author

Seems like I just was accidentally testing on the WebGPU backend, not WebGL2 one... Should be fixed now.

Signed-off-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com>
Signed-off-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com>
@LeviPesin
Copy link
Contributor Author

Error: Diff wrong in 0.3% of pixels in file: webgpu_loader_gltf_sheen

Not sure what could've broken...

@LeviPesin
Copy link
Contributor Author

@sunag Can you please look into this?

@@ -258,7 +258,7 @@ export const blur = tslFn( ( { n, latitudinal, poleAxis, outputDirection, weight

const axis = vec3( cond( latitudinal, poleAxis, cross( poleAxis, outputDirection ) ) ).toVar();

If( all( axis.equals( vec3( 0.0 ) ) ), () => {
If( all( axis.equal( vec3( 0.0 ) ) ), () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... currently equals should return a bvec while equal should return a bool.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why equal should return bool? I think it makes sense to return bool in case of primitive types and bvec in case of vectors (exactly how == works in WGSL and equal in GLSL), as now.

@sunag
Copy link
Collaborator

sunag commented Mar 21, 2024

The formatting of the generated code has improved a lot 🚀

@sunag
Copy link
Collaborator

sunag commented Mar 21, 2024

The webgpu_clearcoat example broken but try adding toVar() in end of this line bellow and this will work again:

const clearcoatLight = outgoingLight.mul( clearcoat.mul( Fcc ).oneMinus() ).add( this.clearcoatSpecularDirect.add( this.clearcoatSpecularIndirect ).mul( clearcoat ) );

I did't compare the generated codes, maybe the new formatting can lose operator precedence?

@LeviPesin
Copy link
Contributor Author

I did't compare the generated codes, maybe the new formatting can lose operator precedence?

If so, this is a bug -- I tried to account for every case (difference between left and right arguments, operators of same precedence that could or could not associate with themselves, operators that don't associate with certain other precedence at all in WGSL), but it's still possible that something fails. I will try to look into it...

@LeviPesin
Copy link
Contributor Author

The formatting of the generated code has improved a lot 🚀

It will also improve much, much more after a PR with various fixes for analyze and TempNode and more integration of them :-)

Signed-off-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com>
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.

None yet

2 participants