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 union order to simplify empty initializers. #101344

Merged
merged 1 commit into from
Jan 9, 2025

Conversation

DarioSamo
Copy link
Contributor

This one's more of a general codebase issue but the particular structures I fixed were rendering related.

There's a bit of not so common knowledge regarding union initialization where only the very first element of the union is picked when using empty initializers such as {} if no other element in the union has an explicit initializer.

This leads to a very significant difference when it comes to code generation when bitfields are involved, as can be verified here:
https://gcc.godbolt.org/z/6vzYnz4ae

The code difference generation can actually introduce subtle bugs where unused bits on the union were left uninitialized, causing more pipeline generation than what is necessary.

We should make sure to follow the rule of always placing first the element that covers the entire union and has the most trivial initialization to ensure subtle bugs like this can't be introduced.

@DarioSamo DarioSamo requested a review from a team as a code owner January 9, 2025 13:44
@AThousandShips AThousandShips added this to the 4.4 milestone Jan 9, 2025
@akien-mga akien-mga merged commit 5240e60 into godotengine:master Jan 9, 2025
20 checks passed
@akien-mga
Copy link
Member

Thanks!

@darksylinc
Copy link
Contributor

Today I got bitten by this issue too (I was on an older master branch), Valgrind reports how these uninitialized variables propagate throughout the codebase.

I strongly recommend this patch to be backported to earlier versions. It may be more serious than we think.

@DarioSamo
Copy link
Contributor Author

I strongly recommend this patch to be backported to earlier versions. It may be more serious than we think.

The structs in the patch don't exist before 4.4.

@darksylinc
Copy link
Contributor

Then we missed some unions. I see them now.

I'll make another PR.

darksylinc added a commit to darksylinc/godot that referenced this pull request Jan 14, 2025
This is a followup to PR godotengine#101344 (commit
0e06eb8).

Some of them were not an issue because Godot was initializing all
members, but they were "fixed" just in case since it could become a
problem in the future.

Valgrind was specifically complaining about HashMapData &
GlobalPipelineData.
@darksylinc
Copy link
Contributor

Done.

Splizard pushed a commit to grow-graphics/godot that referenced this pull request Feb 2, 2025
This is a followup to PR godotengine#101344 (commit
0e06eb8).

Some of them were not an issue because Godot was initializing all
members, but they were "fixed" just in case since it could become a
problem in the future.

Valgrind was specifically complaining about HashMapData &
GlobalPipelineData.
tGautot pushed a commit to tGautot/godot that referenced this pull request Feb 5, 2025
This is a followup to PR godotengine#101344 (commit
0e06eb8).

Some of them were not an issue because Godot was initializing all
members, but they were "fixed" just in case since it could become a
problem in the future.

Valgrind was specifically complaining about HashMapData &
GlobalPipelineData.
tGautot pushed a commit to tGautot/godot that referenced this pull request Feb 5, 2025
This is a followup to PR godotengine#101344 (commit
0e06eb8).

Some of them were not an issue because Godot was initializing all
members, but they were "fixed" just in case since it could become a
problem in the future.

Valgrind was specifically complaining about HashMapData &
GlobalPipelineData.
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.

5 participants