diff --git a/src/core/Cargo.toml b/src/core/Cargo.toml index 488e1003cc1..4cc7cb0a517 100644 --- a/src/core/Cargo.toml +++ b/src/core/Cargo.toml @@ -30,6 +30,7 @@ path = "src/lib.rs" [dependencies] bitflags = "0.8" cgmath = { version = "0.14", optional = true } +derivative = "1.0" draw_state = "0.7" log = "0.3" serde = { version = "1.0", optional = true } diff --git a/src/core/src/command.rs b/src/core/src/command.rs index a3f1d3b36f1..1c7ba00f88f 100644 --- a/src/core/src/command.rs +++ b/src/core/src/command.rs @@ -136,7 +136,7 @@ impl From for ClearColor { } /// Informations about what is accessed by a bunch of commands. -#[derive(Debug)] +#[derive(Clone, Debug, Eq, PartialEq)] pub struct AccessInfo { mapped_reads: HashSet>, mapped_writes: HashSet>, diff --git a/src/core/src/handle.rs b/src/core/src/handle.rs index 4eadb3190e5..6757dc1895c 100644 --- a/src/core/src/handle.rs +++ b/src/core/src/handle.rs @@ -16,8 +16,8 @@ //! Resource handles -use std::{ops, cmp, hash}; use std::marker::PhantomData; +use std::ops::Deref; use std::sync::Arc; use {buffer, shade, texture, Resources}; use memory::Typed; @@ -26,24 +26,19 @@ use memory::Typed; #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct RawBuffer(Arc>); -impl ops::Deref for RawBuffer { +impl Deref for RawBuffer { type Target = buffer::Raw; fn deref(&self) -> &Self::Target { &self.0 } } /// Type-safe buffer handle -#[derive(Clone, Debug)] -pub struct Buffer(RawBuffer, PhantomData); - -impl cmp::PartialEq for Buffer { - fn eq(&self, other: &Self) -> bool { self.0.eq(&other.0) } -} - -impl cmp::Eq for Buffer {} - -impl hash::Hash for Buffer { - fn hash(&self, state: &mut H) { self.0.hash(state) } -} +#[derive(Derivative)] +#[derivative(Clone, Debug, Eq, Hash, PartialEq)] +pub struct Buffer( + RawBuffer, + #[derivative(Hash = "ignore", PartialEq = "ignore")] + PhantomData +); impl Typed for Buffer { type Raw = RawBuffer; @@ -74,28 +69,32 @@ pub struct Shader(Arc); #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct Program(Arc>); -impl ops::Deref for Program { +impl Deref for Program { type Target = shade::Program; fn deref(&self) -> &Self::Target { &self.0 } } /// Raw Pipeline State Handle -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct RawPipelineState(Arc, Program); /// Raw texture handle #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct RawTexture(Arc>); -impl ops::Deref for RawTexture { +impl Deref for RawTexture { type Target = texture::Raw; fn deref(&self) -> &Self::Target { &self.0 } } /// Typed texture object -#[derive(Clone, Debug, Eq, Hash, PartialEq)] -// TODO: manual Eq & Hash impl because PhantomData -pub struct Texture(RawTexture, PhantomData); +#[derive(Derivative)] +#[derivative(Clone, Debug, Eq, Hash, PartialEq)] +pub struct Texture( + RawTexture, + #[derivative(Hash = "ignore", PartialEq = "ignore")] + PhantomData +); impl Typed for Texture { type Raw = RawTexture; @@ -122,9 +121,13 @@ enum ViewSource { pub struct RawShaderResourceView(Arc, ViewSource); /// Type-safe Shader Resource View Handle -#[derive(Clone, Debug, Eq, Hash, PartialEq)] -// TODO: manual Eq & Hash impl because PhantomData -pub struct ShaderResourceView(RawShaderResourceView, PhantomData); +#[derive(Derivative)] +#[derivative(Clone, Debug, Eq, Hash, PartialEq)] +pub struct ShaderResourceView( + RawShaderResourceView, + #[derivative(Hash = "ignore", PartialEq = "ignore")] + PhantomData +); impl Typed for ShaderResourceView { type Raw = RawShaderResourceView; @@ -140,9 +143,13 @@ impl Typed for ShaderResourceView { pub struct RawUnorderedAccessView(Arc, ViewSource); /// Type-safe Unordered Access View Handle -#[derive(Clone, Debug, Eq, Hash, PartialEq)] -// TODO: manual Eq & Hash impl because PhantomData -pub struct UnorderedAccessView(RawUnorderedAccessView, PhantomData); +#[derive(Derivative)] +#[derivative(Clone, Debug, Eq, Hash, PartialEq)] +pub struct UnorderedAccessView( + RawUnorderedAccessView, + #[derivative(Hash = "ignore", PartialEq = "ignore")] + PhantomData +); impl Typed for UnorderedAccessView { type Raw = RawUnorderedAccessView; @@ -180,9 +187,13 @@ impl RawDepthStencilView { } /// Typed RTV -#[derive(Clone, Debug, Eq, Hash, PartialEq)] -// TODO: manual Eq & Hash impl because PhantomData -pub struct RenderTargetView(RawRenderTargetView, PhantomData); +#[derive(Derivative)] +#[derivative(Clone, Debug, Eq, Hash, PartialEq)] +pub struct RenderTargetView( + RawRenderTargetView, + #[derivative(Hash = "ignore", PartialEq = "ignore")] + PhantomData +); impl RenderTargetView { /// Get target dimensions @@ -199,13 +210,19 @@ impl Typed for RenderTargetView { } /// Typed DSV -#[derive(Clone, Debug, Eq, Hash, PartialEq)] -// TODO: manual Eq & Hash impl because PhantomData -pub struct DepthStencilView(RawDepthStencilView, PhantomData); +#[derive(Derivative)] +#[derivative(Clone, Debug, Eq, Hash, PartialEq)] +pub struct DepthStencilView( + RawDepthStencilView, + #[derivative(Hash = "ignore", PartialEq = "ignore")] + PhantomData +); impl DepthStencilView { /// Get target dimensions - pub fn get_dimensions(&self) -> texture::Dimensions { self.raw().get_dimensions() } + pub fn get_dimensions(&self) -> texture::Dimensions { + self.raw().get_dimensions() + } } impl Typed for DepthStencilView { @@ -219,7 +236,7 @@ impl Typed for DepthStencilView { /// Sampler Handle // TODO: Arc it all -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct Sampler(Arc, texture::SamplerInfo); impl Sampler { @@ -228,7 +245,7 @@ impl Sampler { } /// Fence Handle -#[derive(Clone, Debug, PartialEq, Eq, Hash)] +#[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct Fence(Arc); /// Stores reference-counted resources used in a command buffer. diff --git a/src/core/src/lib.rs b/src/core/src/lib.rs index dbe6d83c853..ad816489968 100644 --- a/src/core/src/lib.rs +++ b/src/core/src/lib.rs @@ -19,6 +19,8 @@ #[macro_use] extern crate bitflags; +#[macro_use] +extern crate derivative; extern crate draw_state; extern crate log; @@ -85,10 +87,12 @@ pub type ColorSlot = u8; pub type SamplerSlot = u8; macro_rules! define_shaders { - ($($name:ident),+) => {$( + ( $($name:ident),+ ) => { + $( #[allow(missing_docs)] #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct $name(handle::Shader); + impl $name { #[allow(missing_docs)] pub fn reference(&self, man: &mut handle::Manager) -> &R::Shader { @@ -100,7 +104,8 @@ macro_rules! define_shaders { $name(shader) } } - )+} + )+ + } } define_shaders!(VertexShader, HullShader, DomainShader, GeometryShader, PixelShader); @@ -114,7 +119,6 @@ pub enum ShaderSet { Geometry(VertexShader, GeometryShader, PixelShader), /// Tessellated TODO: Tessellated, TessellatedGeometry, TransformFeedback Tessellated(VertexShader, HullShader, DomainShader, PixelShader), - } impl ShaderSet { @@ -131,7 +135,7 @@ impl ShaderSet { //TODO: use the appropriate units for max vertex count, etc /// Features that the device supports. #[allow(missing_docs)] // pretty self-explanatory fields! -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] pub struct Capabilities { pub max_vertex_count: usize, @@ -309,7 +313,7 @@ pub trait Adapter: Sized { } /// Information about a backend adapater. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] pub struct AdapterInfo { /// Adapter name diff --git a/src/core/src/pso.rs b/src/core/src/pso.rs index ddcb66b58d6..abbd2aedb74 100644 --- a/src/core/src/pso.rs +++ b/src/core/src/pso.rs @@ -28,7 +28,6 @@ use shade::Usage; use std::error::Error; use std::fmt; - /// Maximum number of vertex buffers used in a PSO definition. pub const MAX_VERTEX_BUFFERS: usize = 4; @@ -36,7 +35,7 @@ pub const MAX_VERTEX_BUFFERS: usize = 4; pub type BufferOffset = usize; /// Error types happening upon PSO creation on the device side. -#[derive(Clone, PartialEq, Debug)] +#[derive(Clone, Debug, PartialEq)] pub struct CreationError; impl fmt::Display for CreationError { @@ -213,7 +212,7 @@ impl Descriptor { } /// A complete set of vertex buffers to be used for vertex import in PSO. -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub struct VertexBufferSet( /// Array of buffer handles with offsets in them pub [Option<(R::Buffer, BufferOffset)>; MAX_VERTEX_ATTRIBUTES] @@ -227,19 +226,19 @@ impl VertexBufferSet { } /// A constant buffer run-time parameter for PSO. -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub struct ConstantBufferParam(pub R::Buffer, pub Usage, pub ConstantBufferSlot); /// A shader resource view (SRV) run-time parameter for PSO. -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub struct ResourceViewParam(pub R::ShaderResourceView, pub Usage, pub ResourceViewSlot); /// An unordered access view (UAV) run-time parameter for PSO. -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub struct UnorderedViewParam(pub R::UnorderedAccessView, pub Usage, pub UnorderedViewSlot); /// A sampler run-time parameter for PSO. -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub struct SamplerParam(pub R::Sampler, pub Usage, pub SamplerSlot); /// A complete set of render targets to be used for pixel export in PSO. diff --git a/src/core/src/shade.rs b/src/core/src/shade.rs index 3b9486f42fa..38c69067ea6 100644 --- a/src/core/src/shade.rs +++ b/src/core/src/shade.rs @@ -87,7 +87,7 @@ impl TextureType { } /// A type of the sampler variable. -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] pub struct SamplerType(pub IsComparison, pub IsRect); @@ -348,7 +348,7 @@ impl From for Usage { } /// Vertex information that a shader takes as input. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, Eq, Hash, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] pub struct AttributeVar { /// Name of this attribute. @@ -363,7 +363,7 @@ pub struct AttributeVar { /// A constant in the shader - a bit of data that doesn't vary // between the shader execution units (vertices/pixels/etc). -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, Eq, Hash, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] pub struct ConstVar { /// Name of this constant. @@ -380,7 +380,7 @@ pub struct ConstVar { } /// A constant buffer. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, Eq, Hash, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] pub struct ConstantBufferVar { /// Name of this constant buffer. @@ -396,7 +396,7 @@ pub struct ConstantBufferVar { } /// Texture shader parameter. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, Eq, Hash, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] pub struct TextureVar { /// Name of this texture variable. @@ -412,7 +412,7 @@ pub struct TextureVar { } /// Unordered access shader parameter. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, Eq, Hash, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] pub struct UnorderedVar { /// Name of this unordered variable. @@ -424,7 +424,7 @@ pub struct UnorderedVar { } /// Sampler shader parameter. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, Eq, Hash, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] pub struct SamplerVar { /// Name of this sampler variable. @@ -438,7 +438,7 @@ pub struct SamplerVar { } /// Target output variable. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, Eq, Hash, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] pub struct OutputVar { /// Name of this output variable. @@ -452,7 +452,7 @@ pub struct OutputVar { } /// Metadata about a program. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, Eq, Hash, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] pub struct ProgramInfo { /// Attributes in the program @@ -514,7 +514,7 @@ impl hash::Hash for Program { } /// Error type for trying to store a UniformValue in a ConstVar. -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum CompatibilityError { /// Array sizes differ between the value and the var (trying to upload a vec2 as a vec4, etc) ErrorArraySize, diff --git a/src/render/Cargo.toml b/src/render/Cargo.toml index 6b6ef5c0c50..0a815dde546 100644 --- a/src/render/Cargo.toml +++ b/src/render/Cargo.toml @@ -36,6 +36,7 @@ unstable = [] [dependencies] cgmath = { version = "0.14", optional = true } +derivative = "1.0" draw_state = "0.7" gfx_core = { path = "../core", version = "0.7" } log = "0.3" diff --git a/src/render/src/lib.rs b/src/render/src/lib.rs index c5f319ac8de..a7ee35f267a 100644 --- a/src/render/src/lib.rs +++ b/src/render/src/lib.rs @@ -21,6 +21,8 @@ extern crate cgmath; extern crate log; +#[macro_use] +extern crate derivative; extern crate draw_state; extern crate gfx_core as core; diff --git a/src/render/src/macros/pso.rs b/src/render/src/macros/pso.rs index 5fe62cbdc36..e7e8b3d8176 100644 --- a/src/render/src/macros/pso.rs +++ b/src/render/src/macros/pso.rs @@ -21,15 +21,17 @@ macro_rules! gfx_pipeline_inner { } => { use $crate::pso::{DataLink, DataBind, Descriptor, InitError, RawDataSet, AccessInfo}; - #[derive(Clone, Debug)] + #[derive(Clone, Debug, PartialEq)] pub struct Data { $( pub $field: <$ty as DataBind>::Data, )* } + #[derive(Clone, Debug, PartialEq)] pub struct Meta { $( $field: $ty, )* } + #[derive(Clone, Debug, PartialEq)] pub struct Init<'a> { $( pub $field: <$ty as DataLink<'a>>::Init, )* } diff --git a/src/render/src/macros/structure.rs b/src/render/src/macros/structure.rs index 5995feed16a..21e6df78e03 100644 --- a/src/render/src/macros/structure.rs +++ b/src/render/src/macros/structure.rs @@ -31,7 +31,7 @@ macro_rules! gfx_impl_struct_meta { $( $field:ident: $ty:ty = $name:expr, )* }) => { #[allow(missing_docs)] - #[derive(Clone, Copy, Debug)] + #[derive(Clone, Copy, Debug, PartialEq)] $(#[$attr])* pub struct $root { $( pub $field: $ty, )* diff --git a/src/render/src/pso/buffer.rs b/src/render/src/pso/buffer.rs index e39589946b6..6cbfb2bab71 100644 --- a/src/render/src/pso/buffer.rs +++ b/src/render/src/pso/buffer.rs @@ -32,38 +32,64 @@ pub trait Structure { } type AttributeSlotSet = usize; + /// Service struct to simplify the implementations of `VertexBuffer` and `InstanceBuffer`. -pub struct VertexBufferCommon(RawVertexBuffer, PhantomData<(T, I)>); +#[derive(Derivative)] +#[derivative(Clone, Debug, Eq, Hash, PartialEq)] +pub struct VertexBufferCommon( + RawVertexBuffer, + #[derivative(Hash = "ignore", PartialEq = "ignore")] + PhantomData<(T, I)> +); + /// Vertex buffer component. Advanced per vertex. /// /// - init: `()` /// - data: `Buffer` pub type VertexBuffer = VertexBufferCommon; + /// Instance buffer component. Same as the vertex buffer but advances per instance. pub type InstanceBuffer = VertexBufferCommon; + /// Raw vertex/instance buffer component. Can be used when the formats of vertex attributes /// are not known at compile time. /// /// - init: `(&[&str, element], stride, inst_rate)` /// - data: `RawBuffer` +#[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct RawVertexBuffer(Option, AttributeSlotSet); + /// Constant buffer component. /// /// - init: `&str` = name of the buffer /// - data: `Buffer` -pub struct ConstantBuffer>(RawConstantBuffer, PhantomData); +#[derive(Derivative)] +#[derivative(Clone, Debug, Eq, Hash, PartialEq)] +pub struct ConstantBuffer>( + RawConstantBuffer, + #[derivative(Hash = "ignore", PartialEq = "ignore")] + PhantomData +); + /// Raw constant buffer component. /// /// - init: `&str` = name of the buffer /// - data: `RawBuffer` +#[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct RawConstantBuffer(Option<(Usage, ConstantBufferSlot)>); + /// Global (uniform) constant component. Describes a free-standing value passed into /// the shader, which is not enclosed into any constant buffer. Deprecated in DX10 and higher. /// /// - init: `&str` = name of the constant /// - data: `T` = value -pub struct Global(Option, PhantomData); - +#[derive(Derivative)] +#[derivative(Clone, Debug, Eq, Hash, PartialEq)] +pub struct Global( + Option, + #[derivative(Hash = "ignore", PartialEq = "ignore")] + PhantomData +); fn match_attribute(_: &shade::AttributeVar, _: Format) -> bool { true //TODO diff --git a/src/render/src/pso/mod.rs b/src/render/src/pso/mod.rs index 843523b5575..157c7ffe911 100644 --- a/src/render/src/pso/mod.rs +++ b/src/render/src/pso/mod.rs @@ -57,7 +57,7 @@ pub use core::command::AccessInfo; /// It doesn't have any typing information, since PSO knows what /// format and layout to expect from each resource. #[allow(missing_docs)] -#[derive(Debug)] +#[derive(Clone, Debug, PartialEq)] pub struct RawDataSet{ pub vertex_buffers: c::pso::VertexBufferSet, pub constant_buffers: Vec>, @@ -166,7 +166,7 @@ impl<'a> From> for ElementError { } /// Failure to initilize the link between the shader and the data. -#[derive(Clone, PartialEq, Debug)] +#[derive(Clone, Debug, PartialEq)] pub enum InitError { /// Vertex attribute mismatch. VertexImport(S, Option), @@ -271,8 +271,9 @@ pub trait PipelineData { } /// A strongly typed Pipleline State Object. See the module documentation for more information. -pub struct PipelineState( - c::handle::RawPipelineState, c::Primitive, M); +#[derive(Clone, Debug, Eq, Hash, PartialEq)] +pub struct PipelineState(c::handle::RawPipelineState, + c::Primitive, M); impl PipelineState { /// Create a new PSO from a raw handle and the "meta" instance. diff --git a/src/render/src/pso/resource.rs b/src/render/src/pso/resource.rs index 7badf6ed0ef..481133ec7cf 100644 --- a/src/render/src/pso/resource.rs +++ b/src/render/src/pso/resource.rs @@ -26,24 +26,42 @@ use super::{DataLink, DataBind, RawDataSet, AccessInfo}; /// /// - init: `&str` = name of the resource /// - data: `ShaderResourceView` -pub struct ShaderResource(RawShaderResource, PhantomData); +#[derive(Derivative)] +#[derivative(Clone, Debug, Eq, Hash, PartialEq)] +pub struct ShaderResource( + RawShaderResource, + #[derivative(Hash = "ignore", PartialEq = "ignore")] + PhantomData +); + /// Raw (untyped) shader resource (SRV). /// /// - init: `&str` = name of the resource. This may change in the future. /// - data: `RawShaderResourceView` +#[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct RawShaderResource(Option<(ResourceViewSlot, shade::Usage)>); + /// Unordered access component (UAV). A writable resource (texture/buffer) /// with no defined access order across simultaneously executing shaders. /// Supported on DX10 and higher. /// /// - init: `&str` = name of the resource /// - data: `UnorderedAccessView` -pub struct UnorderedAccess(Option<(UnorderedViewSlot, shade::Usage)>, PhantomData); +#[derive(Derivative)] +#[derivative(Clone, Debug, Eq, Hash, PartialEq)] +pub struct UnorderedAccess( + Option<(UnorderedViewSlot, shade::Usage)>, + #[derivative(Hash = "ignore", PartialEq = "ignore")] + PhantomData +); + /// Sampler component. /// /// - init: `&str` = name of the sampler /// - data: `Sampler` +#[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct Sampler(Option<(SamplerSlot, shade::Usage)>); + /// A convenience type for a texture paired with a sampler. /// It only makes sense for DX9 class hardware, where every texture by default /// is bundled with a sampler, hence they are represented by the same name. @@ -51,9 +69,9 @@ pub struct Sampler(Option<(SamplerSlot, shade::Usage)>); /// /// - init: `&str` = name of the sampler/texture (assuming they match) /// - data: (`ShaderResourceView`, `Sampler`) +#[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct TextureSampler(ShaderResource, Sampler); - impl<'a, T> DataLink<'a> for ShaderResource { type Init = &'a str; fn new() -> Self { @@ -79,7 +97,6 @@ impl DataBind for ShaderResource { } } - impl<'a> DataLink<'a> for RawShaderResource { type Init = &'a str; fn new() -> Self { @@ -114,7 +131,6 @@ impl DataBind for RawShaderResource { } } - impl<'a, T> DataLink<'a> for UnorderedAccess { type Init = &'a str; fn new() -> Self { @@ -149,7 +165,6 @@ impl DataBind for UnorderedAccess { } } - impl<'a> DataLink<'a> for Sampler { type Init = &'a str; fn new() -> Self { @@ -183,7 +198,6 @@ impl DataBind for Sampler { } } - impl<'a, T> DataLink<'a> for TextureSampler { type Init = &'a str; fn new() -> Self { diff --git a/src/render/src/pso/target.rs b/src/render/src/pso/target.rs index 68b96e69bb5..16d007d46e5 100644 --- a/src/render/src/pso/target.rs +++ b/src/render/src/pso/target.rs @@ -14,6 +14,7 @@ //! Render target components for a PSO. +use std::hash::{Hash, Hasher}; use std::marker::PhantomData; use core::{ColorSlot, Resources}; use core::{format, handle, pso, state, target}; @@ -25,44 +26,80 @@ use super::{DataLink, DataBind, RawDataSet, AccessInfo}; /// /// - init: `&str` = name of the target /// - data: `RenderTargetView` -pub struct RenderTarget(Option, PhantomData); +#[derive(Derivative)] +#[derivative(Clone, Debug, Eq, Hash, PartialEq)] +pub struct RenderTarget( + Option, + #[derivative(Hash = "ignore", PartialEq = "ignore")] + PhantomData +); + /// Render target component with active blending mode. /// /// - init: (`&str`, `ColorMask`, `Blend` = blending state) /// - data: `RenderTargetView` -pub struct BlendTarget(RawRenderTarget, PhantomData); +#[derive(Derivative)] +#[derivative(Clone, Debug, Eq, Hash, PartialEq)] +pub struct BlendTarget( + RawRenderTarget, + #[derivative(Hash = "ignore", PartialEq = "ignore")] + PhantomData +); + /// Raw (untyped) render target component with optional blending. /// /// - init: (`&str`, `Format`, `ColorMask`, `Option`) /// - data: `RawRenderTargetView` +#[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct RawRenderTarget(Option); + /// Depth target component. /// /// - init: `Depth` = depth state /// - data: `DepthStencilView` -pub struct DepthTarget(PhantomData); +#[derive(Derivative)] +#[derivative(Clone, Debug, Eq, Hash, PartialEq)] +pub struct DepthTarget( + #[derivative(Hash = "ignore", PartialEq = "ignore")] + PhantomData +); + /// Stencil target component. /// /// - init: `Stencil` = stencil state /// - data: (`DepthStencilView`, `(front, back)` = stencil reference values) -pub struct StencilTarget(PhantomData); +#[derive(Derivative)] +#[derivative(Clone, Debug, Eq, Hash, PartialEq)] +pub struct StencilTarget( + #[derivative(Hash = "ignore", PartialEq = "ignore")] + PhantomData +); + /// Depth + stencil target component. /// /// - init: (`Depth` = depth state, `Stencil` = stencil state) /// - data: (`DepthStencilView`, `(front, back)` = stencil reference values) -pub struct DepthStencilTarget(PhantomData); +#[derive(Derivative)] +#[derivative(Clone, Debug, Eq, Hash, PartialEq)] +pub struct DepthStencilTarget( + #[derivative(Hash = "ignore", PartialEq = "ignore")] + PhantomData +); + /// Scissor component. Sets up the scissor test for rendering. /// /// - init: `()` /// - data: `Rect` = target area +#[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct Scissor(bool); + /// Blend reference component. Sets up the reference color for blending. /// /// - init: `()` /// - data: `ColorValue` +#[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct BlendRef; - impl<'a, T: format::RenderFormat> DataLink<'a> for RenderTarget { type Init = &'a str; fn new() -> Self { diff --git a/tests/macros.rs b/tests/macros.rs index a01325ed29e..b1149b33005 100644 --- a/tests/macros.rs +++ b/tests/macros.rs @@ -2,12 +2,11 @@ extern crate gfx; pub use gfx::format as fm; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] pub struct Rg16; gfx_format!(Rg16: R16_G16 = Vec2); gfx_defines!{ - #[derive(PartialEq)] vertex Vertex { _x: i8 = "x", _y: f32 = "y", @@ -21,7 +20,7 @@ gfx_defines!{ constant Local { pos: [u32; 4] = "pos", } - #[derive(PartialEq)] #[derive(PartialOrd)] + constant LocalMeta { pos: [u32; 4] = "pos_meta", }