Skip to content

Commit

Permalink
project: add optional bytemuck dependency to mark structs as Pod
Browse files Browse the repository at this point in the history
  • Loading branch information
Firestar99 committed Oct 14, 2024
1 parent a361e8f commit ab3254a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/spirv-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ unexpected_cfgs = { level = "allow", check-cfg = ['cfg(target_arch, values("spir
spirv-std-types.workspace = true
spirv-std-macros.workspace = true
bitflags = "1.2.1"
bytemuck = { version = "1.18.0", features = ["derive"], optional = true }

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

[features]
default = []
bytemuck = ["dep:bytemuck", "glam/bytemuck"]
2 changes: 2 additions & 0 deletions crates/spirv-std/src/arch/subgroup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const SUBGROUP: u32 = Scope::Subgroup as u32;

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

/// Defines the class of group operation.
Expand Down
7 changes: 6 additions & 1 deletion crates/spirv-std/src/indirect_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub type DeviceAddress = u64;
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkDrawIndirectCommand.html>
#[repr(C)]
#[derive(Copy, Clone, Debug, Default)]
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Zeroable, bytemuck::Pod))]
pub struct DrawIndirectCommand {
/// vertexCount is the number of vertices to draw.
pub vertex_count: u32,
Expand All @@ -29,6 +30,7 @@ pub struct DrawIndirectCommand {
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkDrawIndexedIndirectCommand.html>
#[repr(C)]
#[derive(Copy, Clone, Debug, Default)]
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Zeroable, bytemuck::Pod))]
pub struct DrawIndexedIndirectCommand {
/// indexCount is the number of vertices to draw.
pub index_count: u32,
Expand All @@ -47,6 +49,7 @@ pub struct DrawIndexedIndirectCommand {
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkDispatchIndirectCommand.html>
#[repr(C)]
#[derive(Copy, Clone, Debug, Default)]
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Zeroable, bytemuck::Pod))]
pub struct DispatchIndirectCommand {
/// x is the number of local workgroups to dispatch in the X dimension.
pub x: u32,
Expand Down Expand Up @@ -81,6 +84,7 @@ impl From<DispatchIndirectCommand> for UVec3 {
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkDrawMeshTasksIndirectCommandEXT.html>
#[repr(C)]
#[derive(Copy, Clone, Debug, Default)]
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Zeroable, bytemuck::Pod))]
pub struct DrawMeshTasksIndirectCommandEXT {
/// groupCountX is the number of local workgroups to dispatch in the X dimension.
pub group_count_x: u32,
Expand Down Expand Up @@ -115,6 +119,7 @@ impl From<DrawMeshTasksIndirectCommandEXT> for UVec3 {
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkTraceRaysIndirectCommandKHR.html>
#[repr(C)]
#[derive(Copy, Clone, Debug, Default)]
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Zeroable, bytemuck::Pod))]
pub struct TraceRaysIndirectCommandKHR {
/// width is the width of the ray trace query dimensions.
pub width: u32,
Expand Down Expand Up @@ -149,7 +154,7 @@ impl From<TraceRaysIndirectCommandKHR> for UVec3 {
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkTraceRaysIndirectCommand2KHR.html>
#[repr(C)]
#[derive(Copy, Clone, Debug, Default)]
#[must_use]
#[cfg_attr(feature = "bytemuck", derive(bytemuck::AnyBitPattern))]
pub struct TraceRaysIndirectCommand2KHR {
/// raygenShaderRecordAddress is a `VkDeviceAddress` of the ray generation shader binding table record used by this command.
pub raygen_shader_record_address: DeviceAddress,
Expand Down
2 changes: 2 additions & 0 deletions crates/spirv-std/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub enum Scope {
bitflags::bitflags! {
/// Memory semantics to determine how some operations should function - used when calling such
/// configurable operations.
#[repr(transparent)]
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Zeroable, bytemuck::Pod))]
pub struct Semantics: u32 {
/// No memory semantics.
const NONE = 0;
Expand Down
2 changes: 2 additions & 0 deletions crates/spirv-std/src/ray_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ bitflags::bitflags! {
/// `NO_OPAQUE`, `CULL_OPAQUE`, `CULL_NO_OPAQUE`, only one of
/// `CULL_BACK_FACING_TRIANGLES` and `CULL_FRONT_FACING_TRIANGLES` may
/// be set.
#[repr(transparent)]
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Zeroable, bytemuck::Pod))]
pub struct RayFlags: u32 {
/// No flags specified.
const NONE = 0;
Expand Down
2 changes: 1 addition & 1 deletion examples/shaders/shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ repository.workspace = true

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

0 comments on commit ab3254a

Please sign in to comment.