Skip to main content

apple_mps/ffi/
mod.rs

1//! Raw FFI declarations matching the Swift bridge.
2
3#![allow(missing_docs)]
4
5use core::ffi::c_void;
6
7extern "C" {
8    pub fn mps_object_release(handle: *mut c_void);
9
10    pub fn mps_image_new_with_descriptor(
11        device_handle: *mut c_void,
12        channel_format: usize,
13        width: usize,
14        height: usize,
15        feature_channels: usize,
16        number_of_images: usize,
17        usage: usize,
18        storage_mode: usize,
19    ) -> *mut c_void;
20    pub fn mps_image_new_with_texture(
21        texture_handle: *mut c_void,
22        feature_channels: usize,
23    ) -> *mut c_void;
24    pub fn mps_image_width(handle: *mut c_void) -> usize;
25    pub fn mps_image_height(handle: *mut c_void) -> usize;
26    pub fn mps_image_feature_channels(handle: *mut c_void) -> usize;
27    pub fn mps_image_number_of_images(handle: *mut c_void) -> usize;
28    pub fn mps_image_pixel_size(handle: *mut c_void) -> usize;
29    pub fn mps_image_pixel_format(handle: *mut c_void) -> usize;
30    pub fn mps_image_read_bytes(
31        handle: *mut c_void,
32        data: *mut c_void,
33        data_layout: usize,
34        bytes_per_row: usize,
35        x: usize,
36        y: usize,
37        z: usize,
38        width: usize,
39        height: usize,
40        depth: usize,
41        feature_channel_offset: usize,
42        feature_channel_count: usize,
43        image_index: usize,
44    ) -> bool;
45    pub fn mps_image_write_bytes(
46        handle: *mut c_void,
47        data: *const c_void,
48        data_layout: usize,
49        bytes_per_row: usize,
50        x: usize,
51        y: usize,
52        z: usize,
53        width: usize,
54        height: usize,
55        depth: usize,
56        feature_channel_offset: usize,
57        feature_channel_count: usize,
58        image_index: usize,
59    ) -> bool;
60
61    pub fn mps_unary_encode_image(
62        kernel_handle: *mut c_void,
63        command_buffer_handle: *mut c_void,
64        source_handle: *mut c_void,
65        destination_handle: *mut c_void,
66    );
67    pub fn mps_unary_encode_texture(
68        kernel_handle: *mut c_void,
69        command_buffer_handle: *mut c_void,
70        source_texture_handle: *mut c_void,
71        destination_texture_handle: *mut c_void,
72    );
73    pub fn mps_unary_set_edge_mode(kernel_handle: *mut c_void, edge_mode: usize);
74    pub fn mps_unary_set_clip_rect(
75        kernel_handle: *mut c_void,
76        x: usize,
77        y: usize,
78        z: usize,
79        width: usize,
80        height: usize,
81        depth: usize,
82    );
83    pub fn mps_image_scale_set_transform(
84        kernel_handle: *mut c_void,
85        scale_x: f64,
86        scale_y: f64,
87        translate_x: f64,
88        translate_y: f64,
89    );
90
91    pub fn mps_binary_encode_image(
92        kernel_handle: *mut c_void,
93        command_buffer_handle: *mut c_void,
94        primary_handle: *mut c_void,
95        secondary_handle: *mut c_void,
96        destination_handle: *mut c_void,
97    );
98    pub fn mps_binary_encode_texture(
99        kernel_handle: *mut c_void,
100        command_buffer_handle: *mut c_void,
101        primary_texture_handle: *mut c_void,
102        secondary_texture_handle: *mut c_void,
103        destination_texture_handle: *mut c_void,
104    );
105    pub fn mps_binary_set_primary_edge_mode(kernel_handle: *mut c_void, edge_mode: usize);
106    pub fn mps_binary_set_secondary_edge_mode(kernel_handle: *mut c_void, edge_mode: usize);
107    pub fn mps_binary_set_clip_rect(
108        kernel_handle: *mut c_void,
109        x: usize,
110        y: usize,
111        z: usize,
112        width: usize,
113        height: usize,
114        depth: usize,
115    );
116    pub fn mps_image_arithmetic_set_scales_bias(
117        kernel_handle: *mut c_void,
118        primary_scale: f32,
119        secondary_scale: f32,
120        bias: f32,
121    );
122    pub fn mps_image_arithmetic_set_clamp(
123        kernel_handle: *mut c_void,
124        minimum_value: f32,
125        maximum_value: f32,
126    );
127
128    pub fn mps_image_gaussian_blur_new(device_handle: *mut c_void, sigma: f32) -> *mut c_void;
129    pub fn mps_image_box_new(
130        device_handle: *mut c_void,
131        kernel_width: usize,
132        kernel_height: usize,
133    ) -> *mut c_void;
134    pub fn mps_image_sobel_new(device_handle: *mut c_void, transform: *const f32) -> *mut c_void;
135    pub fn mps_image_median_new(device_handle: *mut c_void, kernel_diameter: usize) -> *mut c_void;
136    pub fn mps_image_convolution_new(
137        device_handle: *mut c_void,
138        kernel_width: usize,
139        kernel_height: usize,
140        weights: *const f32,
141    ) -> *mut c_void;
142    pub fn mps_image_bilinear_scale_new(device_handle: *mut c_void) -> *mut c_void;
143    pub fn mps_image_lanczos_scale_new(device_handle: *mut c_void) -> *mut c_void;
144    pub fn mps_image_threshold_binary_new(
145        device_handle: *mut c_void,
146        threshold_value: f32,
147        maximum_value: f32,
148        transform: *const f32,
149    ) -> *mut c_void;
150    pub fn mps_image_histogram_new(
151        device_handle: *mut c_void,
152        number_of_entries: usize,
153        histogram_for_alpha: bool,
154        min_values: *const f32,
155        max_values: *const f32,
156    ) -> *mut c_void;
157    pub fn mps_image_histogram_encode_image(
158        histogram_handle: *mut c_void,
159        command_buffer_handle: *mut c_void,
160        source_handle: *mut c_void,
161        histogram_buffer_handle: *mut c_void,
162        histogram_offset: usize,
163    );
164    pub fn mps_image_histogram_encode_texture(
165        histogram_handle: *mut c_void,
166        command_buffer_handle: *mut c_void,
167        source_texture_handle: *mut c_void,
168        histogram_buffer_handle: *mut c_void,
169        histogram_offset: usize,
170    );
171    pub fn mps_image_histogram_size_for_source_format(
172        histogram_handle: *mut c_void,
173        source_format: usize,
174    ) -> usize;
175    pub fn mps_image_statistics_min_max_new(device_handle: *mut c_void) -> *mut c_void;
176    pub fn mps_image_statistics_mean_new(device_handle: *mut c_void) -> *mut c_void;
177    pub fn mps_image_reduce_row_min_new(device_handle: *mut c_void) -> *mut c_void;
178    pub fn mps_image_reduce_row_max_new(device_handle: *mut c_void) -> *mut c_void;
179    pub fn mps_image_reduce_row_mean_new(device_handle: *mut c_void) -> *mut c_void;
180    pub fn mps_image_reduce_row_sum_new(device_handle: *mut c_void) -> *mut c_void;
181    pub fn mps_image_add_new(device_handle: *mut c_void) -> *mut c_void;
182
183    pub fn mps_matrix_descriptor_row_bytes_for_columns(columns: usize, data_type: u32) -> usize;
184    pub fn mps_vector_descriptor_vector_bytes_for_length(length: usize, data_type: u32) -> usize;
185    pub fn mps_matrix_new_with_buffer(
186        buffer_handle: *mut c_void,
187        rows: usize,
188        columns: usize,
189        matrices: usize,
190        row_bytes: usize,
191        matrix_bytes: usize,
192        data_type: u32,
193    ) -> *mut c_void;
194    pub fn mps_matrix_rows(handle: *mut c_void) -> usize;
195    pub fn mps_matrix_columns(handle: *mut c_void) -> usize;
196    pub fn mps_matrix_matrices(handle: *mut c_void) -> usize;
197    pub fn mps_matrix_row_bytes(handle: *mut c_void) -> usize;
198    pub fn mps_matrix_matrix_bytes(handle: *mut c_void) -> usize;
199    pub fn mps_matrix_data_type(handle: *mut c_void) -> u32;
200
201    pub fn mps_vector_new_with_buffer(
202        buffer_handle: *mut c_void,
203        length: usize,
204        vectors: usize,
205        vector_bytes: usize,
206        data_type: u32,
207    ) -> *mut c_void;
208    pub fn mps_vector_length(handle: *mut c_void) -> usize;
209    pub fn mps_vector_vectors(handle: *mut c_void) -> usize;
210    pub fn mps_vector_vector_bytes(handle: *mut c_void) -> usize;
211    pub fn mps_vector_data_type(handle: *mut c_void) -> u32;
212
213    pub fn mps_matrix_multiplication_new(
214        device_handle: *mut c_void,
215        transpose_left: bool,
216        transpose_right: bool,
217        result_rows: usize,
218        result_columns: usize,
219        interior_columns: usize,
220        alpha: f64,
221        beta: f64,
222    ) -> *mut c_void;
223    pub fn mps_matrix_multiplication_encode(
224        handle: *mut c_void,
225        command_buffer_handle: *mut c_void,
226        left_matrix_handle: *mut c_void,
227        right_matrix_handle: *mut c_void,
228        result_matrix_handle: *mut c_void,
229    );
230}