Skip to content

Conversation

@alphataubio
Copy link

ChimeraX-GraphicsMetal

Metal-accelerated multi-GPU graphics for UCSF ChimeraX.

Overview

This bundle provides a high-performance Metal-based graphics renderer for ChimeraX, optimized for macOS systems with Apple Silicon or Intel processors. It leverages Apple's Metal graphics API to deliver improved performance and reduced CPU overhead compared to the default OpenGL renderer.

Key features:

  • Multi-GPU Acceleration: Automatically distributes rendering workloads across multiple GPUs when available
  • Optimized Memory Usage: Uses Metal's advanced memory management techniques for better performance
  • Argument Buffers: Takes advantage of Metal's argument buffers for efficient resource binding
  • Ray Tracing Support: Optional ray-traced shadows and ambient occlusion on supported hardware
  • Mesh Shaders: Utilizes Metal mesh shaders for more efficient geometry processing

Requirements

  • macOS 10.14 (Mojave) or later
  • ChimeraX 1.5 or later
  • A Metal-compatible GPU

Installation

From within ChimeraX:

  1. Open ChimeraX
  2. Run the following command:
    toolshed install ChimeraX-GraphicsMetal
    

Alternatively, you can download the wheel file from the releases page and install it using:

chimerax --nogui --exit --cmd "toolshed install /path/to/ChimeraX-GraphicsMetal-0.1-py3-none-any.whl"

Usage

Enabling Metal Rendering

Metal rendering can be enabled with:

graphics metal

To switch back to OpenGL:

graphics opengl

Multi-GPU Acceleration

If your system has multiple GPUs, you can enable multi-GPU acceleration:

graphics multigpu true

You can also choose a specific strategy for multi-GPU rendering:

set metal multiGPUStrategy split-frame

Available strategies:

  • split-frame - Each GPU renders a different portion of the screen
  • task-based - Different rendering tasks are distributed across GPUs
  • alternating - Frames are alternated between GPUs
  • compute-offload - Main GPU handles rendering, other GPUs handle compute tasks

Preferences

The Metal graphics settings can be configured through the preferences menu:

  1. Open ChimeraX
  2. Go to ToolsGeneralMetal Graphics

Or you can use the command interface:

set metal useMetal true
set metal autoDetect true
set metal multiGPU true
set metal rayTracing false

Building from Source

Prerequisites

  • macOS 10.14+
  • Xcode 12.0+
  • Python 3.9+
  • Cython 0.29.24+
  • NumPy

Build Steps

  1. Clone the repository:

    git clone https://github.com/alphataubio/ChimeraX-GraphicsMetal.git
    cd ChimeraX-GraphicsMetal
    
  2. Build the bundle:

    make build
    
  3. Install in development mode:

    make develop
    

Architecture

The bundle implements a Metal-based renderer that integrates with ChimeraX's graphics system:

  • metal_graphics.py - Python interface to the Metal renderer
  • metal_context.cpp - Core Metal device and context management
  • metal_renderer.cpp - Main rendering pipeline implementation
  • metal_scene.cpp - Scene management for the Metal renderer
  • metal_argbuffer_manager.cpp - Argument buffer management for efficient resource binding
  • metal_heap_manager.cpp - Memory management with Metal heaps
  • metal_event_manager.cpp - Synchronization for multi-GPU rendering
  • metal_multi_gpu.cpp - Multi-GPU coordination and management

@zjp
Copy link
Member

zjp commented May 13, 2025

I am very excited to look this over. Amazing.

@alphataubio
Copy link
Author

I am very excited to look this over. Amazing.

It's just a first draft. Just for fun I gave Claude ai the Apple metal manual and the chimerax graphics bundle and asked it to generate a graphics_metal bundle. Then I committed the files in GitHub.

There's a long way to go but it's the only long term path that makes sense for chimerax as a high performance graphics application. New Macs have 10-80 gpus these days. Even my older macmini m1 toaster has 8. Single gpu OpenGL has additional overhead on top of metal and you're leaving 90-98.75% of the gpu flops on the table.

I haven't even tried to compile it yet. I won't have too much time to work on it. I would appreciate if you can pitch in since you're intimately familiar with chimerax graphics internals. I'm certainly not.

@zjp zjp self-assigned this May 13, 2025
@zjp
Copy link
Member

zjp commented May 13, 2025

Happy to pitch in, this aligns pretty well with what I said I would work on in a grant application we just submitted. I was actually somewhat panicking that you had obviated that part of it. LLMs are getting shockingly good at code. I've found o3 to be pretty good at Qt, and even this kind of low level code if they're prompted the right way. I've been looking at swapping out our marching cubes surface generation for flying edges and changing the tesselation code for surface capping to something faster and it's really helpful to get up to speed very quickly if it doesn't just one shot a solution. It would be amazing if this somehow enabled us to get VR on the Mac again.

@tomgoddard
Copy link
Collaborator

Macs don't have 10-80 gpus, they have tens of cores in a single GPU and all of them are used when rendering OpenGL. Also OpenGL is implemented on Metal on Mac ARM machines. This pull request seems to be based on misunderstandings of how graphics works.

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.

3 participants