diff options
Diffstat (limited to 'flowy/src/main.rs')
-rw-r--r-- | flowy/src/main.rs | 64 |
1 files changed, 43 insertions, 21 deletions
diff --git a/flowy/src/main.rs b/flowy/src/main.rs index d225c00..19084ef 100644 --- a/flowy/src/main.rs +++ b/flowy/src/main.rs @@ -44,7 +44,7 @@ fn main() { depth_or_array_layers: 1, }; - let [texa, texb] = [(), ()].map(|_| { + let textures = [(), ()].map(|_| { device.create_texture(&TextureDescriptor { label: None, size: extent, @@ -99,27 +99,46 @@ fn main() { }, visibility: ShaderStages::COMPUTE, }, - ], - }); - - let bind_goup = device.create_bind_group(&BindGroupDescriptor { - label: None, - layout: &bind_group_layout, - entries: &[ - BindGroupEntry { - binding: 0, - resource: wgpu::BindingResource::TextureView( - &out_tex.create_view(&Default::default()), - ), - }, - BindGroupEntry { - binding: 1, - resource: wgpu::BindingResource::TextureView( - &texa.create_view(&Default::default()), - ), + BindGroupLayoutEntry { + binding: 2, + count: None, + ty: BindingType::Texture { + sample_type: TextureSampleType::Float { filterable: false }, + view_dimension: TextureViewDimension::D2, + multisampled: false, + }, + visibility: ShaderStages::COMPUTE, }, ], }); + let bind_groups = [false, true].map(|i| { + device.create_bind_group(&BindGroupDescriptor { + label: None, + layout: &bind_group_layout, + entries: &[ + BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::TextureView( + &out_tex.create_view(&Default::default()), + ), + }, + BindGroupEntry { + binding: 1, + resource: wgpu::BindingResource::TextureView( + &(if i { &textures[0] } else { &textures[1] }) + .create_view(&Default::default()), + ), + }, + BindGroupEntry { + binding: 2, + resource: wgpu::BindingResource::TextureView( + &(if i { &textures[1] } else { &textures[0] }) + .create_view(&Default::default()), + ), + }, + ], + }) + }); let pipeline_layout = device.create_pipeline_layout(&PipelineLayoutDescriptor { label: None, @@ -135,6 +154,7 @@ fn main() { entry_point: "main", }); + let mut i = 0; loop { eprintln!("read"); stdin().read_exact(&mut buffer).unwrap(); @@ -145,7 +165,7 @@ fn main() { aspect: wgpu::TextureAspect::All, mip_level: 0, origin: Origin3d::ZERO, - texture: &texa, + texture: &textures[i], }, &buffer, wgpu::ImageDataLayout { @@ -165,7 +185,7 @@ fn main() { timestamp_writes: None, }); cpass.set_pipeline(&pipeline); - cpass.set_bind_group(0, &bind_goup, &[]); + cpass.set_bind_group(0, &bind_groups[i], &[]); cpass.dispatch_workgroups(width as u32, height as u32, 1); } @@ -203,5 +223,7 @@ fn main() { download_buffer.unmap(); eprintln!("write"); stdout().write_all(&buffer).unwrap(); + i += 1; + i %= 2; } } |