-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
vulkan system dep: determine version on cross builds #13910
base: master
Are you sure you want to change the base?
Conversation
That's a clever trick. The way it's traditionally done is using
But that's massively slower because it's implemented as a binary search of the value, compiling a program that fails to build until we guessed the right value. See https://github.com/mesonbuild/meson/blob/master/mesonbuild/compilers/mixins/clike.py#L470. Now I'm wondering if |
Oh I didn't see that
God, that is truly horrifying 🤣
Besides the issue that a header included during preprocessing could theoretically contain |
I don't think we can or should rely on preprocess + native compile hacks for answering questions of any sort unless we know via some mechanism that the answer is required to be correct. This could mean for example reading the vulkan headers and asserting that it always spits out non-platform-specific preprocessed text that can then be compiled by any platform to produce a correct answer without linking to the vulkan libraries. Evaluating the size of an int isn't something you can guarantee is required to be correct, because if it were required to be correct then people wouldn't need to check it... using this kind of hack might be useful as a guess which can then be verified via the existing cross-safe logic, though, in order to cut down on the search space in optimal cases. But I don't think it's useful to even theorize about removing the final check. |
Very confused by Eli's comment, so I'm just going to ignore that. First off, this should use Second, I agree with @xclaesse that this check should just use
Third, you've invented a very useful and interesting mechanism of detecting the computed value of defines in a header without running something. I think we should use it to speed-up I don't think we should worry about supporting |
Actually, I guess we shouldn't do this, because it might break detecting older Vulkan SDKs. Maybe just leave a comment to that effect, in case they remove the macro in the future. |
Currently, the vulkan system dep detects its vulkan version by building and running: int main() { printf("%i.%i.%i", VK_VERSION_MAJOR(VK_HEADER_VERSION_COMPLETE), VK_VERSION_MINOR(VK_HEADER_VERSION_COMPLETE), VK_VERSION_PATCH(VK_HEADER_VERSION_COMPLETE)); return 0; } this causes cross builds that do not have the possibility of running on the build machine to evaluate the vulkan dependency with an 'Unknown' version. Instead of evaluating beforementioned piece of C code, the new implementation will instead use cc.compute_int to evaluate the three preprocessor macros. This is relativly expensive for cross builds right now but further optimizations can be made. See mesonbuild#13910 for more details.
c2169f6
to
c4592db
Compare
Currently, the vulkan system dep detects its vulkan version by building and running: int main() { printf("%i.%i.%i", VK_VERSION_MAJOR(VK_HEADER_VERSION_COMPLETE), VK_VERSION_MINOR(VK_HEADER_VERSION_COMPLETE), VK_VERSION_PATCH(VK_HEADER_VERSION_COMPLETE)); return 0; } this causes cross builds that do not have the possibility of running on the build machine to evaluate the vulkan dependency with an 'Unknown' version. Instead of evaluating beforementioned piece of C code, the new implementation will instead use cc.compute_int to evaluate the three preprocessor macros. This is relativly expensive for cross builds right now but further optimizations can be made. See mesonbuild#13910 for more details.
c4592db
to
1cb13f3
Compare
Currently, the vulkan system dep detects its vulkan version by building and running: int main() { printf("%i.%i.%i", VK_VERSION_MAJOR(VK_HEADER_VERSION_COMPLETE), VK_VERSION_MINOR(VK_HEADER_VERSION_COMPLETE), VK_VERSION_PATCH(VK_HEADER_VERSION_COMPLETE)); return 0; } this causes cross builds that do not have the possibility of running on the build machine to evaluate the vulkan dependency with an 'Unknown' version. Instead of evaluating beforementioned piece of C code, the new implementation will instead use cc.compute_int to evaluate the three preprocessor macros. This is relativly expensive for cross builds right now but further optimizations can be made. See mesonbuild#13910 for more details.
1cb13f3
to
be2af61
Compare
Currently, the vulkan system dep detects its vulkan version by building and running: int main() { printf("%i.%i.%i", VK_VERSION_MAJOR(VK_HEADER_VERSION_COMPLETE), VK_VERSION_MINOR(VK_HEADER_VERSION_COMPLETE), VK_VERSION_PATCH(VK_HEADER_VERSION_COMPLETE)); return 0; } this causes cross builds that do not have the possibility of running on the build machine to evaluate the vulkan dependency with an 'Unknown' version. Instead of evaluating beforementioned piece of C code, the new implementation will instead use cc.compute_int to evaluate the three preprocessor macros. This is relativly expensive for cross builds right now but further optimizations can be made. See mesonbuild#13910 for more details.
be2af61
to
4175207
Compare
Currently, the vulkan system dep detects its vulkan version by building and running: int main() { printf("%i.%i.%i", VK_VERSION_MAJOR(VK_HEADER_VERSION_COMPLETE), VK_VERSION_MINOR(VK_HEADER_VERSION_COMPLETE), VK_VERSION_PATCH(VK_HEADER_VERSION_COMPLETE)); return 0; } this causes cross builds that do not have the possibility of running on the build machine to evaluate the vulkan dependency with an 'Unknown' version. Instead of evaluating beforementioned piece of C code, the new implementation will instead use cc.compute_int to evaluate the three preprocessor macros. This is relativly expensive for cross builds right now but further optimizations can be made. See mesonbuild#13910 for more details.
4175207
to
a7c39b2
Compare
@nirbheek: I've tried using get_define in order to speed up cross_compute_int: sp1ritCS@ef74545 There are two issues with it: what headers should be included for the build machine? For example vulkan needs #include <vulkan/vulkan.h>
#ifndef VK_VERSION_PATCH(VK_HEADER_VERSION_COMPLETE)
# define VK_VERSION_PATCH(VK_HEADER_VERSION_COMPLETE) "MESON_GET_DEFINE_UNDEFINED_SENTINEL"
#endif
"MESON_GET_DEFINE_DELIMITER_START"
VK_VERSION_PATCH(VK_HEADER_VERSION_COMPLETE)
"MESON_GET_DEFINE_DELIMITER_END" which gcc doesn't really like and other compilers might fail 🤔
|
I think the |
With guess being correct it obv. only takes one "iteration". The finding of the correct patch version takes 20 iterations. |
With no guess or limits, 27 compilations:
That's actually not that bad, on my laptop that's instantaneous. Of course that kind of stuff adds up in the configure process. One thing meson can do is parallelize those a bit, I had a branch a while ago for that. |
Yeah, glib uses it for computing POLLIN etc, and I went to measure it and it was basically instant. I would recommend making this work first so you are unblocked on your gtk-android work, and we can also backport it easily to 1.6.x. Then we can do the optimizations in a separate PR, which we won't backport. |
thats what I had in mind. This PR is basically ready (I don't think I'm responsible for breaking the windows tests) and my speedup_cross_compute_int branch is independent on this. I just didn't want to create a PR for it yet given the issues I've mentioned.
I'm fine with simply providing a vulkan.pc with gtk-android-builder, this doesn't really block much. #13800 is the far larger blocker 🙃 |
Please open the PR anyway and we can keep the discussion in the right place :) |
Currently, the vulkan system dep detects its vulkan version by building and running:
this causes cross builds that do not have the possibility of running on the build machine to evaluate the vulkan dependency with an 'Unknown' version.
The new implementation provides a fallback mechanism that first evaluates the same code as above (just without the stdio import) using the C Preprocessor for the host machine and then takes the evaluated main function, adds the required stdio and stdint headers and builds it using the build machine c compiler in order to get the vulkan version for the host machine.