Skip to content

Commit c95abd4

Browse files
committed
[add] high level push constant support.
1 parent db53485 commit c95abd4

3 files changed

Lines changed: 44 additions & 15 deletions

File tree

lambda/src/core/render/command.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ pub enum RenderCommand {
3333
},
3434
/// Ends the render pass.
3535
EndRenderPass,
36+
PushConstants {
37+
pipeline: Rc<super::pipeline::RenderPipeline>,
38+
stage: super::pipeline::PipelineStage,
39+
offset: u32,
40+
bytes: &'static [u32],
41+
},
3642
/// Draws a graphical primitive.
3743
Draw { vertices: Range<u32> },
3844
}
@@ -87,6 +93,17 @@ impl RenderCommand {
8793
pipeline: pipeline.into_platform_render_pipeline(),
8894
}
8995
}
96+
RenderCommand::PushConstants {
97+
pipeline,
98+
stage,
99+
offset,
100+
bytes,
101+
} => PlatformRenderCommand::PushConstants {
102+
pipeline: pipeline.into_platform_render_pipeline(),
103+
stage,
104+
offset,
105+
bytes,
106+
},
90107
RenderCommand::Draw { vertices } => {
91108
PlatformRenderCommand::Draw { vertices }
92109
}

lambda/src/core/render/pipeline.rs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,27 @@ impl RenderPipeline {
4040
}
4141
}
4242

43-
pub struct RenderPipelineBuilder {}
43+
pub use lambda_platform::gfx::pipeline::PipelineStage;
44+
use lambda_platform::gfx::pipeline::PushConstantUpload;
45+
46+
pub struct RenderPipelineBuilder {
47+
push_constants: Vec<PushConstantUpload>,
48+
}
4449

4550
impl RenderPipelineBuilder {
4651
pub fn new() -> Self {
47-
return Self {};
52+
return Self {
53+
push_constants: Vec::new(),
54+
};
55+
}
56+
57+
pub fn with_push_constant(
58+
mut self,
59+
stage: PipelineStage,
60+
bytes: u32,
61+
) -> Self {
62+
self.push_constants.push((stage, 0..bytes));
63+
return self;
4864
}
4965

5066
/// Builds a render pipeline based on your builder configuration.
@@ -68,12 +84,14 @@ impl RenderPipelineBuilder {
6884
);
6985

7086
let render_pipeline =
71-
lambda_platform::gfx::pipeline::RenderPipelineBuilder::new().build(
72-
gpu_from_context(render_context),
73-
&platform_render_pass_from_render_pass(render_pass),
74-
&vertex_shader_module,
75-
&fragment_shader_module,
76-
);
87+
lambda_platform::gfx::pipeline::RenderPipelineBuilder::new()
88+
.with_push_constants(self.push_constants)
89+
.build(
90+
gpu_from_context(render_context),
91+
&platform_render_pass_from_render_pass(render_pass),
92+
&vertex_shader_module,
93+
&fragment_shader_module,
94+
);
7795

7896
vertex_shader_module.destroy(mut_gpu_from_context(render_context));
7997
fragment_shader_module.destroy(mut_gpu_from_context(render_context));

lambda/src/math/mod.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
#[repr(C)]
2-
#[derive(Debug, Clone, Copy)]
3-
pub struct Triangle {
4-
color: [f32; 4],
5-
pos: [f32; 2],
6-
scale: [f32; 2],
7-
}
1+
type Vec2 = (f32, f32);

0 commit comments

Comments
 (0)