Skip to content

Commit 5b5c64f

Browse files
committed
[add] platform conversions to depth/stencil ops directly.
1 parent 36d6363 commit 5b5c64f

File tree

2 files changed

+89
-55
lines changed

2 files changed

+89
-55
lines changed

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

Lines changed: 11 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,7 @@ use super::{
4141
command::IndexFormat,
4242
pipeline,
4343
pipeline::RenderPipeline,
44-
render_pass::{
45-
ColorLoadOp,
46-
DepthLoadOp,
47-
RenderPass,
48-
StencilLoadOp,
49-
StoreOp,
50-
},
44+
render_pass::RenderPass,
5145
texture::DepthTexture,
5246
validation,
5347
viewport::Viewport,
@@ -214,54 +208,16 @@ impl<'pass> RenderPassEncoder<'pass> {
214208
let mut rp_builder = platform::render_pass::RenderPassBuilder::new();
215209

216210
// Map color operations from the high-level RenderPass
217-
let color_ops = pass.color_operations();
218-
rp_builder = match color_ops.load {
219-
ColorLoadOp::Load => {
220-
rp_builder.with_color_load_op(platform::render_pass::ColorLoadOp::Load)
221-
}
222-
ColorLoadOp::Clear(color) => rp_builder
223-
.with_color_load_op(platform::render_pass::ColorLoadOp::Clear(color)),
224-
};
225-
rp_builder = match color_ops.store {
226-
StoreOp::Store => {
227-
rp_builder.with_store_op(platform::render_pass::StoreOp::Store)
228-
}
229-
StoreOp::Discard => {
230-
rp_builder.with_store_op(platform::render_pass::StoreOp::Discard)
231-
}
232-
};
233-
234-
// Map depth operations from the high-level RenderPass
235-
let platform_depth_ops = pass.depth_operations().map(|dop| {
236-
platform::render_pass::DepthOperations {
237-
load: match dop.load {
238-
DepthLoadOp::Load => platform::render_pass::DepthLoadOp::Load,
239-
DepthLoadOp::Clear(v) => {
240-
platform::render_pass::DepthLoadOp::Clear(v as f32)
241-
}
242-
},
243-
store: match dop.store {
244-
StoreOp::Store => platform::render_pass::StoreOp::Store,
245-
StoreOp::Discard => platform::render_pass::StoreOp::Discard,
246-
},
247-
}
248-
});
249-
250-
// Map stencil operations from the high-level RenderPass
251-
let platform_stencil_ops = pass.stencil_operations().map(|sop| {
252-
platform::render_pass::StencilOperations {
253-
load: match sop.load {
254-
StencilLoadOp::Load => platform::render_pass::StencilLoadOp::Load,
255-
StencilLoadOp::Clear(v) => {
256-
platform::render_pass::StencilLoadOp::Clear(v)
257-
}
258-
},
259-
store: match sop.store {
260-
StoreOp::Store => platform::render_pass::StoreOp::Store,
261-
StoreOp::Discard => platform::render_pass::StoreOp::Discard,
262-
},
263-
}
264-
});
211+
let (color_load_op, color_store_op) = pass.color_operations().to_platform();
212+
rp_builder = rp_builder
213+
.with_color_load_op(color_load_op)
214+
.with_store_op(color_store_op);
215+
216+
// Map depth and stencil operations from the high-level RenderPass
217+
let platform_depth_ops =
218+
pass.depth_operations().map(|dop| dop.to_platform());
219+
let platform_stencil_ops =
220+
pass.stencil_operations().map(|sop| sop.to_platform());
265221

266222
let depth_view = depth_texture.map(|dt| dt.platform_view_ref());
267223
let has_depth_attachment = depth_texture.is_some();

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ pub enum ColorLoadOp {
2323
Clear([f64; 4]),
2424
}
2525

26+
impl ColorLoadOp {
27+
/// Convert to the platform color load operation.
28+
pub(crate) fn to_platform(self) -> platform::render_pass::ColorLoadOp {
29+
return match self {
30+
ColorLoadOp::Load => platform::render_pass::ColorLoadOp::Load,
31+
ColorLoadOp::Clear(color) => {
32+
platform::render_pass::ColorLoadOp::Clear(color)
33+
}
34+
};
35+
}
36+
}
37+
2638
/// Store operation for the first color attachment.
2739
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2840
pub enum StoreOp {
@@ -32,6 +44,16 @@ pub enum StoreOp {
3244
Discard,
3345
}
3446

47+
impl StoreOp {
48+
/// Convert to the platform store operation.
49+
pub(crate) fn to_platform(self) -> platform::render_pass::StoreOp {
50+
return match self {
51+
StoreOp::Store => platform::render_pass::StoreOp::Store,
52+
StoreOp::Discard => platform::render_pass::StoreOp::Discard,
53+
};
54+
}
55+
}
56+
3557
/// Combined color operations for the first color attachment.
3658
#[derive(Debug, Clone, Copy, PartialEq)]
3759
pub struct ColorOperations {
@@ -48,6 +70,18 @@ impl Default for ColorOperations {
4870
}
4971
}
5072

73+
impl ColorOperations {
74+
/// Convert to the platform color load and store operations.
75+
pub(crate) fn to_platform(
76+
self,
77+
) -> (
78+
platform::render_pass::ColorLoadOp,
79+
platform::render_pass::StoreOp,
80+
) {
81+
return (self.load.to_platform(), self.store.to_platform());
82+
}
83+
}
84+
5185
/// Depth load operation for the depth attachment.
5286
#[derive(Debug, Clone, Copy, PartialEq)]
5387
pub enum DepthLoadOp {
@@ -57,6 +91,18 @@ pub enum DepthLoadOp {
5791
Clear(f64),
5892
}
5993

94+
impl DepthLoadOp {
95+
/// Convert to the platform depth load operation.
96+
pub(crate) fn to_platform(self) -> platform::render_pass::DepthLoadOp {
97+
return match self {
98+
DepthLoadOp::Load => platform::render_pass::DepthLoadOp::Load,
99+
DepthLoadOp::Clear(value) => {
100+
platform::render_pass::DepthLoadOp::Clear(value as f32)
101+
}
102+
};
103+
}
104+
}
105+
60106
/// Depth operations for the first depth attachment.
61107
#[derive(Debug, Clone, Copy, PartialEq)]
62108
pub struct DepthOperations {
@@ -73,6 +119,16 @@ impl Default for DepthOperations {
73119
}
74120
}
75121

122+
impl DepthOperations {
123+
/// Convert to the platform depth operations.
124+
pub(crate) fn to_platform(self) -> platform::render_pass::DepthOperations {
125+
return platform::render_pass::DepthOperations {
126+
load: self.load.to_platform(),
127+
store: self.store.to_platform(),
128+
};
129+
}
130+
}
131+
76132
/// Immutable parameters used when beginning a render pass.
77133
#[derive(Debug, Clone)]
78134
///
@@ -361,6 +417,18 @@ pub enum StencilLoadOp {
361417
Clear(u32),
362418
}
363419

420+
impl StencilLoadOp {
421+
/// Convert to the platform stencil load operation.
422+
pub(crate) fn to_platform(self) -> platform::render_pass::StencilLoadOp {
423+
return match self {
424+
StencilLoadOp::Load => platform::render_pass::StencilLoadOp::Load,
425+
StencilLoadOp::Clear(value) => {
426+
platform::render_pass::StencilLoadOp::Clear(value)
427+
}
428+
};
429+
}
430+
}
431+
364432
/// Stencil operations for the first stencil attachment.
365433
#[derive(Debug, Clone, Copy, PartialEq)]
366434
pub struct StencilOperations {
@@ -377,6 +445,16 @@ impl Default for StencilOperations {
377445
}
378446
}
379447

448+
impl StencilOperations {
449+
/// Convert to the platform stencil operations.
450+
pub(crate) fn to_platform(self) -> platform::render_pass::StencilOperations {
451+
return platform::render_pass::StencilOperations {
452+
load: self.load.to_platform(),
453+
store: self.store.to_platform(),
454+
};
455+
}
456+
}
457+
380458
#[cfg(test)]
381459
mod tests {
382460
use std::cell::RefCell;

0 commit comments

Comments
 (0)