Simo Virokannas

Writings and ramblings

Compiling Pixar’s USD natively on Apple M1

This is in no way meant to be a “standard, do it this way” kind of a solution, but just one way of making it happen. I don’t like how homebrew and alike plug themselves into default locations and potentially taint your environment, so I default to Python-centric virtual environment handlers like miniconda. With the announcement that usdview now supports Metal, I wanted to have a go at it: so this is how you can compile Pixar’s USD (and usdview) without using Rosetta and run natively on M1 chips.

Prerequisites

Xcode – must be installed and run at least one time to install the platform support. You may be able to just use the command line tools (run xcode-select –install ) but I recommend just going ahead and spending 4 hours downloading and installing Xcode.

Miniconda3 Apple M1 – installer can be downloaded at https://docs.conda.io/en/latest/miniconda.html

I like using /opt for these environments, but it’s up to you where you want yours. Install the M1 version of miniconda, activate it (run path_to_conda/bin/activate), then install conda-forge:

conda config --add channels conda-forge
conda config --set channel_priority strict

Install cmake, numpy, pyside6 and pyopengl:

conda install cmake numpy
pip install pyside6 PyOpenGL

Download and prepare USD for compiling

Get the ‘dev’ branch if 22.05 isn’t out yet, otherwise ‘release’. This is because 22.05 is the first one to include Metal support for Hydra.

USD doesn’t support PySide6 (and PySide2 won’t work with M1) so you’ll need to trick it into compiling:

# go to your conda bin folder
cd /opt/conda/bin
ln -s pyside6-uic pyside2-uic
cd /opt/conda/lib/python3.*/site-packages
ln -s PySide6 PySide2

Patch the build_scripts/build_usd.py file around line 427 and add the one line with DPXR_PY_UNDEFINED_DYNAMIC_LOOKUP:

    with CurrentWorkingDirectory(buildDir):
        Run('cmake '
            '-DCMAKE_INSTALL_PREFIX="{instDir}" '
            '-DCMAKE_PREFIX_PATH="{depsInstDir}" '
            '-DCMAKE_BUILD_TYPE={config} '
            '-DPXR_PY_UNDEFINED_DYNAMIC_LOOKUP=ON '
            '{osx_rpath} '
            '{generator} '

Patching usdview

As one would guess, the PySide2 symlink is just a band-aid – stuff won’t just run like that, especially when OpenGL support is one of the biggest changes in PySide6.

You’ll need to patch two files: qt.py and stageView.py. These might get outdated as soon as an official release comes out, so I’ll briefly explain the changes as well.

Apply the two patches inside the folder you have USD checked out in like this (once for each patch):

patch -p1 <path_to_patch.patch

Run the compile script (again, I just like to put the USD build under /opt/USD but choose wherever you like):

python build_scripts/build_usd.py --build-args TBB,"arch=arm64" --python /opt/USD

Test it

Things may have changed, maybe this method no longer works, for any of a million reasons, but even if you don’t get any errors it’s good to test the newly installed USD with a sample set in a fresh terminal. Pixar’s Kitchen set is a great example: https://graphics.pixar.com/usd/release/dl_kitchen_set.html

# activate your conda environment
source /opt/conda/bin/activate

# include USD in your env
export PYTHONPATH=/opt/USD/lib/python
export PATH=/opt/USD/bin:$PATH

# test!
usdview path_to_kitchen_set.usd
Ok maybe it looks a bit different, just couldn’t resist

Clean up PySide2 links

Now that everything’s compiled, you can remove the symlinks for PySide2:

# go to your conda bin folder
cd /opt/conda/bin
rm -f pyside2-uic
cd /opt/conda/lib/python3.*/site-packages
rm -f PySide2

Comments

4 responses to “Compiling Pixar’s USD natively on Apple M1”

  1. Excellent!
    Super-useful.
    I didn’t need to use Conda.
    Just install CMake.app from cmake.org and export PATH=$PATH:/Applications/CMake.app/Contents/bin
    I wrapped this all in a shell script to perform the tasks. (Presuming Xcode and CMake are installed.)

    1. Thank you, and I’m glad it works with the vanilla environment too!

      The reason I’m using conda to wrap the environment is to prevent the two pip packages, PySide6 and PyOpenGL from being available in the system environment, but I’m sure in most cases that’s not even a concern.

  2. Awesome!

    I also have a M1 Mac, however Renderman still doesn’t run on M1 natively, so in theory, launching the terminal via Rosetta (and skipping the PySide6 step of course) should compile it as Intel/x86, is that correct?
    I know it is not the perfect idea, but it’s just so I can have Storm and the Renderman plugin as well in it. Renderman, Houdini and Maya are still in development for M1.

    Will wait for the X-Code download yet (this is why I still haven’t tried), but thanks in advance!
    Thanks!

    1. You’ll need to have a separate conda environment (a x86_64 one) set up, yes, and the most straight-forward way to do that is to do a rosetta terminal session, but you also must use the intel miniconda-installer. But what comes to the PySide6 step: as it took me this long to reply, the whole USD environment now supports pyside6 – no patches needed, just go with it.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.