Skip to content

Commit

Permalink
Merge pull request #30 from xMAC94x/xMAC/update_deps
Browse files Browse the repository at this point in the history
xmac/update deps and cargo clippy and fix CI
  • Loading branch information
zesterer authored May 14, 2024
2 parents 290e14c + b884a0f commit ec083d9
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 74 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Deps
run: sudo apt-get install -y libxkbcommon-x11-dev
- uses: actions/checkout@v2
- name: Build
run: cargo build --verbose
Expand Down
15 changes: 7 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ exclude = [
]

[dependencies]
vek = { version = "0.16", default-features = false, features = [] }
image = { version = "0.24", optional = true }
num_cpus = { version = "1.13", optional = true }
vek = { version = "0.17", default-features = false, features = [] }
image = { version = "0.25", optional = true }
fxhash = { version = "0.2", optional = true }
micromath = { version = "1.1", optional = true }
clipline = "0.1.2"
micromath = { version = "2", optional = true }
clipline = "0.2"

[features]
default = ["std", "image", "par"]
Expand All @@ -28,15 +27,15 @@ libm = ["vek/libm"]
nightly = []
simd = ["vek/repr_simd", "vek/platform_intrinsics"]
image = ["dep:image"]
par = ["std", "num_cpus", "fxhash"]
par = ["std", "fxhash"]
micromath = ["dep:micromath"]

[dev-dependencies]
vek = { version = "0.16", default-features = false, features = ["rgba"] }
vek = { version = "0.17", default-features = false, features = ["rgba"] }
minifb = "0.20"
wavefront = "0.2"
criterion = "0.5"
image = "0.24"
image = "0.25"
derive_more = "0.99"

[lib]
Expand Down
9 changes: 5 additions & 4 deletions src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,9 @@ pub trait Pipeline<'r>: Sized {
};

#[cfg(not(feature = "par"))]
let r = render_seq(self, fetch_vertex, target_size, pixel, depth, msaa_level);
render_seq(self, fetch_vertex, target_size, pixel, depth, msaa_level);
#[cfg(feature = "par")]
let r = render_par(self, fetch_vertex, target_size, pixel, depth, msaa_level);
r
render_par(self, fetch_vertex, target_size, pixel, depth, msaa_level);
}
}

Expand All @@ -320,7 +319,9 @@ fn render_par<'r, Pipe, S, P, D>(

// TODO: Don't pull all vertices at once
let vertices = fetch_vertex.collect::<Vec<_>>();
let threads = num_cpus::get();
let threads = std::thread::available_parallelism()
.map(|cpu| cpu.into())
.unwrap_or(1usize);
let row = AtomicUsize::new(0);

const FRAGMENTS_PER_GROUP: usize = 20_000; // Magic number, maybe make this configurable?
Expand Down
40 changes: 19 additions & 21 deletions src/rasterizer/lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ impl Rasterizer for Lines {
let screen_min = Vec2::<usize>::from(tgt_min).map(|e| e as f32);
let screen_max = Vec2::<usize>::from(tgt_max).map(|e| e as f32);
let bounds_clamped = Aabr::<usize> {
min: (verts_screen.reduce(|a, b| Vec2::partial_min(a, b)) + 0.0)
min: (verts_screen.reduce(Vec2::partial_min) + 0.0)
.clamped(screen_min, screen_max)
.as_(),
max: (verts_screen.reduce(|a, b| Vec2::partial_max(a, b)) + 1.0)
max: (verts_screen.reduce(Vec2::partial_max) + 1.0)
.clamped(screen_min, screen_max)
.as_(),
};
Expand Down Expand Up @@ -95,25 +95,23 @@ impl Rasterizer for Lines {
// Calculate the interpolated z coordinate for the depth target
let z = Lerp::lerp(verts_euc.x.z, verts_euc.y.z, frac);

if coords.passes_z_clip(z) {
if blitter.test_fragment(x, y, z) {
let get_v_data = |x: f32, y: f32| {
let frac = if use_x {
x - verts_screen.x.x
} else {
y - verts_screen.x.y
} * norm;

V::weighted_sum2(
verts_out.x.clone(),
verts_out.y.clone(),
1.0 - frac,
frac,
)
};

blitter.emit_fragment(x, y, get_v_data, z);
}
if coords.passes_z_clip(z) && blitter.test_fragment(x, y, z) {
let get_v_data = |x: f32, y: f32| {
let frac = if use_x {
x - verts_screen.x.x
} else {
y - verts_screen.x.y
} * norm;

V::weighted_sum2(
verts_out.x.clone(),
verts_out.y.clone(),
1.0 - frac,
frac,
)
};

blitter.emit_fragment(x, y, get_v_data, z);
}
},
);
Expand Down
9 changes: 2 additions & 7 deletions src/rasterizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,17 @@ pub use self::{lines::Lines, triangles::Triangles};
use crate::{math::WeightedSum, CoordinateMode};

/// The face culling strategy used during rendering.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[derive(Default, Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum CullMode {
/// Do not cull triangles regardless of their winding order
None,
/// Cull clockwise triangles
#[default]
Back,
/// Cull counter-clockwise triangles
Front,
}

impl Default for CullMode {
fn default() -> Self {
CullMode::Back
}
}

/// A trait for types that define an interface for blitting fragments to surfaces
#[doc(hidden)]
pub trait Blitter<V>: Sized {
Expand Down
52 changes: 25 additions & 27 deletions src/rasterizer/triangles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ impl Rasterizer for Triangles {
let screen_min = Vec2::<usize>::from(tgt_min).map(|e| e as f32);
let screen_max = Vec2::<usize>::from(tgt_max).map(|e| e as f32);
let bounds_clamped = Aabr::<usize> {
min: (verts_screen.reduce(|a, b| Vec2::partial_min(a, b)) + 0.0)
min: (verts_screen.reduce(Vec2::partial_min) + 0.0)
.map3(screen_min, screen_max, |e, min, max| e.max(min).min(max))
.as_(),
max: (verts_screen.reduce(|a, b| Vec2::partial_max(a, b)) + 1.0)
max: (verts_screen.reduce(Vec2::partial_max) + 1.0)
.map3(screen_min, screen_max, |e, min, max| e.max(min).min(max))
.as_(),
};
Expand All @@ -147,6 +147,7 @@ impl Rasterizer for Triangles {
Vec3::new(verts_screen.y, verts_screen.z, verts_screen.x)
}
} else {
#[allow(clippy::collapsible_else_if)]
if verts_screen.x.y < verts_screen.y.y {
Vec3::new(verts_screen.z, verts_screen.x, verts_screen.y)
} else {
Expand Down Expand Up @@ -242,31 +243,28 @@ impl Rasterizer for Triangles {
// Calculate the interpolated z coordinate for the depth target
let z = verts_hom.map(|v| v.z).dot(w_unbalanced);

if NO_VERTS_CLIPPED || coords.passes_z_clip(z) {
if blitter.test_fragment(x, y, z) {
let get_v_data = |x: f32, y: f32| {
let w_hom = w_hom_origin + w_hom_dy * y + w_hom_dx * x;

// Calculate vertex weights to determine vs_out lerping and intersection
let w_unbalanced = Vec3::new(
w_hom.x,
w_hom.y,
w_hom.z - w_hom.x - w_hom.y,
);
let w = w_unbalanced * w_hom.z.recip();

V::weighted_sum3(
verts_out.x.clone(),
verts_out.y.clone(),
verts_out.z.clone(),
w.x,
w.y,
w.z,
)
};

blitter.emit_fragment(x, y, get_v_data, z);
}
if (NO_VERTS_CLIPPED || coords.passes_z_clip(z))
&& blitter.test_fragment(x, y, z)
{
let get_v_data = |x: f32, y: f32| {
let w_hom = w_hom_origin + w_hom_dy * y + w_hom_dx * x;

// Calculate vertex weights to determine vs_out lerping and intersection
let w_unbalanced =
Vec3::new(w_hom.x, w_hom.y, w_hom.z - w_hom.x - w_hom.y);
let w = w_unbalanced * w_hom.z.recip();

V::weighted_sum3(
verts_out.x.clone(),
verts_out.y.clone(),
verts_out.z.clone(),
w.x,
w.y,
w.z,
)
};

blitter.emit_fragment(x, y, get_v_data, z);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/sampler/linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use micromath::F32Ext;
/// A sampler that uses nearest-neighbor sampling.
pub struct Linear<T, I = f32>(pub(crate) T, pub(crate) PhantomData<I>);

impl<'a, T> Sampler<2> for Linear<T, f32>
impl<T> Sampler<2> for Linear<T, f32>
where
T: Texture<2, Index = usize>,
T::Texel: Mul<f32, Output = T::Texel> + Add<Output = T::Texel>,
Expand Down
2 changes: 1 addition & 1 deletion src/sampler/nearest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct Nearest<T, I = f32> {
pub(crate) phantom: PhantomData<I>,
}

impl<'a, T, I, const N: usize> Sampler<N> for Nearest<T, I>
impl<T, I, const N: usize> Sampler<N> for Nearest<T, I>
where
T: Texture<N>,
I: Clone + Mul<Output = I> + Denormalize<T::Index>,
Expand Down
8 changes: 3 additions & 5 deletions src/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ impl<T: Clone, F: Clone, U> Clone for Map<T, F, U> {
}
}

impl<'a, T: Texture<N>, U: Clone, F: Fn(T::Texel) -> U, const N: usize> Texture<N>
for Map<T, F, U>
{
impl<T: Texture<N>, U: Clone, F: Fn(T::Texel) -> U, const N: usize> Texture<N> for Map<T, F, U> {
type Index = T::Index;
type Texel = U;
#[inline(always)]
Expand Down Expand Up @@ -260,7 +258,7 @@ pub trait Target: Texture<2, Index = usize> {
}
}

impl<'a, T: Target> Target for &'a mut T {
impl<T: Target> Target for &mut T {
#[inline(always)]
unsafe fn read_exclusive_unchecked(&self, x: usize, y: usize) -> Self::Texel {
T::read_exclusive_unchecked(self, x, y)
Expand Down Expand Up @@ -341,7 +339,7 @@ where

#[inline(always)]
fn read(&self, [x, y]: [Self::Index; 2]) -> Self::Texel {
self.get_pixel(x as u32, y as u32).clone()
*self.get_pixel(x as u32, y as u32)
}
}

Expand Down

0 comments on commit ec083d9

Please sign in to comment.