Skip to content

Commit

Permalink
Bind Group Entry Collections can be cloned
Browse files Browse the repository at this point in the history
  • Loading branch information
sytherax committed Jul 5, 2024
1 parent 636cb12 commit dd3b2db
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 32 deletions.
14 changes: 7 additions & 7 deletions example/src/shader_bindings.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// File automatically generated by wgsl_bindgen^
//
// ^ wgsl_bindgen version 0.13.0
// ^ wgsl_bindgen version 0.13.1
// Changes made to this file will not be saved.
// SourceHash: 112bfdc89aaa10c3f61563be4e9b48031c48faa832509d6d311f6d8a64e00ece
// SourceHash: 2b45485af563080519b2d0271439c5c6b88e20d1688598059cdfb48aaaaa94c9

#![allow(unused, non_snake_case, non_camel_case_types, non_upper_case_globals)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -518,7 +518,7 @@ pub mod testbed {
pub color_texture: &'a wgpu::TextureView,
pub color_sampler: &'a wgpu::Sampler,
}
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct WgpuBindGroup0EntryCollection<'a> {
pub color_texture: wgpu::BindGroupEntry<'a>,
pub color_sampler: wgpu::BindGroupEntry<'a>,
Expand Down Expand Up @@ -601,7 +601,7 @@ pub mod testbed {
pub struct WgpuBindGroup1EntryCollectionParams<'a> {
pub uniforms: wgpu::BufferBinding<'a>,
}
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct WgpuBindGroup1EntryCollection<'a> {
pub uniforms: wgpu::BindGroupEntry<'a>,
}
Expand Down Expand Up @@ -675,7 +675,7 @@ pub mod testbed {
pub h: wgpu::BufferBinding<'a>,
pub i: wgpu::BufferBinding<'a>,
}
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct WgpuBindGroup2EntryCollection<'a> {
pub rts: wgpu::BindGroupEntry<'a>,
pub a: wgpu::BindGroupEntry<'a>,
Expand Down Expand Up @@ -1281,7 +1281,7 @@ pub mod triangle {
pub color_texture: &'a wgpu::TextureView,
pub color_sampler: &'a wgpu::Sampler,
}
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct WgpuBindGroup0EntryCollection<'a> {
pub color_texture: wgpu::BindGroupEntry<'a>,
pub color_sampler: wgpu::BindGroupEntry<'a>,
Expand Down Expand Up @@ -1364,7 +1364,7 @@ pub mod triangle {
pub struct WgpuBindGroup1EntryCollectionParams<'a> {
pub uniforms: wgpu::BufferBinding<'a>,
}
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct WgpuBindGroup1EntryCollection<'a> {
pub uniforms: wgpu::BindGroupEntry<'a>,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use self::quote_gen::RustItemPath;
use super::*;

#[derive(Constructor)]
pub(super) struct BindGroupLayoutBuilder<'a> {
pub(super) struct BindGroupEntryCollectionBuilder<'a> {
invoking_entry_module: &'a str,
group_no: u32,
data: &'a GroupData<'a>,
generator: &'a BindGroupLayoutGenerator,
}

impl<'a> BindGroupLayoutBuilder<'a> {
impl<'a> BindGroupEntryCollectionBuilder<'a> {
/// Generates a binding entry from a parameter variable and a group binding.
fn create_entry_from_parameter(
&self,
Expand Down Expand Up @@ -116,11 +116,14 @@ impl<'a> BindGroupLayoutBuilder<'a> {
.map(|binding| self.binding_field_tuple(binding))
.collect();

let entry_collection_name =
self.generator.bind_group_entry_collection_struct_name_ident(self.group_no);
let entry_collection_name = self
.generator
.bind_group_entry_collection_struct_name_ident(self.group_no);
let entry_collection_param_name = format_ident!(
"{}Params",
self.generator.bind_group_entry_collection_struct_name_ident(self.group_no)
self
.generator
.bind_group_entry_collection_struct_name_ident(self.group_no)
);
let entry_struct_type = self.generator.entry_struct_type.clone();

Expand All @@ -141,7 +144,7 @@ impl<'a> BindGroupLayoutBuilder<'a> {
#(#entries_param_fields),*
}

#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct #entry_collection_name #lifetime {
#(#entries_fields),*
}
Expand Down
22 changes: 11 additions & 11 deletions wgsl_bindgen/src/generate/bind_group/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use quote_gen::{demangle_and_fully_qualify_str, rust_type};
use crate::wgsl::buffer_binding_type;
use crate::*;

mod layout_builder;
use layout_builder::*;
mod entry_collection_builder;
use entry_collection_builder::*;

pub struct GroupData<'a> {
pub bindings: Vec<GroupBinding<'a>>,
Expand Down Expand Up @@ -152,7 +152,7 @@ pub fn bind_groups_module(
.map(|(group_no, group)| {
let wgpu_generator = &options.wgpu_binding_generator;

let wgpu_layout = BindGroupLayoutBuilder::new(
let bind_group_entry_collection = BindGroupEntryCollectionBuilder::new(
invoking_entry_module,
*group_no,
group,
Expand All @@ -162,7 +162,7 @@ pub fn bind_groups_module(

let additional_layout =
if let Some(additional_generator) = &options.extra_binding_generator {
BindGroupLayoutBuilder::new(
BindGroupEntryCollectionBuilder::new(
invoking_entry_module,
*group_no,
group,
Expand All @@ -186,7 +186,7 @@ pub fn bind_groups_module(

quote! {
#additional_layout
#wgpu_layout
#bind_group_entry_collection
#bindgroup
}
})
Expand Down Expand Up @@ -544,7 +544,7 @@ mod tests {
pub vertex_weights: wgpu::BufferBinding<'a>,
pub dst: wgpu::BufferBinding<'a>,
}
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct WgpuBindGroup0EntryCollection<'a> {
pub src: wgpu::BindGroupEntry<'a>,
pub vertex_weights: wgpu::BindGroupEntry<'a>,
Expand Down Expand Up @@ -646,7 +646,7 @@ mod tests {
pub struct WgpuBindGroup1EntryCollectionParams<'a> {
pub transforms: wgpu::BufferBinding<'a>,
}
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct WgpuBindGroup1EntryCollection<'a> {
pub transforms: wgpu::BindGroupEntry<'a>,
}
Expand Down Expand Up @@ -803,7 +803,7 @@ mod tests {
pub color_texture_msaa: &'a wgpu::TextureView,
pub depth_texture_msaa: &'a wgpu::TextureView,
}
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct WgpuBindGroup0EntryCollection<'a> {
pub color_texture: wgpu::BindGroupEntry<'a>,
pub color_texture_i32: wgpu::BindGroupEntry<'a>,
Expand Down Expand Up @@ -1055,7 +1055,7 @@ mod tests {
pub transforms: wgpu::BufferBinding<'a>,
pub one: wgpu::BufferBinding<'a>,
}
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct WgpuBindGroup1EntryCollection<'a> {
pub transforms: wgpu::BindGroupEntry<'a>,
pub one: wgpu::BindGroupEntry<'a>,
Expand Down Expand Up @@ -1190,7 +1190,7 @@ mod tests {
pub struct WgpuBindGroup0EntryCollectionParams<'a> {
pub transforms: wgpu::BufferBinding<'a>,
}
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct WgpuBindGroup0EntryCollection<'a> {
pub transforms: wgpu::BindGroupEntry<'a>,
}
Expand Down Expand Up @@ -1304,7 +1304,7 @@ mod tests {
pub struct WgpuBindGroup0EntryCollectionParams<'a> {
pub transforms: wgpu::BufferBinding<'a>,
}
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct WgpuBindGroup0EntryCollection<'a> {
pub transforms: wgpu::BindGroupEntry<'a>,
}
Expand Down
2 changes: 1 addition & 1 deletion wgsl_bindgen/src/generate/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ mod test {
}
}
pub fn vs_main_entry(
input0: wgpu::VertexStepMode,
input0: wgpu::VertexStepMode,
input1: wgpu::VertexStepMode,
overrides: &OverrideConstants
) -> VertexEntry<2> {
Expand Down
6 changes: 3 additions & 3 deletions wgsl_bindgen/tests/output/bindgen_bevy.expected.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ pub mod pbr {
pub directional_shadow_textures: &'a wgpu::TextureView,
pub directional_shadow_textures_sampler: &'a wgpu::Sampler,
}
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct WgpuBindGroup0EntryCollection<'a> {
pub view: wgpu::BindGroupEntry<'a>,
pub lights: wgpu::BindGroupEntry<'a>,
Expand Down Expand Up @@ -937,7 +937,7 @@ pub mod pbr {
pub struct WgpuBindGroup1EntryCollectionParams<'a> {
pub material: wgpu::BufferBinding<'a>,
}
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct WgpuBindGroup1EntryCollection<'a> {
pub material: wgpu::BindGroupEntry<'a>,
}
Expand Down Expand Up @@ -1006,7 +1006,7 @@ pub mod pbr {
pub struct WgpuBindGroup2EntryCollectionParams<'a> {
pub mesh: wgpu::BufferBinding<'a>,
}
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct WgpuBindGroup2EntryCollection<'a> {
pub mesh: wgpu::BindGroupEntry<'a>,
}
Expand Down
4 changes: 2 additions & 2 deletions wgsl_bindgen/tests/output/bindgen_main.expected.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub mod main {
pub texture_sint: &'a wgpu::TextureView,
pub texture_uint: &'a wgpu::TextureView,
}
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct WgpuBindGroup0EntryCollection<'a> {
pub buffer: wgpu::BindGroupEntry<'a>,
pub texture_float: wgpu::BindGroupEntry<'a>,
Expand Down Expand Up @@ -226,7 +226,7 @@ pub mod main {
pub struct WgpuBindGroup1EntryCollectionParams<'a> {
pub ONE: wgpu::BufferBinding<'a>,
}
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct WgpuBindGroup1EntryCollection<'a> {
pub ONE: wgpu::BindGroupEntry<'a>,
}
Expand Down
2 changes: 1 addition & 1 deletion wgsl_bindgen/tests/output/bindgen_minimal.expected.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub mod minimal {
pub struct WgpuBindGroup0EntryCollectionParams<'a> {
pub uniform_buf: wgpu::BufferBinding<'a>,
}
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct WgpuBindGroup0EntryCollection<'a> {
pub uniform_buf: wgpu::BindGroupEntry<'a>,
}
Expand Down
2 changes: 1 addition & 1 deletion wgsl_bindgen/tests/output/bindgen_padding.expected.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub mod padding {
pub struct WgpuBindGroup0EntryCollectionParams<'a> {
pub frame: wgpu::BufferBinding<'a>,
}
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct WgpuBindGroup0EntryCollection<'a> {
pub frame: wgpu::BindGroupEntry<'a>,
}
Expand Down

0 comments on commit dd3b2db

Please sign in to comment.