@@ -97,6 +97,35 @@ mod tests {
9797 ) ;
9898 assert_eq ! ( Visibility :: All . to_wgpu( ) , wgpu:: ShaderStages :: all( ) ) ;
9999 }
100+
101+ #[ test]
102+ fn sampled_texture_2d_layout_entry_is_correct ( ) {
103+ let builder = BindGroupLayoutBuilder :: new ( )
104+ . with_sampled_texture_2d ( 1 , Visibility :: Fragment )
105+ . with_sampler ( 2 , Visibility :: Fragment ) ;
106+ assert_eq ! ( builder. entries. len( ) , 2 ) ;
107+ match builder. entries [ 0 ] . ty {
108+ wgpu:: BindingType :: Texture {
109+ sample_type,
110+ view_dimension,
111+ multisampled,
112+ } => {
113+ assert_eq ! ( view_dimension, wgpu:: TextureViewDimension :: D2 ) ;
114+ assert_eq ! ( multisampled, false ) ;
115+ match sample_type {
116+ wgpu:: TextureSampleType :: Float { filterable } => assert ! ( filterable) ,
117+ _ => panic ! ( "expected float sample type" ) ,
118+ }
119+ }
120+ _ => panic ! ( "expected texture binding type" ) ,
121+ }
122+ match builder. entries [ 1 ] . ty {
123+ wgpu:: BindingType :: Sampler ( kind) => {
124+ assert_eq ! ( kind, wgpu:: SamplerBindingType :: Filtering ) ;
125+ }
126+ _ => panic ! ( "expected sampler binding type" ) ,
127+ }
128+ }
100129}
101130
102131/// Builder for creating a `wgpu::BindGroupLayout`.
@@ -155,6 +184,56 @@ impl BindGroupLayoutBuilder {
155184 return self ;
156185 }
157186
187+ /// Declare a sampled texture binding (2D) at the provided index.
188+ pub fn with_sampled_texture_2d (
189+ mut self ,
190+ binding : u32 ,
191+ visibility : Visibility ,
192+ ) -> Self {
193+ self . entries . push ( wgpu:: BindGroupLayoutEntry {
194+ binding,
195+ visibility : visibility. to_wgpu ( ) ,
196+ ty : wgpu:: BindingType :: Texture {
197+ sample_type : wgpu:: TextureSampleType :: Float { filterable : true } ,
198+ view_dimension : wgpu:: TextureViewDimension :: D2 ,
199+ multisampled : false ,
200+ } ,
201+ count : None ,
202+ } ) ;
203+ return self ;
204+ }
205+
206+ /// Declare a sampled texture binding with an explicit view dimension.
207+ pub fn with_sampled_texture_dim (
208+ mut self ,
209+ binding : u32 ,
210+ visibility : Visibility ,
211+ view_dimension : crate :: wgpu:: texture:: ViewDimension ,
212+ ) -> Self {
213+ self . entries . push ( wgpu:: BindGroupLayoutEntry {
214+ binding,
215+ visibility : visibility. to_wgpu ( ) ,
216+ ty : wgpu:: BindingType :: Texture {
217+ sample_type : wgpu:: TextureSampleType :: Float { filterable : true } ,
218+ view_dimension : view_dimension. to_wgpu ( ) ,
219+ multisampled : false ,
220+ } ,
221+ count : None ,
222+ } ) ;
223+ return self ;
224+ }
225+
226+ /// Declare a filtering sampler binding at the provided index.
227+ pub fn with_sampler ( mut self , binding : u32 , visibility : Visibility ) -> Self {
228+ self . entries . push ( wgpu:: BindGroupLayoutEntry {
229+ binding,
230+ visibility : visibility. to_wgpu ( ) ,
231+ ty : wgpu:: BindingType :: Sampler ( wgpu:: SamplerBindingType :: Filtering ) ,
232+ count : None ,
233+ } ) ;
234+ return self ;
235+ }
236+
158237 /// Build the layout using the provided device.
159238 pub fn build ( self , gpu : & Gpu ) -> BindGroupLayout {
160239 let raw =
@@ -220,6 +299,32 @@ impl<'a> BindGroupBuilder<'a> {
220299 return self ;
221300 }
222301
302+ /// Bind a texture view at a binding index.
303+ pub fn with_texture (
304+ mut self ,
305+ binding : u32 ,
306+ texture : & ' a crate :: wgpu:: texture:: Texture ,
307+ ) -> Self {
308+ self . entries . push ( wgpu:: BindGroupEntry {
309+ binding,
310+ resource : wgpu:: BindingResource :: TextureView ( texture. view ( ) ) ,
311+ } ) ;
312+ return self ;
313+ }
314+
315+ /// Bind a sampler at a binding index.
316+ pub fn with_sampler (
317+ mut self ,
318+ binding : u32 ,
319+ sampler : & ' a crate :: wgpu:: texture:: Sampler ,
320+ ) -> Self {
321+ self . entries . push ( wgpu:: BindGroupEntry {
322+ binding,
323+ resource : wgpu:: BindingResource :: Sampler ( sampler. raw ( ) ) ,
324+ } ) ;
325+ return self ;
326+ }
327+
223328 /// Build the bind group with the accumulated entries.
224329 pub fn build ( self , gpu : & Gpu ) -> BindGroup {
225330 let layout = self
0 commit comments