Update FindVulkan.cmake to cross-compile for Windows/Windows on ARM64#1490
Update FindVulkan.cmake to cross-compile for Windows/Windows on ARM64#1490fgiancane8 wants to merge 11 commits intoKhronosGroup:mainfrom
FindVulkan.cmake to cross-compile for Windows/Windows on ARM64#1490Conversation
Let CMake use its own bundled version of this module. It is more maintained and has some quality of life fixed, most notably cross-compilation on Windows(ARM64/Intel). See KhronosGroup#1489 for more context about this change.
|
This is failing on iOS because the standard version of FindVulkan.cmake is missing the following code. In contrast, this code is present in the downstream project version: Possible solutions:
Option 3 is likely the best IMHO and would retain your main objective for this PR. The updated CMakeLists.txt code would look like this: |
|
Thanks for testing @SRSaunders You're exactly right. While we are not quite to the point where we can do a complete removal of findVulkan.cmake in favor of a package maintained config variation; which would be the ultimate correct solution. I think, if possible we should promote these changes back to kitware's gitlab version; then remove the copy here. In the meantime, we should at a minimum accept the upstream changes to our copy of findVulkan.cmake. |
|
Thanks @gpx1000. Just to clarify, Option 1 (merge upstream changes into the project's FindVulkan.cmake) and Option 3 (remove FindVulkan.cmake and patch CMakeLists.txt) are mutually exclusive - we should do one or the other, but not both. Option 2 could happen in parallel regardless and let that process take its course. |
|
I'm not a fan of option 3; it invites a lot of questions as to why it's required and encourages end users to think the top level CMakeLists.txt is too complex to learn anything from (a feedback item we're already receiving). As much as possible, I want to encourage the "best practice" of using find_library(vulkan) being the universal only thing that is needed by end users beyond needing the findVulkan.cmake file if necessary. |
|
Note that there is a discussion on removing the FindVulkan.cmake from CMake: https://gitlab.kitware.com/cmake/cmake/-/issues/25617 |
|
Thanks @SaschaWillems. From the discussion link it seems that Option 1, i.e. merging upstream changes and retaining the project-specific FindVulkan.cmake, is the right way to go. While it appears that Kitware is still accepting changes to the FindVulkan module, the longer term view is that downstream projects should handle it themselves. |
|
Hello and thanks for all the feedbacks! So I started already the discussion with upstream CMake and sounds like the accepted go-to is to at some point remove In the meanwhile what I can do is:
Let me know what you all folks think about. |
Reached out to upstream CMake folks to further clarify. This issue was linked to my previous Pull Request for |
So my understanding on this is that the split would be a requirement since Vulkan on Linux is managed by distro packagers, while on Windows/iOS/macOS is packaged with LunarG SDK. Android is managed by Android SDK itself. So it would make sense to keep the upstream version as much updated as possible so that:
This is what I feel would be the best outcome but let's discuss, I'd like to reach for a conclusion that works for all these major platforms without duplicating too much between vendored/downstream/upstream. |
Seems like it's not on priority list and will take time to materialise. The thread got revived today with similar issues. So as of now, it's basically mostly on upstream CMake and this repo. |
|
FYI: https://gitlab.kitware.com/cmake/cmake/-/issues/27661 Upstream CMake provided a recommended way to build on iOS. They recommended us to have an iOS toolchain file and amend the way we search for the Vulkan SDK. I'll try and post another commit to see if that fixes the issue. |
As per upstream CMake recommendations, configure iOS targets using a toolchain file.
Move all the variables that were passed through command line here, as per CMake upstream recommendation.
|
Thanks for tracking this down and working with kitware on this. The toolchain file idea is not a bad one. We might want to think if there's a way to do additional toolchain files as downstream projects from us (i.e. lots of people copy paste directly out of samples) might use toolchain files for project specific needs and this might inhibit their use if we take up the project's sole toolchain slot. This concern might be addressed via documentation and highlighting the toolchain requirement. But, it is worth considering if we want this for best practice recommendations which samples are meant to be. |
No worries at all!
@gpx1000 , |
|
Well, all platforms technically can use Vulkan Samples, so everything from a rPi / wrist watch to desktop or server rack or XR development rig including the Apple headset, watch, phone, TV, car etc could all be potential platform end points. Each are popular places to have a toolchain. It might be exceedingly rare to the point of not even the SDK has a pre-made build for such platform. But, each does have a potential role as a target end platform. Samples are useful to validate that Vulkan is working on newer unreleased systems as well; so it's hard to predict where it might be used and we try to opt for practices in general that don't make assumptions about what end users might require. If we can make a decision that doesn't restrict users that's what we typically try to do. |
Makes sense. So in my mind:
|
|
By the way, I see we do not yet build for Windows on ARM64. Since this change is exactly trying to validate that, maybe that target should be added as well. |
|
Well we can keep this solely targeted to iOS. It's just important to remember the scope of potential platforms when we make decisions like using a toolchain file vs not. Yes, we can add windows ARM64 build to the CI, but CI in windows already takes a really long time and it's something I've been struggling to find ways to make faster already. I'm hesitant to add more to the CI for windows until I can get the build time reduced on windows. |
Sure, was just sharing couple of ideas to brainstorm on the subject. Let's see if these changes are enough to better align with upstream CMake. We can take further action from there. Thanks! |
|
Good news, build for iOS correctly detected 🚀 Vulkan-Samples/app/CMakeLists.txt Lines 138 to 148 in 19a5668 |
|
iOS is a bit more complicated than just finding the pre-installed Vulkan runtime libraries and dynamically linking to them at runtime which is all you need on most desktop platforms. iOS and other device-oriented Apple platforms (e.g. iPad, AppleTV) require packaging all library dependencies (i.e. MoltenVK.framework and optionally Vulkan.framework and VkLayer_khronos_validation.framework) into an app bundle for installing onto a physical device or device simulator. Because of this Vulkan-Samples needs to know specific library locations so Xcode can build the app bundle and load onto the chosen device or simulator for execution and debugging. The locations are identified by CMake variables set by find_package(Vulkan) which uses project's FindVulkan.cmake as the underlying module. The cmake variables are: I guess this is a long-winded way of saying that any replacement for the FindVulkan.cmake module needs to take these variables into account and define them, or if not possible, change the iOS logic in the above two files to accommodate. The latter is possible but not that much fun as it would mandate a bunch of retesting. And since I was the last person to update most of this iOS-specific logic it would likely fall to me or @gpx1000. With that said, if the only error is an undefined Note that my original Option 3, which @gpx1000 did not like due to adding complexity to the main CMakeLists file, solved the problem without any change to the logic in the two files named above. As an alternative, I could move the same logic from Option 3 into global_options.cmake instead, since that file calls |
|
Going back to the beginning, and perhaps I am missing something here, but given the following: from @fgiancane8:
from @gpx1000:
Why are we trying to change FindVulkan.cmake if Windows ARM64 was the reason for this PR, but will not be added to the project as an official target with CI, at least for now? In spite of the discussion regarding technical alternatives above, iOS currently works just fine with no changes to the project's current FindVulkan.cmake. Is the request in this PR therefore to provide "unofficial" support for Windows ARM64? i.e. allow it to work without adding it as a CI target? Before jumping into cmake changes, I would like to understand the reason and scope. |
Checked upstream CMake, and only
So I posted an update on this. Looks like the SDK is properly detected, but it fails at the app/CMakeLists.txt because of the packaging as resource command over there. I don't really know what's going on there so an explanation would be very appreciated as well! (I am no iOS/macOS developer, only know the ways of Linux and Windows).
Thanks for the super detailed explanation, really appreciated it! |
So the reason for this PR was to fix issues when cross-compiling Vulkan apps to and from ARM64. As of now either Intel machine to ARM64 machine or ARM64 machines to Intel builds are broken. I posted a fix upstream and since there is the whole discussion of unifying the modules, plus CMake will eventually remove their module in favour of LunarG's one (whenever it happens), I was trying to be nice and have a working solution for all Vulkan platforms in place.
Not at all. We can discuss WoA on a separate issue/PR if needed. The goal here was to enable people to cross compile on Windows for both its supported architectures (Intel/ARM64) since LunarG is shipping SDKs supporting both targets. Also a note on the "unofficial": as far as I can tell, LunarG SDK on Windows officially supports Windows on ARM64, shouldn't we consider that enough to mark the target as official? Not saying we need to add CI and strong testing today, maybe tier 2? I would expect people to at some point start playing with Vulkan Samples on those machines as well. What's your thoughts on this? |
Thanks for your clear restatement of the issue. Are Windows ARM64 native builds working with the current project cmake files? Is it only the Windows cross compilation scenarios that aren't? I know from my own efforts that macOS arm64 (Apple Silicon) native builds do work without issue, and cross compiling from macOS x86_64 hosts to iOS arm64 targets also works fine.
Regarding expanding Vulkan-Samples official supported platforms list, that is above my pay grade 😄. I am a contributor with expertise in Apple platforms, but not a maintainer here. Please ask @gpx1000 about whether Windows on ARM64 and Win x86_64 to ARM64 cross-compilation builds (and vice versa) are within the project's scope. As an aside I don't have the hardware for testing those scenarios so can't really contribute on that side of things. To keep things moving on the technical side for possibly removing the project FindVulkan.cmake, can you tell me specifically what you did to generate the cmake error at app/CMakeLists.txt:140 (target_sources):? Okay, I see that you posted new commits. I will have a look at those first... |
|
@fgiancane8 the error caused by an undefined In Vulkan-Samples/app/CMakeLists.txt add the following line: Your solution with the toolchain file finds the iOS Vulkan frameworks because of updating
See the following link for docs on how to build for iOS: https://github.com/KhronosGroup/Vulkan-Samples/blob/main/docs/build.adoc#ios I suppose we could make 3 toolchain file for iOS:
However, this toolchain stuff feels a bit of overkill for the problem at hand. Only two small things really have to change to make this PR (i.e. remove project FindVulkan.cmake) work:
I have tried this and it works fine with no toolchain files. Nothing else has to change, including CI and docs. The only downside is that the project FindVulkan.cmake also defines layer cmake variables: |
No problem at all. So I haven't tested it extensively. We had couple of issues with other projects using Vulkan on Windows on ARM64. I fixed them on CMake upstream initially (as there were some relics of x86 era SDK and no proper management of ARM64). As far as I can tell, with my changes on upstream CMake all the combinations of Windows flavours and Vulkan work.
Haha of course nothing binding here, was talking about community effort altogether. Not expecting to leave all the burden on you (or other solo efforts as well!)
I let the CI here do its own tests. You can find the full log failures here: https://github.com/KhronosGroup/Vulkan-Samples/actions/runs/22683125940/job/65768554240 Just for reference: I would consider the proper/official/recommended command line to build on iOS targets. |
Thanks @gpx1000 ! Take your time for the review,there's no rush. Have a good one and for further clarifications just ping me/us. |
This reverts commit 1a672f7.
This reverts commit 6f1680f.
This reverts commit 265d313.
Backport these patches into our downstream `FindVulkan` CMake module:
5e1440302a FindVulkan: Add support for cross-compiling between Windows x64/ARM64
f9a09f76f3 FindVulkan: Drop support for 32-bit SDK on Windows
b40740f28a FindVulkan: Do not search bin directories for libraries
947adbba91 FindVulkan: Use ENV{VULKAN_SDK} only if it exists
This allows proper libraries discovery of Vulkan Libraries on Windows,
both for x86_64 and ARM64 targets.
Co-Authored-By: Brad King <brad.king@kitware.com>
Tested-By: Giancane, Francesco <fgiancan@qti.qualcomm.com>
FindVulkan.cmakeFindVulkan.cmake to cross-compile for Windows/Windows on ARM64
|
@SRSaunders P.S. if this is ever going to be merged, please squash the commit logs with the PR text otherwise we'll get a lot of unpleasant "revert xxxx" not super cool :) |
Thanks @fgiancane8, I will review this weekend. In the mean time I have submitted my PR with the iOS build changes. I cited you in the copyright notice for the new ios.cmake toolchain file. Thanks for your help on this. |
Thanks @SRSaunders enjoy the weekend and let me know if there is something to amend. I could not post the downstream changes to CMake but will do it either this weekend or on Monday. Talk to you later! |
|
@SRSaunders , On Windows, those Layers are (correctly) marked as not found as there is no .lib file and they are only provided as DLLs. Can you check that these changes work only in the iOS case? I marked the Let me know if there is something else to be addressed, otherwise I think that after this gets reviewed and is merged, we are on feature parity between upstream and downstream |
|
Please find here the upstream MR to add Vulkan Layers discovery capability: https://gitlab.kitware.com/cmake/cmake/-/merge_requests/11808 This would in turn mitigate what was missing on the IOS part as @SRSaunders mentioned. Feedbacks/comments on the upstream MR are welcomed from folks here as well. On a side note, with CMake < 4.3 on MacBooks, finding properly Frameworks for iOS is broken: we may still need to keep the downstream version of FindVulkan around for people not updating to latest CMake, maybe adding a deprecation note somewhere. I was thinking of conditionally including the bundled version of the module only if the detected CMake version is less than 4.3 or whatever upstream version ends up with feature parity with us in their module (possibly 4.4). I'll keep you posted and report once the MR is discussed and reworked or merged. |
gpx1000
left a comment
There was a problem hiding this comment.
Guys, this works well for me. Thanks so much for the work on this!!
37783f6 to
5e92e7f
Compare
|
@gpx1000 sorry I had to force-push to amend the licensing issues. I think there's no need for my changes to be BSD-3-Clause but I am still waiting for the final legal response. |
|
Ah, no worries then. Comment here when you're ready. This has my testing approval when/if you are able to accept the license. |
|
It's just a matter of when, the ifs are mostly cleared :) thanks for the patience! |
|
@fgiancane8 thanks for pushing this forward, but notice you have not replied to my review comments above:
Before proceeding with this PR, would you be able to reply to my review comments? Thanks. |
Sorry @SRSaunders , i missed the comments. I have no problem amending my part. I'll reduce the scope to windows only and let you take care of the rest! |
Changes are addressed in KhronosGroup#1500.
fgiancane8
left a comment
There was a problem hiding this comment.
@SRSaunders , @gpx1000
This should be the final version.
|
@fgiancane8 thanks for removing the Apple-specific parts. The rest looks fine, although I cannot test the Windows ARM stuff since I don't have hardware. I do notice that some legacy Windows Vulkan SDK stuff may be removed here, such as bin32 and lib32, and searching for libs in the bin folder. Is this a concern? I am not a Windows Vulkan SDK expert so I cannot offer an opinion on this. Lastly, and just a small nit, I wonder if you should |
Thanks! This is what I've posted upstream and was extensively tested. It should be good to go. Lib32 and Bin32 are already removed. (at least this is what I see from the diff).
Let me double-check. The plan was to unset the variable just after its usage. It may be an unwanted result of removing the apple code. |
As per request on the discussion thread, let's just import the changes required to build Vulkan Samples on Windows/Windows on ARM64.
9df760a to
1765f77
Compare
fgiancane8
left a comment
There was a problem hiding this comment.
Aesthetic changes to unset.
|
@fgiancane8 this looks good to me. I think all you need to do now is accept the CLA. |
|
CLA accepted. Thank you all for the time and the reviews! |
Backport patches from upstream CMake to support Windows cross-compilation use cases (
x86_64toARM64and vice-versa).Upstream patches backported:
5e1440302a FindVulkan: Add support for cross-compiling between Windows x64/ARM64
f9a09f76f3 FindVulkan: Drop support for 32-bit SDK on Windows
b40740f28a FindVulkan: Do not search bin directories for libraries
947adbba91 FindVulkan: Use ENV{VULKAN_SDK} only if it exists
See #1489 for more context about this change.
General Checklist:
Please ensure the following points are checked:
My code follows the coding styleI have commented any added functions (in line with Doxygen)I have commented any code that could be hard to understandI have used existing framework/helper functions where possibleNote: The Samples CI runs a number of checks including:
I have updated the header Copyright to reflect the current year (CI build will fail if Copyright is out of date)