#![deny(missing_docs)]
#[macro_use]
extern crate bitflags;
#[macro_use]
extern crate log;
extern crate draw_state;
use std::fmt::Debug;
use std::hash::Hash;
use std::any::Any;
pub use draw_state::{state, target};
pub use self::factory::Factory;
pub mod buffer;
pub mod command;
pub mod dummy;
pub mod factory;
pub mod format;
pub mod handle;
pub mod mapping;
pub mod memory;
pub mod pso;
pub mod shade;
pub mod texture;
pub const MAX_VERTEX_ATTRIBUTES: usize = 16;
pub const MAX_COLOR_TARGETS: usize = 4;
pub const MAX_CONSTANT_BUFFERS: usize = 14;
pub const MAX_RESOURCE_VIEWS: usize = 32;
pub const MAX_UNORDERED_VIEWS: usize = 4;
pub const MAX_SAMPLERS: usize = 16;
pub type VertexCount = u32;
pub type InstanceCount = u32;
pub type PatchSize = u8;
pub type AttributeSlot = u8;
pub type ConstantBufferSlot = u8;
pub type ResourceViewSlot = u8;
pub type UnorderedViewSlot = u8;
pub type ColorSlot = u8;
pub type SamplerSlot = u8;
macro_rules! define_shaders {
($($name:ident),+) => {$(
#[allow(missing_docs)]
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct $name<R: Resources>(handle::Shader<R>);
impl<R: Resources> $name<R> {
#[allow(missing_docs)]
pub fn reference(&self, man: &mut handle::Manager<R>) -> &R::Shader {
man.ref_shader(&self.0)
}
}
)+}
}
define_shaders!(VertexShader, HullShader, DomainShader, GeometryShader, PixelShader);
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum ShaderSet<R: Resources> {
Simple(VertexShader<R>, PixelShader<R>),
Geometry(VertexShader<R>, GeometryShader<R>, PixelShader<R>),
Tessellated(VertexShader<R>, HullShader<R>, DomainShader<R>, PixelShader<R>),
}
impl<R: Resources> ShaderSet<R> {
pub fn get_usage(&self) -> shade::Usage {
match self {
&ShaderSet::Simple(..) => shade::VERTEX | shade::PIXEL,
&ShaderSet::Geometry(..) => shade::VERTEX | shade::GEOMETRY | shade::PIXEL,
&ShaderSet::Tessellated(..) => shade::VERTEX | shade::HULL | shade::DOMAIN | shade::PIXEL,
}
}
}
#[derive(Copy, Clone, Debug)]
#[allow(missing_docs)] pub struct Capabilities {
pub max_vertex_count: usize,
pub max_index_count: usize,
pub max_texture_size: usize,
pub max_patch_size: usize,
pub instance_base_supported: bool,
pub instance_call_supported: bool,
pub instance_rate_supported: bool,
pub vertex_base_supported: bool,
pub srgb_color_supported: bool,
pub constant_buffer_supported: bool,
pub unordered_access_view_supported: bool,
pub separate_blending_slots_supported: bool,
}
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
#[repr(u8)]
pub enum Primitive {
PointList,
LineList,
LineStrip,
TriangleList,
TriangleStrip,
PatchList(PatchSize),
}
#[derive(Eq, Ord, PartialEq, PartialOrd, Hash, Copy, Clone, Debug)]
#[allow(missing_docs)]
#[repr(u8)]
pub enum IndexType {
U16,
U32,
}
#[allow(missing_docs)]
pub trait Resources: Clone + Hash + Debug + Eq + PartialEq + Any {
type Buffer: Clone + Hash + Debug + Eq + PartialEq + Any + Send + Sync + Copy;
type Shader: Clone + Hash + Debug + Eq + PartialEq + Any + Send + Sync;
type Program: Clone + Hash + Debug + Eq + PartialEq + Any + Send + Sync;
type PipelineStateObject: Clone + Hash + Debug + Eq + PartialEq + Any + Send + Sync;
type Texture: Clone + Hash + Debug + Eq + PartialEq + Any + Send + Sync;
type ShaderResourceView: Clone + Hash + Debug + Eq + PartialEq + Any + Send + Sync + Copy;
type UnorderedAccessView: Clone + Hash + Debug + Eq + PartialEq + Any + Send + Sync + Copy;
type RenderTargetView: Clone + Hash + Debug + Eq + PartialEq + Any + Send + Sync + Copy;
type DepthStencilView: Clone + Hash + Debug + Eq + PartialEq + Any + Send + Sync;
type Sampler: Clone + Hash + Debug + Eq + PartialEq + Any + Send + Sync + Copy;
type Fence: Clone + Hash + Debug + Eq + PartialEq + Any + Send + Sync;
type Mapping: Hash + Debug + Eq + PartialEq + Any + Send + Sync + mapping::Gate<Self>;
}
pub trait Device: Sized {
type Resources: Resources;
type CommandBuffer: command::Buffer<Self::Resources>;
fn get_capabilities(&self) -> &Capabilities;
fn pin_submitted_resources(&mut self, &handle::Manager<Self::Resources>);
fn submit(&mut self, &mut Self::CommandBuffer,
access: &pso::AccessInfo<Self::Resources>);
fn fenced_submit(&mut self,
&mut Self::CommandBuffer,
access: &pso::AccessInfo<Self::Resources>,
after: Option<handle::Fence<Self::Resources>>)
-> handle::Fence<Self::Resources>;
fn wait_fence(&mut self, &handle::Fence<Self::Resources>);
fn cleanup(&mut self);
}