Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,182 changes: 687 additions & 495 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ difftest-types = { path = "tests/difftests/types" }
tracing = "0.1"
tracing-subscriber = { version = "0.3.20", features = ["env-filter", "json"] }
num-traits = { version = "0.2.15", default-features = false }
glam = { version = ">=0.30.8", default-features = false }
libm = { version = "0.2.5", default-features = false }
bytemuck = { version = "1.23", features = ["derive"] }

Expand Down
22 changes: 18 additions & 4 deletions crates/spirv-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,30 @@ spirv-std-types.workspace = true
spirv-std-macros.workspace = true
bitflags = "1.3.2"
bytemuck = { workspace = true, optional = true }
glam_0_33 = { package = "glam", version = "0.33.0", optional = true, default-features = false, features = ["u32", "i32", "f64"] }
glam_0_32 = { package = "glam", version = "0.32.0", optional = true, default-features = false }
glam_0_31 = { package = "glam", version = "0.31.0", optional = true, default-features = false }
glam_0_30 = { package = "glam", version = "0.30.8", optional = true, default-features = false }

[target.'cfg(target_arch = "spirv")'.dependencies]
num-traits = { workspace = true, features = ["libm"] }
glam = { workspace = true, features = ["libm"] }
libm = { workspace = true }
glam_0_33 = { package = "glam", version = "0.33.0", optional = true, default-features = false, features = ["libm"] }
glam_0_32 = { package = "glam", version = "0.32.0", optional = true, default-features = false, features = ["libm"] }
glam_0_31 = { package = "glam", version = "0.31.0", optional = true, default-features = false, features = ["libm"] }
glam_0_30 = { package = "glam", version = "0.30.8", optional = true, default-features = false, features = ["libm"] }

[target.'cfg(not(target_arch = "spirv"))'.dependencies]
num-traits = { workspace = true, default-features = true }
glam = { workspace = true, default-features = true }
glam_0_33 = { package = "glam", version = "0.33.0", optional = true, default-features = false, features = ["std"] }
glam_0_32 = { package = "glam", version = "0.32.0", optional = true, default-features = false, features = ["std"] }
glam_0_31 = { package = "glam", version = "0.31.0", optional = true, default-features = false, features = ["std"] }
glam_0_30 = { package = "glam", version = "0.30.8", optional = true, default-features = false, features = ["std"] }

[features]
default = []
bytemuck = ["dep:bytemuck", "glam/bytemuck"]
default = ["glam_0_33"]
bytemuck = ["dep:bytemuck", "glam_0_30?/bytemuck", "glam_0_31?/bytemuck", "glam_0_32?/bytemuck", "glam_0_33?/bytemuck"]
glam_0_33 = ["dep:glam_0_33"]
glam_0_32 = ["dep:glam_0_32"]
glam_0_31 = ["dep:glam_0_31"]
glam_0_30 = ["dep:glam_0_30"]
2 changes: 1 addition & 1 deletion crates/spirv-std/src/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
//! no additional safety checks beyond type-checking.
#[cfg(target_arch = "spirv")]
use crate::Integer;
use crate::glam::UVec2;
use crate::{Scalar, SignedInteger, UnsignedInteger, Vector};
#[cfg(target_arch = "spirv")]
use core::arch::asm;
use glam::UVec2;

mod atomics;
mod barrier;
Expand Down
2 changes: 1 addition & 1 deletion crates/spirv-std/src/arch/derivative.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::glam::{Vec2, Vec3, Vec3A, Vec4};
use crate::sealed::Sealed;
use glam::{Vec2, Vec3, Vec3A, Vec4};

#[cfg(target_arch = "spirv")]
macro_rules! deriv_fn {
Expand Down
4 changes: 2 additions & 2 deletions crates/spirv-std/src/arch/subgroup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use crate::{Float, Integer, ScalarComposite, ScalarOrVector, SignedInteger, Unsi
#[cfg(target_arch = "spirv")]
const SUBGROUP: u32 = Scope::Subgroup as u32;

/// `SubgroupMask` is a [`glam::UVec4`] representing a bitmask of all invocations within a subgroup.
/// `SubgroupMask` is a [`crate::glam::UVec4`] representing a bitmask of all invocations within a subgroup.
/// Mostly used in group ballot operations.
pub type SubgroupMask = glam::UVec4;
pub type SubgroupMask = crate::glam::UVec4;

/// Defines the class of group operation.
#[non_exhaustive]
Expand Down
4 changes: 2 additions & 2 deletions crates/spirv-std/src/float.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Traits and helper functions related to floats.

use crate::glam::{Vec2, Vec4};
#[cfg(target_arch = "spirv")]
use core::arch::asm;
use glam::{Vec2, Vec4};

/// Converts two f32 values (floats) into two f16 values (halfs). The result is a u32, with the low
/// 16 bits being the first f16, and the high 16 bits being the second f16.
Expand Down Expand Up @@ -45,7 +45,7 @@ pub fn f16x2_to_vec2(int: u32) -> Vec2 {
/// for u16 not being universal - the upper 16 bits will always be zero.
#[spirv_std_macros::gpu_only]
pub fn f32_to_f16(float: f32) -> u32 {
vec2_to_f16x2(glam::Vec2::new(float, 0.))
vec2_to_f16x2(crate::glam::Vec2::new(float, 0.))
}

/// Converts an f16 (half) into an f32 (float). The parameter is a u32, due to GPU support for u16
Expand Down
1 change: 1 addition & 0 deletions crates/spirv-std/src/image/params.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::{Arrayed, Dimensionality, ImageFormat};
use crate::glam;
use crate::{Integer, Scalar, Vector, VectorTruncateInto};

/// Marker trait for arguments that accept single scalar values or vectors
Expand Down
2 changes: 1 addition & 1 deletion crates/spirv-std/src/indirect_command.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Indirect command structs from vulkan

use glam::UVec3;
use crate::glam::UVec3;

/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkDeviceSize.html>
pub type DeviceSize = u64;
Expand Down
19 changes: 18 additions & 1 deletion crates/spirv-std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,24 @@ pub use scalar_or_vector::*;
pub use typed_buffer::*;
pub use vector::*;

pub use glam;
#[cfg(feature = "glam_0_30")]
pub use ::glam_0_30 as glam;
#[cfg(feature = "glam_0_31")]
pub use ::glam_0_31 as glam;
#[cfg(feature = "glam_0_32")]
pub use ::glam_0_32 as glam;
#[cfg(feature = "glam_0_33")]
pub use ::glam_0_33 as glam;

#[cfg(not(any(
feature = "glam_0_33",
feature = "glam_0_32",
feature = "glam_0_31",
feature = "glam_0_30"
)))]
compile_error!(
"Crate `spirv-std` needs at least one one of it's `glam*` features enabled to select which glam version to use"
);
Comment on lines +119 to +136

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using cfg_select! macro for selecting the version of glam to import would solve docs issue in much more natural and ergonomic way.

Simply select the newest version first with fallbacks to the older version and the wildcard branch at the end will produce compiler error if user didn't select anything.


#[cfg(all(not(test), target_arch = "spirv"))]
#[panic_handler]
Expand Down
2 changes: 1 addition & 1 deletion crates/spirv-std/src/matrix.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! a set of common SPIR-V Matrices, used for intrinsics

use crate::glam::{Affine3A, Mat3, Mat3A, Mat4, Vec3, Vec3A};
use core::fmt::{Debug, Display, Formatter};
use glam::{Affine3A, Mat3, Mat3A, Mat4, Vec3, Vec3A};

/// A Matrix with 4 columns of [`Vec3`], very similar to glam's [`Affine3A`].
///
Expand Down
2 changes: 1 addition & 1 deletion crates/spirv-std/src/ray_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
// NOTE(eddyb) "&-masking with zero", likely due to `NONE = 0` in `bitflags!`.
#![allow(clippy::bad_bit_mask)]

use crate::glam::{UVec2, Vec2, Vec3};
use crate::matrix::Matrix4x3;
#[cfg(target_arch = "spirv")]
use core::arch::asm;
use glam::{UVec2, Vec2, Vec3};

/// An acceleration structure type which is an opaque reference to an
/// acceleration structure handle as defined in the client API specification.
Expand Down
3 changes: 2 additions & 1 deletion crates/spirv-std/src/vector.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! Traits related to vectors.

use crate::glam;
use crate::glam::{Vec3Swizzles, Vec4Swizzles};
use crate::sealed::Sealed;
use crate::{Scalar, ScalarComposite, ScalarOrVector, ScalarOrVectorTransform};
use core::num::NonZeroUsize;
use glam::{Vec3Swizzles, Vec4Swizzles};

/// Abstract trait representing a SPIR-V vector type.
///
Expand Down
1 change: 1 addition & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ deny = [
# Each entry the name of a crate and a version range. If version is
# not specified, all versions will be matched.
#{ name = "ansi_term", version = "=0.11.0" },
{ crate = "glam", wrappers = ["spirv-std"] }
]


Expand Down
5 changes: 4 additions & 1 deletion tests/compiletests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ fn main() {
let workspace_root = tests_dir.parent().unwrap().parent().unwrap();
let original_target_dir = workspace_root.join("target");
let deps_target_dir = original_target_dir.join("compiletest-deps");
let target_spec_dir = original_target_dir.join("compiletest-target-spec");
let compiletest_build_dir = original_target_dir.join("compiletest-results");

// HACK(eddyb) force `compiletest` to pass `ui/...` relative paths to `rustc`,
Expand All @@ -76,6 +77,7 @@ fn main() {
tests_dir,
compiletest_build_dir,
deps_target_dir,
target_spec_dir,
codegen_backend_path,
};

Expand All @@ -87,6 +89,7 @@ struct Runner {
tests_dir: PathBuf,
compiletest_build_dir: PathBuf,
deps_target_dir: PathBuf,
target_spec_dir: PathBuf,
codegen_backend_path: PathBuf,
}

Expand Down Expand Up @@ -159,7 +162,7 @@ impl Runner {
let target = SpirvTarget::parse(env).unwrap();
let rustc_version = query_rustc_version(None).unwrap();
let target_spec =
TargetSpecVersion::target_arg(rustc_version, &target, &self.deps_target_dir)
TargetSpecVersion::target_arg(rustc_version, &target, &self.target_spec_dir)
.unwrap();

let libs = self.build_deps(&target, &target_spec);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ LL | debug_printf!("%v2f", 11.0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `spirv_std::Vector<f32, 2>` is not implemented for `{float}`
|
help: the trait `spirv_std::Vector<f32, 2>` is implemented for `Vec2`
--> $SPIRV_STD_SRC/vector.rs:70:12
::: $SPIRV_STD_SRC/vector.rs:92:1
--> $SPIRV_STD_SRC/vector.rs:71:12
::: $SPIRV_STD_SRC/vector.rs:93:1
|
= note: in this macro invocation
note: required by a bound in `spirv_std::debug_printf::assert_is_vector`
Expand Down
Loading
Loading