Vulkano: How to store a GpuFuture in a struct?

Created on 26 Jul 2017  路  3Comments  路  Source: vulkano-rs/vulkano

Hi,
I tried to create a renderer struct. However most of the vulkano variables are Arc<T>.
The problem is, when I try to store the Box<GpuFuture> in a struct an call self.previous_frame.join(acquire_future), the compiler complains cannot move out of borrowed content.

Which is logical since the join() method takes self as parameter. However, I don't know what the best practise would be here. Should I store it as a Arc<Mutex<GpuFuture>> and always clone + lock ?

Thanks for the help!

-siebencorgie

Most helpful comment

I fixed this issue in my own code using Option<Box<GpuFuture>> with the take method. I'm not sure if it is the most efficient method but it seemed to work for me:

self.previous_frame_end.as_mut().unwrap().cleanup_finished();

let future = self.previous_frame_end.take().unwrap().join(acquire_future)
              .then_execute(self.queue.clone(), command_buffer).unwrap()

self.previous_frame_end = Some(Box::new(future) as Box<_>);

Using Option::take swaps the value of the option with None and returns the current value. This is important because it is a transfer of ownership.

All 3 comments

You could use Option

I fixed this issue in my own code using Option<Box<GpuFuture>> with the take method. I'm not sure if it is the most efficient method but it seemed to work for me:

self.previous_frame_end.as_mut().unwrap().cleanup_finished();

let future = self.previous_frame_end.take().unwrap().join(acquire_future)
              .then_execute(self.queue.clone(), command_buffer).unwrap()

self.previous_frame_end = Some(Box::new(future) as Box<_>);

Using Option::take swaps the value of the option with None and returns the current value. This is important because it is a transfer of ownership.

Thanks for the suggestions, that worked quiet good!

Thanks for the fast help.

Was this page helpful?
0 / 5 - 0 ratings