spirv_std/indirect_command.rs
1//! Indirect command structs from vulkan
2
3use glam::UVec3;
4
5/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkDeviceSize.html>
6pub type DeviceSize = u64;
7
8/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkDeviceAddress.html>
9pub type DeviceAddress = u64;
10
11/// Structure specifying an indirect drawing command
12///
13/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkDrawIndirectCommand.html>
14#[repr(C)]
15#[derive(Copy, Clone, Debug, Default)]
16#[cfg_attr(feature = "bytemuck", derive(bytemuck::Zeroable, bytemuck::Pod))]
17pub struct DrawIndirectCommand {
18 /// vertexCount is the number of vertices to draw.
19 pub vertex_count: u32,
20 /// instanceCount is the number of instances to draw.
21 pub instance_count: u32,
22 /// firstVertex is the index of the first vertex to draw.
23 pub first_vertex: u32,
24 /// firstInstance is the instance ID of the first instance to draw.
25 pub first_instance: u32,
26}
27
28/// Structure specifying an indexed indirect drawing command
29///
30/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkDrawIndexedIndirectCommand.html>
31#[repr(C)]
32#[derive(Copy, Clone, Debug, Default)]
33#[cfg_attr(feature = "bytemuck", derive(bytemuck::Zeroable, bytemuck::Pod))]
34pub struct DrawIndexedIndirectCommand {
35 /// indexCount is the number of vertices to draw.
36 pub index_count: u32,
37 /// instanceCount is the number of instances to draw.
38 pub instance_count: u32,
39 /// firstIndex is the base index within the index buffer.
40 pub first_index: u32,
41 /// vertexOffset is the value added to the vertex index before indexing into the vertex buffer.
42 pub vertex_offset: i32,
43 /// firstInstance is the instance ID of the first instance to draw.
44 pub first_instance: u32,
45}
46
47/// Structure specifying an indirect dispatching command
48///
49/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkDispatchIndirectCommand.html>
50#[repr(C)]
51#[derive(Copy, Clone, Debug, Default)]
52#[cfg_attr(feature = "bytemuck", derive(bytemuck::Zeroable, bytemuck::Pod))]
53pub struct DispatchIndirectCommand {
54 /// x is the number of local workgroups to dispatch in the X dimension.
55 pub x: u32,
56 /// y is the number of local workgroups to dispatch in the Y dimension.
57 pub y: u32,
58 /// z is the number of local workgroups to dispatch in the Z dimension.
59 pub z: u32,
60}
61
62impl From<UVec3> for DispatchIndirectCommand {
63 fn from(v: UVec3) -> Self {
64 Self {
65 x: v.x,
66 y: v.y,
67 z: v.z,
68 }
69 }
70}
71
72impl From<DispatchIndirectCommand> for UVec3 {
73 fn from(v: DispatchIndirectCommand) -> Self {
74 Self {
75 x: v.x,
76 y: v.y,
77 z: v.z,
78 }
79 }
80}
81
82/// Structure specifying a mesh tasks draw indirect command
83///
84/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkDrawMeshTasksIndirectCommandEXT.html>
85#[repr(C)]
86#[derive(Copy, Clone, Debug, Default)]
87#[cfg_attr(feature = "bytemuck", derive(bytemuck::Zeroable, bytemuck::Pod))]
88pub struct DrawMeshTasksIndirectCommandEXT {
89 /// groupCountX is the number of local workgroups to dispatch in the X dimension.
90 pub group_count_x: u32,
91 /// groupCountY is the number of local workgroups to dispatch in the Y dimension.
92 pub group_count_y: u32,
93 /// groupCountZ is the number of local workgroups to dispatch in the Z dimension.
94 pub group_count_z: u32,
95}
96
97impl From<UVec3> for DrawMeshTasksIndirectCommandEXT {
98 fn from(v: UVec3) -> Self {
99 Self {
100 group_count_x: v.x,
101 group_count_y: v.y,
102 group_count_z: v.z,
103 }
104 }
105}
106
107impl From<DrawMeshTasksIndirectCommandEXT> for UVec3 {
108 fn from(v: DrawMeshTasksIndirectCommandEXT) -> Self {
109 Self {
110 x: v.group_count_x,
111 y: v.group_count_y,
112 z: v.group_count_z,
113 }
114 }
115}
116
117/// Structure specifying the parameters of an indirect ray tracing command
118///
119/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkTraceRaysIndirectCommandKHR.html>
120#[repr(C)]
121#[derive(Copy, Clone, Debug, Default)]
122#[cfg_attr(feature = "bytemuck", derive(bytemuck::Zeroable, bytemuck::Pod))]
123pub struct TraceRaysIndirectCommandKHR {
124 /// width is the width of the ray trace query dimensions.
125 pub width: u32,
126 /// height is height of the ray trace query dimensions.
127 pub height: u32,
128 /// depth is depth of the ray trace query dimensions.
129 pub depth: u32,
130}
131
132impl From<UVec3> for TraceRaysIndirectCommandKHR {
133 fn from(v: UVec3) -> Self {
134 Self {
135 width: v.x,
136 height: v.y,
137 depth: v.z,
138 }
139 }
140}
141
142impl From<TraceRaysIndirectCommandKHR> for UVec3 {
143 fn from(v: TraceRaysIndirectCommandKHR) -> Self {
144 Self {
145 x: v.width,
146 y: v.height,
147 z: v.depth,
148 }
149 }
150}
151
152/// Structure specifying the parameters of an indirect trace ray command with indirect shader binding tables
153///
154/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkTraceRaysIndirectCommand2KHR.html>
155#[repr(C)]
156#[derive(Copy, Clone, Debug, Default)]
157#[cfg_attr(feature = "bytemuck", derive(bytemuck::AnyBitPattern))]
158pub struct TraceRaysIndirectCommand2KHR {
159 /// raygenShaderRecordAddress is a `VkDeviceAddress` of the ray generation shader binding table record used by this command.
160 pub raygen_shader_record_address: DeviceAddress,
161 /// raygenShaderRecordSize is a `VkDeviceSize` number of bytes corresponding to the ray generation shader binding table record at base address raygenShaderRecordAddress.
162 pub raygen_shader_record_size: DeviceSize,
163 /// missShaderBindingTableAddress is a `VkDeviceAddress` of the first record in the miss shader binding table used by this command.
164 pub miss_shader_binding_table_address: DeviceAddress,
165 /// missShaderBindingTableSize is a `VkDeviceSize` number of bytes corresponding to the total size of the miss shader binding table at missShaderBindingTableAddress that may be accessed by this command.
166 pub miss_shader_binding_table_size: DeviceSize,
167 /// missShaderBindingTableStride is a `VkDeviceSize` number of bytes between records of the miss shader binding table.
168 pub miss_shader_binding_table_stride: DeviceSize,
169 /// hitShaderBindingTableAddress is a `VkDeviceAddress` of the first record in the hit shader binding table used by this command.
170 pub hit_shader_binding_table_address: DeviceAddress,
171 /// hitShaderBindingTableSize is a `VkDeviceSize` number of bytes corresponding to the total size of the hit shader binding table at hitShaderBindingTableAddress that may be accessed by this command.
172 pub hit_shader_binding_table_size: DeviceSize,
173 /// hitShaderBindingTableStride is a `VkDeviceSize` number of bytes between records of the hit shader binding table.
174 pub hit_shader_binding_table_stride: DeviceSize,
175 /// callableShaderBindingTableAddress is a `VkDeviceAddress` of the first record in the callable shader binding table used by this command.
176 pub callable_shader_binding_table_address: DeviceAddress,
177 /// callableShaderBindingTableSize is a `VkDeviceSize` number of bytes corresponding to the total size of the callable shader binding table at callableShaderBindingTableAddress that may be accessed by this command.
178 pub callable_shader_binding_table_size: DeviceSize,
179 /// callableShaderBindingTableStride is a `VkDeviceSize` number of bytes between records of the callable shader binding table.
180 pub callable_shader_binding_table_stride: DeviceSize,
181 /// width is the width of the ray trace query dimensions.
182 pub width: u32,
183 /// height is height of the ray trace query dimensions.
184 pub height: u32,
185 /// depth is depth of the ray trace query dimensions.
186 pub depth: u32,
187}