Sample CodeiOS, iPadOS, Mac Catalyst, macOS, tvOSReviewed 2026-07-21View on Apple Developer

Improving edge-rendering quality with multisample antialiasing (MSAA)

At a glance

Item Summary
Purpose Apply MSAA to enhance the rendering of edges with custom resolve options and immediate and tile-based resolve paths.
App architecture Objective-C host code with Metal shaders; AAPLViewController hands work to AAPLRenderer, which owns multisample target and resolve setup before MSAA rasterization and resolve.
Main patterns Renderer boundary, Configuration strategy, Explicit resolve stage
Scope High-level review of 18 scanned source files and 14 detected declarations; build assets are omitted.

Project structure

Source bundle/
├── Application/
│   ├── AAPLViewController.m
│   ├── main.m
│   ├── WindowSceneDelegate.m
│   ├── AAPLAppDelegate.h
│   ├── AAPLAppDelegate.m
│   └── AAPLView.h
└── Renderer/
    ├── AAPLShaderCommon.metal
    ├── AAPLRenderer.m
    └── AAPLShaders.metal

Structure observations

  • The entry/composition boundary and renderer or operation boundary are separate in the source; AAPLRenderer is the principal feature coordinator.
  • GPU-specific logic stays in Metal shader files; shared headers bridge host/shader layouts where present.
  • The tree above is intentionally pruned to composition, resource, and shader files.

Overall architecture

Reference code

Renderer/AAPLRenderer.m:405 — multisample store-and-resolve configuration

        MTLStoreAction storeAction = shouldResolve ? MTLStoreActionMultisampleResolve : MTLStoreActionStore;
        renderPassDescriptor.colorAttachments[0].storeAction = storeAction;
        renderPassDescriptor.colorAttachments[0].texture = _multisampleTexture;
        renderPassDescriptor.colorAttachments[0].resolveTexture = shouldResolve ? _resolveResultTexture : nil;

Interpretation

This is the dominant control/data path: platform code composes AAPLRenderer; that object controls multisample target and resolve setup; GPU-visible work ends in MSAA rasterization and resolve. The arrows summarize responsibility transfer, not a claim that every node directly calls the next.

Ownership and state

Ownership evidence

Application/AAPLViewController.m:47AAPLViewController creates and stores _renderer

@implementation AAPLViewController
// ...
    _renderer = [[AAPLRenderer alloc] initWithMetalDevice:_view.device
                                      drawablePixelFormat:_view.colorPixelFormat];
// ...
@end
Owner Object or state Relationship Mutation authority
AAPLViewController _renderer / AAPLRenderer Creates and stores; the diagram uses composition because construction is source-visible. The declaring scope performs setup and replacement.
AAPLRenderer Feature-specific framework and Metal resources Operation-local calls or stored state; exclusive lifetime is not assumed beyond cited evidence. Feature setup/encoding code controls mutation and command submission.

Class and protocol design

Type Responsibility Depends on or conforms to Source
AAPLViewController selects/configures the view and composes the feature objects. PlatformViewController, MTKViewDelegate Application/AAPLViewController.h:36
AAPLRenderer owns pipeline/resource setup and per-frame command encoding. NSObject Renderer/AAPLRenderer.h:14
AAPLView owns presentation timing/drawable behavior and forwards callbacks. MTKView Application/AAPLView.h:16
AAPLAppDelegate handles application/window lifecycle callbacks. UIResponder, UIApplicationDelegate, NSObject Application/AAPLAppDelegate.h:16
WindowSceneDelegate handles application/window lifecycle callbacks. UIResponder, UIWindowSceneDelegate Application/WindowSceneDelegate.h:15
FragData defines the fragment output that carries the resolved multisample color. concrete Metal/framework collaborators Renderer/AAPLShaderCommon.h:10

Framework delegate conformance is a callback seam; the source does not justify calling the whole app protocol-oriented.

Access control

Symbol Access Verified effect Design reason
AAPLAppDelegate header-visible available to translation units that import the header; this is not Swift public. Keep the usable surface no wider than the collaboration requires. (Application/AAPLAppDelegate.h:16)
AAPLRenderer implementation details implementation-only native helpers, stored state, or registration code stays out of the imported header contract. Hide native implementation details from importing translation units. (Renderer/AAPLRenderer.m:1)
AAPLShaderCommon entry points Metal library boundary host code resolves named shader entry points; Swift access modifiers do not apply. Expose only named shader entry points needed by pipeline creation. (Renderer/AAPLShaderCommon.metal:42)

This sample does not use Swift private, fileprivate, or public for its native boundary. Objective-C/Objective-C++ use header versus implementation placement, C++ uses access specifiers/linkage, Python uses module conventions, and Metal entry points cross a compiled-library boundary; these are not Swift access levels.

Logic ownership and placement

Logic Owning type or file Why it lives there
Selects/configures the view and composes the feature objects AAPLViewControllerApplication/AAPLViewController.h:36 The type’s callbacks and stored state align with this responsibility.
Owns pipeline/resource setup and per-frame command encoding AAPLRendererRenderer/AAPLRenderer.h:14 The type’s callbacks and stored state align with this responsibility.
Owns presentation timing/drawable behavior and forwards callbacks AAPLViewApplication/AAPLView.h:16 The type’s callbacks and stored state align with this responsibility.
Handles application/window lifecycle callbacks AAPLAppDelegateApplication/AAPLAppDelegate.h:16 The type’s callbacks and stored state align with this responsibility.
Multisample target and resolve setup AAPLRenderer / Application/AAPLViewController.m:27 Keeps Metal/framework setup and encoding out of entry or lifecycle code.
MSAA rasterization and resolve Renderer/AAPLShaderCommon.metal:42 GPU-parallel code remains in the Metal compilation boundary.

Shader boundary reference

Renderer/AAPLShaderCommon.metal:42 — representative GPU entry/helper

vertex CompositionVertexOut

Design patterns

Pattern Source evidence Purpose or tradeoff
Renderer boundary Application/AAPLViewController.m:27 UI/lifecycle code composes a renderer while GPU state and encoding stay together.
Configuration strategy Application/AAPLViewController.m:47 Makes the sample’s multisample target and resolve setup an explicit, reviewable boundary.
Explicit resolve stage Renderer/AAPLShaderCommon.metal:42 Makes the sample’s multisample target and resolve setup an explicit, reviewable boundary.

Naming conventions

  • Role suffixes make ownership visible: AAPLViewController, AAPLRenderer, AAPLView, AAPLAppDelegate, WindowSceneDelegate.
  • Method names describe setup or encoding actions: application, applicationShouldTerminateAfterLastWindowClosed, acceptsFirstResponder, keyDown, toggleAntialiasing, updateAntialiasingSampleCount, updateAntialiasingResolve.
  • Shader entry points use stage/operation names: averageResolveKernel, hdrResolveKernel, averageResolveTileKernel, hdrResolveTileKernel.
  • AAPL is a sample namespace prefix, not a recommendation for production module naming; retain semantic suffixes such as Renderer, Manager, Scene, or Adapter.

Architecture takeaways

  • Keep AAPLViewController focused on composition; AAPLRenderer is the owner of multisample target and resolve setup.
  • Treat MSAA rasterization and resolve as a separate execution/compilation boundary with explicit resource and data-layout contracts.
  • The verified ownership edge is AAPLViewController_renderer; broader exclusive ownership is not inferred.
  • Access-control rationale follows concrete language boundaries rather than translating every header or shader symbol into Swift terms.

Source map

Source file Architectural role
Application/AAPLViewController.m AAPLViewController
Renderer/AAPLShaderCommon.metal CompositionVertexOut
Application/main.m entry point or feature implementation
Renderer/AAPLRenderer.m AAPLRenderer
Application/WindowSceneDelegate.m WindowSceneDelegate
Renderer/AAPLShaders.metal RasterizerData
Application/AAPLAppDelegate.h AAPLAppDelegate, AAPLAppDelegate
Application/AAPLAppDelegate.m AAPLAppDelegate
Application/AAPLView.h AAPLView