Modify some commands

This commit is contained in:
Pierre Krieger 2016-11-03 22:02:01 +01:00
parent a255fb3e83
commit 5c47a0a783
2 changed files with 18 additions and 8 deletions

View File

@ -11,7 +11,7 @@ use std::cmp;
use std::error;
use std::fmt;
use buffer::Buffer;
use buffer::TrackedBuffer;
use command_buffer::RawCommandBufferPrototype;
use command_buffer::CommandsList;
use command_buffer::CommandsListSink;
@ -22,7 +22,7 @@ use vk;
/// Wraps around a commands list and adds at the end of it a command that copies from a buffer to
/// another.
pub struct CmdCopyBufferUnsynced<L, S, D>
where L: CommandsList, S: Buffer, D: Buffer
where L: CommandsList, S: TrackedBuffer, D: TrackedBuffer
{
// Parent commands list.
previous: L,
@ -36,7 +36,7 @@ pub struct CmdCopyBufferUnsynced<L, S, D>
}
impl<L, S, D> CmdCopyBufferUnsynced<L, S, D>
where L: CommandsList, S: Buffer, D: Buffer
where L: CommandsList, S: TrackedBuffer, D: TrackedBuffer
{
/// Builds a new command.
///
@ -72,7 +72,11 @@ impl<L, S, D> CmdCopyBufferUnsynced<L, S, D>
let size = cmp::min(source.size(), destination.size());
// FIXME: check overlap between source and dest
if source.conflicts_buffer(0, size, false, &destination, 0, size, true) {
return Err(CmdCopyBufferUnsyncedError::OverlappingRanges);
} else {
debug_assert!(!destination.conflicts_buffer(0, size, true, &source, 0, size, false));
}
Ok(CmdCopyBufferUnsynced {
previous: previous,
@ -88,7 +92,7 @@ impl<L, S, D> CmdCopyBufferUnsynced<L, S, D>
}
unsafe impl<L, S, D> CommandsList for CmdCopyBufferUnsynced<L, S, D>
where L: CommandsList, S: Buffer, D: Buffer
where L: CommandsList, S: TrackedBuffer, D: TrackedBuffer
{
#[inline]
fn append<'a>(&'a self, builder: &mut CommandsListSink<'a>) {
@ -97,6 +101,9 @@ unsafe impl<L, S, D> CommandsList for CmdCopyBufferUnsynced<L, S, D>
assert_eq!(self.source.inner().buffer.device().internal_object(),
builder.device().internal_object());
builder.add_buffer_transition(&self.source, 0, self.size as usize, false);
builder.add_buffer_transition(&self.destination, 0, self.size as usize, true);
builder.add_command(Box::new(move |raw: &mut RawCommandBufferPrototype| {
unsafe {
let vk = raw.device.pointers();

View File

@ -12,6 +12,7 @@ use std::fmt;
use buffer::Buffer;
use buffer::BufferInner;
use buffer::TrackedBuffer;
use command_buffer::RawCommandBufferPrototype;
use command_buffer::cmd::CommandsListPossibleOutsideRenderPass;
use command_buffer::CommandsList;
@ -39,7 +40,7 @@ pub struct CmdUpdateBufferUnsynced<'a, L, B, D: ?Sized>
}
impl<'a, L, B, D: ?Sized> CmdUpdateBufferUnsynced<'a, L, B, D>
where B: Buffer,
where B: TrackedBuffer,
L: CommandsList + CommandsListPossibleOutsideRenderPass,
D: Copy + 'static,
{
@ -85,7 +86,7 @@ impl<'a, L, B, D: ?Sized> CmdUpdateBufferUnsynced<'a, L, B, D>
}
unsafe impl<'d, L, B, D: ?Sized> CommandsList for CmdUpdateBufferUnsynced<'d, L, B, D>
where B: Buffer,
where B: TrackedBuffer,
L: CommandsList,
D: Copy + 'static,
{
@ -96,12 +97,14 @@ unsafe impl<'d, L, B, D: ?Sized> CommandsList for CmdUpdateBufferUnsynced<'d, L,
assert_eq!(self.buffer.inner().buffer.device().internal_object(),
builder.device().internal_object());
builder.add_buffer_transition(&self.buffer, 0, self.buffer.size(), true);
builder.add_command(Box::new(move |raw: &mut RawCommandBufferPrototype| {
unsafe {
let vk = raw.device.pointers();
let cmd = raw.command_buffer.clone().take().unwrap();
vk.CmdUpdateBuffer(cmd, self.buffer_handle, self.offset, self.size,
self.data as *const D as *const _);
self.data as *const D as *const _);
}
}));
}