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

WebGPURenderer: Optimize and reuse varyings #28210

Draft
wants to merge 8 commits into
base: dev
Choose a base branch
from

Conversation

RenaudRohlinger
Copy link
Collaborator

WebGPU is currently limited to 16 varyings, which can be quickly exceeded with the node system, leading to errors such as:image

This PR sets up the naming of varyings where possible in order to reuse them, thereby enhancing performance and enabling debugging.

Before this PR with a fairly advanced setup:
Screenshot 2024-04-24 at 20 36 43

After this PR, on the same program:
Screenshot 2024-04-24 at 20 37 51

The only issue I encountered while working on this was my inability to assign the v_normalLocal name to normalLocal. /cc @sunag. Otherwise, everything seems to function well, even in complex setups.

This contribution is funded by Utsubo

@RenaudRohlinger
Copy link
Collaborator Author

Seems like some varyings have some specific issue with the WebGLBackend on 4 examples. Probably flat identifier and hardcoded GLSLNodeBuilder details. Will check tomorrow.

@sunag
Copy link
Collaborator

sunag commented Apr 24, 2024

Hmm... Node.getHash() and Node.getShared() should work in this sense. I think it's worth checking out too because it's not sharing.

@RenaudRohlinger RenaudRohlinger marked this pull request as draft April 25, 2024 01:53
@RenaudRohlinger
Copy link
Collaborator Author

Somehow isolated one of the issue, basically using nodes will just always create new varying even when not necessary. For example using TBNViewMatrix will create a new unnecessary varying instead of grouping them in the vertex.

This will generate 3 varyings:

export const TBNViewMatrix = mat3( tangentView, bitangentView, normalView );
--> bitangentView is an independent varying of normalView.cross( tangentView )

Doing this will use only 2 varyings:

export const TBNViewMatrix = mat3( tangentView, normalView.cross( tangentView ), normalView );

We would need a system to automatically pack the varyings I guess? Seems like my PR is helping when providing names to all varyings. /cc @sunag

@sunag
Copy link
Collaborator

sunag commented Apr 25, 2024

I will check, the current system should resolve this kind of issue, maybe has some bug related with cache. Your PR is good because give name for varyings, the names should help in debugging but should not be essential for optimization until fix this issue.

@RenaudRohlinger
Copy link
Collaborator Author

RenaudRohlinger commented Apr 26, 2024

@sunag One of the issue with the current node system when using named varying is that the AssignNode seems to conflict with the VaryingNode (Only for WebGPU). WGLSL is generating varyings.v_normal but tries to use v_normal.
image

Error:
image

Which is ok and runs well with the GLSLNodeBuilder:
image

To reproduce simply add names to the varyings of the NormalNode and such and try for example to run webgpu_backdrop_water

I don't think I will be able to resolve this easily as my knowledge on the node system is still a bit limited but I believe this issue will need to be resolve first in order to convert this draft to a PR a add various names for the attributes and varyings.

@sunag
Copy link
Collaborator

sunag commented Apr 29, 2024

@RenaudRohlinger Could you share your test again? I pushed a commit for us to analyze. Just NormalNode yet.

@RenaudRohlinger
Copy link
Collaborator Author

This code doesn't seem to work if you try webgpu_backdrop_water

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