|
@@ -1,38 +1,78 @@
|
|
|
-use wgpu::{include_wgsl, util::DeviceExt, BufferUsages, ComputePipeline};
|
|
|
|
|
|
|
+use serde::de;
|
|
|
|
|
+use wgpu::{include_wgsl, util::DeviceExt, BindGroup, BufferUsages, ComputePipeline};
|
|
|
|
|
|
|
|
-pub fn new_compute_pipeline(device: &wgpu::Device)-> ComputePipeline{
|
|
|
|
|
|
|
+pub const SIZE:u32 = 256;
|
|
|
|
|
+pub fn new_compute_pipeline(device: &wgpu::Device)-> (ComputePipeline,BindGroup,(u32,u32)){
|
|
|
|
|
|
|
|
- let u32_size = std::mem::size_of::<u64>() as wgpu::BufferAddress;
|
|
|
|
|
- let time_buffer = device.create_buffer(&wgpu::BufferDescriptor{
|
|
|
|
|
- label: Some("Time uniform"),
|
|
|
|
|
- size: u32_size,
|
|
|
|
|
- usage: BufferUsages::COPY_DST | BufferUsages::UNIFORM,
|
|
|
|
|
- mapped_at_creation: false
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // let u32_size = std::mem::size_of::<u64>() as wgpu::BufferAddress;
|
|
|
|
|
+ // let time_buffer = device.create_buffer(&wgpu::BufferDescriptor{
|
|
|
|
|
+ // label: Some("Time uniform"),
|
|
|
|
|
+ // size: u32_size,
|
|
|
|
|
+ // usage: BufferUsages::COPY_DST | BufferUsages::UNIFORM,
|
|
|
|
|
+ // mapped_at_creation: false
|
|
|
|
|
+ // });
|
|
|
|
|
|
|
|
|
|
|
|
|
- let compute_pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor{
|
|
|
|
|
- label: Some("Compute Pipeline Layout 1"),
|
|
|
|
|
- bind_group_layouts: &[],
|
|
|
|
|
- push_constant_ranges: &[]
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- let compute_shader = device.create_shader_module(include_wgsl!("../shaders/CS_FFTHorizontal.wgsl"));
|
|
|
|
|
|
|
|
|
|
- let attente_buffer = device.create_buffer(&wgpu::BufferDescriptor{
|
|
|
|
|
- label: Some("Buffer attente, qui reste sur le CPU"),
|
|
|
|
|
- size: todo!(),
|
|
|
|
|
- usage: wgpu::BufferUsages::MAP_READ | wgpu::BufferUsages::COPY_DST,
|
|
|
|
|
- mapped_at_creation: false,
|
|
|
|
|
|
|
+ let compute_shader = device.create_shader_module(include_wgsl!("../shaders/Heightmap_compute.wgsl"));
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ let output_texture_size = wgpu::Extent3d{
|
|
|
|
|
+ width: SIZE,
|
|
|
|
|
+ height: SIZE,
|
|
|
|
|
+ depth_or_array_layers: 0
|
|
|
|
|
+ };
|
|
|
|
|
+ let output_texture = device.create_texture(&wgpu::TextureDescriptor{
|
|
|
|
|
+ label: Some("Output Heightmap Texture"),
|
|
|
|
|
+ size: output_texture_size,
|
|
|
|
|
+ mip_level_count: 1,
|
|
|
|
|
+ sample_count: 1,
|
|
|
|
|
+ dimension: wgpu::TextureDimension::D2,
|
|
|
|
|
+ format: wgpu::TextureFormat::Rgba8UnormSrgb,
|
|
|
|
|
+ usage: wgpu::TextureUsages::STORAGE_BINDING | wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::COPY_SRC,
|
|
|
|
|
+ view_formats: &[]
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- // let compute_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor{
|
|
|
|
|
- // label: Some("Compute Buffer"),
|
|
|
|
|
- // contents: bytemuck::cast_slice(todo!()),
|
|
|
|
|
- // usage: BufferUsages::STORAGE | BufferUsages::COPY_DST | BufferUsages::COPY_SRC
|
|
|
|
|
- // });
|
|
|
|
|
|
|
+ let output_texture_view = output_texture.create_view(&wgpu::TextureViewDescriptor::default());
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ let heightmap_texture_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor{
|
|
|
|
|
+ label: Some("Heightmap_texture_bind_group_layout"),
|
|
|
|
|
+ entries: &[
|
|
|
|
|
+ wgpu::BindGroupLayoutEntry{
|
|
|
|
|
+ binding: 0,
|
|
|
|
|
+ visibility: wgpu::ShaderStages::COMPUTE | wgpu::ShaderStages::VERTEX,
|
|
|
|
|
+ ty: wgpu::BindingType::StorageTexture{
|
|
|
|
|
+ access: wgpu::StorageTextureAccess::ReadWrite,
|
|
|
|
|
+ format: wgpu::TextureFormat::Rgba8UnormSrgb,
|
|
|
|
|
+ view_dimension: wgpu::TextureViewDimension::D2
|
|
|
|
|
+ },
|
|
|
|
|
+ count: None
|
|
|
|
|
+ }
|
|
|
|
|
+ ]
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ let heightmap_texture_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor{
|
|
|
|
|
+ label: Some("Heightmap texture bind group"),
|
|
|
|
|
+ layout: &heightmap_texture_bind_group_layout,
|
|
|
|
|
+ entries: &[
|
|
|
|
|
+ wgpu::BindGroupEntry{
|
|
|
|
|
+ binding: 0,
|
|
|
|
|
+ resource: wgpu::BindingResource::TextureView(&output_texture_view)
|
|
|
|
|
+ }
|
|
|
|
|
+ ]
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ //Pipeline Stuff
|
|
|
|
|
+ let compute_pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor{
|
|
|
|
|
+ label: Some("Compute Pipeline Layout 1"),
|
|
|
|
|
+ bind_group_layouts: &[
|
|
|
|
|
+ &heightmap_texture_bind_group_layout
|
|
|
|
|
+ ],
|
|
|
|
|
+ push_constant_ranges: &[]
|
|
|
|
|
+ });
|
|
|
let compute_pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor{
|
|
let compute_pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor{
|
|
|
label: Some("Compute Pipeline 1"),
|
|
label: Some("Compute Pipeline 1"),
|
|
|
layout: Some(&compute_pipeline_layout),
|
|
layout: Some(&compute_pipeline_layout),
|
|
@@ -40,5 +80,18 @@ pub fn new_compute_pipeline(device: &wgpu::Device)-> ComputePipeline{
|
|
|
entry_point: "@compute"
|
|
entry_point: "@compute"
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- return compute_pipeline
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ let dispatch = compute_work_group_count((SIZE,SIZE), (16,16));
|
|
|
|
|
+ return (compute_pipeline,heightmap_texture_bind_group,dispatch)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+pub fn compute_work_group_count(
|
|
|
|
|
+ (width, height): (u32, u32),
|
|
|
|
|
+ (workgroup_width, workgroup_height): (u32, u32),
|
|
|
|
|
+) -> (u32, u32) {
|
|
|
|
|
+ let x = (width + workgroup_width - 1) / workgroup_width;
|
|
|
|
|
+ let y = (height + workgroup_height - 1) / workgroup_height;
|
|
|
|
|
+
|
|
|
|
|
+ (x, y)
|
|
|
|
|
+}
|
|
|
|
|
+// compute_work_group_count((256,256),(16,16)) renvoie (16,16)
|
|
|
|
|
+// et compute_work_group_count((512,512),(16,16)) renvoie (32,32)
|