Skip to content

Conversation

@stuartcarnie
Copy link
Contributor

@stuartcarnie stuartcarnie commented Dec 31, 2025

Summary

This PR introduces a major refactoring of the Metal rendering driver with three key improvements:

1. Architecture Refactoring

The primary purpose of these changes were to separate common code that can be shared with Metal 3 and Metal 4. I have a complete Metal 4 renderer working with this branch to prove the refactoring is complete.

  • Split Metal objects: Renamed metal_objects.h/mmmetal3_objects.h/mm and extracted shared code into new metal_objects_shared.h/mm
  • New MTL3 namespace: Created dedicated namespace for Metal 3-specific functionality with MTL3::RenderingDeviceDriverMetal class
  • Command buffer hierarchy: MDCommandBuffer now inherits from MDCommandBufferBase with virtual methods for polymorphic dispatch to Metal 3 and Metal 4 in the future.
  • Cleaner separation: Shared types (MDRenderPass, MDAttachment, MDSubpass, MDFrameBuffer, shaders, pipelines) moved to shared header for reuse
  • Methods refactored: bind_uniforms_argument_buffers moved from MDUniformSet to MDCommandBuffer, which is Metal 3 specific

2. Dynamic Uniforms Fix

A hack was implemented to disable argument buffers (and use slot binding) when a shader used dynamic uniforms. This has been resolved with this update.

  • Ring buffer allocation: Added MDRingBuffer class for efficient transient GPU memory allocations (16-byte aligned, 64KB default segments)
  • GPU address-based binding: Dynamic uniform buffers now use MTLGPUAddress for argument buffer updates instead of per-frame buffer copies using slot binding, which was a hack.

3. Acyclic Render Graph Support

Important

ARG is opt-in by enabling the rendering/rendering_device/metal3/enable_pipeline_barriers project settings.

Explicit synchronization: Added pipeline_barrier() implementation that tracks pending stages across render/compute/blit encoders

Additional Changes

  • MetalFX updates: Fixes a TODO to handle resource lifetime of scaler objects generically to allow for Metal 4 support in the future.

@stuartcarnie stuartcarnie force-pushed the metal_refactor_and_fixes branch from 0a39afa to e40e37c Compare December 31, 2025 20:32
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change ensures the Defer is not dynamically dispatched


Error RenderingContextDriverMetal::initialize() {
if (OS::get_singleton()->get_environment("MTL_CAPTURE_ENABLED") == "1") {
if (OS::get_singleton()->get_environment("MTL_CAPTURE_ENABLED") == "1" || OS::get_singleton()->get_environment("MTLCAPTURE_DESTINATION_DEVELOPER_TOOLS_ENABLE") == "1") {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ensures labels are generated when running under Xcode 26

@stuartcarnie stuartcarnie force-pushed the metal_refactor_and_fixes branch 2 times, most recently from dd6acbd to 1503ec0 Compare January 1, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants