Skip to content

Autodesk: build_usd.py now installs Vulkan dependencies #3603

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

erikaharrison-adsk
Copy link
Contributor

@erikaharrison-adsk erikaharrison-adsk commented Apr 16, 2025

Description of Change(s)

  • Using build_usd.py, build and install:
    • Vulkan-Headers
    • Vulkan-Utility-Libraries
    • Vulkan-Loader
    • SPIRV-Reflect
    • VulkanMemoryAllocator
    • shaderc
  • Only the required build and runtime files are installed. Tools and debug binaries (like validation layers) are expected to be installed externally (by the Vulkan SDK).
  • All versions match the ones from Vulkan SDK 1.3.296.0 (last 1.3.x release)
  • Removed third party files from hgiVulkan, they are now handled by build_usd.py
    • We had to do some small code changes in hgiVulkan in order to better use the third party dependencies
  • Installing the Vulkan ICD loader will prevent load-time link issues if no Vulkan enabled graphics driver is installed
    • This is an uncommon situation, but we've had it happen, especially in VMs
    • This is an allowed use case for distributing the ICD
  • Using the Vulkan SDK is still supported
    • When using the new argument --use-vulkan-sdk
    • When not using build_usd.py
  • Use BUILD_LOCAL_INTERFACE to keep the hgiVulkan private dependencies out of the pxr target export.
    • This makes it simpler for client projects to import the pxr targets. You don't need to link against as many targets.
    • It's still possible to manually do find_package (using the USD install path) and link against the installed Vulkan dependencies.
  • Add the Vulkan dependencies to pxrConfig.cmake.
    • Make it even simpler for client projects. It also takes care of the Vulkan SDK and build_usd.py differences.
    • Only the public dependencies (not wrapped in BUILD_LOCAL_INTERFACE) need to be found.

Link to proposal (if applicable)

  • N/A

Fixes Issue(s)

  • N/A

Checklist

@jesschimein
Copy link
Collaborator

Filed as internal issue #USD-10914

(This is an automated message. See here for more information.)

@jesschimein
Copy link
Collaborator

/AzurePipelines run

@DarkDefender
Copy link

DarkDefender commented Apr 22, 2025

I've tested this out and it works really well besides two issues:

  1. If I build VulkanMemoryAllocator myself using the default build options for it (not using the build_usd.py script), building openUSD will fail. I would change this so that we always use #include <vk_mem_alloc.h>. Then when using the VULKAN_SDK, we add $ENV{VULKAN_SDK}/include/vma to the default include directories. This way people can use the default/standard VulkanMemoryAllocator without any issues.

  2. When building with GCC 14 on my machine, pxr/imaging/hgiVulkan/sampler.cpp fails to compile because of a missing include. Simply adding #include <algorithm> in the file will solve the build issue.

@DDoS DDoS force-pushed the adsk/feature/vk-install branch from 3808f58 to 901ee01 Compare April 22, 2025 14:19
@DDoS
Copy link
Contributor

DDoS commented Apr 22, 2025

I've tested this out and it works really well besides two issues:

1. If I build VulkanMemoryAllocator myself using the default build options for it (not using the `build_usd.py` script), building openUSD will fail. I would change this so that we always use `#include <vk_mem_alloc.h>`. Then when using the VULKAN_SDK, we add `$ENV{VULKAN_SDK}/include/vma` to the default include directories. This way people can use the default/standard VulkanMemoryAllocator without any issues.

2. When building with GCC 14 on my machine, `pxr/imaging/hgiVulkan/sampler.cpp` fails to compile because of a missing include. Simply adding `#include <algorithm>` in the file will solve the build issue.

Thanks for the feedback, I made some changes, let me know if that fixes your issues.

@DarkDefender
Copy link

I can confirm that it fixes my issues! Thanks! :)

@jesschimein
Copy link
Collaborator

/AzurePipelines run

@DarkDefender
Copy link

DarkDefender commented Apr 23, 2025

@DDoS the new commit breaks compilation for me.
The build now errors out with spirv_reflect not being able to find the spirv headers anymore:

pxr/imaging/hgiVulkan/shaderCompiler.cpp
In file included from pxr/imaging/hgiVulkan/shaderCompiler.cpp:15:
/usr/include/spirv_reflect.h:37:10: fatal error: ./include/spirv/unified1/spirv.h: No such file or directory
   37 | #include "./include/spirv/unified1/spirv.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

If I skip the new commit and just apply the build_usd.py now installs Vulkan dependencies commit, everything compiles fine again.

Seems like your changes somehow broke the logic for passing SPIRV_REFLECT_USE_SYSTEM_SPIRV_H to spirv_reflect

@DDoS
Copy link
Contributor

DDoS commented Apr 23, 2025

@DarkDefender can you please share your spirv-reflect_* cache variable values?

@DarkDefender
Copy link

@DDoS if I grep the cmake cache file I get these two:

spirv-reflect_INCLUDE_DIR:PATH=/usr/include
spirv-reflect_LIBRARY:FILEPATH=/usr/lib/libspirv-reflect-static.a

@DDoS
Copy link
Contributor

DDoS commented Apr 23, 2025

@DarkDefender can you add some debug message() to this condition if (SpirvReflect_FOUND AND NOT EXISTS "${spirv-reflect_INCLUDE_DIR}/include/spirv/unified1/spirv.h") in FindSpirvReflect.cmake to see what the result is?


# In either case we have custom logic for SPIRV-Reflect
find_package(SpirvReflect MODULE REQUIRED)
list(APPEND VULKAN_LIBS $<BUILD_LOCAL_INTERFACE:spirv-reflect>)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I change this back to list(APPEND VULKAN_LIBS spirv-reflect) it seems to work.
I'm guessing that the SpirvReflect_IS_SOURCE_DEP check is needed here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's strange, I didn't expect this to make a difference. I'll have to try harder and reproduce this issue locally to debug. Thanks for helping out.

@DarkDefender
Copy link

@DarkDefender can you add some debug message() to this condition if (SpirvReflect_FOUND AND NOT EXISTS "${spirv-reflect_INCLUDE_DIR}/include/spirv/unified1/spirv.h") in FindSpirvReflect.cmake to see what the result is?

The debug message() gets triggered for me. target_compile_definitions(spirv-reflect INTERFACE SPIRV_REFLECT_USE_SYSTEM_SPIRV_H) should be executed.

@jesschimein
Copy link
Collaborator

/AzurePipelines run

@DDoS
Copy link
Contributor

DDoS commented Apr 24, 2025

@DarkDefender Which CMake version are you using? Which build system?

I really can't reproduce this issue. When I build with build_usd.py, SPIRV_REFLECT_USE_SYSTEM_SPIRV_H is enabled, and spirv.h is found.

@jesschimein
Copy link
Collaborator

/AzurePipelines run

@DarkDefender
Copy link

@DDoS I'm using cmake 3.31.7 and ninja.

Are you sure that the build_usd.py script doesn't copy in the spirv/unified1/spirv.h header?
The CopyDirectory(context, 'include/spirv', 'include/spirv') line makes me a bit suspicious that this might be the case.
If this is the case you wouldn't really notice that SPIRV_REFLECT_USE_SYSTEM_SPIRV_H doesn't get picked up as it will find the spirv.h header that is bundled with spirv-reflect.

@DDoS
Copy link
Contributor

DDoS commented Apr 24, 2025

@DarkDefender The relevant build_usd.py include paths are

  • include
    • spirv_reflect.h
    • spirv
      • unified1
        • spirv.h

When SPIRV_REFLECT_USE_SYSTEM_SPIRV_H is undefined, the path relative to spirv_reflect.h needs to start with include (./include/spirv/unified1/spirv.h), which here it doesn't. Furthermore I can check the compiler command line in build.ninja and see that -DSPIRV_REFLECT_USE_SYSTEM_SPIRV_H is given when building shaderCompiler.o.

Since it appears you're using a system package manager install of spirv-reflect, can you confirm the header does support this define? It was added three years ago: KhronosGroup/SPIRV-Reflect@f2241d5 (sdk-1.3.216.0).

@DarkDefender
Copy link

@DDoS I am using the latest git version of https://github.com/KhronosGroup/SPIRV-Reflect
It does have SPIRV_REFLECT_USE_SYSTEM_SPIRV_H as it wouldn't have worked before if that wasn't the case.

It seems like on my end list(APPEND VULKAN_LIBS $<BUILD_LOCAL_INTERFACE:spirv-reflect>) will ignore that we set SPIRV_REFLECT_USE_SYSTEM_SPIRV_H with target_compile_definitions(spirv-reflect INTERFACE SPIRV_REFLECT_USE_SYSTEM_SPIRV_H) while list(APPEND VULKAN_LIBS spirv-reflect) doesn't.

I'm not sure why though.

@DDoS
Copy link
Contributor

DDoS commented Apr 24, 2025

@DDoS I am using the latest git version of https://github.com/KhronosGroup/SPIRV-Reflect It does have SPIRV_REFLECT_USE_SYSTEM_SPIRV_H as it wouldn't have worked before if that wasn't the case.

It seems like on my end list(APPEND VULKAN_LIBS $<BUILD_LOCAL_INTERFACE:spirv-reflect>) will ignore that we set SPIRV_REFLECT_USE_SYSTEM_SPIRV_H with target_compile_definitions(spirv-reflect INTERFACE SPIRV_REFLECT_USE_SYSTEM_SPIRV_H) while list(APPEND VULKAN_LIBS spirv-reflect) doesn't.

I'm not sure why though.

This almost feels like a CMake bug. I'm using 3.31.6, we're only one patch version off. Could you downgrade and test again?

@DarkDefender
Copy link

DarkDefender commented Apr 25, 2025

I tried with the cmake 3.31.6 version, no change.
I also tried to see if I can reproduce the issue with the build_usd.py and I can.
This is the command I use to reproduce the issue:

python build_scripts/build_usd.py --build-monolithic --no-python --vulkan --no-openvdb --no-embree --no-openimageio --no-opencolorio --no-alembic --no-hdf5 --no-draco --no-materialx --no-mayapy-tests --no-animx-tests --no-tutorials --no-docs --no-python-docs --no-examples --no-tests /tmp/usd_build/

@DDoS Can you see if it also triggers on your machine with the same flags to build_usd.py?
If it makes any difference, the build_usd.py uses make as the build system here.

]
RunCMake(context, force, extraArgs)
CopyFiles(context, 'spirv_reflect.h', 'include')
CopyDirectory(context, 'include/spirv', 'include/spirv')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should remove this as the spirv header file is not used and is not supposed to be used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This header is the one included by spirv_reflect.h. It's needed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you are right. Never mind. I somehow got the idea that the build script also installed the spirv headers. But it doesn't. Sorry for the noise.

@DarkDefender
Copy link

@DDoS Seems like the --build-monolithic is what show cases the issue.
If I build a non monolithic library, it works.

So I'm guessing that there are some flags that doesn't get passed on properly in the monolithic build or something.

@DDoS
Copy link
Contributor

DDoS commented Apr 25, 2025

@DarkDefender Thanks for digging deeper into this! I never tried a monolithic build before, I'll give it a try, and fingers crossed that will reproduce the issue. I think I already have an idea of what the problem may be.

Update: I can confirm this reproduces the issue!

@tallytalwar
Copy link
Contributor

/AzurePipelines run

1 similar comment
@tallytalwar
Copy link
Contributor

/AzurePipelines run

@DDoS DDoS force-pushed the adsk/feature/vk-install branch from 887d0aa to 2a82301 Compare April 25, 2025 20:55
@DDoS
Copy link
Contributor

DDoS commented Apr 25, 2025

@DarkDefender this should fix the problem. Let me know if it works now, thanks.

@DarkDefender
Copy link

DarkDefender commented Apr 28, 2025

Seems to build fine for me now again! :)

I just have one last bit of feedback. (See my review comment)

if (SpirvReflect_FOUND AND NOT EXISTS "${spirv-reflect_INCLUDE_DIR}/include/spirv/unified1/spirv.h")
# Most probably not from the Vulkan SDK, so use a "system path."
# If installed from build_usd.py this will be found in the USD install path.
if (SpirvReflect_IS_SOURCE_DEP)
Copy link

@DarkDefender DarkDefender Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is defined anymore so this will always be false?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed! Good catch, I think this somehow got lost in the cherry-pick.

@DDoS DDoS force-pushed the adsk/feature/vk-install branch from 2a82301 to c1663f8 Compare April 28, 2025 15:01
@@ -12,7 +12,7 @@
#include "pxr/imaging/hgiVulkan/sampler.h"
#include "pxr/imaging/hgiVulkan/diagnostic.h"

#include <float.h>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one last thing I noticed.
On older gcc versions (GCC 11), this include or #include <cfloat> is needed because it can't find the definition of FLT_MAX otherwise. Don't know why this isn't needed in newer gcc versions, but I don't think we do any harm by explicitly including <cfloat>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-added

@DDoS DDoS force-pushed the adsk/feature/vk-install branch from c1663f8 to b8db3a3 Compare April 28, 2025 17:09
@jesschimein
Copy link
Collaborator

/AzurePipelines run

@DarkDefender
Copy link

All seems to be working fine on my side now! Thank you so much for all the back and forth! :)

@jesschimein
Copy link
Collaborator

/AzurePipelines run

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

Successfully merging this pull request may close these issues.

5 participants