mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2025-02-19 18:42:31 +00:00
Building a command buffer can now return an OomError
This commit is contained in:
parent
177db7b7c9
commit
99388714c3
@ -184,7 +184,7 @@ fn main() {
|
||||
.draw(pipeline.clone(), vulkano::command_buffer::DynamicState::none(), vertex_buffer.clone(),
|
||||
set.clone(), ())
|
||||
.end_render_pass()
|
||||
.build();
|
||||
.build().unwrap();
|
||||
|
||||
let future = future
|
||||
.then_execute(queue.clone(), cb)
|
||||
|
@ -189,7 +189,7 @@ fn main() {
|
||||
(vertex_buffer.clone(), normals_buffer.clone()),
|
||||
index_buffer.clone(), set.clone(), ())
|
||||
.end_render_pass()
|
||||
.build();
|
||||
.build().unwrap();
|
||||
|
||||
let future = future
|
||||
.then_execute(queue.clone(), command_buffer)
|
||||
|
@ -397,7 +397,7 @@ fn main() {
|
||||
.end_render_pass()
|
||||
|
||||
// Finish building the command buffer by calling `build`.
|
||||
.build();
|
||||
.build().unwrap();
|
||||
|
||||
let future = future
|
||||
.then_execute(queue.clone(), command_buffer)
|
||||
|
@ -60,14 +60,15 @@ impl AutoCommandBufferBuilder<Arc<StandardCommandPool>> {
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<P, O> CommandBufferBuild for AutoCommandBufferBuilder<P>
|
||||
where Cb<P>: CommandBufferBuild<Out = O>,
|
||||
unsafe impl<P, O, E> CommandBufferBuild for AutoCommandBufferBuilder<P>
|
||||
where Cb<P>: CommandBufferBuild<Out = O, Err = E>,
|
||||
P: CommandPool
|
||||
{
|
||||
type Out = O;
|
||||
type Err = E;
|
||||
|
||||
#[inline]
|
||||
fn build(self) -> Self::Out {
|
||||
fn build(self) -> Result<O, E> {
|
||||
// TODO: wrap around?
|
||||
CommandBufferBuild::build(self.inner)
|
||||
}
|
||||
|
@ -189,9 +189,14 @@ pub unsafe trait CommandBufferBuilder: DeviceOwned {
|
||||
Ok(self.add(cmd))
|
||||
}
|
||||
|
||||
/// Builds the actual command buffer.
|
||||
///
|
||||
/// You must call this function after you have finished adding commands to the command buffer
|
||||
/// builder. A command buffer will returned, which you can then submit or use in an "execute
|
||||
/// commands" command.
|
||||
#[inline]
|
||||
fn build<O>(self) -> O
|
||||
where Self: Sized + CommandBufferBuild<Out = O>
|
||||
fn build(self) -> Result<Self::Out, Self::Err>
|
||||
where Self: Sized + CommandBufferBuild
|
||||
{
|
||||
CommandBufferBuild::build(self)
|
||||
}
|
||||
|
@ -78,19 +78,20 @@ unsafe impl<I> DeviceOwned for AbstractStorageLayer<I> where I: DeviceOwned {
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<I, O> CommandBufferBuild for AbstractStorageLayer<I>
|
||||
where I: CommandBufferBuild<Out = O>
|
||||
unsafe impl<I, O, E> CommandBufferBuild for AbstractStorageLayer<I>
|
||||
where I: CommandBufferBuild<Out = O, Err = E>
|
||||
{
|
||||
type Out = AbstractStorageLayer<O>;
|
||||
type Err = E;
|
||||
|
||||
#[inline]
|
||||
fn build(mut self) -> Self::Out {
|
||||
let inner = self.inner.build();
|
||||
fn build(mut self) -> Result<Self::Out, E> {
|
||||
let inner = try!(self.inner.build());
|
||||
|
||||
AbstractStorageLayer {
|
||||
Ok(AbstractStorageLayer {
|
||||
inner: inner,
|
||||
commands: self.commands,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,13 +41,14 @@ impl<I> AutoPipelineBarriersLayer<I> {
|
||||
}
|
||||
}*/
|
||||
|
||||
unsafe impl<I, O> CommandBufferBuild for AutoPipelineBarriersLayer<I>
|
||||
where I: CommandBufferBuild<Out = O>
|
||||
unsafe impl<I, O, E> CommandBufferBuild for AutoPipelineBarriersLayer<I>
|
||||
where I: CommandBufferBuild<Out = O, Err = E>
|
||||
{
|
||||
type Out = O;
|
||||
type Err = E;
|
||||
|
||||
#[inline]
|
||||
fn build(self) -> O {
|
||||
fn build(self) -> Result<O, E> {
|
||||
self.inner.build()
|
||||
}
|
||||
}
|
||||
|
@ -40,13 +40,14 @@ impl<I> ContextCheckLayer<I> {
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<I, O> CommandBufferBuild for ContextCheckLayer<I>
|
||||
where I: CommandBufferBuild<Out = O>
|
||||
unsafe impl<I, O, E> CommandBufferBuild for ContextCheckLayer<I>
|
||||
where I: CommandBufferBuild<Out = O, Err = E>
|
||||
{
|
||||
type Out = O;
|
||||
type Err = E;
|
||||
|
||||
#[inline]
|
||||
fn build(self) -> O {
|
||||
fn build(self) -> Result<O, E> {
|
||||
self.inner.build()
|
||||
}
|
||||
}
|
||||
|
@ -52,13 +52,14 @@ unsafe impl<I> CommandBufferBuilder for DeviceCheckLayer<I>
|
||||
{
|
||||
}
|
||||
|
||||
unsafe impl<I, O> CommandBufferBuild for DeviceCheckLayer<I>
|
||||
where I: CommandBufferBuild<Out = O>
|
||||
unsafe impl<I, O, E> CommandBufferBuild for DeviceCheckLayer<I>
|
||||
where I: CommandBufferBuild<Out = O, Err = E>
|
||||
{
|
||||
type Out = O;
|
||||
type Err = E;
|
||||
|
||||
#[inline]
|
||||
fn build(self) -> O {
|
||||
fn build(self) -> Result<O, E> {
|
||||
self.inner.build()
|
||||
}
|
||||
}
|
||||
|
@ -54,13 +54,14 @@ unsafe impl<I> CommandBufferBuilder for QueueTyCheckLayer<I>
|
||||
{
|
||||
}
|
||||
|
||||
unsafe impl<I, O> CommandBufferBuild for QueueTyCheckLayer<I>
|
||||
where I: CommandBufferBuild<Out = O>
|
||||
unsafe impl<I, O, E> CommandBufferBuild for QueueTyCheckLayer<I>
|
||||
where I: CommandBufferBuild<Out = O, Err = E>
|
||||
{
|
||||
type Out = O;
|
||||
type Err = E;
|
||||
|
||||
#[inline]
|
||||
fn build(self) -> O {
|
||||
fn build(self) -> Result<O, E> {
|
||||
self.inner.build()
|
||||
}
|
||||
}
|
||||
|
@ -168,13 +168,14 @@ unsafe impl<I, O> AddCommand<commands_raw::CmdSetState> for StateCacheLayer<I>
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<I, O> CommandBufferBuild for StateCacheLayer<I>
|
||||
where I: CommandBufferBuild<Out = O>
|
||||
unsafe impl<I, O, E> CommandBufferBuild for StateCacheLayer<I>
|
||||
where I: CommandBufferBuild<Out = O, Err = E>
|
||||
{
|
||||
type Out = O;
|
||||
type Err = E;
|
||||
|
||||
#[inline]
|
||||
fn build(self) -> O {
|
||||
fn build(self) -> Result<O, E> {
|
||||
self.inner.build()
|
||||
}
|
||||
}
|
||||
|
@ -78,18 +78,19 @@ impl<I> SubmitSyncBuilderLayer<I> {
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<I, O> CommandBufferBuild for SubmitSyncBuilderLayer<I>
|
||||
where I: CommandBufferBuild<Out = O>
|
||||
unsafe impl<I, O, E> CommandBufferBuild for SubmitSyncBuilderLayer<I>
|
||||
where I: CommandBufferBuild<Out = O, Err = E>
|
||||
{
|
||||
type Out = SubmitSyncLayer<O>;
|
||||
type Err = E;
|
||||
|
||||
#[inline]
|
||||
fn build(self) -> Self::Out {
|
||||
SubmitSyncLayer {
|
||||
inner: self.inner.build(),
|
||||
fn build(self) -> Result<Self::Out, E> {
|
||||
Ok(SubmitSyncLayer {
|
||||
inner: try!(self.inner.build()),
|
||||
buffers: self.buffers,
|
||||
images: self.images,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -261,23 +261,24 @@ unsafe impl<P> CommandBufferBuild for UnsafeCommandBufferBuilder<P>
|
||||
where P: CommandPool
|
||||
{
|
||||
type Out = UnsafeCommandBuffer<P>;
|
||||
type Err = OomError;
|
||||
|
||||
#[inline]
|
||||
fn build(mut self) -> Self::Out {
|
||||
fn build(mut self) -> Result<Self::Out, OomError> {
|
||||
unsafe {
|
||||
debug_assert_ne!(self.cmd, 0);
|
||||
let cmd = self.cmd;
|
||||
let vk = self.device.pointers();
|
||||
check_errors(vk.EndCommandBuffer(cmd)).unwrap(); // TODO: handle error
|
||||
try!(check_errors(vk.EndCommandBuffer(cmd)));
|
||||
self.cmd = 0; // Prevents the `Drop` impl of the builder from destroying the cb.
|
||||
|
||||
UnsafeCommandBuffer {
|
||||
Ok(UnsafeCommandBuffer {
|
||||
cmd: cmd,
|
||||
device: self.device.clone(),
|
||||
pool: self.pool.take().unwrap().finish(),
|
||||
flags: self.flags,
|
||||
already_submitted: AtomicBool::new(false),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -347,3 +348,12 @@ unsafe impl<P> VulkanObject for UnsafeCommandBuffer<P> where P: CommandPool {
|
||||
self.cmd
|
||||
}
|
||||
}
|
||||
|
||||
impl<P> Drop for UnsafeCommandBuffer<P> where P: CommandPool {
|
||||
#[inline]
|
||||
fn drop(&mut self) {
|
||||
//unsafe {
|
||||
// FIXME: vk.FreeCommandBuffers()
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
@ -21,9 +21,11 @@ pub unsafe trait AddCommand<C> {
|
||||
pub unsafe trait CommandBufferBuild {
|
||||
/// The type of the built command buffer.
|
||||
type Out;
|
||||
/// Error that can be returned when building.
|
||||
type Err;
|
||||
|
||||
/// Builds the command buffer.
|
||||
fn build(self) -> Self::Out;
|
||||
fn build(self) -> Result<Self::Out, Self::Err>;
|
||||
}
|
||||
|
||||
/*trait Builder {
|
||||
|
Loading…
Reference in New Issue
Block a user