PixarAnimationStudios / OpenUSD

Universal Scene Description
http://www.openusd.org
Other
6.18k stars 1.23k forks source link

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

Open raph080 opened 1 year ago

raph080 commented 1 year ago

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)

Package Versions

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

jesschimein commented 1 year ago

Filed as internal issue #USD-8520

raph080 commented 1 year ago

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

dgovil commented 1 year ago

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.

raph080 commented 1 year ago

Hi @dgovil,

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

dgovil commented 1 year ago

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.

raph080 commented 1 year ago

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

dgovil commented 1 year ago

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:

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

drwave commented 1 year ago

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.

raph080 commented 1 year ago

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:

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 commented 1 year ago

Fixed after

  1. erasing the Hard drive
  2. installing Ventura from scratch
matt-do-it commented 10 months ago

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:

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.

skrotViktor commented 5 months ago

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