Skip to content

Commit

Permalink
Fix scalar-math compile errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitshifter committed Mar 10, 2024
1 parent 00467fa commit 4352a79
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 33 deletions.
26 changes: 21 additions & 5 deletions codegen/templates/vec.rs.tera
Expand Up @@ -132,8 +132,24 @@
{% set zero = "0" %}
{% endif %}

use crate::{
{{ mask_t }},
{% if bveca_from_type and bveca_from_type == "BVec4A" and is_scalar %}
{% if scalar_t == "f32" %}
#[cfg(feature = "scalar-math")]
use crate::BVec4 as BVec4A;
{% endif %}
#[cfg(not(feature = "scalar-math"))]
use crate::BVec4A;
use crate::{
{% if bveca_from_type and bveca_from_type != mask_t %}
{{ mask_t }},
{% endif %}
{% else %}
use crate::{
{{ mask_t }},
{% if bveca_from_type and bveca_from_type != mask_t %}
{{ bveca_from_type }},
{% endif %}
{% endif %}
{% if self_t != vec2_t %}
{{ vec2_t }},
{% endif %}
Expand Down Expand Up @@ -169,9 +185,6 @@ use crate::{
{% if bvec_from_type != mask_t %}
{{ bvec_from_type }},
{% endif %}
{% if bveca_from_type and bveca_from_type != mask_t %}
{{ bveca_from_type }},
{% endif %}
};

#[cfg(not(target_arch = "spirv"))]
Expand Down Expand Up @@ -3240,6 +3253,9 @@ impl From<{{ bvec_from_type }}> for {{ self_t }} {
}

{% if bveca_from_type %}
{% if bveca_from_type == "BVec4A" %}
#[cfg(not(feature = "scalar-math"))]
{% endif %}
impl From<{{ bveca_from_type }}> for {{ self_t }} {
#[inline]
fn from(v: {{ bveca_from_type }}) -> Self {
Expand Down
2 changes: 2 additions & 0 deletions src/f32/coresimd/vec4.rs
Expand Up @@ -1195,6 +1195,8 @@ impl From<BVec4> for Vec4 {
}
}

#[cfg(not(feature = "scalar-math"))]

impl From<BVec4A> for Vec4 {
#[inline]
fn from(v: BVec4A) -> Self {
Expand Down
9 changes: 8 additions & 1 deletion src/f32/scalar/vec4.rs
@@ -1,6 +1,11 @@
// Generated from vec.rs.tera template. Edit the template, not the generated file.

use crate::{f32::math, BVec4, BVec4A, Vec2, Vec3, Vec3A};
#[cfg(feature = "scalar-math")]
use crate::BVec4 as BVec4A;

#[cfg(not(feature = "scalar-math"))]
use crate::BVec4A;
use crate::{f32::math, BVec4, Vec2, Vec3, Vec3A};

#[cfg(not(target_arch = "spirv"))]
use core::fmt;
Expand Down Expand Up @@ -1390,6 +1395,8 @@ impl From<BVec4> for Vec4 {
}
}

#[cfg(not(feature = "scalar-math"))]

impl From<BVec4A> for Vec4 {
#[inline]
fn from(v: BVec4A) -> Self {
Expand Down
2 changes: 2 additions & 0 deletions src/f32/sse2/vec4.rs
Expand Up @@ -1281,6 +1281,8 @@ impl From<BVec4> for Vec4 {
}
}

#[cfg(not(feature = "scalar-math"))]

impl From<BVec4A> for Vec4 {
#[inline]
fn from(v: BVec4A) -> Self {
Expand Down
2 changes: 2 additions & 0 deletions src/f32/wasm32/vec4.rs
Expand Up @@ -1240,6 +1240,8 @@ impl From<BVec4> for Vec4 {
}
}

#[cfg(not(feature = "scalar-math"))]

impl From<BVec4A> for Vec4 {
#[inline]
fn from(v: BVec4A) -> Self {
Expand Down
6 changes: 5 additions & 1 deletion src/f64/dvec4.rs
@@ -1,6 +1,8 @@
// Generated from vec.rs.tera template. Edit the template, not the generated file.

use crate::{f64::math, BVec4, BVec4A, DVec2, DVec3, IVec4, UVec4, Vec4};
#[cfg(not(feature = "scalar-math"))]
use crate::BVec4A;
use crate::{f64::math, BVec4, DVec2, DVec3, IVec4, UVec4, Vec4};

#[cfg(not(target_arch = "spirv"))]
use core::fmt;
Expand Down Expand Up @@ -1404,6 +1406,8 @@ impl From<BVec4> for DVec4 {
}
}

#[cfg(not(feature = "scalar-math"))]

impl From<BVec4A> for DVec4 {
#[inline]
fn from(v: BVec4A) -> Self {
Expand Down
6 changes: 5 additions & 1 deletion src/i16/i16vec4.rs
@@ -1,6 +1,8 @@
// Generated from vec.rs.tera template. Edit the template, not the generated file.

use crate::{BVec4, BVec4A, I16Vec2, I16Vec3, I64Vec4, IVec4, U16Vec4, U64Vec4, UVec4};
#[cfg(not(feature = "scalar-math"))]
use crate::BVec4A;
use crate::{BVec4, I16Vec2, I16Vec3, I64Vec4, IVec4, U16Vec4, U64Vec4, UVec4};

#[cfg(not(target_arch = "spirv"))]
use core::fmt;
Expand Down Expand Up @@ -1556,6 +1558,8 @@ impl From<BVec4> for I16Vec4 {
}
}

#[cfg(not(feature = "scalar-math"))]

impl From<BVec4A> for I16Vec4 {
#[inline]
fn from(v: BVec4A) -> Self {
Expand Down
6 changes: 5 additions & 1 deletion src/i32/ivec4.rs
@@ -1,6 +1,8 @@
// Generated from vec.rs.tera template. Edit the template, not the generated file.

use crate::{BVec4, BVec4A, I16Vec4, I64Vec4, IVec2, IVec3, U16Vec4, U64Vec4, UVec4};
#[cfg(not(feature = "scalar-math"))]
use crate::BVec4A;
use crate::{BVec4, I16Vec4, I64Vec4, IVec2, IVec3, U16Vec4, U64Vec4, UVec4};

#[cfg(not(target_arch = "spirv"))]
use core::fmt;
Expand Down Expand Up @@ -1552,6 +1554,8 @@ impl From<BVec4> for IVec4 {
}
}

#[cfg(not(feature = "scalar-math"))]

impl From<BVec4A> for IVec4 {
#[inline]
fn from(v: BVec4A) -> Self {
Expand Down
6 changes: 5 additions & 1 deletion src/i64/i64vec4.rs
@@ -1,6 +1,8 @@
// Generated from vec.rs.tera template. Edit the template, not the generated file.

use crate::{BVec4, BVec4A, I16Vec4, I64Vec2, I64Vec3, IVec4, U16Vec4, U64Vec4, UVec4};
#[cfg(not(feature = "scalar-math"))]
use crate::BVec4A;
use crate::{BVec4, I16Vec4, I64Vec2, I64Vec3, IVec4, U16Vec4, U64Vec4, UVec4};

#[cfg(not(target_arch = "spirv"))]
use core::fmt;
Expand Down Expand Up @@ -1548,6 +1550,8 @@ impl From<BVec4> for I64Vec4 {
}
}

#[cfg(not(feature = "scalar-math"))]

impl From<BVec4A> for I64Vec4 {
#[inline]
fn from(v: BVec4A) -> Self {
Expand Down
6 changes: 5 additions & 1 deletion src/u16/u16vec4.rs
@@ -1,6 +1,8 @@
// Generated from vec.rs.tera template. Edit the template, not the generated file.

use crate::{BVec4, BVec4A, I16Vec4, I64Vec4, IVec4, U16Vec2, U16Vec3, U64Vec4, UVec4};
#[cfg(not(feature = "scalar-math"))]
use crate::BVec4A;
use crate::{BVec4, I16Vec4, I64Vec4, IVec4, U16Vec2, U16Vec3, U64Vec4, UVec4};

#[cfg(not(target_arch = "spirv"))]
use core::fmt;
Expand Down Expand Up @@ -1420,6 +1422,8 @@ impl From<BVec4> for U16Vec4 {
}
}

#[cfg(not(feature = "scalar-math"))]

impl From<BVec4A> for U16Vec4 {
#[inline]
fn from(v: BVec4A) -> Self {
Expand Down
6 changes: 5 additions & 1 deletion src/u32/uvec4.rs
@@ -1,6 +1,8 @@
// Generated from vec.rs.tera template. Edit the template, not the generated file.

use crate::{BVec4, BVec4A, I16Vec4, I64Vec4, IVec4, U16Vec4, U64Vec4, UVec2, UVec3};
#[cfg(not(feature = "scalar-math"))]
use crate::BVec4A;
use crate::{BVec4, I16Vec4, I64Vec4, IVec4, U16Vec4, U64Vec4, UVec2, UVec3};

#[cfg(not(target_arch = "spirv"))]
use core::fmt;
Expand Down Expand Up @@ -1418,6 +1420,8 @@ impl From<BVec4> for UVec4 {
}
}

#[cfg(not(feature = "scalar-math"))]

impl From<BVec4A> for UVec4 {
#[inline]
fn from(v: BVec4A) -> Self {
Expand Down
6 changes: 5 additions & 1 deletion src/u64/u64vec4.rs
@@ -1,6 +1,8 @@
// Generated from vec.rs.tera template. Edit the template, not the generated file.

use crate::{BVec4, BVec4A, I16Vec4, I64Vec4, IVec4, U16Vec4, U64Vec2, U64Vec3, UVec4};
#[cfg(not(feature = "scalar-math"))]
use crate::BVec4A;
use crate::{BVec4, I16Vec4, I64Vec4, IVec4, U16Vec4, U64Vec2, U64Vec3, UVec4};

#[cfg(not(target_arch = "spirv"))]
use core::fmt;
Expand Down Expand Up @@ -1416,6 +1418,8 @@ impl From<BVec4> for U64Vec4 {
}
}

#[cfg(not(feature = "scalar-math"))]

impl From<BVec4A> for U64Vec4 {
#[inline]
fn from(v: BVec4A) -> Self {
Expand Down
44 changes: 24 additions & 20 deletions tests/vec4.rs
Expand Up @@ -64,26 +64,30 @@ macro_rules! impl_vec4_tests {
$vec4::new(0 as $t, 0 as $t, 1 as $t, 0 as $t),
glam::BVec4::new(false, false, true, false).into()
);
assert_eq!(
$vec4::new(0 as $t, 0 as $t, 0 as $t, 1 as $t),
glam::BVec4::new(false, false, false, true).into()
);
assert_eq!(
$vec4::new(1 as $t, 0 as $t, 0 as $t, 0 as $t),
glam::BVec4A::new(true, false, false, false).into()
);
assert_eq!(
$vec4::new(0 as $t, 1 as $t, 0 as $t, 0 as $t),
glam::BVec4A::new(false, true, false, false).into()
);
assert_eq!(
$vec4::new(0 as $t, 0 as $t, 1 as $t, 0 as $t),
glam::BVec4A::new(false, false, true, false).into()
);
assert_eq!(
$vec4::new(0 as $t, 0 as $t, 0 as $t, 1 as $t),
glam::BVec4A::new(false, false, false, true).into()
);

#[cfg(not(feature = "scalar-math"))]
{
assert_eq!(
$vec4::new(0 as $t, 0 as $t, 0 as $t, 1 as $t),
glam::BVec4::new(false, false, false, true).into()
);
assert_eq!(
$vec4::new(1 as $t, 0 as $t, 0 as $t, 0 as $t),
glam::BVec4A::new(true, false, false, false).into()
);
assert_eq!(
$vec4::new(0 as $t, 1 as $t, 0 as $t, 0 as $t),
glam::BVec4A::new(false, true, false, false).into()
);
assert_eq!(
$vec4::new(0 as $t, 0 as $t, 1 as $t, 0 as $t),
glam::BVec4A::new(false, false, true, false).into()
);
assert_eq!(
$vec4::new(0 as $t, 0 as $t, 0 as $t, 1 as $t),
glam::BVec4A::new(false, false, false, true).into()
);
}

assert_eq!($vec4::new(1 as $t, 0 as $t, 0 as $t, 0 as $t), $vec4::X);
assert_eq!($vec4::new(0 as $t, 1 as $t, 0 as $t, 0 as $t), $vec4::Y);
Expand Down

0 comments on commit 4352a79

Please sign in to comment.