At a glance
| Item |
Summary |
| Purpose |
Configure alternative render paths in your Metal app to enable running your app in Simulator. |
| App architecture |
Objective-C, Swift host code with Metal shaders; Swift / Objective-C app hands work to Renderer, which owns parallel Swift and Objective-C app variants before shared Metal feature with simulator guards. |
| Main patterns |
Parallel language implementations, Capability guard, Renderer boundary |
| Scope |
High-level review of 19 scanned source files and 22 detected declarations; build assets are omitted. |
Project structure
Source bundle/
├── Swift/
│ ├── Renderer/
│ │ └── Renderer.swift
│ └── Application/
│ └── AppDelegate.swift
└── Objective-C/
├── Application/
│ ├── ViewController.m
│ ├── main.m
│ ├── WindowSceneDelegate.m
│ ├── AppDelegate.h
│ └── AppDelegate.m
└── Renderer/
├── Shaders.metal
└── ShaderTypes.h
Structure observations
- The entry/composition boundary and renderer or operation boundary are separate in the source;
Renderer 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
flowchart LR
N1["Swift / Objective-C app"]
N2["Renderer"]
N3["parallel Swift and Objective-C app variants"]
N4["shared Metal feature with simulator guards"]
N1 --> N2
N2 --> N3
N3 --> N4
Reference code
Swift/Renderer/Renderer.swift:84 — target-specific pipeline and framebuffer policy
#if os(macOS) || targetEnvironment(simulator)
blendPipelineState = pipelines[1]
metalKitView.framebufferOnly = false
#endif
Interpretation
This is the dominant control/data path: platform code composes Renderer; that object controls parallel Swift and Objective-C app variants; GPU-visible work ends in shared Metal feature with simulator guards. The arrows summarize responsibility transfer, not a claim that every node directly calls the next.
Ownership and state
classDiagram
ViewController *-- Renderer : _renderer
Ownership evidence
Objective-C/Application/ViewController.m:32 — ViewController creates and stores _renderer
_renderer = [[Renderer alloc] initWithMetalKitView:_view];
NSAssert(_renderer, @"Could not initialize renderer");
#ifdef TARGET_IOS
[_renderer setBlendMode:BlendModeTransparency];
[_renderer setTransparency:_transparencySlider.value];
#endif
| Owner |
Object or state |
Relationship |
Mutation authority |
ViewController |
_renderer / Renderer |
Creates and stores; the diagram uses composition because construction is source-visible. |
The declaring scope performs setup and replacement. |
Renderer |
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 |
ViewController |
selects/configures the view and composes the feature objects. |
PlatformViewController |
Objective-C/Application/ViewController.h:19 |
Renderer |
owns pipeline/resource setup and per-frame command encoding. |
NSObject, MTKViewDelegate |
Objective-C/Renderer/Renderer.h:13 |
AppDelegate |
handles application/window lifecycle callbacks. |
UIResponder, UIApplicationDelegate, NSObject |
Objective-C/Application/AppDelegate.h:10 |
WindowSceneDelegate |
handles application/window lifecycle callbacks. |
UIResponder, UIWindowSceneDelegate |
Objective-C/Application/WindowSceneDelegate.h:11 |
MTLRenderPassDescriptor extension |
applies matching load/store actions to color, depth, and stencil attachments for the simulator/macOS two-pass path. |
Metal render-pass attachments and MTLLoadAction / MTLStoreAction |
Swift/Renderer/Renderer.swift:297 |
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 |
let storageMode = MTLStorageMode.private |
private |
the enclosing declaration and Swift-permitted same-file extensions can use it. |
Keep mutable GPU/resource state under one lexical owner. (Swift/Renderer/AllocateResources.swift:164) |
AppDelegate |
implicit internal |
visible inside the sample target, not exported as public API. |
Keep the usable surface no wider than the collaboration requires. (Swift/Application/AppDelegate.swift:12) |
AppDelegate |
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. (Objective-C/Application/AppDelegate.h:10) |
Renderer 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. (Objective-C/Renderer/Renderer.m:1) |
Shaders 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. (Objective-C/Renderer/Shaders.metal:29) |
Swift’s default is internal; private and fileprivate above use Swift semantics. No public or open app API is inferred when the sample only needs one target. Objective-C/Objective-C++ instead use header versus implementation placement, C++ uses access specifiers/linkage, Python uses module conventions, and Metal entry points cross a compiled-library boundary—none is interchangeable with Swift public.
Logic ownership and placement
| Logic |
Owning type or file |
Why it lives there |
| Selects/configures the view and composes the feature objects |
ViewController — Objective-C/Application/ViewController.h:19 |
The type’s callbacks and stored state align with this responsibility. |
| Owns pipeline/resource setup and per-frame command encoding |
Renderer — Objective-C/Renderer/Renderer.h:13 |
The type’s callbacks and stored state align with this responsibility. |
| Handles application/window lifecycle callbacks |
AppDelegate — Objective-C/Application/AppDelegate.h:10 |
The type’s callbacks and stored state align with this responsibility. |
| Handles application/window lifecycle callbacks |
WindowSceneDelegate — Objective-C/Application/WindowSceneDelegate.h:11 |
The type’s callbacks and stored state align with this responsibility. |
| Parallel Swift and Objective-C app variants |
Renderer / Swift/Renderer/Renderer.swift:84 |
Keeps simulator/macOS capability differences inside renderer setup. |
| Shared Metal feature with simulator guards |
Objective-C/Renderer/Shaders.metal:29 |
GPU-parallel code remains in the Metal compilation boundary. |
Shader boundary reference
Objective-C/Renderer/Shaders.metal:29 — representative GPU entry/helper
vertex ColorInOut vertexShader(Vertex in [[stage_in]],
constant Uniforms & uniforms [[ buffer(BufferIndexUniforms) ]])
{
// ...
}
Design patterns
| Pattern |
Source evidence |
Purpose or tradeoff |
| Parallel language implementations |
Swift/Renderer/Renderer.swift:84 |
Shows the Swift variant expressing the same target-specific renderer policy locally. |
| Capability guard |
Objective-C/Application/ViewController.m:32 |
Makes the sample’s parallel Swift and Objective-C app variants an explicit, reviewable boundary. |
| Renderer boundary |
Objective-C/Renderer/Shaders.metal:29 |
UI/lifecycle code composes a renderer while GPU state and encoding stay together. |
Naming conventions
- Role suffixes make ownership visible:
ViewController, Renderer, AppDelegate, WindowSceneDelegate.
- Method names describe setup or encoding actions:
applicationShouldTerminateAfterLastWindowClosed, application, buildMetalVertexDescriptor, loadTexture, updateDynamicBufferState, uniformsForObject, updateGameState.
- Shader entry points use stage/operation names:
vertexShader, fragmentShader, blendFragmentShader.
- Names favor concrete domain roles and target-local types; no broad
public library namespace is introduced.
Architecture takeaways
- Keep
Swift / Objective-C app focused on composition; Renderer is the owner of parallel Swift and Objective-C app variants.
- Treat shared Metal feature with simulator guards as a separate execution/compilation boundary with explicit resource and data-layout contracts.
- The verified ownership edge is
ViewController → _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 |
Swift/Renderer/Renderer.swift |
Renderer, renderer-local error/state, and simulator/macOS render-pass attachment helpers |
Objective-C/Application/ViewController.m |
ViewController |
Objective-C/Renderer/Shaders.metal |
Vertex, ColorInOut, ColorOut |
Objective-C/Application/main.m |
entry point or feature implementation |
Objective-C/Application/WindowSceneDelegate.m |
WindowSceneDelegate |
Objective-C/Renderer/ShaderTypes.h |
entry point or feature implementation |
Swift/Application/AppDelegate.swift |
AppDelegate, AppDelegate |
Objective-C/Application/AppDelegate.h |
AppDelegate |
Objective-C/Application/AppDelegate.m |
AppDelegate |