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

Fix usages of mesh simplification functions in float=64 builds #67853

Merged
merged 1 commit into from
Jan 2, 2023

Conversation

Zylann
Copy link
Contributor

@Zylann Zylann commented Oct 24, 2022

Fixes #67772

It would be nice if Godot had Vector3f packed arrays in the first place for positions and normals, since that's what they become anyways in the renderer (even for physics it would help, since only broad phase could need doubles).

@Zylann Zylann requested a review from a team as a code owner October 24, 2022 20:57
@clayjohn
Copy link
Member

I wonder if we could use Marshalls::decode_variant() here instead.

@Zylann
Copy link
Contributor Author

Zylann commented Oct 24, 2022

How so? There is no Variant in this code.

@clayjohn
Copy link
Member

How so? There is no Variant in this code.

PackedVector3Array is a variant

@Zylann
Copy link
Contributor Author

Zylann commented Oct 24, 2022

I still don't understand how using Marshall::decode_variant is better than what I did (or even how it solves the problem). This is not about deserializing data from a saved resource, it's about fixing mesh optimization calls for mesh data that's already loaded.

The code where we send data to MeshOptimizer had to be fixed, because it was just wrong in 64-bit float builds. Import went fine.
It is reported reverting #65493 makes the issue go away, so I had a look: I couldnt find anything that stands out with doubles, apart from the fact it was using generate_lods, which this PR fixes, so it may have contributed to the problem.

Edit: I hadn't initially tested with a 64-bit build without this PR, and finally saw it was broken, so I can confirm this PR fixes the issue.

@clayjohn
Copy link
Member

clayjohn commented Oct 25, 2022

Looking into it deeper it looks like Marshall::decode_variant() only runs on buffers that were encoded with Marshall::encode_variant(), so indeed it won't be usable here.

The code here is fine, but I wonder if SurfaceTool is the best place to host the conversion function. I wonder if it would be better to make it something that is more related to PackedVector3Array

Also, we have #ifdef REAL_T_IS_DOUBLE to check if real_t is double, so we can avoid the extra function entirely on non-doubles builds if we want.

@clayjohn
Copy link
Member

We discussed this on the RocketChat. Reduz let us know that we should not be casting PackedVector3Array to *float as we will likely add padding to PackedVector3Array to make it more efficient on mobile hardware. Therefore, we need to add a conversion function somewhere. Reduz originally suggested adding the code to Variant, but suggested that doing it there may make it difficult to access from C++.

To move forward with this PR I guess we just need to figure out where the best place for a PackedVector3Array -> *float (or maybe PackedFloat32Array) would be.

@Zylann
Copy link
Contributor Author

Zylann commented Nov 10, 2022

marshalls?

I probably won't add it to variant for now, but I was pretty much waiting for where I should put this so that ##67772 would be fixed

@clayjohn
Copy link
Member

marshalls?

I probably won't add it to variant for now, but I was pretty much waiting for where I should put this so that ##67772 would be fixed

I guess so. I took another look today and I can't think of any better place for it.

@Zylann Zylann force-pushed the fix_lods_with_doubles branch from 8aa593a to 2aefdcc Compare November 12, 2022 01:16
@Zylann Zylann requested a review from a team as a code owner November 12, 2022 01:16
@fire
Copy link
Member

fire commented Dec 26, 2022

@lyuma I tested this and LODs are not broken. Did not deeply review the code.

@clayjohn clayjohn merged commit 61c7b7f into godotengine:master Jan 2, 2023
@clayjohn
Copy link
Member

clayjohn commented Jan 2, 2023

Looks great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Double Precision builds import with worst LODs
5 participants