At a glance
| Item |
Summary |
| Purpose |
Use advanced Metal features such as indirect command buffers, sparse textures, and variable rate rasterization to implement complex rendering techniques. |
| App architecture |
Objective-C, Objective-C++ host code with Metal shaders; AAPLCameraController hands work to AAPLRenderer, which owns scene, mesh, and texture-management subsystems before multi-pass modern renderer shaders. |
| Main patterns |
Subsystem decomposition, Resource manager, Delegate-driven frame loop |
| Scope |
High-level review of 66 scanned source files and 108 detected declarations; build assets are omitted. |
Project structure
Source bundle/
├── Renderer/
│ ├── AAPLRenderer.mm
│ ├── Shaders/
│ │ ├── AAPLMeshRenderer.metal
│ │ └── AAPLShaderCommon.h
│ └── AAPLMesh.h
├── Application/
│ ├── main.m
│ ├── AAPLSettingsTableViewController.mm
│ ├── AAPLAppDelegate.h
│ └── AAPLViewController.h
└── Asset/
└── AAPLTextureManager.mm
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
flowchart LR
N1["AAPLViewController"]
N2["AAPLRenderer"]
N3["scene/mesh/texture subsystems"]
N4["multi-pass shaders"]
N1 --> N2
N2 --> N3
N3 --> N4
Reference code
Renderer/AAPLRenderer.mm:533 — renderer composes its texture-management subsystem
_textureManager = [[AAPLTextureManager alloc] initWithDevice:_device
commandQueue:_commandQueue
heapSize:TEXTURE_HEAP_SIZE
permanentTextureSize:64
maxTextureSize:4096
useSparseTextures:_config.useSparseTextures];
Interpretation
This is the dominant control/data path: platform code composes AAPLRenderer; that object controls scene, mesh, and texture-management subsystems; GPU-visible work ends in multi-pass modern renderer shaders. The arrows summarize responsibility transfer, not a claim that every node directly calls the next.
Ownership and state
classDiagram
AAPLRenderer *-- AAPLTextureManager : _textureManager
Ownership evidence
Renderer/AAPLRenderer.mm:533 — AAPLRenderer creates and stores _textureManager
@implementation AAPLRenderer
// ...
@end
| Owner |
Object or state |
Relationship |
Mutation authority |
AAPLRenderer |
_textureManager / AAPLTextureManager |
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 |
AAPLCameraController |
selects/configures the view and composes the feature objects. |
NSObject |
Renderer/AAPLCameraController.h:18 |
AAPLSettingsTableViewController |
selects/configures the view and composes the feature objects. |
UITableViewController, UITableViewDelegate, UITableViewDataSource |
Application/AAPLSettingsTableViewController.h:23 |
AAPLViewController |
selects/configures the view and composes the feature objects. |
UIViewController, MTKViewDelegate, NSViewController |
Application/AAPLViewController.h:28 |
AAPLMeshRenderer |
owns pipeline/resource setup and per-frame command encoding. |
NSObject |
Renderer/RenderTech/AAPLMeshRenderer.h:20 |
AAPLRenderer |
owns pipeline/resource setup and per-frame command encoding. |
NSObject |
Renderer/AAPLRenderer.h:37 |
AAPLTextureManager |
centralizes a long-lived resource or instrumentation concern. |
NSObject |
Asset/AAPLTextureManager.h:21 |
AAPLScene |
holds scene geometry, instances, camera, or lighting data. |
NSObject |
Renderer/AAPLScene.h:20 |
A local protocol/conformance boundary is present, so protocol-oriented collaboration is claimed only for that seam.
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:15) |
AAPLTextureManager 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. (Asset/AAPLTextureManager.mm:1) |
AAPLMeshRenderer 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/Shaders/AAPLMeshRenderer.metal:230) |
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 |
AAPLCameraController — Renderer/AAPLCameraController.h:18 |
The type’s callbacks and stored state align with this responsibility. |
| Selects/configures the view and composes the feature objects |
AAPLSettingsTableViewController — Application/AAPLSettingsTableViewController.h:23 |
The type’s callbacks and stored state align with this responsibility. |
| Selects/configures the view and composes the feature objects |
AAPLViewController — Application/AAPLViewController.h:28 |
The type’s callbacks and stored state align with this responsibility. |
| Owns pipeline/resource setup and per-frame command encoding |
AAPLMeshRenderer — Renderer/RenderTech/AAPLMeshRenderer.h:20 |
The type’s callbacks and stored state align with this responsibility. |
| Scene, mesh, and texture-management subsystems |
AAPLRenderer / Renderer/AAPLRenderer.mm:533 |
Keeps subsystem construction and shared GPU-resource policy in the renderer composition root. |
| Multi-pass modern renderer shaders |
Renderer/Shaders/AAPLMeshRenderer.metal:230 |
GPU-parallel code remains in the Metal compilation boundary. |
Shader boundary reference
Renderer/Shaders/AAPLMeshRenderer.metal:230 — representative GPU entry/helper
vertex AAPLDepthOnlyVertexOutput vertexShaderDepthOnly(AAPLDepthOnlyVertex in [[ stage_in ]],
constant AAPLCameraParams & cameraParams [[ buffer(AAPLBufferIndexCameraParams) ]])
{
AAPLDepthOnlyVertexOutput out;
out.position = cameraParams.viewProjectionMatrix * float4(in.position, 1.0);
return out;
}
Design patterns
| Pattern |
Source evidence |
Purpose or tradeoff |
| Subsystem decomposition |
Renderer/AAPLRenderer.mm:533 |
Makes the texture manager a concrete renderer-owned subsystem instead of an inferred ivar relationship. |
| Resource manager |
Renderer/AAPLRenderer.mm:533 |
Makes the sample’s scene, mesh, and texture-management subsystems an explicit, reviewable boundary. |
| Delegate-driven frame loop |
Renderer/AAPLRenderer.h:46 |
A view/display callback triggers updates and command encoding; timing is inverted into the renderer. |
Naming conventions
- Role suffixes make ownership visible:
AAPLCameraController, AAPLSettingsTableViewController, AAPLViewController, AAPLMeshRenderer, AAPLRenderer, AAPLTextureManager, AAPLScene.
- Method names describe setup or encoding actions:
initWithDevice, update, getTexture, addTextures, request, setRequiredMip, loadMipsToTexture.
- Shader entry points use stage/operation names:
vertexShaderDepthOnly, vertexShaderDepthOnlyAlphaMask, vertexShaderDepthOnlyAmplified, vertexShaderDepthOnlyAlphaMaskAmplified, vertexShader, fragmentGBufferShader.
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
AAPLCameraController focused on composition; AAPLRenderer is the owner of scene, mesh, and texture-management subsystems.
- Treat multi-pass modern renderer shaders as a separate execution/compilation boundary with explicit resource and data-layout contracts.
- The verified ownership edge is
AAPLRenderer → _textureManager; 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 |
Renderer/AAPLRenderer.mm |
AAPLConfig, AAPLFrameData, AAPLRenderer |
Renderer/Shaders/AAPLMeshRenderer.metal |
AAPLVertex, AAPLVertexOutput, AAPLDepthOnlyVertex, AAPLDepthOnlyVertexOutput, AAPLDepthOnlyAlphaMaskVertex |
Application/main.m |
entry point or feature implementation |
Application/AAPLSettingsTableViewController.mm |
AAPLWidget, AAPLSection, AAPLSettingsTableViewController |
Asset/AAPLTextureManager.mm |
TextureRequest, TextureEntry, TextureUpdate, StatsEntry, PendingBlit |
Renderer/Shaders/AAPLShaderCommon.h |
AAPLShaderMaterial, AAPLShaderLightParams, AAPLGlobalTextures, AAPLSimpleVertexOut, AAPLSimpleTexVertexOut |
Application/AAPLAppDelegate.h |
AAPLAppDelegate, AAPLAppDelegate |
Application/AAPLViewController.h |
AAPLView, AAPLViewController, AAPLViewController |
Renderer/AAPLMesh.h |
AAPLMeshChunk, AAPLSubMesh, AAPLMaterial, MTLTexture, MTLBuffer |