1use crate::RawPtr;
4use crate::prelude::*;
5use crate::vk;
6use alloc::vec::Vec;
7use core::ptr;
8
9impl crate::ext::shader_object::Device {
10 #[inline]
21 pub unsafe fn create_shaders(
22 &self,
23 create_infos: &[vk::ShaderCreateInfoEXT<'_>],
24 allocator: Option<&vk::AllocationCallbacks<'_>>,
25 ) -> Result<Vec<vk::ShaderEXT>, (Vec<vk::ShaderEXT>, vk::Result)> {
26 unsafe {
27 let mut shaders = Vec::with_capacity(create_infos.len());
28 let err_code = (self.fp.create_shaders_ext)(
29 self.handle,
30 create_infos.len() as u32,
31 create_infos.as_ptr(),
32 allocator.as_raw_ptr(),
33 shaders.as_mut_ptr(),
34 );
35 shaders.set_len(create_infos.len());
36 match err_code {
37 vk::Result::SUCCESS => Ok(shaders),
38 _ => Err((shaders, err_code)),
39 }
40 }
41 }
42
43 #[inline]
45 pub unsafe fn destroy_shader(
46 &self,
47 shader: vk::ShaderEXT,
48 allocator: Option<&vk::AllocationCallbacks<'_>>,
49 ) {
50 unsafe { (self.fp.destroy_shader_ext)(self.handle, shader, allocator.as_raw_ptr()) }
51 }
52
53 #[inline]
55 pub unsafe fn get_shader_binary_data(&self, shader: vk::ShaderEXT) -> VkResult<Vec<u8>> {
56 unsafe {
57 read_into_uninitialized_vector(|count, data: *mut u8| {
58 (self.fp.get_shader_binary_data_ext)(self.handle, shader, count, data.cast())
59 })
60 }
61 }
62
63 #[inline]
65 pub unsafe fn cmd_bind_shaders(
66 &self,
67 command_buffer: vk::CommandBuffer,
68 stages: &[vk::ShaderStageFlags],
69 shaders: &[vk::ShaderEXT],
70 ) {
71 unsafe {
72 assert_eq!(stages.len(), shaders.len());
73 (self.fp.cmd_bind_shaders_ext)(
74 command_buffer,
75 stages.len() as u32,
76 stages.as_ptr(),
77 shaders.as_ptr(),
78 )
79 }
80 }
81
82 #[inline]
84 pub unsafe fn cmd_set_vertex_input(
85 &self,
86 command_buffer: vk::CommandBuffer,
87 vertex_binding_descriptions: &[vk::VertexInputBindingDescription2EXT<'_>],
88 vertex_attribute_descriptions: &[vk::VertexInputAttributeDescription2EXT<'_>],
89 ) {
90 unsafe {
91 (self.fp.cmd_set_vertex_input_ext)(
92 command_buffer,
93 vertex_binding_descriptions.len() as u32,
94 vertex_binding_descriptions.as_ptr(),
95 vertex_attribute_descriptions.len() as u32,
96 vertex_attribute_descriptions.as_ptr(),
97 )
98 }
99 }
100
101 #[inline]
105 pub unsafe fn cmd_set_cull_mode(
106 &self,
107 command_buffer: vk::CommandBuffer,
108 cull_mode: vk::CullModeFlags,
109 ) {
110 unsafe { (self.fp.cmd_set_cull_mode_ext)(command_buffer, cull_mode) }
111 }
112
113 #[inline]
115 pub unsafe fn cmd_set_front_face(
116 &self,
117 command_buffer: vk::CommandBuffer,
118 front_face: vk::FrontFace,
119 ) {
120 unsafe { (self.fp.cmd_set_front_face_ext)(command_buffer, front_face) }
121 }
122
123 #[inline]
125 pub unsafe fn cmd_set_primitive_topology(
126 &self,
127 command_buffer: vk::CommandBuffer,
128 primitive_topology: vk::PrimitiveTopology,
129 ) {
130 unsafe { (self.fp.cmd_set_primitive_topology_ext)(command_buffer, primitive_topology) }
131 }
132
133 #[inline]
135 pub unsafe fn cmd_set_viewport_with_count(
136 &self,
137 command_buffer: vk::CommandBuffer,
138 viewports: &[vk::Viewport],
139 ) {
140 unsafe {
141 (self.fp.cmd_set_viewport_with_count_ext)(
142 command_buffer,
143 viewports.len() as u32,
144 viewports.as_ptr(),
145 )
146 }
147 }
148
149 #[inline]
151 pub unsafe fn cmd_set_scissor_with_count(
152 &self,
153 command_buffer: vk::CommandBuffer,
154 scissors: &[vk::Rect2D],
155 ) {
156 unsafe {
157 (self.fp.cmd_set_scissor_with_count_ext)(
158 command_buffer,
159 scissors.len() as u32,
160 scissors.as_ptr(),
161 )
162 }
163 }
164
165 #[inline]
167 pub unsafe fn cmd_bind_vertex_buffers2(
168 &self,
169 command_buffer: vk::CommandBuffer,
170 first_binding: u32,
171 buffers: &[vk::Buffer],
172 offsets: &[vk::DeviceSize],
173 sizes: Option<&[vk::DeviceSize]>,
174 strides: Option<&[vk::DeviceSize]>,
175 ) {
176 unsafe {
177 assert_eq!(offsets.len(), buffers.len());
178 let p_sizes = if let Some(sizes) = sizes {
179 assert_eq!(sizes.len(), buffers.len());
180 sizes.as_ptr()
181 } else {
182 ptr::null()
183 };
184 let p_strides = if let Some(strides) = strides {
185 assert_eq!(strides.len(), buffers.len());
186 strides.as_ptr()
187 } else {
188 ptr::null()
189 };
190 (self.fp.cmd_bind_vertex_buffers2_ext)(
191 command_buffer,
192 first_binding,
193 buffers.len() as u32,
194 buffers.as_ptr(),
195 offsets.as_ptr(),
196 p_sizes,
197 p_strides,
198 )
199 }
200 }
201
202 #[inline]
204 pub unsafe fn cmd_set_depth_test_enable(
205 &self,
206 command_buffer: vk::CommandBuffer,
207 depth_test_enable: bool,
208 ) {
209 unsafe { (self.fp.cmd_set_depth_test_enable_ext)(command_buffer, depth_test_enable.into()) }
210 }
211
212 #[inline]
214 pub unsafe fn cmd_set_depth_write_enable(
215 &self,
216 command_buffer: vk::CommandBuffer,
217 depth_write_enable: bool,
218 ) {
219 unsafe {
220 (self.fp.cmd_set_depth_write_enable_ext)(command_buffer, depth_write_enable.into())
221 }
222 }
223
224 #[inline]
226 pub unsafe fn cmd_set_depth_compare_op(
227 &self,
228 command_buffer: vk::CommandBuffer,
229 depth_compare_op: vk::CompareOp,
230 ) {
231 unsafe { (self.fp.cmd_set_depth_compare_op_ext)(command_buffer, depth_compare_op) }
232 }
233
234 #[inline]
236 pub unsafe fn cmd_set_depth_bounds_test_enable(
237 &self,
238 command_buffer: vk::CommandBuffer,
239 depth_bounds_test_enable: bool,
240 ) {
241 unsafe {
242 (self.fp.cmd_set_depth_bounds_test_enable_ext)(
243 command_buffer,
244 depth_bounds_test_enable.into(),
245 )
246 }
247 }
248
249 #[inline]
251 pub unsafe fn cmd_set_stencil_test_enable(
252 &self,
253 command_buffer: vk::CommandBuffer,
254 stencil_test_enable: bool,
255 ) {
256 unsafe {
257 (self.fp.cmd_set_stencil_test_enable_ext)(command_buffer, stencil_test_enable.into())
258 }
259 }
260
261 #[inline]
263 pub unsafe fn cmd_set_stencil_op(
264 &self,
265 command_buffer: vk::CommandBuffer,
266 face_mask: vk::StencilFaceFlags,
267 fail_op: vk::StencilOp,
268 pass_op: vk::StencilOp,
269 depth_fail_op: vk::StencilOp,
270 compare_op: vk::CompareOp,
271 ) {
272 unsafe {
273 (self.fp.cmd_set_stencil_op_ext)(
274 command_buffer,
275 face_mask,
276 fail_op,
277 pass_op,
278 depth_fail_op,
279 compare_op,
280 )
281 }
282 }
283
284 #[inline]
288 pub unsafe fn cmd_set_patch_control_points(
289 &self,
290 command_buffer: vk::CommandBuffer,
291 patch_control_points: u32,
292 ) {
293 unsafe { (self.fp.cmd_set_patch_control_points_ext)(command_buffer, patch_control_points) }
294 }
295
296 #[inline]
298 pub unsafe fn cmd_set_rasterizer_discard_enable(
299 &self,
300 command_buffer: vk::CommandBuffer,
301 rasterizer_discard_enable: bool,
302 ) {
303 unsafe {
304 (self.fp.cmd_set_rasterizer_discard_enable_ext)(
305 command_buffer,
306 rasterizer_discard_enable.into(),
307 )
308 }
309 }
310
311 #[inline]
313 pub unsafe fn cmd_set_depth_bias_enable(
314 &self,
315 command_buffer: vk::CommandBuffer,
316 depth_bias_enable: bool,
317 ) {
318 unsafe { (self.fp.cmd_set_depth_bias_enable_ext)(command_buffer, depth_bias_enable.into()) }
319 }
320
321 #[inline]
323 pub unsafe fn cmd_set_logic_op(
324 &self,
325 command_buffer: vk::CommandBuffer,
326 logic_op: vk::LogicOp,
327 ) {
328 unsafe { (self.fp.cmd_set_logic_op_ext)(command_buffer, logic_op) }
329 }
330
331 #[inline]
333 pub unsafe fn cmd_set_primitive_restart_enable(
334 &self,
335 command_buffer: vk::CommandBuffer,
336 primitive_restart_enable: bool,
337 ) {
338 unsafe {
339 (self.fp.cmd_set_primitive_restart_enable_ext)(
340 command_buffer,
341 primitive_restart_enable.into(),
342 )
343 }
344 }
345
346 #[inline]
350 pub unsafe fn cmd_set_tessellation_domain_origin(
351 &self,
352 command_buffer: vk::CommandBuffer,
353 domain_origin: vk::TessellationDomainOrigin,
354 ) {
355 unsafe { (self.fp.cmd_set_tessellation_domain_origin_ext)(command_buffer, domain_origin) }
356 }
357
358 #[inline]
360 pub unsafe fn cmd_set_depth_clamp_enable(
361 &self,
362 command_buffer: vk::CommandBuffer,
363 depth_clamp_enable: bool,
364 ) {
365 unsafe {
366 (self.fp.cmd_set_depth_clamp_enable_ext)(command_buffer, depth_clamp_enable.into())
367 }
368 }
369
370 #[inline]
372 pub unsafe fn cmd_set_polygon_mode(
373 &self,
374 command_buffer: vk::CommandBuffer,
375 polygon_mode: vk::PolygonMode,
376 ) {
377 unsafe { (self.fp.cmd_set_polygon_mode_ext)(command_buffer, polygon_mode) }
378 }
379
380 #[inline]
382 pub unsafe fn cmd_set_rasterization_samples(
383 &self,
384 command_buffer: vk::CommandBuffer,
385 rasterization_samples: vk::SampleCountFlags,
386 ) {
387 unsafe {
388 (self.fp.cmd_set_rasterization_samples_ext)(command_buffer, rasterization_samples)
389 }
390 }
391
392 #[inline]
394 pub unsafe fn cmd_set_sample_mask(
395 &self,
396 command_buffer: vk::CommandBuffer,
397 samples: vk::SampleCountFlags,
398 sample_mask: &[vk::SampleMask],
399 ) {
400 unsafe {
401 assert!(
402 samples.as_raw().is_power_of_two(),
403 "Only one SampleCount bit must be set"
404 );
405 assert_eq!((samples.as_raw() as usize).div_ceil(32), sample_mask.len());
406 (self.fp.cmd_set_sample_mask_ext)(command_buffer, samples, sample_mask.as_ptr())
407 }
408 }
409
410 #[inline]
412 pub unsafe fn cmd_set_alpha_to_coverage_enable(
413 &self,
414 command_buffer: vk::CommandBuffer,
415 alpha_to_coverage_enable: bool,
416 ) {
417 unsafe {
418 (self.fp.cmd_set_alpha_to_coverage_enable_ext)(
419 command_buffer,
420 alpha_to_coverage_enable.into(),
421 )
422 }
423 }
424
425 #[inline]
427 pub unsafe fn cmd_set_alpha_to_one_enable(
428 &self,
429 command_buffer: vk::CommandBuffer,
430 alpha_to_one_enable: bool,
431 ) {
432 unsafe {
433 (self.fp.cmd_set_alpha_to_one_enable_ext)(command_buffer, alpha_to_one_enable.into())
434 }
435 }
436
437 #[inline]
439 pub unsafe fn cmd_set_logic_op_enable(
440 &self,
441 command_buffer: vk::CommandBuffer,
442 logic_op_enable: bool,
443 ) {
444 unsafe { (self.fp.cmd_set_logic_op_enable_ext)(command_buffer, logic_op_enable.into()) }
445 }
446
447 #[inline]
449 pub unsafe fn cmd_set_color_blend_enable(
450 &self,
451 command_buffer: vk::CommandBuffer,
452 first_attachment: u32,
453 color_blend_enables: &[vk::Bool32],
454 ) {
455 unsafe {
456 (self.fp.cmd_set_color_blend_enable_ext)(
457 command_buffer,
458 first_attachment,
459 color_blend_enables.len() as u32,
460 color_blend_enables.as_ptr(),
461 )
462 }
463 }
464
465 #[inline]
467 pub unsafe fn cmd_set_color_blend_equation(
468 &self,
469 command_buffer: vk::CommandBuffer,
470 first_attachment: u32,
471 color_blend_equations: &[vk::ColorBlendEquationEXT],
472 ) {
473 unsafe {
474 (self.fp.cmd_set_color_blend_equation_ext)(
475 command_buffer,
476 first_attachment,
477 color_blend_equations.len() as u32,
478 color_blend_equations.as_ptr(),
479 )
480 }
481 }
482
483 #[inline]
485 pub unsafe fn cmd_set_color_write_mask(
486 &self,
487 command_buffer: vk::CommandBuffer,
488 first_attachment: u32,
489 color_write_masks: &[vk::ColorComponentFlags],
490 ) {
491 unsafe {
492 (self.fp.cmd_set_color_write_mask_ext)(
493 command_buffer,
494 first_attachment,
495 color_write_masks.len() as u32,
496 color_write_masks.as_ptr(),
497 )
498 }
499 }
500
501 #[inline]
503 pub unsafe fn cmd_set_rasterization_stream(
504 &self,
505 command_buffer: vk::CommandBuffer,
506 rasterization_stream: u32,
507 ) {
508 unsafe { (self.fp.cmd_set_rasterization_stream_ext)(command_buffer, rasterization_stream) }
509 }
510
511 #[inline]
513 pub unsafe fn cmd_set_conservative_rasterization_mode(
514 &self,
515 command_buffer: vk::CommandBuffer,
516 conservative_rasterization_mode: vk::ConservativeRasterizationModeEXT,
517 ) {
518 unsafe {
519 (self.fp.cmd_set_conservative_rasterization_mode_ext)(
520 command_buffer,
521 conservative_rasterization_mode,
522 )
523 }
524 }
525
526 #[inline]
528 pub unsafe fn cmd_set_extra_primitive_overestimation_size(
529 &self,
530 command_buffer: vk::CommandBuffer,
531 extra_primitive_overestimation_size: f32,
532 ) {
533 unsafe {
534 (self.fp.cmd_set_extra_primitive_overestimation_size_ext)(
535 command_buffer,
536 extra_primitive_overestimation_size,
537 )
538 }
539 }
540
541 #[inline]
543 pub unsafe fn cmd_set_depth_clip_enable(
544 &self,
545 command_buffer: vk::CommandBuffer,
546 depth_clip_enable: bool,
547 ) {
548 unsafe { (self.fp.cmd_set_depth_clip_enable_ext)(command_buffer, depth_clip_enable.into()) }
549 }
550
551 #[inline]
553 pub unsafe fn cmd_set_sample_locations_enable(
554 &self,
555 command_buffer: vk::CommandBuffer,
556 sample_locations_enable: bool,
557 ) {
558 unsafe {
559 (self.fp.cmd_set_sample_locations_enable_ext)(
560 command_buffer,
561 sample_locations_enable.into(),
562 )
563 }
564 }
565
566 #[inline]
568 pub unsafe fn cmd_set_color_blend_advanced(
569 &self,
570 command_buffer: vk::CommandBuffer,
571 first_attachment: u32,
572 color_blend_advanced: &[vk::ColorBlendAdvancedEXT],
573 ) {
574 unsafe {
575 (self.fp.cmd_set_color_blend_advanced_ext)(
576 command_buffer,
577 first_attachment,
578 color_blend_advanced.len() as u32,
579 color_blend_advanced.as_ptr(),
580 )
581 }
582 }
583
584 #[inline]
586 pub unsafe fn cmd_set_provoking_vertex_mode(
587 &self,
588 command_buffer: vk::CommandBuffer,
589 provoking_vertex_mode: vk::ProvokingVertexModeEXT,
590 ) {
591 unsafe {
592 (self.fp.cmd_set_provoking_vertex_mode_ext)(command_buffer, provoking_vertex_mode)
593 }
594 }
595
596 #[inline]
598 pub unsafe fn cmd_set_line_rasterization_mode(
599 &self,
600 command_buffer: vk::CommandBuffer,
601 line_rasterization_mode: vk::LineRasterizationModeEXT,
602 ) {
603 unsafe {
604 (self.fp.cmd_set_line_rasterization_mode_ext)(command_buffer, line_rasterization_mode)
605 }
606 }
607
608 #[inline]
610 pub unsafe fn cmd_set_line_stipple_enable(
611 &self,
612 command_buffer: vk::CommandBuffer,
613 stippled_line_enable: bool,
614 ) {
615 unsafe {
616 (self.fp.cmd_set_line_stipple_enable_ext)(command_buffer, stippled_line_enable.into())
617 }
618 }
619
620 #[inline]
622 pub unsafe fn cmd_set_depth_clip_negative_one_to_one(
623 &self,
624 command_buffer: vk::CommandBuffer,
625 negative_one_to_one: bool,
626 ) {
627 unsafe {
628 (self.fp.cmd_set_depth_clip_negative_one_to_one_ext)(
629 command_buffer,
630 negative_one_to_one.into(),
631 )
632 }
633 }
634
635 #[inline]
637 pub unsafe fn cmd_set_viewport_w_scaling_enable_nv(
638 &self,
639 command_buffer: vk::CommandBuffer,
640 viewport_w_scaling_enable: bool,
641 ) {
642 unsafe {
643 (self.fp.cmd_set_viewport_w_scaling_enable_nv)(
644 command_buffer,
645 viewport_w_scaling_enable.into(),
646 )
647 }
648 }
649
650 #[inline]
652 pub unsafe fn cmd_set_viewport_swizzle_nv(
653 &self,
654 command_buffer: vk::CommandBuffer,
655 first_attachment: u32,
656 viewport_swizzles: &[vk::ViewportSwizzleNV],
657 ) {
658 unsafe {
659 (self.fp.cmd_set_viewport_swizzle_nv)(
660 command_buffer,
661 first_attachment,
662 viewport_swizzles.len() as u32,
663 viewport_swizzles.as_ptr(),
664 )
665 }
666 }
667
668 #[inline]
670 pub unsafe fn cmd_set_coverage_to_color_enable_nv(
671 &self,
672 command_buffer: vk::CommandBuffer,
673 coverage_to_color_enable: bool,
674 ) {
675 unsafe {
676 (self.fp.cmd_set_coverage_to_color_enable_nv)(
677 command_buffer,
678 coverage_to_color_enable.into(),
679 )
680 }
681 }
682
683 #[inline]
685 pub unsafe fn cmd_set_coverage_to_color_location_nv(
686 &self,
687 command_buffer: vk::CommandBuffer,
688 coverage_to_color_location: u32,
689 ) {
690 unsafe {
691 (self.fp.cmd_set_coverage_to_color_location_nv)(
692 command_buffer,
693 coverage_to_color_location,
694 )
695 }
696 }
697
698 #[inline]
700 pub unsafe fn cmd_set_coverage_modulation_mode_nv(
701 &self,
702 command_buffer: vk::CommandBuffer,
703 coverage_modulation_mode: vk::CoverageModulationModeNV,
704 ) {
705 unsafe {
706 (self.fp.cmd_set_coverage_modulation_mode_nv)(command_buffer, coverage_modulation_mode)
707 }
708 }
709
710 #[inline]
712 pub unsafe fn cmd_set_coverage_modulation_table_enable_nv(
713 &self,
714 command_buffer: vk::CommandBuffer,
715 coverage_modulation_table_enable: bool,
716 ) {
717 unsafe {
718 (self.fp.cmd_set_coverage_modulation_table_enable_nv)(
719 command_buffer,
720 coverage_modulation_table_enable.into(),
721 )
722 }
723 }
724
725 #[inline]
727 pub unsafe fn cmd_set_coverage_modulation_table_nv(
728 &self,
729 command_buffer: vk::CommandBuffer,
730 coverage_modulation_table: &[f32],
731 ) {
732 unsafe {
733 (self.fp.cmd_set_coverage_modulation_table_nv)(
734 command_buffer,
735 coverage_modulation_table.len() as u32,
736 coverage_modulation_table.as_ptr(),
737 )
738 }
739 }
740
741 #[inline]
743 pub unsafe fn cmd_set_shading_rate_image_enable_nv(
744 &self,
745 command_buffer: vk::CommandBuffer,
746 shading_rate_image_enable: bool,
747 ) {
748 unsafe {
749 (self.fp.cmd_set_shading_rate_image_enable_nv)(
750 command_buffer,
751 shading_rate_image_enable.into(),
752 )
753 }
754 }
755
756 #[inline]
758 pub unsafe fn cmd_set_representative_fragment_test_enable_nv(
759 &self,
760 command_buffer: vk::CommandBuffer,
761 representative_fragment_test_enable: bool,
762 ) {
763 unsafe {
764 (self.fp.cmd_set_representative_fragment_test_enable_nv)(
765 command_buffer,
766 representative_fragment_test_enable.into(),
767 )
768 }
769 }
770
771 #[inline]
773 pub unsafe fn cmd_set_coverage_reduction_mode_nv(
774 &self,
775 command_buffer: vk::CommandBuffer,
776 coverage_reduction_mode: vk::CoverageReductionModeNV,
777 ) {
778 unsafe {
779 (self.fp.cmd_set_coverage_reduction_mode_nv)(command_buffer, coverage_reduction_mode)
780 }
781 }
782}