Actually implement DeviceCheckLayer

This commit is contained in:
Pierre Krieger 2017-02-08 11:27:48 +01:00
parent 0c0ca476dd
commit 836015ce80
13 changed files with 135 additions and 9 deletions

View File

@ -14,6 +14,7 @@ use command_buffer::CommandBufferBuilder;
use command_buffer::cmd;
use device::Device;
use device::DeviceOwned;
use VulkanObject;
/// Layer around a command buffer builder that checks whether the commands added to it belong to
/// the same device as the command buffer.
@ -62,10 +63,27 @@ unsafe impl<I, O> CommandBufferBuild for DeviceCheckLayer<I>
}
}
// TODO: actually implement
macro_rules! pass_through {
(($($param:ident),*), $cmd:ty) => {
(($($param:ident),*), $cmd:ty) => (
unsafe impl<'a, I, O $(, $param)*> AddCommand<$cmd> for DeviceCheckLayer<I>
where I: AddCommand<$cmd, Out = O> + DeviceOwned, $cmd: DeviceOwned
{
type Out = DeviceCheckLayer<O>;
#[inline]
fn add(self, command: $cmd) -> Self::Out {
let inner_device = self.inner.device().internal_object();
let cmd_device = command.device().internal_object();
assert_eq!(inner_device, cmd_device);
DeviceCheckLayer {
inner: self.inner.add(command),
}
}
}
);
(($($param:ident),*), $cmd:ty, no-device) => (
unsafe impl<'a, I, O $(, $param)*> AddCommand<$cmd> for DeviceCheckLayer<I>
where I: AddCommand<$cmd, Out = O>
{
@ -78,7 +96,7 @@ macro_rules! pass_through {
}
}
}
}
);
}
pass_through!((Rp, F), cmd::CmdBeginRenderPass<Rp, F>);
@ -86,16 +104,16 @@ pass_through!((S, Pl), cmd::CmdBindDescriptorSets<S, Pl>);
pass_through!((B), cmd::CmdBindIndexBuffer<B>);
pass_through!((Pl), cmd::CmdBindPipeline<Pl>);
pass_through!((V), cmd::CmdBindVertexBuffers<V>);
pass_through!((), cmd::CmdClearAttachments);
pass_through!((), cmd::CmdClearAttachments, no-device);
pass_through!((S, D), cmd::CmdCopyBuffer<S, D>);
pass_through!((), cmd::CmdDispatchRaw);
pass_through!((), cmd::CmdDrawIndexedRaw);
pass_through!((), cmd::CmdDrawIndexedRaw, no-device);
pass_through!((B), cmd::CmdDrawIndirectRaw<B>);
pass_through!((), cmd::CmdDrawRaw);
pass_through!((), cmd::CmdEndRenderPass);
pass_through!((), cmd::CmdDrawRaw, no-device);
pass_through!((), cmd::CmdEndRenderPass, no-device);
pass_through!((C), cmd::CmdExecuteCommands<C>);
pass_through!((B), cmd::CmdFillBuffer<B>);
pass_through!((), cmd::CmdNextSubpass);
pass_through!((), cmd::CmdNextSubpass, no-device);
pass_through!((Pc, Pl), cmd::CmdPushConstants<Pc, Pl>);
pass_through!((), cmd::CmdSetState);
pass_through!((B, D), cmd::CmdUpdateBuffer<'a, B, D>);

View File

@ -109,6 +109,15 @@ impl<F> CmdBeginRenderPass<Arc<RenderPassAbstract>, F>
}
}
unsafe impl<Rp, F> DeviceOwned for CmdBeginRenderPass<Rp, F>
where F: DeviceOwned
{
#[inline]
fn device(&self) -> &Arc<Device> {
self.framebuffer.device()
}
}
unsafe impl<'a, P, Rp, F> AddCommand<&'a CmdBeginRenderPass<Rp, F>> for UnsafeCommandBufferBuilder<P>
where P: CommandPool
{

View File

@ -95,6 +95,15 @@ impl<S, P> CmdBindDescriptorSets<S, P>
}
}
unsafe impl<S, Pl> DeviceOwned for CmdBindDescriptorSets<S, Pl>
where Pl: DeviceOwned
{
#[inline]
fn device(&self) -> &Arc<Device> {
self.pipeline_layout.device()
}
}
unsafe impl<'a, P, Pl, S> AddCommand<&'a CmdBindDescriptorSets<S, Pl>> for UnsafeCommandBufferBuilder<P>
where P: CommandPool
{

View File

@ -66,6 +66,15 @@ impl<B, I> CmdBindIndexBuffer<B>
}
}
unsafe impl<B> DeviceOwned for CmdBindIndexBuffer<B>
where B: DeviceOwned
{
#[inline]
fn device(&self) -> &Arc<Device> {
self.buffer.device()
}
}
unsafe impl<'a, P, B> AddCommand<&'a CmdBindIndexBuffer<B>> for UnsafeCommandBufferBuilder<P>
where P: CommandPool
{

View File

@ -118,6 +118,13 @@ unsafe impl<'a, P, Pl> AddCommand<&'a CmdBindPipeline<Pl>> for UnsafeCommandBuff
}
}
unsafe impl<Pl> DeviceOwned for CmdBindPipeline<Pl> {
#[inline]
fn device(&self) -> &Arc<Device> {
&self.device
}
}
/// Object that represents the internals of the bind pipeline command.
#[derive(Debug, Copy, Clone)]
pub struct CmdBindPipelineSys<'a>(vk::Pipeline, PhantomData<&'a ()>);

View File

@ -57,6 +57,13 @@ impl<B> CmdBindVertexBuffers<B> {
}
}
unsafe impl<B> DeviceOwned for CmdBindVertexBuffers<B> {
#[inline]
fn device(&self) -> &Arc<Device> {
&self.device
}
}
unsafe impl<'a, P, B> AddCommand<&'a CmdBindVertexBuffers<B>> for UnsafeCommandBufferBuilder<P>
where P: CommandPool
{

View File

@ -9,10 +9,12 @@
use std::error;
use std::fmt;
use std::sync::Arc;
use command_buffer::cb::AddCommand;
use command_buffer::cb::UnsafeCommandBufferBuilder;
use command_buffer::pool::CommandPool;
use device::Device;
use device::DeviceOwned;
use VulkanObject;
use VulkanPointers;
@ -36,6 +38,13 @@ impl CmdDispatchRaw {
}
}
unsafe impl DeviceOwned for CmdDispatchRaw {
#[inline]
fn device(&self) -> &Arc<Device> {
unimplemented!()
}
}
unsafe impl<'a, P> AddCommand<&'a CmdDispatchRaw> for UnsafeCommandBufferBuilder<P>
where P: CommandPool
{

View File

@ -7,10 +7,12 @@
// notice may not be copied, modified, or distributed except
// according to those terms.
use std::sync::Arc;
use buffer::Buffer;
use command_buffer::cb::AddCommand;
use command_buffer::cb::UnsafeCommandBufferBuilder;
use command_buffer::pool::CommandPool;
use device::Device;
use device::DeviceOwned;
use VulkanObject;
use VulkanPointers;
@ -40,6 +42,15 @@ impl<B> CmdDrawIndirectRaw<B> where B: Buffer {
}
}
unsafe impl<B> DeviceOwned for CmdDrawIndirectRaw<B>
where B: DeviceOwned
{
#[inline]
fn device(&self) -> &Arc<Device> {
self.buffer.device()
}
}
unsafe impl<'a, B, P> AddCommand<&'a CmdDrawIndirectRaw<B>> for UnsafeCommandBufferBuilder<P>
where B: Buffer,
P: CommandPool

View File

@ -7,11 +7,13 @@
// notice may not be copied, modified, or distributed except
// according to those terms.
use std::sync::Arc;
use smallvec::SmallVec;
use command_buffer::cb::AddCommand;
use command_buffer::cb::UnsafeCommandBufferBuilder;
use command_buffer::pool::CommandPool;
use device::Device;
use device::DeviceOwned;
use VulkanObject;
use VulkanPointers;
@ -43,6 +45,15 @@ impl<Cb> CmdExecuteCommands<Cb> {
}
}
unsafe impl<Cb> DeviceOwned for CmdExecuteCommands<Cb>
where Cb: DeviceOwned
{
#[inline]
fn device(&self) -> &Arc<Device> {
self.command_buffer.device()
}
}
unsafe impl<'a, P, Cb> AddCommand<&'a CmdExecuteCommands<Cb>> for UnsafeCommandBufferBuilder<P>
where P: CommandPool
{

View File

@ -9,12 +9,14 @@
use std::error;
use std::fmt;
use std::sync::Arc;
use buffer::Buffer;
use buffer::BufferInner;
use command_buffer::cb::AddCommand;
use command_buffer::cb::UnsafeCommandBufferBuilder;
use command_buffer::pool::CommandPool;
use device::Device;
use device::DeviceOwned;
use VulkanObject;
use VulkanPointers;
@ -33,6 +35,15 @@ pub struct CmdFillBuffer<B> {
data: u32,
}
unsafe impl<B> DeviceOwned for CmdFillBuffer<B>
where B: DeviceOwned
{
#[inline]
fn device(&self) -> &Arc<Device> {
self.buffer.device()
}
}
impl<B> CmdFillBuffer<B>
where B: Buffer
{

View File

@ -56,6 +56,13 @@ impl<Pc, Pl> CmdPushConstants<Pc, Pl>
}
}
unsafe impl<Pc, Pl> DeviceOwned for CmdPushConstants<Pc, Pl> {
#[inline]
fn device(&self) -> &Arc<Device> {
&self.device
}
}
unsafe impl<'a, P, Pc, Pl> AddCommand<&'a CmdPushConstants<Pc, Pl>> for UnsafeCommandBufferBuilder<P>
where P: CommandPool,
Pl: PipelineLayoutAbstract

View File

@ -60,6 +60,13 @@ impl CmdSetState {
}
}
unsafe impl DeviceOwned for CmdSetState {
#[inline]
fn device(&self) -> &Arc<Device> {
&self.device
}
}
unsafe impl<'a, P> AddCommand<&'a CmdSetState> for UnsafeCommandBufferBuilder<P>
where P: CommandPool
{

View File

@ -9,12 +9,14 @@
use std::error;
use std::fmt;
use std::sync::Arc;
use buffer::Buffer;
use buffer::BufferInner;
use command_buffer::cb::AddCommand;
use command_buffer::cb::UnsafeCommandBufferBuilder;
use command_buffer::pool::CommandPool;
use device::Device;
use device::DeviceOwned;
use VulkanObject;
use VulkanPointers;
@ -79,6 +81,15 @@ impl<'a, B, D: ?Sized> CmdUpdateBuffer<'a, B, D>
}
}
unsafe impl<'a, B, D> DeviceOwned for CmdUpdateBuffer<'a, B, D>
where B: DeviceOwned
{
#[inline]
fn device(&self) -> &Arc<Device> {
self.buffer.device()
}
}
unsafe impl<'a, 'd, P, B, D: ?Sized> AddCommand<&'a CmdUpdateBuffer<'d, B, D>> for UnsafeCommandBufferBuilder<P>
where B: Buffer,
D: Copy + 'static,