pub struct ShaderBuilder { /* private fields */ }
Expand description

Builder for Shader.

Implementations§

source§

impl ShaderBuilder

source

pub fn entry_name(self, value: String) -> Self

The name of the entry point which will be executed by this shader.

The default value is main.

source

pub fn specialization_info(self, value: SpecializationInfo) -> Self

Data about Vulkan specialization constants.

§Examples

Basic usage (GLSL):

#version 460 core

// Defaults to 6 if not set using Shader specialization_info!
layout(constant_id = 0) const uint MY_COUNT = 6;

layout(set = 0, binding = 0) uniform sampler2D my_samplers[MY_COUNT];

void main()
{
    // Code uses MY_COUNT number of my_samplers here
}
// We instead specify 42 for MY_COUNT:
let shader = Shader::new_fragment(my_shader_code.as_slice())
    .specialization_info(SpecializationInfo::new(
        [vk::SpecializationMapEntry {
            constant_id: 0,
            offset: 0,
            size: 4,
        }],
        42u32.to_ne_bytes()
    ));
source

pub fn spirv(self, value: Vec<u8>) -> Self

Shader code.

Although SPIR-V code is specified as u32 values, this field uses u8 in order to make loading from file simpler. You should always have a SPIR-V code length which is a multiple of four bytes, or a panic will happen during pipeline creation.

source

pub fn stage(self, value: ShaderStageFlags) -> Self

The shader stage this structure applies to.

source§

impl ShaderBuilder

source

pub fn new(stage: ShaderStageFlags, spirv: Vec<u8>) -> Self

Specifies a shader with the given stage and shader code values.

source

pub fn build(self) -> Shader

Builds a new Shader.

source

pub fn image_sampler( self, binding: impl Into<DescriptorBinding>, info: impl Into<SamplerInfo> ) -> Self

Specifies a manually-defined image sampler.

Sampled images, by default, use reflection to automatically assign image samplers. Each sampled image may use a suffix such as _llr or _nne for common linear/linear repeat or nearest/nearest clamp-to-edge samplers, respectively.

See the main documentation for more information about automatic image samplers.

Descriptor bindings may be specified as (1, 2) for descriptor set index 1 and binding index 2, or if the descriptor set index is 0 simply specify 2 for the same case.

NOTE: When defining image samplers which are used in multiple stages of a single pipeline you must only call this function on one of the shader stages, it does not matter which one.

§Panics

Panics if two shader stages of the same pipeline define individual calls to image_sampler.

source

pub fn vertex_input( self, bindings: &[VertexInputBindingDescription], attributes: &[VertexInputAttributeDescription] ) -> Self

Specifies a manually-defined vertex input layout.

The vertex input layout, by default, uses reflection to automatically define vertex binding and attribute descriptions. Each vertex location is inferred to have 32-bit channels and be tightly packed in the vertex buffer. In this mode, a location with _ibind_0 or _vbind3 suffixes is inferred to use instance-rate on vertex buffer binding 0 or vertex rate on binding 3, respectively.

See the main documentation for more information about automatic vertex input layout.

Trait Implementations§

source§

impl Clone for ShaderBuilder

source§

fn clone(&self) -> ShaderBuilder

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ShaderBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for ShaderBuilder

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl From<ShaderBuilder> for Shader

source§

fn from(shader: ShaderBuilder) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more