一个基于Rust的工具,将Apple Metal的AIR/LLVM IR转换为Vulkan SPIR-V,无需调用LLVM的llc。

Stars

163

7 天增长

+50

Fork 数

7

开放 Issue

2

开源协议

LGPL-3.0

最近更新

2026-07-26

AI 仓库情报摘要
FR-AI / ANALYSIS

为什么值得关注

它提供了从Metal到Vulkan的跨平台着色器翻译的原生Rust方案,填补了开发者无需依赖外部LLVM工具链即可在Vulkan后端重用Metal着色器的需求。

适合谁使用

  • 同时面向Metal和Vulkan的游戏开发者
  • 需要跨平台着色器兼容性的图形引擎开发者
  • GPU中间表示翻译的研究人员
  • Apple平台上跨平台图形应用的开发者

典型使用场景

  • 将Metal计算或图形着色器转换为SPIR-V以在Vulkan上执行
  • 集成到跨平台渲染的构建流水线中
  • 实验着色器翻译和反射元数据生成
  • 将基于Metal的应用移植到Vulkan

项目优势

  • 原生Rust实现减少了对LLVM工具链的依赖
  • 支持多种着色器阶段(顶点、片段、计算、passthrough)
  • 提供CLI和库API
  • 可选的serde支持用于反射元数据

使用前须知

  • 项目处于alpha阶段(0.x系列),API和输出不稳定
  • 仅支持经过净化的LLVM bitcode,而非任意Metal源码
  • 覆盖依赖于合成测试,并非真实世界着色器验证

README 快速开始

metal2vulkan

Alpha. This project is early and under active development. The public API, CLI flags, reflection layout details, and SPIR-V output may change without a stable semver guarantee while the crate is in the 0.x series. Treat it as research-quality: useful for experimentation and integration pilots, not a frozen interface.

Translate Metal AIR (LLVM bitcode / sanitized .ll) to Vulkan SPIR-V using a native Rust emitter. Production translation does not invoke LLVM llc.

Features

  • Native AIR/LLVM-IR → OpCapability Shader / Logical GLSL450 SPIR-V
  • Stage interface lowering for vertex, fragment, compute (kernel), and passthrough
  • Library API plus a CLI compatible with simple in → out.spv harnesses
  • Optional serde feature for reflection metadata JSON
  • Optional workspace package for local Metal oracle / Vulkan executor experiments

Install

# CLI
cargo install metal2vulkan

# Library (Cargo.toml)
metal2vulkan = "0.1"

CLI

metal2vulkan   --stage vertex|fragment|passthrough|kernel
# optional interface metadata JSON (requires --features serde)
metal2vulkan in.ll out.spv --stage kernel --emit-meta out.json
  • Success: prints a line containing PASS, writes SPIR-V, exits 0
  • Failure: prints FALLBACK, exits non-zero

On failure the CLI writes a repro bundle under $TMPDIR/metal2vulkan-repros (override with METAL2VULKAN_REPRO_DIR).

Example

cargo run --example translate_native -- path/to/shader.ll kernel out.spv

Library

use metal2vulkan::passes::Stage;
use std::path::Path;

fn translate_ll(sanitized_ll: &str) -> Result, String> {
    let tmp = std::env::temp_dir().join("m2v-scratch");
    std::fs::create_dir_all(&tmp).ok();
    metal2vulkan::translate_sanitized_native(sanitized_ll, Stage::Kernel, Path::new(&tmp))
}

See crate docs (cargo doc --open), docs/ARCHITECTURE.md for the pipeline, and docs/REFLECTION.md for how consumers read binding metadata after a convert. Repository layout and the developer loop are in CONTRIBUTING.md. How to stay confident while refactoring (harvest, hash ledgers, A/B) is in docs/VALIDATION.md.

Coverage policy

Grammar and lowering behavior is locked with synthetic Rust tests. This repository does not ship third-p

项目描述

Translate Metal AIR / LLVM IR to Vulkan SPIR-V with a native Rust emitter

相关仓库与替代方案

根据分类、Topic 和编程语言匹配的相似项目。

l0ng-ai
精选
l0ng-ai GitHub avatar

tty7

tty7 is a fast, GPU-accelerated terminal workbench with persistent sessions, built-in input tools, SSH support, and coding agent awareness.

开发者工具CLI 与终端
359
steelbrain
精选
steelbrain GitHub avatar

reims-vgpu

reims-vgpu is an experimental virtual GPU for macOS guests that uses QEMU to decode the guest's GPU command stream and execute it through Metal or Vulkan, leveraging the built-in AppleParavirtGPU driver without requiring custom kexts.

桌面应用
143
m-novotny
精选
m-novotny GitHub avatar

memguard-rs

A Rust library that provides secure memory handling primitives including zeroization on drop, memory locking, constant-time comparison, and compile-time guarded regions, with zero dependencies and no_std support.

嵌入式与物联网安全
131