Skip to content

Metal: add native Apple Silicon GPU conformance harness - #460

Closed
pedrofort wants to merge 1 commit into
Marvisak:mainfrom
pedrofort:metal-conformance
Closed

pedrofort wants to merge 1 commit into
Marvisak:mainfrom
pedrofort:metal-conformance

Conversation

@pedrofort

Copy link
Copy Markdown

Overview

This PR introduces an experimental native Metal GPU conformance harness for Apple Silicon.

It demonstrates that synthetic Xbox GFX10 shaders translated by VIctory can be converted from DXIL to Metal libraries and executed on Apple GPU hardware, with their outputs verified against independent CPU references.

The complete test path is:

GFX10 → VIctory → DXIL → Metal Shader Converter → Metal GPU execution → readback verification

No Wine, Rosetta, Windows VM or game assets are required.

Hardware validation

  • Apple M5 with 16 GB unified memory

  • macOS 27.2.1

  • Native ARM64 executable

  • Rust 1.98.1

  • Xcode and macOS SDK 27.0

  • Metal Shader Converter 4.0.3

  • Metal API and GPU validation enabled

Results

Verification | Result -- | -- Automated checks with optional A/B comparison | 58/58 passed Translated shader pixel comparisons | 16,384/16,384 RGBA channel comparisons | 65,536 Maximum observed channel error in positive tests | 0 Compute buffer values | 64/64 Buffer guard values | 16/16 Failed checks | 0 Blocked checks | 0 Asset policy | 155 files passed Xtask unit tests | 5/5 passed Xtask Clippy | Passed

GPU coverage

  • Constant pixel colors

  • Position-dependent floating-point arithmetic

  • Integer and floating-point conversions

  • Bitwise operations

  • Conditional selection

  • Dynamic byte permutation covering all 256 selector values in each output byte, using two operand pairs

  • Translated vertex shaders

  • Combined translated vertex and pixel pipelines

  • Native versus translated vertex pipeline equivalence

  • Compute dispatch with writable raw buffers

  • GPU memory readback and trailing guard verification

A negative control deliberately compares a red output against a checkerboard reference. The harness correctly detects the mismatch and rejects the result.

Optional differential testing

The harness accepts a second VIctory executable for A/B testing.

During development, the dynamic v_perm_b32 changes from #423 were tested against the original lowering. Both operand sets produced byte-identical GPU outputs, while the candidate no longer declared the INT64 shader feature.

Reproduction

Install Apple's Metal Shader Converter and Xcode, then run:

python3 tests/metal/run.py --victory /path/to/victory

All generated artifacts remain in a temporary directory outside the repository.

The runner produces detailed logs, GPU readbacks and a JSON summary. Failed or blocked checks return a nonzero exit status.

Asset policy

Only the three specifically named Python and Swift test sources are newly permitted. All existing file-size, binary-content, magic-signature and encoded-data checks remain enforced.

No generated binaries, proprietary assets or Apple converter components are committed.

Relationship to other PRs

The harness is independent of the implementation changes in #235, #423 and #438.

A working macOS VIctory executable is required. Native build portability was validated using #235 by @SkippySteve. The optional #423 comparison is not required for normal use.

Limitations

This is a GPU testing infrastructure, not a complete Metal backend or Xbox title runtime.

It does not establish game compatibility, general resource binding support, mesh shader compatibility or performance improvements.

Independent testing on other Apple Silicon generations is welcome.

AI-assisted implementation, reviewed and validated on physical Apple Silicon hardware.

@upipibi upipibi mentioned this pull request Nov 24, 2026
@jeremygold02

Copy link
Copy Markdown
Contributor

Windows-side verification at head 8ce597b2beea8aa5073391010f012755c7a7fc76:

  • cargo test --locked -p xtask metal_test_sources_are_still_checked -- --test-threads=1: 1 passed, 0 failed, 4 filtered. This checks that only the three named Metal harness sources are allowlisted, while other Python/Swift files, an executable-style MZ signature, and an oversized source remain rejected.
  • cargo run --locked -p xtask -- policy: asset policy passed for 155 files.
  • python -m py_compile tests/metal/generate.py tests/metal/run.py: both Python files compiled successfully.

I reviewed the Metal runner and Swift probe. The runner requires native Apple Silicon macOS and exits before creating its temporary lab or invoking Swift, the converter, or GPU commands on other platforms. Therefore the Metal conversion, shader execution, pixel readback and compute-buffer checks were not reproduced here; those hardware results remain unverified by this Windows run.

This verification was AI-assisted.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
@Marvisak

Copy link
Copy Markdown
Owner

Automated triage for the maintainers. Closing because it is outside the project's scope (VIctory targets Windows hosts; ports, launchers and tooling for other platforms are not being taken).

Out of scope: a macOS/Apple Silicon Metal harness (Python and Swift, needs Apple's Metal Shader Converter and the conflicting Linux-build PR #235), and it adds three path exceptions for .py/.swift files to the asset-policy allowlist in xtask/src/policy.rs.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

@Marvisak Marvisak closed this Nov 25, 2026
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