1
- //! Memory buffers
1
+ //! Memory buffers.
2
+ //!
3
+ //! # Buffer
4
+ //!
5
+ //! Buffers interpret memory slices as linear continguous data array.
6
+ //! They can be used as shader resources, vertex buffers, index buffers or for
7
+ //! specifying the action commands for indirect exection.
2
8
3
- use std:: error:: Error ;
4
- use std:: fmt;
5
-
6
- use { IndexType , Backend } ;
9
+ use { format, IndexType , Backend } ;
7
10
8
11
9
12
/// An offset inside a buffer, in bytes.
10
13
pub type Offset = u64 ;
11
14
15
+ /// Buffer state.
16
+ pub type State = Access ;
17
+
12
18
/// Error creating a buffer.
13
- #[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq ) ]
19
+ #[ derive( Fail , Debug , Clone , PartialEq , Eq ) ]
14
20
pub enum CreationError {
15
- /// Required `Usage` is not supported.
16
- Usage ( Usage ) ,
17
- /// Some other problem.
18
- Other ,
19
- }
20
-
21
- impl fmt:: Display for CreationError {
22
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
23
- let description = self . description ( ) ;
24
- match * self {
25
- CreationError :: Usage ( usage) => write ! ( f, "{}: {:?}" , description, usage) ,
26
- _ => write ! ( f, "{}" , description)
27
- }
28
- }
21
+ /// Memory allocation on the host side failed.
22
+ /// This could be caused by a lack of memory.
23
+ #[ fail( display = "Host memory allocation failed." ) ]
24
+ OutOfHostMemory ,
25
+ /// Memory allocation on the device side failed.
26
+ /// This could be caused by a lack of memory.
27
+ #[ fail( display = "Device memory allocation failed." ) ]
28
+ OutOfDeviceMemory ,
29
+ /// Requested buffer usage is not supported.
30
+ ///
31
+ /// Older GL version don't support constant buffers or multiple usage flags.
32
+ #[ fail( display = "Buffer usage unsupported ({:?})." , usage) ]
33
+ UnsupportedUsage {
34
+ /// Unsupported usage passed on buffer creation.
35
+ usage : Usage ,
36
+ } ,
29
37
}
30
38
31
- impl Error for CreationError {
32
- fn description ( & self ) -> & str {
33
- match * self {
34
- CreationError :: Usage ( _) =>
35
- "Required `Usage` is not supported" ,
36
- CreationError :: Other =>
37
- "Some other problem" ,
38
- }
39
- }
40
- }
41
-
42
- /// Error creating a `BufferView`.
43
- #[ derive( Clone , Debug , PartialEq ) ]
44
- pub enum ViewError {
45
- /// The required usage flag is not present in the image.
46
- Usage ( Usage ) ,
47
- /// The backend refused for some reason.
48
- Unsupported ,
49
- }
50
-
51
- impl fmt:: Display for ViewError {
52
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
53
- let description = self . description ( ) ;
54
- match * self {
55
- ViewError :: Usage ( usage) => write ! ( f, "{}: {:?}" , description, usage) ,
56
- _ => write ! ( f, "{}" , description)
57
- }
58
- }
59
- }
60
-
61
- impl Error for ViewError {
62
- fn description ( & self ) -> & str {
63
- match * self {
64
- ViewError :: Usage ( _) =>
65
- "The required usage flag is not present in the image" ,
66
- ViewError :: Unsupported =>
67
- "The backend refused for some reason" ,
68
- }
69
- }
39
+ /// Error creating a buffer view.
40
+ #[ derive( Fail , Debug , Clone , PartialEq , Eq ) ]
41
+ pub enum ViewCreationError {
42
+ /// Memory allocation on the host side failed.
43
+ /// This could be caused by a lack of memory.
44
+ #[ fail( display = "Host memory allocation failed." ) ]
45
+ OutOfHostMemory ,
46
+ /// Memory allocation on the device side failed.
47
+ /// This could be caused by a lack of memory.
48
+ #[ fail( display = "Device memory allocation failed." ) ]
49
+ OutOfDeviceMemory ,
50
+ /// Buffer view format is not supported.
51
+ #[ fail( display = "Buffer view format unsupported ({:?})." , format) ]
52
+ UnsupportedFormat {
53
+ /// Unsupported format passed on view creation.
54
+ format : Option < format:: Format > ,
55
+ } ,
70
56
}
71
57
72
58
bitflags ! (
@@ -95,21 +81,27 @@ bitflags!(
95
81
) ;
96
82
97
83
impl Usage {
98
- /// Can this buffer be used in transfer operations ?
84
+ /// Returns if the buffer can be used in transfer operations.
99
85
pub fn can_transfer ( & self ) -> bool {
100
86
self . intersects ( Usage :: TRANSFER_SRC | Usage :: TRANSFER_DST )
101
87
}
102
88
}
103
89
104
90
bitflags ! (
105
- /// Buffer state flags.
91
+ /// Buffer access flags.
92
+ ///
93
+ /// Access of buffers by the pipeline or shaders.
106
94
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
107
95
pub struct Access : u32 {
108
- ///
96
+ /// Read commands instruction for indirect execution.
109
97
const INDIRECT_COMMAND_READ = 0x1 ;
98
+ /// Read index values for indexed draw commands.
110
99
///
100
+ /// See [`draw_indexed`](../command/trait.RawCommandBuffer.html#tymethod.draw_indexed)
101
+ /// and [`draw_indexed_indirect`](../command/trait.RawCommandBuffer.html#tymethod.draw_indexed_indirect).
111
102
const INDEX_BUFFER_READ = 0x2 ;
112
- ///
103
+ /// Read vertices from vertex buffer for draw commands in the [`VERTEX_INPUT`](
104
+ /// ../pso/struct.PipelineStage.html#associatedconstant.VERTEX_INPUT) stage.
113
105
const VERTEX_BUFFER_READ = 0x4 ;
114
106
///
115
107
const CONSTANT_BUFFER_READ = 0x8 ;
@@ -132,11 +124,10 @@ bitflags!(
132
124
}
133
125
) ;
134
126
135
- /// Buffer state
136
- pub type State = Access ;
137
-
138
- /// Index buffer view for `bind_index_buffer`, slightly
139
- /// analogous to an index table into an array.
127
+ /// Index buffer view for `bind_index_buffer`.
128
+ ///
129
+ /// Defines a buffer slice used for acquiring the indicies on draw commands.
130
+ /// Indices are used to lookup vertex indices in the vertex buffers.
140
131
pub struct IndexBufferView < ' a , B : Backend > {
141
132
/// The buffer to bind.
142
133
pub buffer : & ' a B :: Buffer ,
0 commit comments