ash/extensions/ext/
extended_dynamic_state.rs

1use crate::vk;
2use crate::{Device, Instance};
3use std::ffi::CStr;
4use std::mem;
5use std::ptr;
6
7#[derive(Clone)]
8pub struct ExtendedDynamicState {
9    fp: vk::ExtExtendedDynamicStateFn,
10}
11
12impl ExtendedDynamicState {
13    pub fn new(instance: &Instance, device: &Device) -> Self {
14        let fp = vk::ExtExtendedDynamicStateFn::load(|name| unsafe {
15            mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
16        });
17        Self { fp }
18    }
19
20    /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdSetCullModeEXT.html>
21    #[inline]
22    pub unsafe fn cmd_set_cull_mode(
23        &self,
24        command_buffer: vk::CommandBuffer,
25        cull_mode: vk::CullModeFlags,
26    ) {
27        (self.fp.cmd_set_cull_mode_ext)(command_buffer, cull_mode)
28    }
29
30    /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdSetFrontFaceEXT.html>
31    #[inline]
32    pub unsafe fn cmd_set_front_face(
33        &self,
34        command_buffer: vk::CommandBuffer,
35        front_face: vk::FrontFace,
36    ) {
37        (self.fp.cmd_set_front_face_ext)(command_buffer, front_face)
38    }
39
40    /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdSetPrimitiveTopologyEXT.html>
41    #[inline]
42    pub unsafe fn cmd_set_primitive_topology(
43        &self,
44        command_buffer: vk::CommandBuffer,
45        primitive_topology: vk::PrimitiveTopology,
46    ) {
47        (self.fp.cmd_set_primitive_topology_ext)(command_buffer, primitive_topology)
48    }
49
50    /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdSetViewportWithCountEXT.html>
51    #[inline]
52    pub unsafe fn cmd_set_viewport_with_count(
53        &self,
54        command_buffer: vk::CommandBuffer,
55        viewports: &[vk::Viewport],
56    ) {
57        (self.fp.cmd_set_viewport_with_count_ext)(
58            command_buffer,
59            viewports.len() as u32,
60            viewports.as_ptr(),
61        )
62    }
63
64    /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdSetScissorWithCountEXT.html>
65    #[inline]
66    pub unsafe fn cmd_set_scissor_with_count(
67        &self,
68        command_buffer: vk::CommandBuffer,
69        scissors: &[vk::Rect2D],
70    ) {
71        (self.fp.cmd_set_scissor_with_count_ext)(
72            command_buffer,
73            scissors.len() as u32,
74            scissors.as_ptr(),
75        )
76    }
77
78    /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdBindVertexBuffers2EXT.html>
79    #[inline]
80    pub unsafe fn cmd_bind_vertex_buffers2(
81        &self,
82        command_buffer: vk::CommandBuffer,
83        first_binding: u32,
84        buffers: &[vk::Buffer],
85        offsets: &[vk::DeviceSize],
86        sizes: Option<&[vk::DeviceSize]>,
87        strides: Option<&[vk::DeviceSize]>,
88    ) {
89        assert_eq!(offsets.len(), buffers.len());
90        let p_sizes = if let Some(sizes) = sizes {
91            assert_eq!(sizes.len(), buffers.len());
92            sizes.as_ptr()
93        } else {
94            ptr::null()
95        };
96        let p_strides = if let Some(strides) = strides {
97            assert_eq!(strides.len(), buffers.len());
98            strides.as_ptr()
99        } else {
100            ptr::null()
101        };
102        (self.fp.cmd_bind_vertex_buffers2_ext)(
103            command_buffer,
104            first_binding,
105            buffers.len() as u32,
106            buffers.as_ptr(),
107            offsets.as_ptr(),
108            p_sizes,
109            p_strides,
110        )
111    }
112
113    /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdSetDepthTestEnableEXT.html>
114    #[inline]
115    pub unsafe fn cmd_set_depth_test_enable(
116        &self,
117        command_buffer: vk::CommandBuffer,
118        depth_test_enable: bool,
119    ) {
120        (self.fp.cmd_set_depth_test_enable_ext)(command_buffer, depth_test_enable.into())
121    }
122
123    /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdSetDepthWriteEnableEXT.html>
124    #[inline]
125    pub unsafe fn cmd_set_depth_write_enable(
126        &self,
127        command_buffer: vk::CommandBuffer,
128        depth_write_enable: bool,
129    ) {
130        (self.fp.cmd_set_depth_write_enable_ext)(command_buffer, depth_write_enable.into())
131    }
132
133    /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdSetDepthCompareOpEXT.html>
134    #[inline]
135    pub unsafe fn cmd_set_depth_compare_op(
136        &self,
137        command_buffer: vk::CommandBuffer,
138        depth_compare_op: vk::CompareOp,
139    ) {
140        (self.fp.cmd_set_depth_compare_op_ext)(command_buffer, depth_compare_op)
141    }
142
143    /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdSetDepthBoundsTestEnableEXT.html>
144    #[inline]
145    pub unsafe fn cmd_set_depth_bounds_test_enable(
146        &self,
147        command_buffer: vk::CommandBuffer,
148        depth_bounds_test_enable: bool,
149    ) {
150        (self.fp.cmd_set_depth_bounds_test_enable_ext)(
151            command_buffer,
152            depth_bounds_test_enable.into(),
153        )
154    }
155
156    /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdSetStencilTestEnableEXT.html>
157    #[inline]
158    pub unsafe fn cmd_set_stencil_test_enable(
159        &self,
160        command_buffer: vk::CommandBuffer,
161        stencil_test_enable: bool,
162    ) {
163        (self.fp.cmd_set_stencil_test_enable_ext)(command_buffer, stencil_test_enable.into())
164    }
165
166    /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdSetStencilOpEXT.html>
167    #[inline]
168    pub unsafe fn cmd_set_stencil_op(
169        &self,
170        command_buffer: vk::CommandBuffer,
171        face_mask: vk::StencilFaceFlags,
172        fail_op: vk::StencilOp,
173        pass_op: vk::StencilOp,
174        depth_fail_op: vk::StencilOp,
175        compare_op: vk::CompareOp,
176    ) {
177        (self.fp.cmd_set_stencil_op_ext)(
178            command_buffer,
179            face_mask,
180            fail_op,
181            pass_op,
182            depth_fail_op,
183            compare_op,
184        )
185    }
186
187    #[inline]
188    pub const fn name() -> &'static CStr {
189        vk::ExtExtendedDynamicStateFn::name()
190    }
191
192    #[inline]
193    pub fn fp(&self) -> &vk::ExtExtendedDynamicStateFn {
194        &self.fp
195    }
196}