Skip to content

Commit 58d2d10

Browse files
committed
Replace vek with glam.
This fixes #179.
1 parent 7eb199c commit 58d2d10

File tree

18 files changed

+65
-55
lines changed

18 files changed

+65
-55
lines changed

crates/cuda_std/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ repository = "https://github.com/Rust-GPU/Rust-CUDA"
88
readme = "../../README.md"
99

1010
[dependencies]
11+
glam = { version = ">=0.22", default-features = false, features = ["libm", "cuda", "bytemuck"] }
1112
vek = { version = "0.17.1", default-features = false, features = ["libm"] }
1213
cuda_std_macros = { version = "0.2", path = "../cuda_std_macros" }
1314
half = "2.4.1"

crates/cuda_std/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ mod float_ext;
4949
pub use cuda_std_macros::*;
5050
pub use float::GpuFloat;
5151
pub use float_ext::*;
52+
pub use glam;
5253
pub use half;
54+
#[deprecated(
55+
note = "The `vek` module is deprecated, use `glam` instead."
56+
)]
5357
pub use vek;
5458

5559
pub use half::{bf16, f16};

crates/cuda_std/src/rt/mod.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -152,23 +152,23 @@ impl<'a> From<&'a GridSize> for GridSize {
152152
other.clone()
153153
}
154154
}
155-
impl From<vek::Vec2<u32>> for GridSize {
156-
fn from(vec: vek::Vec2<u32>) -> Self {
155+
impl From<glam::UVec2> for GridSize {
156+
fn from(vec: glam::UVec2) -> Self {
157157
GridSize::xy(vec.x, vec.y)
158158
}
159159
}
160-
impl From<vek::Vec3<u32>> for GridSize {
161-
fn from(vec: vek::Vec3<u32>) -> Self {
160+
impl From<glam::UVec3> for GridSize {
161+
fn from(vec: glam::UVec3) -> Self {
162162
GridSize::xyz(vec.x, vec.y, vec.z)
163163
}
164164
}
165-
impl From<vek::Vec2<usize>> for GridSize {
166-
fn from(vec: vek::Vec2<usize>) -> Self {
165+
impl From<glam::USizeVec2> for GridSize {
166+
fn from(vec: glam::USizeVec2) -> Self {
167167
GridSize::xy(vec.x as u32, vec.y as u32)
168168
}
169169
}
170-
impl From<vek::Vec3<usize>> for GridSize {
171-
fn from(vec: vek::Vec3<usize>) -> Self {
170+
impl From<glam::USizeVec3> for GridSize {
171+
fn from(vec: glam::USizeVec3) -> Self {
172172
GridSize::xyz(vec.x as u32, vec.y as u32, vec.z as u32)
173173
}
174174
}
@@ -228,23 +228,23 @@ impl<'a> From<&'a BlockSize> for BlockSize {
228228
other.clone()
229229
}
230230
}
231-
impl From<vek::Vec2<u32>> for BlockSize {
232-
fn from(vec: vek::Vec2<u32>) -> Self {
231+
impl From<glam::UVec2> for BlockSize {
232+
fn from(vec: glam::UVec2) -> Self {
233233
BlockSize::xy(vec.x, vec.y)
234234
}
235235
}
236-
impl From<vek::Vec3<u32>> for BlockSize {
237-
fn from(vec: vek::Vec3<u32>) -> Self {
236+
impl From<glam::UVec3> for BlockSize {
237+
fn from(vec: glam::UVec3) -> Self {
238238
BlockSize::xyz(vec.x, vec.y, vec.z)
239239
}
240240
}
241-
impl From<vek::Vec2<usize>> for BlockSize {
242-
fn from(vec: vek::Vec2<usize>) -> Self {
241+
impl From<glam::USizeVec2> for BlockSize {
242+
fn from(vec: glam::USizeVec2) -> Self {
243243
BlockSize::xy(vec.x as u32, vec.y as u32)
244244
}
245245
}
246-
impl From<vek::Vec3<usize>> for BlockSize {
247-
fn from(vec: vek::Vec3<usize>) -> Self {
246+
impl From<glam::USizeVec3> for BlockSize {
247+
fn from(vec: glam::USizeVec3) -> Self {
248248
BlockSize::xyz(vec.x as u32, vec.y as u32, vec.z as u32)
249249
}
250250
}

crates/cuda_std/src/thread.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// TODO: write some docs about the terms used in this module.
2020

2121
use cuda_std_macros::gpu_only;
22-
use vek::{Vec2, Vec3};
22+
use glam::{UVec2, UVec3};
2323

2424
// different calling conventions dont exist in nvptx, so we just use C as a placeholder.
2525
extern "C" {
@@ -152,7 +152,7 @@ pub fn grid_dim_z() -> u32 {
152152
/// Gets the 3d index of the thread currently executing the kernel.
153153
#[gpu_only]
154154
#[inline(always)]
155-
pub fn thread_idx() -> Vec3<u32> {
155+
pub fn thread_idx() -> UVec3 {
156156
unsafe {
157157
Vec3::new(
158158
__nvvm_thread_idx_x(),
@@ -165,7 +165,7 @@ pub fn thread_idx() -> Vec3<u32> {
165165
/// Gets the 3d index of the block that the thread currently executing the kernel is located in.
166166
#[gpu_only]
167167
#[inline(always)]
168-
pub fn block_idx() -> Vec3<u32> {
168+
pub fn block_idx() -> UVec3 {
169169
unsafe {
170170
Vec3::new(
171171
__nvvm_block_idx_x(),
@@ -179,7 +179,7 @@ pub fn block_idx() -> Vec3<u32> {
179179
/// how many threads exist in each thread block in every direction.
180180
#[gpu_only]
181181
#[inline(always)]
182-
pub fn block_dim() -> Vec3<u32> {
182+
pub fn block_dim() -> UVec3 {
183183
unsafe {
184184
Vec3::new(
185185
__nvvm_block_dim_x(),
@@ -193,7 +193,7 @@ pub fn block_dim() -> Vec3<u32> {
193193
/// how many thread blocks exist in each grid in every direction.
194194
#[gpu_only]
195195
#[inline(always)]
196-
pub fn grid_dim() -> Vec3<u32> {
196+
pub fn grid_dim() -> UVec3 {
197197
unsafe {
198198
Vec3::new(
199199
__nvvm_grid_dim_x(),
@@ -232,26 +232,26 @@ pub fn index_1d() -> u32 {
232232
}
233233

234234
#[inline(always)]
235-
pub fn index_2d() -> Vec2<u32> {
235+
pub fn index_2d() -> UVec2 {
236236
let i = thread_idx_x() + block_idx_x() * block_dim_x();
237237
let j = thread_idx_y() + block_idx_y() * block_dim_y();
238-
Vec2::new(i, j)
238+
UVec2::new(i, j)
239239
}
240240

241241
#[inline(always)]
242-
pub fn index_3d() -> Vec3<u32> {
242+
pub fn index_3d() -> UVec3 {
243243
let i = thread_idx_x() + block_idx_x() * block_dim_x();
244244
let j = thread_idx_y() + block_idx_y() * block_dim_y();
245245
let k = thread_idx_z() + block_idx_z() * block_dim_z();
246-
Vec3::new(i, j, k)
246+
UVec3::new(i, j, k)
247247
}
248248

249249
/// Whether this is the first thread (not the first thread to be executing). This function is guaranteed
250250
/// to only return true in a single thread that is invoking it. This is useful for only doing something
251251
/// once.
252252
#[inline(always)]
253253
pub fn first() -> bool {
254-
block_idx() == Vec3::zero() && thread_idx() == Vec3::zero()
254+
block_idx() == UVec3::ZERO && thread_idx() == UVec3::ZERO
255255
}
256256

257257
/// Gets the number of threads inside of a warp. Currently 32 threads on every GPU architecture.

crates/cust/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Notable changes to this project will be documented in this file.
44

55
## Unreleased
66

7+
- `cuda_std::vek` is now deprecated. Use `cuda_std::glam`.
78
- Add `memory::memcpy_dtoh` to allow copying from device to host.
89
- `DeviceSlice` is represented as a slice again, but as `[()]` instead of `[T]`.
910
- Reimplemented `Index` and `IndexMut` for `DeviceSlice` and removed `DeviceSlice::index`.

crates/optix_device/Cargo.toml

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
name = "optix_device"
33
version = "0.1.0"
44
edition = "2021"
5-
authors = ["Anders Langlands <[email protected]>", "Riccardo D'Ambrosio <[email protected]>"]
5+
authors = [
6+
"Anders Langlands <[email protected]>",
7+
"Riccardo D'Ambrosio <[email protected]>"
8+
]
69

710
[dependencies]
811
bitflags = "2.8"
912
cuda_std = { version = "0.2", path = "../cuda_std" }
10-
glam = { version = "0.29", features=["cuda", "libm"], default-features=false }
1113
paste = "1.0.15"
1214
seq-macro = "0.3.5"
1315
cust_core = { version = "0.1", path = "../cust_core" }
16+
17+
[target.'cfg(not(target_os = "cuda"))'.dependencies]
18+
glam = { version = "0.29", features = ["cuda"], default-features = false }

crates/optix_device/src/hit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[cfg(target_os = "cuda")]
22
use core::arch::asm;
3-
use cuda_std::gpu_only;
3+
use cuda_std::{gpu_only, glam};
44
use glam::Vec3;
55
/// The type of primitive that a ray hit.
66
#[repr(u32)]

crates/optix_device/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ pub mod trace;
1414
pub mod transform;
1515
pub mod util;
1616

17-
use cuda_std::*;
18-
pub use glam;
17+
use cuda_std::{glam, *};
1918
use glam::UVec3;
2019
pub use misc::*;
2120

crates/optix_device/src/ray.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::trace::*;
22
#[cfg(target_os = "cuda")]
33
use core::arch::asm;
4-
use cuda_std::gpu_only;
4+
use cuda_std::{glam, gpu_only};
55
use glam::Vec3;
66

77
/// Returns the ray origin that was passed into [`trace`] in world-space.

crates/optix_device/src/sys.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::trace::{RayFlags, TraversableHandle};
44
#[cfg(target_os = "cuda")]
55
use core::arch::asm;
6-
use cuda_std::gpu_only;
6+
use cuda_std::{glam, gpu_only};
77
use glam::Vec3;
88
use paste::paste;
99

examples/cuda/cpu/path_tracer/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ version = "0.1.0"
44
edition = "2018"
55

66
[dependencies]
7-
vek = { version = "0.17.1", features = ["bytemuck", "mint"] }
7+
glam = { version = "0.30.1", features = ["bytemuck", "cuda"] }
88
bytemuck = { version = "1.21", features = ["derive"] }
9-
cust = { version = "0.3", path = "../../../../crates/cust", features = ["impl_vek"] }
9+
cust = { version = "0.3", path = "../../../../crates/cust", features = ["impl_glam"] }
1010
image = "0.25.5"
1111
path_tracer_gpu = { path = "../../gpu/path_tracer_gpu" }
1212
gpu_rand = { version = "0.1", path = "../../../../crates/gpu_rand" }

examples/cuda/cpu/path_tracer/src/common.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ use glium::glutin::event::{
22
ElementState, Event, MouseButton, MouseScrollDelta, VirtualKeyCode, WindowEvent,
33
};
44
use path_tracer_gpu::Viewport;
5-
use vek::{Vec2, Vec3};
5+
use glam::{Vec2, Vec3};
66

77
#[derive(Debug, Clone, Copy, PartialEq)]
88
pub struct Camera {
9-
pub origin: Vec3<f32>,
10-
pub lookat: Vec3<f32>,
11-
pub vup: Vec3<f32>,
9+
pub origin: Vec3,
10+
pub lookat: Vec3,
11+
pub vup: Vec3,
1212
pub fov: f32,
1313
pub aspect_ratio: f32,
1414
}
@@ -43,7 +43,7 @@ pub struct CameraController {
4343
}
4444

4545
impl CameraController {
46-
pub fn new(dimensions: Vec2<usize>) -> Self {
46+
pub fn new(dimensions: USizeVec2) -> Self {
4747
CameraController {
4848
sensitivity: 0.1,
4949
last_mouse_pos: dimensions.numcast().unwrap() / 2.0,

examples/cuda/cpu/path_tracer/src/cpu/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ use path_tracer_gpu::{
77
};
88
use rayon::prelude::*;
99
use sysinfo::System;
10-
use vek::{Clamp, Vec2, Vec3};
10+
use glam::{Clamp, Vec2, Vec3};
1111

1212
use crate::{common::Camera, cuda::SEED};
1313

1414
pub struct CpuRenderer {
1515
// this is basically the cuda buffers but not gpu buffers.
16-
accumulated_buffer: Vec<Vec3<f32>>,
16+
accumulated_buffer: Vec<Vec3>,
1717
out_buffer: Vec<Vec3<u8>>,
1818

1919
viewport: Viewport,
@@ -23,7 +23,7 @@ pub struct CpuRenderer {
2323
}
2424

2525
impl CpuRenderer {
26-
pub fn new(dimensions: Vec2<usize>, camera: &Camera, scene: &Scene) -> Self {
26+
pub fn new(dimensions: USizeVec2, camera: &Camera, scene: &Scene) -> Self {
2727
let accumulated_buffer = vec![Vec3::zero(); dimensions.product()];
2828
let out_buffer = vec![Vec3::zero(); dimensions.product()];
2929

@@ -67,7 +67,7 @@ impl CpuRenderer {
6767
new_camera.as_viewport(&mut self.viewport);
6868
}
6969

70-
pub fn resize(&mut self, dimensions: Vec2<usize>) {
70+
pub fn resize(&mut self, dimensions: USizeVec2) {
7171
self.accumulated_buffer
7272
.resize(dimensions.product(), Vec3::zero());
7373
self.out_buffer.resize(dimensions.product(), Vec3::zero());

examples/cuda/cpu/path_tracer/src/cuda/data.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use cust::{
77
};
88
use gpu_rand::DefaultRand;
99
use path_tracer_gpu::{material::MaterialKind, scene::Scene, Object, Viewport};
10-
use vek::{Vec2, Vec3};
10+
use glam::{Vec2, Vec3};
1111

1212
use super::SEED;
1313

examples/cuda/cpu/path_tracer/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use path_tracer_gpu::{
1313
Object,
1414
};
1515
use std::error::Error;
16-
use vek::Vec3;
16+
use glam::Vec3;
1717

1818
pub const WIDTH: u32 = 1920;
1919
pub const HEIGHT: u32 = 1080;

examples/cuda/gpu/path_tracer_gpu/src/lib.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,19 @@ pub mod render_kernels;
1111
pub mod scene;
1212
pub mod sphere;
1313

14-
pub use cuda_std::vek;
14+
pub use cuda_std::glam;
1515
use cust_core::DeviceCopy;
1616
use enum_dispatch::enum_dispatch;
1717
use hittable::{HitRecord, Hittable};
1818
use sphere::Sphere;
1919

20-
pub type Vec3<T = f32> = vek::Vec3<T>;
21-
pub type Point<T = f32> = vek::Vec3<T>;
22-
pub type Vec2<T = f32> = vek::Vec2<T>;
20+
use glam::{Vec2, Vec3, USizeVec2};
21+
pub type Point = Vec3;
2322

2423
#[derive(Default, Clone, Copy, DeviceCopy)]
2524
#[repr(C)]
2625
pub struct Viewport {
27-
pub bounds: vek::Vec2<usize>,
26+
pub bounds: USizeVec2,
2827
pub lower_left: Vec3,
2928
pub horizontal: Vec3,
3029
pub vertical: Vec3,

examples/cuda/gpu/path_tracer_gpu/src/render.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub fn color(ray: Ray) -> Vec3 {
88
(1.0 - t) * Vec3::one() + t * Vec3::new(0.5, 0.7, 1.0)
99
}
1010

11-
pub fn generate_ray(idx: vek::Vec2<u32>, view: &Viewport, offset: Vec2) -> Ray {
11+
pub fn generate_ray(idx: UVec2, view: &Viewport, offset: Vec2) -> Ray {
1212
let uv = (idx.numcast::<f32>().unwrap() + offset) / view.bounds.numcast().unwrap();
1313
Ray {
1414
origin: view.origin,

examples/cuda/gpu/path_tracer_gpu/src/render_kernels.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{render::*, scene::Scene, *};
2-
use cuda_std::{vek::Clamp, *};
2+
use cuda_std::*;
3+
use glam::{U8Vec3, Vec2, Vec3};
34
use gpu_rand::{DefaultRand, GpuRand};
45

56
#[kernel]
@@ -38,7 +39,7 @@ pub unsafe fn scale_buffer(fb: *const Vec3, out: *mut Vec3, samples: u32, view:
3839

3940
/// Postprocesses a (scaled) buffer into a final u8 buffer.
4041
#[kernel]
41-
pub unsafe fn postprocess(fb: *const Vec3, out: *mut vek::Vec3<u8>, view: Viewport) {
42+
pub unsafe fn postprocess(fb: *const Vec3, out: *mut U8Vec3, view: Viewport) {
4243
let idx_2d = thread::index_2d();
4344
if idx_2d.x >= view.bounds.x as u32 || idx_2d.y >= view.bounds.y as u32 {
4445
return;
@@ -50,7 +51,7 @@ pub unsafe fn postprocess(fb: *const Vec3, out: *mut vek::Vec3<u8>, view: Viewpo
5051
let gamma_corrected = original.sqrt();
5152

5253
*out = (gamma_corrected * 255.0)
53-
.clamped(Vec3::zero(), Vec3::broadcast(255.0))
54+
.clamp(Vec3::zero(), Vec3::broadcast(255.0))
5455
.numcast()
5556
.unwrap();
5657
}

0 commit comments

Comments
 (0)