Skip to main content

Shader

Struct Shader 

Source
pub struct Shader {
    pub entry_name: String,
    pub specialization: Option<SpecializationMap>,
    pub spirv: SpirvBinary,
    pub stage: ShaderStageFlags,
    /* private fields */
}
Expand description

Describes a shader program which runs on a pipeline stage.

See VkShaderModuleCreateInfo and VkPipelineShaderStageCreateInfo.

Fields§

§entry_name: String

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

The default value is main.

§specialization: Option<SpecializationMap>

Data about Vulkan specialization constants.

See VkSpecializationInfo.

§Examples

Basic usage (GLSL):

#version 460 core
#pragma shader_stage(compute)

// Defaults to 6 if not set using Shader specialization!
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(
        SpecializationMap::new(42u32.to_ne_bytes())
            .constant(0, 0, 4)
    );
§spirv: SpirvBinary

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 an error will be returned during pipeline creation.

See VkShaderModuleCreateInfo.

§stage: ShaderStageFlags

The shader stage this structure applies to.

See VkShaderStageFlagBits.

Implementations§

Source§

impl Shader

Source

pub fn new( stage: ShaderStageFlags, spirv: impl Into<SpirvBinary>, ) -> ShaderBuilder

Specifies a shader with the given stage and shader code.

See VkShaderModuleCreateInfo.

Source

pub fn new_any_hit(spirv: impl Into<SpirvBinary>) -> ShaderBuilder

Creates a new ray tracing any-hit shader.

§Panics

Panics if the shader code is invalid. Use try_build on the returned builder for a fallible path.

Source

pub fn try_new_any_hit( spirv: impl Into<SpirvBinary>, ) -> Result<Shader, DriverError>

Creates a Creates a new ray tracing any-hit shader. , returning an error if the SPIR-V is invalid.

Source

pub fn new_callable(spirv: impl Into<SpirvBinary>) -> ShaderBuilder

Creates a new ray tracing callable shader.

§Panics

Panics if the shader code is invalid. Use try_build on the returned builder for a fallible path.

Source

pub fn try_new_callable( spirv: impl Into<SpirvBinary>, ) -> Result<Shader, DriverError>

Creates a Creates a new ray tracing callable shader. , returning an error if the SPIR-V is invalid.

Source

pub fn new_closest_hit(spirv: impl Into<SpirvBinary>) -> ShaderBuilder

Creates a new ray tracing closest-hit shader.

§Panics

Panics if the shader code is invalid. Use try_build on the returned builder for a fallible path.

Source

pub fn try_new_closest_hit( spirv: impl Into<SpirvBinary>, ) -> Result<Shader, DriverError>

Creates a Creates a new ray tracing closest-hit shader. , returning an error if the SPIR-V is invalid.

Source

pub fn new_compute(spirv: impl Into<SpirvBinary>) -> ShaderBuilder

Creates a new compute shader.

§Panics

Panics if the shader code is invalid. Use try_build on the returned builder for a fallible path.

Source

pub fn try_new_compute( spirv: impl Into<SpirvBinary>, ) -> Result<Shader, DriverError>

Creates a Creates a new compute shader. , returning an error if the SPIR-V is invalid.

Source

pub fn new_fragment(spirv: impl Into<SpirvBinary>) -> ShaderBuilder

Creates a new fragment shader.

§Panics

Panics if the shader code is invalid. Use try_build on the returned builder for a fallible path.

Source

pub fn try_new_fragment( spirv: impl Into<SpirvBinary>, ) -> Result<Shader, DriverError>

Creates a Creates a new fragment shader. , returning an error if the SPIR-V is invalid.

Source

pub fn new_geometry(spirv: impl Into<SpirvBinary>) -> ShaderBuilder

Creates a new geometry shader.

§Panics

Panics if the shader code is invalid. Use try_build on the returned builder for a fallible path.

Source

pub fn try_new_geometry( spirv: impl Into<SpirvBinary>, ) -> Result<Shader, DriverError>

Creates a Creates a new geometry shader. , returning an error if the SPIR-V is invalid.

Source

pub fn new_intersection(spirv: impl Into<SpirvBinary>) -> ShaderBuilder

Creates a new ray tracing intersection shader.

§Panics

Panics if the shader code is invalid. Use try_build on the returned builder for a fallible path.

Source

pub fn try_new_intersection( spirv: impl Into<SpirvBinary>, ) -> Result<Shader, DriverError>

Creates a Creates a new ray tracing intersection shader. , returning an error if the SPIR-V is invalid.

Source

pub fn new_mesh(spirv: impl Into<SpirvBinary>) -> ShaderBuilder

Creates a new mesh shader.

§Panics

Panics if the shader code is invalid. Use try_build on the returned builder for a fallible path.

Source

pub fn try_new_mesh( spirv: impl Into<SpirvBinary>, ) -> Result<Shader, DriverError>

Creates a Creates a new mesh shader. , returning an error if the SPIR-V is invalid.

Source

pub fn new_miss(spirv: impl Into<SpirvBinary>) -> ShaderBuilder

Creates a new ray tracing miss shader.

§Panics

Panics if the shader code is invalid. Use try_build on the returned builder for a fallible path.

Source

pub fn try_new_miss( spirv: impl Into<SpirvBinary>, ) -> Result<Shader, DriverError>

Creates a Creates a new ray tracing miss shader. , returning an error if the SPIR-V is invalid.

Source

pub fn new_ray_gen(spirv: impl Into<SpirvBinary>) -> ShaderBuilder

Creates a new ray tracing ray-generation shader.

§Panics

Panics if the shader code is invalid. Use try_build on the returned builder for a fallible path.

Source

pub fn try_new_ray_gen( spirv: impl Into<SpirvBinary>, ) -> Result<Shader, DriverError>

Creates a Creates a new ray tracing ray-generation shader. , returning an error if the SPIR-V is invalid.

Source

pub fn new_task(spirv: impl Into<SpirvBinary>) -> ShaderBuilder

Creates a new task shader.

§Panics

Panics if the shader code is invalid. Use try_build on the returned builder for a fallible path.

Source

pub fn try_new_task( spirv: impl Into<SpirvBinary>, ) -> Result<Shader, DriverError>

Creates a Creates a new task shader. , returning an error if the SPIR-V is invalid.

Source

pub fn new_tessellation_ctrl(spirv: impl Into<SpirvBinary>) -> ShaderBuilder

Creates a new tessellation control shader.

§Panics

Panics if the shader code is invalid. Use try_build on the returned builder for a fallible path.

Source

pub fn try_new_tessellation_ctrl( spirv: impl Into<SpirvBinary>, ) -> Result<Shader, DriverError>

Creates a Creates a new tessellation control shader. , returning an error if the SPIR-V is invalid.

Source

pub fn new_tessellation_eval(spirv: impl Into<SpirvBinary>) -> ShaderBuilder

Creates a new tessellation evaluation shader.

§Panics

Panics if the shader code is invalid. Use try_build on the returned builder for a fallible path.

Source

pub fn try_new_tessellation_eval( spirv: impl Into<SpirvBinary>, ) -> Result<Shader, DriverError>

Creates a Creates a new tessellation evaluation shader. , returning an error if the SPIR-V is invalid.

Source

pub fn new_vertex(spirv: impl Into<SpirvBinary>) -> ShaderBuilder

Creates a new vertex shader.

§Panics

Panics if the shader code is invalid. Use try_build on the returned builder for a fallible path.

Source

pub fn try_new_vertex( spirv: impl Into<SpirvBinary>, ) -> Result<Shader, DriverError>

Creates a Creates a new vertex shader. , returning an error if the SPIR-V is invalid.

Source

pub fn builder() -> ShaderBuilder

Creates a default ShaderBuilder.

Source

pub fn from_spirv(spirv: impl Into<SpirvBinary>) -> ShaderBuilder

Specifies a shader with the given shader code.

See VkShaderModuleCreateInfo.

Trait Implementations§

Source§

impl Clone for Shader

Source§

fn clone(&self) -> Shader

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Shader

Source§

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

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

impl TryFrom<&[u8]> for Shader

Source§

type Error = DriverError

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

fn try_from(spirv: &[u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&[u32]> for Shader

Source§

type Error = DriverError

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

fn try_from(spirv: &[u32]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<ShaderBuilder> for Shader

Source§

type Error = DriverError

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

fn try_from(shader: ShaderBuilder) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Vec<u8>> for Shader

Source§

type Error = DriverError

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

fn try_from(spirv: Vec<u8>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Vec<u32>> for Shader

Source§

type Error = DriverError

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

fn try_from(spirv: Vec<u32>) -> Result<Self, Self::Error>

Performs the conversion.

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
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

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>,

Source§

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>,

Source§

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.