forked from hexops/mach-objc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmtl_manual.zig
239 lines (192 loc) · 7.92 KB
/
mtl_manual.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
const c = @import("../c.zig");
const cf = @import("../core_foundation/cf.zig");
const ns = @import("../foundation/ns.zig");
// ------------------------------------------------------------------------------------------------
// Opaque types
pub const dispatch_data_t = *opaque {};
pub const dispatch_queue_t = *opaque {};
pub const IOSurfaceRef = *opaque {};
// TODO - can we use definition in ns
extern const _NSConcreteStackBlock: *anyopaque;
// ------------------------------------------------------------------------------------------------
// Types
// MTLCounters.hpp
pub const CommonCounter = *ns.String;
pub const CommonCounterSet = *ns.String;
// MTLDevice.hpp
pub const DeviceNotificationName = *ns.String;
pub const AutoreleasedComputePipelineReflection = *ComputePipelineReflection;
pub const AutoreleasedRenderPipelineReflection = *RenderPipelineReflection;
pub const Timestamp = u64;
// MTLLibrary.hpp
pub const AutoreleasedArgument = *Argument;
// ------------------------------------------------------------------------------------------------
// Constants
// MTLCounters.hpp
extern const CounterErrorDomain: ns.ErrorDomain;
extern const CommonCounterTimestamp: CommonCounter;
extern const CommonCounterTessellationInputPatches: CommonCounter;
extern const CommonCounterVertexInvocations: CommonCounter;
extern const CommonCounterPostTessellationVertexInvocations: CommonCounter;
extern const CommonCounterClipperInvocations: CommonCounter;
extern const CommonCounterClipperPrimitivesOut: CommonCounter;
extern const CommonCounterFragmentInvocations: CommonCounter;
extern const CommonCounterFragmentsPassed: CommonCounter;
extern const CommonCounterComputeKernelInvocations: CommonCounter;
extern const CommonCounterTotalCycles: CommonCounter;
extern const CommonCounterVertexCycles: CommonCounter;
extern const CommonCounterTessellationCycles: CommonCounter;
extern const CommonCounterPostTessellationVertexCycles: CommonCounter;
extern const CommonCounterFragmentCycles: CommonCounter;
extern const CommonCounterRenderTargetWriteCycles: CommonCounter;
extern const CommonCounterSetTimestamp: CommonCounterSet;
extern const CommonCounterSetStageUtilization: CommonCounterSet;
extern const CommonCounterSetStatistic: CommonCounterSet;
// MTLDevice.hpp
extern const DeviceWasAddedNotification: DeviceNotificationName;
extern const DeviceRemovalRequestedNotification: DeviceNotificationName;
extern const DeviceWasRemovedNotification: DeviceNotificationName;
// ------------------------------------------------------------------------------------------------
// Functions
// MTLDevice.hpp
extern fn MTLCreateSystemDefaultDevice() ?*Device;
pub const createSystemDefaultDevice = MTLCreateSystemDefaultDevice;
//extern fn MTLCopyAllDevices() *ns.Array;
//extern fn MTLCopyAllDevicesWithObserver(**ns.Object, DeviceNotificationHandlerBlock) *ns.Array;
//extern fn MTLRemoveDeviceObserver(*ns.Object) void;
// ------------------------------------------------------------------------------------------------
// Structs
// MTLComputeCommandEncoder.hpp
pub const DispatchThreadgroupsIndirectArguments = extern struct {
threadgroupsPerGrid: [3]u32,
pub fn init(threadgroupsPerGrid: [3]u32) DispatchThreadgroupsIndirectArguments {
return DispatchThreadgroupsIndirectArguments{ .threadgroupsPerGrid = threadgroupsPerGrid };
}
};
pub const StageInRegionIndirectArguments = extern struct {
stageInOrigin: [3]u32,
stageInSize: [3]u32,
pub fn init(stageInOrigin: [3]u32, stageInSize: [3]u32) StageInRegionIndirectArguments {
return StageInRegionIndirectArguments{ .stageInOrigin = stageInOrigin, .stageInSize = stageInSize };
}
};
// MTLRenderCommandEncoder.hpp
pub const ScissorRect = extern struct {
x: ns.UInteger,
y: ns.UInteger,
width: ns.UInteger,
height: ns.UInteger,
pub fn init(x: ns.UInteger, y: ns.UInteger, width: ns.UInteger, height: ns.UInteger) ScissorRect {
return ScissorRect{ .x = x, .y = y, .width = width, .height = height };
}
};
pub const Viewport = extern struct {
originX: f64,
originY: f64,
width: f64,
height: f64,
znear: f64,
zfar: f64,
pub fn init(originX: f64, originY: f64, width: f64, height: f64, znear: f64, zfar: f64) Viewport {
return Viewport{ .originX = originX, .originY = originY, .width = width, .height = height, .znear = znear, .zfar = zfar };
}
};
pub const VertexAmplificationViewMapping = extern struct {
viewportArrayIndexOffset: u32,
renderTargetArrayIndexOffset: u32,
pub fn init(viewportArrayIndexOffset: u32, renderTargetArrayIndexOffset: u32) VertexAmplificationViewMapping {
return VertexAmplificationViewMapping{ .viewportArrayIndexOffset = viewportArrayIndexOffset, .renderTargetArrayIndexOffset = renderTargetArrayIndexOffset };
}
};
// MTLRenderPass.hpp
pub const ClearColor = extern struct {
red: f64,
green: f64,
blue: f64,
alpha: f64,
pub fn init(red: f64, green: f64, blue: f64, alpha: f64) ClearColor {
return ClearColor{ .red = red, .green = green, .blue = blue, .alpha = alpha };
}
};
// MTLTexture.hpp
pub const TextureSwizzleChannels = extern struct {
red: TextureSwizzle,
green: TextureSwizzle,
blue: TextureSwizzle,
alpha: TextureSwizzle,
pub fn init(red: TextureSwizzle, green: TextureSwizzle, blue: TextureSwizzle, alpha: TextureSwizzle) TextureSwizzleChannels {
return TextureSwizzleChannels{ .red = red, .green = green, .blue = blue, .alpha = alpha };
}
};
// MTLTypes.hpp
pub const Origin = extern struct {
x: ns.UInteger,
y: ns.UInteger,
z: ns.UInteger,
pub fn init(x: ns.UInteger, y: ns.UInteger, z: ns.UInteger) Origin {
return .{ .x = x, .y = y, .z = z };
}
};
pub const Size = extern struct {
width: ns.UInteger,
height: ns.UInteger,
depth: ns.UInteger,
pub fn init(width: ns.UInteger, height: ns.UInteger, depth: ns.UInteger) Size {
return .{ .width = width, .height = height, .depth = depth };
}
};
pub const Region = extern struct {
origin: Origin,
size: Size,
pub fn init1d(x: ns.UInteger, width: ns.UInteger) Region {
return .{ .origin = .{ .x = x, .y = 0, .z = 0 }, .size = .{ .width = width, .height = 1, .depth = 1 } };
}
pub fn init2d(x: ns.UInteger, y: ns.UInteger, width: ns.UInteger, height: ns.UInteger) Region {
return .{ .origin = .{ .x = x, .y = y, .z = 0 }, .size = .{ .width = width, .height = height, .depth = 1 } };
}
pub fn init3d(x: ns.UInteger, y: ns.UInteger, z: ns.UInteger, width: ns.UInteger, height: ns.UInteger, depth: ns.UInteger) Region {
return .{ .origin = .{ .x = x, .y = y, .z = z }, .size = .{ .width = width, .height = height, .depth = depth } };
}
};
pub const SamplePosition = extern struct {
x: f32,
y: f32,
pub fn init(x: f32, y: f32) SamplePosition {
return .{ .x = x, .y = y };
}
};
pub const Coordinate2D = SamplePosition;
pub const ResourceID = extern struct {
_impl: u64,
};
// MTLCounters.hpp
pub const CounterResultTimestamp = extern struct { timestamp: u64 };
pub const CounterResultStageUtilization = extern struct {
totalCycles: u64,
vertexCycles: u64,
tessellationCycles: u64,
postTessellationVertexCycles: u64,
fragmentCycles: u64,
renderTargetCycles: u64,
};
pub const CounterResultStatistic = extern struct {
tessellationInputPatches: u64,
vertexInvocations: u64,
postTessellationVertexInvocations: u64,
clipperInvocations: u64,
clipperPrimitivesOut: u64,
fragmentInvocations: u64,
fragmentsPassed: u64,
computeKernelInvocations: u64,
};
// MTLDevice.hpp
pub const AccelerationStructureSizes = extern struct {
accelerationStructureSize: ns.UInteger,
buildScratchBufferSize: ns.UInteger,
refitScratchBufferSize: ns.UInteger,
};
pub const SizeAndAlign = extern struct {
size: ns.UInteger,
@"align": ns.UInteger,
};
// ------------------------------------------------------------------------------------------------