Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an example to patch bindgroup entry module path. #59

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sytherax
Copy link
Collaborator

No description provided.

Copy link

gooroo-dev bot commented Mar 21, 2025

Please double check the following review of the pull request:

Issues counts

🐞Mistake 🤪Typo 🚨Security 🚀Performance 💪Best Practices 📖Readability ❓Others
0 0 0 0 0 0 0

Changes in the diff

  • ➕ Added a new feature to override the bind group entry module path using .override_bind_group_entry_module_path.
  • ➖ Removed the WgpuBindGroup0Entries and WgpuBindGroup0 structs from the layouts module.
  • ➕ Added the WgpuBindGroup0Entries and WgpuBindGroup0 structs to a new bindings module.
  • 🛠️ Updated the WgpuBindGroups struct to use the bindings::WgpuBindGroup0 instead of WgpuBindGroup0.
  • 🛠️ Updated the pipeline layout descriptor to use bindings::WgpuBindGroup0::get_bind_group_layout.

Identified Issues

ID Type Details Severity Confidence
1 💪Best Practices Lack of documentation for the new bindings module and its structs. 🟡Low 🟡Low

Issue 1: Lack of documentation for the new bindings module and its structs

The new bindings module and its structs (WgpuBindGroup0EntriesParams, WgpuBindGroup0Entries, and WgpuBindGroup0) lack documentation comments. This can make it harder for other developers to understand the purpose and usage of these components.

File Path: wgsl_bindgen/tests/output/bindgen_layouts.expected.rs

Lines of Code: 987-1087

Suggested Fix

Add documentation comments to the bindings module and its structs to improve code readability and maintainability.

/// Module containing bindings for Wgpu bind groups.
pub mod bindings {
    use super::{_root, _root::*};

    /// Parameters for creating `WgpuBindGroup0Entries`.
    #[derive(Debug)]
    pub struct WgpuBindGroup0EntriesParams<'a> {
        pub color_texture: &'a wgpu::TextureView,
        pub color_sampler: &'a wgpu::Sampler,
    }

    /// Represents entries for a Wgpu bind group.
    #[derive(Clone, Debug)]
    pub struct WgpuBindGroup0Entries<'a> {
        pub color_texture: wgpu::BindGroupEntry<'a>,
        pub color_sampler: wgpu::BindGroupEntry<'a>,
    }

    impl<'a> WgpuBindGroup0Entries<'a> {
        /// Creates a new instance of `WgpuBindGroup0Entries`.
        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),
                },
            }
        }

        /// Returns the entries as an array.
        pub fn as_array(self) -> [wgpu::BindGroupEntry<'a>; 2] {
            [self.color_texture, self.color_sampler]
        }

        /// Collects the entries into a specified collection.
        pub fn collect<B: FromIterator<wgpu::BindGroupEntry<'a>>>(self) -> B {
            self.as_array().into_iter().collect()
        }
    }

    /// Represents a Wgpu bind group.
    #[derive(Debug)]
    pub struct WgpuBindGroup0(wgpu::BindGroup);

    impl WgpuBindGroup0 {
        /// Layout descriptor for the bind group.
        pub const LAYOUT_DESCRIPTOR: wgpu::BindGroupLayoutDescriptor<'static> = wgpu::BindGroupLayoutDescriptor {
            label: Some("Bindings::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_sampler"
                wgpu::BindGroupLayoutEntry {
                    binding: 1,
                    visibility: wgpu::ShaderStages::VERTEX_FRAGMENT,
                    ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
                    count: None,
                },
            ],
        };

        /// Retrieves the bind group layout from the device.
        pub fn get_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout {
            device.create_bind_group_layout(&Self::LAYOUT_DESCRIPTOR)
        }

        /// Creates a bind group from the specified bindings.
        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("Bindings::BindGroup0"),
                        layout: &bind_group_layout,
                        entries: &entries,
                    },
                );
            Self(bind_group)
        }

        /// Sets the bind group in the specified render pass.
        pub fn set(&self, pass: &mut impl SetBindGroup) {
            pass.set_bind_group(0, &self.0, &[]);
        }
    }
}

Explanation

The fix involves adding documentation comments to the bindings module and its structs. This helps other developers understand the purpose and usage of these components, improving code readability and maintainability.

Missing Tests

To ensure the new feature works as expected, consider adding the following tests:

  1. Test for override_bind_group_entry_module_path: Verify that the bind group entries are correctly overridden to use the specified module path.

  2. Test for bindings::WgpuBindGroup0Entries: Ensure that the new, as_array, and collect methods function correctly.

  3. Test for bindings::WgpuBindGroup0: Validate that the get_bind_group_layout, from_bindings, and set methods operate as intended.

Summon me to re-review when updated! Yours, Gooroo.dev
React or reply to keep the conversation going!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant