Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
bitshifter committed Feb 6, 2024
1 parent bcbc026 commit 1332b6a
Show file tree
Hide file tree
Showing 36 changed files with 214 additions and 142 deletions.
32 changes: 29 additions & 3 deletions codegen/templates/mat.rs.tera
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,9 @@ impl {{ self_t }} {
pub fn from_mat4(m: {{ mat4_t }}) -> Self {
{% if self_t == "Mat3A" %}
Self::from_cols(
m.x_axis.into(),
m.y_axis.into(),
m.z_axis.into(),
m.x_axis.xyz().into(),
m.y_axis.xyz().into(),
m.z_axis.xyz().into(),
)
{% else %}
Self::from_cols(
Expand Down Expand Up @@ -2278,6 +2278,32 @@ impl From<Mat3> for Mat3A {
}
{% endif %}

{% if self_t == "Mat4" %}
impl From<Mat4A> for Mat4 {
#[inline]
fn from(m: Mat4A) -> Self {
Self {
x_axis: m.x_axis.into(),
y_axis: m.y_axis.into(),
z_axis: m.z_axis.into(),
w_axis: m.w_axis.into(),
}
}
}
{% elif self_t == "Mat4A" %}
impl From<Mat4> for Mat4A {
#[inline]
fn from(m: Mat4) -> Self {
Self {
x_axis: m.x_axis.into(),
y_axis: m.y_axis.into(),
z_axis: m.z_axis.into(),
w_axis: m.w_axis.into(),
}
}
}
{% endif %}

impl Sum<Self> for {{ self_t }} {
fn sum<I>(iter: I) -> Self
where
Expand Down
46 changes: 33 additions & 13 deletions codegen/templates/vec.rs.tera
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
{% endif %}
{% set vec2_t = "Vec2" %}
{% set vec3_t = "Vec3" %}
{% set vec3a_t = "Vec3A" %}
{% set vec4_t = "Vec4" %}
{% elif scalar_t == "f64" %}
{% set self_t = "DVec" ~ dim %}
Expand Down Expand Up @@ -144,8 +143,11 @@
{% if self_t != vec3_t %}
{{ vec3_t }},
{% endif %}
{% if dim == 4 and scalar_t == "f32" %}
{{ vec3a_t }},
{% if self_t == "Vec4A" or self_t == "Vec4" %}
Vec3A,
{% endif %}
{% if self_t == "Vec4" %}
Vec4A,
{% endif %}
{% if dim > 2 and self_t != vec4_t %}
{{ vec4_t }},
Expand Down Expand Up @@ -478,11 +480,7 @@ impl {{ self_t }} {
#[inline]
#[must_use]
pub(crate) fn from_vec4(v: {{ vec4_t }}) -> Self {
{% if is_scalar %}
Self { x: v.x, y: v.y, z: v.z }
{% else %}
Self(v.0)
{% endif %}
Self::new(v.x, v.y, v.z)
}

/// Creates a 4D vector from `self` and the given `w` value.
Expand Down Expand Up @@ -512,8 +510,7 @@ impl {{ self_t }} {
#[inline]
#[must_use]
pub fn truncate(self) -> {{ vec3_t }} {
use crate::swizzles::Vec4Swizzles;
self.xyz()
{{ vec3_t }}::new(self.x, self.y, self.z)
}
{% endif %}

Expand Down Expand Up @@ -3066,12 +3063,13 @@ impl From<Vec3> for Vec3A {
}
}

impl From<Vec4> for Vec3A {
{#
impl From<Vec4A> for Vec3A {
/// Creates a [`Vec3A`] from the `x`, `y` and `z` elements of `self` discarding `w`.
///
/// On architectures where SIMD is supported such as SSE2 on `x86_64` this conversion is a noop.
#[inline]
fn from(v: Vec4) -> Self {
fn from(v: Vec4A) -> Self {
{% if is_scalar %}
Self {
x: v.x,
Expand All @@ -3083,6 +3081,7 @@ impl From<Vec4> for Vec3A {
{% endif %}
}
}
#}

impl From<Vec3A> for Vec3 {
#[inline]
Expand Down Expand Up @@ -3116,7 +3115,13 @@ impl From<Vec3A> for Vec3 {
impl From<(Vec3A, f32)> for {{ self_t }} {
#[inline]
fn from((v, w): (Vec3A, f32)) -> Self {
v.extend(w)
{% if is_simd %}
let v = Self(v.0);
v.w = w;
v
{% else %}
Self::new(v.x, v.y, v.z, w)
{% endif %}
}
}

Expand All @@ -3126,6 +3131,21 @@ impl From<(f32, Vec3A)> for {{ self_t }} {
Self::new(x, v.x, v.y, v.z)
}
}
{% if is_align %}
impl From<Vec4> for Vec4A {
#[inline]
fn from(v: Vec4) -> Self {
Self::new(v.x, v.y, v.z, v.w)
}
}
{% else %}
impl From<Vec4A> for Vec4 {
#[inline]
fn from(v: Vec4A) -> Self {
Self::new(v.x, v.y, v.z, v.w)
}
}
{% endif %}
{% endif %}

{% if dim == 3 %}
Expand Down
1 change: 1 addition & 0 deletions src/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub use mat2::{mat2, Mat2};
pub use mat3::{mat3, Mat3};
pub use mat3a::{mat3a, Mat3A};
pub use mat4::{mat4, Mat4};
pub use mat4a::{mat4a, Mat4A};
pub use quat::{quat, Quat};
pub use vec2::{vec2, Vec2};
pub use vec3::{vec3, Vec3};
Expand Down
6 changes: 5 additions & 1 deletion src/f32/coresimd/mat3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ impl Mat3A {
#[inline]
#[must_use]
pub fn from_mat4(m: Mat4) -> Self {
Self::from_cols(m.x_axis.into(), m.y_axis.into(), m.z_axis.into())
Self::from_cols(
m.x_axis.xyz().into(),
m.y_axis.xyz().into(),
m.z_axis.xyz().into(),
)
}

/// Creates a 3D rotation matrix from the given quaternion.
Expand Down
12 changes: 12 additions & 0 deletions src/f32/coresimd/mat4a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,18 @@ impl MulAssign<f32> for Mat4A {
}
}

impl From<Mat4> for Mat4A {
#[inline]
fn from(m: Mat4) -> Self {
Self {
x_axis: m.x_axis.into(),
y_axis: m.y_axis.into(),
z_axis: m.z_axis.into(),
w_axis: m.w_axis.into(),
}
}
}

impl Sum<Self> for Mat4A {
fn sum<I>(iter: I) -> Self
where
Expand Down
12 changes: 1 addition & 11 deletions src/f32/coresimd/vec3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl Vec3A {
#[inline]
#[must_use]
pub(crate) fn from_vec4(v: Vec4) -> Self {
Self(v.0)
Self::new(v.x, v.y, v.z)
}

/// Creates a 4D vector from `self` and the given `w` value.
Expand Down Expand Up @@ -1209,16 +1209,6 @@ impl From<Vec3> for Vec3A {
}
}

impl From<Vec4> for Vec3A {
/// Creates a [`Vec3A`] from the `x`, `y` and `z` elements of `self` discarding `w`.
///
/// On architectures where SIMD is supported such as SSE2 on `x86_64` this conversion is a noop.
#[inline]
fn from(v: Vec4) -> Self {
Self(v.0)
}
}

impl From<Vec3A> for Vec3 {
#[inline]
fn from(v: Vec3A) -> Self {
Expand Down
14 changes: 11 additions & 3 deletions src/f32/coresimd/vec4a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ impl Vec4A {
#[inline]
#[must_use]
pub fn truncate(self) -> Vec3 {
use crate::swizzles::Vec4Swizzles;
self.xyz()
Vec3::new(self.x, self.y, self.z)
}

/// Computes the dot product of `self` and `rhs`.
Expand Down Expand Up @@ -1117,7 +1116,9 @@ impl From<Vec4A> for (f32, f32, f32, f32) {
impl From<(Vec3A, f32)> for Vec4A {
#[inline]
fn from((v, w): (Vec3A, f32)) -> Self {
v.extend(w)
let v = Self(v.0);
v.w = w;
v
}
}

Expand All @@ -1128,6 +1129,13 @@ impl From<(f32, Vec3A)> for Vec4A {
}
}

impl From<Vec4> for Vec4A {
#[inline]
fn from(v: Vec4) -> Self {
Self::new(v.x, v.y, v.z, v.w)
}
}

impl From<(Vec3, f32)> for Vec4A {
#[inline]
fn from((v, w): (Vec3, f32)) -> Self {
Expand Down
12 changes: 12 additions & 0 deletions src/f32/mat4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,18 @@ impl MulAssign<f32> for Mat4 {
}
}

impl From<Mat4A> for Mat4 {
#[inline]
fn from(m: Mat4A) -> Self {
Self {
x_axis: m.x_axis.into(),
y_axis: m.y_axis.into(),
z_axis: m.z_axis.into(),
w_axis: m.w_axis.into(),
}
}
}

impl Sum<Self> for Mat4 {
fn sum<I>(iter: I) -> Self
where
Expand Down
6 changes: 5 additions & 1 deletion src/f32/scalar/mat3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ impl Mat3A {
#[inline]
#[must_use]
pub fn from_mat4(m: Mat4) -> Self {
Self::from_cols(m.x_axis.into(), m.y_axis.into(), m.z_axis.into())
Self::from_cols(
m.x_axis.xyz().into(),
m.y_axis.xyz().into(),
m.z_axis.xyz().into(),
)
}

/// Creates a 3D rotation matrix from the given quaternion.
Expand Down
12 changes: 12 additions & 0 deletions src/f32/scalar/mat4a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,18 @@ impl MulAssign<f32> for Mat4A {
}
}

impl From<Mat4> for Mat4A {
#[inline]
fn from(m: Mat4) -> Self {
Self {
x_axis: m.x_axis.into(),
y_axis: m.y_axis.into(),
z_axis: m.z_axis.into(),
w_axis: m.w_axis.into(),
}
}
}

impl Sum<Self> for Mat4A {
fn sum<I>(iter: I) -> Self
where
Expand Down
20 changes: 1 addition & 19 deletions src/f32/scalar/vec3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,7 @@ impl Vec3A {
#[inline]
#[must_use]
pub(crate) fn from_vec4(v: Vec4) -> Self {
Self {
x: v.x,
y: v.y,
z: v.z,
}
Self::new(v.x, v.y, v.z)
}

/// Creates a 4D vector from `self` and the given `w` value.
Expand Down Expand Up @@ -1327,20 +1323,6 @@ impl From<Vec3> for Vec3A {
}
}

impl From<Vec4> for Vec3A {
/// Creates a [`Vec3A`] from the `x`, `y` and `z` elements of `self` discarding `w`.
///
/// On architectures where SIMD is supported such as SSE2 on `x86_64` this conversion is a noop.
#[inline]
fn from(v: Vec4) -> Self {
Self {
x: v.x,
y: v.y,
z: v.z,
}
}
}

impl From<Vec3A> for Vec3 {
#[inline]
fn from(v: Vec3A) -> Self {
Expand Down
12 changes: 9 additions & 3 deletions src/f32/scalar/vec4a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ impl Vec4A {
#[inline]
#[must_use]
pub fn truncate(self) -> Vec3 {
use crate::swizzles::Vec4Swizzles;
self.xyz()
Vec3::new(self.x, self.y, self.z)
}

/// Computes the dot product of `self` and `rhs`.
Expand Down Expand Up @@ -1331,7 +1330,7 @@ impl From<Vec4A> for (f32, f32, f32, f32) {
impl From<(Vec3A, f32)> for Vec4A {
#[inline]
fn from((v, w): (Vec3A, f32)) -> Self {
v.extend(w)
Self::new(v.x, v.y, v.z, w)
}
}

Expand All @@ -1342,6 +1341,13 @@ impl From<(f32, Vec3A)> for Vec4A {
}
}

impl From<Vec4> for Vec4A {
#[inline]
fn from(v: Vec4) -> Self {
Self::new(v.x, v.y, v.z, v.w)
}
}

impl From<(Vec3, f32)> for Vec4A {
#[inline]
fn from((v, w): (Vec3, f32)) -> Self {
Expand Down
6 changes: 5 additions & 1 deletion src/f32/sse2/mat3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ impl Mat3A {
#[inline]
#[must_use]
pub fn from_mat4(m: Mat4) -> Self {
Self::from_cols(m.x_axis.into(), m.y_axis.into(), m.z_axis.into())
Self::from_cols(
m.x_axis.xyz().into(),
m.y_axis.xyz().into(),
m.z_axis.xyz().into(),
)
}

/// Creates a 3D rotation matrix from the given quaternion.
Expand Down
Loading

0 comments on commit 1332b6a

Please sign in to comment.