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
impl Shader
sourcepub fn new(stage: ShaderStageFlags, spirv: impl ShaderCode) -> ShaderBuilder
pub fn new(stage: ShaderStageFlags, spirv: impl ShaderCode) -> ShaderBuilder
Specifies a shader with the given stage
and shader code values.
sourcepub fn new_any_hit(spirv: impl ShaderCode) -> ShaderBuilder
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.
sourcepub fn new_callable(spirv: impl ShaderCode) -> ShaderBuilder
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.
sourcepub fn new_closest_hit(spirv: impl ShaderCode) -> ShaderBuilder
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.
sourcepub fn new_compute(spirv: impl ShaderCode) -> ShaderBuilder
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.
sourcepub fn new_fragment(spirv: impl ShaderCode) -> ShaderBuilder
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.
sourcepub fn new_geometry(spirv: impl ShaderCode) -> ShaderBuilder
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.
sourcepub fn new_intersection(spirv: impl ShaderCode) -> ShaderBuilder
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.
sourcepub fn new_mesh(spirv: impl ShaderCode) -> ShaderBuilder
pub fn new_mesh(spirv: impl ShaderCode) -> ShaderBuilder
sourcepub fn new_miss(spirv: impl ShaderCode) -> ShaderBuilder
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.
sourcepub fn new_ray_gen(spirv: impl ShaderCode) -> ShaderBuilder
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.
sourcepub fn new_task(spirv: impl ShaderCode) -> ShaderBuilder
pub fn new_task(spirv: impl ShaderCode) -> ShaderBuilder
sourcepub fn new_tesselation_ctrl(spirv: impl ShaderCode) -> ShaderBuilder
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.
sourcepub fn new_tesselation_eval(spirv: impl ShaderCode) -> ShaderBuilder
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.
sourcepub fn new_vertex(spirv: impl ShaderCode) -> ShaderBuilder
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 From<ShaderBuilder> for Shader
impl From<ShaderBuilder> for Shader
source§fn from(shader: ShaderBuilder) -> Self
fn from(shader: ShaderBuilder) -> Self
Auto Trait Implementations§
impl Freeze for Shader
impl RefUnwindSafe for Shader
impl Send for Shader
impl Sync for Shader
impl Unpin for Shader
impl UnwindSafe for Shader
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.