Skip to main content

MewPipeline

Trait MewPipeline 

Source
pub trait MewPipeline {
    type BindGroupSet;
    type BindGroupArray<T>;
    type VertexArray<T>;
    type FragmentArray<T>;

    // Required methods
    fn new(pipeline: RenderPipeline) -> Self;
    fn bind_group_layout_types_array(    ) -> Self::BindGroupArray<(TypeId, BindGroupLayoutDescriptor<'static>)>;
    fn map_bind_group_array<'a, A: 'a, B: 'a, F: FnMut(&'a A) -> B>(
        array: &'a Self::BindGroupArray<A>,
        f: F,
    ) -> Self::BindGroupArray<B>;
    fn layout_desc<'a, 'b>(
        bind_group_layouts: &'a Self::BindGroupArray<&'b BindGroupLayout>,
    ) -> PipelineLayoutDescriptor<'a>;
    fn fragment_targets<'a>(
        surface_fmt: TextureFormat,
    ) -> Self::FragmentArray<Option<ColorTargetState>>;
    fn pipeline_desc<'a>(
        layout: &'a MewPipelineLayout<Self>,
        shader: &'a ShaderModule,
        vertex_entry: Option<&'a str>,
        fragment_entry: Option<&'a str>,
        fragment_targets: &'a Self::FragmentArray<Option<ColorTargetState>>,
    ) -> RenderPipelineDescriptor<'a>;
}
Expand description

Trait for pipeline wrapper types, to get layouts and descriptors about the inner pipeline.

The number of internal bind groups must be defined in the generic parameter, because associated consts are “uNsTAbLe”, apparently.

Ideally, avoid using this directly - it’s horribly designed, so just look away and use the pipeline macro.

Required Associated Types§

Source

type BindGroupSet

A tuple of the pipeline’s internal bind groups (max of 4).

Source

type BindGroupArray<T>

A generic array the length of the number of bind groups (literally [T; N]).

Source

type VertexArray<T>

A generic array the length of the number of vertex types (literally [T; N]).

Source

type FragmentArray<T>

A generic array the length of the number of fragment targets (literally [T; N]).

Required Methods§

Source

fn new(pipeline: RenderPipeline) -> Self

Build this pipeline type from a wgpu::RenderPipeline.

Source

fn bind_group_layout_types_array() -> Self::BindGroupArray<(TypeId, BindGroupLayoutDescriptor<'static>)>

Get an array of the internal bind groups’ type IDs & wgpu::BindGroupLayoutDescriptors.

Source

fn map_bind_group_array<'a, A: 'a, B: 'a, F: FnMut(&'a A) -> B>( array: &'a Self::BindGroupArray<A>, f: F, ) -> Self::BindGroupArray<B>

Run a closure on each element in an array the lenth of the number of bind groups (Self::BindGroupArray).

This is only necessary because of a limitation with Rust’s generics in traits. Take a look at the above Self::BindGroupArray, Self::VertexArray, & Self::FragmentArray - the compiler has no way of knowing those are just supposed to be primitive arrays with a generic const length. Ideally I’d just specify a const usize in the trait, but nooOOoo you’re not allowed to do that, so I have to make do with this.

Primitive arrays also aren’t distinguishable by any sort of trait to narrow down the type (really all I need is a std::iter::Map), but I don’t want to import any bloat libraries & writing something is probably overkill for how I’m using it (purely internally).

Source

fn layout_desc<'a, 'b>( bind_group_layouts: &'a Self::BindGroupArray<&'b BindGroupLayout>, ) -> PipelineLayoutDescriptor<'a>

Get the wgpu::PipelineLayoutDescriptor to build the pipeline. Requires an array of references of its internal bind groups’ &BindGroupLayouts which are mappable from Self::bind_group_layout_types_array.
Need to do it separately like this because const fns in traits are “uNsTAbLe”, apparently, and lifetimes exist.

Source

fn fragment_targets<'a>( surface_fmt: TextureFormat, ) -> Self::FragmentArray<Option<ColorTargetState>>

Get an array of Option<wgpu::ColorTargetState>s.

If a specific colour format was specified for this state in the macro, it will only be Some if the passed surface wgpu::TextureFormat matches. If it was set to ANY, then for that entry it will always return Some with the passed-in format.

tbh I’m not sure if this is how it’s intended to be used but yolo

Source

fn pipeline_desc<'a>( layout: &'a MewPipelineLayout<Self>, shader: &'a ShaderModule, vertex_entry: Option<&'a str>, fragment_entry: Option<&'a str>, fragment_targets: &'a Self::FragmentArray<Option<ColorTargetState>>, ) -> RenderPipelineDescriptor<'a>

Get a wgpu::RenderPipelineDescriptor from a layout for this specific type of pipeline, plus a shader and the fragment targets array from Self::fragment_targets.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§