Skip to content

Commit af0b7db

Browse files
committed
[add] buffer implementation for gpu memory allocations, update matrix implementations.
1 parent 46566dd commit af0b7db

3 files changed

Lines changed: 42 additions & 10 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
pub struct Buffer;
2+
3+
pub struct BufferBuilder {
4+
buffer_length: usize,
5+
usage: gfx_hal::buffer::Usage,
6+
}
7+
8+
impl BufferBuilder {
9+
pub fn new() -> Self {
10+
return Self {
11+
buffer_length: 0,
12+
usage: gfx_hal::buffer::Usage::empty(),
13+
};
14+
}
15+
16+
pub fn with_length(&mut self, length: usize) -> &mut Self {
17+
self.buffer_length = length;
18+
return self;
19+
}
20+
21+
pub fn with_usage(&mut self, usage: gfx_hal::buffer::Usage) -> &mut Self {
22+
self.usage = usage;
23+
return self;
24+
}
25+
26+
pub fn build<RenderBackend: super::internal::Backend>(
27+
self,
28+
device: &mut RenderBackend::Device,
29+
) -> Buffer {
30+
todo!();
31+
}
32+
}

crates/lambda-platform/src/gfx/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
pub mod api;
44
pub mod assembler;
5+
pub mod buffer;
56
pub mod command;
67
pub mod fence;
78
pub mod framebuffer;

lambda/src/math/matrix.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ pub fn rotate_matrix<
101101
"Axis vector must have 3 elements (x, y, z)"
102102
);
103103

104-
// Convert the angle from turns to radians
105104
let angle_in_radians = turns_to_radians(angle_in_turns);
106105
let cosine_of_angle = angle_in_radians.cos();
107106
let sin_of_angle = -angle_in_radians.sin();
@@ -284,7 +283,7 @@ where
284283

285284
for (i, a) in self.as_ref().iter().enumerate() {
286285
for (j, b) in transposed.as_ref().iter().enumerate() {
287-
result.as_mut()[i].as_mut()[j] += a.dot(&b);
286+
result.update(i, j, a.dot(b));
288287
}
289288
}
290289
return result;
@@ -294,7 +293,7 @@ where
294293
let mut result = Self::default();
295294
for (i, a) in self.as_ref().iter().enumerate() {
296295
for j in 0..a.as_ref().len() {
297-
result.as_mut()[i].as_mut()[j] = self.as_ref()[j].as_ref()[i];
296+
result.update(i, j, self.at(j, i));
298297
}
299298
}
300299
return result;
@@ -320,10 +319,10 @@ where
320319
return match height {
321320
1 => self.as_ref()[0].as_ref()[0],
322321
2 => {
323-
let a = self.as_ref()[0].as_ref()[0];
324-
let b = self.as_ref()[0].as_ref()[1];
325-
let c = self.as_ref()[1].as_ref()[0];
326-
let d = self.as_ref()[1].as_ref()[1];
322+
let a = self.at(0, 0);
323+
let b = self.at(0, 1);
324+
let c = self.at(1, 0);
325+
let d = self.at(1, 1);
327326
a * d - b * c
328327
}
329328
_ => {
@@ -334,12 +333,12 @@ where
334333
let mut row = Vec::new();
335334
for k in 0..height {
336335
if k != i {
337-
row.push(self.as_ref()[j].as_ref()[k]);
336+
row.push(self.at(j, k));
338337
}
339338
}
340339
submatrix.push(row);
341340
}
342-
result += self.as_ref()[0].as_ref()[i]
341+
result += self.at(0, i)
343342
* submatrix.determinant()
344343
* (-1.0 as f32).powi(i as i32);
345344
}
@@ -350,7 +349,7 @@ where
350349

351350
/// Return the size as a (rows, columns).
352351
fn size(&self) -> (usize, usize) {
353-
return (self.as_ref().len(), self.as_ref()[0].as_ref().len());
352+
return (self.as_ref().len(), self.row(0).size());
354353
}
355354

356355
/// Return a reference to the row.

0 commit comments

Comments
 (0)