diff --git a/examples/src/bin/debug.rs b/examples/src/bin/debug.rs index 6446cb9f1b..7e79836510 100644 --- a/examples/src/bin/debug.rs +++ b/examples/src/bin/debug.rs @@ -9,7 +9,9 @@ use std::sync::Arc; use vulkano::{ - command_buffer::allocator::StandardCommandBufferAllocator, + command_buffer::{ + allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage, + }, device::{ physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo, }, @@ -174,6 +176,12 @@ fn main() { let queue = queues.next().unwrap(); let command_buffer_allocator = StandardCommandBufferAllocator::new(device); + let mut command_buffer_builder = AutoCommandBufferBuilder::primary( + &command_buffer_allocator, + queue.queue_family_index(), + CommandBufferUsage::OneTimeSubmit, + ) + .unwrap(); // Create an image in order to generate some additional logging: let pixel_format = Format::R8G8B8A8_UINT; @@ -188,8 +196,7 @@ fn main() { dimensions, MipmapsCount::One, pixel_format, - &command_buffer_allocator, - queue, + &mut command_buffer_builder, ) .unwrap(); diff --git a/examples/src/bin/image-self-copy-blit/main.rs b/examples/src/bin/image-self-copy-blit/main.rs index 8b7d91c0af..ea332e1cd6 100644 --- a/examples/src/bin/image-self-copy-blit/main.rs +++ b/examples/src/bin/image-self-copy-blit/main.rs @@ -212,8 +212,14 @@ fn main() { let descriptor_set_allocator = StandardDescriptorSetAllocator::new(device.clone()); let command_buffer_allocator = StandardCommandBufferAllocator::new(device.clone()); + let mut uploads = AutoCommandBufferBuilder::primary( + &command_buffer_allocator, + queue.queue_family_index(), + CommandBufferUsage::OneTimeSubmit, + ) + .unwrap(); - let (texture, tex_future) = { + let texture = { let png_bytes = include_bytes!("image_img.png").to_vec(); let cursor = Cursor::new(png_bytes); let decoder = png::Decoder::new(cursor); @@ -248,14 +254,8 @@ fn main() { ) .unwrap(); - let mut builder = AutoCommandBufferBuilder::primary( - &command_buffer_allocator, - queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, - ) - .unwrap(); // here, we perform image copying and blitting on the same image - builder + uploads // clear the image buffer .clear_color_image(ClearColorImageInfo::image(image.clone())) .unwrap() @@ -312,12 +312,8 @@ fn main() { ..BlitImageInfo::images(image.clone(), image.clone()) }) .unwrap(); - let command_buffer = builder.build().unwrap(); - ( - ImageView::new_default(image).unwrap(), - command_buffer.execute(queue.clone()).unwrap(), - ) + ImageView::new_default(image).unwrap() }; let sampler = Sampler::new( @@ -359,7 +355,14 @@ fn main() { let mut framebuffers = window_size_dependent_setup(&images, render_pass.clone(), &mut viewport); let mut recreate_swapchain = false; - let mut previous_frame_end = Some(tex_future.boxed()); + let mut previous_frame_end = Some( + uploads + .build() + .unwrap() + .execute(queue.clone()) + .unwrap() + .boxed(), + ); event_loop.run(move |event, _, control_flow| match event { Event::WindowEvent { diff --git a/examples/src/bin/image/main.rs b/examples/src/bin/image/main.rs index 9e37c6843d..9cb7393806 100644 --- a/examples/src/bin/image/main.rs +++ b/examples/src/bin/image/main.rs @@ -13,7 +13,7 @@ use vulkano::{ buffer::{BufferUsage, CpuAccessibleBuffer, TypedBufferAccess}, command_buffer::{ allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage, - RenderPassBeginInfo, SubpassContents, + PrimaryCommandBuffer, RenderPassBeginInfo, SubpassContents, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet, @@ -210,8 +210,14 @@ fn main() { let descriptor_set_allocator = StandardDescriptorSetAllocator::new(device.clone()); let command_buffer_allocator = StandardCommandBufferAllocator::new(device.clone()); + let mut uploads = AutoCommandBufferBuilder::primary( + &command_buffer_allocator, + queue.queue_family_index(), + CommandBufferUsage::OneTimeSubmit, + ) + .unwrap(); - let (texture, tex_future) = { + let texture = { let png_bytes = include_bytes!("image_img.png").to_vec(); let cursor = Cursor::new(png_bytes); let decoder = png::Decoder::new(cursor); @@ -226,16 +232,15 @@ fn main() { image_data.resize((info.width * info.height * 4) as usize, 0); reader.next_frame(&mut image_data).unwrap(); - let (image, future) = ImmutableImage::from_iter( + let image = ImmutableImage::from_iter( image_data, dimensions, MipmapsCount::One, Format::R8G8B8A8_SRGB, - &command_buffer_allocator, - queue.clone(), + &mut uploads, ) .unwrap(); - (ImageView::new_default(image).unwrap(), future) + ImageView::new_default(image).unwrap() }; let sampler = Sampler::new( @@ -277,7 +282,14 @@ fn main() { let mut framebuffers = window_size_dependent_setup(&images, render_pass.clone(), &mut viewport); let mut recreate_swapchain = false; - let mut previous_frame_end = Some(tex_future.boxed()); + let mut previous_frame_end = Some( + uploads + .build() + .unwrap() + .execute(queue.clone()) + .unwrap() + .boxed(), + ); event_loop.run(move |event, _, control_flow| match event { Event::WindowEvent { diff --git a/examples/src/bin/immutable-sampler/main.rs b/examples/src/bin/immutable-sampler/main.rs index c4e77deefe..f6534e036a 100644 --- a/examples/src/bin/immutable-sampler/main.rs +++ b/examples/src/bin/immutable-sampler/main.rs @@ -22,7 +22,7 @@ use vulkano::{ buffer::{BufferUsage, CpuAccessibleBuffer, TypedBufferAccess}, command_buffer::{ allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage, - RenderPassBeginInfo, SubpassContents, + PrimaryCommandBuffer, RenderPassBeginInfo, SubpassContents, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet, @@ -216,8 +216,14 @@ fn main() { let descriptor_set_allocator = StandardDescriptorSetAllocator::new(device.clone()); let command_buffer_allocator = StandardCommandBufferAllocator::new(device.clone()); + let mut uploads = AutoCommandBufferBuilder::primary( + &command_buffer_allocator, + queue.queue_family_index(), + CommandBufferUsage::OneTimeSubmit, + ) + .unwrap(); - let (texture, tex_future) = { + let texture = { let png_bytes = include_bytes!("image_img.png").to_vec(); let cursor = Cursor::new(png_bytes); let decoder = png::Decoder::new(cursor); @@ -232,16 +238,15 @@ fn main() { image_data.resize((info.width * info.height * 4) as usize, 0); reader.next_frame(&mut image_data).unwrap(); - let (image, future) = ImmutableImage::from_iter( + let image = ImmutableImage::from_iter( image_data, dimensions, MipmapsCount::One, Format::R8G8B8A8_SRGB, - &command_buffer_allocator, - queue.clone(), + &mut uploads, ) .unwrap(); - (ImageView::new_default(image).unwrap(), future) + ImageView::new_default(image).unwrap() }; let sampler = Sampler::new( @@ -290,7 +295,14 @@ fn main() { let mut framebuffers = window_size_dependent_setup(&images, render_pass.clone(), &mut viewport); let mut recreate_swapchain = false; - let mut previous_frame_end = Some(tex_future.boxed()); + let mut previous_frame_end = Some( + uploads + .build() + .unwrap() + .execute(queue.clone()) + .unwrap() + .boxed(), + ); event_loop.run(move |event, _, control_flow| match event { Event::WindowEvent { diff --git a/examples/src/bin/push-descriptors/main.rs b/examples/src/bin/push-descriptors/main.rs index 3cdbd73e6b..ee8e839411 100644 --- a/examples/src/bin/push-descriptors/main.rs +++ b/examples/src/bin/push-descriptors/main.rs @@ -13,7 +13,7 @@ use vulkano::{ buffer::{BufferUsage, CpuAccessibleBuffer, TypedBufferAccess}, command_buffer::{ allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage, - RenderPassBeginInfo, SubpassContents, + PrimaryCommandBuffer, RenderPassBeginInfo, SubpassContents, }, descriptor_set::WriteDescriptorSet, device::{ @@ -205,8 +205,14 @@ fn main() { .unwrap(); let command_buffer_allocator = StandardCommandBufferAllocator::new(device.clone()); + let mut uploads = AutoCommandBufferBuilder::primary( + &command_buffer_allocator, + queue.queue_family_index(), + CommandBufferUsage::OneTimeSubmit, + ) + .unwrap(); - let (texture, tex_future) = { + let texture = { let png_bytes = include_bytes!("image_img.png").to_vec(); let cursor = Cursor::new(png_bytes); let decoder = png::Decoder::new(cursor); @@ -221,16 +227,15 @@ fn main() { image_data.resize((info.width * info.height * 4) as usize, 0); reader.next_frame(&mut image_data).unwrap(); - let (image, future) = ImmutableImage::from_iter( + let image = ImmutableImage::from_iter( image_data, dimensions, MipmapsCount::One, Format::R8G8B8A8_SRGB, - &command_buffer_allocator, - queue.clone(), + &mut uploads, ) .unwrap(); - (ImageView::new_default(image).unwrap(), future) + ImageView::new_default(image).unwrap() }; let sampler = Sampler::new( @@ -269,7 +274,14 @@ fn main() { let mut framebuffers = window_size_dependent_setup(&images, render_pass.clone(), &mut viewport); let mut recreate_swapchain = false; - let mut previous_frame_end = Some(tex_future.boxed()); + let mut previous_frame_end = Some( + uploads + .build() + .unwrap() + .execute(queue.clone()) + .unwrap() + .boxed(), + ); event_loop.run(move |event, _, control_flow| match event { Event::WindowEvent { diff --git a/examples/src/bin/runtime_array/main.rs b/examples/src/bin/runtime_array/main.rs index 155789e566..064422f479 100644 --- a/examples/src/bin/runtime_array/main.rs +++ b/examples/src/bin/runtime_array/main.rs @@ -13,7 +13,7 @@ use vulkano::{ buffer::{BufferUsage, CpuAccessibleBuffer, TypedBufferAccess}, command_buffer::{ allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage, - RenderPassBeginInfo, SubpassContents, + PrimaryCommandBuffer, RenderPassBeginInfo, SubpassContents, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, @@ -272,6 +272,12 @@ fn main() { let descriptor_set_allocator = StandardDescriptorSetAllocator::new(device.clone()); let command_buffer_allocator = StandardCommandBufferAllocator::new(device.clone()); + let mut uploads = AutoCommandBufferBuilder::primary( + &command_buffer_allocator, + queue.queue_family_index(), + CommandBufferUsage::OneTimeSubmit, + ) + .unwrap(); let mascot_texture = { let png_bytes = include_bytes!("rust_mascot.png").to_vec(); @@ -293,11 +299,9 @@ fn main() { dimensions, MipmapsCount::One, Format::R8G8B8A8_SRGB, - &command_buffer_allocator, - queue.clone(), + &mut uploads, ) - .unwrap() - .0; + .unwrap(); ImageView::new_default(image).unwrap() }; @@ -322,11 +326,9 @@ fn main() { dimensions, MipmapsCount::One, Format::R8G8B8A8_SRGB, - &command_buffer_allocator, - queue.clone(), + &mut uploads, ) - .unwrap() - .0; + .unwrap(); ImageView::new_default(image).unwrap() }; @@ -410,8 +412,14 @@ fn main() { let mut framebuffers = window_size_dependent_setup(&images, render_pass.clone(), &mut viewport); let mut recreate_swapchain = false; - let mut previous_frame_end: Option> = - Some(Box::new(vulkano::sync::now(device.clone()))); + let mut previous_frame_end = Some( + uploads + .build() + .unwrap() + .execute(queue.clone()) + .unwrap() + .boxed(), + ); event_loop.run(move |event, _, control_flow| match event { Event::WindowEvent { diff --git a/examples/src/bin/texture_array/main.rs b/examples/src/bin/texture_array/main.rs index 53547fba58..e3ff204939 100644 --- a/examples/src/bin/texture_array/main.rs +++ b/examples/src/bin/texture_array/main.rs @@ -13,7 +13,7 @@ use vulkano::{ buffer::{BufferUsage, CpuAccessibleBuffer, TypedBufferAccess}, command_buffer::{ allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage, - RenderPassBeginInfo, SubpassContents, + PrimaryCommandBuffer, RenderPassBeginInfo, SubpassContents, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet, @@ -212,8 +212,14 @@ fn main() { let descriptor_set_allocator = StandardDescriptorSetAllocator::new(device.clone()); let command_buffer_allocator = StandardCommandBufferAllocator::new(device.clone()); + let mut uploads = AutoCommandBufferBuilder::primary( + &command_buffer_allocator, + queue.queue_family_index(), + CommandBufferUsage::OneTimeSubmit, + ) + .unwrap(); - let (texture, tex_future) = { + let texture = { let image_array_data: Vec<_> = vec![ include_bytes!("square.png").to_vec(), include_bytes!("star.png").to_vec(), @@ -236,16 +242,15 @@ fn main() { height: 128, array_layers: 3, }; // Replace with your actual image array dimensions - let (image, future) = ImmutableImage::from_iter( + let image = ImmutableImage::from_iter( image_array_data, dimensions, MipmapsCount::Log2, Format::R8G8B8A8_SRGB, - &command_buffer_allocator, - queue.clone(), + &mut uploads, ) .unwrap(); - (ImageView::new_default(image).unwrap(), future) + ImageView::new_default(image).unwrap() }; let sampler = Sampler::new(device.clone(), SamplerCreateInfo::simple_repeat_linear()).unwrap(); @@ -278,7 +283,14 @@ fn main() { let mut framebuffers = window_size_dependent_setup(&images, render_pass.clone(), &mut viewport); let mut recreate_swapchain = false; - let mut previous_frame_end = Some(tex_future.boxed()); + let mut previous_frame_end = Some( + uploads + .build() + .unwrap() + .execute(queue.clone()) + .unwrap() + .boxed(), + ); event_loop.run(move |event, _, control_flow| match event { Event::WindowEvent { diff --git a/vulkano/src/buffer/device_local.rs b/vulkano/src/buffer/device_local.rs index e09af131c9..d63803db5a 100644 --- a/vulkano/src/buffer/device_local.rs +++ b/vulkano/src/buffer/device_local.rs @@ -22,9 +22,9 @@ use super::{ use crate::{ command_buffer::{ allocator::CommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferBeginError, - CommandBufferExecFuture, CommandBufferUsage, CopyBufferInfo, PrimaryCommandBuffer, + CopyBufferInfo, }, - device::{Device, DeviceOwned, Queue}, + device::{Device, DeviceOwned}, memory::{ pool::{ alloc_dedicated_with_exportable_fd, AllocFromRequirementsFilter, AllocLayout, @@ -34,7 +34,7 @@ use crate::{ DedicatedAllocation, DeviceMemoryError, ExternalMemoryHandleType, MemoryPool, MemoryRequirements, }, - sync::{NowFuture, Sharing}, + sync::Sharing, DeviceSize, }; use smallvec::SmallVec; @@ -181,20 +181,14 @@ where /// the initial upload operation. In order to be allowed to use the `DeviceLocalBuffer`, you /// must either submit your operation after this future, or execute this future and wait for it /// to be finished before submitting your own operation. - pub fn from_buffer( + pub fn from_buffer( source: Arc, usage: BufferUsage, - command_buffer_allocator: &impl CommandBufferAllocator, - queue: Arc, - ) -> Result< - ( - Arc>, - CommandBufferExecFuture, - ), - DeviceLocalBufferCreationError, - > + command_buffer_builder: &mut AutoCommandBufferBuilder, + ) -> Result>, DeviceLocalBufferCreationError> where B: TypedBufferAccess + 'static, + A: CommandBufferAllocator, { unsafe { // We automatically set `transfer_dst` to true in order to avoid annoying errors. @@ -214,21 +208,11 @@ where .copied(), )?; - let mut cbb = AutoCommandBufferBuilder::primary( - command_buffer_allocator, - queue.queue_family_index(), - CommandBufferUsage::MultipleSubmit, - )?; - cbb.copy_buffer(CopyBufferInfo::buffers(source, buffer.clone())) + command_buffer_builder + .copy_buffer(CopyBufferInfo::buffers(source, buffer.clone())) .unwrap(); // TODO: return error? - let cb = cbb.build().unwrap(); // TODO: return OomError - - let future = match cb.execute(queue) { - Ok(f) => f, - Err(_) => unreachable!(), - }; - Ok((buffer, future)) + Ok(buffer) } } } @@ -251,20 +235,16 @@ where /// # Panics /// /// - Panics if `T` has zero size. - pub fn from_data( + pub fn from_data( data: T, usage: BufferUsage, - command_buffer_allocator: &impl CommandBufferAllocator, - queue: Arc, - ) -> Result< - ( - Arc>, - CommandBufferExecFuture, - ), - DeviceLocalBufferCreationError, - > { + command_buffer_builder: &mut AutoCommandBufferBuilder, + ) -> Result>, DeviceLocalBufferCreationError> + where + A: CommandBufferAllocator, + { let source = CpuAccessibleBuffer::from_data( - queue.device().clone(), + command_buffer_builder.device().clone(), BufferUsage { transfer_src: true, ..BufferUsage::empty() @@ -272,7 +252,7 @@ where false, data, )?; - DeviceLocalBuffer::from_buffer(source, usage, command_buffer_allocator, queue) + DeviceLocalBuffer::from_buffer(source, usage, command_buffer_builder) } } @@ -284,24 +264,18 @@ where /// /// - Panics if `T` has zero size. /// - Panics if `data` is empty. - pub fn from_iter( + pub fn from_iter( data: D, usage: BufferUsage, - command_buffer_allocator: &impl CommandBufferAllocator, - queue: Arc, - ) -> Result< - ( - Arc>, - CommandBufferExecFuture, - ), - DeviceLocalBufferCreationError, - > + command_buffer_builder: &mut AutoCommandBufferBuilder, + ) -> Result>, DeviceLocalBufferCreationError> where D: IntoIterator, D::IntoIter: ExactSizeIterator, + A: CommandBufferAllocator, { let source = CpuAccessibleBuffer::from_iter( - queue.device().clone(), + command_buffer_builder.device().clone(), BufferUsage { transfer_src: true, ..BufferUsage::empty() @@ -309,7 +283,7 @@ where false, data, )?; - DeviceLocalBuffer::from_buffer(source, usage, command_buffer_allocator, queue) + DeviceLocalBuffer::from_buffer(source, usage, command_buffer_builder) } } @@ -594,22 +568,32 @@ impl From for DeviceLocalBufferCreationError { #[cfg(test)] mod tests { use super::*; - use crate::{command_buffer::allocator::StandardCommandBufferAllocator, sync::GpuFuture}; + use crate::{ + command_buffer::{ + allocator::StandardCommandBufferAllocator, CommandBufferUsage, PrimaryCommandBuffer, + }, + sync::GpuFuture, + }; #[test] fn from_data_working() { let (device, queue) = gfx_dev_and_queue!(); - let cb_allocator = StandardCommandBufferAllocator::new(device.clone()); + let command_buffer_allocator = StandardCommandBufferAllocator::new(device.clone()); + let mut command_buffer_builder = AutoCommandBufferBuilder::primary( + &command_buffer_allocator, + queue.queue_family_index(), + CommandBufferUsage::OneTimeSubmit, + ) + .unwrap(); - let (buffer, _) = DeviceLocalBuffer::from_data( + let buffer = DeviceLocalBuffer::from_data( 12u32, BufferUsage { transfer_src: true, ..BufferUsage::empty() }, - &cb_allocator, - queue.clone(), + &mut command_buffer_builder, ) .unwrap(); @@ -624,15 +608,10 @@ mod tests { ) .unwrap(); - let mut cbb = AutoCommandBufferBuilder::primary( - &cb_allocator, - queue.queue_family_index(), - CommandBufferUsage::MultipleSubmit, - ) - .unwrap(); - cbb.copy_buffer(CopyBufferInfo::buffers(buffer, destination.clone())) + command_buffer_builder + .copy_buffer(CopyBufferInfo::buffers(buffer, destination.clone())) .unwrap(); - let _ = cbb + let _ = command_buffer_builder .build() .unwrap() .execute(queue) @@ -648,16 +627,21 @@ mod tests { fn from_iter_working() { let (device, queue) = gfx_dev_and_queue!(); - let cb_allocator = StandardCommandBufferAllocator::new(device.clone()); + let command_buffer_allocator = StandardCommandBufferAllocator::new(device.clone()); + let mut command_buffer_builder = AutoCommandBufferBuilder::primary( + &command_buffer_allocator, + queue.queue_family_index(), + CommandBufferUsage::OneTimeSubmit, + ) + .unwrap(); - let (buffer, _) = DeviceLocalBuffer::from_iter( + let buffer = DeviceLocalBuffer::from_iter( (0..512u32).map(|n| n * 2), BufferUsage { transfer_src: true, ..BufferUsage::empty() }, - &cb_allocator, - queue.clone(), + &mut command_buffer_builder, ) .unwrap(); @@ -672,15 +656,10 @@ mod tests { ) .unwrap(); - let mut cbb = AutoCommandBufferBuilder::primary( - &cb_allocator, - queue.queue_family_index(), - CommandBufferUsage::MultipleSubmit, - ) - .unwrap(); - cbb.copy_buffer(CopyBufferInfo::buffers(buffer, destination.clone())) + command_buffer_builder + .copy_buffer(CopyBufferInfo::buffers(buffer, destination.clone())) .unwrap(); - let _ = cbb + let _ = command_buffer_builder .build() .unwrap() .execute(queue) @@ -699,7 +678,13 @@ mod tests { fn create_buffer_zero_size_data() { let (device, queue) = gfx_dev_and_queue!(); - let cb_allocator = StandardCommandBufferAllocator::new(device); + let command_buffer_allocator = StandardCommandBufferAllocator::new(device); + let mut command_buffer_builder = AutoCommandBufferBuilder::primary( + &command_buffer_allocator, + queue.queue_family_index(), + CommandBufferUsage::OneTimeSubmit, + ) + .unwrap(); assert_should_panic!({ DeviceLocalBuffer::from_data( @@ -708,8 +693,7 @@ mod tests { transfer_dst: true, ..BufferUsage::empty() }, - &cb_allocator, - queue.clone(), + &mut command_buffer_builder, ) .unwrap(); }); diff --git a/vulkano/src/buffer/view.rs b/vulkano/src/buffer/view.rs index 044e4ce1ec..1e01a05d2c 100644 --- a/vulkano/src/buffer/view.rs +++ b/vulkano/src/buffer/view.rs @@ -26,17 +26,16 @@ //! //! # let device: Arc = return; //! # let queue: Arc = return; -//! # let command_buffer_allocator: vulkano::command_buffer::allocator::StandardCommandBufferAllocator = return; //! let usage = BufferUsage { //! storage_texel_buffer: true, //! ..BufferUsage::empty() //! }; //! -//! let (buffer, _future) = DeviceLocalBuffer::<[u32]>::from_iter( -//! (0..128).map(|n| n), +//! let buffer = DeviceLocalBuffer::<[u32]>::array( +//! device.clone(), +//! 128, //! usage, -//! &command_buffer_allocator, -//! queue.clone() +//! [queue.queue_family_index()], //! ).unwrap(); //! let _view = BufferView::new( //! buffer, @@ -483,7 +482,6 @@ mod tests { view::{BufferView, BufferViewCreateInfo, BufferViewCreationError}, BufferUsage, DeviceLocalBuffer, }, - command_buffer::allocator::StandardCommandBufferAllocator, format::Format, }; @@ -497,15 +495,9 @@ mod tests { ..BufferUsage::empty() }; - let cb_allocator = StandardCommandBufferAllocator::new(device); - - let (buffer, _) = DeviceLocalBuffer::<[[u8; 4]]>::from_iter( - (0..128).map(|_| [0; 4]), - usage, - &cb_allocator, - queue, - ) - .unwrap(); + let buffer = + DeviceLocalBuffer::<[[u8; 4]]>::array(device, 128, usage, [queue.queue_family_index()]) + .unwrap(); BufferView::new( buffer, BufferViewCreateInfo { @@ -526,15 +518,9 @@ mod tests { ..BufferUsage::empty() }; - let cb_allocator = StandardCommandBufferAllocator::new(device); - - let (buffer, _) = DeviceLocalBuffer::<[[u8; 4]]>::from_iter( - (0..128).map(|_| [0; 4]), - usage, - &cb_allocator, - queue, - ) - .unwrap(); + let buffer = + DeviceLocalBuffer::<[[u8; 4]]>::array(device, 128, usage, [queue.queue_family_index()]) + .unwrap(); BufferView::new( buffer, BufferViewCreateInfo { @@ -555,10 +541,8 @@ mod tests { ..BufferUsage::empty() }; - let cb_allocator = StandardCommandBufferAllocator::new(device); - - let (buffer, _) = - DeviceLocalBuffer::<[u32]>::from_iter((0..128).map(|_| 0), usage, &cb_allocator, queue) + let buffer = + DeviceLocalBuffer::<[u32]>::array(device, 128, usage, [queue.queue_family_index()]) .unwrap(); BufferView::new( buffer, @@ -575,13 +559,14 @@ mod tests { // `VK_FORMAT_R8G8B8A8_UNORM` guaranteed to be a supported format let (device, queue) = gfx_dev_and_queue!(); - let cb_allocator = StandardCommandBufferAllocator::new(device); - - let (buffer, _) = DeviceLocalBuffer::<[[u8; 4]]>::from_iter( - (0..128).map(|_| [0; 4]), - BufferUsage::empty(), - &cb_allocator, - queue, + let buffer = DeviceLocalBuffer::<[[u8; 4]]>::array( + device, + 128, + BufferUsage { + transfer_dst: true, // Dummy value + ..BufferUsage::empty() + }, + [queue.queue_family_index()], ) .unwrap(); @@ -607,13 +592,11 @@ mod tests { ..BufferUsage::empty() }; - let cb_allocator = StandardCommandBufferAllocator::new(device); - - let (buffer, _) = DeviceLocalBuffer::<[[f64; 4]]>::from_iter( - (0..128).map(|_| [0.0; 4]), + let buffer = DeviceLocalBuffer::<[[f64; 4]]>::array( + device, + 128, usage, - &cb_allocator, - queue, + [queue.queue_family_index()], ) .unwrap(); diff --git a/vulkano/src/command_buffer/synced/mod.rs b/vulkano/src/command_buffer/synced/mod.rs index 527ef3d45b..0ac9416691 100644 --- a/vulkano/src/command_buffer/synced/mod.rs +++ b/vulkano/src/command_buffer/synced/mod.rs @@ -537,6 +537,7 @@ mod tests { }, sys::CommandBufferBeginInfo, AutoCommandBufferBuilder, CommandBufferLevel, CommandBufferUsage, FillBufferInfo, + PrimaryCommandBuffer, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, @@ -580,20 +581,30 @@ mod tests { unsafe { let (device, queue) = gfx_dev_and_queue!(); - let allocator = StandardCommandBufferAllocator::new(device); + let command_buffer_allocator = StandardCommandBufferAllocator::new(device); + let mut command_buffer_builder = AutoCommandBufferBuilder::primary( + &command_buffer_allocator, + queue.queue_family_index(), + CommandBufferUsage::OneTimeSubmit, + ) + .unwrap(); // Create a tiny test buffer - let (buf, future) = DeviceLocalBuffer::from_data( + let buffer = DeviceLocalBuffer::from_data( 0u32, BufferUsage { transfer_dst: true, ..BufferUsage::empty() }, - &allocator, - queue.clone(), + &mut command_buffer_builder, ) .unwrap(); - future + + command_buffer_builder + .build() + .unwrap() + .execute(queue.clone()) + .unwrap() .then_signal_fence_and_flush() .unwrap() .wait(None) @@ -603,7 +614,7 @@ mod tests { let secondary = (0..2) .map(|_| { let mut builder = AutoCommandBufferBuilder::secondary( - &allocator, + &command_buffer_allocator, queue.queue_family_index(), CommandBufferUsage::SimultaneousUse, Default::default(), @@ -612,14 +623,14 @@ mod tests { builder .fill_buffer(FillBufferInfo { data: 42u32, - ..FillBufferInfo::dst_buffer(buf.clone()) + ..FillBufferInfo::dst_buffer(buffer.clone()) }) .unwrap(); Arc::new(builder.build().unwrap()) }) .collect::>(); - let allocs = allocator + let allocs = command_buffer_allocator .allocate(queue.queue_family_index(), CommandBufferLevel::Primary, 2) .unwrap() .collect::>(); diff --git a/vulkano/src/image/immutable.rs b/vulkano/src/image/immutable.rs index aa57b1bc6f..58b0c53874 100644 --- a/vulkano/src/image/immutable.rs +++ b/vulkano/src/image/immutable.rs @@ -16,10 +16,9 @@ use crate::{ buffer::{BufferAccess, BufferContents, BufferUsage, CpuAccessibleBuffer}, command_buffer::{ allocator::CommandBufferAllocator, AutoCommandBufferBuilder, BlitImageInfo, - BufferImageCopy, CommandBufferBeginError, CommandBufferExecFuture, CommandBufferUsage, - CopyBufferToImageInfo, ImageBlit, PrimaryCommandBuffer, + BufferImageCopy, CommandBufferBeginError, CopyBufferToImageInfo, ImageBlit, }, - device::{Device, DeviceOwned, Queue}, + device::{Device, DeviceOwned}, format::Format, image::sys::UnsafeImageCreateInfo, memory::{ @@ -30,7 +29,7 @@ use crate::{ DedicatedAllocation, DeviceMemoryError, MemoryPool, }, sampler::Filter, - sync::{NowFuture, Sharing}, + sync::Sharing, DeviceSize, OomError, }; use smallvec::{smallvec, SmallVec}; @@ -177,21 +176,21 @@ impl ImmutableImage { } /// Construct an ImmutableImage from the contents of `iter`. - pub fn from_iter( + pub fn from_iter( iter: I, dimensions: ImageDimensions, mip_levels: MipmapsCount, format: Format, - command_buffer_allocator: &impl CommandBufferAllocator, - queue: Arc, - ) -> Result<(Arc, CommandBufferExecFuture), ImmutableImageCreationError> + command_buffer_builder: &mut AutoCommandBufferBuilder, + ) -> Result, ImmutableImageCreationError> where [Px]: BufferContents, I: IntoIterator, I::IntoIter: ExactSizeIterator, + A: CommandBufferAllocator, { let source = CpuAccessibleBuffer::from_iter( - queue.device().clone(), + command_buffer_builder.device().clone(), BufferUsage { transfer_src: true, ..BufferUsage::empty() @@ -204,20 +203,21 @@ impl ImmutableImage { dimensions, mip_levels, format, - command_buffer_allocator, - queue, + command_buffer_builder, ) } /// Construct an ImmutableImage containing a copy of the data in `source`. - pub fn from_buffer( + pub fn from_buffer( source: Arc, dimensions: ImageDimensions, mip_levels: MipmapsCount, format: Format, - command_buffer_allocator: &impl CommandBufferAllocator, - queue: Arc, - ) -> Result<(Arc, CommandBufferExecFuture), ImmutableImageCreationError> { + command_buffer_builder: &mut AutoCommandBufferBuilder, + ) -> Result, ImmutableImageCreationError> + where + A: CommandBufferAllocator, + { let region = BufferImageCopy { image_subresource: ImageSubresourceLayers::from_parameters( format, @@ -260,34 +260,23 @@ impl ImmutableImage { .copied(), )?; - let mut cbb = AutoCommandBufferBuilder::primary( - command_buffer_allocator, - queue.queue_family_index(), - CommandBufferUsage::MultipleSubmit, - )?; - cbb.copy_buffer_to_image(CopyBufferToImageInfo { - regions: smallvec![region], - ..CopyBufferToImageInfo::buffer_image(source, initializer) - }) - .unwrap(); + command_buffer_builder + .copy_buffer_to_image(CopyBufferToImageInfo { + regions: smallvec![region], + ..CopyBufferToImageInfo::buffer_image(source, initializer) + }) + .unwrap(); if need_to_generate_mipmaps { generate_mipmaps( - &mut cbb, + command_buffer_builder, image.clone(), image.dimensions, ImageLayout::ShaderReadOnlyOptimal, ); } - let cb = cbb.build().unwrap(); - - let future = match cb.execute(queue) { - Ok(f) => f, - Err(e) => unreachable!("{:?}", e), - }; - - Ok((image, future)) + Ok(image) } } diff --git a/vulkano/src/image/mod.rs b/vulkano/src/image/mod.rs index 7974e4c462..38cdc64e3c 100644 --- a/vulkano/src/image/mod.rs +++ b/vulkano/src/image/mod.rs @@ -910,7 +910,9 @@ pub struct SparseImageMemoryRequirements { #[cfg(test)] mod tests { use crate::{ - command_buffer::allocator::StandardCommandBufferAllocator, + command_buffer::{ + allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage, + }, format::Format, image::{ImageAccess, ImageDimensions, ImmutableImage, MipmapsCount}, }; @@ -1019,7 +1021,13 @@ mod tests { fn mipmap_working_immutable_image() { let (device, queue) = gfx_dev_and_queue!(); - let cb_allocator = StandardCommandBufferAllocator::new(device); + let command_buffer_allocator = StandardCommandBufferAllocator::new(device); + let mut command_buffer_builder = AutoCommandBufferBuilder::primary( + &command_buffer_allocator, + queue.queue_family_index(), + CommandBufferUsage::OneTimeSubmit, + ) + .unwrap(); let dimensions = ImageDimensions::Dim2d { width: 512, @@ -1031,13 +1039,12 @@ mod tests { vec.resize(512 * 512, 0u8); - let (image, _) = ImmutableImage::from_iter( + let image = ImmutableImage::from_iter( vec.into_iter(), dimensions, MipmapsCount::One, Format::R8_UNORM, - &cb_allocator, - queue.clone(), + &mut command_buffer_builder, ) .unwrap(); assert_eq!(image.mip_levels(), 1); @@ -1047,13 +1054,12 @@ mod tests { vec.resize(512 * 512, 0u8); - let (image, _) = ImmutableImage::from_iter( + let image = ImmutableImage::from_iter( vec.into_iter(), dimensions, MipmapsCount::Log2, Format::R8_UNORM, - &cb_allocator, - queue, + &mut command_buffer_builder, ) .unwrap(); assert_eq!(image.mip_levels(), 10); diff --git a/vulkano/src/sampler/ycbcr.rs b/vulkano/src/sampler/ycbcr.rs index 7eaaab080c..e3431c0285 100644 --- a/vulkano/src/sampler/ycbcr.rs +++ b/vulkano/src/sampler/ycbcr.rs @@ -26,8 +26,8 @@ //! # let device: std::sync::Arc = return; //! # let image_data: Vec = return; //! # let queue: std::sync::Arc = return; -//! # let command_buffer_allocator: vulkano::command_buffer::allocator::StandardCommandBufferAllocator = return; //! # let descriptor_set_allocator: vulkano::descriptor_set::allocator::StandardDescriptorSetAllocator = return; +//! # let mut command_buffer_builder: vulkano::command_buffer::AutoCommandBufferBuilder = return; //! use vulkano::descriptor_set::{PersistentDescriptorSet, WriteDescriptorSet}; //! use vulkano::descriptor_set::layout::{DescriptorSetLayout, DescriptorSetLayoutBinding, DescriptorSetLayoutCreateInfo, DescriptorType}; //! use vulkano::format::Format; @@ -66,13 +66,12 @@ //! }, //! ).unwrap(); //! -//! let (image, future) = ImmutableImage::from_iter( +//! let image = ImmutableImage::from_iter( //! image_data, //! ImageDimensions::Dim2d { width: 1920, height: 1080, array_layers: 1 }, //! MipmapsCount::One, //! Format::G8_B8_R8_3PLANE_420_UNORM, -//! &command_buffer_allocator, -//! queue.clone(), +//! &mut command_buffer_builder, //! ).unwrap(); //! //! let create_info = ImageViewCreateInfo {