Applying temporal antialiasing and upscaling using MetalFX
At a glance
| Item | Summary |
|---|---|
| Purpose | Reduce render workloads while increasing image detail with MetalFX. |
| App architecture | A C/Objective-C header, Metal, Swift sample with the source-visible chain AAPLAppDelegate → AAPLViewController → AAPLRenderer → Metal APIs. |
| Main patterns | View-controller organization, Delegate or data-source callbacks |
| Project style | 10 scanned source file(s) across C/Objective-C header, Metal, Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: DispatchSemaphore; none alone proves a background thread. |
| State/event model | No structured observation or publisher-scheduling marker indexed. |
| Key frameworks/packages | MetalKit, simd, Cocoa, Metal, UIKit; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
├── Application/
│ ├── iOS/
│ │ ├── AAPLAppDelegate.swift
│ │ ├── AAPLViewController.swift
│ │ └── Base.lproj/
│ │ ├── LaunchScreen.storyboard
│ │ └── Main.storyboard
│ └── macOS/
│ ├── AAPLAppDelegate.swift
│ └── AAPLViewController.swift
└── Renderer/
├── AAPLRenderer.swift
├── AAPLRenderTarget.swift
├── AAPLRendererHelper.swift
├── Shaders.metal
├── AAPLMathUtilities.swift
└── ShaderTypes.h
Structure observations
- Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
- Primary languages: C/Objective-C header, Metal, Swift.
- The verified tree contains 8 project/configuration file(s) and 9 source declaration(s).
Overall architecture
flowchart LR
N1["AAPLAppDelegate"]
N2["AAPLViewController"]
N3["AAPLRenderer"]
N4["Metal APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
Reference code
Application/iOS/AAPLAppDelegate.swift:10 — architecture anchor
@main
class AAPLAppDelegate: UIResponder, UIApplicationDelegate {
// ...
var window: UIWindow?
// ...
}Interpretation
The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into MetalFX.
Ownership and state
classDiagram
AAPLAppDelegate o-- UIWindow : window
AAPLRenderer *-- Bool : animationEnabled
AAPLRenderer *-- Bool : resetHistoryEnabled
AAPLRenderer *-- Bool : firstFrameTemporal
Ownership evidence
Application/iOS/AAPLAppDelegate.swift:13 — stored dependency or nearest verified ownership anchor
@main
class AAPLAppDelegate: UIResponder, UIApplicationDelegate {
// ...
var window: UIWindow?
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
AAPLAppDelegate |
UIWindow (window) |
stores or receives | App/module collaborators |
AAPLRenderer |
Bool (animationEnabled) |
owns value state | App/module collaborators |
AAPLRenderer |
Bool (resetHistoryEnabled) |
owns value state | App/module collaborators |
AAPLRenderer |
Bool (firstFrameTemporal) |
owns value state | App/module collaborators |
Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.
Concurrency, scheduling, and thread safety
Evidence limit: actor isolation, async/await, or Task creation does not by itself prove background-thread execution; Sendable conformance alone does not prove thread-safe mutation.
| Concern | Source mechanism | Verified placement or handoff | Evidence |
|---|---|---|---|
| Synchronization | DispatchSemaphore |
The source references a synchronization primitive; the protected state requires surrounding review. | Renderer/AAPLRenderer.swift:43 |
@MainActor/MainActor.run, DispatchQueue.main, and RunLoop.main are reported as distinct isolation, queue, and event-loop mechanisms. A plain Task is kept separate from Task.detached; neither is labeled as a background thread.
Reference code
Renderer/AAPLRenderer.swift:43 — representative execution boundary
class AAPLRenderer: NSObject, MTKViewDelegate {
// ...
let inFlightSemaphore = DispatchSemaphore(value: AAPLMaxBuffersInFlight)
// ...
}State propagation, frameworks, and dependencies
Evidence limit: an import proves a source-level compilation dependency at the cited line; it does not prove runtime use, architectural adoption, or whether a Swift package is a direct application dependency.
| Category | Mechanism or module | Verified role | Evidence |
|---|---|---|---|
| Source import | MetalKit |
The cited file imports this module; runtime use and architectural role are not inferred. | Application/iOS/AAPLViewController.swift:9 |
| Source import | simd |
The cited file imports this module; runtime use and architectural role are not inferred. | Renderer/AAPLMathUtilities.swift:8 |
| Source import | Cocoa |
The cited file imports this module; runtime use and architectural role are not inferred. | Application/macOS/AAPLAppDelegate.swift:8 |
| Source import | Metal |
The cited file imports this module; runtime use and architectural role are not inferred. | Renderer/AAPLRenderTarget.swift:8 |
| Source import | UIKit |
The cited file imports this module; runtime use and architectural role are not inferred. | Application/iOS/AAPLAppDelegate.swift:8 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | Renderer/ShaderTypes.h:14 |
receive(on:) describes downstream delivery scheduling, while subscribe(on:) describes upstream subscription/request/cancel scheduling. An import Combine alone establishes neither behavior nor a Store, reducer, Redux, or other application architecture.
Class and protocol design
Application/iOS/AAPLAppDelegate.swift:11 — representative type boundary
@main
class AAPLAppDelegate: UIResponder, UIApplicationDelegate {
// ...
var window: UIWindow?
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
AAPLAppDelegate |
Receives callback-driven events | UIResponder, UIApplicationDelegate |
AAPLAppDelegate |
Receives callback-driven events | NSObject, NSApplicationDelegate |
AAPLRenderer |
Owns drawing, GPU, or presentation processing | NSObject, MTKViewDelegate |
AAPLViewController |
View lifecycle, callbacks, and feature coordination | UIViewController |
AAPLViewController |
View lifecycle, callbacks, and feature coordination | NSViewController |
AAPLScalingMode |
Defines a closed set of feature states or choices | Int |
AAPLRenderTarget |
Owns feature behavior and collaborator lifecycle | Concrete collaborators/imported frameworks |
AAPLRendererHelper |
Owns feature behavior and collaborator lifecycle | Concrete collaborators/imported frameworks |
AAPLVertexV4T2 |
Represents a feature value or composable behavior | Concrete collaborators/imported frameworks |
No local protocol conformance is claimed as protocol-oriented design; external framework conformances are listed only as dependencies.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
renderScale (Renderer/AAPLRenderTarget.swift:22) |
public |
The symbol is visible to importing modules. | Inference: make the declaration available across a module or target boundary. |
animationEnabled (Renderer/AAPLRenderer.swift:21) |
public |
The symbol is visible to importing modules. | Inference: make the declaration available across a module or target boundary. |
resetHistoryEnabled (Renderer/AAPLRenderer.swift:22) |
public |
The symbol is visible to importing modules. | Inference: make the declaration available across a module or target boundary. |
firstFrameTemporal (Renderer/AAPLRenderer.swift:23) |
public |
The symbol is visible to importing modules. | Inference: make the declaration available across a module or target boundary. |
Reference code
Renderer/AAPLRenderTarget.swift:22 — representative boundary
class AAPLRenderTarget {
// ...
public var renderScale: Float = 0.5
// ...
}Swift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.
Logic ownership and placement
| Logic | Owning type or file | Placement rationale |
|---|---|---|
| View lifecycle, callbacks, and feature coordination | AAPLViewController |
The source’s Controller suffix makes this role explicit. |
| Receives callback-driven events | AAPLAppDelegate |
The source’s Delegate suffix makes this role explicit. |
| Owns drawing, GPU, or presentation processing | AAPLRenderer |
The source’s Renderer suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| View-controller organization | Application/iOS/AAPLViewController.swift:12 |
A controller is the verified coordination boundary; this is MVC-style only where a separate model is present. |
| Delegate or data-source callbacks | Application/iOS/AAPLAppDelegate.swift:11 |
Callback protocols invert event delivery back into the sample’s owner. |
Naming conventions
- Types: Controller: AAPLViewController; Delegate: AAPLAppDelegate; Renderer: AAPLRenderer.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
application,applicationWillResignActive,applicationDidEnterBackground,applicationWillEnterForeground,applicationDidBecomeActive,applicationDidFinishLaunching,applicationWillTerminate,applicationShouldTerminateAfterLastWindowClosed. - Files:
Application/iOS/AAPLAppDelegate.swift,Application/macOS/AAPLAppDelegate.swift,Renderer/AAPLRenderer.swift,Application/iOS/AAPLViewController.swift,Application/macOS/AAPLViewController.swift,Renderer/AAPLRenderTarget.swift.
Architecture takeaways
AAPLAppDelegateis the main source-visible entry or composition anchor for this sample.- Framework work reaches MetalKit, simd, Cocoa, Metal through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
- Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
- Access-control conclusions separate verified language visibility from the likely design rationale.
- The source does not justify labeling the design protocol-oriented.
Source map
| Source file | Relevant symbols |
|---|---|
Application/iOS/AAPLAppDelegate.swift |
Cited implementation, AAPLAppDelegate, UIKit |
Renderer/AAPLRenderTarget.swift |
Cited implementation, Metal, AAPLRenderTarget |
Renderer/AAPLRenderer.swift |
Cited implementation, DispatchSemaphore, AAPLScalingMode, AAPLRenderer |
Application/iOS/AAPLViewController.swift |
AAPLViewController, MetalKit |
Renderer/AAPLMathUtilities.swift |
simd, Feature implementation |
Application/macOS/AAPLAppDelegate.swift |
Cocoa, AAPLAppDelegate |
Renderer/ShaderTypes.h |
Foundation, Feature implementation |
Application/macOS/AAPLViewController.swift |
AAPLViewController |
Renderer/AAPLRendererHelper.swift |
AAPLRendererHelper |
Renderer/Shaders.metal |
AAPLVertexV4T2 |