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

Optimize GLES3 CanvasLight calculations and make it precise. #161

Conversation

WhalesState
Copy link

test-light.mp4

@jss2a98aj
Copy link
Member

Can you upload a project with that test scene? I would like to benchmark it.

@WhalesState
Copy link
Author

I have edited the project to use the default physics engine, and freezed all the physics nodes after 0.5 seconds because godot 2d physics performance will affect the benchmark.

test.zip

@WhalesState WhalesState force-pushed the gles3-canvas-light-optimization branch from e8f7665 to 309cdc1 Compare November 30, 2024 18:58
@jss2a98aj
Copy link
Member

I am getting slightly worse performance in the test with the changes. I am going to try production builds next to see if it changes anything.

Before

Project FPS: 1216 (0.82 mspf)
Project FPS: 1249 (0.80 mspf)
Project FPS: 1250 (0.80 mspf)
Project FPS: 1244 (0.80 mspf)
Project FPS: 1215 (0.82 mspf)
Project FPS: 1210 (0.82 mspf)
Project FPS: 1238 (0.80 mspf)

After

Project FPS: 1178 (0.84 mspf)
Project FPS: 1178 (0.84 mspf)
Project FPS: 1170 (0.85 mspf)
Project FPS: 1169 (0.85 mspf)
Project FPS: 1179 (0.84 mspf)
Project FPS: 1156 (0.86 mspf)
Project FPS: 1145 (0.87 mspf)

@jss2a98aj
Copy link
Member

jss2a98aj commented Nov 30, 2024

With production=yes performance is almost the same between the two implementations.
Before

Project FPS: 1233 (0.81 mspf)
Project FPS: 1242 (0.80 mspf)
Project FPS: 1223 (0.81 mspf)
Project FPS: 1240 (0.80 mspf)
Project FPS: 1240 (0.80 mspf)
Project FPS: 1234 (0.81 mspf)
Project FPS: 1240 (0.80 mspf)

After

Project FPS: 1247 (0.80 mspf)
Project FPS: 1250 (0.80 mspf)
Project FPS: 1250 (0.80 mspf)
Project FPS: 1250 (0.80 mspf)
Project FPS: 1251 (0.79 mspf)
Project FPS: 1250 (0.80 mspf)
Project FPS: 1252 (0.79 mspf)

@WhalesState
Copy link
Author

With production=yes performance is almost the same between the two implementations. Before

I see that after is faster by nearly 10 frames most of the time, also we are just skipping some useless calculactions that happens 4 times for each light update frame.

// Before
for (int i = 0; i < 4; i++) {
	Vector3 cam_target = Basis::from_euler(Vector3(0, 0, Math_TAU * ((i + 3) / 4.0))).xform(Vector3(0, 1, 0));
	projection = projection * Projection(Transform3D().looking_at(cam_target, Vector3(0, 0, -1)).affine_inverse());
}
// After
Projection projections[4] = {
	Projection(Vector4(0, 0, -1, 0), Vector4(1, 0, 0, 0), Vector4(0, -1, 0, 0), Vector4(0, 0, 0, 1)),
	Projection(Vector4(-1, 0, 0, 0), Vector4(0, 0, -1, 0), Vector4(0, -1, 0, 0), Vector4(0, 0, 0, 1)),
	Projection(Vector4(0, 0, 1, 0), Vector4(-1, 0, 0, 0), Vector4(0, -1, 0, 0), Vector4(0, 0, 0, 1)),
	Projection(Vector4(1, 0, 0, 0), Vector4(0, 0, 1, 0), Vector4(0, -1, 0, 0), Vector4(0, 0, 0, 1))
};
for (int i = 0; i < 4; i++) {
	projection = projection * projections[i];
}

@WhalesState WhalesState force-pushed the gles3-canvas-light-optimization branch from 309cdc1 to 15574c6 Compare December 1, 2024 00:24
@WhalesState
Copy link
Author

I have done some more changes to make it slightly faster.
Building both locally with optimize=none.

// Before
Project FPS: 103 (9.70 mspf)
Project FPS: 102 (9.80 mspf)
Project FPS: 105 (9.52 mspf)
Project FPS: 104 (9.61 mspf)
Project FPS: 104 (9.61 mspf)
Project FPS: 104 (9.61 mspf)
Project FPS: 105 (9.52 mspf)
Project FPS: 108 (9.25 mspf)
Project FPS: 104 (9.61 mspf)
Project FPS: 108 (9.25 mspf)

// After
Project FPS: 113 (8.84 mspf)
Project FPS: 104 (9.61 mspf)
Project FPS: 104 (9.61 mspf)
Project FPS: 104 (9.61 mspf)
Project FPS: 108 (9.25 mspf)
Project FPS: 104 (9.61 mspf)
Project FPS: 110 (9.09 mspf)
Project FPS: 112 (8.92 mspf)
Project FPS: 105 (9.52 mspf)
Project FPS: 113 (8.84 mspf)

@WhalesState WhalesState force-pushed the gles3-canvas-light-optimization branch from 15574c6 to ca21b41 Compare December 1, 2024 00:25
Copy link
Member

@jss2a98aj jss2a98aj left a comment

Choose a reason for hiding this comment

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

I have done some more changes to make it slightly faster. Building both locally with optimize=none.

I tried it with optimize=none as well, and the performance improvement is cleanly past margin of error.
Before

Project FPS: 668 (1.49 mspf)
Project FPS: 670 (1.49 mspf)
Project FPS: 669 (1.49 mspf)
Project FPS: 670 (1.49 mspf)
Project FPS: 670 (1.49 mspf)
Project FPS: 664 (1.50 mspf)
Project FPS: 670 (1.49 mspf)

After

Project FPS: 684 (1.46 mspf)
Project FPS: 681 (1.46 mspf)
Project FPS: 681 (1.46 mspf)
Project FPS: 683 (1.46 mspf)
Project FPS: 685 (1.45 mspf)
Project FPS: 684 (1.46 mspf)
Project FPS: 684 (1.46 mspf)

production=yes still just barely performs better, though within margin of error. I think this will be most beneficial on older systems. Those do need performance improvements the most anyways.

@jss2a98aj jss2a98aj merged commit 39e889c into blazium-engine:blazium-dev Dec 2, 2024
22 checks passed
@WhalesState WhalesState deleted the gles3-canvas-light-optimization branch December 2, 2024 07:46
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.

4 participants