[macOS] Fix Metal RHI 3D viewer crashes and enable qtAliceVision plugins#3030
[macOS] Fix Metal RHI 3D viewer crashes and enable qtAliceVision plugins#3030NeverGET wants to merge 6 commits into
Conversation
|
This is AWESOME! I ran into all these issues and did some very dirty hacking to get a bare minimum of it working 😅. |
|
You're welcome, BTW I bundled the app and using daily 😄. |
| ambient: root.ambient | ||
| shininess: root.shininess | ||
| specular: root.specular | ||
| ambient: "#111" | ||
| shininess: 1.0 | ||
| specular: "#000" |
There was a problem hiding this comment.
What's the reason to change that?
There was a problem hiding this comment.
Actually the mesh preview is looking a bit phased off, like whiteish. I tried to make it look like full saturated colour but it didn't worked either and I was feeling very happy about the app is working, I directly go into PR.
Tldr; it just a mess I forgot to revert
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #3030 +/- ##
===========================================
- Coverage 83.35% 83.21% -0.14%
===========================================
Files 73 73
Lines 9882 9901 +19
===========================================
+ Hits 8237 8239 +2
- Misses 1645 1662 +17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| @@ -196,12 +196,15 @@ def matchDescription(self, value, strict=True): | |||
| class GroupAttribute(Attribute): | |||
| """ A macro Attribute composed of several Attributes """ | |||
| @deprecated.depreciateParam("group", "Param 'group' on {name} should not be used anymore. Please use 'commandLineGroup' instead") | |||
There was a problem hiding this comment.
| @deprecated.depreciateParam("group", "Param 'group' on {name} should not be used anymore. Please use 'commandLineGroup' instead") | |
| @deprecated.depreciateParam("group", "Param argument 'group' on {name} should not be used anymore. Please use 'commandLineGroup' instead") | |
| @deprecated.depreciateParam("groupDesc", "GroupAttribute argument 'groupDesc' on {name} should not be used anymore. Please use 'items' instead") |
|
@NeverGET Could you rebase this PR onto the develop branch (instead of a merge)? |
Will do. I think I have a valid AdaptiveCpp build now and will report any issues asap. I'll be on a train ride tonight, so maybe I can take it for a spin then. |
|
I just went ahead and did the testing: (+): It does not crash anymore, models and images are loaded correctly and (afaict) the 3D Viewer now works correctly on macOS (🚀)1 (-): I don't know what to think about the
Everything else LGTM. But I would really prefer to not use/introduce more environment variables but instead try to reduce them in general. |
4097642 to
a6d4304
Compare
|
Hi @fabiencastan @philippremy — apologies for the long silence on this one. The past couple of months turned out to be unexpectedly busy and I only now got the time to come back and properly address the review. Thanks a lot for the detailed feedback and for taking the time to test it on macOS. I've pushed an updated branch that addresses every point:
What remains is the macOS RHI/shader work — Metal normal fixes, OpenGL fallback techniques, the cgroup fix, and the Qt plugin-path existence guards. I re-tested locally on macOS (Apple Silicon, Metal RHI): the full pipeline recomputes end to end and the 3D viewer works. Let me know if anything else needs adjusting. |
|
Hello, Thanks for your contribution.
Thanks ! |
Metal RHI strictly validates that vertex shader inputs match the vertex descriptor provided by the geometry. The SphericalHarmonics shaders declared a vertexNormal input, but custom Qt3D geometries (Grid3D, BoundingBox, Locator3D) and some loaded meshes don't provide normal attributes, causing Metal pipeline creation to fail with a crash. Instead of requiring normals as a vertex attribute, compute flat face normals in the fragment shader using dFdx/dFdy screen-space derivatives of the world position. This produces correct lighting for flat-shaded geometry and works regardless of whether the mesh provides normals. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Built-in Qt3D materials (PhongMaterial, DiffuseSpecularMaterial) expect a vertexNormal attribute in the vertex descriptor. On Metal RHI, if a geometry lacks this attribute, the render pipeline state creation fails with a crash because Metal strictly validates that all shader inputs are satisfied by the vertex descriptor. Add default upward-facing (0, 1, 0) normal attributes to: - Grid3D.qml (dynamic count matching grid vertices) - BoundingBox.qml (24 vertices) - Locator3D.qml (6 vertices) These normals ensure Metal pipeline compatibility while maintaining correct visual appearance for these helper geometries. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Meshes loaded via SceneLoader (OBJ, PLY, etc.) may lack normal attributes. When these meshes are rendered with built-in Qt3D materials that require vertexNormal, Metal RHI crashes due to missing vertex descriptor entries. Add Scene3DHelper.ensureNormals(entity) that traverses all QGeometry children of a loaded entity and adds default (0, 1, 0) normal attributes to any geometry missing them. Call this method in MediaLoader's sceneLoaderPostProcess before material setup. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add QML import paths for PySide6's bundled QML modules and the AliceVision bundle's PlugIns directory. This enables the QML engine to discover and load qtAliceVision, SfmDataEntity, and DepthMapEntity QML plugins that provide camera visualization, SfM data overlay, and depth map rendering in the 3D viewer. The PySide6 QML path ensures Qt3D and QtQuick.Scene3D modules are found, while the AV_BUNDLE/PlugIns path provides the AliceVision- specific visualization plugins. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Guard QT_PLUGIN_PATH and QML2_IMPORT_PATH setup behind directory existence checks. On macOS with PySide6, these directories may not exist in the standard locations and setting invalid paths causes plugin loading failures. - Add macOS-specific DYLD_FALLBACK_LIBRARY_PATH handling (analogous to LD_LIBRARY_PATH on Linux) so AliceVision framework libraries can be found at runtime. - Use Metal as the default RHI backend on macOS (QSG_RHI_BACKEND=metal) via setdefault so it can be overridden, while keeping OpenGL as the default on other platforms. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Some AliceVision node descriptors from the MTL-AliceVision bundle use the older 'groupDesc' parameter name instead of 'items' in GroupAttribute constructors. Add backward compatibility by accepting 'groupDesc' as a deprecated alias and defaulting positional params to allow keyword-only usage patterns. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
a6d4304 to
d62e860
Compare
|
Hi @servantftransperfect — thanks, both points are fair. cgroup: you're right, I had the semantics backwards. Looking at the For context on why I touched that file in the first place: while debugging the macOS crashes I also noticed Meshroom wasn't using all CPU threads on my machine, and I tried a few things to nudge it — that change was one of those experiments and ended up being a leftover. With it dropped, AliceVision's own detection takes over, which is what should happen. OpenGL fallback shaders: no real-world use case. The actual macOS Metal fix is in the modified Branch is force-pushed; the PR now has 6 focused commits. |
|
I am not sure to know why, but without your PR, the bounding box and the widgets were correctly lighted using the directional light (in the 3D viewer). Now using your PR, as you explicitely added wrong normals, the lighting is weird. I am not sure we wanted (in the first place) those widgets to be affected by the lighting. Would you have time finding a solution to make them unlit ? I can see in the doc there is a PerVertexColorMaterial which requires to replace normals with color. |
Summary
vertexNormalattributes in custom Qt3D geometriesdFdx/dFdyderivatives instead of requiring normals as vertex attributes in SphericalHarmonics shadersensureNormals()to dynamically patch loaded meshes (OBJ/PLY) that lack normalssetupEnvironment()(Metal RHI backend default, Qt plugin path existence guards)groupDescbackward compatibility for AliceVision node descriptorsAcknowledgments
Huge thanks to @music-dsp-collection for the incredible work on MTL-AliceVision (alicevision/AliceVision#2019) — bringing Metal GPU support and the complete macOS build pipeline to AliceVision is a massive achievement. And to the entire @alicevision team for building such an amazing open-source photogrammetry ecosystem. This PR is a small contribution building on top of their foundational work to help get the Meshroom 3D viewer running smoothly on macOS.
Context
While testing Meshroom on macOS 26.3 (Apple Silicon M4 Max, Mac15,6) with the MTL-AliceVision bundle from PR alicevision/AliceVision#2019, we found that the 3D viewer crashed due to Metal's strict vertex descriptor validation when geometries lacked normal attributes that built-in Qt3D materials expect.
Root cause: Metal RHI validates that all vertex shader inputs (
layout(location = N) in ...) are satisfied by the geometry's vertex descriptor. When a shader declaresvertexNormalbut the geometry only providesvertexPosition, Metal's pipeline state creation fails, crashing the application.Fixes applied:
vertexNormalinput entirely; compute flat normals fromdFdx/dFdyderivatives of world position in the fragment shader(0, 1, 0)normal attributesScene3DHelper.ensureNormals()dynamically adds normals to geometries missing themTest Plan
QT3D_RENDERERoverride needed)Tested on
🤖 Generated with Claude Code