1#![deny(missing_docs)]
16
17#[macro_use]
21extern crate bitflags;
22extern crate draw_state;
23extern crate log;
24
25#[cfg(feature = "mint")]
26extern crate mint;
27
28#[cfg(feature = "serialize")]
29#[macro_use]
30extern crate serde;
31
32use std::fmt::{self, Debug};
33use std::error::Error;
34use std::hash::Hash;
35use std::any::Any;
36
37pub use draw_state::{state, target};
38pub use self::factory::Factory;
39
40pub mod buffer;
41pub mod command;
42pub mod dummy;
43pub mod factory;
44pub mod format;
45pub mod handle;
46pub mod mapping;
47pub mod memory;
48pub mod pso;
49pub mod shade;
50pub mod texture;
51
52pub const MAX_VERTEX_ATTRIBUTES: usize = 16;
54pub const MAX_COLOR_TARGETS: usize = 4;
56pub const MAX_CONSTANT_BUFFERS: usize = 14;
58pub const MAX_RESOURCE_VIEWS: usize = 32;
60pub const MAX_UNORDERED_VIEWS: usize = 4;
62pub const MAX_SAMPLERS: usize = 16;
64
65pub type VertexCount = u32;
67pub type InstanceCount = u32;
69pub type PatchSize = u8;
71
72pub type AttributeSlot = u8;
74pub type ConstantBufferSlot = u8;
76pub type ResourceViewSlot = u8;
78pub type UnorderedViewSlot = u8;
80pub type ColorSlot = u8;
82pub type SamplerSlot = u8;
84
85macro_rules! define_shaders {
86 ( $($name:ident),+ ) => {
87 $(
88 #[allow(missing_docs)]
89 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
90 pub struct $name<R: Resources>(handle::Shader<R>);
91
92 impl<R: Resources> $name<R> {
93 #[allow(missing_docs)]
94 pub fn reference(&self, man: &mut handle::Manager<R>) -> &R::Shader {
95 man.ref_shader(&self.0)
96 }
97
98 #[doc(hidden)]
99 pub fn new(shader: handle::Shader<R>) -> Self {
100 $name(shader)
101 }
102 }
103 )+
104 }
105}
106
107define_shaders!(VertexShader, HullShader, DomainShader, GeometryShader, PixelShader);
108
109#[derive(Clone, Debug, Eq, Hash, PartialEq)]
111pub enum ShaderSet<R: Resources> {
112 Simple(VertexShader<R>, PixelShader<R>),
114 Geometry(VertexShader<R>, GeometryShader<R>, PixelShader<R>),
116 Tessellated(VertexShader<R>, HullShader<R>, DomainShader<R>, PixelShader<R>),
118 TessellatedGeometry(VertexShader<R>, HullShader<R>, DomainShader<R>, GeometryShader<R>, PixelShader<R>),
120}
121
122impl<R: Resources> ShaderSet<R> {
123 pub fn get_usage(&self) -> shade::Usage {
125 use shade::Usage;
126 match *self {
127 ShaderSet::Simple(..) => Usage::VERTEX | Usage::PIXEL,
128 ShaderSet::Geometry(..) => Usage::VERTEX | Usage::GEOMETRY | Usage::PIXEL,
129 ShaderSet::Tessellated(..) => Usage::VERTEX | Usage::HULL | Usage::DOMAIN | Usage::PIXEL,
130 ShaderSet::TessellatedGeometry(..) => Usage::VERTEX | Usage::HULL | Usage::DOMAIN | Usage::GEOMETRY | Usage::PIXEL,
131 }
132 }
133}
134
135#[allow(missing_docs)] #[derive(Clone, Copy, Debug, Eq, PartialEq)]
139#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
140pub struct Capabilities {
141 pub max_vertex_count: usize,
142 pub max_index_count: usize,
143 pub max_texture_size: usize,
144 pub max_patch_size: usize,
145
146 pub instance_base_supported: bool,
147 pub instance_call_supported: bool,
148 pub instance_rate_supported: bool,
149 pub vertex_base_supported: bool,
150 pub srgb_color_supported: bool,
151 pub constant_buffer_supported: bool,
152 pub unordered_access_view_supported: bool,
153 pub separate_blending_slots_supported: bool,
154 pub copy_buffer_supported: bool,
155}
156
157#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
159#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
160#[repr(u8)]
161pub enum Primitive {
162 PointList,
164 LineList,
167 LineStrip,
171 TriangleList,
174 TriangleStrip,
177 LineListAdjacency,
181 LineStripAdjacency,
185 TriangleListAdjacency,
190 TriangleStripAdjacency,
197 PatchList(PatchSize),
200}
201
202#[allow(missing_docs)]
204#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
205#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
206#[repr(u8)]
207pub enum IndexType {
208 U16,
209 U32,
210}
211
212#[allow(missing_docs)]
214pub trait Resources: Clone + Hash + Debug + Eq + PartialEq + Any {
215 type Buffer: Clone + Hash + Debug + Eq + PartialEq + Any + Send + Sync + Copy;
216 type Shader: Clone + Hash + Debug + Eq + PartialEq + Any + Send + Sync;
217 type Program: Clone + Hash + Debug + Eq + PartialEq + Any + Send + Sync;
218 type PipelineStateObject: Clone + Hash + Debug + Eq + PartialEq + Any + Send + Sync;
219 type Texture: Clone + Hash + Debug + Eq + PartialEq + Any + Send + Sync;
220 type ShaderResourceView: Clone + Hash + Debug + Eq + PartialEq + Any + Send + Sync + Copy;
221 type UnorderedAccessView: Clone + Hash + Debug + Eq + PartialEq + Any + Send + Sync + Copy;
222 type RenderTargetView: Clone + Hash + Debug + Eq + PartialEq + Any + Send + Sync + Copy;
223 type DepthStencilView: Clone + Hash + Debug + Eq + PartialEq + Any + Send + Sync;
224 type Sampler: Clone + Hash + Debug + Eq + PartialEq + Any + Send + Sync + Copy;
225 type Fence: Clone + Hash + Debug + Eq + PartialEq + Any + Send + Sync;
226 type Mapping: Hash + Debug + Eq + PartialEq + Any + Send + Sync + mapping::Gate<Self>;
227}
228
229#[allow(missing_docs)]
230#[derive(Clone, Debug, PartialEq)]
231#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
232pub enum SubmissionError {
233 AccessOverlap,
234}
235
236impl fmt::Display for SubmissionError {
237 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
238 use self::SubmissionError::*;
239 match *self {
240 AccessOverlap => write!(f, "{}", self.description()),
241 }
242 }
243}
244
245impl Error for SubmissionError {
246 fn description(&self) -> &str {
247 use self::SubmissionError::*;
248 match *self {
249 AccessOverlap => "A resource access overlaps with another"
250 }
251 }
252}
253
254#[allow(missing_docs)]
255pub type SubmissionResult<T> = Result<T, SubmissionError>;
256
257pub trait Device: Sized {
259 type Resources: Resources;
261 type CommandBuffer: command::Buffer<Self::Resources>;
264
265 fn get_capabilities(&self) -> &Capabilities;
267
268 fn pin_submitted_resources(&mut self, &handle::Manager<Self::Resources>);
270
271 fn submit(&mut self,
273 &mut Self::CommandBuffer,
274 access: &command::AccessInfo<Self::Resources>)
275 -> SubmissionResult<()>;
276
277 fn fenced_submit(&mut self,
280 &mut Self::CommandBuffer,
281 access: &command::AccessInfo<Self::Resources>,
282 after: Option<handle::Fence<Self::Resources>>)
283 -> SubmissionResult<handle::Fence<Self::Resources>>;
284
285 fn wait_fence(&mut self, &handle::Fence<Self::Resources>);
287
288 fn cleanup(&mut self);
290}
291
292pub trait Adapter: Sized {
294 type CommandQueue: CommandQueue;
296 type Device: Device;
298 type QueueFamily: QueueFamily;
300
301 fn enumerate_adapters() -> Vec<Self>;
303
304 fn open<'a, I>(&self, queue_descs: I) -> (Self::Device, Vec<Self::CommandQueue>)
306 where I: Iterator<Item=(&'a Self::QueueFamily, u32)>;
307
308 fn get_info(&self) -> &AdapterInfo;
310
311 fn get_queue_families(&self) -> &[Self::QueueFamily];
313}
314
315#[derive(Clone, Debug, Eq, PartialEq)]
317#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
318pub struct AdapterInfo {
319 pub name: String,
321 pub vendor: usize,
323 pub device: usize,
325 pub software_rendering: bool,
327}
328
329pub trait QueueFamily: 'static {
332 type Surface: Surface;
334
335 fn supports_present(&self, surface: &Self::Surface) -> bool;
337
338 fn num_queues(&self) -> u32;
341}
342
343pub trait CommandQueue { }
346
347pub trait Surface {
349 type CommandQueue: CommandQueue;
351 type SwapChain: SwapChain;
353 type Window;
355
356 fn from_window(window: &Self::Window) -> Self;
358
359 fn build_swapchain<T: format::RenderFormat>(&self, present_queue: &Self::CommandQueue)
361 -> Self::SwapChain;
362}
363
364#[derive(Clone, Debug)]
366#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
367pub struct Frame(usize);
368
369impl Frame {
370 #[doc(hidden)]
371 pub fn new(id: usize) -> Self {
372 Frame(id)
373 }
374}
375
376pub trait SwapChain {
379 fn acquire_frame(&mut self) -> Frame;
381
382 fn present(&mut self);
384}