[][src]Trait vulkano::pipeline::shader::SpecializationConstants

pub unsafe trait SpecializationConstants {
    fn descriptors() -> &'static [SpecializationMapEntry];
}

Trait for types that contain specialization data for shaders.

Shader modules can contain what is called specialization constants. They are the same as constants except that their values can be defined when you create a compute pipeline or a graphics pipeline. Doing so is done by passing a type that implements the SpecializationConstants trait and that stores the values in question. The descriptors() method of this trait indicates how to grab them.

Boolean specialization constants must be stored as 32bits integers, where 0 means false and any non-zero value means true. Integer and floating-point specialization constants are stored as their Rust equivalent.

This trait is implemented on () for shaders that don't have any specialization constant.

Note that it is the shader module that chooses which type that implements SpecializationConstants it is possible to pass when creating the pipeline, through the EntryPointAbstract trait. Therefore there is generally no point to implement this trait yourself, unless you are also writing your own implementation of EntryPointAbstract.

Example

use vulkano::pipeline::shader::SpecializationConstants;
use vulkano::pipeline::shader::SpecializationMapEntry;

#[repr(C)]      // `#[repr(C)]` guarantees that the struct has a specific layout
struct MySpecConstants {
    my_integer_constant: i32,
    a_boolean: u32,
    floating_point: f32,
}

unsafe impl SpecializationConstants for MySpecConstants {
    fn descriptors() -> &'static [SpecializationMapEntry] {
        static DESCRIPTORS: [SpecializationMapEntry; 3] = [
            SpecializationMapEntry {
                constant_id: 0,
                offset: 0,
                size: 4,
            },
            SpecializationMapEntry {
                constant_id: 1,
                offset: 4,
                size: 4,
            },
            SpecializationMapEntry {
                constant_id: 2,
                offset: 8,
                size: 4,
            },
        ];

        &DESCRIPTORS
    }
}

Safety

  • The SpecializationMapEntry returned must contain valid offsets and sizes.
  • The size of each SpecializationMapEntry must match the size of the corresponding constant (4 for booleans).

Required methods

fn descriptors() -> &'static [SpecializationMapEntry]

Returns descriptors of the struct's layout.

Loading content...

Implementations on Foreign Types

impl SpecializationConstants for ()[src]

Loading content...

Implementors

Loading content...