diff --git a/README.md b/README.md index de481cc..e74ddb1 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ When deriving bytemuck, wgsl_bindgen will use naga's layout calculations to add wgpu uses resource bindings organized into bind groups to define global shader resources like textures and buffers. Shaders can have many resource bindings organized into up to 4 bind groups. wgsl_bindgen will generate types and functions for initializing and setting these bind groups in a more typesafe way. Adding, removing, or changing bind groups in the WGSl shader will typically result in a compile error instead of a runtime error when compiling the code without updating the code for creating or using these bind groups. -While bind groups can easily be set all at once using the `bind_groups::set_bind_groups` function, it's recommended to organize bindings into bindgroups based on their update frequency. Bind group 0 will change the least frequently like per frame resources with bind group 3 changing most frequently like per draw resources. Bind groups can be set individually using their `set(render_pass)` method. This can provide a small performance improvement for scenes with many draw calls. See [descriptor table frequency (DX12)](https://learn.microsoft.com/en-us/windows/win32/direct3d12/advanced-use-of-descriptor-tables#changing-descriptor-table-entries-between-rendering-calls) and [descriptor set frequency (Vulkan)](https://vkguide.dev/docs/chapter-4/descriptors/#mental-model) for details. +While bind groups can easily be set all at once using the `set_bind_groups` function, it's recommended to organize bindings into bindgroups based on their update frequency. Bind group 0 will change the least frequently like per frame resources with bind group 3 changing most frequently like per draw resources. Bind groups can be set individually using their `set(render_pass)` method. This can provide a small performance improvement for scenes with many draw calls. See [descriptor table frequency (DX12)](https://learn.microsoft.com/en-us/windows/win32/direct3d12/advanced-use-of-descriptor-tables#changing-descriptor-table-entries-between-rendering-calls) and [descriptor set frequency (Vulkan)](https://vkguide.dev/docs/chapter-4/descriptors/#mental-model) for details. Organizing bind groups in this way can also help to better organize rendering resources in application code instead of redundantly storing all resources with each object. The `bindgroups::BindGroup0` may only need to be stored once while `bindgroups::BindGroup3` may be stored for each mesh in the scene. Note that bind groups store references to their underlying resource bindings, so it is not necessary to recreate a bind group if the only the uniform or storage buffer contents change. Avoid creating new bind groups during rendering if possible for best performance. diff --git a/example/src/shader_bindings.rs b/example/src/shader_bindings.rs index cddb8a8..2652f6d 100644 --- a/example/src/shader_bindings.rs +++ b/example/src/shader_bindings.rs @@ -491,384 +491,369 @@ pub mod testbed { data.build() } } - pub mod bind_groups { - use super::{_root, _root::*}; - #[derive(Debug)] - pub struct WgpuBindGroup0EntriesParams<'a> { - pub color_texture: &'a wgpu::TextureView, - pub color_sampler: &'a wgpu::Sampler, - } - #[derive(Clone, Debug)] - pub struct WgpuBindGroup0Entries<'a> { - pub color_texture: wgpu::BindGroupEntry<'a>, - pub color_sampler: wgpu::BindGroupEntry<'a>, - } - impl<'a> WgpuBindGroup0Entries<'a> { - pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { - Self { - color_texture: wgpu::BindGroupEntry { - binding: 0, - resource: wgpu::BindingResource::TextureView( - params.color_texture, - ), - }, - color_sampler: wgpu::BindGroupEntry { - binding: 1, - resource: wgpu::BindingResource::Sampler(params.color_sampler), - }, - } - } - pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 2] { - [self.color_texture, self.color_sampler] - } - pub fn collect>>(self) -> B { - self.as_array().into_iter().collect() + #[derive(Debug)] + pub struct WgpuBindGroup0EntriesParams<'a> { + pub color_texture: &'a wgpu::TextureView, + pub color_sampler: &'a wgpu::Sampler, + } + #[derive(Clone, Debug)] + pub struct WgpuBindGroup0Entries<'a> { + pub color_texture: wgpu::BindGroupEntry<'a>, + pub color_sampler: wgpu::BindGroupEntry<'a>, + } + impl<'a> WgpuBindGroup0Entries<'a> { + pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { + Self { + color_texture: wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::TextureView(params.color_texture), + }, + color_sampler: wgpu::BindGroupEntry { + binding: 1, + resource: wgpu::BindingResource::Sampler(params.color_sampler), + }, } } - #[derive(Debug)] - pub struct WgpuBindGroup0(wgpu::BindGroup); - impl WgpuBindGroup0 { - pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { - label: Some("Testbed::BindGroup0::LayoutDescriptor"), - entries: &[ - /// @binding(0): "color_texture" - wgpu::BindGroupLayoutEntry { - binding: 0, - visibility: wgpu::ShaderStages::COMPUTE, - ty: wgpu::BindingType::Texture { - sample_type: wgpu::TextureSampleType::Float { - filterable: true, - }, - view_dimension: wgpu::TextureViewDimension::D2, - multisampled: false, + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 2] { + [self.color_texture, self.color_sampler] + } + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() + } + } + #[derive(Debug)] + pub struct WgpuBindGroup0(wgpu::BindGroup); + impl WgpuBindGroup0 { + pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { + label: Some("Testbed::BindGroup0::LayoutDescriptor"), + entries: &[ + /// @binding(0): "color_texture" + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStages::COMPUTE, + ty: wgpu::BindingType::Texture { + sample_type: wgpu::TextureSampleType::Float { + filterable: true, }, - count: None, + view_dimension: wgpu::TextureViewDimension::D2, + multisampled: false, }, - /// @binding(1): "color_sampler" - wgpu::BindGroupLayoutEntry { - binding: 1, - visibility: wgpu::ShaderStages::COMPUTE, - ty: wgpu::BindingType::Sampler( - wgpu::SamplerBindingType::Filtering, - ), - count: None, + count: None, + }, + /// @binding(1): "color_sampler" + wgpu::BindGroupLayoutEntry { + binding: 1, + visibility: wgpu::ShaderStages::COMPUTE, + ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering), + count: None, + }, + ], + }; + pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout { + device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) + } + pub fn from_bindings( + device: &wgpu::Device, + bindings: WgpuBindGroup0Entries, + ) -> Self { + let bind_group_layout = Self::get_bind_group_layout(&device); + let entries = bindings.as_array(); + let bind_group = device + .create_bind_group( + &wgpu::BindGroupDescriptor { + label: Some("Testbed::BindGroup0"), + layout: &bind_group_layout, + entries: &entries, }, - ], - }; - pub fn get_bind_group_layout( - device: &wgpu::Device, - ) -> wgpu::BindGroupLayout { - device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) - } - pub fn from_bindings( - device: &wgpu::Device, - bindings: WgpuBindGroup0Entries, - ) -> Self { - let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.as_array(); - let bind_group = device - .create_bind_group( - &wgpu::BindGroupDescriptor { - label: Some("Testbed::BindGroup0"), - layout: &bind_group_layout, - entries: &entries, - }, - ); - Self(bind_group) - } - pub fn set<'a>(&'a self, render_pass: &mut wgpu::ComputePass<'a>) { - render_pass.set_bind_group(0, &self.0, &[]); + ); + Self(bind_group) + } + pub fn set<'a>(&'a self, render_pass: &mut wgpu::ComputePass<'a>) { + render_pass.set_bind_group(0, &self.0, &[]); + } + } + #[derive(Debug)] + pub struct WgpuBindGroup1EntriesParams<'a> { + pub uniforms: wgpu::BufferBinding<'a>, + } + #[derive(Clone, Debug)] + pub struct WgpuBindGroup1Entries<'a> { + pub uniforms: wgpu::BindGroupEntry<'a>, + } + impl<'a> WgpuBindGroup1Entries<'a> { + pub fn new(params: WgpuBindGroup1EntriesParams<'a>) -> Self { + Self { + uniforms: wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::Buffer(params.uniforms), + }, } } - #[derive(Debug)] - pub struct WgpuBindGroup1EntriesParams<'a> { - pub uniforms: wgpu::BufferBinding<'a>, + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { + [self.uniforms] } - #[derive(Clone, Debug)] - pub struct WgpuBindGroup1Entries<'a> { - pub uniforms: wgpu::BindGroupEntry<'a>, + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() } - impl<'a> WgpuBindGroup1Entries<'a> { - pub fn new(params: WgpuBindGroup1EntriesParams<'a>) -> Self { - Self { - uniforms: wgpu::BindGroupEntry { - binding: 0, - resource: wgpu::BindingResource::Buffer(params.uniforms), + } + #[derive(Debug)] + pub struct WgpuBindGroup1(wgpu::BindGroup); + impl WgpuBindGroup1 { + pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { + label: Some("Testbed::BindGroup1::LayoutDescriptor"), + entries: &[ + /// @binding(0): "uniforms" + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStages::COMPUTE, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: std::num::NonZeroU64::new( + std::mem::size_of::<_root::testbed::Uniforms>() as _, + ), }, - } - } - pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { - [self.uniforms] - } - pub fn collect>>(self) -> B { - self.as_array().into_iter().collect() - } + count: None, + }, + ], + }; + pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout { + device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) } - #[derive(Debug)] - pub struct WgpuBindGroup1(wgpu::BindGroup); - impl WgpuBindGroup1 { - pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { - label: Some("Testbed::BindGroup1::LayoutDescriptor"), - entries: &[ - /// @binding(0): "uniforms" - wgpu::BindGroupLayoutEntry { - binding: 0, - visibility: wgpu::ShaderStages::COMPUTE, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::<_root::testbed::Uniforms>() as _, - ), - }, - count: None, + pub fn from_bindings( + device: &wgpu::Device, + bindings: WgpuBindGroup1Entries, + ) -> Self { + let bind_group_layout = Self::get_bind_group_layout(&device); + let entries = bindings.as_array(); + let bind_group = device + .create_bind_group( + &wgpu::BindGroupDescriptor { + label: Some("Testbed::BindGroup1"), + layout: &bind_group_layout, + entries: &entries, }, - ], - }; - pub fn get_bind_group_layout( - device: &wgpu::Device, - ) -> wgpu::BindGroupLayout { - device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) - } - pub fn from_bindings( - device: &wgpu::Device, - bindings: WgpuBindGroup1Entries, - ) -> Self { - let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.as_array(); - let bind_group = device - .create_bind_group( - &wgpu::BindGroupDescriptor { - label: Some("Testbed::BindGroup1"), - layout: &bind_group_layout, - entries: &entries, - }, - ); - Self(bind_group) - } - pub fn set<'a>(&'a self, render_pass: &mut wgpu::ComputePass<'a>) { - render_pass.set_bind_group(1, &self.0, &[]); - } + ); + Self(bind_group) } - #[derive(Debug)] - pub struct WgpuBindGroup2EntriesParams<'a> { - pub a: wgpu::BufferBinding<'a>, - pub b: wgpu::BufferBinding<'a>, - pub c: wgpu::BufferBinding<'a>, - pub d: wgpu::BufferBinding<'a>, - pub f: wgpu::BufferBinding<'a>, - pub h: wgpu::BufferBinding<'a>, - pub i: wgpu::BufferBinding<'a>, - } - #[derive(Clone, Debug)] - pub struct WgpuBindGroup2Entries<'a> { - pub a: wgpu::BindGroupEntry<'a>, - pub b: wgpu::BindGroupEntry<'a>, - pub c: wgpu::BindGroupEntry<'a>, - pub d: wgpu::BindGroupEntry<'a>, - pub f: wgpu::BindGroupEntry<'a>, - pub h: wgpu::BindGroupEntry<'a>, - pub i: wgpu::BindGroupEntry<'a>, - } - impl<'a> WgpuBindGroup2Entries<'a> { - pub fn new(params: WgpuBindGroup2EntriesParams<'a>) -> Self { - Self { - a: wgpu::BindGroupEntry { - binding: 2, - resource: wgpu::BindingResource::Buffer(params.a), - }, - b: wgpu::BindGroupEntry { - binding: 3, - resource: wgpu::BindingResource::Buffer(params.b), - }, - c: wgpu::BindGroupEntry { - binding: 4, - resource: wgpu::BindingResource::Buffer(params.c), - }, - d: wgpu::BindGroupEntry { - binding: 5, - resource: wgpu::BindingResource::Buffer(params.d), - }, - f: wgpu::BindGroupEntry { - binding: 6, - resource: wgpu::BindingResource::Buffer(params.f), - }, - h: wgpu::BindGroupEntry { - binding: 8, - resource: wgpu::BindingResource::Buffer(params.h), - }, - i: wgpu::BindGroupEntry { - binding: 9, - resource: wgpu::BindingResource::Buffer(params.i), - }, - } - } - pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 7] { - [self.a, self.b, self.c, self.d, self.f, self.h, self.i] - } - pub fn collect>>(self) -> B { - self.as_array().into_iter().collect() + pub fn set<'a>(&'a self, render_pass: &mut wgpu::ComputePass<'a>) { + render_pass.set_bind_group(1, &self.0, &[]); + } + } + #[derive(Debug)] + pub struct WgpuBindGroup2EntriesParams<'a> { + pub a: wgpu::BufferBinding<'a>, + pub b: wgpu::BufferBinding<'a>, + pub c: wgpu::BufferBinding<'a>, + pub d: wgpu::BufferBinding<'a>, + pub f: wgpu::BufferBinding<'a>, + pub h: wgpu::BufferBinding<'a>, + pub i: wgpu::BufferBinding<'a>, + } + #[derive(Clone, Debug)] + pub struct WgpuBindGroup2Entries<'a> { + pub a: wgpu::BindGroupEntry<'a>, + pub b: wgpu::BindGroupEntry<'a>, + pub c: wgpu::BindGroupEntry<'a>, + pub d: wgpu::BindGroupEntry<'a>, + pub f: wgpu::BindGroupEntry<'a>, + pub h: wgpu::BindGroupEntry<'a>, + pub i: wgpu::BindGroupEntry<'a>, + } + impl<'a> WgpuBindGroup2Entries<'a> { + pub fn new(params: WgpuBindGroup2EntriesParams<'a>) -> Self { + Self { + a: wgpu::BindGroupEntry { + binding: 2, + resource: wgpu::BindingResource::Buffer(params.a), + }, + b: wgpu::BindGroupEntry { + binding: 3, + resource: wgpu::BindingResource::Buffer(params.b), + }, + c: wgpu::BindGroupEntry { + binding: 4, + resource: wgpu::BindingResource::Buffer(params.c), + }, + d: wgpu::BindGroupEntry { + binding: 5, + resource: wgpu::BindingResource::Buffer(params.d), + }, + f: wgpu::BindGroupEntry { + binding: 6, + resource: wgpu::BindingResource::Buffer(params.f), + }, + h: wgpu::BindGroupEntry { + binding: 8, + resource: wgpu::BindingResource::Buffer(params.h), + }, + i: wgpu::BindGroupEntry { + binding: 9, + resource: wgpu::BindingResource::Buffer(params.i), + }, } } - #[derive(Debug)] - pub struct WgpuBindGroup2(wgpu::BindGroup); - impl WgpuBindGroup2 { - pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { - label: Some("Testbed::BindGroup2::LayoutDescriptor"), - entries: &[ - /// @binding(2): "a" - wgpu::BindGroupLayoutEntry { - binding: 2, - visibility: wgpu::ShaderStages::COMPUTE, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Storage { - read_only: true, - }, - has_dynamic_offset: false, - min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::() as _, - ), + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 7] { + [self.a, self.b, self.c, self.d, self.f, self.h, self.i] + } + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() + } + } + #[derive(Debug)] + pub struct WgpuBindGroup2(wgpu::BindGroup); + impl WgpuBindGroup2 { + pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { + label: Some("Testbed::BindGroup2::LayoutDescriptor"), + entries: &[ + /// @binding(2): "a" + wgpu::BindGroupLayoutEntry { + binding: 2, + visibility: wgpu::ShaderStages::COMPUTE, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Storage { + read_only: true, }, - count: None, + has_dynamic_offset: false, + min_binding_size: std::num::NonZeroU64::new( + std::mem::size_of::() as _, + ), }, - /// @binding(3): "b" - wgpu::BindGroupLayoutEntry { - binding: 3, - visibility: wgpu::ShaderStages::COMPUTE, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Storage { - read_only: true, - }, - has_dynamic_offset: false, - min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::<_root::utils::types::VectorsU32>() as _, - ), + count: None, + }, + /// @binding(3): "b" + wgpu::BindGroupLayoutEntry { + binding: 3, + visibility: wgpu::ShaderStages::COMPUTE, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Storage { + read_only: true, }, - count: None, + has_dynamic_offset: false, + min_binding_size: std::num::NonZeroU64::new( + std::mem::size_of::<_root::utils::types::VectorsU32>() as _, + ), }, - /// @binding(4): "c" - wgpu::BindGroupLayoutEntry { - binding: 4, - visibility: wgpu::ShaderStages::COMPUTE, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Storage { - read_only: true, - }, - has_dynamic_offset: false, - min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::<_root::utils::types::VectorsI32>() as _, - ), + count: None, + }, + /// @binding(4): "c" + wgpu::BindGroupLayoutEntry { + binding: 4, + visibility: wgpu::ShaderStages::COMPUTE, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Storage { + read_only: true, }, - count: None, + has_dynamic_offset: false, + min_binding_size: std::num::NonZeroU64::new( + std::mem::size_of::<_root::utils::types::VectorsI32>() as _, + ), }, - /// @binding(5): "d" - wgpu::BindGroupLayoutEntry { - binding: 5, - visibility: wgpu::ShaderStages::COMPUTE, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Storage { - read_only: true, - }, - has_dynamic_offset: false, - min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::<_root::utils::types::VectorsF32>() as _, - ), + count: None, + }, + /// @binding(5): "d" + wgpu::BindGroupLayoutEntry { + binding: 5, + visibility: wgpu::ShaderStages::COMPUTE, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Storage { + read_only: true, }, - count: None, + has_dynamic_offset: false, + min_binding_size: std::num::NonZeroU64::new( + std::mem::size_of::<_root::utils::types::VectorsF32>() as _, + ), }, - /// @binding(6): "f" - wgpu::BindGroupLayoutEntry { - binding: 6, - visibility: wgpu::ShaderStages::COMPUTE, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Storage { - read_only: true, - }, - has_dynamic_offset: false, - min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::<_root::utils::types::MatricesF32>() as _, - ), + count: None, + }, + /// @binding(6): "f" + wgpu::BindGroupLayoutEntry { + binding: 6, + visibility: wgpu::ShaderStages::COMPUTE, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Storage { + read_only: true, }, - count: None, + has_dynamic_offset: false, + min_binding_size: std::num::NonZeroU64::new( + std::mem::size_of::<_root::utils::types::MatricesF32>() as _, + ), }, - /// @binding(8): "h" - wgpu::BindGroupLayoutEntry { - binding: 8, - visibility: wgpu::ShaderStages::COMPUTE, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Storage { - read_only: true, - }, - has_dynamic_offset: false, - min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::<_root::utils::types::StaticArrays>() - as _, - ), + count: None, + }, + /// @binding(8): "h" + wgpu::BindGroupLayoutEntry { + binding: 8, + visibility: wgpu::ShaderStages::COMPUTE, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Storage { + read_only: true, }, - count: None, + has_dynamic_offset: false, + min_binding_size: std::num::NonZeroU64::new( + std::mem::size_of::<_root::utils::types::StaticArrays>() as _, + ), }, - /// @binding(9): "i" - wgpu::BindGroupLayoutEntry { - binding: 9, - visibility: wgpu::ShaderStages::COMPUTE, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Storage { - read_only: true, - }, - has_dynamic_offset: false, - min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::<_root::utils::types::Nested>() as _, - ), + count: None, + }, + /// @binding(9): "i" + wgpu::BindGroupLayoutEntry { + binding: 9, + visibility: wgpu::ShaderStages::COMPUTE, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Storage { + read_only: true, }, - count: None, + has_dynamic_offset: false, + min_binding_size: std::num::NonZeroU64::new( + std::mem::size_of::<_root::utils::types::Nested>() as _, + ), }, - ], - }; - pub fn get_bind_group_layout( - device: &wgpu::Device, - ) -> wgpu::BindGroupLayout { - device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) - } - pub fn from_bindings( - device: &wgpu::Device, - bindings: WgpuBindGroup2Entries, - ) -> Self { - let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.as_array(); - let bind_group = device - .create_bind_group( - &wgpu::BindGroupDescriptor { - label: Some("Testbed::BindGroup2"), - layout: &bind_group_layout, - entries: &entries, - }, - ); - Self(bind_group) - } - pub fn set<'a>(&'a self, render_pass: &mut wgpu::ComputePass<'a>) { - render_pass.set_bind_group(2, &self.0, &[]); - } + count: None, + }, + ], + }; + pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout { + device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) } - #[derive(Debug, Copy, Clone)] - pub struct WgpuBindGroups<'a> { - pub bind_group0: &'a WgpuBindGroup0, - pub bind_group1: &'a WgpuBindGroup1, - pub bind_group2: &'a WgpuBindGroup2, - } - impl<'a> WgpuBindGroups<'a> { - pub fn set(&self, pass: &mut wgpu::ComputePass<'a>) { - self.bind_group0.set(pass); - self.bind_group1.set(pass); - self.bind_group2.set(pass); - } + pub fn from_bindings( + device: &wgpu::Device, + bindings: WgpuBindGroup2Entries, + ) -> Self { + let bind_group_layout = Self::get_bind_group_layout(&device); + let entries = bindings.as_array(); + let bind_group = device + .create_bind_group( + &wgpu::BindGroupDescriptor { + label: Some("Testbed::BindGroup2"), + layout: &bind_group_layout, + entries: &entries, + }, + ); + Self(bind_group) + } + pub fn set<'a>(&'a self, render_pass: &mut wgpu::ComputePass<'a>) { + render_pass.set_bind_group(2, &self.0, &[]); + } + } + #[derive(Debug, Copy, Clone)] + pub struct WgpuBindGroups<'a> { + pub bind_group0: &'a WgpuBindGroup0, + pub bind_group1: &'a WgpuBindGroup1, + pub bind_group2: &'a WgpuBindGroup2, + } + impl<'a> WgpuBindGroups<'a> { + pub fn set(&self, pass: &mut wgpu::ComputePass<'a>) { + self.bind_group0.set(pass); + self.bind_group1.set(pass); + self.bind_group2.set(pass); } } - pub use self::bind_groups::*; pub fn set_bind_groups<'a>( pass: &mut wgpu::ComputePass<'a>, - bind_group0: &'a bind_groups::WgpuBindGroup0, - bind_group1: &'a bind_groups::WgpuBindGroup1, - bind_group2: &'a bind_groups::WgpuBindGroup2, + bind_group0: &'a WgpuBindGroup0, + bind_group1: &'a WgpuBindGroup1, + bind_group2: &'a WgpuBindGroup2, ) { bind_group0.set(pass); bind_group1.set(pass); @@ -950,9 +935,9 @@ pub mod testbed { &wgpu::PipelineLayoutDescriptor { label: Some("Testbed::PipelineLayout"), bind_group_layouts: &[ - &bind_groups::WgpuBindGroup0::get_bind_group_layout(device), - &bind_groups::WgpuBindGroup1::get_bind_group_layout(device), - &bind_groups::WgpuBindGroup2::get_bind_group_layout(device), + &WgpuBindGroup0::get_bind_group_layout(device), + &WgpuBindGroup1::get_bind_group_layout(device), + &WgpuBindGroup2::get_bind_group_layout(device), ], push_constant_ranges: &[], }, @@ -1210,182 +1195,170 @@ pub mod triangle { } } } - pub mod bind_groups { - use super::{_root, _root::*}; - #[derive(Debug)] - pub struct WgpuBindGroup0EntriesParams<'a> { - pub color_texture: &'a wgpu::TextureView, - pub color_sampler: &'a wgpu::Sampler, - } - #[derive(Clone, Debug)] - pub struct WgpuBindGroup0Entries<'a> { - pub color_texture: wgpu::BindGroupEntry<'a>, - pub color_sampler: wgpu::BindGroupEntry<'a>, - } - impl<'a> WgpuBindGroup0Entries<'a> { - pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { - Self { - color_texture: wgpu::BindGroupEntry { - binding: 0, - resource: wgpu::BindingResource::TextureView( - params.color_texture, - ), - }, - color_sampler: wgpu::BindGroupEntry { - binding: 1, - resource: wgpu::BindingResource::Sampler(params.color_sampler), - }, - } - } - pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 2] { - [self.color_texture, self.color_sampler] - } - pub fn collect>>(self) -> B { - self.as_array().into_iter().collect() + #[derive(Debug)] + pub struct WgpuBindGroup0EntriesParams<'a> { + pub color_texture: &'a wgpu::TextureView, + pub color_sampler: &'a wgpu::Sampler, + } + #[derive(Clone, Debug)] + pub struct WgpuBindGroup0Entries<'a> { + pub color_texture: wgpu::BindGroupEntry<'a>, + pub color_sampler: wgpu::BindGroupEntry<'a>, + } + impl<'a> WgpuBindGroup0Entries<'a> { + pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { + Self { + color_texture: wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::TextureView(params.color_texture), + }, + color_sampler: wgpu::BindGroupEntry { + binding: 1, + resource: wgpu::BindingResource::Sampler(params.color_sampler), + }, } } - #[derive(Debug)] - pub struct WgpuBindGroup0(wgpu::BindGroup); - impl WgpuBindGroup0 { - pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { - label: Some("Triangle::BindGroup0::LayoutDescriptor"), - entries: &[ - /// @binding(0): "color_texture" - wgpu::BindGroupLayoutEntry { - binding: 0, - visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, - ty: wgpu::BindingType::Texture { - sample_type: wgpu::TextureSampleType::Float { - filterable: true, - }, - view_dimension: wgpu::TextureViewDimension::D2, - multisampled: false, + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 2] { + [self.color_texture, self.color_sampler] + } + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() + } + } + #[derive(Debug)] + pub struct WgpuBindGroup0(wgpu::BindGroup); + impl WgpuBindGroup0 { + pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { + label: Some("Triangle::BindGroup0::LayoutDescriptor"), + entries: &[ + /// @binding(0): "color_texture" + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, + ty: wgpu::BindingType::Texture { + sample_type: wgpu::TextureSampleType::Float { + filterable: true, }, - count: None, + view_dimension: wgpu::TextureViewDimension::D2, + multisampled: false, }, - /// @binding(1): "color_sampler" - wgpu::BindGroupLayoutEntry { - binding: 1, - visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, - ty: wgpu::BindingType::Sampler( - wgpu::SamplerBindingType::Filtering, - ), - count: None, + count: None, + }, + /// @binding(1): "color_sampler" + wgpu::BindGroupLayoutEntry { + binding: 1, + visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, + ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering), + count: None, + }, + ], + }; + pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout { + device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) + } + pub fn from_bindings( + device: &wgpu::Device, + bindings: WgpuBindGroup0Entries, + ) -> Self { + let bind_group_layout = Self::get_bind_group_layout(&device); + let entries = bindings.as_array(); + let bind_group = device + .create_bind_group( + &wgpu::BindGroupDescriptor { + label: Some("Triangle::BindGroup0"), + layout: &bind_group_layout, + entries: &entries, }, - ], - }; - pub fn get_bind_group_layout( - device: &wgpu::Device, - ) -> wgpu::BindGroupLayout { - device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) - } - pub fn from_bindings( - device: &wgpu::Device, - bindings: WgpuBindGroup0Entries, - ) -> Self { - let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.as_array(); - let bind_group = device - .create_bind_group( - &wgpu::BindGroupDescriptor { - label: Some("Triangle::BindGroup0"), - layout: &bind_group_layout, - entries: &entries, - }, - ); - Self(bind_group) - } - pub fn set<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>) { - render_pass.set_bind_group(0, &self.0, &[]); + ); + Self(bind_group) + } + pub fn set<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>) { + render_pass.set_bind_group(0, &self.0, &[]); + } + } + #[derive(Debug)] + pub struct WgpuBindGroup1EntriesParams<'a> { + pub uniforms: wgpu::BufferBinding<'a>, + } + #[derive(Clone, Debug)] + pub struct WgpuBindGroup1Entries<'a> { + pub uniforms: wgpu::BindGroupEntry<'a>, + } + impl<'a> WgpuBindGroup1Entries<'a> { + pub fn new(params: WgpuBindGroup1EntriesParams<'a>) -> Self { + Self { + uniforms: wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::Buffer(params.uniforms), + }, } } - #[derive(Debug)] - pub struct WgpuBindGroup1EntriesParams<'a> { - pub uniforms: wgpu::BufferBinding<'a>, + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { + [self.uniforms] } - #[derive(Clone, Debug)] - pub struct WgpuBindGroup1Entries<'a> { - pub uniforms: wgpu::BindGroupEntry<'a>, + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() } - impl<'a> WgpuBindGroup1Entries<'a> { - pub fn new(params: WgpuBindGroup1EntriesParams<'a>) -> Self { - Self { - uniforms: wgpu::BindGroupEntry { - binding: 0, - resource: wgpu::BindingResource::Buffer(params.uniforms), + } + #[derive(Debug)] + pub struct WgpuBindGroup1(wgpu::BindGroup); + impl WgpuBindGroup1 { + pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { + label: Some("Triangle::BindGroup1::LayoutDescriptor"), + entries: &[ + /// @binding(0): "uniforms" + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: std::num::NonZeroU64::new( + std::mem::size_of::<_root::triangle::Uniforms>() as _, + ), }, - } - } - pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { - [self.uniforms] - } - pub fn collect>>(self) -> B { - self.as_array().into_iter().collect() - } + count: None, + }, + ], + }; + pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout { + device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) } - #[derive(Debug)] - pub struct WgpuBindGroup1(wgpu::BindGroup); - impl WgpuBindGroup1 { - pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { - label: Some("Triangle::BindGroup1::LayoutDescriptor"), - entries: &[ - /// @binding(0): "uniforms" - wgpu::BindGroupLayoutEntry { - binding: 0, - visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::<_root::triangle::Uniforms>() as _, - ), - }, - count: None, + pub fn from_bindings( + device: &wgpu::Device, + bindings: WgpuBindGroup1Entries, + ) -> Self { + let bind_group_layout = Self::get_bind_group_layout(&device); + let entries = bindings.as_array(); + let bind_group = device + .create_bind_group( + &wgpu::BindGroupDescriptor { + label: Some("Triangle::BindGroup1"), + layout: &bind_group_layout, + entries: &entries, }, - ], - }; - pub fn get_bind_group_layout( - device: &wgpu::Device, - ) -> wgpu::BindGroupLayout { - device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) - } - pub fn from_bindings( - device: &wgpu::Device, - bindings: WgpuBindGroup1Entries, - ) -> Self { - let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.as_array(); - let bind_group = device - .create_bind_group( - &wgpu::BindGroupDescriptor { - label: Some("Triangle::BindGroup1"), - layout: &bind_group_layout, - entries: &entries, - }, - ); - Self(bind_group) - } - pub fn set<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>) { - render_pass.set_bind_group(1, &self.0, &[]); - } + ); + Self(bind_group) } - #[derive(Debug, Copy, Clone)] - pub struct WgpuBindGroups<'a> { - pub bind_group0: &'a WgpuBindGroup0, - pub bind_group1: &'a WgpuBindGroup1, + pub fn set<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>) { + render_pass.set_bind_group(1, &self.0, &[]); } - impl<'a> WgpuBindGroups<'a> { - pub fn set(&self, pass: &mut wgpu::RenderPass<'a>) { - self.bind_group0.set(pass); - self.bind_group1.set(pass); - } + } + #[derive(Debug, Copy, Clone)] + pub struct WgpuBindGroups<'a> { + pub bind_group0: &'a WgpuBindGroup0, + pub bind_group1: &'a WgpuBindGroup1, + } + impl<'a> WgpuBindGroups<'a> { + pub fn set(&self, pass: &mut wgpu::RenderPass<'a>) { + self.bind_group0.set(pass); + self.bind_group1.set(pass); } } - pub use self::bind_groups::*; pub fn set_bind_groups<'a>( pass: &mut wgpu::RenderPass<'a>, - bind_group0: &'a bind_groups::WgpuBindGroup0, - bind_group1: &'a bind_groups::WgpuBindGroup1, + bind_group0: &'a WgpuBindGroup0, + bind_group1: &'a WgpuBindGroup1, ) { bind_group0.set(pass); bind_group1.set(pass); @@ -1463,8 +1436,8 @@ pub mod triangle { &wgpu::PipelineLayoutDescriptor { label: Some("Triangle::PipelineLayout"), bind_group_layouts: &[ - &bind_groups::WgpuBindGroup0::get_bind_group_layout(device), - &bind_groups::WgpuBindGroup1::get_bind_group_layout(device), + &WgpuBindGroup0::get_bind_group_layout(device), + &WgpuBindGroup1::get_bind_group_layout(device), ], push_constant_ranges: &[], }, diff --git a/wgsl_bindgen/src/generate/bind_group/mod.rs b/wgsl_bindgen/src/generate/bind_group/mod.rs index 3f58db6..546e0ef 100644 --- a/wgsl_bindgen/src/generate/bind_group/mod.rs +++ b/wgsl_bindgen/src/generate/bind_group/mod.rs @@ -220,7 +220,7 @@ pub fn bind_groups_module( .wgpu_binding_generator .bind_group_layout .bind_group_name_ident(*group_no); - quote!(#group: &'a bind_groups::#group_name) + quote!(#group: &'a #group_name) }) .collect(); @@ -246,30 +246,20 @@ pub fn bind_groups_module( // Don't include empty modules. quote!() } else { - // Create a module to avoid name conflicts with user structs. - let mut bind_group_mod = RustModBuilder::new(true, false); - bind_group_mod.add( - "bind_groups", - quote! { - #(#bind_groups)* - - #[derive(Debug, Copy, Clone)] - pub struct WgpuBindGroups<'a> { - #(#bind_group_fields),* - } + quote! { + #(#bind_groups)* - impl<'a> WgpuBindGroups<'a> { - pub fn set(&self, pass: &mut #render_pass) { - #(self.#set_groups)* - } - } - }, - ); + #[derive(Debug, Copy, Clone)] + pub struct WgpuBindGroups<'a> { + #(#bind_group_fields),* + } - let bind_group_mod_tokens = bind_group_mod.generate(); - quote! { - #bind_group_mod_tokens - pub use self::bind_groups::*; // TODO: Perhaps remove the bind_groups mod + impl<'a> WgpuBindGroups<'a> { + pub fn set(&self, pass: &mut #render_pass) { + #(self.#set_groups)* + } + } + #set_bind_groups } } @@ -536,198 +526,194 @@ mod tests { assert_tokens_eq!( quote! { - pub mod bind_groups { - use super::{_root, _root::*}; - #[derive(Debug)] - pub struct WgpuBindGroup0EntriesParams<'a> { - pub src: wgpu::BufferBinding<'a>, - pub vertex_weights: wgpu::BufferBinding<'a>, - pub dst: wgpu::BufferBinding<'a>, - } - #[derive(Clone, Debug)] - pub struct WgpuBindGroup0Entries<'a> { - pub src: wgpu::BindGroupEntry<'a>, - pub vertex_weights: wgpu::BindGroupEntry<'a>, - pub dst: wgpu::BindGroupEntry<'a>, - } - impl<'a> WgpuBindGroup0Entries<'a> { - pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { - Self { - src: wgpu::BindGroupEntry { - binding: 0, - resource: wgpu::BindingResource::Buffer(params.src), - }, - vertex_weights: wgpu::BindGroupEntry { - binding: 1, - resource: wgpu::BindingResource::Buffer(params.vertex_weights), - }, - dst: wgpu::BindGroupEntry { - binding: 2, - resource: wgpu::BindingResource::Buffer(params.dst), - }, - } - } - pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 3] { - [ self.src, self.vertex_weights, self.dst ] - } - pub fn collect>>(self) -> B { - self.as_array().into_iter().collect() - } + #[derive(Debug)] + pub struct WgpuBindGroup0EntriesParams<'a> { + pub src: wgpu::BufferBinding<'a>, + pub vertex_weights: wgpu::BufferBinding<'a>, + pub dst: wgpu::BufferBinding<'a>, + } + #[derive(Clone, Debug)] + pub struct WgpuBindGroup0Entries<'a> { + pub src: wgpu::BindGroupEntry<'a>, + pub vertex_weights: wgpu::BindGroupEntry<'a>, + pub dst: wgpu::BindGroupEntry<'a>, + } + impl<'a> WgpuBindGroup0Entries<'a> { + pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { + Self { + src: wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::Buffer(params.src), + }, + vertex_weights: wgpu::BindGroupEntry { + binding: 1, + resource: wgpu::BindingResource::Buffer(params.vertex_weights), + }, + dst: wgpu::BindGroupEntry { + binding: 2, + resource: wgpu::BindingResource::Buffer(params.dst), + }, } - #[derive(Debug)] - pub struct WgpuBindGroup0(wgpu::BindGroup); - impl WgpuBindGroup0 { - pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { - label: Some("Test::BindGroup0::LayoutDescriptor"), - entries: &[ - /// @binding(0): "src" - wgpu::BindGroupLayoutEntry { - binding: 0, - visibility: wgpu::ShaderStages::COMPUTE, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Storage { - read_only: true, - }, - has_dynamic_offset: false, - min_binding_size: None, + } + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 3] { + [ self.src, self.vertex_weights, self.dst ] + } + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() + } + } + #[derive(Debug)] + pub struct WgpuBindGroup0(wgpu::BindGroup); + impl WgpuBindGroup0 { + pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { + label: Some("Test::BindGroup0::LayoutDescriptor"), + entries: &[ + /// @binding(0): "src" + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStages::COMPUTE, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Storage { + read_only: true, }, - count: None, + has_dynamic_offset: false, + min_binding_size: None, }, - /// @binding(1): "vertex_weights" - wgpu::BindGroupLayoutEntry { - binding: 1, - visibility: wgpu::ShaderStages::COMPUTE, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Storage { - read_only: true, - }, - has_dynamic_offset: false, - min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::<_root::test::VertexWeights>() as _, - ), + count: None, + }, + /// @binding(1): "vertex_weights" + wgpu::BindGroupLayoutEntry { + binding: 1, + visibility: wgpu::ShaderStages::COMPUTE, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Storage { + read_only: true, }, - count: None, + has_dynamic_offset: false, + min_binding_size: std::num::NonZeroU64::new( + std::mem::size_of::<_root::test::VertexWeights>() as _, + ), }, - /// @binding(2): "dst" - wgpu::BindGroupLayoutEntry { - binding: 2, - visibility: wgpu::ShaderStages::COMPUTE, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Storage { - read_only: false, - }, - has_dynamic_offset: false, - min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::<_root::test::Vertices>() as _, - ), + count: None, + }, + /// @binding(2): "dst" + wgpu::BindGroupLayoutEntry { + binding: 2, + visibility: wgpu::ShaderStages::COMPUTE, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Storage { + read_only: false, }, - count: None, + has_dynamic_offset: false, + min_binding_size: std::num::NonZeroU64::new( + std::mem::size_of::<_root::test::Vertices>() as _, + ), }, - ], - }; - pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout { - device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) - } - pub fn from_bindings(device: &wgpu::Device, bindings: WgpuBindGroup0Entries) -> Self { - let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.as_array(); - let bind_group = device - .create_bind_group( - &wgpu::BindGroupDescriptor { - label: Some("Test::BindGroup0"), - layout: &bind_group_layout, - entries: &entries, - }, - ); - Self(bind_group) - } - pub fn set<'a>(&'a self, render_pass: &mut wgpu::ComputePass<'a>) { - render_pass.set_bind_group(0, &self.0, &[]); - } + count: None, + }, + ], + }; + pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout { + device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) } - #[derive(Debug)] - pub struct WgpuBindGroup1EntriesParams<'a> { - pub transforms: wgpu::BufferBinding<'a>, + pub fn from_bindings(device: &wgpu::Device, bindings: WgpuBindGroup0Entries) -> Self { + let bind_group_layout = Self::get_bind_group_layout(&device); + let entries = bindings.as_array(); + let bind_group = device + .create_bind_group( + &wgpu::BindGroupDescriptor { + label: Some("Test::BindGroup0"), + layout: &bind_group_layout, + entries: &entries, + }, + ); + Self(bind_group) } - #[derive(Clone, Debug)] - pub struct WgpuBindGroup1Entries<'a> { - pub transforms: wgpu::BindGroupEntry<'a>, + pub fn set<'a>(&'a self, render_pass: &mut wgpu::ComputePass<'a>) { + render_pass.set_bind_group(0, &self.0, &[]); } - impl<'a> WgpuBindGroup1Entries<'a> { - pub fn new(params: WgpuBindGroup1EntriesParams<'a>) -> Self { - Self { - transforms: wgpu::BindGroupEntry { - binding: 0, - resource: wgpu::BindingResource::Buffer(params.transforms), - }, - } - } - pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { - [ self.transforms ] - } - pub fn collect>>(self) -> B { - self.as_array().into_iter().collect() - } + } + #[derive(Debug)] + pub struct WgpuBindGroup1EntriesParams<'a> { + pub transforms: wgpu::BufferBinding<'a>, + } + #[derive(Clone, Debug)] + pub struct WgpuBindGroup1Entries<'a> { + pub transforms: wgpu::BindGroupEntry<'a>, + } + impl<'a> WgpuBindGroup1Entries<'a> { + pub fn new(params: WgpuBindGroup1EntriesParams<'a>) -> Self { + Self { + transforms: wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::Buffer(params.transforms), + }, } - #[derive(Debug)] - pub struct WgpuBindGroup1(wgpu::BindGroup); - impl WgpuBindGroup1 { - pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { - label: Some("Test::BindGroup1::LayoutDescriptor"), - entries: &[ - /// @binding(0): "transforms" - wgpu::BindGroupLayoutEntry { - binding: 0, - visibility: wgpu::ShaderStages::COMPUTE, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::<_root::test::Transforms>() as _, - ), - }, - count: None, + } + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { + [ self.transforms ] + } + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() + } + } + #[derive(Debug)] + pub struct WgpuBindGroup1(wgpu::BindGroup); + impl WgpuBindGroup1 { + pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { + label: Some("Test::BindGroup1::LayoutDescriptor"), + entries: &[ + /// @binding(0): "transforms" + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStages::COMPUTE, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: std::num::NonZeroU64::new( + std::mem::size_of::<_root::test::Transforms>() as _, + ), }, - ], - }; - - pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout { - device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) - } - pub fn from_bindings(device: &wgpu::Device, bindings: WgpuBindGroup1Entries) -> Self { - let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.as_array(); - let bind_group = device - .create_bind_group( - &wgpu::BindGroupDescriptor { - label: Some("Test::BindGroup1"), - layout: &bind_group_layout, - entries: &entries, - }, - ); - Self(bind_group) - } - pub fn set<'a>(&'a self, render_pass: &mut wgpu::ComputePass<'a>) { - render_pass.set_bind_group(1, &self.0, &[]); - } + count: None, + }, + ], + }; + + pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout { + device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) + } + pub fn from_bindings(device: &wgpu::Device, bindings: WgpuBindGroup1Entries) -> Self { + let bind_group_layout = Self::get_bind_group_layout(&device); + let entries = bindings.as_array(); + let bind_group = device + .create_bind_group( + &wgpu::BindGroupDescriptor { + label: Some("Test::BindGroup1"), + layout: &bind_group_layout, + entries: &entries, + }, + ); + Self(bind_group) } - #[derive(Debug, Copy, Clone)] - pub struct WgpuBindGroups<'a> { - pub bind_group0: &'a WgpuBindGroup0, - pub bind_group1: &'a WgpuBindGroup1, + pub fn set<'a>(&'a self, render_pass: &mut wgpu::ComputePass<'a>) { + render_pass.set_bind_group(1, &self.0, &[]); } - impl<'a> WgpuBindGroups<'a> { - pub fn set(&self, pass: &mut wgpu::ComputePass<'a>) { - self.bind_group0.set(pass); - self.bind_group1.set(pass); - } + } + #[derive(Debug, Copy, Clone)] + pub struct WgpuBindGroups<'a> { + pub bind_group0: &'a WgpuBindGroup0, + pub bind_group1: &'a WgpuBindGroup1, + } + impl<'a> WgpuBindGroups<'a> { + pub fn set(&self, pass: &mut wgpu::ComputePass<'a>) { + self.bind_group0.set(pass); + self.bind_group1.set(pass); } } - pub use self::bind_groups::*; pub fn set_bind_groups<'a>( pass: &mut wgpu::ComputePass<'a>, - bind_group0: &'a bind_groups::WgpuBindGroup0, - bind_group1: &'a bind_groups::WgpuBindGroup1, + bind_group0: &'a WgpuBindGroup0, + bind_group1: &'a WgpuBindGroup1, ) { bind_group0.set(pass); bind_group1.set(pass); @@ -793,373 +779,369 @@ mod tests { // TODO: Are storage buffers valid for vertex/fragment? assert_tokens_eq!( quote! { - pub mod bind_groups { - use super::{_root, _root::*}; - #[derive(Debug)] - pub struct WgpuBindGroup0EntriesParams<'a> { - pub color_texture: &'a wgpu::TextureView, - pub color_texture_i32: &'a wgpu::TextureView, - pub color_texture_u32: &'a wgpu::TextureView, - pub color_sampler: &'a wgpu::Sampler, - pub depth_texture: &'a wgpu::TextureView, - pub comparison_sampler: &'a wgpu::Sampler, - pub storage_tex_read: &'a wgpu::TextureView, - pub storage_tex_write: &'a wgpu::TextureView, - pub storage_tex_read_write: &'a wgpu::TextureView, - pub color_texture_msaa: &'a wgpu::TextureView, - pub depth_texture_msaa: &'a wgpu::TextureView, - } - #[derive(Clone, Debug)] - pub struct WgpuBindGroup0Entries<'a> { - pub color_texture: wgpu::BindGroupEntry<'a>, - pub color_texture_i32: wgpu::BindGroupEntry<'a>, - pub color_texture_u32: wgpu::BindGroupEntry<'a>, - pub color_sampler: wgpu::BindGroupEntry<'a>, - pub depth_texture: wgpu::BindGroupEntry<'a>, - pub comparison_sampler: wgpu::BindGroupEntry<'a>, - pub storage_tex_read: wgpu::BindGroupEntry<'a>, - pub storage_tex_write: wgpu::BindGroupEntry<'a>, - pub storage_tex_read_write: wgpu::BindGroupEntry<'a>, - pub color_texture_msaa: wgpu::BindGroupEntry<'a>, - pub depth_texture_msaa: wgpu::BindGroupEntry<'a>, + #[derive(Debug)] + pub struct WgpuBindGroup0EntriesParams<'a> { + pub color_texture: &'a wgpu::TextureView, + pub color_texture_i32: &'a wgpu::TextureView, + pub color_texture_u32: &'a wgpu::TextureView, + pub color_sampler: &'a wgpu::Sampler, + pub depth_texture: &'a wgpu::TextureView, + pub comparison_sampler: &'a wgpu::Sampler, + pub storage_tex_read: &'a wgpu::TextureView, + pub storage_tex_write: &'a wgpu::TextureView, + pub storage_tex_read_write: &'a wgpu::TextureView, + pub color_texture_msaa: &'a wgpu::TextureView, + pub depth_texture_msaa: &'a wgpu::TextureView, + } + #[derive(Clone, Debug)] + pub struct WgpuBindGroup0Entries<'a> { + pub color_texture: wgpu::BindGroupEntry<'a>, + pub color_texture_i32: wgpu::BindGroupEntry<'a>, + pub color_texture_u32: wgpu::BindGroupEntry<'a>, + pub color_sampler: wgpu::BindGroupEntry<'a>, + pub depth_texture: wgpu::BindGroupEntry<'a>, + pub comparison_sampler: wgpu::BindGroupEntry<'a>, + pub storage_tex_read: wgpu::BindGroupEntry<'a>, + pub storage_tex_write: wgpu::BindGroupEntry<'a>, + pub storage_tex_read_write: wgpu::BindGroupEntry<'a>, + pub color_texture_msaa: wgpu::BindGroupEntry<'a>, + pub depth_texture_msaa: wgpu::BindGroupEntry<'a>, + } + impl<'a> WgpuBindGroup0Entries<'a> { + pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { + Self { + color_texture: wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::TextureView( + params.color_texture, + ), + }, + color_texture_i32: wgpu::BindGroupEntry { + binding: 1, + resource: wgpu::BindingResource::TextureView( + params.color_texture_i32, + ), + }, + color_texture_u32: wgpu::BindGroupEntry { + binding: 2, + resource: wgpu::BindingResource::TextureView( + params.color_texture_u32, + ), + }, + color_sampler: wgpu::BindGroupEntry { + binding: 3, + resource: wgpu::BindingResource::Sampler( + params.color_sampler, + ), + }, + depth_texture: wgpu::BindGroupEntry { + binding: 4, + resource: wgpu::BindingResource::TextureView( + params.depth_texture, + ), + }, + comparison_sampler: wgpu::BindGroupEntry { + binding: 5, + resource: wgpu::BindingResource::Sampler( + params.comparison_sampler, + ), + }, + storage_tex_read: wgpu::BindGroupEntry { + binding: 6, + resource: wgpu::BindingResource::TextureView( + params.storage_tex_read, + ), + }, + storage_tex_write: wgpu::BindGroupEntry { + binding: 7, + resource: wgpu::BindingResource::TextureView( + params.storage_tex_write, + ), + }, + storage_tex_read_write: wgpu::BindGroupEntry { + binding: 8, + resource: wgpu::BindingResource::TextureView( + params.storage_tex_read_write, + ), + }, + color_texture_msaa: wgpu::BindGroupEntry { + binding: 9, + resource: wgpu::BindingResource::TextureView( + params.color_texture_msaa, + ), + }, + depth_texture_msaa: wgpu::BindGroupEntry { + binding: 10, + resource: wgpu::BindingResource::TextureView( + params.depth_texture_msaa, + ), + }, + } - impl<'a> WgpuBindGroup0Entries<'a> { - pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { - Self { - color_texture: wgpu::BindGroupEntry { + } + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 11] { + [ + self.color_texture, + self.color_texture_i32, + self.color_texture_u32, + self.color_sampler, + self.depth_texture, + self.comparison_sampler, + self.storage_tex_read, + self.storage_tex_write, + self.storage_tex_read_write, + self.color_texture_msaa, + self.depth_texture_msaa, + ] + } + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() + } + } + #[derive(Debug)] + pub struct WgpuBindGroup0(wgpu::BindGroup); + impl WgpuBindGroup0 { + pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { + label: Some("Test::BindGroup0::LayoutDescriptor"), + entries: &[ + /// @binding(0): "color_texture" + wgpu::BindGroupLayoutEntry { binding: 0, - resource: wgpu::BindingResource::TextureView( - params.color_texture, - ), + visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, + ty: wgpu::BindingType::Texture { + sample_type: wgpu::TextureSampleType::Float { + filterable: true, + }, + view_dimension: wgpu::TextureViewDimension::D2, + multisampled: false, + }, + count: None, }, - color_texture_i32: wgpu::BindGroupEntry { + /// @binding(1): "color_texture_i32" + wgpu::BindGroupLayoutEntry { binding: 1, - resource: wgpu::BindingResource::TextureView( - params.color_texture_i32, - ), + visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, + ty: wgpu::BindingType::Texture { + sample_type: wgpu::TextureSampleType::Sint, + view_dimension: wgpu::TextureViewDimension::D2, + multisampled: false, + }, + count: None, }, - color_texture_u32: wgpu::BindGroupEntry { + /// @binding(2): "color_texture_u32" + wgpu::BindGroupLayoutEntry { binding: 2, - resource: wgpu::BindingResource::TextureView( - params.color_texture_u32, - ), + visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, + ty: wgpu::BindingType::Texture { + sample_type: wgpu::TextureSampleType::Uint, + view_dimension: wgpu::TextureViewDimension::D2, + multisampled: false, + }, + count: None, }, - color_sampler: wgpu::BindGroupEntry { + /// @binding(3): "color_sampler" + wgpu::BindGroupLayoutEntry { binding: 3, - resource: wgpu::BindingResource::Sampler( - params.color_sampler, - ), + visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, + ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering), + count: None, }, - depth_texture: wgpu::BindGroupEntry { + /// @binding(4): "depth_texture" + wgpu::BindGroupLayoutEntry { binding: 4, - resource: wgpu::BindingResource::TextureView( - params.depth_texture, - ), + visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, + ty: wgpu::BindingType::Texture { + sample_type: wgpu::TextureSampleType::Depth, + view_dimension: wgpu::TextureViewDimension::D2, + multisampled: false, + }, + count: None, }, - comparison_sampler: wgpu::BindGroupEntry { + /// @binding(5): "comparison_sampler" + wgpu::BindGroupLayoutEntry { binding: 5, - resource: wgpu::BindingResource::Sampler( - params.comparison_sampler, - ), + visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, + ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Comparison), + count: None, }, - storage_tex_read: wgpu::BindGroupEntry { + /// @binding(6): "storage_tex_read" + wgpu::BindGroupLayoutEntry { binding: 6, - resource: wgpu::BindingResource::TextureView( - params.storage_tex_read, - ), + visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, + ty: wgpu::BindingType::StorageTexture { + access: wgpu::StorageTextureAccess::ReadOnly, + format: wgpu::TextureFormat::R32Float, + view_dimension: wgpu::TextureViewDimension::D2, + }, + count: None, }, - storage_tex_write: wgpu::BindGroupEntry { + /// @binding(7): "storage_tex_write" + wgpu::BindGroupLayoutEntry { binding: 7, - resource: wgpu::BindingResource::TextureView( - params.storage_tex_write, - ), + visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, + ty: wgpu::BindingType::StorageTexture { + access: wgpu::StorageTextureAccess::WriteOnly, + format: wgpu::TextureFormat::Rg32Sint, + view_dimension: wgpu::TextureViewDimension::D2, + }, + count: None, }, - storage_tex_read_write: wgpu::BindGroupEntry { + /// @binding(8): "storage_tex_read_write" + wgpu::BindGroupLayoutEntry { binding: 8, - resource: wgpu::BindingResource::TextureView( - params.storage_tex_read_write, - ), + visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, + ty: wgpu::BindingType::StorageTexture { + access: wgpu::StorageTextureAccess::ReadWrite, + format: wgpu::TextureFormat::Rgba8Uint, + view_dimension: wgpu::TextureViewDimension::D2, + }, + count: None, }, - color_texture_msaa: wgpu::BindGroupEntry { + /// @binding(9): "color_texture_msaa" + wgpu::BindGroupLayoutEntry { binding: 9, - resource: wgpu::BindingResource::TextureView( - params.color_texture_msaa, - ), + visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, + ty: wgpu::BindingType::Texture { + sample_type: wgpu::TextureSampleType::Float { + filterable: true, + }, + view_dimension: wgpu::TextureViewDimension::D2, + multisampled: true, + }, + count: None, }, - depth_texture_msaa: wgpu::BindGroupEntry { + /// @binding(10): "depth_texture_msaa" + wgpu::BindGroupLayoutEntry { binding: 10, - resource: wgpu::BindingResource::TextureView( - params.depth_texture_msaa, - ), + visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, + ty: wgpu::BindingType::Texture { + sample_type: wgpu::TextureSampleType::Depth, + view_dimension: wgpu::TextureViewDimension::D2, + multisampled: true, + }, + count: None, }, - - } - } - pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 11] { - [ - self.color_texture, - self.color_texture_i32, - self.color_texture_u32, - self.color_sampler, - self.depth_texture, - self.comparison_sampler, - self.storage_tex_read, - self.storage_tex_write, - self.storage_tex_read_write, - self.color_texture_msaa, - self.depth_texture_msaa, - ] - } - pub fn collect>>(self) -> B { - self.as_array().into_iter().collect() - } + ], + }; + pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout { + device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) } - #[derive(Debug)] - pub struct WgpuBindGroup0(wgpu::BindGroup); - impl WgpuBindGroup0 { - pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { - label: Some("Test::BindGroup0::LayoutDescriptor"), - entries: &[ - /// @binding(0): "color_texture" - wgpu::BindGroupLayoutEntry { - binding: 0, - visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, - ty: wgpu::BindingType::Texture { - sample_type: wgpu::TextureSampleType::Float { - filterable: true, - }, - view_dimension: wgpu::TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }, - /// @binding(1): "color_texture_i32" - wgpu::BindGroupLayoutEntry { - binding: 1, - visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, - ty: wgpu::BindingType::Texture { - sample_type: wgpu::TextureSampleType::Sint, - view_dimension: wgpu::TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }, - /// @binding(2): "color_texture_u32" - wgpu::BindGroupLayoutEntry { - binding: 2, - visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, - ty: wgpu::BindingType::Texture { - sample_type: wgpu::TextureSampleType::Uint, - view_dimension: wgpu::TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }, - /// @binding(3): "color_sampler" - wgpu::BindGroupLayoutEntry { - binding: 3, - visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, - ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering), - count: None, - }, - /// @binding(4): "depth_texture" - wgpu::BindGroupLayoutEntry { - binding: 4, - visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, - ty: wgpu::BindingType::Texture { - sample_type: wgpu::TextureSampleType::Depth, - view_dimension: wgpu::TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }, - /// @binding(5): "comparison_sampler" - wgpu::BindGroupLayoutEntry { - binding: 5, - visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, - ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Comparison), - count: None, - }, - /// @binding(6): "storage_tex_read" - wgpu::BindGroupLayoutEntry { - binding: 6, - visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, - ty: wgpu::BindingType::StorageTexture { - access: wgpu::StorageTextureAccess::ReadOnly, - format: wgpu::TextureFormat::R32Float, - view_dimension: wgpu::TextureViewDimension::D2, - }, - count: None, - }, - /// @binding(7): "storage_tex_write" - wgpu::BindGroupLayoutEntry { - binding: 7, - visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, - ty: wgpu::BindingType::StorageTexture { - access: wgpu::StorageTextureAccess::WriteOnly, - format: wgpu::TextureFormat::Rg32Sint, - view_dimension: wgpu::TextureViewDimension::D2, - }, - count: None, - }, - /// @binding(8): "storage_tex_read_write" - wgpu::BindGroupLayoutEntry { - binding: 8, - visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, - ty: wgpu::BindingType::StorageTexture { - access: wgpu::StorageTextureAccess::ReadWrite, - format: wgpu::TextureFormat::Rgba8Uint, - view_dimension: wgpu::TextureViewDimension::D2, - }, - count: None, - }, - /// @binding(9): "color_texture_msaa" - wgpu::BindGroupLayoutEntry { - binding: 9, - visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, - ty: wgpu::BindingType::Texture { - sample_type: wgpu::TextureSampleType::Float { - filterable: true, - }, - view_dimension: wgpu::TextureViewDimension::D2, - multisampled: true, - }, - count: None, - }, - /// @binding(10): "depth_texture_msaa" - wgpu::BindGroupLayoutEntry { - binding: 10, - visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, - ty: wgpu::BindingType::Texture { - sample_type: wgpu::TextureSampleType::Depth, - view_dimension: wgpu::TextureViewDimension::D2, - multisampled: true, - }, - count: None, - }, - ], - }; - pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout { - device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) - } - pub fn from_bindings(device: &wgpu::Device, bindings: WgpuBindGroup0Entries) -> Self { - let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.as_array(); - let bind_group = device - .create_bind_group( - &wgpu::BindGroupDescriptor { - label: Some("Test::BindGroup0"), - layout: &bind_group_layout, - entries: &entries, - }, - ); - Self(bind_group) - } - pub fn set<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>) { - render_pass.set_bind_group(0, &self.0, &[]); - } + pub fn from_bindings(device: &wgpu::Device, bindings: WgpuBindGroup0Entries) -> Self { + let bind_group_layout = Self::get_bind_group_layout(&device); + let entries = bindings.as_array(); + let bind_group = device + .create_bind_group( + &wgpu::BindGroupDescriptor { + label: Some("Test::BindGroup0"), + layout: &bind_group_layout, + entries: &entries, + }, + ); + Self(bind_group) } - #[derive(Debug)] - pub struct WgpuBindGroup1EntriesParams<'a> { - pub transforms: wgpu::BufferBinding<'a>, - pub one: wgpu::BufferBinding<'a>, + pub fn set<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>) { + render_pass.set_bind_group(0, &self.0, &[]); } - #[derive(Clone, Debug)] - pub struct WgpuBindGroup1Entries<'a> { - pub transforms: wgpu::BindGroupEntry<'a>, - pub one: wgpu::BindGroupEntry<'a>, + } + #[derive(Debug)] + pub struct WgpuBindGroup1EntriesParams<'a> { + pub transforms: wgpu::BufferBinding<'a>, + pub one: wgpu::BufferBinding<'a>, + } + #[derive(Clone, Debug)] + pub struct WgpuBindGroup1Entries<'a> { + pub transforms: wgpu::BindGroupEntry<'a>, + pub one: wgpu::BindGroupEntry<'a>, + } + impl<'a> WgpuBindGroup1Entries<'a> { + pub fn new(params: WgpuBindGroup1EntriesParams<'a>) -> Self { + Self { + transforms: wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::Buffer(params.transforms), + }, + one: wgpu::BindGroupEntry { + binding: 1, + resource: wgpu::BindingResource::Buffer(params.one), + }, } - impl<'a> WgpuBindGroup1Entries<'a> { - pub fn new(params: WgpuBindGroup1EntriesParams<'a>) -> Self { - Self { - transforms: wgpu::BindGroupEntry { + } + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 2] { + [ self.transforms, self.one ] + } + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() + } + } + #[derive(Debug)] + pub struct WgpuBindGroup1(wgpu::BindGroup); + impl WgpuBindGroup1 { + pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { + label: Some("Test::BindGroup1::LayoutDescriptor"), + entries: &[ + /// @binding(0): "transforms" + wgpu::BindGroupLayoutEntry { binding: 0, - resource: wgpu::BindingResource::Buffer(params.transforms), + visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: std::num::NonZeroU64::new( + std::mem::size_of::<_root::test::Transforms>() as _, + ), + }, + count: None, }, - one: wgpu::BindGroupEntry { + /// @binding(1): "one" + wgpu::BindGroupLayoutEntry { binding: 1, - resource: wgpu::BindingResource::Buffer(params.one), + visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: std::num::NonZeroU64::new( + std::mem::size_of::() as _, + ), + }, + count: None, }, - } - } - pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 2] { - [ self.transforms, self.one ] - } - pub fn collect>>(self) -> B { - self.as_array().into_iter().collect() - } + ], + }; + pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout { + device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) } - #[derive(Debug)] - pub struct WgpuBindGroup1(wgpu::BindGroup); - impl WgpuBindGroup1 { - pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { - label: Some("Test::BindGroup1::LayoutDescriptor"), - entries: &[ - /// @binding(0): "transforms" - wgpu::BindGroupLayoutEntry { - binding: 0, - visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::<_root::test::Transforms>() as _, - ), - }, - count: None, - }, - /// @binding(1): "one" - wgpu::BindGroupLayoutEntry { - binding: 1, - visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::() as _, - ), - }, - count: None, - }, - ], - }; - pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout { - device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) - } - pub fn from_bindings(device: &wgpu::Device, bindings: WgpuBindGroup1Entries) -> Self { - let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.as_array(); - let bind_group = device - .create_bind_group( - &wgpu::BindGroupDescriptor { - label: Some("Test::BindGroup1"), - layout: &bind_group_layout, - entries: &entries, - }, - ); - Self(bind_group) - } - pub fn set<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>) { - render_pass.set_bind_group(1, &self.0, &[]); - } + pub fn from_bindings(device: &wgpu::Device, bindings: WgpuBindGroup1Entries) -> Self { + let bind_group_layout = Self::get_bind_group_layout(&device); + let entries = bindings.as_array(); + let bind_group = device + .create_bind_group( + &wgpu::BindGroupDescriptor { + label: Some("Test::BindGroup1"), + layout: &bind_group_layout, + entries: &entries, + }, + ); + Self(bind_group) } - #[derive(Debug, Copy, Clone)] - pub struct WgpuBindGroups<'a> { - pub bind_group0: &'a WgpuBindGroup0, - pub bind_group1: &'a WgpuBindGroup1, + pub fn set<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>) { + render_pass.set_bind_group(1, &self.0, &[]); } - impl<'a> WgpuBindGroups<'a> { - pub fn set(&self, pass: &mut wgpu::RenderPass<'a>) { - self.bind_group0.set(pass); - self.bind_group1.set(pass); - } + } + #[derive(Debug, Copy, Clone)] + pub struct WgpuBindGroups<'a> { + pub bind_group0: &'a WgpuBindGroup0, + pub bind_group1: &'a WgpuBindGroup1, + } + impl<'a> WgpuBindGroups<'a> { + pub fn set(&self, pass: &mut wgpu::RenderPass<'a>) { + self.bind_group0.set(pass); + self.bind_group1.set(pass); } } - pub use self::bind_groups::*; pub fn set_bind_groups<'a>( pass: &mut wgpu::RenderPass<'a>, - bind_group0: &'a bind_groups::WgpuBindGroup0, - bind_group1: &'a bind_groups::WgpuBindGroup1, + bind_group0: &'a WgpuBindGroup0, + bind_group1: &'a WgpuBindGroup1, ) { bind_group0.set(pass); @@ -1196,89 +1178,86 @@ mod tests { assert_tokens_eq!( quote! { - pub mod bind_groups { - use super::{_root, _root::*}; - #[derive(Debug)] - pub struct WgpuBindGroup0EntriesParams<'a> { - pub transforms: wgpu::BufferBinding<'a>, - } - #[derive(Clone, Debug)] - pub struct WgpuBindGroup0Entries<'a> { - pub transforms: wgpu::BindGroupEntry<'a>, - } - impl<'a> WgpuBindGroup0Entries<'a> { - pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { - Self { - transforms: wgpu::BindGroupEntry { - binding: 0, - resource: wgpu::BindingResource::Buffer(params.transforms), - }, - } - } - pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { - [ - self.transforms, - ] - } - pub fn collect>>(self) -> B { - self.as_array().into_iter().collect() - } + #[derive(Debug)] + pub struct WgpuBindGroup0EntriesParams<'a> { + pub transforms: wgpu::BufferBinding<'a>, + } + #[derive(Clone, Debug)] + pub struct WgpuBindGroup0Entries<'a> { + pub transforms: wgpu::BindGroupEntry<'a>, + } + impl<'a> WgpuBindGroup0Entries<'a> { + pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { + Self { + transforms: wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::Buffer(params.transforms), + }, } - #[derive(Debug)] - pub struct WgpuBindGroup0(wgpu::BindGroup); - impl WgpuBindGroup0 { - pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { - label: Some("Test::BindGroup0::LayoutDescriptor"), - entries: &[ - /// @binding(0): "transforms" - wgpu::BindGroupLayoutEntry { - binding: 0, - visibility: wgpu::ShaderStages::VERTEX, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::<_root::test::Transforms>() as _, - ), - }, - count: None, + } + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { + [ + self.transforms, + ] + } + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() + } + } + #[derive(Debug)] + pub struct WgpuBindGroup0(wgpu::BindGroup); + impl WgpuBindGroup0 { + pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { + label: Some("Test::BindGroup0::LayoutDescriptor"), + entries: &[ + /// @binding(0): "transforms" + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStages::VERTEX, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: std::num::NonZeroU64::new( + std::mem::size_of::<_root::test::Transforms>() as _, + ), }, - ], - }; - pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout { - device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) - } - pub fn from_bindings(device: &wgpu::Device, bindings: WgpuBindGroup0Entries) -> Self { - let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.as_array(); - let bind_group = device - .create_bind_group( - &wgpu::BindGroupDescriptor { - label: Some("Test::BindGroup0"), - layout: &bind_group_layout, - entries: &entries, - }, - ); - Self(bind_group) - } - pub fn set<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>) { - render_pass.set_bind_group(0, &self.0, &[]); - } + count: None, + }, + ], + }; + pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout { + device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) + } + pub fn from_bindings(device: &wgpu::Device, bindings: WgpuBindGroup0Entries) -> Self { + let bind_group_layout = Self::get_bind_group_layout(&device); + let entries = bindings.as_array(); + let bind_group = device + .create_bind_group( + &wgpu::BindGroupDescriptor { + label: Some("Test::BindGroup0"), + layout: &bind_group_layout, + entries: &entries, + }, + ); + Self(bind_group) } - #[derive(Debug, Copy, Clone)] - pub struct WgpuBindGroups<'a> { - pub bind_group0: &'a WgpuBindGroup0, + pub fn set<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>) { + render_pass.set_bind_group(0, &self.0, &[]); } - impl<'a> WgpuBindGroups<'a> { - pub fn set(&self, pass: &mut wgpu::RenderPass<'a>) { - self.bind_group0.set(pass); - } + } + #[derive(Debug, Copy, Clone)] + pub struct WgpuBindGroups<'a> { + pub bind_group0: &'a WgpuBindGroup0, + } + impl<'a> WgpuBindGroups<'a> { + pub fn set(&self, pass: &mut wgpu::RenderPass<'a>) { + self.bind_group0.set(pass); } } - pub use self::bind_groups::*; + pub fn set_bind_groups<'a>( pass: &mut wgpu::RenderPass<'a>, - bind_group0: &'a bind_groups::WgpuBindGroup0, + bind_group0: &'a WgpuBindGroup0, ) { bind_group0.set(pass); } @@ -1313,88 +1292,85 @@ mod tests { assert_tokens_eq!( quote! { - pub mod bind_groups { - use super::{_root, _root::*}; - #[derive(Debug)] - pub struct WgpuBindGroup0EntriesParams<'a> { - pub transforms: wgpu::BufferBinding<'a>, - } - #[derive(Clone, Debug)] - pub struct WgpuBindGroup0Entries<'a> { - pub transforms: wgpu::BindGroupEntry<'a>, + #[derive(Debug)] + pub struct WgpuBindGroup0EntriesParams<'a> { + pub transforms: wgpu::BufferBinding<'a>, + } + #[derive(Clone, Debug)] + pub struct WgpuBindGroup0Entries<'a> { + pub transforms: wgpu::BindGroupEntry<'a>, + } + impl<'a> WgpuBindGroup0Entries<'a> { + pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { + Self { + transforms: wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::Buffer(params.transforms), + }, } - impl<'a> WgpuBindGroup0Entries<'a> { - pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { - Self { - transforms: wgpu::BindGroupEntry { - binding: 0, - resource: wgpu::BindingResource::Buffer(params.transforms), + } + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { + [ self.transforms ] + } + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() + } + } + #[derive(Debug)] + pub struct WgpuBindGroup0(wgpu::BindGroup); + impl WgpuBindGroup0 { + pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { + label: Some("Test::BindGroup0::LayoutDescriptor"), + entries: &[ + /// @binding(0): "transforms" + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStages::FRAGMENT, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: std::num::NonZeroU64::new( + std::mem::size_of::<_root::test::Transforms>() as _, + ), }, - } - } - pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { - [ self.transforms ] - } - pub fn collect>>(self) -> B { - self.as_array().into_iter().collect() - } + count: None, + }, + ], + }; + + pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout { + device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) } - #[derive(Debug)] - pub struct WgpuBindGroup0(wgpu::BindGroup); - impl WgpuBindGroup0 { - pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { - label: Some("Test::BindGroup0::LayoutDescriptor"), - entries: &[ - /// @binding(0): "transforms" - wgpu::BindGroupLayoutEntry { - binding: 0, - visibility: wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::<_root::test::Transforms>() as _, - ), + pub fn from_bindings(device: &wgpu::Device, bindings: WgpuBindGroup0Entries) -> Self { + let bind_group_layout = Self::get_bind_group_layout(&device); + let entries = bindings.as_array(); + let bind_group = device + .create_bind_group( + &wgpu::BindGroupDescriptor { + label: Some("Test::BindGroup0"), + layout: &bind_group_layout, + entries: &entries, }, - count: None, - }, - ], - }; - - pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout { - device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) - } - pub fn from_bindings(device: &wgpu::Device, bindings: WgpuBindGroup0Entries) -> Self { - let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.as_array(); - let bind_group = device - .create_bind_group( - &wgpu::BindGroupDescriptor { - label: Some("Test::BindGroup0"), - layout: &bind_group_layout, - entries: &entries, - }, - ); - Self(bind_group) - } - pub fn set<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>) { - render_pass.set_bind_group(0, &self.0, &[]); - } + ); + Self(bind_group) } - #[derive(Debug, Copy, Clone)] - pub struct WgpuBindGroups<'a> { - pub bind_group0: &'a WgpuBindGroup0, + pub fn set<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>) { + render_pass.set_bind_group(0, &self.0, &[]); } - impl<'a> WgpuBindGroups<'a> { - pub fn set(&self, pass: &mut wgpu::RenderPass<'a>) { - self.bind_group0.set(pass); - } + } + #[derive(Debug, Copy, Clone)] + pub struct WgpuBindGroups<'a> { + pub bind_group0: &'a WgpuBindGroup0, + } + impl<'a> WgpuBindGroups<'a> { + pub fn set(&self, pass: &mut wgpu::RenderPass<'a>) { + self.bind_group0.set(pass); } } - pub use self::bind_groups::*; + pub fn set_bind_groups<'a>( pass: &mut wgpu::RenderPass<'a>, - bind_group0: &'a bind_groups::WgpuBindGroup0, + bind_group0: &'a WgpuBindGroup0, ) { bind_group0.set(pass); } diff --git a/wgsl_bindgen/src/generate/pipeline.rs b/wgsl_bindgen/src/generate/pipeline.rs index b1b6ad0..d60ecff 100644 --- a/wgsl_bindgen/src/generate/pipeline.rs +++ b/wgsl_bindgen/src/generate/pipeline.rs @@ -50,7 +50,7 @@ pub fn create_pipeline_layout_fn( .wgpu_binding_generator .bind_group_layout .bind_group_name_ident(*group_no); - quote!(bind_groups::#group::get_bind_group_layout(device)) + quote!(#group::get_bind_group_layout(device)) }) .collect(); diff --git a/wgsl_bindgen/tests/output/bindgen_bevy.expected.rs b/wgsl_bindgen/tests/output/bindgen_bevy.expected.rs index 2ee0df3..a229f94 100644 --- a/wgsl_bindgen/tests/output/bindgen_bevy.expected.rs +++ b/wgsl_bindgen/tests/output/bindgen_bevy.expected.rs @@ -698,407 +698,391 @@ pub mod bytemuck_impls { } pub mod pbr { use super::{_root, _root::*}; - pub mod bind_groups { - use super::{_root, _root::*}; - #[derive(Debug)] - pub struct WgpuBindGroup0EntriesParams<'a> { - pub view: wgpu::BufferBinding<'a>, - pub lights: wgpu::BufferBinding<'a>, - pub point_lights: wgpu::BufferBinding<'a>, - pub cluster_light_index_lists: wgpu::BufferBinding<'a>, - pub cluster_offsets_and_counts: wgpu::BufferBinding<'a>, - pub point_shadow_textures: &'a wgpu::TextureView, - pub point_shadow_textures_sampler: &'a wgpu::Sampler, - pub directional_shadow_textures: &'a wgpu::TextureView, - pub directional_shadow_textures_sampler: &'a wgpu::Sampler, - } - #[derive(Clone, Debug)] - pub struct WgpuBindGroup0Entries<'a> { - pub view: wgpu::BindGroupEntry<'a>, - pub lights: wgpu::BindGroupEntry<'a>, - pub point_lights: wgpu::BindGroupEntry<'a>, - pub cluster_light_index_lists: wgpu::BindGroupEntry<'a>, - pub cluster_offsets_and_counts: wgpu::BindGroupEntry<'a>, - pub point_shadow_textures: wgpu::BindGroupEntry<'a>, - pub point_shadow_textures_sampler: wgpu::BindGroupEntry<'a>, - pub directional_shadow_textures: wgpu::BindGroupEntry<'a>, - pub directional_shadow_textures_sampler: wgpu::BindGroupEntry<'a>, - } - impl<'a> WgpuBindGroup0Entries<'a> { - pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { - Self { - view: wgpu::BindGroupEntry { - binding: 0, - resource: wgpu::BindingResource::Buffer(params.view), - }, - lights: wgpu::BindGroupEntry { - binding: 1, - resource: wgpu::BindingResource::Buffer(params.lights), - }, - point_lights: wgpu::BindGroupEntry { - binding: 6, - resource: wgpu::BindingResource::Buffer(params.point_lights), - }, - cluster_light_index_lists: wgpu::BindGroupEntry { - binding: 7, - resource: wgpu::BindingResource::Buffer( - params.cluster_light_index_lists, - ), - }, - cluster_offsets_and_counts: wgpu::BindGroupEntry { - binding: 8, - resource: wgpu::BindingResource::Buffer( - params.cluster_offsets_and_counts, - ), - }, - point_shadow_textures: wgpu::BindGroupEntry { - binding: 2, - resource: wgpu::BindingResource::TextureView( - params.point_shadow_textures, - ), - }, - point_shadow_textures_sampler: wgpu::BindGroupEntry { - binding: 3, - resource: wgpu::BindingResource::Sampler( - params.point_shadow_textures_sampler, - ), - }, - directional_shadow_textures: wgpu::BindGroupEntry { - binding: 4, - resource: wgpu::BindingResource::TextureView( - params.directional_shadow_textures, - ), - }, - directional_shadow_textures_sampler: wgpu::BindGroupEntry { - binding: 5, - resource: wgpu::BindingResource::Sampler( - params.directional_shadow_textures_sampler, - ), - }, - } - } - pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 9] { - [ - self.view, - self.lights, - self.point_lights, - self.cluster_light_index_lists, - self.cluster_offsets_and_counts, - self.point_shadow_textures, - self.point_shadow_textures_sampler, - self.directional_shadow_textures, - self.directional_shadow_textures_sampler, - ] - } - pub fn collect>>(self) -> B { - self.as_array().into_iter().collect() + #[derive(Debug)] + pub struct WgpuBindGroup0EntriesParams<'a> { + pub view: wgpu::BufferBinding<'a>, + pub lights: wgpu::BufferBinding<'a>, + pub point_lights: wgpu::BufferBinding<'a>, + pub cluster_light_index_lists: wgpu::BufferBinding<'a>, + pub cluster_offsets_and_counts: wgpu::BufferBinding<'a>, + pub point_shadow_textures: &'a wgpu::TextureView, + pub point_shadow_textures_sampler: &'a wgpu::Sampler, + pub directional_shadow_textures: &'a wgpu::TextureView, + pub directional_shadow_textures_sampler: &'a wgpu::Sampler, + } + #[derive(Clone, Debug)] + pub struct WgpuBindGroup0Entries<'a> { + pub view: wgpu::BindGroupEntry<'a>, + pub lights: wgpu::BindGroupEntry<'a>, + pub point_lights: wgpu::BindGroupEntry<'a>, + pub cluster_light_index_lists: wgpu::BindGroupEntry<'a>, + pub cluster_offsets_and_counts: wgpu::BindGroupEntry<'a>, + pub point_shadow_textures: wgpu::BindGroupEntry<'a>, + pub point_shadow_textures_sampler: wgpu::BindGroupEntry<'a>, + pub directional_shadow_textures: wgpu::BindGroupEntry<'a>, + pub directional_shadow_textures_sampler: wgpu::BindGroupEntry<'a>, + } + impl<'a> WgpuBindGroup0Entries<'a> { + pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { + Self { + view: wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::Buffer(params.view), + }, + lights: wgpu::BindGroupEntry { + binding: 1, + resource: wgpu::BindingResource::Buffer(params.lights), + }, + point_lights: wgpu::BindGroupEntry { + binding: 6, + resource: wgpu::BindingResource::Buffer(params.point_lights), + }, + cluster_light_index_lists: wgpu::BindGroupEntry { + binding: 7, + resource: wgpu::BindingResource::Buffer( + params.cluster_light_index_lists, + ), + }, + cluster_offsets_and_counts: wgpu::BindGroupEntry { + binding: 8, + resource: wgpu::BindingResource::Buffer( + params.cluster_offsets_and_counts, + ), + }, + point_shadow_textures: wgpu::BindGroupEntry { + binding: 2, + resource: wgpu::BindingResource::TextureView( + params.point_shadow_textures, + ), + }, + point_shadow_textures_sampler: wgpu::BindGroupEntry { + binding: 3, + resource: wgpu::BindingResource::Sampler( + params.point_shadow_textures_sampler, + ), + }, + directional_shadow_textures: wgpu::BindGroupEntry { + binding: 4, + resource: wgpu::BindingResource::TextureView( + params.directional_shadow_textures, + ), + }, + directional_shadow_textures_sampler: wgpu::BindGroupEntry { + binding: 5, + resource: wgpu::BindingResource::Sampler( + params.directional_shadow_textures_sampler, + ), + }, } } - #[derive(Debug)] - pub struct WgpuBindGroup0(wgpu::BindGroup); - impl WgpuBindGroup0 { - pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { - label: Some("Pbr::BindGroup0::LayoutDescriptor"), - entries: &[ - /// @binding(0): "_root::bevy_pbr::mesh_view_bindings::view" - wgpu::BindGroupLayoutEntry { - binding: 0, - visibility: wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::< - _root::bevy_pbr::mesh_view_types::View, - >() as _, - ), - }, - count: None, - }, - /// @binding(1): "_root::bevy_pbr::mesh_view_bindings::lights" - wgpu::BindGroupLayoutEntry { - binding: 1, - visibility: wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::< - _root::bevy_pbr::mesh_view_types::Lights, - >() as _, - ), - }, - count: None, + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 9] { + [ + self.view, + self.lights, + self.point_lights, + self.cluster_light_index_lists, + self.cluster_offsets_and_counts, + self.point_shadow_textures, + self.point_shadow_textures_sampler, + self.directional_shadow_textures, + self.directional_shadow_textures_sampler, + ] + } + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() + } + } + #[derive(Debug)] + pub struct WgpuBindGroup0(wgpu::BindGroup); + impl WgpuBindGroup0 { + pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { + label: Some("Pbr::BindGroup0::LayoutDescriptor"), + entries: &[ + /// @binding(0): "_root::bevy_pbr::mesh_view_bindings::view" + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStages::FRAGMENT, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: std::num::NonZeroU64::new( + std::mem::size_of::<_root::bevy_pbr::mesh_view_types::View>() + as _, + ), }, - /// @binding(6): "_root::bevy_pbr::mesh_view_bindings::point_lights" - wgpu::BindGroupLayoutEntry { - binding: 6, - visibility: wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Storage { - read_only: true, - }, - has_dynamic_offset: false, - min_binding_size: None, - }, - count: None, + count: None, + }, + /// @binding(1): "_root::bevy_pbr::mesh_view_bindings::lights" + wgpu::BindGroupLayoutEntry { + binding: 1, + visibility: wgpu::ShaderStages::FRAGMENT, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: std::num::NonZeroU64::new( + std::mem::size_of::< + _root::bevy_pbr::mesh_view_types::Lights, + >() as _, + ), }, - /// @binding(7): "_root::bevy_pbr::mesh_view_bindings::cluster_light_index_lists" - wgpu::BindGroupLayoutEntry { - binding: 7, - visibility: wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Storage { - read_only: true, - }, - has_dynamic_offset: false, - min_binding_size: None, + count: None, + }, + /// @binding(6): "_root::bevy_pbr::mesh_view_bindings::point_lights" + wgpu::BindGroupLayoutEntry { + binding: 6, + visibility: wgpu::ShaderStages::FRAGMENT, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Storage { + read_only: true, }, - count: None, + has_dynamic_offset: false, + min_binding_size: None, }, - /// @binding(8): "_root::bevy_pbr::mesh_view_bindings::cluster_offsets_and_counts" - wgpu::BindGroupLayoutEntry { - binding: 8, - visibility: wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Storage { - read_only: true, - }, - has_dynamic_offset: false, - min_binding_size: None, + count: None, + }, + /// @binding(7): "_root::bevy_pbr::mesh_view_bindings::cluster_light_index_lists" + wgpu::BindGroupLayoutEntry { + binding: 7, + visibility: wgpu::ShaderStages::FRAGMENT, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Storage { + read_only: true, }, - count: None, + has_dynamic_offset: false, + min_binding_size: None, }, - /// @binding(2): "_root::bevy_pbr::mesh_view_bindings::point_shadow_textures" - wgpu::BindGroupLayoutEntry { - binding: 2, - visibility: wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Texture { - sample_type: wgpu::TextureSampleType::Depth, - view_dimension: wgpu::TextureViewDimension::Cube, - multisampled: false, + count: None, + }, + /// @binding(8): "_root::bevy_pbr::mesh_view_bindings::cluster_offsets_and_counts" + wgpu::BindGroupLayoutEntry { + binding: 8, + visibility: wgpu::ShaderStages::FRAGMENT, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Storage { + read_only: true, }, - count: None, + has_dynamic_offset: false, + min_binding_size: None, }, - /// @binding(3): "_root::bevy_pbr::mesh_view_bindings::point_shadow_textures_sampler" - wgpu::BindGroupLayoutEntry { - binding: 3, - visibility: wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Sampler( - wgpu::SamplerBindingType::Comparison, - ), - count: None, + count: None, + }, + /// @binding(2): "_root::bevy_pbr::mesh_view_bindings::point_shadow_textures" + wgpu::BindGroupLayoutEntry { + binding: 2, + visibility: wgpu::ShaderStages::FRAGMENT, + ty: wgpu::BindingType::Texture { + sample_type: wgpu::TextureSampleType::Depth, + view_dimension: wgpu::TextureViewDimension::Cube, + multisampled: false, }, - /// @binding(4): "_root::bevy_pbr::mesh_view_bindings::directional_shadow_textures" - wgpu::BindGroupLayoutEntry { - binding: 4, - visibility: wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Texture { - sample_type: wgpu::TextureSampleType::Depth, - view_dimension: wgpu::TextureViewDimension::D2, - multisampled: false, - }, - count: None, + count: None, + }, + /// @binding(3): "_root::bevy_pbr::mesh_view_bindings::point_shadow_textures_sampler" + wgpu::BindGroupLayoutEntry { + binding: 3, + visibility: wgpu::ShaderStages::FRAGMENT, + ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Comparison), + count: None, + }, + /// @binding(4): "_root::bevy_pbr::mesh_view_bindings::directional_shadow_textures" + wgpu::BindGroupLayoutEntry { + binding: 4, + visibility: wgpu::ShaderStages::FRAGMENT, + ty: wgpu::BindingType::Texture { + sample_type: wgpu::TextureSampleType::Depth, + view_dimension: wgpu::TextureViewDimension::D2, + multisampled: false, }, - /// @binding(5): "_root::bevy_pbr::mesh_view_bindings::directional_shadow_textures_sampler" - wgpu::BindGroupLayoutEntry { - binding: 5, - visibility: wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Sampler( - wgpu::SamplerBindingType::Comparison, - ), - count: None, + count: None, + }, + /// @binding(5): "_root::bevy_pbr::mesh_view_bindings::directional_shadow_textures_sampler" + wgpu::BindGroupLayoutEntry { + binding: 5, + visibility: wgpu::ShaderStages::FRAGMENT, + ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Comparison), + count: None, + }, + ], + }; + pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout { + device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) + } + pub fn from_bindings( + device: &wgpu::Device, + bindings: WgpuBindGroup0Entries, + ) -> Self { + let bind_group_layout = Self::get_bind_group_layout(&device); + let entries = bindings.as_array(); + let bind_group = device + .create_bind_group( + &wgpu::BindGroupDescriptor { + label: Some("Pbr::BindGroup0"), + layout: &bind_group_layout, + entries: &entries, }, - ], - }; - pub fn get_bind_group_layout( - device: &wgpu::Device, - ) -> wgpu::BindGroupLayout { - device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) - } - pub fn from_bindings( - device: &wgpu::Device, - bindings: WgpuBindGroup0Entries, - ) -> Self { - let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.as_array(); - let bind_group = device - .create_bind_group( - &wgpu::BindGroupDescriptor { - label: Some("Pbr::BindGroup0"), - layout: &bind_group_layout, - entries: &entries, - }, - ); - Self(bind_group) - } - pub fn set<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>) { - render_pass.set_bind_group(0, &self.0, &[]); + ); + Self(bind_group) + } + pub fn set<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>) { + render_pass.set_bind_group(0, &self.0, &[]); + } + } + #[derive(Debug)] + pub struct WgpuBindGroup1EntriesParams<'a> { + pub material: wgpu::BufferBinding<'a>, + } + #[derive(Clone, Debug)] + pub struct WgpuBindGroup1Entries<'a> { + pub material: wgpu::BindGroupEntry<'a>, + } + impl<'a> WgpuBindGroup1Entries<'a> { + pub fn new(params: WgpuBindGroup1EntriesParams<'a>) -> Self { + Self { + material: wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::Buffer(params.material), + }, } } - #[derive(Debug)] - pub struct WgpuBindGroup1EntriesParams<'a> { - pub material: wgpu::BufferBinding<'a>, + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { + [self.material] } - #[derive(Clone, Debug)] - pub struct WgpuBindGroup1Entries<'a> { - pub material: wgpu::BindGroupEntry<'a>, + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() } - impl<'a> WgpuBindGroup1Entries<'a> { - pub fn new(params: WgpuBindGroup1EntriesParams<'a>) -> Self { - Self { - material: wgpu::BindGroupEntry { - binding: 0, - resource: wgpu::BindingResource::Buffer(params.material), + } + #[derive(Debug)] + pub struct WgpuBindGroup1(wgpu::BindGroup); + impl WgpuBindGroup1 { + pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { + label: Some("Pbr::BindGroup1::LayoutDescriptor"), + entries: &[ + /// @binding(0): "_root::bevy_pbr::pbr::bindings::material" + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStages::FRAGMENT, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: std::num::NonZeroU64::new( + std::mem::size_of::< + _root::bevy_pbr::pbr::types::StandardMaterial, + >() as _, + ), }, - } - } - pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { - [self.material] - } - pub fn collect>>(self) -> B { - self.as_array().into_iter().collect() - } + count: None, + }, + ], + }; + pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout { + device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) } - #[derive(Debug)] - pub struct WgpuBindGroup1(wgpu::BindGroup); - impl WgpuBindGroup1 { - pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { - label: Some("Pbr::BindGroup1::LayoutDescriptor"), - entries: &[ - /// @binding(0): "_root::bevy_pbr::pbr::bindings::material" - wgpu::BindGroupLayoutEntry { - binding: 0, - visibility: wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::< - _root::bevy_pbr::pbr::types::StandardMaterial, - >() as _, - ), - }, - count: None, + pub fn from_bindings( + device: &wgpu::Device, + bindings: WgpuBindGroup1Entries, + ) -> Self { + let bind_group_layout = Self::get_bind_group_layout(&device); + let entries = bindings.as_array(); + let bind_group = device + .create_bind_group( + &wgpu::BindGroupDescriptor { + label: Some("Pbr::BindGroup1"), + layout: &bind_group_layout, + entries: &entries, }, - ], - }; - pub fn get_bind_group_layout( - device: &wgpu::Device, - ) -> wgpu::BindGroupLayout { - device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) - } - pub fn from_bindings( - device: &wgpu::Device, - bindings: WgpuBindGroup1Entries, - ) -> Self { - let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.as_array(); - let bind_group = device - .create_bind_group( - &wgpu::BindGroupDescriptor { - label: Some("Pbr::BindGroup1"), - layout: &bind_group_layout, - entries: &entries, - }, - ); - Self(bind_group) - } - pub fn set<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>) { - render_pass.set_bind_group(1, &self.0, &[]); + ); + Self(bind_group) + } + pub fn set<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>) { + render_pass.set_bind_group(1, &self.0, &[]); + } + } + #[derive(Debug)] + pub struct WgpuBindGroup2EntriesParams<'a> { + pub mesh: wgpu::BufferBinding<'a>, + } + #[derive(Clone, Debug)] + pub struct WgpuBindGroup2Entries<'a> { + pub mesh: wgpu::BindGroupEntry<'a>, + } + impl<'a> WgpuBindGroup2Entries<'a> { + pub fn new(params: WgpuBindGroup2EntriesParams<'a>) -> Self { + Self { + mesh: wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::Buffer(params.mesh), + }, } } - #[derive(Debug)] - pub struct WgpuBindGroup2EntriesParams<'a> { - pub mesh: wgpu::BufferBinding<'a>, + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { + [self.mesh] } - #[derive(Clone, Debug)] - pub struct WgpuBindGroup2Entries<'a> { - pub mesh: wgpu::BindGroupEntry<'a>, + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() } - impl<'a> WgpuBindGroup2Entries<'a> { - pub fn new(params: WgpuBindGroup2EntriesParams<'a>) -> Self { - Self { - mesh: wgpu::BindGroupEntry { - binding: 0, - resource: wgpu::BindingResource::Buffer(params.mesh), + } + #[derive(Debug)] + pub struct WgpuBindGroup2(wgpu::BindGroup); + impl WgpuBindGroup2 { + pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { + label: Some("Pbr::BindGroup2::LayoutDescriptor"), + entries: &[ + /// @binding(0): "_root::bevy_pbr::mesh_bindings::mesh" + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStages::FRAGMENT, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: std::num::NonZeroU64::new( + std::mem::size_of::<_root::bevy_pbr::mesh_types::Mesh>() as _, + ), }, - } - } - pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { - [self.mesh] - } - pub fn collect>>(self) -> B { - self.as_array().into_iter().collect() - } + count: None, + }, + ], + }; + pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout { + device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) } - #[derive(Debug)] - pub struct WgpuBindGroup2(wgpu::BindGroup); - impl WgpuBindGroup2 { - pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { - label: Some("Pbr::BindGroup2::LayoutDescriptor"), - entries: &[ - /// @binding(0): "_root::bevy_pbr::mesh_bindings::mesh" - wgpu::BindGroupLayoutEntry { - binding: 0, - visibility: wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::<_root::bevy_pbr::mesh_types::Mesh>() - as _, - ), - }, - count: None, + pub fn from_bindings( + device: &wgpu::Device, + bindings: WgpuBindGroup2Entries, + ) -> Self { + let bind_group_layout = Self::get_bind_group_layout(&device); + let entries = bindings.as_array(); + let bind_group = device + .create_bind_group( + &wgpu::BindGroupDescriptor { + label: Some("Pbr::BindGroup2"), + layout: &bind_group_layout, + entries: &entries, }, - ], - }; - pub fn get_bind_group_layout( - device: &wgpu::Device, - ) -> wgpu::BindGroupLayout { - device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) - } - pub fn from_bindings( - device: &wgpu::Device, - bindings: WgpuBindGroup2Entries, - ) -> Self { - let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.as_array(); - let bind_group = device - .create_bind_group( - &wgpu::BindGroupDescriptor { - label: Some("Pbr::BindGroup2"), - layout: &bind_group_layout, - entries: &entries, - }, - ); - Self(bind_group) - } - pub fn set<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>) { - render_pass.set_bind_group(2, &self.0, &[]); - } + ); + Self(bind_group) } - #[derive(Debug, Copy, Clone)] - pub struct WgpuBindGroups<'a> { - pub bind_group0: &'a WgpuBindGroup0, - pub bind_group1: &'a WgpuBindGroup1, - pub bind_group2: &'a WgpuBindGroup2, - } - impl<'a> WgpuBindGroups<'a> { - pub fn set(&self, pass: &mut wgpu::RenderPass<'a>) { - self.bind_group0.set(pass); - self.bind_group1.set(pass); - self.bind_group2.set(pass); - } + pub fn set<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>) { + render_pass.set_bind_group(2, &self.0, &[]); + } + } + #[derive(Debug, Copy, Clone)] + pub struct WgpuBindGroups<'a> { + pub bind_group0: &'a WgpuBindGroup0, + pub bind_group1: &'a WgpuBindGroup1, + pub bind_group2: &'a WgpuBindGroup2, + } + impl<'a> WgpuBindGroups<'a> { + pub fn set(&self, pass: &mut wgpu::RenderPass<'a>) { + self.bind_group0.set(pass); + self.bind_group1.set(pass); + self.bind_group2.set(pass); } } - pub use self::bind_groups::*; pub fn set_bind_groups<'a>( pass: &mut wgpu::RenderPass<'a>, - bind_group0: &'a bind_groups::WgpuBindGroup0, - bind_group1: &'a bind_groups::WgpuBindGroup1, - bind_group2: &'a bind_groups::WgpuBindGroup2, + bind_group0: &'a WgpuBindGroup0, + bind_group1: &'a WgpuBindGroup1, + bind_group2: &'a WgpuBindGroup2, ) { bind_group0.set(pass); bind_group1.set(pass); @@ -1149,9 +1133,9 @@ pub mod pbr { &wgpu::PipelineLayoutDescriptor { label: Some("Pbr::PipelineLayout"), bind_group_layouts: &[ - &bind_groups::WgpuBindGroup0::get_bind_group_layout(device), - &bind_groups::WgpuBindGroup1::get_bind_group_layout(device), - &bind_groups::WgpuBindGroup2::get_bind_group_layout(device), + &WgpuBindGroup0::get_bind_group_layout(device), + &WgpuBindGroup1::get_bind_group_layout(device), + &WgpuBindGroup2::get_bind_group_layout(device), ], push_constant_ranges: &[], }, diff --git a/wgsl_bindgen/tests/output/bindgen_main.expected.rs b/wgsl_bindgen/tests/output/bindgen_main.expected.rs index fc977b3..613e22c 100644 --- a/wgsl_bindgen/tests/output/bindgen_main.expected.rs +++ b/wgsl_bindgen/tests/output/bindgen_main.expected.rs @@ -98,220 +98,210 @@ pub mod main { data.build() } } - pub mod bind_groups { - use super::{_root, _root::*}; - #[derive(Debug)] - pub struct WgpuBindGroup0EntriesParams<'a> { - pub buffer: wgpu::BufferBinding<'a>, - pub texture_float: &'a wgpu::TextureView, - pub texture_sint: &'a wgpu::TextureView, - pub texture_uint: &'a wgpu::TextureView, + #[derive(Debug)] + pub struct WgpuBindGroup0EntriesParams<'a> { + pub buffer: wgpu::BufferBinding<'a>, + pub texture_float: &'a wgpu::TextureView, + pub texture_sint: &'a wgpu::TextureView, + pub texture_uint: &'a wgpu::TextureView, + } + #[derive(Clone, Debug)] + pub struct WgpuBindGroup0Entries<'a> { + pub buffer: wgpu::BindGroupEntry<'a>, + pub texture_float: wgpu::BindGroupEntry<'a>, + pub texture_sint: wgpu::BindGroupEntry<'a>, + pub texture_uint: wgpu::BindGroupEntry<'a>, + } + impl<'a> WgpuBindGroup0Entries<'a> { + pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { + Self { + buffer: wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::Buffer(params.buffer), + }, + texture_float: wgpu::BindGroupEntry { + binding: 1, + resource: wgpu::BindingResource::TextureView(params.texture_float), + }, + texture_sint: wgpu::BindGroupEntry { + binding: 2, + resource: wgpu::BindingResource::TextureView(params.texture_sint), + }, + texture_uint: wgpu::BindGroupEntry { + binding: 3, + resource: wgpu::BindingResource::TextureView(params.texture_uint), + }, + } } - #[derive(Clone, Debug)] - pub struct WgpuBindGroup0Entries<'a> { - pub buffer: wgpu::BindGroupEntry<'a>, - pub texture_float: wgpu::BindGroupEntry<'a>, - pub texture_sint: wgpu::BindGroupEntry<'a>, - pub texture_uint: wgpu::BindGroupEntry<'a>, + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 4] { + [self.buffer, self.texture_float, self.texture_sint, self.texture_uint] } - impl<'a> WgpuBindGroup0Entries<'a> { - pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { - Self { - buffer: wgpu::BindGroupEntry { - binding: 0, - resource: wgpu::BindingResource::Buffer(params.buffer), - }, - texture_float: wgpu::BindGroupEntry { - binding: 1, - resource: wgpu::BindingResource::TextureView( - params.texture_float, - ), - }, - texture_sint: wgpu::BindGroupEntry { - binding: 2, - resource: wgpu::BindingResource::TextureView(params.texture_sint), - }, - texture_uint: wgpu::BindGroupEntry { - binding: 3, - resource: wgpu::BindingResource::TextureView(params.texture_uint), - }, - } - } - pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 4] { - [self.buffer, self.texture_float, self.texture_sint, self.texture_uint] - } - pub fn collect>>(self) -> B { - self.as_array().into_iter().collect() - } + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() } - #[derive(Debug)] - pub struct WgpuBindGroup0(wgpu::BindGroup); - impl WgpuBindGroup0 { - pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { - label: Some("Main::BindGroup0::LayoutDescriptor"), - entries: &[ - /// @binding(0): "buffer" - wgpu::BindGroupLayoutEntry { - binding: 0, - visibility: wgpu::ShaderStages::COMPUTE, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Storage { - read_only: false, - }, - has_dynamic_offset: false, - min_binding_size: None, + } + #[derive(Debug)] + pub struct WgpuBindGroup0(wgpu::BindGroup); + impl WgpuBindGroup0 { + pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { + label: Some("Main::BindGroup0::LayoutDescriptor"), + entries: &[ + /// @binding(0): "buffer" + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStages::COMPUTE, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Storage { + read_only: false, }, - count: None, + has_dynamic_offset: false, + min_binding_size: None, }, - /// @binding(1): "texture_float" - wgpu::BindGroupLayoutEntry { - binding: 1, - visibility: wgpu::ShaderStages::COMPUTE, - ty: wgpu::BindingType::Texture { - sample_type: wgpu::TextureSampleType::Float { - filterable: true, - }, - view_dimension: wgpu::TextureViewDimension::D2, - multisampled: false, + count: None, + }, + /// @binding(1): "texture_float" + wgpu::BindGroupLayoutEntry { + binding: 1, + visibility: wgpu::ShaderStages::COMPUTE, + ty: wgpu::BindingType::Texture { + sample_type: wgpu::TextureSampleType::Float { + filterable: true, }, - count: None, + view_dimension: wgpu::TextureViewDimension::D2, + multisampled: false, }, - /// @binding(2): "texture_sint" - wgpu::BindGroupLayoutEntry { - binding: 2, - visibility: wgpu::ShaderStages::COMPUTE, - ty: wgpu::BindingType::Texture { - sample_type: wgpu::TextureSampleType::Sint, - view_dimension: wgpu::TextureViewDimension::D2, - multisampled: false, - }, - count: None, + count: None, + }, + /// @binding(2): "texture_sint" + wgpu::BindGroupLayoutEntry { + binding: 2, + visibility: wgpu::ShaderStages::COMPUTE, + ty: wgpu::BindingType::Texture { + sample_type: wgpu::TextureSampleType::Sint, + view_dimension: wgpu::TextureViewDimension::D2, + multisampled: false, }, - /// @binding(3): "texture_uint" - wgpu::BindGroupLayoutEntry { - binding: 3, - visibility: wgpu::ShaderStages::COMPUTE, - ty: wgpu::BindingType::Texture { - sample_type: wgpu::TextureSampleType::Uint, - view_dimension: wgpu::TextureViewDimension::D2, - multisampled: false, - }, - count: None, + count: None, + }, + /// @binding(3): "texture_uint" + wgpu::BindGroupLayoutEntry { + binding: 3, + visibility: wgpu::ShaderStages::COMPUTE, + ty: wgpu::BindingType::Texture { + sample_type: wgpu::TextureSampleType::Uint, + view_dimension: wgpu::TextureViewDimension::D2, + multisampled: false, }, - ], - }; - pub fn get_bind_group_layout( - device: &wgpu::Device, - ) -> wgpu::BindGroupLayout { - device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) - } - pub fn from_bindings( - device: &wgpu::Device, - bindings: WgpuBindGroup0Entries, - ) -> Self { - let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.as_array(); - let bind_group = device - .create_bind_group( - &wgpu::BindGroupDescriptor { - label: Some("Main::BindGroup0"), - layout: &bind_group_layout, - entries: &entries, - }, - ); - Self(bind_group) - } - pub fn set<'a>(&'a self, render_pass: &mut wgpu::ComputePass<'a>) { - render_pass.set_bind_group(0, &self.0, &[]); + count: None, + }, + ], + }; + pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout { + device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) + } + pub fn from_bindings( + device: &wgpu::Device, + bindings: WgpuBindGroup0Entries, + ) -> Self { + let bind_group_layout = Self::get_bind_group_layout(&device); + let entries = bindings.as_array(); + let bind_group = device + .create_bind_group( + &wgpu::BindGroupDescriptor { + label: Some("Main::BindGroup0"), + layout: &bind_group_layout, + entries: &entries, + }, + ); + Self(bind_group) + } + pub fn set<'a>(&'a self, render_pass: &mut wgpu::ComputePass<'a>) { + render_pass.set_bind_group(0, &self.0, &[]); + } + } + #[derive(Debug)] + pub struct WgpuBindGroup1EntriesParams<'a> { + pub ONE: wgpu::BufferBinding<'a>, + } + #[derive(Clone, Debug)] + pub struct WgpuBindGroup1Entries<'a> { + pub ONE: wgpu::BindGroupEntry<'a>, + } + impl<'a> WgpuBindGroup1Entries<'a> { + pub fn new(params: WgpuBindGroup1EntriesParams<'a>) -> Self { + Self { + ONE: wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::Buffer(params.ONE), + }, } } - #[derive(Debug)] - pub struct WgpuBindGroup1EntriesParams<'a> { - pub ONE: wgpu::BufferBinding<'a>, + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { + [self.ONE] } - #[derive(Clone, Debug)] - pub struct WgpuBindGroup1Entries<'a> { - pub ONE: wgpu::BindGroupEntry<'a>, + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() } - impl<'a> WgpuBindGroup1Entries<'a> { - pub fn new(params: WgpuBindGroup1EntriesParams<'a>) -> Self { - Self { - ONE: wgpu::BindGroupEntry { - binding: 0, - resource: wgpu::BindingResource::Buffer(params.ONE), + } + #[derive(Debug)] + pub struct WgpuBindGroup1(wgpu::BindGroup); + impl WgpuBindGroup1 { + pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { + label: Some("Main::BindGroup1::LayoutDescriptor"), + entries: &[ + /// @binding(0): "_root::bindings::ONE" + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStages::COMPUTE, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: std::num::NonZeroU64::new( + std::mem::size_of::() as _, + ), }, - } - } - pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { - [self.ONE] - } - pub fn collect>>(self) -> B { - self.as_array().into_iter().collect() - } + count: None, + }, + ], + }; + pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout { + device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) } - #[derive(Debug)] - pub struct WgpuBindGroup1(wgpu::BindGroup); - impl WgpuBindGroup1 { - pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { - label: Some("Main::BindGroup1::LayoutDescriptor"), - entries: &[ - /// @binding(0): "_root::bindings::ONE" - wgpu::BindGroupLayoutEntry { - binding: 0, - visibility: wgpu::ShaderStages::COMPUTE, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::() as _, - ), - }, - count: None, + pub fn from_bindings( + device: &wgpu::Device, + bindings: WgpuBindGroup1Entries, + ) -> Self { + let bind_group_layout = Self::get_bind_group_layout(&device); + let entries = bindings.as_array(); + let bind_group = device + .create_bind_group( + &wgpu::BindGroupDescriptor { + label: Some("Main::BindGroup1"), + layout: &bind_group_layout, + entries: &entries, }, - ], - }; - pub fn get_bind_group_layout( - device: &wgpu::Device, - ) -> wgpu::BindGroupLayout { - device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) - } - pub fn from_bindings( - device: &wgpu::Device, - bindings: WgpuBindGroup1Entries, - ) -> Self { - let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.as_array(); - let bind_group = device - .create_bind_group( - &wgpu::BindGroupDescriptor { - label: Some("Main::BindGroup1"), - layout: &bind_group_layout, - entries: &entries, - }, - ); - Self(bind_group) - } - pub fn set<'a>(&'a self, render_pass: &mut wgpu::ComputePass<'a>) { - render_pass.set_bind_group(1, &self.0, &[]); - } + ); + Self(bind_group) } - #[derive(Debug, Copy, Clone)] - pub struct WgpuBindGroups<'a> { - pub bind_group0: &'a WgpuBindGroup0, - pub bind_group1: &'a WgpuBindGroup1, + pub fn set<'a>(&'a self, render_pass: &mut wgpu::ComputePass<'a>) { + render_pass.set_bind_group(1, &self.0, &[]); } - impl<'a> WgpuBindGroups<'a> { - pub fn set(&self, pass: &mut wgpu::ComputePass<'a>) { - self.bind_group0.set(pass); - self.bind_group1.set(pass); - } + } + #[derive(Debug, Copy, Clone)] + pub struct WgpuBindGroups<'a> { + pub bind_group0: &'a WgpuBindGroup0, + pub bind_group1: &'a WgpuBindGroup1, + } + impl<'a> WgpuBindGroups<'a> { + pub fn set(&self, pass: &mut wgpu::ComputePass<'a>) { + self.bind_group0.set(pass); + self.bind_group1.set(pass); } } - pub use self::bind_groups::*; pub fn set_bind_groups<'a>( pass: &mut wgpu::ComputePass<'a>, - bind_group0: &'a bind_groups::WgpuBindGroup0, - bind_group1: &'a bind_groups::WgpuBindGroup1, + bind_group0: &'a WgpuBindGroup0, + bind_group1: &'a WgpuBindGroup1, ) { bind_group0.set(pass); bind_group1.set(pass); @@ -372,8 +362,8 @@ pub mod main { &wgpu::PipelineLayoutDescriptor { label: Some("Main::PipelineLayout"), bind_group_layouts: &[ - &bind_groups::WgpuBindGroup0::get_bind_group_layout(device), - &bind_groups::WgpuBindGroup1::get_bind_group_layout(device), + &WgpuBindGroup0::get_bind_group_layout(device), + &WgpuBindGroup1::get_bind_group_layout(device), ], push_constant_ranges: &[], }, diff --git a/wgsl_bindgen/tests/output/bindgen_minimal.expected.rs b/wgsl_bindgen/tests/output/bindgen_minimal.expected.rs index 7480568..67408ed 100644 --- a/wgsl_bindgen/tests/output/bindgen_minimal.expected.rs +++ b/wgsl_bindgen/tests/output/bindgen_minimal.expected.rs @@ -79,92 +79,86 @@ pub mod minimal { data.build() } } - pub mod bind_groups { - use super::{_root, _root::*}; - #[derive(Debug)] - pub struct WgpuBindGroup0EntriesParams<'a> { - pub uniform_buf: wgpu::BufferBinding<'a>, + #[derive(Debug)] + pub struct WgpuBindGroup0EntriesParams<'a> { + pub uniform_buf: wgpu::BufferBinding<'a>, + } + #[derive(Clone, Debug)] + pub struct WgpuBindGroup0Entries<'a> { + pub uniform_buf: wgpu::BindGroupEntry<'a>, + } + impl<'a> WgpuBindGroup0Entries<'a> { + pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { + Self { + uniform_buf: wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::Buffer(params.uniform_buf), + }, + } + } + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { + [self.uniform_buf] } - #[derive(Clone, Debug)] - pub struct WgpuBindGroup0Entries<'a> { - pub uniform_buf: wgpu::BindGroupEntry<'a>, + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() } - impl<'a> WgpuBindGroup0Entries<'a> { - pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { - Self { - uniform_buf: wgpu::BindGroupEntry { - binding: 0, - resource: wgpu::BindingResource::Buffer(params.uniform_buf), + } + #[derive(Debug)] + pub struct WgpuBindGroup0(wgpu::BindGroup); + impl WgpuBindGroup0 { + pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { + label: Some("Minimal::BindGroup0::LayoutDescriptor"), + entries: &[ + /// @binding(0): "uniform_buf" + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStages::COMPUTE, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: std::num::NonZeroU64::new( + std::mem::size_of::<_root::minimal::Uniforms>() as _, + ), }, - } - } - pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { - [self.uniform_buf] - } - pub fn collect>>(self) -> B { - self.as_array().into_iter().collect() - } + count: None, + }, + ], + }; + pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout { + device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) } - #[derive(Debug)] - pub struct WgpuBindGroup0(wgpu::BindGroup); - impl WgpuBindGroup0 { - pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { - label: Some("Minimal::BindGroup0::LayoutDescriptor"), - entries: &[ - /// @binding(0): "uniform_buf" - wgpu::BindGroupLayoutEntry { - binding: 0, - visibility: wgpu::ShaderStages::COMPUTE, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::<_root::minimal::Uniforms>() as _, - ), - }, - count: None, + pub fn from_bindings( + device: &wgpu::Device, + bindings: WgpuBindGroup0Entries, + ) -> Self { + let bind_group_layout = Self::get_bind_group_layout(&device); + let entries = bindings.as_array(); + let bind_group = device + .create_bind_group( + &wgpu::BindGroupDescriptor { + label: Some("Minimal::BindGroup0"), + layout: &bind_group_layout, + entries: &entries, }, - ], - }; - pub fn get_bind_group_layout( - device: &wgpu::Device, - ) -> wgpu::BindGroupLayout { - device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) - } - pub fn from_bindings( - device: &wgpu::Device, - bindings: WgpuBindGroup0Entries, - ) -> Self { - let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.as_array(); - let bind_group = device - .create_bind_group( - &wgpu::BindGroupDescriptor { - label: Some("Minimal::BindGroup0"), - layout: &bind_group_layout, - entries: &entries, - }, - ); - Self(bind_group) - } - pub fn set<'a>(&'a self, render_pass: &mut wgpu::ComputePass<'a>) { - render_pass.set_bind_group(0, &self.0, &[]); - } + ); + Self(bind_group) } - #[derive(Debug, Copy, Clone)] - pub struct WgpuBindGroups<'a> { - pub bind_group0: &'a WgpuBindGroup0, + pub fn set<'a>(&'a self, render_pass: &mut wgpu::ComputePass<'a>) { + render_pass.set_bind_group(0, &self.0, &[]); } - impl<'a> WgpuBindGroups<'a> { - pub fn set(&self, pass: &mut wgpu::ComputePass<'a>) { - self.bind_group0.set(pass); - } + } + #[derive(Debug, Copy, Clone)] + pub struct WgpuBindGroups<'a> { + pub bind_group0: &'a WgpuBindGroup0, + } + impl<'a> WgpuBindGroups<'a> { + pub fn set(&self, pass: &mut wgpu::ComputePass<'a>) { + self.bind_group0.set(pass); } } - pub use self::bind_groups::*; pub fn set_bind_groups<'a>( pass: &mut wgpu::ComputePass<'a>, - bind_group0: &'a bind_groups::WgpuBindGroup0, + bind_group0: &'a WgpuBindGroup0, ) { bind_group0.set(pass); } @@ -203,7 +197,7 @@ pub mod minimal { &wgpu::PipelineLayoutDescriptor { label: Some("Minimal::PipelineLayout"), bind_group_layouts: &[ - &bind_groups::WgpuBindGroup0::get_bind_group_layout(device), + &WgpuBindGroup0::get_bind_group_layout(device), ], push_constant_ranges: &[], }, diff --git a/wgsl_bindgen/tests/output/bindgen_padding.expected.rs b/wgsl_bindgen/tests/output/bindgen_padding.expected.rs index 98f2164..2703ea3 100644 --- a/wgsl_bindgen/tests/output/bindgen_padding.expected.rs +++ b/wgsl_bindgen/tests/output/bindgen_padding.expected.rs @@ -82,94 +82,88 @@ pub mod padding { data.build() } } - pub mod bind_groups { - use super::{_root, _root::*}; - #[derive(Debug)] - pub struct WgpuBindGroup0EntriesParams<'a> { - pub frame: wgpu::BufferBinding<'a>, + #[derive(Debug)] + pub struct WgpuBindGroup0EntriesParams<'a> { + pub frame: wgpu::BufferBinding<'a>, + } + #[derive(Clone, Debug)] + pub struct WgpuBindGroup0Entries<'a> { + pub frame: wgpu::BindGroupEntry<'a>, + } + impl<'a> WgpuBindGroup0Entries<'a> { + pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { + Self { + frame: wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::Buffer(params.frame), + }, + } } - #[derive(Clone, Debug)] - pub struct WgpuBindGroup0Entries<'a> { - pub frame: wgpu::BindGroupEntry<'a>, + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { + [self.frame] } - impl<'a> WgpuBindGroup0Entries<'a> { - pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { - Self { - frame: wgpu::BindGroupEntry { - binding: 0, - resource: wgpu::BindingResource::Buffer(params.frame), - }, - } - } - pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { - [self.frame] - } - pub fn collect>>(self) -> B { - self.as_array().into_iter().collect() - } + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() } - #[derive(Debug)] - pub struct WgpuBindGroup0(wgpu::BindGroup); - impl WgpuBindGroup0 { - pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { - label: Some("Padding::BindGroup0::LayoutDescriptor"), - entries: &[ - /// @binding(0): "frame" - wgpu::BindGroupLayoutEntry { - binding: 0, - visibility: wgpu::ShaderStages::COMPUTE, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Storage { - read_only: true, - }, - has_dynamic_offset: false, - min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::<_root::padding::Style>() as _, - ), + } + #[derive(Debug)] + pub struct WgpuBindGroup0(wgpu::BindGroup); + impl WgpuBindGroup0 { + pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { + label: Some("Padding::BindGroup0::LayoutDescriptor"), + entries: &[ + /// @binding(0): "frame" + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStages::COMPUTE, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Storage { + read_only: true, }, - count: None, + has_dynamic_offset: false, + min_binding_size: std::num::NonZeroU64::new( + std::mem::size_of::<_root::padding::Style>() as _, + ), }, - ], - }; - pub fn get_bind_group_layout( - device: &wgpu::Device, - ) -> wgpu::BindGroupLayout { - device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) - } - pub fn from_bindings( - device: &wgpu::Device, - bindings: WgpuBindGroup0Entries, - ) -> Self { - let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.as_array(); - let bind_group = device - .create_bind_group( - &wgpu::BindGroupDescriptor { - label: Some("Padding::BindGroup0"), - layout: &bind_group_layout, - entries: &entries, - }, - ); - Self(bind_group) - } - pub fn set<'a>(&'a self, render_pass: &mut wgpu::ComputePass<'a>) { - render_pass.set_bind_group(0, &self.0, &[]); - } + count: None, + }, + ], + }; + pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout { + device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) } - #[derive(Debug, Copy, Clone)] - pub struct WgpuBindGroups<'a> { - pub bind_group0: &'a WgpuBindGroup0, + pub fn from_bindings( + device: &wgpu::Device, + bindings: WgpuBindGroup0Entries, + ) -> Self { + let bind_group_layout = Self::get_bind_group_layout(&device); + let entries = bindings.as_array(); + let bind_group = device + .create_bind_group( + &wgpu::BindGroupDescriptor { + label: Some("Padding::BindGroup0"), + layout: &bind_group_layout, + entries: &entries, + }, + ); + Self(bind_group) } - impl<'a> WgpuBindGroups<'a> { - pub fn set(&self, pass: &mut wgpu::ComputePass<'a>) { - self.bind_group0.set(pass); - } + pub fn set<'a>(&'a self, render_pass: &mut wgpu::ComputePass<'a>) { + render_pass.set_bind_group(0, &self.0, &[]); + } + } + #[derive(Debug, Copy, Clone)] + pub struct WgpuBindGroups<'a> { + pub bind_group0: &'a WgpuBindGroup0, + } + impl<'a> WgpuBindGroups<'a> { + pub fn set(&self, pass: &mut wgpu::ComputePass<'a>) { + self.bind_group0.set(pass); } } - pub use self::bind_groups::*; pub fn set_bind_groups<'a>( pass: &mut wgpu::ComputePass<'a>, - bind_group0: &'a bind_groups::WgpuBindGroup0, + bind_group0: &'a WgpuBindGroup0, ) { bind_group0.set(pass); } @@ -208,7 +202,7 @@ pub mod padding { &wgpu::PipelineLayoutDescriptor { label: Some("Padding::PipelineLayout"), bind_group_layouts: &[ - &bind_groups::WgpuBindGroup0::get_bind_group_layout(device), + &WgpuBindGroup0::get_bind_group_layout(device), ], push_constant_ranges: &[], },