Combining blit and compute operations in a single pass
At a glance
| Item |
Summary |
| Purpose |
Run concurrent blit commands and then a compute dispatch in a single pass with a unified compute encoder. |
| App architecture |
Objective-C host code with Metal shaders; ViewController hands work to Metal4Renderer, which owns combined command-encoder setup before blit and compute commands in one pass. |
| Main patterns |
Renderer boundary, Explicit GPU pipeline, Host-shader data contract |
| Scope |
High-level review of 13 scanned source files and 11 detected declarations; build assets are omitted. |
Project structure
Source bundle/
├── Renderer/
│ ├── Metal4Renderer.m
│ ├── Shaders.metal
│ └── ShaderTypes.h
└── Application/
├── ViewController.m
├── main.m
├── WindowSceneDelegate.m
├── AppDelegate.h
├── AppDelegate.m
└── ViewController.h
Structure observations
- The entry/composition boundary and renderer or operation boundary are separate in the source;
Metal4Renderer 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["ViewController"]
N2["Metal4Renderer"]
N3["combined command-encoder setup"]
N4["blit and compute commands in one pass"]
N1 --> N2
N2 --> N3
N3 --> N4
Reference code
Renderer/Metal4Renderer.m:507 — feature handoff or setup anchor
@implementation Metal4Renderer
// ...
- (void)encodeChyronTextureCopy:(id<MTL4ComputeCommandEncoder>)computeEncoder
// ...
@end
Interpretation
This is the dominant control/data path: platform code composes Metal4Renderer; that object controls combined command-encoder setup; GPU-visible work ends in blit and compute commands in one pass. The arrows summarize responsibility transfer, not a claim that every node directly calls the next.
Ownership and state
classDiagram
ViewController *-- Metal4Renderer : renderer
Ownership evidence
Application/ViewController.m:28 — ViewController creates and stores renderer
@implementation ViewController
// ...
renderer = [[Metal4Renderer alloc] initWithView:view];
// ...
@end
| Owner |
Object or state |
Relationship |
Mutation authority |
ViewController |
renderer / Metal4Renderer |
Creates and stores; the diagram uses composition because construction is source-visible. |
The declaring scope performs setup and replacement. |
Metal4Renderer |
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 |
Application/ViewController.h:21 |
Metal4Renderer |
owns pipeline/resource setup and per-frame command encoding. |
NSObject, MTKViewDelegate |
Renderer/Metal4Renderer.h:12 |
AppDelegate |
handles application/window lifecycle callbacks. |
UIResponder, UIApplicationDelegate |
Application/AppDelegate.h:10 |
WindowSceneDelegate |
handles application/window lifecycle callbacks. |
UIResponder, UIWindowSceneDelegate |
Application/WindowSceneDelegate.h:11 |
TGAImage |
parses supported TGA files and converts BGR(A) pixels into Metal-ready BGRA image data. |
NSObject |
Renderer/Utility/TGAImage.m:80 |
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 |
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. (Application/AppDelegate.h:10) |
Metal4Renderer 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/Metal4Renderer.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. (Renderer/Shaders.metal:89) |
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 |
ViewController — Application/ViewController.h:21 |
The type’s callbacks and stored state align with this responsibility. |
| Owns pipeline/resource setup and per-frame command encoding |
Metal4Renderer — Renderer/Metal4Renderer.h:12 |
The type’s callbacks and stored state align with this responsibility. |
| Handles application/window lifecycle callbacks |
AppDelegate — Application/AppDelegate.h:10 |
The type’s callbacks and stored state align with this responsibility. |
| Handles application/window lifecycle callbacks |
WindowSceneDelegate — Application/WindowSceneDelegate.h:11 |
The type’s callbacks and stored state align with this responsibility. |
| Combined command-encoder setup |
Metal4Renderer / Renderer/Metal4Renderer.m:507 |
Keeps Metal/framework setup and encoding out of entry or lifecycle code. |
| Blit and compute commands in one pass |
Renderer/Shaders.metal:89 |
GPU-parallel grayscale conversion remains in the Metal compilation boundary. |
Shader boundary reference
Renderer/Shaders.metal:89 — grayscale compute entry point used by the combined pass
kernel void
Design patterns
| Pattern |
Source evidence |
Purpose or tradeoff |
| Renderer boundary |
Renderer/Metal4Renderer.m:507 |
UI/lifecycle code composes a renderer while GPU state and encoding stay together. |
| Explicit GPU pipeline |
Application/ViewController.m:28 |
Makes the sample’s combined command-encoder setup an explicit, reviewable boundary. |
| Host-shader data contract |
Renderer/Metal4Renderer.m:22 |
Shared indices/structs and matching bindings couple host encoding to shader signatures deliberately. |
Naming conventions
- Role suffixes make ownership visible:
ViewController, Metal4Renderer, AppDelegate, WindowSceneDelegate.
- Method names describe setup or encoding actions:
application, viewDidLoad, scene, sceneDidDisconnect, initWithView, loadImageToTexture, createCompiler.
- Shader entry points use stage/operation names:
samplingShader, convertToGrayscale.
- Names favor concrete domain roles and target-local types; no broad
public library namespace is introduced.
Architecture takeaways
- Keep
ViewController focused on composition; Metal4Renderer is the owner of combined command-encoder setup.
- Treat blit and compute commands in one pass 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 |
Renderer/Metal4Renderer.m |
Metal4Renderer |
Application/ViewController.m |
ViewController |
Renderer/Shaders.metal |
RasterizerData |
Application/main.m |
entry point or feature implementation |
Application/WindowSceneDelegate.m |
WindowSceneDelegate |
Renderer/ShaderTypes.h |
entry point or feature implementation |
Application/AppDelegate.h |
AppDelegate |
Application/AppDelegate.m |
AppDelegate |
Application/ViewController.h |
ViewController |