Debian Codegraph @

third_party/rust/metal/src/encoder.rs

raw
1 // Copyright 2017 GFX developers
2 //
3 // Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4 // http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5 // http://opensource.org/licenses/MIT>, at your option. This file may not be
6 // copied, modified, or distributed except according to those terms.
7
8 use super::*;
9
10 use std::ops::Range;
11
12 /// See <https://developer.apple.com/documentation/metal/mtlcounterdontsample>
13 pub const COUNTER_DONT_SAMPLE: NSUInteger = NSUInteger::MAX; // #define MTLCounterDontSample ((NSUInteger)-1)
14
15 /// See <https://developer.apple.com/documentation/metal/mtlprimitivetype>
16 #[repr(u64)]
17 #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
18 pub enum MTLPrimitiveType {
19 Point = 0,
20 Line = 1,
21 LineStrip = 2,
22 Triangle = 3,
23 TriangleStrip = 4,
24 }
25
26 /// See <https://developer.apple.com/documentation/metal/mtlindextype>
27 #[repr(u64)]
28 #[allow(non_camel_case_types)]
29 #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
30 pub enum MTLIndexType {
31 UInt16 = 0,
32 UInt32 = 1,
33 }
34
35 /// See <https://developer.apple.com/documentation/metal/mtlvisibilityresultmode>
36 #[repr(u64)]
37 #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
38 pub enum MTLVisibilityResultMode {
39 Disabled = 0,
40 Boolean = 1,
41 Counting = 2,
42 }
43
44 /// See <https://developer.apple.com/documentation/metal/mtlcullmode>
45 #[repr(u64)]
46 #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
47 pub enum MTLCullMode {
48 None = 0,
49 Front = 1,
50 Back = 2,
51 }
52
53 /// See <https://developer.apple.com/documentation/metal/mtlwinding>
54 #[repr(u64)]
55 #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
56 pub enum MTLWinding {
57 Clockwise = 0,
58 CounterClockwise = 1,
59 }
60
61 /// See <https://developer.apple.com/documentation/metal/mtldepthclipmode>
62 #[repr(u64)]
63 #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
64 pub enum MTLDepthClipMode {
65 Clip = 0,
66 Clamp = 1,
67 }
68
69 /// See <https://developer.apple.com/documentation/metal/mtltrianglefillmode>
70 #[repr(u64)]
71 #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
72 pub enum MTLTriangleFillMode {
73 Fill = 0,
74 Lines = 1,
75 }
76
77 bitflags::bitflags! {
78 /// https://developer.apple.com/documentation/metal/mtlblitoption
79 #[allow(non_upper_case_globals)]
80 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
81 pub struct MTLBlitOption: NSUInteger {
82 /// https://developer.apple.com/documentation/metal/mtlblitoption/mtlblitoptionnone
83 const None = 0;
84 /// https://developer.apple.com/documentation/metal/mtlblitoption/mtlblitoptiondepthfromdepthstencil
85 const DepthFromDepthStencil = 1 << 0;
86 /// https://developer.apple.com/documentation/metal/mtlblitoption/mtlblitoptionstencilfromdepthstencil
87 const StencilFromDepthStencil = 1 << 1;
88 /// https://developer.apple.com/documentation/metal/mtlblitoption/mtlblitoptionrowlinearpvrtc
89 const RowLinearPVRTC = 1 << 2;
90 }
91 }
92
93 /// See <https://developer.apple.com/documentation/metal/mtlscissorrect>
94 #[repr(C)]
95 #[derive(Copy, Clone, Debug)]
96 pub struct MTLScissorRect {
97 pub x: NSUInteger,
98 pub y: NSUInteger,
99 pub width: NSUInteger,
100 pub height: NSUInteger,
101 }
102
103 /// See <https://developer.apple.com/documentation/metal/mtlviewport>
104 #[repr(C)]
105 #[derive(Copy, Clone, Debug)]
106 pub struct MTLViewport {
107 pub originX: f64,
108 pub originY: f64,
109 pub width: f64,
110 pub height: f64,
111 pub znear: f64,
112 pub zfar: f64,
113 }
114
115 /// See <https://developer.apple.com/documentation/metal/mtldrawprimitivesindirectarguments>
116 #[repr(C)]
117 #[derive(Copy, Clone, Debug)]
118 pub struct MTLDrawPrimitivesIndirectArguments {
119 pub vertexCount: u32,
120 pub instanceCount: u32,
121 pub vertexStart: u32,
122 pub baseInstance: u32,
123 }
124
125 /// See <https://developer.apple.com/documentation/metal/mtldrawindexedprimitivesindirectarguments>
126 #[repr(C)]
127 #[derive(Copy, Clone, Debug)]
128 pub struct MTLDrawIndexedPrimitivesIndirectArguments {
129 pub indexCount: u32,
130 pub instanceCount: u32,
131 pub indexStart: u32,
132 pub baseVertex: i32,
133 pub baseInstance: u32,
134 }
135
136 /// See <https://developer.apple.com/documentation/metal/mtlvertexamplificationviewmapping>
137 #[repr(C)]
138 #[derive(Copy, Clone, Debug)]
139 pub struct VertexAmplificationViewMapping {
140 pub renderTargetArrayIndexOffset: u32,
141 pub viewportArrayIndexOffset: u32,
142 }
143
144 #[allow(dead_code)]
145 type MTLVertexAmplicationViewMapping = VertexAmplificationViewMapping;
146
147 /// See <https://developer.apple.com/documentation/metal/mtlcommandencoder>
148 pub enum MTLCommandEncoder {}
149
150 foreign_obj_type! {
151 type CType = MTLCommandEncoder;
152 pub struct CommandEncoder;
153 }
154
155 impl CommandEncoderRef {
156 pub fn label(&self) -> &str {
157 unsafe {
158 let label = msg_send![self, label];
159 crate::nsstring_as_str(label)
160 }
161 }
162
163 pub fn set_label(&self, label: &str) {
164 unsafe {
165 let nslabel = crate::nsstring_from_str(label);
166 msg_send![self, setLabel: nslabel]
167 }
168 }
169
170 pub fn end_encoding(&self) {
171 unsafe { msg_send![self, endEncoding] }
172 }
173
174 pub fn insert_debug_signpost(&self, name: &str) {
175 unsafe {
176 let nslabel = crate::nsstring_from_str(name);
177 msg_send![self, insertDebugSignpost: nslabel]
178 }
179 }
180
181 pub fn push_debug_group(&self, name: &str) {
182 unsafe {
183 let nslabel = crate::nsstring_from_str(name);
184 msg_send![self, pushDebugGroup: nslabel]
185 }
186 }
187
188 pub fn pop_debug_group(&self) {
189 unsafe { msg_send![self, popDebugGroup] }
190 }
191 }
192
193 /// See <https://developer.apple.com/documentation/metal/mtlparallelrendercommandencoder>
194 pub enum MTLParallelRenderCommandEncoder {}
195
196 foreign_obj_type! {
197 type CType = MTLParallelRenderCommandEncoder;
198 pub struct ParallelRenderCommandEncoder;
199 type ParentType = CommandEncoder;
200 }
201
202 impl ParallelRenderCommandEncoderRef {
203 pub fn render_command_encoder(&self) -> &RenderCommandEncoderRef {
204 unsafe { msg_send![self, renderCommandEncoder] }
205 }
206 }
207
208 /// See <https://developer.apple.com/documentation/metal/mtlrendercommandencoder/>
209 pub enum MTLRenderCommandEncoder {}
210
211 foreign_obj_type! {
212 type CType = MTLRenderCommandEncoder;
213 pub struct RenderCommandEncoder;
214 type ParentType = CommandEncoder;
215 }
216
217 impl RenderCommandEncoderRef {
218 pub fn set_render_pipeline_state(&self, pipeline_state: &RenderPipelineStateRef) {
219 unsafe { msg_send![self, setRenderPipelineState: pipeline_state] }
220 }
221
222 pub fn set_viewport(&self, viewport: MTLViewport) {
223 unsafe { msg_send![self, setViewport: viewport] }
224 }
225
226 pub fn set_front_facing_winding(&self, winding: MTLWinding) {
227 unsafe { msg_send![self, setFrontFacingWinding: winding] }
228 }
229
230 pub fn set_cull_mode(&self, mode: MTLCullMode) {
231 unsafe { msg_send![self, setCullMode: mode] }
232 }
233
234 pub fn set_depth_clip_mode(&self, mode: MTLDepthClipMode) {
235 unsafe { msg_send![self, setDepthClipMode: mode] }
236 }
237
238 pub fn set_depth_bias(&self, bias: f32, scale: f32, clamp: f32) {
239 unsafe {
240 msg_send![self, setDepthBias:bias
241 slopeScale:scale
242 clamp:clamp]
243 }
244 }
245
246 pub fn set_scissor_rect(&self, rect: MTLScissorRect) {
247 unsafe { msg_send![self, setScissorRect: rect] }
248 }
249
250 pub fn set_triangle_fill_mode(&self, mode: MTLTriangleFillMode) {
251 unsafe { msg_send![self, setTriangleFillMode: mode] }
252 }
253
254 pub fn set_blend_color(&self, red: f32, green: f32, blue: f32, alpha: f32) {
255 unsafe {
256 msg_send![self, setBlendColorRed:red
257 green:green
258 blue:blue
259 alpha:alpha]
260 }
261 }
262
263 pub fn set_depth_stencil_state(&self, depth_stencil_state: &DepthStencilStateRef) {
264 unsafe { msg_send![self, setDepthStencilState: depth_stencil_state] }
265 }
266
267 pub fn set_stencil_reference_value(&self, value: u32) {
268 unsafe { msg_send![self, setStencilReferenceValue: value] }
269 }
270
271 pub fn set_stencil_front_back_reference_value(&self, front: u32, back: u32) {
272 unsafe {
273 msg_send![self, setStencilFrontReferenceValue:front
274 backReferenceValue:back]
275 }
276 }
277
278 pub fn set_visibility_result_mode(&self, mode: MTLVisibilityResultMode, offset: NSUInteger) {
279 unsafe {
280 msg_send![self, setVisibilityResultMode:mode
281 offset:offset]
282 }
283 }
284
285 pub fn set_vertex_amplification_count(
286 &self,
287 count: NSUInteger,
288 view_mappings: Option<&[VertexAmplificationViewMapping]>,
289 ) {
290 unsafe {
291 msg_send! [self, setVertexAmplificationCount: count viewMappings: view_mappings.map_or(std::ptr::null(), |vm| vm.as_ptr())]
292 }
293 }
294
295 // Specifying Resources for a Vertex Shader Function
296
297 pub fn set_vertex_bytes(
298 &self,
299 index: NSUInteger,
300 length: NSUInteger,
301 bytes: *const std::ffi::c_void,
302 ) {
303 unsafe {
304 msg_send![self,
305 setVertexBytes:bytes
306 length:length
307 atIndex:index
308 ]
309 }
310 }
311
312 pub fn set_vertex_buffer(
313 &self,
314 index: NSUInteger,
315 buffer: Option<&BufferRef>,
316 offset: NSUInteger,
317 ) {
318 unsafe {
319 msg_send![self,
320 setVertexBuffer:buffer
321 offset:offset
322 atIndex:index
323 ]
324 }
325 }
326
327 pub fn set_vertex_buffer_offset(&self, index: NSUInteger, offset: NSUInteger) {
328 unsafe {
329 msg_send![self,
330 setVertexBufferOffset:offset
331 atIndex:index
332 ]
333 }
334 }
335
336 pub fn set_vertex_buffers(
337 &self,
338 start_index: NSUInteger,
339 data: &[Option<&BufferRef>],
340 offsets: &[NSUInteger],
341 ) {
342 debug_assert_eq!(offsets.len(), data.len());
343 unsafe {
344 msg_send![self,
345 setVertexBuffers: data.as_ptr()
346 offsets: offsets.as_ptr()
347 withRange: NSRange {
348 location: start_index,
349 length: data.len() as _,
350 }
351 ]
352 }
353 }
354
355 pub fn set_vertex_texture(&self, index: NSUInteger, texture: Option<&TextureRef>) {
356 unsafe {
357 msg_send![self,
358 setVertexTexture:texture
359 atIndex:index
360 ]
361 }
362 }
363
364 pub fn set_vertex_textures(&self, start_index: NSUInteger, data: &[Option<&TextureRef>]) {
365 unsafe {
366 msg_send![self,
367 setVertexTextures: data.as_ptr()
368 withRange: NSRange {
369 location: start_index,
370 length: data.len() as _,
371 }
372 ]
373 }
374 }
375
376 pub fn set_vertex_sampler_state(&self, index: NSUInteger, sampler: Option<&SamplerStateRef>) {
377 unsafe {
378 msg_send![self,
379 setVertexSamplerState:sampler
380 atIndex:index
381 ]
382 }
383 }
384
385 pub fn set_vertex_sampler_states(
386 &self,
387 start_index: NSUInteger,
388 data: &[Option<&SamplerStateRef>],
389 ) {
390 unsafe {
391 msg_send![self,
392 setVertexSamplerStates: data.as_ptr()
393 withRange: NSRange {
394 location: start_index,
395 length: data.len() as _,
396 }
397 ]
398 }
399 }
400
401 pub fn set_vertex_sampler_state_with_lod(
402 &self,
403 index: NSUInteger,
404 sampler: Option<&SamplerStateRef>,
405 lod_clamp: Range<f32>,
406 ) {
407 unsafe {
408 msg_send![self,
409 setVertexSamplerState:sampler
410 lodMinClamp:lod_clamp.start
411 lodMaxClamp:lod_clamp.end
412 atIndex:index
413 ]
414 }
415 }
416
417 /// Only available in (macos(12.0), ios(15.0))
418 pub fn set_vertex_acceleration_structure(
419 &self,
420 index: NSUInteger,
421 accel: Option<&AccelerationStructureRef>,
422 ) {
423 unsafe {
424 msg_send![
425 self,
426 setVertexAccelerationStructure: accel
427 atBufferIndex: index
428 ]
429 }
430 }
431
432 /// Only available in (macos(12.0), ios(15.0))
433 pub fn set_vertex_intersection_function_table(
434 &self,
435 index: NSUInteger,
436 table: Option<&IntersectionFunctionTableRef>,
437 ) {
438 unsafe {
439 msg_send![
440 self,
441 setVertexIntersectionFunctionTable: table
442 atBufferIndex: index
443 ]
444 }
445 }
446
447 pub fn set_vertex_visible_function_table(
448 &self,
449 buffer_index: NSUInteger,
450 visible_function_table: Option<&VisibleFunctionTableRef>,
451 ) {
452 unsafe {
453 msg_send![self,
454 setVertexVisibleFunctionTable:visible_function_table
455 atBufferIndex:buffer_index]
456 }
457 }
458
459 pub fn set_vertex_visible_function_tables(
460 &self,
461 buffer_start_index: NSUInteger,
462 visible_function_tables: &[&VisibleFunctionTableRef],
463 ) {
464 unsafe {
465 msg_send![self,
466 setVertexVisibleFunctionTables:visible_function_tables.as_ptr()
467 withBufferRange: NSRange {
468 location: buffer_start_index,
469 length: visible_function_tables.len() as _,
470 }
471 ]
472 }
473 }
474
475 // Specifying Resources for a Object Shader Function
476
477 /// Only available in (macos(13.0), ios(16.0))
478 pub fn set_object_buffer(
479 &self,
480 index: NSUInteger,
481 buffer: Option<&BufferRef>,
482 offset: NSUInteger,
483 ) {
484 unsafe {
485 msg_send![self,
486 setObjectBuffer:buffer
487 offset:offset
488 atIndex:index
489 ]
490 }
491 }
492
493 /// Only available in (macos(13.0), ios(16.0))
494 pub fn set_object_buffer_offset(&self, index: NSUInteger, offset: NSUInteger) {
495 unsafe {
496 msg_send![self,
497 setObjectBufferOffset:offset
498 atIndex:index
499 ]
500 }
501 }
502
503 /// Only available in (macos(13.0), ios(16.0))
504 pub fn set_object_bytes(
505 &self,
506 index: NSUInteger,
507 length: NSUInteger,
508 bytes: *const std::ffi::c_void,
509 ) {
510 unsafe {
511 msg_send![self,
512 setObjectBytes:bytes
513 length:length
514 atIndex:index
515 ]
516 }
517 }
518
519 /// Only available in (macos(13.0), ios(16.0))
520 pub fn set_object_sampler_state(&self, index: NSUInteger, sampler: Option<&SamplerStateRef>) {
521 unsafe {
522 msg_send![self,
523 setObjectSamplerState:sampler
524 atIndex:index
525 ]
526 }
527 }
528
529 /// Only available in (macos(13.0), ios(16.0))
530 pub fn set_object_sampler_state_with_lod(
531 &self,
532 index: NSUInteger,
533 sampler: Option<&SamplerStateRef>,
534 lod_clamp: Range<f32>,
535 ) {
536 unsafe {
537 msg_send![self,
538 setObjectSamplerState:sampler
539 lodMinClamp:lod_clamp.start
540 lodMaxClamp:lod_clamp.end
541 atIndex:index
542 ]
543 }
544 }
545
546 /// Only available in (macos(13.0), ios(16.0))
547 pub fn set_object_texture(&self, index: NSUInteger, texture: Option<&TextureRef>) {
548 unsafe {
549 msg_send![self,
550 setObjectTexture:texture
551 atIndex:index
552 ]
553 }
554 }
555
556 /// Only available in (macos(13.0), ios(16.0))
557 pub fn set_object_threadgroup_memory_length(&self, index: NSUInteger, length: NSUInteger) {
558 unsafe {
559 msg_send![self,
560 setObjectThreadgroupMemoryLength: length
561 atIndex: index
562 ]
563 }
564 }
565
566 /// Only available in (macos(13.0), ios(16.0))
567 pub fn set_object_buffers(
568 &self,
569 start_index: NSUInteger,
570 data: &[Option<&BufferRef>],
571 offsets: &[NSUInteger],
572 ) {
573 debug_assert_eq!(offsets.len(), data.len());
574 unsafe {
575 msg_send![self,
576 setObjectBuffers: data.as_ptr()
577 offsets: offsets.as_ptr()
578 withRange: NSRange {
579 location: start_index,
580 length: data.len() as _,
581 }
582 ]
583 }
584 }
585
586 /// Only available in (macos(13.0), ios(16.0))
587 pub fn set_object_sampler_states(
588 &self,
589 start_index: NSUInteger,
590 data: &[Option<&SamplerStateRef>],
591 ) {
592 unsafe {
593 msg_send![self,
594 setObjectSamplerStates: data.as_ptr()
595 withRange: NSRange {
596 location: start_index,
597 length: data.len() as _,
598 }
599 ]
600 }
601 }
602
603 /// Only available in (macos(13.0), ios(16.0))
604 pub fn set_object_textures(&self, start_index: NSUInteger, data: &[Option<&TextureRef>]) {
605 unsafe {
606 msg_send![self,
607 setObjectTextures: data.as_ptr()
608 withRange: NSRange {
609 location: start_index,
610 length: data.len() as _,
611 }
612 ]
613 }
614 }
615
616 // Specifying Resources for a Mesh Shader
617
618 /// Only available in (macos(13.0), ios(16.0))
619 pub fn set_mesh_buffer(
620 &self,
621 index: NSUInteger,
622 buffer: Option<&BufferRef>,
623 offset: NSUInteger,
624 ) {
625 unsafe {
626 msg_send![self,
627 setMeshBuffer:buffer
628 offset:offset
629 atIndex:index
630 ]
631 }
632 }
633
634 /// Only available in (macos(13.0), ios(16.0))
635 pub fn set_mesh_buffer_offset(&self, index: NSUInteger, offset: NSUInteger) {
636 unsafe {
637 msg_send![self,
638 setMeshBufferOffset:offset
639 atIndex:index
640 ]
641 }
642 }
643
644 /// Only available in (macos(13.0), ios(16.0))
645 pub fn set_mesh_bytes(
646 &self,
647 index: NSUInteger,
648 length: NSUInteger,
649 bytes: *const std::ffi::c_void,
650 ) {
651 unsafe {
652 msg_send![self,
653 setMeshBytes:bytes
654 length:length
655 atIndex:index
656 ]
657 }
658 }
659
660 /// Only available in (macos(13.0), ios(16.0))
661 pub fn set_mesh_sampler_state(&self, index: NSUInteger, sampler: Option<&SamplerStateRef>) {
662 unsafe {
663 msg_send![self,
664 setMeshSamplerState:sampler
665 atIndex:index
666 ]
667 }
668 }
669
670 /// Only available in (macos(13.0), ios(16.0))
671 pub fn set_mesh_sampler_state_with_lod(
672 &self,
673 index: NSUInteger,
674 sampler: Option<&SamplerStateRef>,
675 lod_clamp: Range<f32>,
676 ) {
677 unsafe {
678 msg_send![self,
679 setMeshSamplerState:sampler
680 lodMinClamp:lod_clamp.start
681 lodMaxClamp:lod_clamp.end
682 atIndex:index
683 ]
684 }
685 }
686
687 /// Only available in (macos(13.0), ios(16.0))
688 pub fn set_mesh_texture(&self, index: NSUInteger, texture: Option<&TextureRef>) {
689 unsafe {
690 msg_send![self,
691 setMeshTexture:texture
692 atIndex:index
693 ]
694 }
695 }
696
697 /// Only available in (macos(13.0), ios(16.0))
698 pub fn set_mesh_buffers(
699 &self,
700 start_index: NSUInteger,
701 data: &[Option<&BufferRef>],
702 offsets: &[NSUInteger],
703 ) {
704 debug_assert_eq!(offsets.len(), data.len());
705 unsafe {
706 msg_send![self,
707 setMeshBuffers: data.as_ptr()
708 offsets: offsets.as_ptr()
709 withRange: NSRange {
710 location: start_index,
711 length: data.len() as _,
712 }
713 ]
714 }
715 }
716
717 /// Only available in (macos(13.0), ios(16.0))
718 pub fn set_mesh_sampler_states(
719 &self,
720 start_index: NSUInteger,
721 data: &[Option<&SamplerStateRef>],
722 ) {
723 unsafe {
724 msg_send![self,
725 setMeshSamplerStates: data.as_ptr()
726 withRange: NSRange {
727 location: start_index,
728 length: data.len() as _,
729 }
730 ]
731 }
732 }
733
734 /// Only available in (macos(13.0), ios(16.0))
735 pub fn set_mesh_textures(&self, start_index: NSUInteger, data: &[Option<&TextureRef>]) {
736 unsafe {
737 msg_send![self,
738 setMeshTextures: data.as_ptr()
739 withRange: NSRange {
740 location: start_index,
741 length: data.len() as _,
742 }
743 ]
744 }
745 }
746
747 // Specifying Resources for a Fragment Shader Function
748
749 pub fn set_fragment_bytes(
750 &self,
751 index: NSUInteger,
752 length: NSUInteger,
753 bytes: *const std::ffi::c_void,
754 ) {
755 unsafe {
756 msg_send![self,
757 setFragmentBytes:bytes
758 length:length
759 atIndex:index
760 ]
761 }
762 }
763
764 pub fn set_fragment_buffer(
765 &self,
766 index: NSUInteger,
767 buffer: Option<&BufferRef>,
768 offset: NSUInteger,
769 ) {
770 unsafe {
771 msg_send![self,
772 setFragmentBuffer:buffer
773 offset:offset
774 atIndex:index
775 ]
776 }
777 }
778
779 pub fn set_fragment_buffer_offset(&self, index: NSUInteger, offset: NSUInteger) {
780 unsafe {
781 msg_send![self,
782 setFragmentBufferOffset:offset
783 atIndex:index
784 ]
785 }
786 }
787
788 pub fn set_fragment_buffers(
789 &self,
790 start_index: NSUInteger,
791 data: &[Option<&BufferRef>],
792 offsets: &[NSUInteger],
793 ) {
794 debug_assert_eq!(offsets.len(), data.len());
795 unsafe {
796 msg_send![self,
797 setFragmentBuffers: data.as_ptr()
798 offsets: offsets.as_ptr()
799 withRange: NSRange {
800 location: start_index,
801 length: data.len() as _,
802 }
803 ]
804 }
805 }
806
807 pub fn set_fragment_texture(&self, index: NSUInteger, texture: Option<&TextureRef>) {
808 unsafe {
809 msg_send![self,
810 setFragmentTexture:texture
811 atIndex:index
812 ]
813 }
814 }
815
816 pub fn set_fragment_textures(&self, start_index: NSUInteger, data: &[Option<&TextureRef>]) {
817 unsafe {
818 msg_send![self,
819 setFragmentTextures: data.as_ptr()
820 withRange: NSRange {
821 location: start_index,
822 length: data.len() as _,
823 }
824 ]
825 }
826 }
827
828 pub fn set_fragment_sampler_state(&self, index: NSUInteger, sampler: Option<&SamplerStateRef>) {
829 unsafe {
830 msg_send![self, setFragmentSamplerState:sampler
831 atIndex:index]
832 }
833 }
834
835 pub fn set_fragment_sampler_states(
836 &self,
837 start_index: NSUInteger,
838 data: &[Option<&SamplerStateRef>],
839 ) {
840 unsafe {
841 msg_send![self,
842 setFragmentSamplerStates: data.as_ptr()
843 withRange: NSRange {
844 location: start_index,
845 length: data.len() as _,
846 }
847 ]
848 }
849 }
850
851 pub fn set_fragment_sampler_state_with_lod(
852 &self,
853 index: NSUInteger,
854 sampler: Option<&SamplerStateRef>,
855 lod_clamp: Range<f32>,
856 ) {
857 unsafe {
858 msg_send![self,
859 setFragmentSamplerState:sampler
860 lodMinClamp:lod_clamp.start
861 lodMaxClamp:lod_clamp.end
862 atIndex:index
863 ]
864 }
865 }
866
867 /// Only available in (macos(12.0), ios(15.0))
868 pub fn set_fragment_acceleration_structure(
869 &self,
870 index: NSUInteger,
871 accel: Option<&AccelerationStructureRef>,
872 ) {
873 unsafe {
874 msg_send![
875 self,
876 setFragmentAccelerationStructure: accel
877 atBufferIndex: index
878 ]
879 }
880 }
881
882 /// Only available in (macos(12.0), ios(15.0))
883 pub fn set_fragment_intersection_function_table(
884 &self,
885 index: NSUInteger,
886 table: Option<&IntersectionFunctionTableRef>,
887 ) {
888 unsafe {
889 msg_send![
890 self,
891 setFragmentIntersectionFunctionTable: table
892 atBufferIndex: index
893 ]
894 }
895 }
896
897 pub fn set_fragment_visible_function_table(
898 &self,
899 buffer_index: NSUInteger,
900 visible_function_table: Option<&VisibleFunctionTableRef>,
901 ) {
902 unsafe {
903 msg_send![self,
904 setFragmentVisibleFunctionTable:visible_function_table
905 atBufferIndex:buffer_index]
906 }
907 }
908
909 pub fn set_fragment_visible_function_tables(
910 &self,
911 buffer_start_index: NSUInteger,
912 visible_function_tables: &[&VisibleFunctionTableRef],
913 ) {
914 unsafe {
915 msg_send![self,
916 setFragmentVisibleFunctionTables:visible_function_tables.as_ptr()
917 withBufferRange: NSRange {
918 location: buffer_start_index,
919 length: visible_function_tables.len() as _,
920 }
921 ]
922 }
923 }
924
925 // Drawing Geometric Primitives
926
927 pub fn draw_primitives(
928 &self,
929 primitive_type: MTLPrimitiveType,
930 vertex_start: NSUInteger,
931 vertex_count: NSUInteger,
932 ) {
933 unsafe {
934 msg_send![self,
935 drawPrimitives: primitive_type
936 vertexStart: vertex_start
937 vertexCount: vertex_count
938 ]
939 }
940 }
941
942 pub fn draw_primitives_instanced(
943 &self,
944 primitive_type: MTLPrimitiveType,
945 vertex_start: NSUInteger,
946 vertex_count: NSUInteger,
947 instance_count: NSUInteger,
948 ) {
949 unsafe {
950 msg_send![self,
951 drawPrimitives: primitive_type
952 vertexStart: vertex_start
953 vertexCount: vertex_count
954 instanceCount: instance_count
955 ]
956 }
957 }
958
959 pub fn draw_primitives_instanced_base_instance(
960 &self,
961 primitive_type: MTLPrimitiveType,
962 vertex_start: NSUInteger,
963 vertex_count: NSUInteger,
964 instance_count: NSUInteger,
965 base_instance: NSUInteger,
966 ) {
967 unsafe {
968 msg_send![self,
969 drawPrimitives: primitive_type
970 vertexStart: vertex_start
971 vertexCount: vertex_count
972 instanceCount: instance_count
973 baseInstance: base_instance
974 ]
975 }
976 }
977
978 pub fn draw_primitives_indirect(
979 &self,
980 primitive_type: MTLPrimitiveType,
981 indirect_buffer: &BufferRef,
982 indirect_buffer_offset: NSUInteger,
983 ) {
984 unsafe {
985 msg_send![self,
986 drawPrimitives: primitive_type
987 indirectBuffer: indirect_buffer
988 indirectBufferOffset: indirect_buffer_offset
989 ]
990 }
991 }
992
993 pub fn draw_indexed_primitives(
994 &self,
995 primitive_type: MTLPrimitiveType,
996 index_count: NSUInteger,
997 index_type: MTLIndexType,
998 index_buffer: &BufferRef,
999 index_buffer_offset: NSUInteger,
1000 ) {
1001 unsafe {
1002 msg_send![self,
1003 drawIndexedPrimitives: primitive_type
1004 indexCount: index_count
1005 indexType: index_type
1006 indexBuffer: index_buffer
1007 indexBufferOffset: index_buffer_offset
1008 ]
1009 }
1010 }
1011
1012 pub fn draw_indexed_primitives_instanced(
1013 &self,
1014 primitive_type: MTLPrimitiveType,
1015 index_count: NSUInteger,
1016 index_type: MTLIndexType,
1017 index_buffer: &BufferRef,
1018 index_buffer_offset: NSUInteger,
1019 instance_count: NSUInteger,
1020 ) {
1021 unsafe {
1022 msg_send![self,
1023 drawIndexedPrimitives: primitive_type
1024 indexCount: index_count
1025 indexType: index_type
1026 indexBuffer: index_buffer
1027 indexBufferOffset: index_buffer_offset
1028 instanceCount: instance_count
1029 ]
1030 }
1031 }
1032
1033 #[allow(clippy::too_many_arguments)]
1034 pub fn draw_indexed_primitives_instanced_base_instance(
1035 &self,
1036 primitive_type: MTLPrimitiveType,
1037 index_count: NSUInteger,
1038 index_type: MTLIndexType,
1039 index_buffer: &BufferRef,
1040 index_buffer_offset: NSUInteger,
1041 instance_count: NSUInteger,
1042 base_vertex: NSInteger,
1043 base_instance: NSUInteger,
1044 ) {
1045 unsafe {
1046 msg_send![self,
1047 drawIndexedPrimitives: primitive_type
1048 indexCount: index_count
1049 indexType: index_type
1050 indexBuffer: index_buffer
1051 indexBufferOffset: index_buffer_offset
1052 instanceCount: instance_count
1053 baseVertex: base_vertex
1054 baseInstance: base_instance
1055 ]
1056 }
1057 }
1058
1059 pub fn draw_indexed_primitives_indirect(
1060 &self,
1061 primitive_type: MTLPrimitiveType,
1062 index_type: MTLIndexType,
1063 index_buffer: &BufferRef,
1064 index_buffer_offset: NSUInteger,
1065 indirect_buffer: &BufferRef,
1066 indirect_buffer_offset: NSUInteger,
1067 ) {
1068 unsafe {
1069 msg_send![self,
1070 drawIndexedPrimitives: primitive_type
1071 indexType: index_type
1072 indexBuffer: index_buffer
1073 indexBufferOffset: index_buffer_offset
1074 indirectBuffer: indirect_buffer
1075 indirectBufferOffset: indirect_buffer_offset
1076 ]
1077 }
1078 }
1079
1080 // TODO: more draws
1081 // fn setVertexBufferOffset_atIndex(self, offset: NSUInteger, index: NSUInteger);
1082 // fn setVertexBuffers_offsets_withRange(self, buffers: *const id, offsets: *const NSUInteger, range: NSRange);
1083 // fn setVertexSamplerStates_lodMinClamps_lodMaxClamps_withRange(self, samplers: *const id, lodMinClamps: *const f32, lodMaxClamps: *const f32, range: NSRange);
1084
1085 /// Only available in (macos(13.0), ios(16.0))
1086 pub fn draw_mesh_threadgroups(
1087 &self,
1088 threadgroups_per_grid: MTLSize,
1089 threads_per_object_threadgroup: MTLSize,
1090 threads_per_mesh_threadgroup: MTLSize,
1091 ) {
1092 unsafe {
1093 msg_send![self,
1094 drawMeshThreadgroups: threadgroups_per_grid
1095 threadsPerObjectThreadgroup: threads_per_object_threadgroup
1096 threadsPerMeshThreadgroup: threads_per_mesh_threadgroup
1097 ]
1098 }
1099 }
1100
1101 /// Only available in (macos(13.0), ios(16.0))
1102 pub fn draw_mesh_threadgroups_with_indirect_buffer(
1103 &self,
1104 indirect_buffer: &BufferRef,
1105 indirect_buffer_offset: NSUInteger,
1106 threads_per_object_threadgroup: MTLSize,
1107 threads_per_mesh_threadgroup: MTLSize,
1108 ) {
1109 unsafe {
1110 msg_send![self,
1111 drawMeshThreadgroupsWithIndirectBuffer: indirect_buffer
1112 indirectBufferOffset: indirect_buffer_offset
1113 threadsPerObjectThreadgroup: threads_per_object_threadgroup
1114 threadsPerMeshThreadgroup: threads_per_mesh_threadgroup
1115 ]
1116 }
1117 }
1118
1119 /// Only available in (macos(13.0), ios(16.0))
1120 pub fn draw_mesh_threads(
1121 &self,
1122 threads_per_grid: MTLSize,
1123 threads_per_object_threadgroup: MTLSize,
1124 threads_per_mesh_threadgroup: MTLSize,
1125 ) {
1126 unsafe {
1127 msg_send![self,
1128 drawMeshThreads: threads_per_grid
1129 threadsPerObjectThreadgroup: threads_per_object_threadgroup
1130 threadsPerMeshThreadgroup: threads_per_mesh_threadgroup
1131 ]
1132 }
1133 }
1134
1135 /// Adds an untracked resource to the render pass.
1136 ///
1137 /// Availability: iOS 11.0+, macOS 10.13+
1138 ///
1139 /// # Arguments
1140 /// * `resource`: A resource within an argument buffer.
1141 /// * `usage`: Options for describing how a graphics function uses the resource.
1142 ///
1143 /// See <https://developer.apple.com/documentation/metal/mtlrendercommandencoder/2866168-useresource?language=objc>
1144 #[deprecated(note = "Use use_resource_at instead")]
1145 pub fn use_resource(&self, resource: &ResourceRef, usage: MTLResourceUsage) {
1146 unsafe {
1147 msg_send![self,
1148 useResource:resource
1149 usage:usage
1150 ]
1151 }
1152 }
1153
1154 /// Adds an untracked resource to the render pass, specifying which render stages need it.
1155 ///
1156 /// Availability: iOS 13.0+, macOS 10.15+
1157 ///
1158 /// # Arguments
1159 /// * `resource`: A resource within an argument buffer.
1160 /// * `usage`: Options for describing how a graphics function uses the resource.
1161 /// * `stages`: The render stages where the resource must be resident.
1162 ///
1163 /// See <https://developer.apple.com/documentation/metal/mtlrendercommandencoder/3043404-useresource>
1164 pub fn use_resource_at(
1165 &self,
1166 resource: &ResourceRef,
1167 usage: MTLResourceUsage,
1168 stages: MTLRenderStages,
1169 ) {
1170 unsafe {
1171 msg_send![self,
1172 useResource: resource
1173 usage: usage
1174 stages: stages
1175 ]
1176 }
1177 }
1178
1179 /// Adds an array of untracked resources to the render pass, specifying which stages need them.
1180 ///
1181 /// When working with color render targets, call this method as late as possible to improve performance.
1182 ///
1183 /// Availability: iOS 13.0+, macOS 10.15+
1184 ///
1185 /// # Arguments
1186 /// * `resources`: A slice of resources within an argument buffer.
1187 /// * `usage`: Options for describing how a graphics function uses the resources.
1188 /// * `stages`: The render stages where the resources must be resident.
1189 pub fn use_resources(
1190 &self,
1191 resources: &[&ResourceRef],
1192 usage: MTLResourceUsage,
1193 stages: MTLRenderStages,
1194 ) {
1195 unsafe {
1196 msg_send![self,
1197 useResources: resources.as_ptr()
1198 count: resources.len() as NSUInteger
1199 usage: usage
1200 stages: stages
1201 ]
1202 }
1203 }
1204
1205 /// Adds the resources in a heap to the render pass.
1206 ///
1207 /// Availability: iOS 11.0+, macOS 10.13+
1208 ///
1209 /// # Arguments:
1210 /// * `heap`: A heap that contains resources within an argument buffer.
1211 ///
1212 /// See <https://developer.apple.com/documentation/metal/mtlrendercommandencoder/2866163-useheap?language=objc>
1213 #[deprecated(note = "Use use_heap_at instead")]
1214 pub fn use_heap(&self, heap: &HeapRef) {
1215 unsafe { msg_send![self, useHeap: heap] }
1216 }
1217
1218 /// Adds the resources in a heap to the render pass, specifying which render stages need them.
1219 ///
1220 /// Availability: iOS 13.0+, macOS 10.15+
1221 ///
1222 /// # Arguments
1223 /// * `heap`: A heap that contains resources within an argument buffer.
1224 /// * `stages`: The render stages where the resources must be resident.
1225 ///
1226 pub fn use_heap_at(&self, heap: &HeapRef, stages: MTLRenderStages) {
1227 unsafe {
1228 msg_send![self,
1229 useHeap: heap
1230 stages: stages
1231 ]
1232 }
1233 }
1234
1235 /// Adds the resources in an array of heaps to the render pass, specifying which render stages need them.
1236 ///
1237 /// Availability: iOS 13.0+, macOS 10.15+
1238 ///
1239 /// # Arguments
1240 ///
1241 /// * `heaps`: A slice of heaps that contains resources within an argument buffer.
1242 /// * `stages`: The render stages where the resources must be resident.
1243 pub fn use_heaps(&self, heaps: &[&HeapRef], stages: MTLRenderStages) {
1244 unsafe {
1245 msg_send![self,
1246 useHeaps: heaps.as_ptr()
1247 count: heaps.len() as NSUInteger
1248 stages: stages
1249 ]
1250 }
1251 }
1252
1253 pub fn execute_commands_in_buffer(
1254 &self,
1255 buffer: &IndirectCommandBufferRef,
1256 with_range: NSRange,
1257 ) {
1258 unsafe { msg_send![self, executeCommandsInBuffer:buffer withRange:with_range] }
1259 }
1260
1261 pub fn update_fence(&self, fence: &FenceRef, after_stages: MTLRenderStages) {
1262 unsafe {
1263 msg_send![self,
1264 updateFence: fence
1265 afterStages: after_stages
1266 ]
1267 }
1268 }
1269
1270 pub fn wait_for_fence(&self, fence: &FenceRef, before_stages: MTLRenderStages) {
1271 unsafe {
1272 msg_send![self,
1273 waitForFence: fence
1274 beforeStages: before_stages
1275 ]
1276 }
1277 }
1278
1279 /// See: <https://developer.apple.com/documentation/metal/mtlrendercommandencoder/3194379-samplecountersinbuffer>
1280 pub fn sample_counters_in_buffer(
1281 &self,
1282 sample_buffer: &CounterSampleBufferRef,
1283 sample_index: NSUInteger,
1284 with_barrier: bool,
1285 ) {
1286 unsafe {
1287 msg_send![self,
1288 sampleCountersInBuffer: sample_buffer
1289 atSampleIndex: sample_index
1290 withBarrier: with_barrier
1291 ]
1292 }
1293 }
1294 }
1295
1296 /// See <https://developer.apple.com/documentation/metal/mtlblitcommandencoder/>
1297 pub enum MTLBlitCommandEncoder {}
1298
1299 foreign_obj_type! {
1300 type CType = MTLBlitCommandEncoder;
1301 pub struct BlitCommandEncoder;
1302 type ParentType = CommandEncoder;
1303 }
1304
1305 impl BlitCommandEncoderRef {
1306 pub fn synchronize_resource(&self, resource: &ResourceRef) {
1307 unsafe { msg_send![self, synchronizeResource: resource] }
1308 }
1309
1310 pub fn fill_buffer(&self, destination_buffer: &BufferRef, range: crate::NSRange, value: u8) {
1311 unsafe {
1312 msg_send![self,
1313 fillBuffer: destination_buffer
1314 range: range
1315 value: value
1316 ]
1317 }
1318 }
1319
1320 pub fn generate_mipmaps(&self, texture: &TextureRef) {
1321 unsafe { msg_send![self, generateMipmapsForTexture: texture] }
1322 }
1323
1324 pub fn copy_from_buffer(
1325 &self,
1326 source_buffer: &BufferRef,
1327 source_offset: NSUInteger,
1328 destination_buffer: &BufferRef,
1329 destination_offset: NSUInteger,
1330 size: NSUInteger,
1331 ) {
1332 unsafe {
1333 msg_send![self,
1334 copyFromBuffer: source_buffer
1335 sourceOffset: source_offset
1336 toBuffer: destination_buffer
1337 destinationOffset: destination_offset
1338 size: size
1339 ]
1340 }
1341 }
1342
1343 #[allow(clippy::too_many_arguments)]
1344 pub fn copy_from_texture(
1345 &self,
1346 source_texture: &TextureRef,
1347 source_slice: NSUInteger,
1348 source_level: NSUInteger,
1349 source_origin: MTLOrigin,
1350 source_size: MTLSize,
1351 destination_texture: &TextureRef,
1352 destination_slice: NSUInteger,
1353 destination_level: NSUInteger,
1354 destination_origin: MTLOrigin,
1355 ) {
1356 unsafe {
1357 msg_send![self,
1358 copyFromTexture: source_texture
1359 sourceSlice: source_slice
1360 sourceLevel: source_level
1361 sourceOrigin: source_origin
1362 sourceSize: source_size
1363 toTexture: destination_texture
1364 destinationSlice: destination_slice
1365 destinationLevel: destination_level
1366 destinationOrigin: destination_origin
1367 ]
1368 }
1369 }
1370
1371 #[allow(clippy::too_many_arguments)]
1372 pub fn copy_from_buffer_to_texture(
1373 &self,
1374 source_buffer: &BufferRef,
1375 source_offset: NSUInteger,
1376 source_bytes_per_row: NSUInteger,
1377 source_bytes_per_image: NSUInteger,
1378 source_size: MTLSize,
1379 destination_texture: &TextureRef,
1380 destination_slice: NSUInteger,
1381 destination_level: NSUInteger,
1382 destination_origin: MTLOrigin,
1383 options: MTLBlitOption,
1384 ) {
1385 unsafe {
1386 msg_send![self,
1387 copyFromBuffer: source_buffer
1388 sourceOffset: source_offset
1389 sourceBytesPerRow: source_bytes_per_row
1390 sourceBytesPerImage: source_bytes_per_image
1391 sourceSize: source_size
1392 toTexture: destination_texture
1393 destinationSlice: destination_slice
1394 destinationLevel: destination_level
1395 destinationOrigin: destination_origin
1396 options: options
1397 ]
1398 }
1399 }
1400
1401 /// See <https://developer.apple.com/documentation/metal/mtlblitcommandencoder/1400756-copy>
1402 #[allow(clippy::too_many_arguments)]
1403 pub fn copy_from_texture_to_buffer(
1404 &self,
1405 source_texture: &TextureRef,
1406 source_slice: NSUInteger,
1407 source_level: NSUInteger,
1408 source_origin: MTLOrigin,
1409 source_size: MTLSize,
1410 destination_buffer: &BufferRef,
1411 destination_offset: NSUInteger,
1412 destination_bytes_per_row: NSUInteger,
1413 destination_bytes_per_image: NSUInteger,
1414 options: MTLBlitOption,
1415 ) {
1416 unsafe {
1417 msg_send![self,
1418 copyFromTexture: source_texture
1419 sourceSlice: source_slice
1420 sourceLevel: source_level
1421 sourceOrigin: source_origin
1422 sourceSize: source_size
1423 toBuffer: destination_buffer
1424 destinationOffset: destination_offset
1425 destinationBytesPerRow: destination_bytes_per_row
1426 destinationBytesPerImage: destination_bytes_per_image
1427 options: options
1428 ]
1429 }
1430 }
1431
1432 pub fn optimize_contents_for_gpu_access(&self, texture: &TextureRef) {
1433 unsafe { msg_send![self, optimizeContentsForGPUAccess: texture] }
1434 }
1435
1436 pub fn optimize_contents_for_gpu_access_slice_level(
1437 &self,
1438 texture: &TextureRef,
1439 slice: NSUInteger,
1440 level: NSUInteger,
1441 ) {
1442 unsafe {
1443 msg_send![self,
1444 optimizeContentsForGPUAccess: texture
1445 slice: slice
1446 level: level
1447 ]
1448 }
1449 }
1450
1451 pub fn optimize_contents_for_cpu_access(&self, texture: &TextureRef) {
1452 unsafe { msg_send![self, optimizeContentsForCPUAccess: texture] }
1453 }
1454
1455 pub fn optimize_contents_for_cpu_access_slice_level(
1456 &self,
1457 texture: &TextureRef,
1458 slice: NSUInteger,
1459 level: NSUInteger,
1460 ) {
1461 unsafe {
1462 msg_send![self,
1463 optimizeContentsForCPUAccess: texture
1464 slice: slice
1465 level: level
1466 ]
1467 }
1468 }
1469
1470 pub fn update_fence(&self, fence: &FenceRef) {
1471 unsafe { msg_send![self, updateFence: fence] }
1472 }
1473
1474 pub fn wait_for_fence(&self, fence: &FenceRef) {
1475 unsafe { msg_send![self, waitForFence: fence] }
1476 }
1477
1478 pub fn copy_indirect_command_buffer(
1479 &self,
1480 source: &IndirectCommandBufferRef,
1481 source_range: NSRange,
1482 destination: &IndirectCommandBufferRef,
1483 destination_index: NSUInteger,
1484 ) {
1485 unsafe {
1486 msg_send![self,
1487 copyIndirectCommandBuffer: source
1488 sourceRange: source_range
1489 destination: destination
1490 destinationIndex: destination_index
1491 ]
1492 }
1493 }
1494
1495 pub fn reset_commands_in_buffer(&self, buffer: &IndirectCommandBufferRef, range: NSRange) {
1496 unsafe {
1497 msg_send![self,
1498 resetCommandsInBuffer: buffer
1499 withRange: range
1500 ]
1501 }
1502 }
1503
1504 pub fn optimize_indirect_command_buffer(
1505 &self,
1506 buffer: &IndirectCommandBufferRef,
1507 range: NSRange,
1508 ) {
1509 unsafe {
1510 msg_send![self,
1511 optimizeIndirectCommandBuffer: buffer
1512 withRange: range
1513 ]
1514 }
1515 }
1516
1517 /// See: <https://developer.apple.com/documentation/metal/mtlblitcommandencoder/3194348-samplecountersinbuffer>
1518 pub fn sample_counters_in_buffer(
1519 &self,
1520 sample_buffer: &CounterSampleBufferRef,
1521 sample_index: NSUInteger,
1522 with_barrier: bool,
1523 ) {
1524 unsafe {
1525 msg_send![self,
1526 sampleCountersInBuffer: sample_buffer
1527 atSampleIndex: sample_index
1528 withBarrier: with_barrier
1529 ]
1530 }
1531 }
1532
1533 /// See: <https://developer.apple.com/documentation/metal/mtlblitcommandencoder/3194347-resolvecounters>
1534 pub fn resolve_counters(
1535 &self,
1536 sample_buffer: &CounterSampleBufferRef,
1537 range: crate::NSRange,
1538 destination_buffer: &BufferRef,
1539 destination_offset: NSUInteger,
1540 ) {
1541 unsafe {
1542 msg_send![self,
1543 resolveCounters: sample_buffer
1544 inRange: range
1545 destinationBuffer: destination_buffer
1546 destinationOffset: destination_offset
1547 ]
1548 }
1549 }
1550 }
1551
1552 /// See <https://developer.apple.com/documentation/metal/mtlcomputecommandencoder/>
1553 pub enum MTLComputeCommandEncoder {}
1554
1555 foreign_obj_type! {
1556 type CType = MTLComputeCommandEncoder;
1557 pub struct ComputeCommandEncoder;
1558 type ParentType = CommandEncoder;
1559 }
1560
1561 impl ComputeCommandEncoderRef {
1562 pub fn set_compute_pipeline_state(&self, state: &ComputePipelineStateRef) {
1563 unsafe { msg_send![self, setComputePipelineState: state] }
1564 }
1565
1566 pub fn set_buffer(&self, index: NSUInteger, buffer: Option<&BufferRef>, offset: NSUInteger) {
1567 unsafe { msg_send![self, setBuffer:buffer offset:offset atIndex:index] }
1568 }
1569
1570 pub fn set_buffers(
1571 &self,
1572 start_index: NSUInteger,
1573 data: &[Option<&BufferRef>],
1574 offsets: &[NSUInteger],
1575 ) {
1576 debug_assert_eq!(offsets.len(), data.len());
1577 unsafe {
1578 msg_send![self,
1579 setBuffers: data.as_ptr()
1580 offsets: offsets.as_ptr()
1581 withRange: NSRange {
1582 location: start_index,
1583 length: data.len() as _,
1584 }
1585 ]
1586 }
1587 }
1588
1589 pub fn set_texture(&self, index: NSUInteger, texture: Option<&TextureRef>) {
1590 unsafe {
1591 msg_send![self,
1592 setTexture:texture
1593 atIndex:index
1594 ]
1595 }
1596 }
1597
1598 pub fn set_textures(&self, start_index: NSUInteger, data: &[Option<&TextureRef>]) {
1599 unsafe {
1600 msg_send![self,
1601 setTextures: data.as_ptr()
1602 withRange: NSRange {
1603 location: start_index,
1604 length: data.len() as _,
1605 }
1606 ]
1607 }
1608 }
1609
1610 pub fn set_sampler_state(&self, index: NSUInteger, sampler: Option<&SamplerStateRef>) {
1611 unsafe {
1612 msg_send![self,
1613 setSamplerState:sampler
1614 atIndex:index
1615 ]
1616 }
1617 }
1618
1619 pub fn set_sampler_states(&self, start_index: NSUInteger, data: &[Option<&SamplerStateRef>]) {
1620 unsafe {
1621 msg_send![self,
1622 setSamplerStates: data.as_ptr()
1623 withRange: NSRange {
1624 location: start_index,
1625 length: data.len() as _,
1626 }
1627 ]
1628 }
1629 }
1630
1631 pub fn set_sampler_state_with_lod(
1632 &self,
1633 index: NSUInteger,
1634 sampler: Option<&SamplerStateRef>,
1635 lod_clamp: Range<f32>,
1636 ) {
1637 unsafe {
1638 msg_send![self,
1639 setSamplerState:sampler
1640 lodMinClamp:lod_clamp.start
1641 lodMaxClamp:lod_clamp.end
1642 atIndex:index
1643 ]
1644 }
1645 }
1646
1647 pub fn set_bytes(&self, index: NSUInteger, length: NSUInteger, bytes: *const std::ffi::c_void) {
1648 unsafe {
1649 msg_send![self,
1650 setBytes: bytes
1651 length: length
1652 atIndex: index
1653 ]
1654 }
1655 }
1656
1657 pub fn set_visible_function_table(
1658 &self,
1659 buffer_index: NSUInteger,
1660 visible_function_table: Option<&VisibleFunctionTableRef>,
1661 ) {
1662 unsafe {
1663 msg_send![self,
1664 setVisibleFunctionTable:visible_function_table
1665 atBufferIndex:buffer_index]
1666 }
1667 }
1668
1669 pub fn set_visible_function_tables(
1670 &self,
1671 buffer_start_index: NSUInteger,
1672 visible_function_tables: &[&VisibleFunctionTableRef],
1673 ) {
1674 unsafe {
1675 msg_send![self,
1676 setVisibleFunctionTables:visible_function_tables.as_ptr()
1677 withBufferRange: NSRange {
1678 location: buffer_start_index,
1679 length: visible_function_tables.len() as _,
1680 }
1681 ]
1682 }
1683 }
1684
1685 pub fn dispatch_thread_groups(
1686 &self,
1687 thread_groups_count: MTLSize,
1688 threads_per_threadgroup: MTLSize,
1689 ) {
1690 unsafe {
1691 msg_send![self,
1692 dispatchThreadgroups:thread_groups_count
1693 threadsPerThreadgroup:threads_per_threadgroup
1694 ]
1695 }
1696 }
1697
1698 pub fn dispatch_threads(&self, threads_per_grid: MTLSize, threads_per_thread_group: MTLSize) {
1699 unsafe {
1700 msg_send![self,
1701 dispatchThreads:threads_per_grid
1702 threadsPerThreadgroup:threads_per_thread_group
1703 ]
1704 }
1705 }
1706
1707 pub fn dispatch_thread_groups_indirect(
1708 &self,
1709 buffer: &BufferRef,
1710 offset: NSUInteger,
1711 threads_per_threadgroup: MTLSize,
1712 ) {
1713 unsafe {
1714 msg_send![self,
1715 dispatchThreadgroupsWithIndirectBuffer:buffer
1716 indirectBufferOffset:offset
1717 threadsPerThreadgroup:threads_per_threadgroup
1718 ]
1719 }
1720 }
1721
1722 pub fn set_threadgroup_memory_length(&self, at_index: NSUInteger, size: NSUInteger) {
1723 unsafe {
1724 msg_send![self,
1725 setThreadgroupMemoryLength:size
1726 atIndex: at_index
1727 ]
1728 }
1729 }
1730
1731 /// Encodes a barrier so that changes to a set of resources made by commands encoded before the
1732 /// barrier are completed before further commands are executed.
1733 ///
1734 /// Availability: iOS 12.0+, macOS 10.14+
1735 ///
1736 /// # Arguments
1737 /// * `resources`: A slice of resources.
1738 pub fn memory_barrier_with_resources(&self, resources: &[&ResourceRef]) {
1739 unsafe {
1740 msg_send![self,
1741 memoryBarrierWithResources: resources.as_ptr()
1742 count: resources.len() as NSUInteger
1743 ]
1744 }
1745 }
1746
1747 /// Specifies that a resource in an argument buffer can be safely used by a compute pass.
1748 ///
1749 /// Availability: iOS 11.0+, macOS 10.13+
1750 ///
1751 /// # Arguments
1752 /// * `resource`: A specific resource within an argument buffer.
1753 /// * `usage`: The options that describe how the resource will be used by a compute function.
1754 pub fn use_resource(&self, resource: &ResourceRef, usage: MTLResourceUsage) {
1755 unsafe {
1756 msg_send![self,
1757 useResource: resource
1758 usage: usage
1759 ]
1760 }
1761 }
1762
1763 /// Specifies that an array of resources in an argument buffer can be safely used by a compute pass.
1764 ///
1765 /// Availability: iOS 11.0+, macOS 10.13+
1766 ///
1767 /// See <https://developer.apple.com/documentation/metal/mtlcomputecommandencoder/2866561-useresources>
1768 ///
1769 /// # Arguments
1770 /// * `resources`: A slice of resources within an argument buffer.
1771 /// * `usage`: The options that describe how the array of resources will be used by a compute function.
1772 pub fn use_resources(&self, resources: &[&ResourceRef], usage: MTLResourceUsage) {
1773 unsafe {
1774 msg_send![self,
1775 useResources: resources.as_ptr()
1776 count: resources.len() as NSUInteger
1777 usage: usage
1778 ]
1779 }
1780 }
1781
1782 /// Specifies that a heap containing resources in an argument buffer can be safely used by a compute pass.
1783 ///
1784 /// Availability: iOS 11.0+, macOS 10.13+
1785 ///
1786 /// See <https://developer.apple.com/documentation/metal/mtlcomputecommandencoder/2866530-useheap>
1787 ///
1788 /// # Arguments
1789 /// * `heap`: A heap that contains resources within an argument buffer.
1790 pub fn use_heap(&self, heap: &HeapRef) {
1791 unsafe { msg_send![self, useHeap: heap] }
1792 }
1793
1794 /// Specifies that an array of heaps containing resources in an argument buffer can be safely
1795 /// used by a compute pass.
1796 ///
1797 /// Availability: iOS 11.0+, macOS 10.13+
1798 ///
1799 /// # Arguments
1800 /// * `heaps`: A slice of heaps that contains resources within an argument buffer.
1801 pub fn use_heaps(&self, heaps: &[&HeapRef]) {
1802 unsafe {
1803 msg_send![self,
1804 useHeaps: heaps.as_ptr()
1805 count: heaps.len() as NSUInteger
1806 ]
1807 }
1808 }
1809
1810 pub fn update_fence(&self, fence: &FenceRef) {
1811 unsafe { msg_send![self, updateFence: fence] }
1812 }
1813
1814 pub fn wait_for_fence(&self, fence: &FenceRef) {
1815 unsafe { msg_send![self, waitForFence: fence] }
1816 }
1817
1818 /// Only available in (macos(11.0), ios(14.0))
1819 pub fn set_acceleration_structure(
1820 &self,
1821 index: NSUInteger,
1822 accel: Option<&AccelerationStructureRef>,
1823 ) {
1824 unsafe {
1825 msg_send![
1826 self,
1827 setAccelerationStructure: accel
1828 atBufferIndex: index
1829 ]
1830 }
1831 }
1832
1833 /// Only available in (macos(11.0), ios(14.0))
1834 pub fn set_intersection_function_table(
1835 &self,
1836 index: NSUInteger,
1837 table: Option<&IntersectionFunctionTableRef>,
1838 ) {
1839 unsafe {
1840 msg_send![
1841 self,
1842 setIntersectionFunctionTable: table
1843 atBufferIndex: index
1844 ]
1845 }
1846 }
1847
1848 /// See: <https://developer.apple.com/documentation/metal/mtlcomputecommandencoder/3194349-samplecountersinbuffer>
1849 pub fn sample_counters_in_buffer(
1850 &self,
1851 sample_buffer: &CounterSampleBufferRef,
1852 sample_index: NSUInteger,
1853 with_barrier: bool,
1854 ) {
1855 unsafe {
1856 msg_send![self,
1857 sampleCountersInBuffer: sample_buffer
1858 atSampleIndex: sample_index
1859 withBarrier: with_barrier
1860 ]
1861 }
1862 }
1863 }
1864
1865 /// See <https://developer.apple.com/documentation/metal/mtlargumentencoder/>
1866 pub enum MTLArgumentEncoder {}
1867
1868 foreign_obj_type! {
1869 type CType = MTLArgumentEncoder;
1870 pub struct ArgumentEncoder;
1871 }
1872
1873 impl ArgumentEncoderRef {
1874 pub fn encoded_length(&self) -> NSUInteger {
1875 unsafe { msg_send![self, encodedLength] }
1876 }
1877
1878 pub fn alignment(&self) -> NSUInteger {
1879 unsafe { msg_send![self, alignment] }
1880 }
1881
1882 pub fn set_argument_buffer(&self, buffer: &BufferRef, offset: NSUInteger) {
1883 unsafe {
1884 msg_send![self,
1885 setArgumentBuffer: buffer
1886 offset: offset
1887 ]
1888 }
1889 }
1890
1891 pub fn set_argument_buffer_to_element(
1892 &self,
1893 array_element: NSUInteger,
1894 buffer: &BufferRef,
1895 offset: NSUInteger,
1896 ) {
1897 unsafe {
1898 msg_send![self,
1899 setArgumentBuffer: buffer
1900 startOffset: offset
1901 arrayElement: array_element
1902 ]
1903 }
1904 }
1905
1906 pub fn set_buffer(&self, at_index: NSUInteger, buffer: &BufferRef, offset: NSUInteger) {
1907 unsafe {
1908 msg_send![self,
1909 setBuffer: buffer
1910 offset: offset
1911 atIndex: at_index
1912 ]
1913 }
1914 }
1915
1916 pub fn set_buffers(
1917 &self,
1918 start_index: NSUInteger,
1919 data: &[&BufferRef],
1920 offsets: &[NSUInteger],
1921 ) {
1922 assert_eq!(offsets.len(), data.len());
1923 unsafe {
1924 msg_send![self,
1925 setBuffers: data.as_ptr()
1926 offsets: offsets.as_ptr()
1927 withRange: NSRange {
1928 location: start_index,
1929 length: data.len() as _,
1930 }
1931 ]
1932 }
1933 }
1934
1935 pub fn set_texture(&self, at_index: NSUInteger, texture: &TextureRef) {
1936 unsafe {
1937 msg_send![self,
1938 setTexture: texture
1939 atIndex: at_index
1940 ]
1941 }
1942 }
1943
1944 pub fn set_textures(&self, start_index: NSUInteger, data: &[&TextureRef]) {
1945 unsafe {
1946 msg_send![self,
1947 setTextures: data.as_ptr()
1948 withRange: NSRange {
1949 location: start_index,
1950 length: data.len() as _,
1951 }
1952 ]
1953 }
1954 }
1955
1956 pub fn set_sampler_state(&self, at_index: NSUInteger, sampler_state: &SamplerStateRef) {
1957 unsafe {
1958 msg_send![self,
1959 setSamplerState: sampler_state
1960 atIndex: at_index
1961 ]
1962 }
1963 }
1964
1965 pub fn set_sampler_states(&self, start_index: NSUInteger, data: &[&SamplerStateRef]) {
1966 unsafe {
1967 msg_send![self,
1968 setSamplerStates: data.as_ptr()
1969 withRange: NSRange {
1970 location: start_index,
1971 length: data.len() as _,
1972 }
1973 ]
1974 }
1975 }
1976
1977 pub fn set_render_pipeline_state(
1978 &self,
1979 at_index: NSUInteger,
1980 pipeline: &RenderPipelineStateRef,
1981 ) {
1982 unsafe {
1983 msg_send![self,
1984 setRenderPipelineState: pipeline
1985 atIndex: at_index
1986 ]
1987 }
1988 }
1989
1990 pub fn set_render_pipeline_states(
1991 &self,
1992 start_index: NSUInteger,
1993 pipelines: &[&RenderPipelineStateRef],
1994 ) {
1995 unsafe {
1996 msg_send![self,
1997 setRenderPipelineStates: pipelines.as_ptr()
1998 withRange: NSRange {
1999 location: start_index,
2000 length: pipelines.len() as _,
2001 }
2002 ]
2003 }
2004 }
2005
2006 pub fn constant_data(&self, at_index: NSUInteger) -> *mut std::ffi::c_void {
2007 unsafe { msg_send![self, constantDataAtIndex: at_index] }
2008 }
2009
2010 pub fn set_indirect_command_buffer(
2011 &self,
2012 at_index: NSUInteger,
2013 buffer: &IndirectCommandBufferRef,
2014 ) {
2015 unsafe {
2016 msg_send![self,
2017 setIndirectCommandBuffer: buffer
2018 atIndex: at_index
2019 ]
2020 }
2021 }
2022
2023 pub fn set_indirect_command_buffers(
2024 &self,
2025 start_index: NSUInteger,
2026 data: &[&IndirectCommandBufferRef],
2027 ) {
2028 unsafe {
2029 msg_send![self,
2030 setIndirectCommandBuffers: data.as_ptr()
2031 withRange: NSRange {
2032 location: start_index,
2033 length: data.len() as _,
2034 }
2035 ]
2036 }
2037 }
2038
2039 pub fn new_argument_encoder_for_buffer(&self, index: NSUInteger) -> ArgumentEncoder {
2040 unsafe {
2041 let ptr = msg_send![self, newArgumentEncoderForBufferAtIndex: index];
2042 ArgumentEncoder::from_ptr(ptr)
2043 }
2044 }
2045 }