Struct screen_13::driver::shader::Shader

source ·
pub struct Shader {
    pub entry_name: String,
    pub specialization_info: Option<SpecializationInfo>,
    pub spirv: Vec<u8>,
    pub stage: ShaderStageFlags,
    /* private fields */
}
Expand description

Describes a shader program which runs on some pipeline stage.

Fields§

§entry_name: String

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

The default value is main.

§specialization_info: Option<SpecializationInfo>

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()
    ));
§spirv: Vec<u8>

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.

§stage: ShaderStageFlags

The shader stage this structure applies to.

Implementations§

source§

impl Shader

source

pub fn new(stage: ShaderStageFlags, spirv: impl ShaderCode) -> ShaderBuilder

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

source

pub fn new_any_hit(spirv: impl ShaderCode) -> ShaderBuilder

Creates a new ray trace shader.

§Panics

If the shader code is invalid or not a multiple of four bytes in length.

source

pub fn new_callable(spirv: impl ShaderCode) -> ShaderBuilder

Creates a new ray trace shader.

§Panics

If the shader code is invalid or not a multiple of four bytes in length.

source

pub fn new_closest_hit(spirv: impl ShaderCode) -> ShaderBuilder

Creates a new ray trace shader.

§Panics

If the shader code is invalid or not a multiple of four bytes in length.

source

pub fn new_compute(spirv: impl ShaderCode) -> ShaderBuilder

Creates a new compute shader.

§Panics

If the shader code is invalid or not a multiple of four bytes in length.

source

pub fn new_fragment(spirv: impl ShaderCode) -> ShaderBuilder

Creates a new fragment shader.

§Panics

If the shader code is invalid or not a multiple of four bytes in length.

source

pub fn new_geometry(spirv: impl ShaderCode) -> ShaderBuilder

Creates a new geometry shader.

§Panics

If the shader code is invalid or not a multiple of four bytes in length.

source

pub fn new_intersection(spirv: impl ShaderCode) -> ShaderBuilder

Creates a new ray trace shader.

§Panics

If the shader code is invalid or not a multiple of four bytes in length.

source

pub fn new_mesh(spirv: impl ShaderCode) -> ShaderBuilder

Creates a new mesh shader.

§Panics

If the shader code is invalid.

source

pub fn new_miss(spirv: impl ShaderCode) -> ShaderBuilder

Creates a new ray trace shader.

§Panics

If the shader code is invalid or not a multiple of four bytes in length.

source

pub fn new_ray_gen(spirv: impl ShaderCode) -> ShaderBuilder

Creates a new ray trace shader.

§Panics

If the shader code is invalid or not a multiple of four bytes in length.

source

pub fn new_task(spirv: impl ShaderCode) -> ShaderBuilder

Creates a new mesh task shader.

§Panics

If the shader code is invalid.

source

pub fn new_tesselation_ctrl(spirv: impl ShaderCode) -> ShaderBuilder

Creates a new tesselation control shader.

§Panics

If the shader code is invalid or not a multiple of four bytes in length.

source

pub fn new_tesselation_eval(spirv: impl ShaderCode) -> ShaderBuilder

Creates a new tesselation evaluation shader.

§Panics

If the shader code is invalid or not a multiple of four bytes in length.

source

pub fn new_vertex(spirv: impl ShaderCode) -> ShaderBuilder

Creates a new vertex shader.

§Panics

If the shader code is invalid or not a multiple of four bytes in length.

Trait Implementations§

source§

impl Clone for Shader

source§

fn clone(&self) -> Shader

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 Shader

source§

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

Formats the value using the given formatter. 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
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> 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.