Skip to content

Commit ab3254a

Browse files
committed
project: add optional bytemuck dependency to mark structs as Pod
1 parent a361e8f commit ab3254a

File tree

7 files changed

+17
-2
lines changed

7 files changed

+17
-2
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/spirv-std/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ unexpected_cfgs = { level = "allow", check-cfg = ['cfg(target_arch, values("spir
1414
spirv-std-types.workspace = true
1515
spirv-std-macros.workspace = true
1616
bitflags = "1.2.1"
17+
bytemuck = { version = "1.18.0", features = ["derive"], optional = true }
1718

1819
[target.'cfg(target_arch = "spirv")'.dependencies]
1920
num-traits = { workspace = true, features = ["libm"] }
@@ -25,3 +26,4 @@ glam = { workspace = true, default-features = true }
2526

2627
[features]
2728
default = []
29+
bytemuck = ["dep:bytemuck", "glam/bytemuck"]

crates/spirv-std/src/arch/subgroup.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ const SUBGROUP: u32 = Scope::Subgroup as u32;
1313

1414
/// `SubgroupMask` is a [`glam::UVec4`] representing a bitmask of all invocations within a subgroup.
1515
/// Mostly used in group ballot operations.
16+
#[repr(transparent)]
1617
#[derive(Copy, Clone, Default, Eq, PartialEq)]
18+
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Zeroable, bytemuck::Pod))]
1719
pub struct SubgroupMask(pub glam::UVec4);
1820

1921
/// Defines the class of group operation.

crates/spirv-std/src/indirect_command.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub type DeviceAddress = u64;
1313
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkDrawIndirectCommand.html>
1414
#[repr(C)]
1515
#[derive(Copy, Clone, Debug, Default)]
16+
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Zeroable, bytemuck::Pod))]
1617
pub struct DrawIndirectCommand {
1718
/// vertexCount is the number of vertices to draw.
1819
pub vertex_count: u32,
@@ -29,6 +30,7 @@ pub struct DrawIndirectCommand {
2930
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkDrawIndexedIndirectCommand.html>
3031
#[repr(C)]
3132
#[derive(Copy, Clone, Debug, Default)]
33+
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Zeroable, bytemuck::Pod))]
3234
pub struct DrawIndexedIndirectCommand {
3335
/// indexCount is the number of vertices to draw.
3436
pub index_count: u32,
@@ -47,6 +49,7 @@ pub struct DrawIndexedIndirectCommand {
4749
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkDispatchIndirectCommand.html>
4850
#[repr(C)]
4951
#[derive(Copy, Clone, Debug, Default)]
52+
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Zeroable, bytemuck::Pod))]
5053
pub struct DispatchIndirectCommand {
5154
/// x is the number of local workgroups to dispatch in the X dimension.
5255
pub x: u32,
@@ -81,6 +84,7 @@ impl From<DispatchIndirectCommand> for UVec3 {
8184
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkDrawMeshTasksIndirectCommandEXT.html>
8285
#[repr(C)]
8386
#[derive(Copy, Clone, Debug, Default)]
87+
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Zeroable, bytemuck::Pod))]
8488
pub struct DrawMeshTasksIndirectCommandEXT {
8589
/// groupCountX is the number of local workgroups to dispatch in the X dimension.
8690
pub group_count_x: u32,
@@ -115,6 +119,7 @@ impl From<DrawMeshTasksIndirectCommandEXT> for UVec3 {
115119
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkTraceRaysIndirectCommandKHR.html>
116120
#[repr(C)]
117121
#[derive(Copy, Clone, Debug, Default)]
122+
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Zeroable, bytemuck::Pod))]
118123
pub struct TraceRaysIndirectCommandKHR {
119124
/// width is the width of the ray trace query dimensions.
120125
pub width: u32,
@@ -149,7 +154,7 @@ impl From<TraceRaysIndirectCommandKHR> for UVec3 {
149154
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkTraceRaysIndirectCommand2KHR.html>
150155
#[repr(C)]
151156
#[derive(Copy, Clone, Debug, Default)]
152-
#[must_use]
157+
#[cfg_attr(feature = "bytemuck", derive(bytemuck::AnyBitPattern))]
153158
pub struct TraceRaysIndirectCommand2KHR {
154159
/// raygenShaderRecordAddress is a `VkDeviceAddress` of the ray generation shader binding table record used by this command.
155160
pub raygen_shader_record_address: DeviceAddress,

crates/spirv-std/src/memory.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ pub enum Scope {
2929
bitflags::bitflags! {
3030
/// Memory semantics to determine how some operations should function - used when calling such
3131
/// configurable operations.
32+
#[repr(transparent)]
33+
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Zeroable, bytemuck::Pod))]
3234
pub struct Semantics: u32 {
3335
/// No memory semantics.
3436
const NONE = 0;

crates/spirv-std/src/ray_tracing.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ bitflags::bitflags! {
141141
/// `NO_OPAQUE`, `CULL_OPAQUE`, `CULL_NO_OPAQUE`, only one of
142142
/// `CULL_BACK_FACING_TRIANGLES` and `CULL_FRONT_FACING_TRIANGLES` may
143143
/// be set.
144+
#[repr(transparent)]
145+
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Zeroable, bytemuck::Pod))]
144146
pub struct RayFlags: u32 {
145147
/// No flags specified.
146148
const NONE = 0;

examples/shaders/shared/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ repository.workspace = true
99

1010
[dependencies]
1111
spirv-std = { workspace = true }
12-
bytemuck = { version = "1.6.3", features = ["derive"] }
12+
bytemuck = { version = "1.18.0", features = ["derive"] }

0 commit comments

Comments
 (0)