Loading textures and models using Metal fast resource loading
At a glance
| Item | Summary |
|---|---|
| Purpose | Stream texture and buffer data directly from disk into Metal resources using fast resource loading. |
| App architecture | A C/Objective-C header, Metal, Objective-C, Objective-C++ sample with the source-visible chain main → AAPLViewController → AAPLRenderer → MetalKit / Metal APIs. |
| Main patterns | View-controller organization, Delegate or data-source callbacks |
| Project style | 12 scanned source file(s) across C/Objective-C header, Metal, Objective-C, Objective-C++, organized around ranked entry, type, and file boundaries. |
| Execution model | No structured execution marker indexed; callback threading requires source review. |
| State/event model | No structured observation or publisher-scheduling marker indexed. |
| Key frameworks/packages | Cocoa, TargetConditionals.h, MetalKit, simd, stdlib.h; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
├── main.m
├── Renderer/
│ ├── AAPLRenderer.mm
│ ├── AAPLRenderer.h
│ ├── Shaders/
│ │ ├── AAPLShaders.metal
│ │ └── AAPLShaderTypes.h
│ ├── AAPLConfig.h
│ ├── AAPLMathUtilities.h
│ └── AAPLMathUtilities.m
├── AAPLAppDelegate.h
├── AAPLAppDelegate.m
├── AAPLViewController.h
└── AAPLViewController.m
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, Objective-C, Objective-C++.
- The verified tree contains 5 project/configuration file(s) and 7 source declaration(s).
Overall architecture
flowchart LR
N1["main"]
N2["AAPLViewController"]
N3["AAPLRenderer"]
N4["MetalKit / Metal APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
Reference code
main.m:19 — architecture anchor
#if TARGET_OS_IOS
int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AAPLAppDelegate class]));
}
}
#endifInterpretation
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 Metal.
Ownership and state
classDiagram
AAPLRenderer o-- bool : cycleDetailedObjects
AAPLRenderer o-- bool : rotateObjects
AAPLRenderer o-- bool : reloadDetailedObject
AAPLRenderer o-- bool : useMTLIO
Ownership evidence
Renderer/AAPLRenderer.h:19 — stored dependency or nearest verified ownership anchor
@interface AAPLRenderer : NSObject
// ...
@property (nonatomic) bool cycleDetailedObjects;
// ...
@end| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
AAPLRenderer |
bool (cycleDetailedObjects) |
stores or receives | Header-visible collaborators |
AAPLRenderer |
bool (rotateObjects) |
stores or receives | Header-visible collaborators |
AAPLRenderer |
bool (reloadDetailedObject) |
stores or receives | Header-visible collaborators |
AAPLRenderer |
bool (useMTLIO) |
stores or receives | Header-visible 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.
No source-visible execution, scheduling, or synchronization boundary was found in the indexed source.
@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.
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 | Cocoa |
The cited file imports this module; runtime use and architectural role are not inferred. | AAPLAppDelegate.h:8 |
| Source import | TargetConditionals.h |
The cited file imports this module; runtime use and architectural role are not inferred. | AAPLViewController.h:7 |
| Source import | MetalKit |
The cited file imports this module; runtime use and architectural role are not inferred. | AAPLViewController.h:9 |
| Source import | simd |
The cited file imports this module; runtime use and architectural role are not inferred. | Renderer/AAPLMathUtilities.h:9 |
| Source import | stdlib.h |
The cited file imports this module; runtime use and architectural role are not inferred. | Renderer/AAPLMathUtilities.h:8 |
| Source import | assert.h |
The cited file imports this module; runtime use and architectural role are not inferred. | Renderer/AAPLMathUtilities.m:10 |
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
AAPLAppDelegate.h:10 — representative type boundary
@interface AAPLAppDelegate : NSObject <NSApplicationDelegate>
@end| Type | Responsibility | Depends on or conforms to |
|---|---|---|
AAPLAppDelegate |
Receives callback-driven events | NSObject, NSApplicationDelegate |
AAPLViewController |
View lifecycle, callbacks, and feature coordination | PlatformViewController |
AAPLRenderer |
Owns drawing, GPU, or presentation processing | NSObject |
AAPLResourceCommon |
Represents a feature value or composable behavior | Concrete collaborators/imported frameworks |
AAPLTextureParams |
Represents a feature value or composable behavior | AAPLResourceCommon |
AAPLModelParams |
Represents a feature value or composable behavior | AAPLResourceCommon |
FragmentIn |
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 |
|---|---|---|---|
cycleDetailedObjects (Renderer/AAPLRenderer.h:19) |
header-visible |
The declaration is exposed to translation units that import the header. | Inference: declare a contract needed by other Objective-C/C translation units. |
rotateObjects (Renderer/AAPLRenderer.h:21) |
header-visible |
The declaration is exposed to translation units that import the header. | Inference: declare a contract needed by other Objective-C/C translation units. |
reloadDetailedObject (Renderer/AAPLRenderer.h:23) |
header-visible |
The declaration is exposed to translation units that import the header. | Inference: declare a contract needed by other Objective-C/C translation units. |
useMTLIO (Renderer/AAPLRenderer.h:25) |
header-visible |
The declaration is exposed to translation units that import the header. | Inference: declare a contract needed by other Objective-C/C translation units. |
Reference code
Renderer/AAPLRenderer.h:19 — representative boundary
@interface AAPLRenderer : NSObject
// ...
@property (nonatomic) bool cycleDetailedObjects;
// ...
@endSwift 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 | AAPLViewController.h:13 |
A controller is the verified coordination boundary; this is MVC-style only where a separate model is present. |
| Delegate or data-source callbacks | AAPLAppDelegate.h:10 |
Callback protocols invert event delivery back into the sample’s owner. |
Main application flow
sequenceDiagram
participant AAPLRenderer
participant _pendingIOCommandsCount
participant _ioQueue
participant commandBuffer
AAPLRenderer->>_pendingIOCommandsCount: load()
AAPLRenderer->>_ioQueue: commandBuffer()
AAPLRenderer->>_pendingIOCommandsCount: fetch_add()
AAPLRenderer->>AAPLRenderer: loadModelDataWithMTLIO()
AAPLRenderer->>AAPLRenderer: loadTextureDataWithMTLIO()
AAPLRenderer->>commandBuffer: addCompletedHandler()
AAPLRenderer->>AAPLRenderer: resourcesDidFinishLoading()
AAPLRenderer->>commandBuffer: commit()
Reference code
Renderer/AAPLRenderer.mm:597 — loadResourcesUsingMTLIO()
- (void)loadResourcesUsingMTLIO
{
// If there are too many pending IO commands, return without doing anything.
if (_pendingIOCommandsCount.load() > 8)
return;
// Create the MTLIO command buffer and increment the number of pending commands.
id<MTLIOCommandBuffer> commandBuffer = [_ioQueue commandBuffer];
_pendingIOCommandsCount.fetch_add(1);
for (int i = 0; i < AAPLNumObjects; i++)
{
// Process the 3D model buffers.
if (_models[i].loadStatus == LoadStatusLargeResourceLoading)
[self loadModelDataWithMTLIO:commandBuffer index:i resolutionIndex:LargeIndex];
// Process the 2D texture maps.
if (_textures[i].loadStatus == LoadStatusLargeResourceLoading)
[self loadTextureDataWithMTLIO:commandBuffer index:i resolutionIndex:LargeIndex];
}
// Commit the command buffer and wait for resources to load.
[commandBuffer addCompletedHandler:^(id<MTLIOCommandBuffer> nonnull) {
if (commandBuffer.status == MTLIOStatusComplete)
[self resourcesDidFinishLoading];
self->_pendingIOCommandsCount.fetch_sub(1);
}];
[commandBuffer commit];
}
Naming conventions
- Types: Controller: AAPLViewController; Delegate: AAPLAppDelegate; Renderer: AAPLRenderer.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
initWithMetalKitView,loadMetal,loadResources,loadModelHeader,loadTextureHeader,loadModelData,loadTextureData,loadResourcesUsingTraditionalLoaders. - Files:
Renderer/AAPLRenderer.mm,AAPLAppDelegate.h,AAPLAppDelegate.m,AAPLViewController.h,AAPLViewController.m,Renderer/AAPLRenderer.h.
Architecture takeaways
mainis the main source-visible entry or composition anchor for this sample.- Framework work reaches Cocoa, MetalKit, simd, 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 |
|---|---|
main.m |
Cited implementation, Feature implementation |
Renderer/AAPLRenderer.h |
Cited implementation, cycleDetailedObjects, rotateObjects, reloadDetailedObject, useMTLIO, AAPLRenderer |
AAPLAppDelegate.h |
AAPLAppDelegate, Cited implementation, Cocoa |
AAPLViewController.h |
AAPLViewController, TargetConditionals.h, MetalKit |
Renderer/AAPLMathUtilities.h |
simd, stdlib.h, Feature implementation |
Renderer/AAPLMathUtilities.m |
assert.h, Feature implementation |
Renderer/AAPLRenderer.mm |
AAPLResourceCommon, AAPLTextureParams, AAPLModelParams, AAPLRenderer |
AAPLAppDelegate.m |
AAPLAppDelegate |
AAPLViewController.m |
AAPLViewController |
Renderer/Shaders/AAPLShaders.metal |
FragmentIn |
Renderer/AAPLConfig.h |
Feature implementation |
Renderer/Shaders/AAPLShaderTypes.h |
Feature implementation |