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