pub struct ResourceBuilder<'a> {
pub bindings: Vec<Binding<'a>>,
}Expand description
Collects resource bindings for automatic layout and bind group generation.
After populating the builder via add_* methods, use
generate_layout_entries to produce
wgpu::BindGroupLayoutEntry arrays and
generate_wgsl for WGSL declarations.
Fields§
§bindings: Vec<Binding<'a>>Implementations§
Source§impl<'a> ResourceBuilder<'a>
impl<'a> ResourceBuilder<'a>
pub fn new() -> ResourceBuilder<'a>
pub fn add_uniform_buffer( &mut self, name: &'a str, buffer: &BufferRef, data: Option<&'a [u8]>, visibility: ShaderStages, has_dynamic_offset: bool, min_binding_size: Option<NonZero<u64>>, struct_name: Option<WgslStructName>, )
pub fn add_uniform<T>(
&mut self,
name: &'a str,
cpu_buffer: &'a CpuBuffer<T>,
visibility: ShaderStages,
)where
T: WgslStruct + GpuData,
pub fn add_dynamic_uniform<T>(
&mut self,
name: &'a str,
buffer_ref: &BufferRef,
data: Option<&'a [u8]>,
min_binding_size: NonZero<u64>,
visibility: ShaderStages,
)where
T: WgslStruct,
Sourcepub fn add_texture(
&mut self,
name: &'a str,
source: Option<impl Into<TextureSource>>,
sample_type: TextureSampleType,
view_dimension: TextureViewDimension,
visibility: ShaderStages,
)
pub fn add_texture( &mut self, name: &'a str, source: Option<impl Into<TextureSource>>, sample_type: TextureSampleType, view_dimension: TextureViewDimension, visibility: ShaderStages, )
Adds a texture binding with an auto-paired sampler.
This produces two GPU binding slots: the texture view at the
current index and the sampler at the next index. The sampler
binding type is inferred from sample_type (depth → comparison,
otherwise → filtering).
pub fn add_storage_buffer( &mut self, name: &'a str, buffer: &BufferRef, data: Option<&'a [u8]>, read_only: bool, visibility: ShaderStages, struct_name: Option<WgslStructName>, )
pub fn add_storage<T>(
&mut self,
name: &'a str,
buffer: &BufferRef,
data: Option<&'a [u8]>,
read_only: bool,
visibility: ShaderStages,
)where
T: WgslStruct,
Sourcepub fn generate_layout_entries(&self) -> Vec<BindGroupLayoutEntry>
pub fn generate_layout_entries(&self) -> Vec<BindGroupLayoutEntry>
Generates wgpu::BindGroupLayoutEntry array from collected bindings.
Each buffer binding produces one layout entry. Each texture binding produces two entries (texture view + auto-paired sampler).
Sourcepub fn generate_wgsl(&self, group_index: u32) -> String
pub fn generate_wgsl(&self, group_index: u32) -> String
Generates WGSL binding declarations and struct definitions.
Buffer bindings produce a single var<uniform> or var<storage>
declaration. Texture bindings produce both a var t_ texture
declaration and a var s_ sampler declaration.
Trait Implementations§
Source§impl Default for ResourceBuilder<'_>
impl Default for ResourceBuilder<'_>
Source§fn default() -> ResourceBuilder<'_>
fn default() -> ResourceBuilder<'_>
Auto Trait Implementations§
impl<'a> Freeze for ResourceBuilder<'a>
impl<'a> RefUnwindSafe for ResourceBuilder<'a>
impl<'a> Send for ResourceBuilder<'a>
impl<'a> Sync for ResourceBuilder<'a>
impl<'a> Unpin for ResourceBuilder<'a>
impl<'a> UnsafeUnpin for ResourceBuilder<'a>
impl<'a> UnwindSafe for ResourceBuilder<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().