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

detail::GenericFeaturesPNextNode's constructor is error-prone due to inconsistent struct alignment #295

Open
n0F4x opened this issue Jul 3, 2024 · 3 comments

Comments

@n0F4x
Copy link
Contributor

n0F4x commented Jul 3, 2024

I had an issue where creating a Vulkan feature struct ended up with a rounded alignment (32 bytes), but the same structure created in another context was not aligned (28 bytes).
This made the resulting detail::GenericFeaturesPNextNodes different.

I was trying to use PhysicalDevice::are_extension_features_present with the 28-byte version as a parameter, and the function returned an unexpected result as the stored feature had been aligned to 32 bytes.
Based on the differing "last" 4 bytes I got the result that the requested feature is not supported, whereas this is not true.

Compiled with:
Clang version 17.0.6
Target x86_64-w64-windows-gnu

@n0F4x
Copy link
Contributor Author

n0F4x commented Jul 4, 2024

Here are some more tests.

Calling PhysicalDevice::are_extension_features_present normally:
normal call
temp

Calling PhysicalDevice::are_extension_features_present with a static variable:
static_call
static

@n0F4x
Copy link
Contributor Author

n0F4x commented Jul 4, 2024

The problem is not that the struct doesn't get aligned correctly, but that the value of the extra alignment bits are inconsistent.

@charles-lunarg
Copy link
Owner

I didn't forget about this - I just had other priorities since this issue was created.
The real solution is to generate all the struct comparisons. I cannot see a way to do generic struct comparisons that ultimately doesn't leave the code liable to padding concerns. sizeof cannot be trusted to yield useful values.

I started working on a branch which does the codegen, but it became a bigger task than I could finish in a day and had to put it to the side for the time being.

The WIP branch with my progress is here:
https://github.com/charles-lunarg/vk-bootstrap/tree/generate_feature_struct_comparisons

(I swear I had typed out a reply but maybe I never hit enter, and it was lost on a machine reset?)

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