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

Including Operations Only Possible in Custom Nodes Causes the Entire Function To Be Inside A Custom Node #1

Open
Bartalon opened this issue Oct 25, 2021 · 4 comments

Comments

@Bartalon
Copy link

Ideally this plugin would be able to differentiate between content that needs to definitely be part of a Custom node and everything else in order to take advantage of constant folding.

Function code:

void testFunc(float3 color, float intensity, out float3 diffuse, out float x) {

	float val = 0.1;
	int i = 0;
	while ( i <= 10 ) {
		diffuse.x = (val * (float)i);
		i += 1;
	}

	x = intensity * 0.5;
}
  • Generated graph:
    image

  • Expected format: Intensity parameter and X output are not used within the while loop, and therefore could be broken out from the custom node:
    image

@Phyronnaz
Copy link
Owner

Thanks for the feedback!

The plugin is indeed pretty simple & doesn't translate the actual HLSL into a shader graph.
Doing so would require parsing the HLSL code itself, which would be way out of the scope of the plugin.

Out of curiosity, do you have examples where constant folding really improves performance? I've always been curious to see how important is really is.

@Bartalon
Copy link
Author

No problem, I figured it might be out of scope. One day perhaps :)

I'm not a programmer, but constant folding seems to apply to code compiling in general. From what I understand, something like 2 * 10 * 12 would be constant-folded to become just 240 without any multiply operations. A Custom node in the Material Editor (according to Epic) would not benefit from this and instead would have each multiplication operation as part of the compiled shader code.

https://en.wikipedia.org/wiki/Constant_folding

@Phyronnaz
Copy link
Owner

Gotcha :)

Actually, "classic" constant folding is already done by the shader compiler - if you have 2 * 10 * 12 the bytecode will just use 240.

The unreal constant folding is to apply that to "constant" parameters that aren't known at the shader compile time. Eg, if you have sin(MyParameter) unreal can precompute the sin when you set MyParameter, only doing the operation once instead of once per pixel per frame.

As far as I can tell this can be useful in some very specific scenarios, but in the vast majority of cases it shouldn't matter much if at all.

@Bartalon
Copy link
Author

Oh cool, thanks for the extra info! This makes sense.

It would be ideal to have that separation with this plug-in if only just to maintain team-accessible graphs. But as you said, out of scope for the time being. :)

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

No branches or pull requests

2 participants