Skip to content

Commit d6774e1

Browse files
committed
[move] pod to it's own module and update examples.
1 parent df476b7 commit d6774e1

File tree

7 files changed

+51
-42
lines changed

7 files changed

+51
-42
lines changed

crates/lambda-rs/examples/indexed_multi_vertex_buffers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ struct PositionVertex {
8989
position: [f32; 3],
9090
}
9191

92-
unsafe impl lambda::render::buffer::PlainOldData for PositionVertex {}
92+
unsafe impl lambda::pod::PlainOldData for PositionVertex {}
9393

9494
#[repr(C)]
9595
#[derive(Clone, Copy, Debug)]
9696
struct ColorVertex {
9797
color: [f32; 3],
9898
}
9999

100-
unsafe impl lambda::render::buffer::PlainOldData for ColorVertex {}
100+
unsafe impl lambda::pod::PlainOldData for ColorVertex {}
101101

102102
// --------------------------------- COMPONENT ---------------------------------
103103

crates/lambda-rs/examples/instanced_quads.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ struct QuadVertex {
9292
position: [f32; 3],
9393
}
9494

95-
unsafe impl lambda::render::buffer::PlainOldData for QuadVertex {}
95+
unsafe impl lambda::pod::PlainOldData for QuadVertex {}
9696

9797
#[repr(C)]
9898
#[derive(Clone, Copy, Debug)]
@@ -101,7 +101,7 @@ struct InstanceData {
101101
color: [f32; 3],
102102
}
103103

104-
unsafe impl lambda::render::buffer::PlainOldData for InstanceData {}
104+
unsafe impl lambda::pod::PlainOldData for InstanceData {}
105105

106106
// --------------------------------- COMPONENT ---------------------------------
107107

crates/lambda-rs/examples/uniform_buffer_triangle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub struct GlobalsUniform {
101101
pub render_matrix: [[f32; 4]; 4],
102102
}
103103

104-
unsafe impl lambda::render::buffer::PlainOldData for GlobalsUniform {}
104+
unsafe impl lambda::pod::PlainOldData for GlobalsUniform {}
105105

106106
// --------------------------------- COMPONENT ---------------------------------
107107

crates/lambda-rs/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
pub mod component;
1515
pub mod events;
1616
pub mod math;
17+
pub mod pod;
1718
pub mod render;
1819
pub mod runtime;
1920
pub mod runtimes;

crates/lambda-rs/src/pod.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//! Plain-old-data marker trait for safe byte uploads.
2+
//!
3+
//! The engine frequently uploads CPU data into GPU buffers by reinterpreting
4+
//! a value or slice as raw bytes. This is only sound for types that are safe
5+
//! to view as bytes.
6+
7+
/// Marker trait for types that are safe to reinterpret as raw bytes.
8+
///
9+
/// This trait is required by typed buffer upload APIs (for example
10+
/// `render::buffer::Buffer::write_value` and `render::buffer::Buffer::write_slice`)
11+
/// and typed buffer creation APIs (for example
12+
/// `render::buffer::BufferBuilder::build`) because those operations upload the
13+
/// in-memory representation of a value to the GPU.
14+
///
15+
/// # Safety
16+
/// Types implementing `PlainOldData` MUST satisfy all of the following:
17+
/// - Every byte of the value is initialized (including any padding bytes).
18+
/// - The type has no pointers or references that would be invalidated by a
19+
/// raw byte copy.
20+
/// - The type's byte representation is stable for GPU consumption. Prefer
21+
/// `#[repr(C)]` or `#[repr(transparent)]`.
22+
///
23+
/// Implementing this trait incorrectly can cause undefined behavior.
24+
pub unsafe trait PlainOldData: Copy {}
25+
26+
unsafe impl PlainOldData for u8 {}
27+
unsafe impl PlainOldData for i8 {}
28+
unsafe impl PlainOldData for u16 {}
29+
unsafe impl PlainOldData for i16 {}
30+
unsafe impl PlainOldData for u32 {}
31+
unsafe impl PlainOldData for i32 {}
32+
unsafe impl PlainOldData for u64 {}
33+
unsafe impl PlainOldData for i64 {}
34+
unsafe impl PlainOldData for u128 {}
35+
unsafe impl PlainOldData for i128 {}
36+
unsafe impl PlainOldData for usize {}
37+
unsafe impl PlainOldData for isize {}
38+
unsafe impl PlainOldData for f32 {}
39+
unsafe impl PlainOldData for f64 {}
40+
unsafe impl PlainOldData for bool {}
41+
unsafe impl PlainOldData for char {}
42+
unsafe impl<T: PlainOldData, const N: usize> PlainOldData for [T; N] {}

crates/lambda-rs/src/render/buffer.rs

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,7 @@ use super::{
2727
mesh::Mesh,
2828
RenderContext,
2929
};
30-
31-
/// Marker trait for types that are safe to reinterpret as raw bytes.
32-
///
33-
/// This trait is required by `Buffer::write_value`, `Buffer::write_slice`, and
34-
/// `BufferBuilder::build` because those APIs upload the in-memory representation
35-
/// of a value to the GPU.
36-
///
37-
/// # Safety
38-
/// Types implementing `PlainOldData` MUST satisfy all of the following:
39-
/// - Every byte of the value is initialized (including any padding bytes).
40-
/// - The type has no pointers or references that would be invalidated by a
41-
/// raw byte copy.
42-
/// - The type's byte representation is stable for GPU consumption. Prefer
43-
/// `#[repr(C)]` or `#[repr(transparent)]`.
44-
///
45-
/// Implementing this trait incorrectly can cause undefined behavior.
46-
pub unsafe trait PlainOldData: Copy {}
47-
48-
unsafe impl PlainOldData for u8 {}
49-
unsafe impl PlainOldData for i8 {}
50-
unsafe impl PlainOldData for u16 {}
51-
unsafe impl PlainOldData for i16 {}
52-
unsafe impl PlainOldData for u32 {}
53-
unsafe impl PlainOldData for i32 {}
54-
unsafe impl PlainOldData for u64 {}
55-
unsafe impl PlainOldData for i64 {}
56-
unsafe impl PlainOldData for u128 {}
57-
unsafe impl PlainOldData for i128 {}
58-
unsafe impl PlainOldData for usize {}
59-
unsafe impl PlainOldData for isize {}
60-
unsafe impl PlainOldData for f32 {}
61-
unsafe impl PlainOldData for f64 {}
62-
unsafe impl PlainOldData for bool {}
63-
unsafe impl PlainOldData for char {}
64-
unsafe impl<T: PlainOldData, const N: usize> PlainOldData for [T; N] {}
65-
66-
unsafe impl PlainOldData for super::vertex::Vertex {}
30+
pub use crate::pod::PlainOldData;
6731

6832
/// High‑level classification for buffers created by the engine.
6933
#[derive(Clone, Copy, Debug, PartialEq, Eq)]

crates/lambda-rs/src/render/vertex.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ pub struct Vertex {
7878
pub color: [f32; 3],
7979
}
8080

81+
unsafe impl crate::pod::PlainOldData for Vertex {}
82+
8183
/// Builder for constructing a `Vertex` instance incrementally.
8284
#[derive(Clone, Copy, Debug)]
8385
pub struct VertexBuilder {

0 commit comments

Comments
 (0)