1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//! Encompasses hardware state required to execute a draw command

use Resources;
use descriptor::DescriptorSetLayout;
use shader::Type;
use std::fmt;

/// The graphics pipeline has no methods of its own, instead if is referenced by draw commands.
pub trait GraphicsPipeline {

}

/// The pipeline is constructed from a 'template' that contains each shader stage
pub struct GraphicsPipelineInfo<'r: 'b, 'b, R: 'r + Resources<'r>> {
    pub input_assembler: InputAssembler,
    pub vertex_shader: PipelineShader<'r, 'b, R>,
    pub fragment_shader: PipelineShader<'r, 'b, R>
}

/// Gathers
pub struct InputAssembler {
    pub topology: Topology
}

pub struct PipelineShader<'r: 'b, 'b, R: 'r + Resources<'r>> {
    pub shader: &'b R::Shader,
    pub descriptor_layout: Vec<DescriptorSetLayout>
}

#[derive(Debug, Copy, Clone)]
/// A topology (or primitive) is a type of shape that can be rendered
pub enum Topology {
    Points,
    Lines,
    LineStrip,
    LineLoop,
    Triangles,
    TriangleStrip,
    TriangleFan
}

/// The pipeline can fail to be created
#[derive(PartialEq, Eq, Clone)]
pub enum GraphicsPipelineCreationError {
    /// The shader program failed to link
    ProgramLinkError(LinkError),

    /// There was a different number of descriptor set layouts between the different shaders.
    /// All shaders in a pipeline must have the same number of descriptor set layouts
    DescriptorSetLayoutCountMismatch(Type, usize, Type, usize),

    /// There was a different number of descriptor slots between the different shaders.
    /// All shaders in a pipeline must have same size descriptor set layout
    DescriptorSetLayoutSlotCountMismatch(usize, Type, usize, Type, usize),

    /// Sometimes the shader entity index can't be found inside the shader source code.
    ShaderEntityIndexNotFound(Type, u32),

    /// There was a miscellaneous error while converting the `DescriptorSet`
    /// system to a traditional binding model such as that of OpenGL
    DescriptorSetToTraditionalBindingConversionError(String)
}

impl fmt::Debug for GraphicsPipelineCreationError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            &GraphicsPipelineCreationError::ProgramLinkError(ref error) => write!(f, "ProgramLinkError({:?})", error),
            &GraphicsPipelineCreationError::DescriptorSetLayoutCountMismatch(first_shader, first, this_shader, this) => write!(f, "DescriptorSetLayoutCountMismatch: the {} shader has {} layouts, but the {} shader has {} layouts", first_shader.to_lowercase(), first, this_shader.to_lowercase(), this),
            &GraphicsPipelineCreationError::DescriptorSetLayoutSlotCountMismatch(set, first_shader, first, this_shader, this) => write!(f, "DescriptorSetLayoutSlotCountMismatch: descriptor set {} in the {} shader has {} slots, but the same descriptor set in the {} shader has {} slots", set, first_shader.to_lowercase(), first, this_shader.to_lowercase(), this),
            &GraphicsPipelineCreationError::ShaderEntityIndexNotFound(ty, index) => write!(f, "ShaderEntityIndexNotFound: index {} in the {} shader", index, ty.to_lowercase()),
            &GraphicsPipelineCreationError::DescriptorSetToTraditionalBindingConversionError(ref message) => write!(f, "DescriptorSetToTraditionalBindingConversionError({:?})", message)
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq)]
/// The LinkError includes an error message, explaining what went wrong
pub struct LinkError {
    pub message: String
}

impl From<LinkError> for GraphicsPipelineCreationError {
    fn from(error: LinkError) -> Self {
        GraphicsPipelineCreationError::ProgramLinkError(error)
    }
}