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: StringThe 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: SpirvBinaryShader 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.
stage: ShaderStageFlagsThe shader stage this structure applies to.
Implementations§
Source§impl Shader
impl Shader
Sourcepub fn new(
stage: ShaderStageFlags,
spirv: impl Into<SpirvBinary>,
) -> ShaderBuilder
pub fn new( stage: ShaderStageFlags, spirv: impl Into<SpirvBinary>, ) -> ShaderBuilder
Specifies a shader with the given stage and shader code.
Sourcepub fn new_any_hit(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
pub fn new_any_hit(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
Sourcepub fn try_new_any_hit(
spirv: impl Into<SpirvBinary>,
) -> Result<Shader, DriverError>
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.
Sourcepub fn new_callable(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
pub fn new_callable(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
Sourcepub fn try_new_callable(
spirv: impl Into<SpirvBinary>,
) -> Result<Shader, DriverError>
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.
Sourcepub fn new_closest_hit(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
pub fn new_closest_hit(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
Sourcepub fn try_new_closest_hit(
spirv: impl Into<SpirvBinary>,
) -> Result<Shader, DriverError>
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.
Sourcepub fn new_compute(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
pub fn new_compute(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
Sourcepub fn try_new_compute(
spirv: impl Into<SpirvBinary>,
) -> Result<Shader, DriverError>
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.
Sourcepub fn new_fragment(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
pub fn new_fragment(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
Sourcepub fn try_new_fragment(
spirv: impl Into<SpirvBinary>,
) -> Result<Shader, DriverError>
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.
Sourcepub fn new_geometry(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
pub fn new_geometry(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
Sourcepub fn try_new_geometry(
spirv: impl Into<SpirvBinary>,
) -> Result<Shader, DriverError>
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.
Sourcepub fn new_intersection(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
pub fn new_intersection(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
Sourcepub fn try_new_intersection(
spirv: impl Into<SpirvBinary>,
) -> Result<Shader, DriverError>
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.
Sourcepub fn new_mesh(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
pub fn new_mesh(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
Sourcepub fn try_new_mesh(
spirv: impl Into<SpirvBinary>,
) -> Result<Shader, DriverError>
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.
Sourcepub fn new_miss(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
pub fn new_miss(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
Sourcepub fn try_new_miss(
spirv: impl Into<SpirvBinary>,
) -> Result<Shader, DriverError>
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.
Sourcepub fn new_ray_gen(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
pub fn new_ray_gen(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
Sourcepub fn try_new_ray_gen(
spirv: impl Into<SpirvBinary>,
) -> Result<Shader, DriverError>
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.
Sourcepub fn new_task(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
pub fn new_task(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
Sourcepub fn try_new_task(
spirv: impl Into<SpirvBinary>,
) -> Result<Shader, DriverError>
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.
Sourcepub fn new_tessellation_ctrl(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
pub fn new_tessellation_ctrl(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
Sourcepub fn try_new_tessellation_ctrl(
spirv: impl Into<SpirvBinary>,
) -> Result<Shader, DriverError>
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.
Sourcepub fn new_tessellation_eval(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
pub fn new_tessellation_eval(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
Sourcepub fn try_new_tessellation_eval(
spirv: impl Into<SpirvBinary>,
) -> Result<Shader, DriverError>
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.
Sourcepub fn new_vertex(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
pub fn new_vertex(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
Sourcepub fn try_new_vertex(
spirv: impl Into<SpirvBinary>,
) -> Result<Shader, DriverError>
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.
Sourcepub fn builder() -> ShaderBuilder
pub fn builder() -> ShaderBuilder
Creates a default ShaderBuilder.
Sourcepub fn from_spirv(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
pub fn from_spirv(spirv: impl Into<SpirvBinary>) -> ShaderBuilder
Specifies a shader with the given shader code.