OpenUSD icon indicating copy to clipboard operation
OpenUSD copied to clipboard

usdview: Failed to link GL program for Metal/GL interop on Mac M2

Open raph080 opened this issue 2 years ago • 12 comments

Description of Issue

Hi OpenUSD team !

I am trying to compile OpenUSD and usdview with my new MacBook Air M2.

The compilation seems to succeed. But when I try to open a use file with usdview, I get the following error:

> usdview /path/to/usd/share/usd/tutorials/convertingLayerFormats/Sphere.usd
State file not found, a new one will be created.
Fatal coding error: Failed to link GL program for Metal/GL interop:
ERROR: One or more attached shaders not successfully compiled
 [Python], in _OutputShaderLog(), /path/to/usd/pxr/imaging/hgiInterop/metal.mm:135
zsh: abort      usdview

Steps to Reproduce

  1. download latest OpenUSD and compile it
  2. run usdview with a test usd file

System Information (OS, Hardware)

  • MacBook Air M2 2022 with Ventura 13.4.1
  • (Xcode 14.3.1)

Package Versions

  • Python 3.9.13 from python.org
  • PySide6 6.3.1 (pip3 install PySide6==6.3.1)
  • PyOpenGL 3.1.5 (pip3 install PyOpenGL==3.1.5)
  • cmake 3.27.0
  • OpenUSD 23.08

Build Flags

The command used to build is the following python3 build_scripts/build_usd.py /custom/install/path

I tried with a lot of different configurations (conda, USD > 22.11, Python > 3.7, PySide6 > 6.3.1). But I am always facing that final error.

Thank you very much, Raphael

raph080 avatar Jul 21 '23 22:07 raph080

Filed as internal issue #USD-8520

jesschimein avatar Jul 24 '23 16:07 jesschimein

Hi @jesschimein,

Thank you for your help on this.

I am surprised since, while browsing, it seems people have succeeded to compile USD/usdview for apple silicon and Ventura. But maybe not the last version of Ventura. Or would be possible I am missing a "driver" or something ?

Raphael

raph080 avatar Jul 26 '23 06:07 raph080

I don't know what could be causing that error, but usdview is working for me on Ventura 13.4, 13.5 and Sonoma 14.0 without issue. I'm building USD 23.8 for Python 3.9 and 3.10, PyOpenGL 3.1.6, PySide 6.5.1 and CMake 3.25.1.

There's no drivers to speak of on macOS so I suspect that either something in the library versions used are problematic?

Unfortunately I don't know what that could be, but could you try using PySide 6.5 and PyOpenGL 3.1.6 instead to see if that might solve the issue? It's possible they're requesting a context thats different than expected.

dgovil avatar Jul 26 '23 06:07 dgovil

Hi @dgovil,

Thank you for your feedback, I will try again with your configuration. Are you working with apple M2 chip ?

raph080 avatar Jul 26 '23 06:07 raph080

I’ve tried it on an M1 Max MacBook Pro and an Intel iMac Pro. I haven’t heard any issues from coworkers on an M2 either. To the best of my knowledge, that compilation pathway is the same for both M series.

Sorry, wish I knew more at this time to help, but hopefully that can maybe help rule out system configuration.

dgovil avatar Jul 26 '23 07:07 dgovil

That is really interesting, thank you @dgovil.

I tried your config and I the error changed a little bit, but still the same one.

Value [True, True, True, False] did not pass custom validation for state property 'primViewColumnVisibility'.
    Using default value [True, True, True, True, False].
Warning: Unknown pick mode 'Prims', falling back to 'Select Prims'
Fatal coding error: Failed to link GL program for Metal/GL interop:
ERROR: One or more attached shaders not successfully compiled
 [Python], in _OutputShaderLog(), /Users/raphjou/Downloads/OpenUSD-23.08/pxr/imaging/hgiInterop/metal.mm:135
zsh: abort      usdview

This is weird because my Mac is new and running usdview is the first thing I tried on it. Are you maybe compiling USD with different build flags ?

Thank you very much, Raphael

raph080 avatar Jul 26 '23 13:07 raph080

We can’t seem to reproduce this issue. Maybe someone from Pixar has some ideas. I’ll think a bit more and see if there’s any troubleshooting steps that might help.

Just to clarify, you cloned the USD repo fresh and there’s no chance of previous versions being in the mix?

———

Steps we did:

On a fresh M2 MacBook Air running Ventura macOS 13.5, we installed the latest:

  • Xcode 14
  • CMake 3.27.1
  • python 3.10
  • PySide6
  • PyOpenGL

built with the following arguments:

python3 ./build_scripts/build_usd.py
--prefer-speed-over-safety
--python
--usd-imaging
--openimageio
--openvdb --alembic
--embree
--materialx
/opt/local/usd-metal_usdview

dgovil avatar Jul 26 '23 20:07 dgovil

I would investigate what version of PySide and PyOpenGL you have installed.

On Jul 26, 2023, at 1:46 PM, Dhruv Govil @.***> wrote:

We can’t seem to reproduce this issue

On a fresh M2 MacBook Air running Ventura macOS 13.5, we installed the latest:

Xcode 14 CMake 3.27.1 python 3.10 PySide6 PyOpenGL built with the following arguments:

python3 ./build_scripts/build_usd.py --prefer-speed-over-safety --python --usd-imaging --openimageio --openvdb --alembic --embree --materialx /opt/local/usd-metal_usdview

— Reply to this email directly, view it on GitHub https://github.com/PixarAnimationStudios/OpenUSD/issues/2547#issuecomment-1652470986, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM2AOS3MG7HHYSDOXSUXO3XSF64HANCNFSM6AAAAAA2TMT4JQ. You are receiving this because you are subscribed to this thread.

drwave avatar Jul 26 '23 20:07 drwave

Hi @drwave @dgovil,

Thank you for your help on this. Indeed It should come from the Python/PySide/PyOpenGL I am installing.

@dgovil here are the exact steps I am doing:

  • reformat my MacBook Air M2 Ventura 13.5 (factory reset)
  • Then I setup the Mac during boot up ("Francais", "Belgique", "Male", skip assistant migration, skip iCloud setup,...)
  • open AppStore, search for Xcode, enter iCloud credentials, install Xcode (v14.3.1)
  • open Xcode, Agree the agreement, click "install" with macOS 13.3 and IOS 16.4 checked, continue, close Xcode.
  • download python 3.10.11 from that link and install it
  • open terminal
    • > python3 --versionshould returns "Python 3.10.11"
    • run python3 -m pip install PySide6 PyOpenGL. This install
      • PySide6-6.5.2-cp37-abi3-macosx_10_9_universal2.whl
      • PyOpenGL-3.1.7-py3-none-any.whl
      • PySide6_Addons-6.5.2-cp37-abi3-macosx_10_9_universal2.whl
      • shiboken6-6.5.2-cp37-abi3-macosx_10_9_universal2.whl
      • PySide6_Essentials-6.5.2-cp37-abi3-macosx_10_9_universal2.whl
  • download cmake 3.27.1 from that link and uncompress it.
  • open a terminal
    • export PATH=/Users/raph/Downloads/cmake-3.27.1-macos-universal/CMake.app/Contents/bin:$PATH
    • cd Downloads
    • mkdir USD_install
    • git clone https://github.com/PixarAnimationStudios/OpenUSD.git
    • cd OpenUSD
    • git checkout release
    • python3 build_scripts/build_usd.py /Users/raph/Downloads/USD_install
    • export PATH=/Users/raph/Downloads/USD_install/bin:$PATH
    • export PYTHONPATH=/Users/raph/Downloads/USD_install/lib/python:$PYTHONPATH
    • usdview /Users/raph/Downloads/USD_install/share/usd/tutorials/convertingLayerFormats/Sphere.usda

Can you see something nasty in my steps ?

Maybe I should bring more precision concerning the error.

When running usdview /usd/file/path.usda, I can see usdview opening, and the UI is visible during 1 sec. Then it closes with the error

Fatal coding error: Failed to link GL program for Metal/GL interop:
ERROR: One or more attached shaders not successfully compiled
 [Python], in _OutputShaderLog(), /Users/raphjou/Downloads/OpenUSD/pxr/imaging/hgiInterop/metal.mm:135
zsh: abort      usdview 

I then have a popup with the 3 options: "Run again, Report... Ignore". The report gives me this: report.txt

Thank you very much guys for your help

raph080 avatar Jul 27 '23 06:07 raph080

Fixed after

  1. erasing the Hard drive
  2. installing Ventura from scratch

raph080 avatar Oct 17 '23 03:10 raph080

I had the same issue on a brand new MacBook Pro with Ventura and USD 23.11. I think it might be related to OpenGL in Pyside. I was able to fix it by using these dependencies installed via MacPorts:

  • Python 3.11
  • Pyside2 (instead of Pyside6)
  • Boost 1.78

In addition to that, usdview and Storm only did succesfully start after manually specifying the OpenGL version in stageview.py:

glFormat = QGLFormat() glFormat.setVersion(4, 3) ## Also try 4, 1 - might work as well glFormat.setProfile(QGLFormat.CoreProfile)

After applying these patches, storm works flawlessly and as expected. I think it might be an option for the codebase to set the profile and OpenGL version in stageview.py depending on architecture or processor.

matt-do-it avatar Feb 03 '24 08:02 matt-do-it

I've had this issue as well.

I believe I found where the error comes from. This function will give glLanguageVersion==1 instead of glLanguageVersion==1.20. Changing the dot(.) to a comma(,) in the input string fixes the issue. The issue persists even when using "1.20" as input instead of glGetString(..).

https://github.com/PixarAnimationStudios/OpenUSD/blob/2864f3d04f396432f22ec5d6928fc37d34bb4c90/pxr/imaging/hgiInterop/metal.mm#L82-L85

Can confirm it works in a clean program compiled with clang:

#include <cassert>
#include <iostream>

int main() {
    float ver;
    sscanf("1.20", "%f", &ver);
    assert(ver == 1.20f);
}

I can't find anything suggesting why this error would happen, but I've currently worked around it by doing:

int major, minor;
sscanf((char *)glGetString(GL_SHADING_LANGUAGE_VERSION), "%d.%d", &major, &minor);
GLuint version = 100 * major + minor;

which seems to work. However, I'm a bit concerned why this would happen in the first place.

System Information (OS, Hardware)

Software:

System Software Overview:

  System Version: macOS 14.5 (23F79)
  Kernel Version: Darwin 23.5.0
  Boot Volume: Macintosh HD
  Boot Mode: Normal
  Secure Virtual Memory: Enabled
  System Integrity Protection: Enabled

Hardware:

Hardware Overview:

  Model Identifier: MacBookPro18,3
  Chip: Apple M1 Pro
  Total Number of Cores: 10 (8 performance and 2 efficiency)
  Memory: 32 GB
  Activation Lock Status: Enabled

Package Versions

USD 24.05 Boost 1.85.0 PyOpenGL 3.1.7 Python 3.11 PySide6 6.7.1

skrotViktor avatar Jun 10 '24 12:06 skrotViktor