[][src]Trait web_glitz::pipeline::resources::Resources

pub unsafe trait Resources {
    type Bindings: Borrow<[BindingDescriptor]> + 'static;
    fn confirm_slot_bindings<C>(
        confirmer: &C,
        descriptors: &[ResourceSlotDescriptor]
    ) -> Result<(), IncompatibleResources>
    where
        C: SlotBindingConfirmer
;
fn into_bind_group(
        self,
        context: &mut BindGroupEncodingContext
    ) -> BindGroupEncoding<Self::Bindings>; }

Provides a group of resources (uniform block buffers, sampled textures) that may be bound to a pipeline, such that the pipeline may access these resources during execution.

Usage

The programmable stages of a pipeline may require access to various resources during pipeline execution. To this end, the code for a programmable stage may define slots for such resources (e.g. uniform blocks, texture samplers):

#version 300 es

uniform sampler2D some_texture;

uniform sampler2DArray some_other_texture;

layout(std140) uniform SomeUniformBlock {
    vec4 some_uniform;
    mat4 some_other_uniform;
};

main () {
    ...
}

This trait may be safely derived automatically on a type to define how specific resource instances should be bound to the pipeline before it is executed:

use web_glitz::image::texture_2d::FloatSampledTexture2D;
use web_glitz::image::texture_2d_array::FloatSampledTexture2DArray;
use web_glitz::buffer::Buffer;
use web_glitz::std140;
use web_glitz::std140::repr_std140;

#[derive(web_glitz::derive::Resources)]
struct MyResources<'a> {
    #[texture_resource(binding=0)]
    some_texture: FloatSampledTexture2D<'a>,

    #[texture_resource(binding=1, name="some_other_texture")]
    second_texture: FloatSampledTexture2DArray<'a>,

    #[buffer_resource(binding=0, name="SomeUniformBlock")]
    some_uniform_block: &'a Buffer<SomeUniformBlock>
}

#[repr_std140]
#[derive(web_glitz::derive::InterfaceBlock)]
struct SomeUniformBlock {
    some_uniform: std140::vec4,
    some_other_uniform: std140::mat4x4
}

Any field marked with a #[texture_resource(...)] attribute defines a texture binding; any field marked with a #[buffer_resource(...)] attribute defines a buffer binding.

A #[texture_resource(...)] attribute must always declare a binding index; this should be a positive integer that is smaller than the [RenderingContext::max_texture_resource_index] for the [RenderingContext] with which you intend to use the Resources (hardware dependent, at least 32). If the field name does not match the resource name used in the shader code, then the attribute should also declare a name with a string that does match the resource name used in the shader code; if the field name does match the name used in the shader, then name may be omitted. The field's type must implement TextureResource; a #[texture_resource(...)] field that does not implement TextureResource will result in a compilation error. If multiple #[texture_resource(...)] fields are defined, then all fields must declare a unique binding index; 2 or more #[texture_resource(...)] fields with the same binding index will result in a compilation error.

A #[buffer_resource(...)] attribute must always declare a binding index; this should be a positive integer that is smaller than the [RenderingContext::max_buffer_resource_index] for the [RenderingContext] with which you intend to use the Resources (hardware dependent, at least 24). If the field name does not match the block name used in the shader code, then the attribute should also declare a name with a string that does match the block name used in the shader code; if the field name does match the name used in the shader, then name may be omitted. The field's type must implement BufferResource; a #[buffer_resource(...)] field that does not implement BufferResource will result in a compilation error. The type contained in the resource must implement InterfaceBlock and its memory layout should match the layout expected by the pipeline (see InterfaceBlock and [web_glitz::std140]). If multiple #[buffer_resource(...)] fields are defined, then all fields must declare a unique binding index; 2 or more #[buffer_resource(...)] fields with the same binding index will result in a compilation error.

Note that while binding indices must be internally unique amongst #[texture_resource(...)] fields and must be internally unique amongst #[buffer_resource(...)] fields, both binding types use a separate set of bindings: a #[texture_resource(...)] field may declare the same binding index as a #[buffer_resource(...)].

A [GraphicsPipelineDescriptor] must declare the Resources type that may be used with pipelines created from it, see [GraphicsPipelineDescriptorBuilder::resources]. The compatibility of the resource bindings declared this type will be checked against the pipeline's resource slots when the pipeline is created, see [RenderingContext::create_graphics_pipeline].

Associated Types

Loading content...

Required methods

fn confirm_slot_bindings<C>(
    confirmer: &C,
    descriptors: &[ResourceSlotDescriptor]
) -> Result<(), IncompatibleResources> where
    C: SlotBindingConfirmer

Confirms that the BindGroupEncoding for these Resources as created by [encode_bind_group] will match a pipeline's resource slots as describe by the [descriptors], using the [confirmer].

If this function does not return an error, then calling [encode_bind_group] for any instance of the type will return a BindGroupEncoding that can be safely used with any pipeline described by the [descriptors].

fn into_bind_group(
    self,
    context: &mut BindGroupEncodingContext
) -> BindGroupEncoding<Self::Bindings>

Encodes these Resources into a bind group, so that they can be bound to specific binding indices efficiently before a pipeline is executed.

Loading content...

Implementations on Foreign Types

impl Resources for ()[src]

type Bindings = [BindingDescriptor; 0]

Loading content...

Implementors

Loading content...