diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 05e1d36..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,93 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. -Breaking changes in the generated code will be considered as breaking changes when versioning wgsl_bindgen itself. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## unreleased -### Added -* Added `BindGroups::set` method for setting all bind groups from a struct. - -### Changed -* Moved vertex input methods from vertex module to top level. -* Moved `set_bind_groups` to top level and changed parameters to directly take bind group references. - -### Fixed -* Fixed an issue where `@builtin()` attributes were not supported in struct definitions. - -### 0.5.0 - 2023-10-28 -### Added -* Added `create_shader_module_embedded` for including the source as a string literal instead of using `include_str!`. -* Added `#[derive(Debug)]` to generated types for easier debugging and profiling. - -## 0.4.1 - 2023-05-04 -### Changed -* Adjusted code generation to skip structs that are only used internally in the shader. - -### Fixed -* Update naga to 0.12.0 to match wgpu 0.16. - -## 0.4.0 - 2023-04-30 -### Added -* Added vertex buffer layout function to each vertex input struct. -* Added support for nalgebra for matrix and vector types. -* Added const asserts to check approriate Rust struct memory layouts with WGSL when deriving bytemuck. -* Added support for storage textures. -* Added support for multisampled textures. -* Added a function for creating compute pipelines. -* Added optional derives for `serde::Serialize` and `serde::Deserialize`. -* Added functions to initialize vertex state for pipeline descriptors. - -### Changed -* Skip generating structs for shader stage outputs since they aren't needed. - -## 0.3.1 - 2022-12-18 -### Changed -* Updated documentation. - -## 0.3.0 - 2022-12-13 -### Added -* Added a check to force bind groups to be consecutive. -* Added a check for repeated bind groups or bindings. -* Added an example project. -* Added support for array bindings. -* Added support for depth textures. -* Added support for additional WGSL scalar types. -* Added `WriteOptions` to control generated derives. -* Added support for `glam` or Rust types for vectors and matrices. -* Added the workgroup size for generated code for compute shaders. - -### Changed -* Changed the return type of `create_shader_module` to `String` instead of writing to a file. -* Changed the visibility of resources to match the shader stages present in the module. -* Changed shader source parameter of `create_shader_module` take `&str` instead of a path. -* Changed bind groups to be more flexible by taking `wgpu::BufferBinding` instead of `wgpu::Buffer`. -* Changed project to depend on `wgpu-types` instead of `wgpu` itself. - -### Removed -* Removed the notice for generated code from the generated module string. -* Removed vertex attribute location code. -* Removed inaccurate generated struct size code. - -## 0.2.0 - 2022-03-09 -### Added -* Added create_pipeline_layout function. -* Added create_shader_module function. -* Added constants for vertex input locations. -* Added functions to set all bind groups or individual bind groups. -* Added Rust structs for global types like uniforms and vertex inputs. -* Added code to generate vertex state from vertex input structs. -* Added `#[derive(PartialEq)]` to generated structs. - -### Fixed -* Fixed an issue where the generated code would not use `wgpu::ComputePass` for compute only modules. - -### Changed -* Moved bindgroup layout descriptors to constants. -* Converted the procedural macro to a function to be used in build scripts. -* Always generate Rust types like arrays instead of forcing glam. - -## 0.1.0 - 2021-07-10 -Initial release! \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 120000 index 0000000..458c974 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1 @@ +wgsl_bindgen/CHANGELOG.md \ No newline at end of file diff --git a/example/assets/more-shader-files/reachme.wgsl b/example/assets/more-shader-files/reachme.wgsl deleted file mode 100644 index f4fde84..0000000 --- a/example/assets/more-shader-files/reachme.wgsl +++ /dev/null @@ -1,7 +0,0 @@ -struct rtsStruct { - other_data: i32, - the_array: array, -}; - -@group(1) @binding(1) -var ONE: f32; diff --git a/example/build.rs b/example/build.rs index 242aff5..c70487f 100644 --- a/example/build.rs +++ b/example/build.rs @@ -6,16 +6,16 @@ use wgsl_bindgen::{ fn main() -> Result<()> { WgslBindgenOptionBuilder::default() - .workspace_root("assets/shader") - .add_entry_point("assets/shader/utils/testbed.wgsl") - .add_entry_point("assets/shader/triangle.wgsl") + .workspace_root("shaders") + .add_entry_point("shaders/testbed.wgsl") + .add_entry_point("shaders/triangle.wgsl") .skip_hash_check(true) .serialization_strategy(WgslTypeSerializeStrategy::Bytemuck) .type_map(GlamWgslTypeMap) .override_struct_field_type( - [("types::VectorsU32", "a", quote!(crate::MyTwoU32))].map(Into::into), + [("utils::types::VectorsU32", "a", quote!(crate::MyTwoU32))].map(Into::into), ) - .add_override_struct_mapping(("types::Scalars", quote!(crate::MyScalars))) + .add_override_struct_mapping(("utils::types::Scalars", quote!(crate::MyScalars))) .add_custom_padding_field_regexp(Regex::new("_pad.*").unwrap()) .short_constructor(2) .shader_source_type( diff --git a/example/assets/shader/utils/testbed.wgsl b/example/shaders/testbed.wgsl similarity index 62% rename from example/assets/shader/utils/testbed.wgsl rename to example/shaders/testbed.wgsl index dddf3f8..27d180a 100644 --- a/example/assets/shader/utils/testbed.wgsl +++ b/example/shaders/testbed.wgsl @@ -1,13 +1,4 @@ -#import "../../more-shader-files/reachme" as reachme -#import types::{Scalars, VectorsU32, VectorsI32, VectorsF32, MatricesF32, StaticArrays, Nested} - -// The following also works -// #import "../more-shader-files/reachme.wgsl" as reachme - -@group(2) @binding(1) -// TODO: Fix this, I think the bug is in naga_oil. -// var rts: array; -var rts: reachme::rtsStruct; +#import utils::types::{Scalars, VectorsU32, VectorsI32, VectorsF32, MatricesF32, StaticArrays, Nested} @group(2) @binding(2) var a: Scalars; diff --git a/example/assets/shader/triangle.wgsl b/example/shaders/triangle.wgsl similarity index 100% rename from example/assets/shader/triangle.wgsl rename to example/shaders/triangle.wgsl diff --git a/example/assets/shader/types.wgsl b/example/shaders/utils/types.wgsl similarity index 100% rename from example/assets/shader/types.wgsl rename to example/shaders/utils/types.wgsl diff --git a/example/src/main.rs b/example/src/main.rs index 59f547d..4c1f817 100644 --- a/example/src/main.rs +++ b/example/src/main.rs @@ -147,8 +147,8 @@ impl State { // Use the generated types to ensure the correct bind group is assigned to each slot. let bind_group0 = shader_bindings::triangle::WgpuBindGroup0::from_bindings( &device, - shader_bindings::triangle::WgpuBindGroup0EntryCollection::new( - shader_bindings::triangle::WgpuBindGroup0EntryCollectionParams { + shader_bindings::triangle::WgpuBindGroup0Entries::new( + shader_bindings::triangle::WgpuBindGroup0EntriesParams { color_texture: &view, color_sampler: &sampler, }, @@ -165,8 +165,8 @@ impl State { let bind_group1 = shader_bindings::triangle::WgpuBindGroup1::from_bindings( &device, - shader_bindings::triangle::WgpuBindGroup1EntryCollection::new( - shader_bindings::triangle::WgpuBindGroup1EntryCollectionParams { + shader_bindings::triangle::WgpuBindGroup1Entries::new( + shader_bindings::triangle::WgpuBindGroup1EntriesParams { uniforms: uniforms_buffer.as_entire_buffer_binding(), }, ), diff --git a/example/src/shader_bindings.rs b/example/src/shader_bindings.rs index 572c2cd..cddb8a8 100644 --- a/example/src/shader_bindings.rs +++ b/example/src/shader_bindings.rs @@ -1,8 +1,8 @@ // File automatically generated by wgsl_bindgen^ // -// ^ wgsl_bindgen version 0.13.1 +// ^ wgsl_bindgen version 0.13.2 // Changes made to this file will not be saved. -// SourceHash: 2b45485af563080519b2d0271439c5c6b88e20d1688598059cdfb48aaaaa94c9 +// SourceHash: 09f54f4ac8c923323002ee67b8d10cb3cdedfaf0c34942bab6d37967adaf5648 #![allow(unused, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] @@ -78,52 +78,47 @@ pub mod layout_asserts { assert!(std::mem::size_of:: < glam::Mat4 > () == 64); assert!(std::mem::align_of:: < glam::Mat4 > () == 16); }; - const REACHMERTS_STRUCT_ASSERTS: () = { - assert!(std::mem::offset_of!(reachme::rtsStruct < 1 >, other_data) == 0); - assert!(std::mem::offset_of!(reachme::rtsStruct < 1 >, the_array) == 4); - assert!(std::mem::size_of:: < reachme::rtsStruct < 1 > > () == 8); + const UTILSTYPES_VECTORS_U32_ASSERTS: () = { + assert!(std::mem::offset_of!(utils::types::VectorsU32, a) == 0); + assert!(std::mem::offset_of!(utils::types::VectorsU32, b) == 16); + assert!(std::mem::offset_of!(utils::types::VectorsU32, c) == 32); + assert!(std::mem::size_of:: < utils::types::VectorsU32 > () == 64); }; - const TYPES_VECTORS_U32_ASSERTS: () = { - assert!(std::mem::offset_of!(types::VectorsU32, a) == 0); - assert!(std::mem::offset_of!(types::VectorsU32, b) == 16); - assert!(std::mem::offset_of!(types::VectorsU32, c) == 32); - assert!(std::mem::size_of:: < types::VectorsU32 > () == 64); + const UTILSTYPES_VECTORS_I32_ASSERTS: () = { + assert!(std::mem::offset_of!(utils::types::VectorsI32, a) == 0); + assert!(std::mem::offset_of!(utils::types::VectorsI32, b) == 16); + assert!(std::mem::offset_of!(utils::types::VectorsI32, c) == 32); + assert!(std::mem::size_of:: < utils::types::VectorsI32 > () == 48); }; - const TYPES_VECTORS_I32_ASSERTS: () = { - assert!(std::mem::offset_of!(types::VectorsI32, a) == 0); - assert!(std::mem::offset_of!(types::VectorsI32, b) == 16); - assert!(std::mem::offset_of!(types::VectorsI32, c) == 32); - assert!(std::mem::size_of:: < types::VectorsI32 > () == 48); + const UTILSTYPES_VECTORS_F32_ASSERTS: () = { + assert!(std::mem::offset_of!(utils::types::VectorsF32, a) == 0); + assert!(std::mem::offset_of!(utils::types::VectorsF32, b) == 16); + assert!(std::mem::offset_of!(utils::types::VectorsF32, c) == 32); + assert!(std::mem::size_of:: < utils::types::VectorsF32 > () == 48); }; - const TYPES_VECTORS_F32_ASSERTS: () = { - assert!(std::mem::offset_of!(types::VectorsF32, a) == 0); - assert!(std::mem::offset_of!(types::VectorsF32, b) == 16); - assert!(std::mem::offset_of!(types::VectorsF32, c) == 32); - assert!(std::mem::size_of:: < types::VectorsF32 > () == 48); + const UTILSTYPES_MATRICES_F32_ASSERTS: () = { + assert!(std::mem::offset_of!(utils::types::MatricesF32, a) == 0); + assert!(std::mem::offset_of!(utils::types::MatricesF32, b) == 64); + assert!(std::mem::offset_of!(utils::types::MatricesF32, c) == 128); + assert!(std::mem::offset_of!(utils::types::MatricesF32, d) == 160); + assert!(std::mem::offset_of!(utils::types::MatricesF32, e) == 208); + assert!(std::mem::offset_of!(utils::types::MatricesF32, f) == 256); + assert!(std::mem::offset_of!(utils::types::MatricesF32, g) == 288); + assert!(std::mem::offset_of!(utils::types::MatricesF32, h) == 320); + assert!(std::mem::offset_of!(utils::types::MatricesF32, i) == 352); + assert!(std::mem::size_of:: < utils::types::MatricesF32 > () == 368); }; - const TYPES_MATRICES_F32_ASSERTS: () = { - assert!(std::mem::offset_of!(types::MatricesF32, a) == 0); - assert!(std::mem::offset_of!(types::MatricesF32, b) == 64); - assert!(std::mem::offset_of!(types::MatricesF32, c) == 128); - assert!(std::mem::offset_of!(types::MatricesF32, d) == 160); - assert!(std::mem::offset_of!(types::MatricesF32, e) == 208); - assert!(std::mem::offset_of!(types::MatricesF32, f) == 256); - assert!(std::mem::offset_of!(types::MatricesF32, g) == 288); - assert!(std::mem::offset_of!(types::MatricesF32, h) == 320); - assert!(std::mem::offset_of!(types::MatricesF32, i) == 352); - assert!(std::mem::size_of:: < types::MatricesF32 > () == 368); + const UTILSTYPES_STATIC_ARRAYS_ASSERTS: () = { + assert!(std::mem::offset_of!(utils::types::StaticArrays, a) == 0); + assert!(std::mem::offset_of!(utils::types::StaticArrays, b) == 20); + assert!(std::mem::offset_of!(utils::types::StaticArrays, c) == 32); + assert!(std::mem::offset_of!(utils::types::StaticArrays, d) == 32800); + assert!(std::mem::size_of:: < utils::types::StaticArrays > () == 32864); }; - const TYPES_STATIC_ARRAYS_ASSERTS: () = { - assert!(std::mem::offset_of!(types::StaticArrays, a) == 0); - assert!(std::mem::offset_of!(types::StaticArrays, b) == 20); - assert!(std::mem::offset_of!(types::StaticArrays, c) == 32); - assert!(std::mem::offset_of!(types::StaticArrays, d) == 32800); - assert!(std::mem::size_of:: < types::StaticArrays > () == 32864); - }; - const TYPES_NESTED_ASSERTS: () = { - assert!(std::mem::offset_of!(types::Nested, a) == 0); - assert!(std::mem::offset_of!(types::Nested, b) == 368); - assert!(std::mem::size_of:: < types::Nested > () == 416); + const UTILSTYPES_NESTED_ASSERTS: () = { + assert!(std::mem::offset_of!(utils::types::Nested, a) == 0); + assert!(std::mem::offset_of!(utils::types::Nested, b) == 368); + assert!(std::mem::size_of:: < utils::types::Nested > () == 416); }; const TESTBED_UNIFORMS_ASSERTS: () = { assert!(std::mem::offset_of!(testbed::Uniforms, color_rgb) == 0); @@ -135,342 +130,327 @@ pub mod layout_asserts { assert!(std::mem::size_of:: < triangle::Uniforms > () == 16); }; } -pub mod reachme { - use super::{_root, _root::*}; - #[derive(Debug, PartialEq, Clone, Copy)] - pub struct rtsStruct { - /// size: 4, offset: 0x0, type: `i32` - pub other_data: i32, - /// size: 4, offset: 0x4, type: `array` - pub the_array: [u32; N], - } - pub const fn rtsStruct( - other_data: i32, - the_array: [u32; N], - ) -> rtsStruct { - rtsStruct { other_data, the_array } - } -} -pub mod bytemuck_impls { +pub mod utils { use super::{_root, _root::*}; - unsafe impl bytemuck::Zeroable for reachme::rtsStruct {} - unsafe impl bytemuck::Pod for reachme::rtsStruct {} - unsafe impl bytemuck::Zeroable for types::VectorsU32 {} - unsafe impl bytemuck::Pod for types::VectorsU32 {} - unsafe impl bytemuck::Zeroable for types::VectorsI32 {} - unsafe impl bytemuck::Pod for types::VectorsI32 {} - unsafe impl bytemuck::Zeroable for types::VectorsF32 {} - unsafe impl bytemuck::Pod for types::VectorsF32 {} - unsafe impl bytemuck::Zeroable for types::MatricesF32 {} - unsafe impl bytemuck::Pod for types::MatricesF32 {} - unsafe impl bytemuck::Zeroable for types::StaticArrays {} - unsafe impl bytemuck::Pod for types::StaticArrays {} - unsafe impl bytemuck::Zeroable for types::Nested {} - unsafe impl bytemuck::Pod for types::Nested {} - unsafe impl bytemuck::Zeroable for testbed::Uniforms {} - unsafe impl bytemuck::Pod for testbed::Uniforms {} - unsafe impl bytemuck::Zeroable for triangle::Uniforms {} - unsafe impl bytemuck::Pod for triangle::Uniforms {} - unsafe impl bytemuck::Zeroable for triangle::VertexInput {} - unsafe impl bytemuck::Pod for triangle::VertexInput {} -} -pub mod types { - use super::{_root, _root::*}; - #[repr(C, align(16))] - #[derive(Debug, PartialEq, Clone, Copy)] - pub struct VectorsU32 { - /// size: 8, offset: 0x0, type: `vec2` - pub a: crate::MyTwoU32, - pub _pad_a: [u8; 0x10 - core::mem::size_of::<[u32; 2]>()], - /// size: 12, offset: 0x10, type: `vec3` - pub b: [u32; 4], - /// size: 16, offset: 0x20, type: `vec4` - pub c: [u32; 4], - pub _padding: [u8; 0x4], - pub _pad__padding: [u8; 0x10 - core::mem::size_of::()], - } - impl VectorsU32 { - pub const fn new(a: crate::MyTwoU32, b: [u32; 4], c: [u32; 4]) -> Self { - Self { - a, - _pad_a: [0; 0x10 - core::mem::size_of::<[u32; 2]>()], - b, - c, - _padding: [0; 0x4], - _pad__padding: [0; 0x10 - core::mem::size_of::()], + pub mod types { + use super::{_root, _root::*}; + #[repr(C, align(16))] + #[derive(Debug, PartialEq, Clone, Copy)] + pub struct VectorsU32 { + /// size: 8, offset: 0x0, type: `vec2` + pub a: crate::MyTwoU32, + pub _pad_a: [u8; 0x10 - core::mem::size_of::<[u32; 2]>()], + /// size: 12, offset: 0x10, type: `vec3` + pub b: [u32; 4], + /// size: 16, offset: 0x20, type: `vec4` + pub c: [u32; 4], + pub _padding: [u8; 0x4], + pub _pad__padding: [u8; 0x10 - core::mem::size_of::()], + } + impl VectorsU32 { + pub const fn new(a: crate::MyTwoU32, b: [u32; 4], c: [u32; 4]) -> Self { + Self { + a, + _pad_a: [0; 0x10 - core::mem::size_of::<[u32; 2]>()], + b, + c, + _padding: [0; 0x4], + _pad__padding: [0; 0x10 - core::mem::size_of::()], + } } } - } - #[repr(C)] - #[derive(Debug, PartialEq, Clone, Copy)] - pub struct VectorsU32Init { - pub a: crate::MyTwoU32, - pub b: [u32; 4], - pub c: [u32; 4], - } - impl VectorsU32Init { - pub const fn build(&self) -> VectorsU32 { - VectorsU32 { - a: self.a, - _pad_a: [0; 0x10 - core::mem::size_of::<[u32; 2]>()], - b: self.b, - c: self.c, - _padding: [0; 0x4], - _pad__padding: [0; 0x10 - core::mem::size_of::()], + #[repr(C)] + #[derive(Debug, PartialEq, Clone, Copy)] + pub struct VectorsU32Init { + pub a: crate::MyTwoU32, + pub b: [u32; 4], + pub c: [u32; 4], + } + impl VectorsU32Init { + pub const fn build(&self) -> VectorsU32 { + VectorsU32 { + a: self.a, + _pad_a: [0; 0x10 - core::mem::size_of::<[u32; 2]>()], + b: self.b, + c: self.c, + _padding: [0; 0x4], + _pad__padding: [0; 0x10 - core::mem::size_of::()], + } } } - } - impl From for VectorsU32 { - fn from(data: VectorsU32Init) -> Self { - data.build() + impl From for VectorsU32 { + fn from(data: VectorsU32Init) -> Self { + data.build() + } } - } - #[repr(C, align(16))] - #[derive(Debug, PartialEq, Clone, Copy)] - pub struct VectorsI32 { - /// size: 8, offset: 0x0, type: `vec2` - pub a: [i32; 2], - pub _pad_a: [u8; 0x10 - core::mem::size_of::<[i32; 2]>()], - /// size: 12, offset: 0x10, type: `vec3` - pub b: [i32; 4], - /// size: 16, offset: 0x20, type: `vec4` - pub c: [i32; 4], - } - impl VectorsI32 { - pub const fn new(a: [i32; 2], b: [i32; 4], c: [i32; 4]) -> Self { - Self { - a, - _pad_a: [0; 0x10 - core::mem::size_of::<[i32; 2]>()], - b, - c, + #[repr(C, align(16))] + #[derive(Debug, PartialEq, Clone, Copy)] + pub struct VectorsI32 { + /// size: 8, offset: 0x0, type: `vec2` + pub a: [i32; 2], + pub _pad_a: [u8; 0x10 - core::mem::size_of::<[i32; 2]>()], + /// size: 12, offset: 0x10, type: `vec3` + pub b: [i32; 4], + /// size: 16, offset: 0x20, type: `vec4` + pub c: [i32; 4], + } + impl VectorsI32 { + pub const fn new(a: [i32; 2], b: [i32; 4], c: [i32; 4]) -> Self { + Self { + a, + _pad_a: [0; 0x10 - core::mem::size_of::<[i32; 2]>()], + b, + c, + } } } - } - #[repr(C)] - #[derive(Debug, PartialEq, Clone, Copy)] - pub struct VectorsI32Init { - pub a: [i32; 2], - pub b: [i32; 4], - pub c: [i32; 4], - } - impl VectorsI32Init { - pub const fn build(&self) -> VectorsI32 { - VectorsI32 { - a: self.a, - _pad_a: [0; 0x10 - core::mem::size_of::<[i32; 2]>()], - b: self.b, - c: self.c, + #[repr(C)] + #[derive(Debug, PartialEq, Clone, Copy)] + pub struct VectorsI32Init { + pub a: [i32; 2], + pub b: [i32; 4], + pub c: [i32; 4], + } + impl VectorsI32Init { + pub const fn build(&self) -> VectorsI32 { + VectorsI32 { + a: self.a, + _pad_a: [0; 0x10 - core::mem::size_of::<[i32; 2]>()], + b: self.b, + c: self.c, + } } } - } - impl From for VectorsI32 { - fn from(data: VectorsI32Init) -> Self { - data.build() + impl From for VectorsI32 { + fn from(data: VectorsI32Init) -> Self { + data.build() + } } - } - #[repr(C, align(16))] - #[derive(Debug, PartialEq, Clone, Copy)] - pub struct VectorsF32 { - /// size: 8, offset: 0x0, type: `vec2` - pub a: [f32; 2], - pub _pad_a: [u8; 0x10 - core::mem::size_of::<[f32; 2]>()], - /// size: 12, offset: 0x10, type: `vec3` - pub b: glam::Vec3A, - /// size: 16, offset: 0x20, type: `vec4` - pub c: glam::Vec4, - } - impl VectorsF32 { - pub const fn new(a: [f32; 2], b: glam::Vec3A, c: glam::Vec4) -> Self { - Self { - a, - _pad_a: [0; 0x10 - core::mem::size_of::<[f32; 2]>()], - b, - c, + #[repr(C, align(16))] + #[derive(Debug, PartialEq, Clone, Copy)] + pub struct VectorsF32 { + /// size: 8, offset: 0x0, type: `vec2` + pub a: [f32; 2], + pub _pad_a: [u8; 0x10 - core::mem::size_of::<[f32; 2]>()], + /// size: 12, offset: 0x10, type: `vec3` + pub b: glam::Vec3A, + /// size: 16, offset: 0x20, type: `vec4` + pub c: glam::Vec4, + } + impl VectorsF32 { + pub const fn new(a: [f32; 2], b: glam::Vec3A, c: glam::Vec4) -> Self { + Self { + a, + _pad_a: [0; 0x10 - core::mem::size_of::<[f32; 2]>()], + b, + c, + } } } - } - #[repr(C)] - #[derive(Debug, PartialEq, Clone, Copy)] - pub struct VectorsF32Init { - pub a: [f32; 2], - pub b: glam::Vec3A, - pub c: glam::Vec4, - } - impl VectorsF32Init { - pub const fn build(&self) -> VectorsF32 { - VectorsF32 { - a: self.a, - _pad_a: [0; 0x10 - core::mem::size_of::<[f32; 2]>()], - b: self.b, - c: self.c, + #[repr(C)] + #[derive(Debug, PartialEq, Clone, Copy)] + pub struct VectorsF32Init { + pub a: [f32; 2], + pub b: glam::Vec3A, + pub c: glam::Vec4, + } + impl VectorsF32Init { + pub const fn build(&self) -> VectorsF32 { + VectorsF32 { + a: self.a, + _pad_a: [0; 0x10 - core::mem::size_of::<[f32; 2]>()], + b: self.b, + c: self.c, + } } } - } - impl From for VectorsF32 { - fn from(data: VectorsF32Init) -> Self { - data.build() + impl From for VectorsF32 { + fn from(data: VectorsF32Init) -> Self { + data.build() + } } - } - #[repr(C, align(16))] - #[derive(Debug, PartialEq, Clone, Copy)] - pub struct MatricesF32 { - /// size: 64, offset: 0x0, type: `mat4x4` - pub a: glam::Mat4, - /// size: 64, offset: 0x40, type: `mat4x3` - pub b: [[f32; 4]; 4], - /// size: 32, offset: 0x80, type: `mat4x2` - pub c: [[f32; 2]; 4], - /// size: 48, offset: 0xA0, type: `mat3x4` - pub d: [[f32; 4]; 3], - /// size: 48, offset: 0xD0, type: `mat3x3` - pub e: glam::Mat3A, - /// size: 24, offset: 0x100, type: `mat3x2` - pub f: [[f32; 2]; 3], - pub _pad_f: [u8; 0x20 - core::mem::size_of::<[[f32; 2]; 3]>()], - /// size: 32, offset: 0x120, type: `mat2x4` - pub g: [[f32; 4]; 2], - /// size: 32, offset: 0x140, type: `mat2x3` - pub h: [[f32; 4]; 2], - /// size: 16, offset: 0x160, type: `mat2x2` - pub i: [[f32; 2]; 2], - } - impl MatricesF32 { - pub const fn new( - a: glam::Mat4, - b: [[f32; 4]; 4], - c: [[f32; 2]; 4], - d: [[f32; 4]; 3], - e: glam::Mat3A, - f: [[f32; 2]; 3], - g: [[f32; 4]; 2], - h: [[f32; 4]; 2], - i: [[f32; 2]; 2], - ) -> Self { - Self { - a, - b, - c, - d, - e, - f, - _pad_f: [0; 0x20 - core::mem::size_of::<[[f32; 2]; 3]>()], - g, - h, - i, + #[repr(C, align(16))] + #[derive(Debug, PartialEq, Clone, Copy)] + pub struct MatricesF32 { + /// size: 64, offset: 0x0, type: `mat4x4` + pub a: glam::Mat4, + /// size: 64, offset: 0x40, type: `mat4x3` + pub b: [[f32; 4]; 4], + /// size: 32, offset: 0x80, type: `mat4x2` + pub c: [[f32; 2]; 4], + /// size: 48, offset: 0xA0, type: `mat3x4` + pub d: [[f32; 4]; 3], + /// size: 48, offset: 0xD0, type: `mat3x3` + pub e: glam::Mat3A, + /// size: 24, offset: 0x100, type: `mat3x2` + pub f: [[f32; 2]; 3], + pub _pad_f: [u8; 0x20 - core::mem::size_of::<[[f32; 2]; 3]>()], + /// size: 32, offset: 0x120, type: `mat2x4` + pub g: [[f32; 4]; 2], + /// size: 32, offset: 0x140, type: `mat2x3` + pub h: [[f32; 4]; 2], + /// size: 16, offset: 0x160, type: `mat2x2` + pub i: [[f32; 2]; 2], + } + impl MatricesF32 { + pub const fn new( + a: glam::Mat4, + b: [[f32; 4]; 4], + c: [[f32; 2]; 4], + d: [[f32; 4]; 3], + e: glam::Mat3A, + f: [[f32; 2]; 3], + g: [[f32; 4]; 2], + h: [[f32; 4]; 2], + i: [[f32; 2]; 2], + ) -> Self { + Self { + a, + b, + c, + d, + e, + f, + _pad_f: [0; 0x20 - core::mem::size_of::<[[f32; 2]; 3]>()], + g, + h, + i, + } } } - } - #[repr(C)] - #[derive(Debug, PartialEq, Clone, Copy)] - pub struct MatricesF32Init { - pub a: glam::Mat4, - pub b: [[f32; 4]; 4], - pub c: [[f32; 2]; 4], - pub d: [[f32; 4]; 3], - pub e: glam::Mat3A, - pub f: [[f32; 2]; 3], - pub g: [[f32; 4]; 2], - pub h: [[f32; 4]; 2], - pub i: [[f32; 2]; 2], - } - impl MatricesF32Init { - pub const fn build(&self) -> MatricesF32 { - MatricesF32 { - a: self.a, - b: self.b, - c: self.c, - d: self.d, - e: self.e, - f: self.f, - _pad_f: [0; 0x20 - core::mem::size_of::<[[f32; 2]; 3]>()], - g: self.g, - h: self.h, - i: self.i, + #[repr(C)] + #[derive(Debug, PartialEq, Clone, Copy)] + pub struct MatricesF32Init { + pub a: glam::Mat4, + pub b: [[f32; 4]; 4], + pub c: [[f32; 2]; 4], + pub d: [[f32; 4]; 3], + pub e: glam::Mat3A, + pub f: [[f32; 2]; 3], + pub g: [[f32; 4]; 2], + pub h: [[f32; 4]; 2], + pub i: [[f32; 2]; 2], + } + impl MatricesF32Init { + pub const fn build(&self) -> MatricesF32 { + MatricesF32 { + a: self.a, + b: self.b, + c: self.c, + d: self.d, + e: self.e, + f: self.f, + _pad_f: [0; 0x20 - core::mem::size_of::<[[f32; 2]; 3]>()], + g: self.g, + h: self.h, + i: self.i, + } } } - } - impl From for MatricesF32 { - fn from(data: MatricesF32Init) -> Self { - data.build() + impl From for MatricesF32 { + fn from(data: MatricesF32Init) -> Self { + data.build() + } } - } - #[repr(C, align(16))] - #[derive(Debug, PartialEq, Clone, Copy)] - pub struct StaticArrays { - /// size: 20, offset: 0x0, type: `array` - pub a: [u32; 5], - pub _pad_a: [u8; 0x14 - core::mem::size_of::<[u32; 5]>()], - /// size: 12, offset: 0x14, type: `array` - pub b: [f32; 3], - pub _pad_b: [u8; 0xC - core::mem::size_of::<[f32; 3]>()], - /// size: 32768, offset: 0x20, type: `array, 512>` - pub c: [glam::Mat4; 512], - pub _pad_c: [u8; 0x8000 - core::mem::size_of::<[glam::Mat4; 512]>()], - /// size: 64, offset: 0x8020, type: `array, 4>` - pub d: [glam::Vec3A; 4], - pub _pad_d: [u8; 0x40 - core::mem::size_of::<[glam::Vec3A; 4]>()], - } - impl StaticArrays { - pub const fn new( - a: [u32; 5], - b: [f32; 3], - c: [glam::Mat4; 512], - d: [glam::Vec3A; 4], - ) -> Self { - Self { - a, - _pad_a: [0; 0x14 - core::mem::size_of::<[u32; 5]>()], - b, - _pad_b: [0; 0xC - core::mem::size_of::<[f32; 3]>()], - c, - _pad_c: [0; 0x8000 - core::mem::size_of::<[glam::Mat4; 512]>()], - d, - _pad_d: [0; 0x40 - core::mem::size_of::<[glam::Vec3A; 4]>()], + #[repr(C, align(16))] + #[derive(Debug, PartialEq, Clone, Copy)] + pub struct StaticArrays { + /// size: 20, offset: 0x0, type: `array` + pub a: [u32; 5], + pub _pad_a: [u8; 0x14 - core::mem::size_of::<[u32; 5]>()], + /// size: 12, offset: 0x14, type: `array` + pub b: [f32; 3], + pub _pad_b: [u8; 0xC - core::mem::size_of::<[f32; 3]>()], + /// size: 32768, offset: 0x20, type: `array, 512>` + pub c: [glam::Mat4; 512], + pub _pad_c: [u8; 0x8000 - core::mem::size_of::<[glam::Mat4; 512]>()], + /// size: 64, offset: 0x8020, type: `array, 4>` + pub d: [glam::Vec3A; 4], + pub _pad_d: [u8; 0x40 - core::mem::size_of::<[glam::Vec3A; 4]>()], + } + impl StaticArrays { + pub const fn new( + a: [u32; 5], + b: [f32; 3], + c: [glam::Mat4; 512], + d: [glam::Vec3A; 4], + ) -> Self { + Self { + a, + _pad_a: [0; 0x14 - core::mem::size_of::<[u32; 5]>()], + b, + _pad_b: [0; 0xC - core::mem::size_of::<[f32; 3]>()], + c, + _pad_c: [0; 0x8000 - core::mem::size_of::<[glam::Mat4; 512]>()], + d, + _pad_d: [0; 0x40 - core::mem::size_of::<[glam::Vec3A; 4]>()], + } } } - } - #[repr(C)] - #[derive(Debug, PartialEq, Clone, Copy)] - pub struct StaticArraysInit { - pub a: [u32; 5], - pub b: [f32; 3], - pub c: [glam::Mat4; 512], - pub d: [glam::Vec3A; 4], - } - impl StaticArraysInit { - pub const fn build(&self) -> StaticArrays { - StaticArrays { - a: self.a, - _pad_a: [0; 0x14 - core::mem::size_of::<[u32; 5]>()], - b: self.b, - _pad_b: [0; 0xC - core::mem::size_of::<[f32; 3]>()], - c: self.c, - _pad_c: [0; 0x8000 - core::mem::size_of::<[glam::Mat4; 512]>()], - d: self.d, - _pad_d: [0; 0x40 - core::mem::size_of::<[glam::Vec3A; 4]>()], + #[repr(C)] + #[derive(Debug, PartialEq, Clone, Copy)] + pub struct StaticArraysInit { + pub a: [u32; 5], + pub b: [f32; 3], + pub c: [glam::Mat4; 512], + pub d: [glam::Vec3A; 4], + } + impl StaticArraysInit { + pub const fn build(&self) -> StaticArrays { + StaticArrays { + a: self.a, + _pad_a: [0; 0x14 - core::mem::size_of::<[u32; 5]>()], + b: self.b, + _pad_b: [0; 0xC - core::mem::size_of::<[f32; 3]>()], + c: self.c, + _pad_c: [0; 0x8000 - core::mem::size_of::<[glam::Mat4; 512]>()], + d: self.d, + _pad_d: [0; 0x40 - core::mem::size_of::<[glam::Vec3A; 4]>()], + } } } - } - impl From for StaticArrays { - fn from(data: StaticArraysInit) -> Self { - data.build() + impl From for StaticArrays { + fn from(data: StaticArraysInit) -> Self { + data.build() + } + } + #[repr(C, align(16))] + #[derive(Debug, PartialEq, Clone, Copy)] + pub struct Nested { + /// size: 368, offset: 0x0, type: `struct` + pub a: _root::utils::types::MatricesF32, + /// size: 48, offset: 0x170, type: `struct` + pub b: _root::utils::types::VectorsF32, + } + pub const fn Nested( + a: _root::utils::types::MatricesF32, + b: _root::utils::types::VectorsF32, + ) -> Nested { + Nested { a, b } } - } - #[repr(C, align(16))] - #[derive(Debug, PartialEq, Clone, Copy)] - pub struct Nested { - /// size: 368, offset: 0x0, type: `struct` - pub a: _root::types::MatricesF32, - /// size: 48, offset: 0x170, type: `struct` - pub b: _root::types::VectorsF32, - } - pub const fn Nested( - a: _root::types::MatricesF32, - b: _root::types::VectorsF32, - ) -> Nested { - Nested { a, b } } } +pub mod bytemuck_impls { + use super::{_root, _root::*}; + unsafe impl bytemuck::Zeroable for utils::types::VectorsU32 {} + unsafe impl bytemuck::Pod for utils::types::VectorsU32 {} + unsafe impl bytemuck::Zeroable for utils::types::VectorsI32 {} + unsafe impl bytemuck::Pod for utils::types::VectorsI32 {} + unsafe impl bytemuck::Zeroable for utils::types::VectorsF32 {} + unsafe impl bytemuck::Pod for utils::types::VectorsF32 {} + unsafe impl bytemuck::Zeroable for utils::types::MatricesF32 {} + unsafe impl bytemuck::Pod for utils::types::MatricesF32 {} + unsafe impl bytemuck::Zeroable for utils::types::StaticArrays {} + unsafe impl bytemuck::Pod for utils::types::StaticArrays {} + unsafe impl bytemuck::Zeroable for utils::types::Nested {} + unsafe impl bytemuck::Pod for utils::types::Nested {} + unsafe impl bytemuck::Zeroable for testbed::Uniforms {} + unsafe impl bytemuck::Pod for testbed::Uniforms {} + unsafe impl bytemuck::Zeroable for triangle::Uniforms {} + unsafe impl bytemuck::Pod for triangle::Uniforms {} + unsafe impl bytemuck::Zeroable for triangle::VertexInput {} + unsafe impl bytemuck::Pod for triangle::VertexInput {} +} pub mod testbed { use super::{_root, _root::*}; #[repr(C, align(16))] @@ -514,17 +494,17 @@ pub mod testbed { pub mod bind_groups { use super::{_root, _root::*}; #[derive(Debug)] - pub struct WgpuBindGroup0EntryCollectionParams<'a> { + pub struct WgpuBindGroup0EntriesParams<'a> { pub color_texture: &'a wgpu::TextureView, pub color_sampler: &'a wgpu::Sampler, } #[derive(Clone, Debug)] - pub struct WgpuBindGroup0EntryCollection<'a> { + pub struct WgpuBindGroup0Entries<'a> { pub color_texture: wgpu::BindGroupEntry<'a>, pub color_sampler: wgpu::BindGroupEntry<'a>, } - impl<'a> WgpuBindGroup0EntryCollection<'a> { - pub fn new(params: WgpuBindGroup0EntryCollectionParams<'a>) -> Self { + impl<'a> WgpuBindGroup0Entries<'a> { + pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { Self { color_texture: wgpu::BindGroupEntry { binding: 0, @@ -538,9 +518,12 @@ pub mod testbed { }, } } - pub fn entries(self) -> [wgpu::BindGroupEntry<'a>; 2] { + 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); @@ -579,10 +562,10 @@ pub mod testbed { } pub fn from_bindings( device: &wgpu::Device, - bindings: WgpuBindGroup0EntryCollection, + bindings: WgpuBindGroup0Entries, ) -> Self { let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.entries(); + let entries = bindings.as_array(); let bind_group = device .create_bind_group( &wgpu::BindGroupDescriptor { @@ -598,15 +581,15 @@ pub mod testbed { } } #[derive(Debug)] - pub struct WgpuBindGroup1EntryCollectionParams<'a> { + pub struct WgpuBindGroup1EntriesParams<'a> { pub uniforms: wgpu::BufferBinding<'a>, } #[derive(Clone, Debug)] - pub struct WgpuBindGroup1EntryCollection<'a> { + pub struct WgpuBindGroup1Entries<'a> { pub uniforms: wgpu::BindGroupEntry<'a>, } - impl<'a> WgpuBindGroup1EntryCollection<'a> { - pub fn new(params: WgpuBindGroup1EntryCollectionParams<'a>) -> Self { + impl<'a> WgpuBindGroup1Entries<'a> { + pub fn new(params: WgpuBindGroup1EntriesParams<'a>) -> Self { Self { uniforms: wgpu::BindGroupEntry { binding: 0, @@ -614,9 +597,12 @@ pub mod testbed { }, } } - pub fn entries(self) -> [wgpu::BindGroupEntry<'a>; 1] { + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { [self.uniforms] } + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() + } } #[derive(Debug)] pub struct WgpuBindGroup1(wgpu::BindGroup); @@ -646,10 +632,10 @@ pub mod testbed { } pub fn from_bindings( device: &wgpu::Device, - bindings: WgpuBindGroup1EntryCollection, + bindings: WgpuBindGroup1Entries, ) -> Self { let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.entries(); + let entries = bindings.as_array(); let bind_group = device .create_bind_group( &wgpu::BindGroupDescriptor { @@ -665,8 +651,7 @@ pub mod testbed { } } #[derive(Debug)] - pub struct WgpuBindGroup2EntryCollectionParams<'a> { - pub rts: wgpu::BufferBinding<'a>, + pub struct WgpuBindGroup2EntriesParams<'a> { pub a: wgpu::BufferBinding<'a>, pub b: wgpu::BufferBinding<'a>, pub c: wgpu::BufferBinding<'a>, @@ -676,8 +661,7 @@ pub mod testbed { pub i: wgpu::BufferBinding<'a>, } #[derive(Clone, Debug)] - pub struct WgpuBindGroup2EntryCollection<'a> { - pub rts: wgpu::BindGroupEntry<'a>, + pub struct WgpuBindGroup2Entries<'a> { pub a: wgpu::BindGroupEntry<'a>, pub b: wgpu::BindGroupEntry<'a>, pub c: wgpu::BindGroupEntry<'a>, @@ -686,13 +670,9 @@ pub mod testbed { pub h: wgpu::BindGroupEntry<'a>, pub i: wgpu::BindGroupEntry<'a>, } - impl<'a> WgpuBindGroup2EntryCollection<'a> { - pub fn new(params: WgpuBindGroup2EntryCollectionParams<'a>) -> Self { + impl<'a> WgpuBindGroup2Entries<'a> { + pub fn new(params: WgpuBindGroup2EntriesParams<'a>) -> Self { Self { - rts: wgpu::BindGroupEntry { - binding: 1, - resource: wgpu::BindingResource::Buffer(params.rts), - }, a: wgpu::BindGroupEntry { binding: 2, resource: wgpu::BindingResource::Buffer(params.a), @@ -723,8 +703,11 @@ pub mod testbed { }, } } - pub fn entries(self) -> [wgpu::BindGroupEntry<'a>; 8] { - [self.rts, self.a, self.b, self.c, self.d, self.f, self.h, self.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() } } #[derive(Debug)] @@ -733,19 +716,6 @@ pub mod testbed { pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor { label: Some("Testbed::BindGroup2::LayoutDescriptor"), entries: &[ - /// @binding(1): "rts" - 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: None, - }, - count: None, - }, /// @binding(2): "a" wgpu::BindGroupLayoutEntry { binding: 2, @@ -771,7 +741,7 @@ pub mod testbed { }, has_dynamic_offset: false, min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::<_root::types::VectorsU32>() as _, + std::mem::size_of::<_root::utils::types::VectorsU32>() as _, ), }, count: None, @@ -786,7 +756,7 @@ pub mod testbed { }, has_dynamic_offset: false, min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::<_root::types::VectorsI32>() as _, + std::mem::size_of::<_root::utils::types::VectorsI32>() as _, ), }, count: None, @@ -801,7 +771,7 @@ pub mod testbed { }, has_dynamic_offset: false, min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::<_root::types::VectorsF32>() as _, + std::mem::size_of::<_root::utils::types::VectorsF32>() as _, ), }, count: None, @@ -816,7 +786,7 @@ pub mod testbed { }, has_dynamic_offset: false, min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::<_root::types::MatricesF32>() as _, + std::mem::size_of::<_root::utils::types::MatricesF32>() as _, ), }, count: None, @@ -831,7 +801,8 @@ pub mod testbed { }, has_dynamic_offset: false, min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::<_root::types::StaticArrays>() as _, + std::mem::size_of::<_root::utils::types::StaticArrays>() + as _, ), }, count: None, @@ -846,7 +817,7 @@ pub mod testbed { }, has_dynamic_offset: false, min_binding_size: std::num::NonZeroU64::new( - std::mem::size_of::<_root::types::Nested>() as _, + std::mem::size_of::<_root::utils::types::Nested>() as _, ), }, count: None, @@ -860,10 +831,10 @@ pub mod testbed { } pub fn from_bindings( device: &wgpu::Device, - bindings: WgpuBindGroup2EntryCollection, + bindings: WgpuBindGroup2Entries, ) -> Self { let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.entries(); + let entries = bindings.as_array(); let bind_group = device .create_bind_group( &wgpu::BindGroupDescriptor { @@ -998,37 +969,32 @@ pub mod testbed { }) } pub const SHADER_STRING: &'static str = r#" -struct rtsStructX_naga_oil_mod_XEIXC4LZOFYXW233SMUWXG2DBMRSXELLGNFWGK4ZPOJSWCY3INVSSEX { - other_data: i32, - the_array: array, -} - -struct ScalarsX_naga_oil_mod_XOR4XAZLTX { +struct ScalarsX_naga_oil_mod_XOV2GS3DTHI5HI6LQMVZQX { a: u32, b: i32, c: f32, } -struct VectorsU32X_naga_oil_mod_XOR4XAZLTX { +struct VectorsU32X_naga_oil_mod_XOV2GS3DTHI5HI6LQMVZQX { a: vec2, b: vec3, c: vec4, _padding: f32, } -struct VectorsI32X_naga_oil_mod_XOR4XAZLTX { +struct VectorsI32X_naga_oil_mod_XOV2GS3DTHI5HI6LQMVZQX { a: vec2, b: vec3, c: vec4, } -struct VectorsF32X_naga_oil_mod_XOR4XAZLTX { +struct VectorsF32X_naga_oil_mod_XOV2GS3DTHI5HI6LQMVZQX { a: vec2, b: vec3, c: vec4, } -struct MatricesF32X_naga_oil_mod_XOR4XAZLTX { +struct MatricesF32X_naga_oil_mod_XOV2GS3DTHI5HI6LQMVZQX { a: mat4x4, b: mat4x3, c: mat4x2, @@ -1040,39 +1006,37 @@ struct MatricesF32X_naga_oil_mod_XOR4XAZLTX { i: mat2x2, } -struct StaticArraysX_naga_oil_mod_XOR4XAZLTX { +struct StaticArraysX_naga_oil_mod_XOV2GS3DTHI5HI6LQMVZQX { a: array, b: array, c: array, 512>, d: array, 4>, } -struct NestedX_naga_oil_mod_XOR4XAZLTX { - a: MatricesF32X_naga_oil_mod_XOR4XAZLTX, - b: VectorsF32X_naga_oil_mod_XOR4XAZLTX, +struct NestedX_naga_oil_mod_XOV2GS3DTHI5HI6LQMVZQX { + a: MatricesF32X_naga_oil_mod_XOV2GS3DTHI5HI6LQMVZQX, + b: VectorsF32X_naga_oil_mod_XOV2GS3DTHI5HI6LQMVZQX, } struct Uniforms { color_rgb: vec4, - scalars: ScalarsX_naga_oil_mod_XOR4XAZLTX, + scalars: ScalarsX_naga_oil_mod_XOV2GS3DTHI5HI6LQMVZQX, } -@group(2) @binding(1) -var rts: rtsStructX_naga_oil_mod_XEIXC4LZOFYXW233SMUWXG2DBMRSXELLGNFWGK4ZPOJSWCY3INVSSEX; @group(2) @binding(2) -var a: ScalarsX_naga_oil_mod_XOR4XAZLTX; +var a: ScalarsX_naga_oil_mod_XOV2GS3DTHI5HI6LQMVZQX; @group(2) @binding(3) -var b: VectorsU32X_naga_oil_mod_XOR4XAZLTX; +var b: VectorsU32X_naga_oil_mod_XOV2GS3DTHI5HI6LQMVZQX; @group(2) @binding(4) -var c: VectorsI32X_naga_oil_mod_XOR4XAZLTX; +var c: VectorsI32X_naga_oil_mod_XOV2GS3DTHI5HI6LQMVZQX; @group(2) @binding(5) -var d: VectorsF32X_naga_oil_mod_XOR4XAZLTX; +var d: VectorsF32X_naga_oil_mod_XOV2GS3DTHI5HI6LQMVZQX; @group(2) @binding(6) -var f: MatricesF32X_naga_oil_mod_XOR4XAZLTX; +var f: MatricesF32X_naga_oil_mod_XOV2GS3DTHI5HI6LQMVZQX; @group(2) @binding(8) -var h: StaticArraysX_naga_oil_mod_XOR4XAZLTX; +var h: StaticArraysX_naga_oil_mod_XOV2GS3DTHI5HI6LQMVZQX; @group(2) @binding(9) -var i: NestedX_naga_oil_mod_XOR4XAZLTX; +var i: NestedX_naga_oil_mod_XOV2GS3DTHI5HI6LQMVZQX; @group(0) @binding(0) var color_texture: texture_2d; @group(0) @binding(1) @@ -1094,23 +1058,11 @@ fn main(@builtin(global_invocation_id) id: vec3) { ) -> () { composer .add_composable_module(naga_oil::compose::ComposableModuleDescriptor { - source: include_str!( - "../assets/shader/utils/../../more-shader-files/reachme.wgsl" - ), - file_path: "../assets/shader/utils/../../more-shader-files/reachme.wgsl", - language: naga_oil::compose::ShaderLanguage::Wgsl, - shader_defs: shader_defs.clone(), - as_name: Some("\"../../more-shader-files/reachme\"".into()), - ..Default::default() - }) - .expect("failed to add composer module"); - composer - .add_composable_module(naga_oil::compose::ComposableModuleDescriptor { - source: include_str!("../assets/shader/types.wgsl"), - file_path: "../assets/shader/types.wgsl", + source: include_str!("../shaders/utils/types.wgsl"), + file_path: "../shaders/utils/types.wgsl", language: naga_oil::compose::ShaderLanguage::Wgsl, shader_defs: shader_defs.clone(), - as_name: Some("types".into()), + as_name: Some("utils::types".into()), ..Default::default() }) .expect("failed to add composer module"); @@ -1122,8 +1074,8 @@ fn main(@builtin(global_invocation_id) id: vec3) { ) -> wgpu::naga::Module { composer .make_naga_module(naga_oil::compose::NagaModuleDescriptor { - source: include_str!("../assets/shader/utils/testbed.wgsl"), - file_path: "../assets/shader/utils/testbed.wgsl", + source: include_str!("../shaders/testbed.wgsl"), + file_path: "../shaders/testbed.wgsl", shader_defs, ..Default::default() }) @@ -1156,19 +1108,12 @@ fn main(@builtin(global_invocation_id) id: vec3) { }) } pub const SHADER_ENTRY_PATH: &str = include_absolute_path::include_absolute_path!( - "../assets/shader/utils/testbed.wgsl" + "../shaders/testbed.wgsl" ); - pub const MORESHADERFILESREACHME_PATH: &str = include_absolute_path::include_absolute_path!( - "../assets/shader/utils/../../more-shader-files/reachme.wgsl" + pub const UTILS_TYPES_PATH: &str = include_absolute_path::include_absolute_path!( + "../shaders/utils/types.wgsl" ); - pub const TYPES_PATH: &str = include_absolute_path::include_absolute_path!( - "../assets/shader/types.wgsl" - ); - pub const SHADER_PATHS: &[&str] = &[ - SHADER_ENTRY_PATH, - MORESHADERFILESREACHME_PATH, - TYPES_PATH, - ]; + pub const SHADER_PATHS: &[&str] = &[SHADER_ENTRY_PATH, UTILS_TYPES_PATH]; pub fn load_shader_modules_from_path( composer: &mut naga_oil::compose::Composer, shader_defs: &std::collections::HashMap< @@ -1178,20 +1123,11 @@ fn main(@builtin(global_invocation_id) id: vec3) { ) -> Result<(), naga_oil::compose::ComposerError> { composer .add_composable_module(naga_oil::compose::ComposableModuleDescriptor { - source: &std::fs::read_to_string(MORESHADERFILESREACHME_PATH).unwrap(), - file_path: "../assets/shader/utils/../../more-shader-files/reachme.wgsl", + source: &std::fs::read_to_string(UTILS_TYPES_PATH).unwrap(), + file_path: "../shaders/utils/types.wgsl", language: naga_oil::compose::ShaderLanguage::Wgsl, shader_defs: shader_defs.clone(), - as_name: Some("\"../../more-shader-files/reachme\"".into()), - ..Default::default() - })?; - composer - .add_composable_module(naga_oil::compose::ComposableModuleDescriptor { - source: &std::fs::read_to_string(TYPES_PATH).unwrap(), - file_path: "../assets/shader/types.wgsl", - language: naga_oil::compose::ShaderLanguage::Wgsl, - shader_defs: shader_defs.clone(), - as_name: Some("types".into()), + as_name: Some("utils::types".into()), ..Default::default() })?; Ok(()) @@ -1203,7 +1139,7 @@ fn main(@builtin(global_invocation_id) id: vec3) { composer .make_naga_module(naga_oil::compose::NagaModuleDescriptor { source: &std::fs::read_to_string(SHADER_ENTRY_PATH).unwrap(), - file_path: "../assets/shader/utils/testbed.wgsl", + file_path: "../shaders/testbed.wgsl", shader_defs, ..Default::default() }) @@ -1277,17 +1213,17 @@ pub mod triangle { pub mod bind_groups { use super::{_root, _root::*}; #[derive(Debug)] - pub struct WgpuBindGroup0EntryCollectionParams<'a> { + pub struct WgpuBindGroup0EntriesParams<'a> { pub color_texture: &'a wgpu::TextureView, pub color_sampler: &'a wgpu::Sampler, } #[derive(Clone, Debug)] - pub struct WgpuBindGroup0EntryCollection<'a> { + pub struct WgpuBindGroup0Entries<'a> { pub color_texture: wgpu::BindGroupEntry<'a>, pub color_sampler: wgpu::BindGroupEntry<'a>, } - impl<'a> WgpuBindGroup0EntryCollection<'a> { - pub fn new(params: WgpuBindGroup0EntryCollectionParams<'a>) -> Self { + impl<'a> WgpuBindGroup0Entries<'a> { + pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { Self { color_texture: wgpu::BindGroupEntry { binding: 0, @@ -1301,9 +1237,12 @@ pub mod triangle { }, } } - pub fn entries(self) -> [wgpu::BindGroupEntry<'a>; 2] { + 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); @@ -1342,10 +1281,10 @@ pub mod triangle { } pub fn from_bindings( device: &wgpu::Device, - bindings: WgpuBindGroup0EntryCollection, + bindings: WgpuBindGroup0Entries, ) -> Self { let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.entries(); + let entries = bindings.as_array(); let bind_group = device .create_bind_group( &wgpu::BindGroupDescriptor { @@ -1361,15 +1300,15 @@ pub mod triangle { } } #[derive(Debug)] - pub struct WgpuBindGroup1EntryCollectionParams<'a> { + pub struct WgpuBindGroup1EntriesParams<'a> { pub uniforms: wgpu::BufferBinding<'a>, } #[derive(Clone, Debug)] - pub struct WgpuBindGroup1EntryCollection<'a> { + pub struct WgpuBindGroup1Entries<'a> { pub uniforms: wgpu::BindGroupEntry<'a>, } - impl<'a> WgpuBindGroup1EntryCollection<'a> { - pub fn new(params: WgpuBindGroup1EntryCollectionParams<'a>) -> Self { + impl<'a> WgpuBindGroup1Entries<'a> { + pub fn new(params: WgpuBindGroup1EntriesParams<'a>) -> Self { Self { uniforms: wgpu::BindGroupEntry { binding: 0, @@ -1377,9 +1316,12 @@ pub mod triangle { }, } } - pub fn entries(self) -> [wgpu::BindGroupEntry<'a>; 1] { + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { [self.uniforms] } + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() + } } #[derive(Debug)] pub struct WgpuBindGroup1(wgpu::BindGroup); @@ -1409,10 +1351,10 @@ pub mod triangle { } pub fn from_bindings( device: &wgpu::Device, - bindings: WgpuBindGroup1EntryCollection, + bindings: WgpuBindGroup1Entries, ) -> Self { let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.entries(); + let entries = bindings.as_array(); let bind_group = device .create_bind_group( &wgpu::BindGroupDescriptor { @@ -1592,8 +1534,8 @@ fn fs_main(in_1: VertexOutput) -> @location(0) vec4 { ) -> wgpu::naga::Module { composer .make_naga_module(naga_oil::compose::NagaModuleDescriptor { - source: include_str!("../assets/shader/triangle.wgsl"), - file_path: "../assets/shader/triangle.wgsl", + source: include_str!("../shaders/triangle.wgsl"), + file_path: "../shaders/triangle.wgsl", shader_defs, ..Default::default() }) @@ -1626,7 +1568,7 @@ fn fs_main(in_1: VertexOutput) -> @location(0) vec4 { }) } pub const SHADER_ENTRY_PATH: &str = include_absolute_path::include_absolute_path!( - "../assets/shader/triangle.wgsl" + "../shaders/triangle.wgsl" ); pub const SHADER_PATHS: &[&str] = &[SHADER_ENTRY_PATH]; pub fn load_shader_modules_from_path( @@ -1645,7 +1587,7 @@ fn fs_main(in_1: VertexOutput) -> @location(0) vec4 { composer .make_naga_module(naga_oil::compose::NagaModuleDescriptor { source: &std::fs::read_to_string(SHADER_ENTRY_PATH).unwrap(), - file_path: "../assets/shader/triangle.wgsl", + file_path: "../shaders/triangle.wgsl", shader_defs, ..Default::default() }) diff --git a/wgsl_bindgen/src/bindgen/options/bindings.rs b/wgsl_bindgen/src/bindgen/options/bindings.rs index bc36bb3..50697e0 100644 --- a/wgsl_bindgen/src/bindgen/options/bindings.rs +++ b/wgsl_bindgen/src/bindgen/options/bindings.rs @@ -63,11 +63,8 @@ impl BindGroupLayoutGenerator { format_ident!("{}{}", self.name_prefix, group_index) } - pub(crate) fn bind_group_entry_collection_struct_name_ident( - &self, - group_index: u32, - ) -> Ident { - format_ident!("{}{}{}", self.name_prefix, group_index, "EntryCollection") + pub(crate) fn bind_group_entries_struct_name_ident(&self, group_index: u32) -> Ident { + format_ident!("{}{}{}", self.name_prefix, group_index, "Entries") } } diff --git a/wgsl_bindgen/src/generate/bind_group/entry_collection_builder.rs b/wgsl_bindgen/src/generate/bind_group/entries_struct_builder.rs similarity index 92% rename from wgsl_bindgen/src/generate/bind_group/entry_collection_builder.rs rename to wgsl_bindgen/src/generate/bind_group/entries_struct_builder.rs index 705293d..63bf343 100644 --- a/wgsl_bindgen/src/generate/bind_group/entry_collection_builder.rs +++ b/wgsl_bindgen/src/generate/bind_group/entries_struct_builder.rs @@ -4,14 +4,14 @@ use self::quote_gen::RustItemPath; use super::*; #[derive(Constructor)] -pub(super) struct BindGroupEntryCollectionBuilder<'a> { +pub(super) struct BindGroupEntriesStructBuilder<'a> { invoking_entry_module: &'a str, group_no: u32, data: &'a GroupData<'a>, generator: &'a BindGroupLayoutGenerator, } -impl<'a> BindGroupEntryCollectionBuilder<'a> { +impl<'a> BindGroupEntriesStructBuilder<'a> { /// Generates a binding entry from a parameter variable and a group binding. fn create_entry_from_parameter( &self, @@ -118,12 +118,12 @@ impl<'a> BindGroupEntryCollectionBuilder<'a> { let entry_collection_name = self .generator - .bind_group_entry_collection_struct_name_ident(self.group_no); + .bind_group_entries_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) + .bind_group_entries_struct_name_ident(self.group_no) ); let entry_struct_type = self.generator.entry_struct_type.clone(); @@ -156,9 +156,13 @@ impl<'a> BindGroupEntryCollectionBuilder<'a> { } } - pub fn entries(self) -> [#entry_struct_type; #entries_length] { + pub fn as_array(self) -> [#entry_struct_type; #entries_length] { [ #(#all_entries),* ] } + + pub fn collect>(self) -> B { + self.as_array().into_iter().collect() + } } } } diff --git a/wgsl_bindgen/src/generate/bind_group/mod.rs b/wgsl_bindgen/src/generate/bind_group/mod.rs index 06b47f8..3f58db6 100644 --- a/wgsl_bindgen/src/generate/bind_group/mod.rs +++ b/wgsl_bindgen/src/generate/bind_group/mod.rs @@ -7,8 +7,8 @@ use quote_gen::{demangle_and_fully_qualify_str, rust_type}; use crate::wgsl::buffer_binding_type; use crate::*; -mod entry_collection_builder; -use entry_collection_builder::*; +mod entries_struct_builder; +use entries_struct_builder::*; pub struct GroupData<'a> { pub bindings: Vec>, @@ -83,11 +83,11 @@ impl<'a> BindGroupBuilder<'a> { }; let bind_group_name = self.struct_name(); - let bind_group_entry_collection_struct_name = self + let bind_group_entries_struct_name = self .options .wgpu_binding_generator .bind_group_layout - .bind_group_entry_collection_struct_name_ident(self.group_no); + .bind_group_entries_struct_name_ident(self.group_no); let bind_group_layout_descriptor = self.bind_group_layout_descriptor(); @@ -103,9 +103,9 @@ impl<'a> BindGroupBuilder<'a> { device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR) } - pub fn from_bindings(device: &wgpu::Device, bindings: #bind_group_entry_collection_struct_name) -> Self { + pub fn from_bindings(device: &wgpu::Device, bindings: #bind_group_entries_struct_name) -> Self { let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.entries(); + let entries = bindings.as_array(); let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { label: Some(#bind_group_label), layout: &bind_group_layout, @@ -152,7 +152,7 @@ pub fn bind_groups_module( .map(|(group_no, group)| { let wgpu_generator = &options.wgpu_binding_generator; - let bind_group_entry_collection = BindGroupEntryCollectionBuilder::new( + let bind_group_entries_struct = BindGroupEntriesStructBuilder::new( invoking_entry_module, *group_no, group, @@ -162,7 +162,7 @@ pub fn bind_groups_module( let additional_layout = if let Some(additional_generator) = &options.extra_binding_generator { - BindGroupEntryCollectionBuilder::new( + BindGroupEntriesStructBuilder::new( invoking_entry_module, *group_no, group, @@ -186,7 +186,7 @@ pub fn bind_groups_module( quote! { #additional_layout - #bind_group_entry_collection + #bind_group_entries_struct #bindgroup } }) @@ -539,19 +539,19 @@ mod tests { pub mod bind_groups { use super::{_root, _root::*}; #[derive(Debug)] - pub struct WgpuBindGroup0EntryCollectionParams<'a> { + 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 WgpuBindGroup0EntryCollection<'a> { + pub struct WgpuBindGroup0Entries<'a> { pub src: wgpu::BindGroupEntry<'a>, pub vertex_weights: wgpu::BindGroupEntry<'a>, pub dst: wgpu::BindGroupEntry<'a>, } - impl<'a> WgpuBindGroup0EntryCollection<'a> { - pub fn new(params: WgpuBindGroup0EntryCollectionParams<'a>) -> Self { + impl<'a> WgpuBindGroup0Entries<'a> { + pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { Self { src: wgpu::BindGroupEntry { binding: 0, @@ -567,9 +567,12 @@ mod tests { }, } } - pub fn entries(self) -> [wgpu::BindGroupEntry<'a>; 3] { + 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); @@ -625,9 +628,9 @@ mod tests { 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: WgpuBindGroup0EntryCollection) -> Self { + pub fn from_bindings(device: &wgpu::Device, bindings: WgpuBindGroup0Entries) -> Self { let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.entries(); + let entries = bindings.as_array(); let bind_group = device .create_bind_group( &wgpu::BindGroupDescriptor { @@ -643,15 +646,15 @@ mod tests { } } #[derive(Debug)] - pub struct WgpuBindGroup1EntryCollectionParams<'a> { + pub struct WgpuBindGroup1EntriesParams<'a> { pub transforms: wgpu::BufferBinding<'a>, } #[derive(Clone, Debug)] - pub struct WgpuBindGroup1EntryCollection<'a> { + pub struct WgpuBindGroup1Entries<'a> { pub transforms: wgpu::BindGroupEntry<'a>, } - impl<'a> WgpuBindGroup1EntryCollection<'a> { - pub fn new(params: WgpuBindGroup1EntryCollectionParams<'a>) -> Self { + impl<'a> WgpuBindGroup1Entries<'a> { + pub fn new(params: WgpuBindGroup1EntriesParams<'a>) -> Self { Self { transforms: wgpu::BindGroupEntry { binding: 0, @@ -659,9 +662,12 @@ mod tests { }, } } - pub fn entries(self) -> [wgpu::BindGroupEntry<'a>; 1] { + 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); @@ -688,9 +694,9 @@ mod tests { 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: WgpuBindGroup1EntryCollection) -> Self { + pub fn from_bindings(device: &wgpu::Device, bindings: WgpuBindGroup1Entries) -> Self { let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.entries(); + let entries = bindings.as_array(); let bind_group = device .create_bind_group( &wgpu::BindGroupDescriptor { @@ -790,7 +796,7 @@ mod tests { pub mod bind_groups { use super::{_root, _root::*}; #[derive(Debug)] - pub struct WgpuBindGroup0EntryCollectionParams<'a> { + pub struct WgpuBindGroup0EntriesParams<'a> { pub color_texture: &'a wgpu::TextureView, pub color_texture_i32: &'a wgpu::TextureView, pub color_texture_u32: &'a wgpu::TextureView, @@ -804,7 +810,7 @@ mod tests { pub depth_texture_msaa: &'a wgpu::TextureView, } #[derive(Clone, Debug)] - pub struct WgpuBindGroup0EntryCollection<'a> { + pub struct WgpuBindGroup0Entries<'a> { pub color_texture: wgpu::BindGroupEntry<'a>, pub color_texture_i32: wgpu::BindGroupEntry<'a>, pub color_texture_u32: wgpu::BindGroupEntry<'a>, @@ -817,8 +823,8 @@ mod tests { pub color_texture_msaa: wgpu::BindGroupEntry<'a>, pub depth_texture_msaa: wgpu::BindGroupEntry<'a>, } - impl<'a> WgpuBindGroup0EntryCollection<'a> { - pub fn new(params: WgpuBindGroup0EntryCollectionParams<'a>) -> Self { + impl<'a> WgpuBindGroup0Entries<'a> { + pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { Self { color_texture: wgpu::BindGroupEntry { binding: 0, @@ -889,7 +895,7 @@ mod tests { } } - pub fn entries(self) -> [wgpu::BindGroupEntry<'a>; 11] { + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 11] { [ self.color_texture, self.color_texture_i32, @@ -904,6 +910,9 @@ mod tests { self.depth_texture_msaa, ] } + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() + } } #[derive(Debug)] pub struct WgpuBindGroup0(wgpu::BindGroup); @@ -1033,9 +1042,9 @@ mod tests { 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: WgpuBindGroup0EntryCollection) -> Self { + pub fn from_bindings(device: &wgpu::Device, bindings: WgpuBindGroup0Entries) -> Self { let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.entries(); + let entries = bindings.as_array(); let bind_group = device .create_bind_group( &wgpu::BindGroupDescriptor { @@ -1051,17 +1060,17 @@ mod tests { } } #[derive(Debug)] - pub struct WgpuBindGroup1EntryCollectionParams<'a> { + pub struct WgpuBindGroup1EntriesParams<'a> { pub transforms: wgpu::BufferBinding<'a>, pub one: wgpu::BufferBinding<'a>, } #[derive(Clone, Debug)] - pub struct WgpuBindGroup1EntryCollection<'a> { + pub struct WgpuBindGroup1Entries<'a> { pub transforms: wgpu::BindGroupEntry<'a>, pub one: wgpu::BindGroupEntry<'a>, } - impl<'a> WgpuBindGroup1EntryCollection<'a> { - pub fn new(params: WgpuBindGroup1EntryCollectionParams<'a>) -> Self { + impl<'a> WgpuBindGroup1Entries<'a> { + pub fn new(params: WgpuBindGroup1EntriesParams<'a>) -> Self { Self { transforms: wgpu::BindGroupEntry { binding: 0, @@ -1073,9 +1082,12 @@ mod tests { }, } } - pub fn entries(self) -> [wgpu::BindGroupEntry<'a>; 2] { + 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); @@ -1114,9 +1126,9 @@ mod tests { 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: WgpuBindGroup1EntryCollection) -> Self { + pub fn from_bindings(device: &wgpu::Device, bindings: WgpuBindGroup1Entries) -> Self { let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.entries(); + let entries = bindings.as_array(); let bind_group = device .create_bind_group( &wgpu::BindGroupDescriptor { @@ -1187,15 +1199,15 @@ mod tests { pub mod bind_groups { use super::{_root, _root::*}; #[derive(Debug)] - pub struct WgpuBindGroup0EntryCollectionParams<'a> { + pub struct WgpuBindGroup0EntriesParams<'a> { pub transforms: wgpu::BufferBinding<'a>, } #[derive(Clone, Debug)] - pub struct WgpuBindGroup0EntryCollection<'a> { + pub struct WgpuBindGroup0Entries<'a> { pub transforms: wgpu::BindGroupEntry<'a>, } - impl<'a> WgpuBindGroup0EntryCollection<'a> { - pub fn new(params: WgpuBindGroup0EntryCollectionParams<'a>) -> Self { + impl<'a> WgpuBindGroup0Entries<'a> { + pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { Self { transforms: wgpu::BindGroupEntry { binding: 0, @@ -1203,11 +1215,14 @@ mod tests { }, } } - pub fn entries(self) -> [wgpu::BindGroupEntry<'a>; 1] { + 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); @@ -1233,9 +1248,9 @@ mod tests { 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: WgpuBindGroup0EntryCollection) -> Self { + pub fn from_bindings(device: &wgpu::Device, bindings: WgpuBindGroup0Entries) -> Self { let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.entries(); + let entries = bindings.as_array(); let bind_group = device .create_bind_group( &wgpu::BindGroupDescriptor { @@ -1301,15 +1316,15 @@ mod tests { pub mod bind_groups { use super::{_root, _root::*}; #[derive(Debug)] - pub struct WgpuBindGroup0EntryCollectionParams<'a> { + pub struct WgpuBindGroup0EntriesParams<'a> { pub transforms: wgpu::BufferBinding<'a>, } #[derive(Clone, Debug)] - pub struct WgpuBindGroup0EntryCollection<'a> { + pub struct WgpuBindGroup0Entries<'a> { pub transforms: wgpu::BindGroupEntry<'a>, } - impl<'a> WgpuBindGroup0EntryCollection<'a> { - pub fn new(params: WgpuBindGroup0EntryCollectionParams<'a>) -> Self { + impl<'a> WgpuBindGroup0Entries<'a> { + pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { Self { transforms: wgpu::BindGroupEntry { binding: 0, @@ -1317,9 +1332,12 @@ mod tests { }, } } - pub fn entries(self) -> [wgpu::BindGroupEntry<'a>; 1] { + 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); @@ -1346,9 +1364,9 @@ mod tests { 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: WgpuBindGroup0EntryCollection) -> Self { + pub fn from_bindings(device: &wgpu::Device, bindings: WgpuBindGroup0Entries) -> Self { let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.entries(); + let entries = bindings.as_array(); let bind_group = device .create_bind_group( &wgpu::BindGroupDescriptor { diff --git a/wgsl_bindgen/tests/deptree_tests.rs b/wgsl_bindgen/tests/deptree_tests.rs index 7fd65c9..cb7c4d9 100644 --- a/wgsl_bindgen/tests/deptree_tests.rs +++ b/wgsl_bindgen/tests/deptree_tests.rs @@ -118,30 +118,6 @@ fn test_bevy_full_dependencies() { assert_eq!(&actual, expected); } -#[test] -fn test_example_wgsl_dep_tree() { - let result = DependencyTree::try_build( - "../example/assets/shader".into(), - None, - vec![SourceFilePath::new( - "../example/assets/shader/utils/testbed.wgsl", - )], - vec![], - ) - .unwrap(); - - assert_eq!( - result.all_files_including_dependencies(), - indexset![ - SourceFilePath::new("../example/assets/shader/utils/testbed.wgsl"), - SourceFilePath::new( - "../example/assets/shader/utils/../../more-shader-files/reachme.wgsl" - ), - SourceFilePath::new("../example/assets/shader/types.wgsl"), - ] - ) -} - #[test] fn test_bevy_mesh_wgsl_dependency_order() { let deptree = build_bevy_deptree(); diff --git a/wgsl_bindgen/tests/output/bindgen_bevy.expected.rs b/wgsl_bindgen/tests/output/bindgen_bevy.expected.rs index 2a3570e..2ee0df3 100644 --- a/wgsl_bindgen/tests/output/bindgen_bevy.expected.rs +++ b/wgsl_bindgen/tests/output/bindgen_bevy.expected.rs @@ -701,7 +701,7 @@ pub mod pbr { pub mod bind_groups { use super::{_root, _root::*}; #[derive(Debug)] - pub struct WgpuBindGroup0EntryCollectionParams<'a> { + pub struct WgpuBindGroup0EntriesParams<'a> { pub view: wgpu::BufferBinding<'a>, pub lights: wgpu::BufferBinding<'a>, pub point_lights: wgpu::BufferBinding<'a>, @@ -713,7 +713,7 @@ pub mod pbr { pub directional_shadow_textures_sampler: &'a wgpu::Sampler, } #[derive(Clone, Debug)] - pub struct WgpuBindGroup0EntryCollection<'a> { + pub struct WgpuBindGroup0Entries<'a> { pub view: wgpu::BindGroupEntry<'a>, pub lights: wgpu::BindGroupEntry<'a>, pub point_lights: wgpu::BindGroupEntry<'a>, @@ -724,8 +724,8 @@ pub mod pbr { pub directional_shadow_textures: wgpu::BindGroupEntry<'a>, pub directional_shadow_textures_sampler: wgpu::BindGroupEntry<'a>, } - impl<'a> WgpuBindGroup0EntryCollection<'a> { - pub fn new(params: WgpuBindGroup0EntryCollectionParams<'a>) -> Self { + impl<'a> WgpuBindGroup0Entries<'a> { + pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { Self { view: wgpu::BindGroupEntry { binding: 0, @@ -777,7 +777,7 @@ pub mod pbr { }, } } - pub fn entries(self) -> [wgpu::BindGroupEntry<'a>; 9] { + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 9] { [ self.view, self.lights, @@ -790,6 +790,9 @@ pub mod pbr { self.directional_shadow_textures_sampler, ] } + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() + } } #[derive(Debug)] pub struct WgpuBindGroup0(wgpu::BindGroup); @@ -915,10 +918,10 @@ pub mod pbr { } pub fn from_bindings( device: &wgpu::Device, - bindings: WgpuBindGroup0EntryCollection, + bindings: WgpuBindGroup0Entries, ) -> Self { let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.entries(); + let entries = bindings.as_array(); let bind_group = device .create_bind_group( &wgpu::BindGroupDescriptor { @@ -934,15 +937,15 @@ pub mod pbr { } } #[derive(Debug)] - pub struct WgpuBindGroup1EntryCollectionParams<'a> { + pub struct WgpuBindGroup1EntriesParams<'a> { pub material: wgpu::BufferBinding<'a>, } #[derive(Clone, Debug)] - pub struct WgpuBindGroup1EntryCollection<'a> { + pub struct WgpuBindGroup1Entries<'a> { pub material: wgpu::BindGroupEntry<'a>, } - impl<'a> WgpuBindGroup1EntryCollection<'a> { - pub fn new(params: WgpuBindGroup1EntryCollectionParams<'a>) -> Self { + impl<'a> WgpuBindGroup1Entries<'a> { + pub fn new(params: WgpuBindGroup1EntriesParams<'a>) -> Self { Self { material: wgpu::BindGroupEntry { binding: 0, @@ -950,9 +953,12 @@ pub mod pbr { }, } } - pub fn entries(self) -> [wgpu::BindGroupEntry<'a>; 1] { + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { [self.material] } + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() + } } #[derive(Debug)] pub struct WgpuBindGroup1(wgpu::BindGroup); @@ -984,10 +990,10 @@ pub mod pbr { } pub fn from_bindings( device: &wgpu::Device, - bindings: WgpuBindGroup1EntryCollection, + bindings: WgpuBindGroup1Entries, ) -> Self { let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.entries(); + let entries = bindings.as_array(); let bind_group = device .create_bind_group( &wgpu::BindGroupDescriptor { @@ -1003,15 +1009,15 @@ pub mod pbr { } } #[derive(Debug)] - pub struct WgpuBindGroup2EntryCollectionParams<'a> { + pub struct WgpuBindGroup2EntriesParams<'a> { pub mesh: wgpu::BufferBinding<'a>, } #[derive(Clone, Debug)] - pub struct WgpuBindGroup2EntryCollection<'a> { + pub struct WgpuBindGroup2Entries<'a> { pub mesh: wgpu::BindGroupEntry<'a>, } - impl<'a> WgpuBindGroup2EntryCollection<'a> { - pub fn new(params: WgpuBindGroup2EntryCollectionParams<'a>) -> Self { + impl<'a> WgpuBindGroup2Entries<'a> { + pub fn new(params: WgpuBindGroup2EntriesParams<'a>) -> Self { Self { mesh: wgpu::BindGroupEntry { binding: 0, @@ -1019,9 +1025,12 @@ pub mod pbr { }, } } - pub fn entries(self) -> [wgpu::BindGroupEntry<'a>; 1] { + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { [self.mesh] } + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() + } } #[derive(Debug)] pub struct WgpuBindGroup2(wgpu::BindGroup); @@ -1052,10 +1061,10 @@ pub mod pbr { } pub fn from_bindings( device: &wgpu::Device, - bindings: WgpuBindGroup2EntryCollection, + bindings: WgpuBindGroup2Entries, ) -> Self { let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.entries(); + let entries = bindings.as_array(); let bind_group = device .create_bind_group( &wgpu::BindGroupDescriptor { diff --git a/wgsl_bindgen/tests/output/bindgen_main.expected.rs b/wgsl_bindgen/tests/output/bindgen_main.expected.rs index af5ed64..fc977b3 100644 --- a/wgsl_bindgen/tests/output/bindgen_main.expected.rs +++ b/wgsl_bindgen/tests/output/bindgen_main.expected.rs @@ -101,21 +101,21 @@ pub mod main { pub mod bind_groups { use super::{_root, _root::*}; #[derive(Debug)] - pub struct WgpuBindGroup0EntryCollectionParams<'a> { + 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 WgpuBindGroup0EntryCollection<'a> { + 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> WgpuBindGroup0EntryCollection<'a> { - pub fn new(params: WgpuBindGroup0EntryCollectionParams<'a>) -> Self { + impl<'a> WgpuBindGroup0Entries<'a> { + pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { Self { buffer: wgpu::BindGroupEntry { binding: 0, @@ -137,9 +137,12 @@ pub mod main { }, } } - pub fn entries(self) -> [wgpu::BindGroupEntry<'a>; 4] { + 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() + } } #[derive(Debug)] pub struct WgpuBindGroup0(wgpu::BindGroup); @@ -204,10 +207,10 @@ pub mod main { } pub fn from_bindings( device: &wgpu::Device, - bindings: WgpuBindGroup0EntryCollection, + bindings: WgpuBindGroup0Entries, ) -> Self { let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.entries(); + let entries = bindings.as_array(); let bind_group = device .create_bind_group( &wgpu::BindGroupDescriptor { @@ -223,15 +226,15 @@ pub mod main { } } #[derive(Debug)] - pub struct WgpuBindGroup1EntryCollectionParams<'a> { + pub struct WgpuBindGroup1EntriesParams<'a> { pub ONE: wgpu::BufferBinding<'a>, } #[derive(Clone, Debug)] - pub struct WgpuBindGroup1EntryCollection<'a> { + pub struct WgpuBindGroup1Entries<'a> { pub ONE: wgpu::BindGroupEntry<'a>, } - impl<'a> WgpuBindGroup1EntryCollection<'a> { - pub fn new(params: WgpuBindGroup1EntryCollectionParams<'a>) -> Self { + impl<'a> WgpuBindGroup1Entries<'a> { + pub fn new(params: WgpuBindGroup1EntriesParams<'a>) -> Self { Self { ONE: wgpu::BindGroupEntry { binding: 0, @@ -239,9 +242,12 @@ pub mod main { }, } } - pub fn entries(self) -> [wgpu::BindGroupEntry<'a>; 1] { + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { [self.ONE] } + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() + } } #[derive(Debug)] pub struct WgpuBindGroup1(wgpu::BindGroup); @@ -271,10 +277,10 @@ pub mod main { } pub fn from_bindings( device: &wgpu::Device, - bindings: WgpuBindGroup1EntryCollection, + bindings: WgpuBindGroup1Entries, ) -> Self { let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.entries(); + let entries = bindings.as_array(); let bind_group = device .create_bind_group( &wgpu::BindGroupDescriptor { diff --git a/wgsl_bindgen/tests/output/bindgen_minimal.expected.rs b/wgsl_bindgen/tests/output/bindgen_minimal.expected.rs index d7256d4..7480568 100644 --- a/wgsl_bindgen/tests/output/bindgen_minimal.expected.rs +++ b/wgsl_bindgen/tests/output/bindgen_minimal.expected.rs @@ -82,15 +82,15 @@ pub mod minimal { pub mod bind_groups { use super::{_root, _root::*}; #[derive(Debug)] - pub struct WgpuBindGroup0EntryCollectionParams<'a> { + pub struct WgpuBindGroup0EntriesParams<'a> { pub uniform_buf: wgpu::BufferBinding<'a>, } #[derive(Clone, Debug)] - pub struct WgpuBindGroup0EntryCollection<'a> { + pub struct WgpuBindGroup0Entries<'a> { pub uniform_buf: wgpu::BindGroupEntry<'a>, } - impl<'a> WgpuBindGroup0EntryCollection<'a> { - pub fn new(params: WgpuBindGroup0EntryCollectionParams<'a>) -> Self { + impl<'a> WgpuBindGroup0Entries<'a> { + pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { Self { uniform_buf: wgpu::BindGroupEntry { binding: 0, @@ -98,9 +98,12 @@ pub mod minimal { }, } } - pub fn entries(self) -> [wgpu::BindGroupEntry<'a>; 1] { + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { [self.uniform_buf] } + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() + } } #[derive(Debug)] pub struct WgpuBindGroup0(wgpu::BindGroup); @@ -130,10 +133,10 @@ pub mod minimal { } pub fn from_bindings( device: &wgpu::Device, - bindings: WgpuBindGroup0EntryCollection, + bindings: WgpuBindGroup0Entries, ) -> Self { let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.entries(); + let entries = bindings.as_array(); let bind_group = device .create_bind_group( &wgpu::BindGroupDescriptor { diff --git a/wgsl_bindgen/tests/output/bindgen_padding.expected.rs b/wgsl_bindgen/tests/output/bindgen_padding.expected.rs index 38e462c..98f2164 100644 --- a/wgsl_bindgen/tests/output/bindgen_padding.expected.rs +++ b/wgsl_bindgen/tests/output/bindgen_padding.expected.rs @@ -85,15 +85,15 @@ pub mod padding { pub mod bind_groups { use super::{_root, _root::*}; #[derive(Debug)] - pub struct WgpuBindGroup0EntryCollectionParams<'a> { + pub struct WgpuBindGroup0EntriesParams<'a> { pub frame: wgpu::BufferBinding<'a>, } #[derive(Clone, Debug)] - pub struct WgpuBindGroup0EntryCollection<'a> { + pub struct WgpuBindGroup0Entries<'a> { pub frame: wgpu::BindGroupEntry<'a>, } - impl<'a> WgpuBindGroup0EntryCollection<'a> { - pub fn new(params: WgpuBindGroup0EntryCollectionParams<'a>) -> Self { + impl<'a> WgpuBindGroup0Entries<'a> { + pub fn new(params: WgpuBindGroup0EntriesParams<'a>) -> Self { Self { frame: wgpu::BindGroupEntry { binding: 0, @@ -101,9 +101,12 @@ pub mod padding { }, } } - pub fn entries(self) -> [wgpu::BindGroupEntry<'a>; 1] { + pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 1] { [self.frame] } + pub fn collect>>(self) -> B { + self.as_array().into_iter().collect() + } } #[derive(Debug)] pub struct WgpuBindGroup0(wgpu::BindGroup); @@ -135,10 +138,10 @@ pub mod padding { } pub fn from_bindings( device: &wgpu::Device, - bindings: WgpuBindGroup0EntryCollection, + bindings: WgpuBindGroup0Entries, ) -> Self { let bind_group_layout = Self::get_bind_group_layout(&device); - let entries = bindings.entries(); + let entries = bindings.as_array(); let bind_group = device .create_bind_group( &wgpu::BindGroupDescriptor {