Skip to content

Commit cdf6830

Browse files
committed
CPU side optimization pass
Allocate wrangler resources on stack using `smallvec`. Attempt to add SIMD to math lib, current state is that `Vec2` and `Vec4` see either no improvement over non-explicit SIMD (not sure how LLVM/rustc optimizes) in most cases. `Vec3` sees similar improvement as `Vec4` with drawback of ruining dispatching vertex data to GPU by adding a bunch of junk bytes, also segfaults when I move the camera so I am taking out the SIMD impl for `Vec3` for now. The only reason I am leaving SIMD code in is because my Vec mulitply benchmarks are currently seeing a speedup of ~2x in SIMD vs non SIMD, but I am unable to reproduce this speedup in more complex cases so this may just be smoke in mirrors or something. Example of speedup ``` vec4 multiply vecs time: [212.75 ps 212.79 ps 212.84 ps] change: [-49.767% -49.698% -49.638%] (p = 0.00 < 0.05) Performance has improved. ``` Granted this is in picoseconds so we are acutely at the mercy of electrons here.
1 parent 0cf8f6e commit cdf6830

File tree

32 files changed

+1019
-665
lines changed

32 files changed

+1019
-665
lines changed

.cargo/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
[target.x86_64-unknown-linux-gnu]
77
linker = "/usr/bin/clang"
8-
rustflags = ["-Clink-arg=-fuse-ld=lld", "-Zshare-generics=y"]
8+
rustflags = ["-C", "link-arg=-fuse-ld=lld", "-Zshare-generics=y"]
99

1010
# NOTE: you must manually install https://github.com/michaeleisel/zld on mac. you can easily do this with the "brew" package manager:
1111
# `brew install michaeleisel/zld/zld`

Cargo.lock

Lines changed: 13 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

atlas/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ rand = { version = "0.8", features = ["small_rng"] }
1313
bytemuck = "1.4"
1414
tracing = "0.1"
1515
bitflags = "1.3"
16+
static_assertions = "1.1.0"
1617

1718
[dependencies.wgpu]
1819
version = "0.12"

atlas/src/camera/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use pantheon::math::Mat3;
2-
use pantheon::math::Mat4;
3-
use pantheon::math::Vec2;
4-
use pantheon::math::Vec3;
1+
use pantheon::math::prelude::*;
52
use pantheon::winit::event::VirtualKeyCode;
63

74
//const YAW_DEFAULT: f32 = -90.0;

atlas/src/entity/component.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ impl<'a> MousePick<'a> {
4141
pub trait MouseComponent {
4242
// TODO think about x/y/z and hover events
4343
fn click_start(&mut self, ctx: &mut Context);
44+
fn clicked(&mut self, ctx: &mut Context, _camera: &Camera);
4445
fn click_end(&mut self, ctx: &mut Context);
4546
fn mouse_over(&mut self, ctx: &mut Context, pos: Vec3, cam: &Camera);
4647
fn check_collision(

atlas/src/entity/cube.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,21 @@ impl<'a> DrawComponent<'a> for Cuboid<'a> {
370370

371371
impl<'a> MouseComponent for Cuboid<'a> {
372372
fn click_start(&mut self, _ctx: &mut Context) {}
373+
fn clicked(&mut self, ctx: &mut Context, camera: &Camera) {
374+
//@TODO this is impossible in 3D space dont @ me
375+
// fix to be in relation to a ground plane
376+
let delta = mouse::delta(ctx);
377+
//println!("delta: {:#?}", delta);
378+
379+
let ndc_x = delta.x / ctx.gfx_context.window_dims.width;
380+
let ndc_y = -delta.y / ctx.gfx_context.window_dims.height;
381+
382+
let delta_x = 2.0 * (self.position - camera.origin).magnitude() * ndc_x * camera.u;
383+
let delta_y = 2.0 * (self.position - camera.origin).magnitude() * ndc_y * camera.v;
384+
let trans = delta_x + delta_y;
385+
386+
self.translate(trans.into());
387+
}
373388
fn click_end(&mut self, _ctx: &mut Context) {}
374389

375390
fn mouse_over(&mut self, ctx: &mut Context, pos: Vec3, camera: &Camera) {

atlas/src/entity/plane.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use pantheon::math::Vec3;
1+
use pantheon::math::prelude::*;
22

33
#[derive(Debug)]
44
pub struct Plane {
@@ -8,7 +8,7 @@ pub struct Plane {
88

99
impl Plane {
1010
pub fn new(p0: Vec3, p1: Vec3, p2: Vec3) -> Option<Self> {
11-
let norm = (p1 - p0).cross(&(p2 - p0)).make_unit_vector();
11+
let norm = (p1 - p0).cross(&(p2 - p0)).unit_vector();
1212

1313
if norm.magnitude() == 0.0 {
1414
None

atlas/src/entity/sun.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::Cuboid;
22
use super::DrawComponent;
33
use super::Entity;
44
use super::MouseComponent;
5+
use crate::camera::Camera;
56
use crate::vertex::*;
67
use pantheon::Vec3;
78
use pantheon::{Color, Mat4, PolygonMode, Topology};
@@ -117,6 +118,8 @@ impl<'a> MouseComponent for Sun<'a> {
117118
self.cube.click_start(ctx);
118119
}
119120

121+
fn clicked(&mut self, _ctx: &mut pantheon::context::Context, _camera: &Camera) {}
122+
120123
fn click_end(&mut self, ctx: &mut pantheon::context::Context) {
121124
self.cube.click_end(ctx);
122125
}

atlas/src/entity/terrain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ use super::component::*;
22
use super::Camera;
33
use crate::rendering;
44
use crate::rendering::prelude::Passes;
5+
use crate::vertex::BasicVertex;
56
use crate::vertex::ShadedVertex;
67
use pantheon::graphics::mode::DrawMode;
78
use pantheon::graphics::prelude::*;
8-
use pantheon::graphics::vertex::Vertex;
99
use pantheon::graphics::Color;
1010
use pantheon::graphics::Drawable;
1111
use pantheon::graphics::PolygonMode;
@@ -18,7 +18,7 @@ pub struct Terrain<'a> {
1818
pub verts: Vec<ShadedVertex>,
1919
pub indices: Vec<u32>,
2020
pub center: Vec3,
21-
norm_debug: Vec<Vertex>,
21+
norm_debug: Vec<BasicVertex>,
2222
draw_call_handle: Option<DrawCallHandle<'a>>,
2323
topology: Topology,
2424
pub scale: f32,

atlas/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[macro_use]
2+
extern crate static_assertions;
3+
14
pub mod camera;
25
pub mod entity;
36
pub mod message;

0 commit comments

Comments
 (0)