Skip to content

tools/sim: get MetaDrive simulator working on macOS#38261

Open
hamiikalhor wants to merge 2 commits into
commaai:masterfrom
hamiikalhor:metadrive-macos
Open

tools/sim: get MetaDrive simulator working on macOS#38261
hamiikalhor wants to merge 2 commits into
commaai:masterfrom
hamiikalhor:metadrive-macos

Conversation

@hamiikalhor

Copy link
Copy Markdown

Fixes #33207. Re-enables the MetaDrive simulator on macOS with feature parity to Linux; tools/sim/tests/test_metadrive_bridge.py now passes on macOS (Apple Silicon).

Changes

  • pyproject.toml / uv.lock: re-enable the metadrive-simulator dependency. Still excluded on the comma device (aarch64 Linux) via the existing marker.
  • system/manager/process.py: only pre-import process modules under the fork start method. macOS defaults to spawn, where every child re-imports anyway and pre-importing the UI (which initializes Cocoa) in the manager process breaks startup.
  • tools/sim/lib/camerad.py: stamp the camera end-of-frame timestamp with time.monotonic_ns() so it shares the simulated sensors' logMonoTime clock domain. Otherwise locationd rejects all camera odometry on its timing check and openpilot never engages.
  • .github/workflows/tests.yaml: re-enable the simulator_driving job (disabled while the sim wasn't ready).

Dependency

Road rendering on macOS also needs the terrain shader fix in commaai/metadrive (texture2Dtexture, rejected by Apple's GLSL at #version 330): commaai/metadrive#15. This PR points at @minimal, so that needs to land first.

Verification

On macOS (Apple Silicon):

CI=1 pytest -n0 -s openpilot/tools/sim/tests/test_metadrive_bridge.py
# 1 passed, 1 skipped in ~63s

openpilot engages and drives the loop with no failure states; offscreen rendering via CocoaGraphicsPipe (no xvfb needed on macOS). The skipped item is the abstract TestSimBridgeBase, same as on Linux.

Notes

modeld stays on the default CPU backend on macOS (unchanged). Metal currently fails the model build's determinism check and CPU:LLVM needs libLLVM that isn't part of the macOS setup, so the GPU/LLVM path is left as a follow-up.

@github-actions

Copy link
Copy Markdown
Contributor

Process replay diff report

Replays driving segments through this PR and compares the behavior to master.
Please review any changes carefully to ensure they are expected.

✅ 0 changed, 66 passed, 0 errors

Re-enables the MetaDrive bridge on macOS (issue commaai#33207):

- pyproject: re-enable the metadrive-simulator dependency (still excluded
  on the comma device, aarch64 Linux, via the existing marker)
- manager: only pre-import process modules under the "fork" start method.
  With "spawn" (the default on macOS) every child re-imports anyway, and
  pre-importing the UI (which initializes Cocoa) in the manager process
  breaks startup on macOS.
- tools/sim/camerad: stamp the camera EOF with time.monotonic_ns() so it
  shares the simulated sensors' logMonoTime clock domain. Otherwise
  locationd rejects all camera odometry and openpilot never engages.

Road rendering also requires the macOS terrain shader fix in
commaai/metadrive (texture2D -> texture).

Verified on macOS (Apple Silicon): tools/sim/tests/test_metadrive_bridge.py
passes (offscreen rendering via CocoaGraphicsPipe, openpilot engages and
drives the loop with no failure states).
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.

Get MetaDrive simulator working on macOS

1 participant