1use crate::ffi::*;
2
3#[doc(hidden)]
4macro_rules! __cl_enum {
5 ($enum_name:ident, $cl_type:ident, $body:tt) => {
6 __enum_define!($enum_name, $body);
7 __enum_two_way_from!($enum_name, $cl_type, $body);
8 __test_enum_converter!($enum_name, $cl_type, $body);
9 };
10}
11
12#[doc(hidden)]
13macro_rules! __enum_two_way_from {
14 ($source_type:ident, $dest_type:ident, { $($source_value:ident => $dest_value:expr),* }) => {
15 impl From<$source_type> for $dest_type {
16 fn from(source_value: $source_type) -> $dest_type {
17 (source_value as $dest_type)
18 }
19 }
20
21 impl From<&$source_type> for $dest_type {
22 fn from(source_value: &$source_type) -> $dest_type {
23 $source_type::from(*source_value) as $dest_type
24 }
25 }
26
27 impl From<$dest_type> for $source_type {
28 fn from(dest_value: $dest_type) -> $source_type {
29 $(
34 if dest_value == $dest_value as $dest_type {
35 return $source_type::$source_value
36 }
37 )*
38
39 panic!(
41 "From failed for {:?} to {:?} for value {:?}",
42 stringify!($right_type),
43 stringify!($source_type),
44 dest_value
45 );
46 }
47 }
48 };
49
50 ($source_type:ident, $dest_type:ident, $source_value:expr, $dest_value:expr) => {
51 two_way_from!($source_type, $dest_type, $source_value, $dest_value)
52 };
53}
54
55#[doc(hidden)]
56macro_rules! __enum_define {
57 ($name:ident, { $($field:ident => $value:expr),* }) => {
58 #[allow(non_camel_case_types)]
59
60 #[repr(C)]
61 #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Hash)]
62 pub enum $name {
63 $(
64 $field = $value as isize,
65 )*
66 }
67 };
68}
69
70#[doc(hidden)]
71macro_rules! __test_enum_converter {
72 ($enum_type:ident, $other_type:ty ,{ $($enum_value:expr => $other_value:expr),* }) => {
73 paste::item! {
74 $(
75 #[allow(non_snake_case)]
76 #[test]
77 fn [<type_ $enum_type __ $enum_value _converts_to_and_from_ $other_type>]() {
78 assert_eq!($enum_type::from($other_value), $enum_type::$enum_value);
79 assert_eq!($other_type::from($enum_type::$enum_value), $other_value);
80 }
81 )*
82 }
83 };
84}
85
86__cl_enum!(AddressingMode, cl_addressing_mode, {
87 NoneType => 0x1130,
88 ClampToEdge => 0x1131,
89 Clamp => 0x1132,
90 Repeat => 0x1133,
91 MirroredRepeat => 0x1134
92});
93
94__cl_enum!(ChannelOrder, cl_channel_order, {
95 R => 0x10B0,
96 A => 0x10B1,
97 RG => 0x10B2,
98 RA => 0x10B3,
99 RGB => 0x10B4,
100 RGBA => 0x10B5,
101 BGRA => 0x10B6,
102 ARGB => 0x10B7,
103 Intensity => 0x10B8,
104 Luminance => 0x10B9,
105 Rx => 0x10BA,
106 RGx => 0x10BB,
107 RGBx => 0x10BC,
108 Depth => 0x10BD,
109 DepthStencil => 0x10BE,
110 sRGB => 0x10BF,
111 sRGBx => 0x10C0,
112 sRGBA => 0x10C1,
113 sBGRA => 0x10C2,
114 ABGR => 0x10C3
115});
116
117__cl_enum!(ChannelType, cl_channel_type, {
118 SnormInt8 => 0x10D0,
119 SnormInt16 => 0x10D1,
120 UnormInt8 => 0x10D2,
121 UnormInt16 => 0x10D3,
122 UnormShort_565 => 0x10D4,
123 UnormShort_555 => 0x10D5,
124 UnormInt_101010 => 0x10D6,
125 SignedInt8 => 0x10D7,
126 SignedInt16 => 0x10D8,
127 SignedInt32 => 0x10D9,
128 UnsignedInt8 => 0x10DA,
129 UnsignedInt16 => 0x10DB,
130 UnsignedInt32 => 0x10DC,
131 HalfFloat => 0x10DD,
132 Float => 0x10DE,
133 UnormInt24 => 0x10DF,
134 UnormInt_101010_2 => 0x10E0
135});
136
137__cl_enum!(FilterMode, cl_filter_mode, {
138 Nearest => 0x1140,
139 Linear => 0x1141
140});
141
142__cl_enum!(ImageInfo, cl_image_info, {
143 Format => 0x1110,
144 ElementSize => 0x1111,
145 RowPitch => 0x1112,
146 SlicePitch => 0x1113,
147 Width => 0x1114,
148 Height => 0x1115,
149 Depth => 0x1116,
150 ArraySize => 0x1117,
151 Buffer => 0x1118,
152 NumMipLevels => 0x1119,
153 NumSamples => 0x111A
154});
155
156__cl_enum!(SamplerInfo, cl_sampler_info, {
167 ReferenceCount => 0x1150,
168 Context => 0x1151,
169 NormalizedCoords => 0x1152,
170 AddressingMode => 0x1153,
171 FilterMode => 0x1154,
172 MipFilterMode => 0x1155,
173 LodMin => 0x1156,
174 LodMax => 0x1157
175});
176
177__cl_enum!(MapFlags, cl_map_flags, {
178 Read => 1,
179 Write => 2,
180 WriteInvalidateRegion => 4
181});
182
183__cl_enum!(PlatformInfo, cl_platform_info, {
185 Profile => 0x0900,
186 Version => 0x0901,
187 Name => 0x0902,
188 Vendor => 0x0903,
189 Extensions => 0x0904
190 });
193
194__cl_enum!(DeviceInfo, cl_device_info, {
205 Type => 0x1000,
206 VendorId => 0x1001,
207 MaxComputeUnits => 0x1002,
208 MaxWorkItemDimensions => 0x1003,
209 MaxWorkGroupSize => 0x1004,
210 MaxWorkItemSizes => 0x1005,
211 PreferredVectorWidthChar => 0x1006,
212 PreferredVectorWidthShort => 0x1007,
213 PreferredVectorWidthInt => 0x1008,
214 PreferredVectorWidthLong => 0x1009,
215 PreferredVectorWidthFloat => 0x100A,
216 PreferredVectorWidthDouble => 0x100B,
217 PreferredVectorWidthHalf => 0x1034,
218 MaxClockFrequency => 0x100C,
219 AddressBits => 0x100D,
220 MaxReadImageArgs => 0x100E,
221 MaxWriteImageArgs => 0x100F,
222 MaxMemAllocSize => 0x1010,
223 Image2DMaxWidth => 0x1011,
224 Image2DMaxHeight => 0x1012,
225 Image3DMaxWidth => 0x1013,
226 Image3DMaxHeight => 0x1014,
227 Image3DMaxDepth => 0x1015,
228 ImageSupport => 0x1016,
229 MaxParameterSize => 0x1017,
230 MaxSamplers => 0x1018,
231 MemBaseAddrAlign => 0x1019,
232 MinDataTypeAlignSize => 0x101A,
233 SingleFpConfig => 0x101B,
234 GlobalMemCacheType => 0x101C,
235 GlobalMemCachelineSize => 0x101D,
236 GlobalMemCacheSize => 0x101E,
237 GlobalMemSize => 0x101F,
238 MaxConstantBufferSize => 0x1020,
239 MaxConstantArgs => 0x1021,
240 LocalMemType => 0x1022,
241 LocalMemSize => 0x1023,
242 ErrorCorrectionSupport => 0x1024,
243 ProfilingTimerResolution => 0x1025,
244 EndianLittle => 0x1026,
245 Available => 0x1027,
246 CompilerAvailable => 0x1028,
247 ExecutionCapabilities => 0x1029,
248 QueueOnHostProperties => 0x102A,
249 Name => 0x102B,
250 Vendor => 0x102C,
251 Profile => 0x102E,
252 Version => 0x102F,
253 Extensions => 0x1030,
254 Platform => 0x1031,
255 DoubleFpConfig => 0x1032,
256 HostUnifiedMemory => 0x1035, NativeVectorWidthChar => 0x1036,
258 NativeVectorWidthShort => 0x1037,
259 NativeVectorWidthInt => 0x1038,
260 NativeVectorWidthLong => 0x1039,
261 NativeVectorWidthFloat => 0x103A,
262 NativeVectorWidthDouble => 0x103B,
263 NativeVectorWidthHalf => 0x103C,
264 OpenclCVersion => 0x103D,
265 LinkerAvailable => 0x103E,
266 BuiltInKernels => 0x103F,
267 ImageMaxBufferSize => 0x1040,
268 ImageMaxArraySize => 0x1041,
269 ParentDevice => 0x1042,
270 PartitionMaxSubDevices => 0x1043,
271 PartitionProperties => 0x1044,
272 PartitionAffinityDomain => 0x1045,
273 PartitionType => 0x1046,
274 ReferenceCount => 0x1047,
275 PreferredInteropUserSync => 0x1048,
276 PrintfBufferSize => 0x1049,
277 ImagePitchAlignment => 0x104A,
278 ImageBaseAddressAlignment => 0x104B,
279 MaxReadWriteImageArgs => 0x104C,
280 MaxGlobalVariableSize => 0x104D,
281 QueueOnDeviceProperties => 0x104E,
282 QueueOnDevicePreferredSize => 0x104F,
283 QueueOnDeviceMaxSize => 0x1050,
284 MaxOnDeviceQueues => 0x1051,
285 MaxOnDeviceEvents => 0x1052,
286 SvmCapabilities => 0x1053,
287 GlobalVariablePreferredTotalSize => 0x1054,
288 MaxPipeArgs => 0x1055,
289 PipeMaxActiveReservations => 0x1056,
290 PipeMaxPacketSize => 0x1057,
291 PreferredPlatformAtomicAlignment => 0x1058,
292 PreferredGlobalAtomicAlignment => 0x1059,
293 PreferredLocalAtomicAlignment => 0x105A,
294 IlVersion => 0x105B,
295 MaxNumSubGroups => 0x105C,
296 SubGroupIndependentForwardProgress => 0x105D,
297 HalfFpConfig => 0x1033,
298 DriverVersion => 0x102D
299});
300
301__cl_enum!(DeviceLocalMemType, cl_device_local_mem_type, {
302 Local => 0x1,
303 Global => 0x2
304});
305
306__cl_enum!(DeviceMemCacheType, cl_device_mem_cache_type, {
307 NoneType => 0x0,
308 ReadOnlyCache => 0x1,
309 ReadWriteCache => 0x2
310});
311
312__cl_enum!(DevicePartitionProperty, cl_device_partition_property, {
313 Equally => 0x1086,
314 ByCounts => 0x1087,
315 ByAffinityDomain => 0x1088
319});
320
321__cl_enum!(ContextInfo, cl_context_info, {
322 ReferenceCount => 0x1080,
323 Devices => 0x1081,
324 Properties => 0x1082,
325 NumDevices => 0x1083
326});
327
328__cl_enum!(ContextProperties, cl_context_properties, {
329 Platform => 0x1084,
330 InteropUserSync => 0x1085
331});
332
333__cl_enum!(ProgramBuildInfo, cl_program_build_info, {
334 Status => 0x1181,
335 Options => 0x1182,
336 Log => 0x1183,
337 GlobalVariableTotalSize => 0x1185
340});
341
342__cl_enum!(ProgramInfo, cl_program_info, {
343 ReferenceCount => 0x1160,
344 Context => 0x1161,
345 NumDevices => 0x1162,
346 Devices => 0x1163,
347 Source => 0x1164,
348 BinarySizes => 0x1165,
349 Binaries => 0x1166,
350 NumKernels => 0x1167,
351 KernelNames => 0x1168
352 });
357
358__cl_enum!(BuildStatus, cl_build_status, {
360 Success => 0,
361 NoneType => -1,
362 Error => -2,
363 InProgress => -3
364});
365
366__cl_enum!(ProgramBinaryType, cl_program_binary_type, {
368 NoneType => 0x0,
369 CompiledObject => 0x1,
370 Library => 0x2,
371 Executable => 0x4
372});
373
374__cl_enum!(MemMigrationFlags, cl_mem_migration_flags, {
375 Host => 1,
376 ContentUndefined => (1 << 1)
377});
378
379__cl_enum!(MemObjectType, cl_mem_object_type, {
380 Buffer => 0x10F0,
381 Image2D => 0x10F1,
382 Image3D => 0x10F2,
383 Image2DArray => 0x10F3,
384 Image1D => 0x10F4,
385 Image1DArray => 0x10F5,
386 Image1DBuffer => 0x10F6,
387 Pipe => 0x10F7
388});
389
390__cl_enum!(MemInfo, cl_mem_info, {
391 Type => 0x1100,
392 Flags => 0x1101,
393 Size => 0x1102,
394 HostPtr => 0x1103,
395 MapCount => 0x1104,
396 ReferenceCount => 0x1105,
397 Context => 0x1106,
398 AssociatedMemobject => 0x1107,
399 Offset => 0x1108
400
401 });
404
405__cl_enum!(BufferCreateType, cl_buffer_create_type, {
406 CreateTypeRegion => 0x1220
408});
409
410__cl_enum!(KernelInfo, cl_kernel_info, {
411 FunctionName => 0x1190,
412 NumArgs => 0x1191,
413 ReferenceCount => 0x1192,
414 Context => 0x1193,
415 Program => 0x1194,
416 Attributes => 0x1195
417 });
421
422__cl_enum!(KernelWorkGroupInfo, cl_kernel_work_group_info, {
423 WorkGroupSize => 0x11B0,
424 CompileWorkGroupSize => 0x11B1,
425 LocalMemSize => 0x11B2,
426 PreferredWorkGroupSizeMultiple => 0x11B3,
427 PrivateMemSize => 0x11B4,
428 GlobalWorkSize => 0x11B5
429});
430
431__cl_enum!(KernelArgAccessQualifier, cl_kernel_arg_access_qualifier, {
432 ReadOnly => 0x11A0,
433 WriteOnly => 0x11A1,
434 ReadWrite => 0x11A2,
435 NoneType => 0x11A3
436});
437
438__cl_enum!(KernelArgTypeQualifier, cl_kernel_arg_type_qualifier, {
439 NoneType => 0,
440 Const => 1,
441 Restrict => 2,
442 Volatile => 4,
443 Pipe => 8
444});
445
446__cl_enum!(KernelArgAddressQualifier, cl_kernel_arg_address_qualifier, {
447 Global => 0x119B,
448 Local => 0x119C,
449 Constant => 0x119D,
450 Private => 0x119E
451});
452
453__cl_enum!(KernelArgInfo, cl_kernel_arg_info, {
454 AddressQualifier => 0x1196,
455 AccessQualifier => 0x1197,
456 TypeName => 0x1198,
457 TypeQualifier => 0x1199,
458 Name => 0x119A
459});
460
461__cl_enum!(CommandQueueInfo, cl_command_queue_info, {
462 Context => 0x1090,
463 Device => 0x1091,
464 ReferenceCount => 0x1092,
465 Properties => 0x1093
466
467 });
473
474__cl_enum!(CommandExecutionStatus, cl_int, {
475 Complete => 0x0,
476 Running => 0x1,
477 Submitted => 0x2,
478 Queued => 0x3
479});
480
481__cl_enum!(CommandType, cl_command_type, {
483 NdrangeKernel => 0x11F0,
484 Task => 0x11F1,
485 NativeKernel => 0x11F2,
486 ReadBuffer => 0x11F3,
487 WriteBuffer => 0x11F4,
488 CopyBuffer => 0x11F5,
489 ReadImage => 0x11F6,
490 WriteImage => 0x11F7,
491 CopyImage => 0x11F8,
492 CopyImageToBuffer => 0x11F9,
493 CopyBufferToImage => 0x11FA,
494 MapBuffer => 0x11FB,
495 MapImage => 0x11FC,
496 UnmapMemObject => 0x11FD,
497 Marker => 0x11FE,
498 AcquireGlObjects => 0x11FF,
499 ReleaseGlObjects => 0x1200,
500 ReadBufferRect => 0x1201,
501 WriteBufferRect => 0x1202,
502 CopyBufferRect => 0x1203,
503 User => 0x1204,
504 Barrier => 0x1205,
505 MigrateMemObjects => 0x1206,
506 FillBuffer => 0x1207,
507 FillImage => 0x1208,
508 SvmFree => 0x1209,
509 SvmMemcpy => 0x120A,
510 SvmMemfill => 0x120B,
511 SvmMap => 0x120C,
512 SvmUnmap => 0x120D
513});
514
515__cl_enum!(EventInfo, cl_event_info, {
516 CommandQueue => 0x11D0,
517 CommandType => 0x11D1,
518 ReferenceCount => 0x11D2,
519 CommandExecutionStatus => 0x11D3,
520 Context => 0x11D4
521});
522
523__cl_enum!(ProfilingInfo, cl_profiling_info, {
524 Queued => 0x1280,
525 Submit => 0x1281,
526 Start => 0x1282,
527 End => 0x1283,
528 Complete => 0x1284
529});
530
531