@@ -23,8 +23,16 @@ pub mod internal {
2323 ) -> & RenderBackend :: GraphicsPipeline {
2424 return & pipeline. pipeline ;
2525 }
26+
27+ pub fn pipeline_layout_for < RenderBackend : gfx_hal:: Backend > (
28+ pipeline : & super :: RenderPipeline < RenderBackend > ,
29+ ) -> & RenderBackend :: PipelineLayout {
30+ return & pipeline. pipeline_layout ;
31+ }
2632}
2733
34+ use std:: ops:: Range ;
35+
2836use gfx_hal:: device:: Device ;
2937
3038use super :: {
@@ -35,14 +43,41 @@ use super::{
3543/// Builder for a gfx-hal backed render pipeline.
3644pub struct RenderPipelineBuilder < RenderBackend : internal:: Backend > {
3745 pipeline_layout : Option < RenderBackend :: PipelineLayout > ,
46+ push_constants : Vec < PushConstantUpload > ,
3847}
3948
49+ pub type PipelineStage = gfx_hal:: pso:: ShaderStageFlags ;
50+
51+ pub type PushConstantUpload = ( PipelineStage , Range < u32 > ) ;
52+
4053impl < RenderBackend : internal:: Backend > RenderPipelineBuilder < RenderBackend > {
4154 pub fn new ( ) -> Self {
4255 return Self {
4356 pipeline_layout : None ,
57+ push_constants : Vec :: new ( ) ,
4458 } ;
4559 }
60+
61+ /// Adds a push constant to the render pipeline at the set PipelineStage(s)
62+ pub fn with_push_constant (
63+ mut self ,
64+ stage : PipelineStage ,
65+ bytes : u32 ,
66+ ) -> Self {
67+ self . push_constants . push ( ( stage, 0 ..bytes) ) ;
68+ return self ;
69+ }
70+
71+ /// Adds multiple push constants to the render pipeline at their
72+ /// set PipelineStage(s)
73+ pub fn with_push_constants (
74+ mut self ,
75+ push_constants : Vec < PushConstantUpload > ,
76+ ) -> Self {
77+ self . push_constants . extend ( push_constants) ;
78+ return self ;
79+ }
80+
4681 /// Builds a render pipeline based on your builder configuration. You can
4782 /// configure a render pipeline to be however you'd like it to be.
4883 pub fn build (
@@ -54,10 +89,13 @@ impl<RenderBackend: internal::Backend> RenderPipelineBuilder<RenderBackend> {
5489 ) -> RenderPipeline < RenderBackend > {
5590 // TODO(vmarcella): The pipeline layout should be configurable through the
5691 // RenderPipelineBuilder.
92+ let push_constants = self . push_constants . into_iter ( ) ;
93+
5794 let pipeline_layout = unsafe {
5895 use internal:: Device ;
96+
5997 super :: internal:: logical_device_for ( gpu)
60- . create_pipeline_layout ( vec ! [ ] . into_iter ( ) , vec ! [ ] . into_iter ( ) )
98+ . create_pipeline_layout ( vec ! [ ] . into_iter ( ) , push_constants )
6199 . expect (
62100 "The GPU does not have enough memory to allocate a pipeline layout" ,
63101 )
0 commit comments