Add common generic entries to BindGroupLayoutBuilder

This commit is contained in:
Jarrod Doyle 2023-06-29 10:56:51 +01:00
parent c56fe7d69b
commit 056c35a441
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
2 changed files with 57 additions and 23 deletions

View File

@ -37,6 +37,57 @@ impl<'a> BindGroupLayoutBuilder<'a> {
self self
} }
#[inline]
pub fn with_uniform_entry(
self,
visibility: wgpu::ShaderStages,
count: Option<NonZeroU32>,
) -> Self {
self.with_entry(
visibility,
wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: false,
min_binding_size: None,
},
count,
)
}
#[inline]
pub fn with_rw_storage_entry(
self,
visibility: wgpu::ShaderStages,
count: Option<NonZeroU32>,
) -> Self {
self.with_entry(
visibility,
wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Storage { read_only: false },
has_dynamic_offset: false,
min_binding_size: None,
},
count,
)
}
#[inline]
pub fn with_ro_storage_entry(
self,
visibility: wgpu::ShaderStages,
count: Option<NonZeroU32>,
) -> Self {
self.with_entry(
visibility,
wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Storage { read_only: true },
has_dynamic_offset: false,
min_binding_size: None,
},
count,
)
}
#[inline] #[inline]
pub fn build(self, context: &Context) -> wgpu::BindGroupLayout { pub fn build(self, context: &Context) -> wgpu::BindGroupLayout {
context context

View File

@ -67,23 +67,6 @@ impl VoxelRenderer {
let cs_descriptor = wgpu::include_wgsl!("../../assets/shaders/voxel_volume.wgsl"); let cs_descriptor = wgpu::include_wgsl!("../../assets/shaders/voxel_volume.wgsl");
let cs = context.device.create_shader_module(cs_descriptor); let cs = context.device.create_shader_module(cs_descriptor);
// Re-usable common definitions
let ty_uniform = wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: false,
min_binding_size: None,
};
let ty_rw_storage = wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Storage { read_only: false },
has_dynamic_offset: false,
min_binding_size: None,
};
let ty_ro_storage = wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Storage { read_only: true },
has_dynamic_offset: false,
min_binding_size: None,
};
let raycast_layout = render::BindGroupLayoutBuilder::new() let raycast_layout = render::BindGroupLayoutBuilder::new()
.with_entry( .with_entry(
wgpu::ShaderStages::COMPUTE, wgpu::ShaderStages::COMPUTE,
@ -94,12 +77,12 @@ impl VoxelRenderer {
}, },
None, None,
) )
.with_entry(wgpu::ShaderStages::COMPUTE, ty_uniform, None) .with_uniform_entry(wgpu::ShaderStages::COMPUTE, None)
.with_entry(wgpu::ShaderStages::COMPUTE, ty_rw_storage, None) .with_rw_storage_entry(wgpu::ShaderStages::COMPUTE, None)
.with_entry(wgpu::ShaderStages::COMPUTE, ty_ro_storage, None) .with_ro_storage_entry(wgpu::ShaderStages::COMPUTE, None)
.with_entry(wgpu::ShaderStages::COMPUTE, ty_ro_storage, None) .with_ro_storage_entry(wgpu::ShaderStages::COMPUTE, None)
.with_entry(wgpu::ShaderStages::COMPUTE, ty_rw_storage, None) .with_rw_storage_entry(wgpu::ShaderStages::COMPUTE, None)
.with_entry(wgpu::ShaderStages::COMPUTE, ty_uniform, None) .with_uniform_entry(wgpu::ShaderStages::COMPUTE, None)
.build(context); .build(context);
let raycast_bind_group = render::BindGroupBuilder::new() let raycast_bind_group = render::BindGroupBuilder::new()
.with_layout(&raycast_layout) .with_layout(&raycast_layout)