#![allow(unused, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum ShaderEntry { Minimal, } impl ShaderEntry { pub fn create_pipeline_layout(&self, device: &wgpu::Device) -> wgpu::PipelineLayout { match self { Self::Minimal => minimal::create_pipeline_layout(device), } } pub fn create_shader_module_embed_source( &self, device: &wgpu::Device, ) -> wgpu::ShaderModule { match self { Self::Minimal => minimal::create_shader_module_embed_source(device), } } } mod _root { pub use super::*; } pub mod layout_asserts { use super::{_root, _root::*}; const WGSL_BASE_TYPE_ASSERTS: () = { assert!(std::mem::size_of::() == 16); assert!(std::mem::align_of::() == 16); assert!(std::mem::size_of::() == 16); assert!(std::mem::align_of::() == 16); assert!(std::mem::size_of::() == 48); assert!(std::mem::align_of::() == 16); assert!(std::mem::size_of::() == 64); assert!(std::mem::align_of::() == 16); }; const MINIMAL_UNIFORMS_ASSERTS: () = { assert!(std::mem::offset_of!(minimal::Uniforms, color) == 0); assert!(std::mem::offset_of!(minimal::Uniforms, width) == 16); assert!(std::mem::size_of::() == 256); }; } pub mod minimal { use super::{_root, _root::*}; #[repr(C, align(256))] #[derive(Debug, PartialEq, Clone, Copy)] pub struct Uniforms { /// size: 16, offset: 0x0, type: `vec4` pub color: glam::Vec4, /// size: 4, offset: 0x10, type: `f32` pub width: f32, pub _pad_width: [u8; 0x10 - core::mem::size_of::()], } impl Uniforms { pub const fn new(color: glam::Vec4, width: f32) -> Self { Self { color, width, _pad_width: [0; 0x10 - core::mem::size_of::()], } } } #[repr(C)] #[derive(Debug, PartialEq, Clone, Copy)] pub struct UniformsInit { pub color: glam::Vec4, pub width: f32, } impl UniformsInit { pub const fn build(&self) -> Uniforms { Uniforms { color: self.color, width: self.width, _pad_width: [0; 0x10 - core::mem::size_of::()], } } } impl From for Uniforms { fn from(data: UniformsInit) -> Self { data.build() } } #[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] } 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("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 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, &[]); } } #[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 fn set_bind_groups<'a>( pass: &mut wgpu::ComputePass<'a>, bind_group0: &'a WgpuBindGroup0, ) { bind_group0.set(pass); } pub mod compute { pub const MAIN_WORKGROUP_SIZE: [u32; 3] = [1, 1, 1]; pub fn create_main_pipeline_embed_source( device: &wgpu::Device, ) -> wgpu::ComputePipeline { let module = super::create_shader_module_embed_source(device); let layout = super::create_pipeline_layout(device); device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor { label: Some("Compute Pipeline main"), layout: Some(&layout), module: &module, entry_point: "main", compilation_options: Default::default(), cache: None, }) } } pub const ENTRY_MAIN: &str = "main"; #[derive(Debug)] pub struct WgpuPipelineLayout; impl WgpuPipelineLayout { pub fn bind_group_layout_entries( entries: [wgpu::BindGroupLayout; 1], ) -> [wgpu::BindGroupLayout; 1] { entries } } pub fn create_pipeline_layout(device: &wgpu::Device) -> wgpu::PipelineLayout { device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { label: Some("Minimal::PipelineLayout"), bind_group_layouts: &[&WgpuBindGroup0::get_bind_group_layout(device)], push_constant_ranges: &[], }) } pub fn create_shader_module_embed_source(device: &wgpu::Device) -> wgpu::ShaderModule { let source = std::borrow::Cow::Borrowed(SHADER_STRING); device.create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("minimal.wgsl"), source: wgpu::ShaderSource::Wgsl(source), }) } pub const SHADER_STRING: &'static str = r#" struct Uniforms { color: vec4, width: f32, } @group(0) @binding(0) var uniform_buf: Uniforms; @compute @workgroup_size(1, 1, 1) fn main(@builtin(global_invocation_id) id: vec3) { return; } "#; } pub mod bytemuck_impls { use super::{_root, _root::*}; unsafe impl bytemuck::Zeroable for minimal::Uniforms {} unsafe impl bytemuck::Pod for minimal::Uniforms {} }