diff --git a/examples/async-update/main.rs b/examples/async-update/main.rs index 59466e44..64b8be9b 100644 --- a/examples/async-update/main.rs +++ b/examples/async-update/main.rs @@ -43,7 +43,8 @@ use vulkano::{ buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage}, command_buffer::{ allocator::StandardCommandBufferAllocator, BufferImageCopy, ClearColorImageInfo, - CommandBufferUsage, CopyBufferToImageInfo, RecordingCommandBuffer, RenderPassBeginInfo, + CommandBufferBeginInfo, CommandBufferLevel, CommandBufferUsage, CopyBufferToImageInfo, + RecordingCommandBuffer, RenderPassBeginInfo, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, @@ -331,10 +332,14 @@ fn main() -> Result<(), impl Error> { // Initialize the textures. { - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator.clone(), graphics_queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); for texture in &textures { @@ -587,10 +592,14 @@ fn main() -> Result<(), impl Error> { recreate_swapchain = true; } - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator.clone(), graphics_queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); builder @@ -761,10 +770,14 @@ fn run_worker( // Write to the texture that's currently not in use for rendering. let texture = textures[!current_index as usize].clone(); - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator.clone(), transfer_queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); builder diff --git a/examples/basic-compute-shader/main.rs b/examples/basic-compute-shader/main.rs index 6a85992a..77e753a9 100644 --- a/examples/basic-compute-shader/main.rs +++ b/examples/basic-compute-shader/main.rs @@ -8,7 +8,8 @@ use std::sync::Arc; use vulkano::{ buffer::{Buffer, BufferCreateInfo, BufferUsage}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, RecordingCommandBuffer, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, RecordingCommandBuffer, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, @@ -195,10 +196,14 @@ fn main() { .unwrap(); // In order to execute our operation, we have to build a command buffer. - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator, queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); builder diff --git a/examples/buffer-allocator/main.rs b/examples/buffer-allocator/main.rs index 08217d2d..c03844c6 100644 --- a/examples/buffer-allocator/main.rs +++ b/examples/buffer-allocator/main.rs @@ -11,8 +11,8 @@ use vulkano::{ BufferContents, BufferUsage, }, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, RecordingCommandBuffer, - RenderPassBeginInfo, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, RecordingCommandBuffer, RenderPassBeginInfo, }, device::{ physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo, @@ -369,10 +369,14 @@ fn main() -> Result<(), impl Error> { let buffer = buffer_allocator.allocate_slice(data.len() as _).unwrap(); buffer.write().unwrap().copy_from_slice(&data); - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); builder diff --git a/examples/clear-attachments/main.rs b/examples/clear-attachments/main.rs index d3cf7ede..626665b0 100644 --- a/examples/clear-attachments/main.rs +++ b/examples/clear-attachments/main.rs @@ -1,8 +1,9 @@ use std::{error::Error, sync::Arc}; use vulkano::{ command_buffer::{ - allocator::StandardCommandBufferAllocator, ClearAttachment, ClearRect, CommandBufferUsage, - RecordingCommandBuffer, RenderPassBeginInfo, + allocator::StandardCommandBufferAllocator, ClearAttachment, ClearRect, + CommandBufferBeginInfo, CommandBufferLevel, CommandBufferUsage, RecordingCommandBuffer, + RenderPassBeginInfo, }, device::{ physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo, @@ -207,10 +208,14 @@ fn main() -> Result<(), impl Error> { recreate_swapchain = true; } - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); builder diff --git a/examples/deferred/frame/ambient_lighting_system.rs b/examples/deferred/frame/ambient_lighting_system.rs index 4ae122a6..353a25fb 100644 --- a/examples/deferred/frame/ambient_lighting_system.rs +++ b/examples/deferred/frame/ambient_lighting_system.rs @@ -2,8 +2,9 @@ use std::sync::Arc; use vulkano::{ buffer::{Buffer, BufferCreateInfo, BufferUsage, Subbuffer}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferInheritanceInfo, - CommandBufferUsage, RecordingCommandBuffer, SecondaryAutoCommandBuffer, + allocator::StandardCommandBufferAllocator, CommandBuffer, CommandBufferBeginInfo, + CommandBufferInheritanceInfo, CommandBufferLevel, CommandBufferUsage, + RecordingCommandBuffer, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, @@ -162,7 +163,7 @@ impl AmbientLightingSystem { viewport_dimensions: [u32; 2], color_input: Arc, ambient_color: [f32; 3], - ) -> Arc { + ) -> Arc { let push_constants = fs::PushConstants { color: [ambient_color[0], ambient_color[1], ambient_color[2], 1.0], }; @@ -182,12 +183,16 @@ impl AmbientLightingSystem { depth_range: 0.0..=1.0, }; - let mut builder = RecordingCommandBuffer::secondary( + let mut builder = RecordingCommandBuffer::new( self.command_buffer_allocator.clone(), self.gfx_queue.queue_family_index(), - CommandBufferUsage::MultipleSubmit, - CommandBufferInheritanceInfo { - render_pass: Some(self.subpass.clone().into()), + CommandBufferLevel::Secondary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::MultipleSubmit, + inheritance_info: Some(CommandBufferInheritanceInfo { + render_pass: Some(self.subpass.clone().into()), + ..Default::default() + }), ..Default::default() }, ) diff --git a/examples/deferred/frame/directional_lighting_system.rs b/examples/deferred/frame/directional_lighting_system.rs index 80cd86d7..cb27792e 100644 --- a/examples/deferred/frame/directional_lighting_system.rs +++ b/examples/deferred/frame/directional_lighting_system.rs @@ -3,8 +3,9 @@ use std::sync::Arc; use vulkano::{ buffer::{Buffer, BufferCreateInfo, BufferUsage, Subbuffer}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferInheritanceInfo, - CommandBufferUsage, RecordingCommandBuffer, SecondaryAutoCommandBuffer, + allocator::StandardCommandBufferAllocator, CommandBuffer, CommandBufferBeginInfo, + CommandBufferInheritanceInfo, CommandBufferLevel, CommandBufferUsage, + RecordingCommandBuffer, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, @@ -172,7 +173,7 @@ impl DirectionalLightingSystem { normals_input: Arc, direction: Vector3, color: [f32; 3], - ) -> Arc { + ) -> Arc { let push_constants = fs::PushConstants { color: [color[0], color[1], color[2], 1.0], direction: direction.extend(0.0).into(), @@ -196,12 +197,16 @@ impl DirectionalLightingSystem { depth_range: 0.0..=1.0, }; - let mut builder = RecordingCommandBuffer::secondary( + let mut builder = RecordingCommandBuffer::new( self.command_buffer_allocator.clone(), self.gfx_queue.queue_family_index(), - CommandBufferUsage::MultipleSubmit, - CommandBufferInheritanceInfo { - render_pass: Some(self.subpass.clone().into()), + CommandBufferLevel::Secondary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::MultipleSubmit, + inheritance_info: Some(CommandBufferInheritanceInfo { + render_pass: Some(self.subpass.clone().into()), + ..Default::default() + }), ..Default::default() }, ) diff --git a/examples/deferred/frame/point_lighting_system.rs b/examples/deferred/frame/point_lighting_system.rs index 9f7b6946..f494d33b 100644 --- a/examples/deferred/frame/point_lighting_system.rs +++ b/examples/deferred/frame/point_lighting_system.rs @@ -3,8 +3,9 @@ use std::sync::Arc; use vulkano::{ buffer::{Buffer, BufferCreateInfo, BufferUsage, Subbuffer}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferInheritanceInfo, - CommandBufferUsage, RecordingCommandBuffer, SecondaryAutoCommandBuffer, + allocator::StandardCommandBufferAllocator, CommandBuffer, CommandBufferBeginInfo, + CommandBufferInheritanceInfo, CommandBufferLevel, CommandBufferUsage, + RecordingCommandBuffer, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, @@ -183,7 +184,7 @@ impl PointLightingSystem { screen_to_world: Matrix4, position: Vector3, color: [f32; 3], - ) -> Arc { + ) -> Arc { let push_constants = fs::PushConstants { screen_to_world: screen_to_world.into(), color: [color[0], color[1], color[2], 1.0], @@ -209,12 +210,16 @@ impl PointLightingSystem { depth_range: 0.0..=1.0, }; - let mut builder = RecordingCommandBuffer::secondary( + let mut builder = RecordingCommandBuffer::new( self.command_buffer_allocator.clone(), self.gfx_queue.queue_family_index(), - CommandBufferUsage::MultipleSubmit, - CommandBufferInheritanceInfo { - render_pass: Some(self.subpass.clone().into()), + CommandBufferLevel::Secondary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::MultipleSubmit, + inheritance_info: Some(CommandBufferInheritanceInfo { + render_pass: Some(self.subpass.clone().into()), + ..Default::default() + }), ..Default::default() }, ) diff --git a/examples/deferred/frame/system.rs b/examples/deferred/frame/system.rs index a883eb13..c9359e37 100644 --- a/examples/deferred/frame/system.rs +++ b/examples/deferred/frame/system.rs @@ -7,9 +7,9 @@ use cgmath::{Matrix4, SquareMatrix, Vector3}; use std::sync::Arc; use vulkano::{ command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, PrimaryAutoCommandBuffer, - RecordingCommandBuffer, RenderPassBeginInfo, SecondaryAutoCommandBuffer, SubpassBeginInfo, - SubpassContents, + allocator::StandardCommandBufferAllocator, CommandBuffer, CommandBufferBeginInfo, + CommandBufferLevel, CommandBufferUsage, RecordingCommandBuffer, RenderPassBeginInfo, + SubpassBeginInfo, SubpassContents, }, descriptor_set::allocator::StandardDescriptorSetAllocator, device::Queue, @@ -338,10 +338,14 @@ impl FrameSystem { .unwrap(); // Start the command buffer builder that will be filled throughout the frame handling. - let mut command_buffer_builder = RecordingCommandBuffer::primary( + let mut command_buffer_builder = RecordingCommandBuffer::new( self.command_buffer_allocator.clone(), self.gfx_queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); command_buffer_builder @@ -394,7 +398,7 @@ pub struct Frame<'a> { // Framebuffer that was used when starting the render pass. framebuffer: Arc, // The command buffer builder that will be built during the lifetime of this object. - command_buffer_builder: Option>, + command_buffer_builder: Option, // Matrix that was passed to `frame()`. world_to_framebuffer: Matrix4, } @@ -487,7 +491,7 @@ pub struct DrawPass<'f, 's: 'f> { impl<'f, 's: 'f> DrawPass<'f, 's> { /// Appends a command that executes a secondary command buffer that performs drawing. - pub fn execute(&mut self, command_buffer: Arc) { + pub fn execute(&mut self, command_buffer: Arc) { self.frame .command_buffer_builder .as_mut() diff --git a/examples/deferred/triangle_draw_system.rs b/examples/deferred/triangle_draw_system.rs index ae71b085..fb31697d 100644 --- a/examples/deferred/triangle_draw_system.rs +++ b/examples/deferred/triangle_draw_system.rs @@ -2,8 +2,9 @@ use std::sync::Arc; use vulkano::{ buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage, Subbuffer}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferInheritanceInfo, - CommandBufferUsage, RecordingCommandBuffer, SecondaryAutoCommandBuffer, + allocator::StandardCommandBufferAllocator, CommandBuffer, CommandBufferBeginInfo, + CommandBufferInheritanceInfo, CommandBufferLevel, CommandBufferUsage, + RecordingCommandBuffer, }, device::Queue, memory::allocator::{AllocationCreateInfo, MemoryTypeFilter, StandardMemoryAllocator}, @@ -127,13 +128,17 @@ impl TriangleDrawSystem { } /// Builds a secondary command buffer that draws the triangle on the current subpass. - pub fn draw(&self, viewport_dimensions: [u32; 2]) -> Arc { - let mut builder = RecordingCommandBuffer::secondary( + pub fn draw(&self, viewport_dimensions: [u32; 2]) -> Arc { + let mut builder = RecordingCommandBuffer::new( self.command_buffer_allocator.clone(), self.gfx_queue.queue_family_index(), - CommandBufferUsage::MultipleSubmit, - CommandBufferInheritanceInfo { - render_pass: Some(self.subpass.clone().into()), + CommandBufferLevel::Secondary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::MultipleSubmit, + inheritance_info: Some(CommandBufferInheritanceInfo { + render_pass: Some(self.subpass.clone().into()), + ..Default::default() + }), ..Default::default() }, ) diff --git a/examples/dynamic-buffers/main.rs b/examples/dynamic-buffers/main.rs index e72fe407..4f326f3e 100644 --- a/examples/dynamic-buffers/main.rs +++ b/examples/dynamic-buffers/main.rs @@ -8,7 +8,8 @@ use std::{iter::repeat, mem::size_of, sync::Arc}; use vulkano::{ buffer::{Buffer, BufferCreateInfo, BufferUsage}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, RecordingCommandBuffer, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, RecordingCommandBuffer, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, layout::DescriptorType, DescriptorBufferInfo, @@ -236,10 +237,14 @@ fn main() { .unwrap(); // Build the command buffer, using different offsets for each call. - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator, queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); diff --git a/examples/dynamic-local-size/main.rs b/examples/dynamic-local-size/main.rs index 2f7b0478..5235860f 100644 --- a/examples/dynamic-local-size/main.rs +++ b/examples/dynamic-local-size/main.rs @@ -8,8 +8,8 @@ use std::{fs::File, io::BufWriter, path::Path, sync::Arc}; use vulkano::{ buffer::{Buffer, BufferCreateInfo, BufferUsage}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, CopyImageToBufferInfo, - RecordingCommandBuffer, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, CopyImageToBufferInfo, RecordingCommandBuffer, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, @@ -249,10 +249,14 @@ fn main() { ) .unwrap(); - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator, queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); builder diff --git a/examples/gl-interop/main.rs b/examples/gl-interop/main.rs index a6d30222..3a34d12c 100644 --- a/examples/gl-interop/main.rs +++ b/examples/gl-interop/main.rs @@ -20,8 +20,9 @@ mod linux { use vulkano::{ buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage, Subbuffer}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, RecordingCommandBuffer, - RenderPassBeginInfo, SemaphoreSubmitInfo, SubmitInfo, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, RecordingCommandBuffer, RenderPassBeginInfo, SemaphoreSubmitInfo, + SubmitInfo, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, @@ -390,10 +391,14 @@ mod linux { recreate_swapchain = true; } - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); builder diff --git a/examples/image-self-copy-blit/main.rs b/examples/image-self-copy-blit/main.rs index 3cf0b349..7eedcab3 100644 --- a/examples/image-self-copy-blit/main.rs +++ b/examples/image-self-copy-blit/main.rs @@ -3,8 +3,9 @@ use vulkano::{ buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage}, command_buffer::{ allocator::StandardCommandBufferAllocator, BlitImageInfo, BufferImageCopy, - ClearColorImageInfo, CommandBufferUsage, CopyBufferToImageInfo, CopyImageInfo, ImageBlit, - ImageCopy, RecordingCommandBuffer, RenderPassBeginInfo, + ClearColorImageInfo, CommandBufferBeginInfo, CommandBufferLevel, CommandBufferUsage, + CopyBufferToImageInfo, CopyImageInfo, ImageBlit, ImageCopy, RecordingCommandBuffer, + RenderPassBeginInfo, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, @@ -210,10 +211,14 @@ fn main() -> Result<(), impl Error> { Default::default(), )); - let mut uploads = RecordingCommandBuffer::primary( + let mut uploads = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); @@ -470,10 +475,14 @@ fn main() -> Result<(), impl Error> { recreate_swapchain = true; } - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); builder diff --git a/examples/image/main.rs b/examples/image/main.rs index fc2225ef..67a52845 100644 --- a/examples/image/main.rs +++ b/examples/image/main.rs @@ -2,8 +2,8 @@ use std::{error::Error, sync::Arc}; use vulkano::{ buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, CopyBufferToImageInfo, - RecordingCommandBuffer, RenderPassBeginInfo, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, CopyBufferToImageInfo, RecordingCommandBuffer, RenderPassBeginInfo, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, @@ -210,10 +210,14 @@ fn main() -> Result<(), impl Error> { Default::default(), )); - let mut uploads = RecordingCommandBuffer::primary( + let mut uploads = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); @@ -418,10 +422,14 @@ fn main() -> Result<(), impl Error> { recreate_swapchain = true; } - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); builder diff --git a/examples/immutable-sampler/main.rs b/examples/immutable-sampler/main.rs index 74035b60..354f0ef7 100644 --- a/examples/immutable-sampler/main.rs +++ b/examples/immutable-sampler/main.rs @@ -11,8 +11,8 @@ use std::{error::Error, sync::Arc}; use vulkano::{ buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, CopyBufferToImageInfo, - RecordingCommandBuffer, RenderPassBeginInfo, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, CopyBufferToImageInfo, RecordingCommandBuffer, RenderPassBeginInfo, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, @@ -216,10 +216,14 @@ fn main() -> Result<(), impl Error> { Default::default(), )); - let mut uploads = RecordingCommandBuffer::primary( + let mut uploads = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); @@ -436,10 +440,14 @@ fn main() -> Result<(), impl Error> { recreate_swapchain = true; } - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); builder diff --git a/examples/indirect/main.rs b/examples/indirect/main.rs index ef658996..f205e00b 100644 --- a/examples/indirect/main.rs +++ b/examples/indirect/main.rs @@ -21,8 +21,8 @@ use vulkano::{ BufferContents, BufferUsage, }, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, DrawIndirectCommand, - RecordingCommandBuffer, RenderPassBeginInfo, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, DrawIndirectCommand, RecordingCommandBuffer, RenderPassBeginInfo, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, @@ -467,10 +467,14 @@ fn main() -> Result<(), impl Error> { ) .unwrap(); - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); diff --git a/examples/instancing/main.rs b/examples/instancing/main.rs index d9ed7a5b..227f5b0c 100644 --- a/examples/instancing/main.rs +++ b/examples/instancing/main.rs @@ -7,8 +7,8 @@ use std::{error::Error, sync::Arc}; use vulkano::{ buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, RecordingCommandBuffer, - RenderPassBeginInfo, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, RecordingCommandBuffer, RenderPassBeginInfo, }, device::{ physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo, @@ -402,10 +402,14 @@ fn main() -> Result<(), impl Error> { recreate_swapchain = true; } - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); builder diff --git a/examples/interactive-fractal/fractal_compute_pipeline.rs b/examples/interactive-fractal/fractal_compute_pipeline.rs index 337e5ac3..deb0c700 100644 --- a/examples/interactive-fractal/fractal_compute_pipeline.rs +++ b/examples/interactive-fractal/fractal_compute_pipeline.rs @@ -4,7 +4,8 @@ use std::sync::Arc; use vulkano::{ buffer::{Buffer, BufferCreateInfo, BufferUsage, Subbuffer}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, RecordingCommandBuffer, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, RecordingCommandBuffer, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, @@ -147,10 +148,14 @@ impl FractalComputePipeline { [], ) .unwrap(); - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( self.command_buffer_allocator.clone(), self.queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); diff --git a/examples/interactive-fractal/pixels_draw_pipeline.rs b/examples/interactive-fractal/pixels_draw_pipeline.rs index 151628aa..d88d5061 100644 --- a/examples/interactive-fractal/pixels_draw_pipeline.rs +++ b/examples/interactive-fractal/pixels_draw_pipeline.rs @@ -2,8 +2,9 @@ use std::sync::Arc; use vulkano::{ buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage, Subbuffer}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferInheritanceInfo, - CommandBufferUsage, RecordingCommandBuffer, SecondaryAutoCommandBuffer, + allocator::StandardCommandBufferAllocator, CommandBuffer, CommandBufferBeginInfo, + CommandBufferInheritanceInfo, CommandBufferLevel, CommandBufferUsage, + RecordingCommandBuffer, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, @@ -199,17 +200,17 @@ impl PixelsDrawPipeline { } /// Draws input `image` over a quad of size -1.0 to 1.0. - pub fn draw( - &self, - viewport_dimensions: [u32; 2], - image: Arc, - ) -> Arc { - let mut builder = RecordingCommandBuffer::secondary( + pub fn draw(&self, viewport_dimensions: [u32; 2], image: Arc) -> Arc { + let mut builder = RecordingCommandBuffer::new( self.command_buffer_allocator.clone(), self.gfx_queue.queue_family_index(), - CommandBufferUsage::MultipleSubmit, - CommandBufferInheritanceInfo { - render_pass: Some(self.subpass.clone().into()), + CommandBufferLevel::Secondary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::MultipleSubmit, + inheritance_info: Some(CommandBufferInheritanceInfo { + render_pass: Some(self.subpass.clone().into()), + ..Default::default() + }), ..Default::default() }, ) diff --git a/examples/interactive-fractal/place_over_frame.rs b/examples/interactive-fractal/place_over_frame.rs index 7ac1b24f..6633036b 100644 --- a/examples/interactive-fractal/place_over_frame.rs +++ b/examples/interactive-fractal/place_over_frame.rs @@ -2,8 +2,9 @@ use crate::pixels_draw_pipeline::PixelsDrawPipeline; use std::sync::Arc; use vulkano::{ command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, RecordingCommandBuffer, - RenderPassBeginInfo, SubpassBeginInfo, SubpassContents, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, RecordingCommandBuffer, RenderPassBeginInfo, SubpassBeginInfo, + SubpassContents, }, descriptor_set::allocator::StandardDescriptorSetAllocator, device::Queue, @@ -88,10 +89,14 @@ impl RenderPassPlaceOverFrame { .unwrap(); // Create primary command buffer builder. - let mut command_buffer_builder = RecordingCommandBuffer::primary( + let mut command_buffer_builder = RecordingCommandBuffer::new( self.command_buffer_allocator.clone(), self.gfx_queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); diff --git a/examples/msaa-renderpass/main.rs b/examples/msaa-renderpass/main.rs index 0ae97d0c..7be7d562 100644 --- a/examples/msaa-renderpass/main.rs +++ b/examples/msaa-renderpass/main.rs @@ -57,8 +57,8 @@ use std::{fs::File, io::BufWriter, path::Path, sync::Arc}; use vulkano::{ buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, CopyImageToBufferInfo, - RecordingCommandBuffer, RenderPassBeginInfo, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, CopyImageToBufferInfo, RecordingCommandBuffer, RenderPassBeginInfo, }, device::{ physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo, @@ -380,10 +380,14 @@ fn main() { ) .unwrap(); - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator, queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); builder diff --git a/examples/multi-window-game-of-life/game_of_life.rs b/examples/multi-window-game-of-life/game_of_life.rs index 69f4cee2..51642aba 100644 --- a/examples/multi-window-game-of-life/game_of_life.rs +++ b/examples/multi-window-game-of-life/game_of_life.rs @@ -5,8 +5,8 @@ use std::sync::Arc; use vulkano::{ buffer::{Buffer, BufferCreateInfo, BufferUsage, Subbuffer}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, PrimaryAutoCommandBuffer, - RecordingCommandBuffer, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, RecordingCommandBuffer, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, @@ -130,10 +130,14 @@ impl GameOfLifeComputePipeline { life_color: [f32; 4], dead_color: [f32; 4], ) -> Box { - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( self.command_buffer_allocator.clone(), self.compute_queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); @@ -163,7 +167,7 @@ impl GameOfLifeComputePipeline { /// Builds the command for a dispatch. fn dispatch( &self, - builder: &mut RecordingCommandBuffer, + builder: &mut RecordingCommandBuffer, life_color: [f32; 4], dead_color: [f32; 4], // Step determines whether we color or compute life (see branch in the shader)s. diff --git a/examples/multi-window-game-of-life/pixels_draw.rs b/examples/multi-window-game-of-life/pixels_draw.rs index ddbea940..d0965db2 100644 --- a/examples/multi-window-game-of-life/pixels_draw.rs +++ b/examples/multi-window-game-of-life/pixels_draw.rs @@ -3,8 +3,9 @@ use std::sync::Arc; use vulkano::{ buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage, Subbuffer}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferInheritanceInfo, - CommandBufferUsage, RecordingCommandBuffer, SecondaryAutoCommandBuffer, + allocator::StandardCommandBufferAllocator, CommandBuffer, CommandBufferBeginInfo, + CommandBufferInheritanceInfo, CommandBufferLevel, CommandBufferUsage, + RecordingCommandBuffer, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, @@ -195,17 +196,17 @@ impl PixelsDrawPipeline { } /// Draws input `image` over a quad of size -1.0 to 1.0. - pub fn draw( - &self, - viewport_dimensions: [u32; 2], - image: Arc, - ) -> Arc { - let mut builder = RecordingCommandBuffer::secondary( + pub fn draw(&self, viewport_dimensions: [u32; 2], image: Arc) -> Arc { + let mut builder = RecordingCommandBuffer::new( self.command_buffer_allocator.clone(), self.gfx_queue.queue_family_index(), - CommandBufferUsage::MultipleSubmit, - CommandBufferInheritanceInfo { - render_pass: Some(self.subpass.clone().into()), + CommandBufferLevel::Secondary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::MultipleSubmit, + inheritance_info: Some(CommandBufferInheritanceInfo { + render_pass: Some(self.subpass.clone().into()), + ..Default::default() + }), ..Default::default() }, ) diff --git a/examples/multi-window-game-of-life/render_pass.rs b/examples/multi-window-game-of-life/render_pass.rs index 636bf195..62c59040 100644 --- a/examples/multi-window-game-of-life/render_pass.rs +++ b/examples/multi-window-game-of-life/render_pass.rs @@ -2,8 +2,9 @@ use crate::{app::App, pixels_draw::PixelsDrawPipeline}; use std::sync::Arc; use vulkano::{ command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, RecordingCommandBuffer, - RenderPassBeginInfo, SubpassBeginInfo, SubpassContents, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, RecordingCommandBuffer, RenderPassBeginInfo, SubpassBeginInfo, + SubpassContents, }, device::Queue, format::Format, @@ -78,10 +79,14 @@ impl RenderPassPlaceOverFrame { .unwrap(); // Create a primary command buffer builder. - let mut command_buffer_builder = RecordingCommandBuffer::primary( + let mut command_buffer_builder = RecordingCommandBuffer::new( self.command_buffer_allocator.clone(), self.gfx_queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); diff --git a/examples/multi-window/main.rs b/examples/multi-window/main.rs index 4bd3ab18..adbac3c1 100644 --- a/examples/multi-window/main.rs +++ b/examples/multi-window/main.rs @@ -11,8 +11,8 @@ use std::{collections::HashMap, error::Error, sync::Arc}; use vulkano::{ buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, RecordingCommandBuffer, - RenderPassBeginInfo, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, RecordingCommandBuffer, RenderPassBeginInfo, }, device::{ physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo, @@ -447,10 +447,14 @@ fn main() -> Result<(), impl Error> { *recreate_swapchain = true; } - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); diff --git a/examples/multiview/main.rs b/examples/multiview/main.rs index 76340330..8770c2b0 100644 --- a/examples/multiview/main.rs +++ b/examples/multiview/main.rs @@ -7,8 +7,9 @@ use std::{fs::File, io::BufWriter, path::Path, sync::Arc}; use vulkano::{ buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage, Subbuffer}, command_buffer::{ - allocator::StandardCommandBufferAllocator, BufferImageCopy, CommandBufferUsage, - CopyImageToBufferInfo, RecordingCommandBuffer, RenderPassBeginInfo, + allocator::StandardCommandBufferAllocator, BufferImageCopy, CommandBufferBeginInfo, + CommandBufferLevel, CommandBufferUsage, CopyImageToBufferInfo, RecordingCommandBuffer, + RenderPassBeginInfo, }, device::{ physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, Features, @@ -330,10 +331,14 @@ fn main() { let buffer1 = create_buffer(); let buffer2 = create_buffer(); - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator, queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); diff --git a/examples/occlusion-query/main.rs b/examples/occlusion-query/main.rs index 0df509bf..a5e31bad 100644 --- a/examples/occlusion-query/main.rs +++ b/examples/occlusion-query/main.rs @@ -6,8 +6,8 @@ use std::{error::Error, sync::Arc}; use vulkano::{ buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, RecordingCommandBuffer, - RenderPassBeginInfo, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, RecordingCommandBuffer, RenderPassBeginInfo, }, device::{ physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo, @@ -426,10 +426,14 @@ fn main() -> Result<(), impl Error> { recreate_swapchain = true; } - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); diff --git a/examples/push-constants/main.rs b/examples/push-constants/main.rs index 0812584c..35c235df 100644 --- a/examples/push-constants/main.rs +++ b/examples/push-constants/main.rs @@ -7,7 +7,8 @@ use std::sync::Arc; use vulkano::{ buffer::{Buffer, BufferCreateInfo, BufferUsage}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, RecordingCommandBuffer, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, RecordingCommandBuffer, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, @@ -180,10 +181,14 @@ fn main() { // // Note that there is no type safety for the push constant data, so be careful to only pass an // instance of the struct generated by the `vulkano_shaders::shaders!` macro. - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator, queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); builder diff --git a/examples/push-descriptors/main.rs b/examples/push-descriptors/main.rs index 57710f94..9fefa3f1 100644 --- a/examples/push-descriptors/main.rs +++ b/examples/push-descriptors/main.rs @@ -2,8 +2,8 @@ use std::{error::Error, sync::Arc}; use vulkano::{ buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, CopyBufferToImageInfo, - RecordingCommandBuffer, RenderPassBeginInfo, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, CopyBufferToImageInfo, RecordingCommandBuffer, RenderPassBeginInfo, }, descriptor_set::{layout::DescriptorSetLayoutCreateFlags, WriteDescriptorSet}, device::{ @@ -201,10 +201,14 @@ fn main() -> Result<(), impl Error> { device.clone(), Default::default(), )); - let mut uploads = RecordingCommandBuffer::primary( + let mut uploads = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); @@ -405,10 +409,14 @@ fn main() -> Result<(), impl Error> { recreate_swapchain = true; } - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); builder diff --git a/examples/runtime-array/main.rs b/examples/runtime-array/main.rs index 55830c75..2fcb5e51 100644 --- a/examples/runtime-array/main.rs +++ b/examples/runtime-array/main.rs @@ -2,8 +2,8 @@ use std::{error::Error, io::Cursor, sync::Arc}; use vulkano::{ buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, CopyBufferToImageInfo, - RecordingCommandBuffer, RenderPassBeginInfo, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, CopyBufferToImageInfo, RecordingCommandBuffer, RenderPassBeginInfo, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, layout::DescriptorBindingFlags, DescriptorSet, @@ -270,10 +270,14 @@ fn main() -> Result<(), impl Error> { Default::default(), )); - let mut uploads = RecordingCommandBuffer::primary( + let mut uploads = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); @@ -539,10 +543,14 @@ fn main() -> Result<(), impl Error> { recreate_swapchain = true; } - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); builder diff --git a/examples/runtime-shader/main.rs b/examples/runtime-shader/main.rs index bf47cc80..6233d204 100644 --- a/examples/runtime-shader/main.rs +++ b/examples/runtime-shader/main.rs @@ -16,8 +16,8 @@ use std::{error::Error, fs::File, io::Read, path::Path, sync::Arc}; use vulkano::{ buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, RecordingCommandBuffer, - RenderPassBeginInfo, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, RecordingCommandBuffer, RenderPassBeginInfo, }, device::{ physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo, @@ -348,10 +348,14 @@ fn main() -> Result<(), impl Error> { recreate_swapchain = true; } - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::MultipleSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::MultipleSubmit, + ..Default::default() + }, ) .unwrap(); builder diff --git a/examples/self-copy-buffer/main.rs b/examples/self-copy-buffer/main.rs index 3067b358..b598901c 100644 --- a/examples/self-copy-buffer/main.rs +++ b/examples/self-copy-buffer/main.rs @@ -6,8 +6,8 @@ use std::sync::Arc; use vulkano::{ buffer::{Buffer, BufferCreateInfo, BufferUsage}, command_buffer::{ - allocator::StandardCommandBufferAllocator, BufferCopy, CommandBufferUsage, - CopyBufferInfoTyped, RecordingCommandBuffer, + allocator::StandardCommandBufferAllocator, BufferCopy, CommandBufferBeginInfo, + CommandBufferLevel, CommandBufferUsage, CopyBufferInfoTyped, RecordingCommandBuffer, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, @@ -162,10 +162,14 @@ fn main() { ) .unwrap(); - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator, queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); builder diff --git a/examples/shader-include/main.rs b/examples/shader-include/main.rs index a5e3e0db..8f223236 100644 --- a/examples/shader-include/main.rs +++ b/examples/shader-include/main.rs @@ -6,7 +6,8 @@ use std::sync::Arc; use vulkano::{ buffer::{Buffer, BufferCreateInfo, BufferUsage}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, RecordingCommandBuffer, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, RecordingCommandBuffer, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, @@ -166,10 +167,14 @@ fn main() { ) .unwrap(); - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator, queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); builder diff --git a/examples/shader-types-sharing/main.rs b/examples/shader-types-sharing/main.rs index cb408316..93fd7205 100644 --- a/examples/shader-types-sharing/main.rs +++ b/examples/shader-types-sharing/main.rs @@ -20,7 +20,8 @@ use std::sync::Arc; use vulkano::{ buffer::{Buffer, BufferCreateInfo, BufferUsage, Subbuffer}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, RecordingCommandBuffer, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, RecordingCommandBuffer, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, @@ -192,10 +193,14 @@ fn main() { ) .unwrap(); - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator, queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); builder diff --git a/examples/simple-particles/main.rs b/examples/simple-particles/main.rs index a3b38edd..655f85e8 100644 --- a/examples/simple-particles/main.rs +++ b/examples/simple-particles/main.rs @@ -7,8 +7,8 @@ use std::{error::Error, sync::Arc, time::SystemTime}; use vulkano::{ buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, CopyBufferInfo, - RecordingCommandBuffer, RenderPassBeginInfo, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, CopyBufferInfo, RecordingCommandBuffer, RenderPassBeginInfo, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, @@ -386,10 +386,14 @@ fn main() -> Result<(), impl Error> { .unwrap(); // Create one-time command to copy between the buffers. - let mut cbb = RecordingCommandBuffer::primary( + let mut cbb = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); cbb.copy_buffer(CopyBufferInfo::buffers( @@ -581,10 +585,14 @@ fn main() -> Result<(), impl Error> { None => sync::now(device.clone()).boxed(), }; - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); builder diff --git a/examples/specialization-constants/main.rs b/examples/specialization-constants/main.rs index 20d9afed..97ccc1b9 100644 --- a/examples/specialization-constants/main.rs +++ b/examples/specialization-constants/main.rs @@ -4,7 +4,8 @@ use std::sync::Arc; use vulkano::{ buffer::{Buffer, BufferCreateInfo, BufferUsage}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, RecordingCommandBuffer, + allocator::StandardCommandBufferAllocator, CommandBufferLevel, CommandBufferUsage, + RecordingCommandBuffer, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, @@ -167,10 +168,14 @@ fn main() { ) .unwrap(); - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator, queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + vulkano::command_buffer::CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); builder diff --git a/examples/teapot/main.rs b/examples/teapot/main.rs index a02962a7..3d1d9133 100644 --- a/examples/teapot/main.rs +++ b/examples/teapot/main.rs @@ -7,8 +7,8 @@ use vulkano::{ Buffer, BufferCreateInfo, BufferUsage, }, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, RecordingCommandBuffer, - RenderPassBeginInfo, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, RecordingCommandBuffer, RenderPassBeginInfo, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, @@ -365,10 +365,14 @@ fn main() -> Result<(), impl Error> { recreate_swapchain = true; } - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); builder diff --git a/examples/tessellation/main.rs b/examples/tessellation/main.rs index 11f1dc96..e6b65911 100644 --- a/examples/tessellation/main.rs +++ b/examples/tessellation/main.rs @@ -16,8 +16,8 @@ use std::{error::Error, sync::Arc}; use vulkano::{ buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, RecordingCommandBuffer, - RenderPassBeginInfo, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, RecordingCommandBuffer, RenderPassBeginInfo, }, device::{ physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, Features, @@ -466,10 +466,14 @@ fn main() -> Result<(), impl Error> { recreate_swapchain = true; } - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); builder diff --git a/examples/texture-array/main.rs b/examples/texture-array/main.rs index a7caef5c..0e4a42a1 100644 --- a/examples/texture-array/main.rs +++ b/examples/texture-array/main.rs @@ -2,8 +2,8 @@ use std::{error::Error, sync::Arc}; use vulkano::{ buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, CopyBufferToImageInfo, - RecordingCommandBuffer, RenderPassBeginInfo, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, CopyBufferToImageInfo, RecordingCommandBuffer, RenderPassBeginInfo, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, @@ -212,10 +212,14 @@ fn main() -> Result<(), impl Error> { Default::default(), )); - let mut uploads = RecordingCommandBuffer::primary( + let mut uploads = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); @@ -429,10 +433,14 @@ fn main() -> Result<(), impl Error> { recreate_swapchain = true; } - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); builder diff --git a/examples/triangle-v1_3/main.rs b/examples/triangle-v1_3/main.rs index 9e27ef61..5a51e520 100644 --- a/examples/triangle-v1_3/main.rs +++ b/examples/triangle-v1_3/main.rs @@ -16,8 +16,8 @@ use std::{error::Error, sync::Arc}; use vulkano::{ buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, RecordingCommandBuffer, - RenderingAttachmentInfo, RenderingInfo, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, RecordingCommandBuffer, RenderingAttachmentInfo, RenderingInfo, }, device::{ physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, Features, @@ -597,10 +597,14 @@ fn main() -> Result<(), impl Error> { // // Note that we have to pass a queue family when we create the command buffer. The // command buffer will only be executable on that given queue family. - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); diff --git a/examples/triangle/main.rs b/examples/triangle/main.rs index 5b7c7039..e1a12b7e 100644 --- a/examples/triangle/main.rs +++ b/examples/triangle/main.rs @@ -11,8 +11,9 @@ use std::{error::Error, sync::Arc}; use vulkano::{ buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, RecordingCommandBuffer, - RenderPassBeginInfo, SubpassBeginInfo, SubpassContents, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, RecordingCommandBuffer, RenderPassBeginInfo, SubpassBeginInfo, + SubpassContents, }, device::{ physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo, @@ -599,10 +600,14 @@ fn main() -> Result<(), impl Error> { // // Note that we have to pass a queue family when we create the command buffer. The // command buffer will only be executable on that given queue family. - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( command_buffer_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); diff --git a/vulkano/src/buffer/allocator.rs b/vulkano/src/buffer/allocator.rs index a92ccd8a..ad1929cf 100644 --- a/vulkano/src/buffer/allocator.rs +++ b/vulkano/src/buffer/allocator.rs @@ -78,7 +78,9 @@ const MAX_ARENAS: usize = 32; /// allocator::{SubbufferAllocator, SubbufferAllocatorCreateInfo}, /// BufferUsage, /// }, -/// command_buffer::{CommandBufferUsage, RecordingCommandBuffer}, +/// command_buffer::{ +/// CommandBufferBeginInfo, CommandBufferLevel, CommandBufferUsage, RecordingCommandBuffer, +/// }, /// memory::allocator::MemoryTypeFilter, /// sync::GpuFuture, /// }; @@ -105,10 +107,14 @@ const MAX_ARENAS: usize = 32; /// *subbuffer.write().unwrap() = data; /// /// // You can then use `subbuffer` as if it was an entirely separate buffer. -/// RecordingCommandBuffer::primary( +/// RecordingCommandBuffer::new( /// command_buffer_allocator.clone(), /// queue.queue_family_index(), -/// CommandBufferUsage::OneTimeSubmit, +/// CommandBufferLevel::Primary, +/// CommandBufferBeginInfo { +/// usage: CommandBufferUsage::OneTimeSubmit, +/// ..Default::default() +/// }, /// ) /// .unwrap() /// // For the sake of the example we just call `update_buffer` on the buffer, even though diff --git a/vulkano/src/buffer/mod.rs b/vulkano/src/buffer/mod.rs index 32da1572..46ee0043 100644 --- a/vulkano/src/buffer/mod.rs +++ b/vulkano/src/buffer/mod.rs @@ -121,7 +121,10 @@ pub mod view; /// ``` /// use vulkano::{ /// buffer::{BufferUsage, Buffer, BufferCreateInfo}, -/// command_buffer::{CommandBufferUsage, CopyBufferInfo, RecordingCommandBuffer}, +/// command_buffer::{ +/// CommandBufferBeginInfo, CommandBufferLevel, CommandBufferUsage, CopyBufferInfo, +/// RecordingCommandBuffer, +/// }, /// memory::allocator::{AllocationCreateInfo, MemoryTypeFilter}, /// sync::GpuFuture, /// DeviceSize, @@ -171,10 +174,14 @@ pub mod view; /// .unwrap(); /// /// // Create a one-time command to copy between the buffers. -/// let mut cbb = RecordingCommandBuffer::primary( +/// let mut cbb = RecordingCommandBuffer::new( /// command_buffer_allocator.clone(), /// queue.queue_family_index(), -/// CommandBufferUsage::OneTimeSubmit, +/// CommandBufferLevel::Primary, +/// CommandBufferBeginInfo { +/// usage: CommandBufferUsage::OneTimeSubmit, +/// ..Default::default() +/// }, /// ) /// .unwrap(); /// cbb.copy_buffer(CopyBufferInfo::buffers( diff --git a/vulkano/src/command_buffer/auto/builder.rs b/vulkano/src/command_buffer/auto/builder.rs index 3a6be7ce..cedf1e36 100644 --- a/vulkano/src/command_buffer/auto/builder.rs +++ b/vulkano/src/command_buffer/auto/builder.rs @@ -1,18 +1,16 @@ use super::{ - CommandInfo, PrimaryAutoCommandBuffer, RenderPassCommand, Resource, ResourceUseRef2, - SubmitState, + CommandBuffer, CommandInfo, RenderPassCommand, Resource, ResourceUseRef2, SubmitState, }; use crate::{ buffer::{Buffer, IndexBuffer, Subbuffer}, command_buffer::{ allocator::CommandBufferAllocator, - sys::{CommandBufferBeginInfo, RawCommandBuffer, RawRecordingCommandBuffer}, + sys::{CommandBufferBeginInfo, RawRecordingCommandBuffer}, CommandBufferBufferRangeUsage, CommandBufferBufferUsage, CommandBufferImageRangeUsage, CommandBufferImageUsage, CommandBufferInheritanceInfo, CommandBufferInheritanceRenderPassType, CommandBufferLevel, CommandBufferResourcesUsage, - CommandBufferUsage, RenderingInfo, ResourceUseRef, SecondaryAutoCommandBuffer, - SecondaryCommandBufferBufferUsage, SecondaryCommandBufferImageUsage, - SecondaryCommandBufferResourcesUsage, SubpassContents, + CommandBufferUsage, RenderingInfo, ResourceUseRef, SecondaryCommandBufferBufferUsage, + SecondaryCommandBufferImageUsage, SecondaryCommandBufferResourcesUsage, SubpassContents, }, descriptor_set::{DescriptorSetResources, DescriptorSetWithOffsets}, device::{Device, DeviceOwned}, @@ -45,7 +43,6 @@ use smallvec::SmallVec; use std::{ collections::hash_map::Entry, fmt::Debug, - marker::PhantomData, mem::take, ops::{Range, RangeInclusive}, sync::{atomic::AtomicBool, Arc}, @@ -58,134 +55,42 @@ use std::{ /// /// Note that command buffers in the recording state don't implement the `Send` and `Sync` traits. /// Once a command buffer has finished recording, however, it *does* implement `Send` and `Sync`. -pub struct RecordingCommandBuffer { +pub struct RecordingCommandBuffer { pub(in crate::command_buffer) inner: RawRecordingCommandBuffer, commands: Vec<( CommandInfo, Box, )>, pub(in crate::command_buffer) builder_state: CommandBufferBuilderState, - _data: PhantomData, } -impl RecordingCommandBuffer { - /// Starts recording a primary command buffer. +impl RecordingCommandBuffer { + /// Allocates and begins recording a new command buffer. #[inline] - pub fn primary( - allocator: Arc, - queue_family_index: u32, - usage: CommandBufferUsage, - ) -> Result, Validated> { - unsafe { - RecordingCommandBuffer::begin( - allocator, - queue_family_index, - CommandBufferLevel::Primary, - CommandBufferBeginInfo { - usage, - inheritance_info: None, - _ne: crate::NonExhaustive(()), - }, - ) - } - } - - #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] - #[inline] - pub unsafe fn primary_unchecked( - allocator: Arc, - queue_family_index: u32, - usage: CommandBufferUsage, - ) -> Result, Validated> { - RecordingCommandBuffer::begin_unchecked( - allocator, - queue_family_index, - CommandBufferLevel::Primary, - CommandBufferBeginInfo { - usage, - inheritance_info: None, - _ne: crate::NonExhaustive(()), - }, - ) - } -} - -impl RecordingCommandBuffer { - /// Starts recording a secondary command buffer. - #[inline] - pub fn secondary( - allocator: Arc, - queue_family_index: u32, - usage: CommandBufferUsage, - inheritance_info: CommandBufferInheritanceInfo, - ) -> Result, Validated> { - unsafe { - RecordingCommandBuffer::begin( - allocator, - queue_family_index, - CommandBufferLevel::Secondary, - CommandBufferBeginInfo { - usage, - inheritance_info: Some(inheritance_info), - _ne: crate::NonExhaustive(()), - }, - ) - } - } - - #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] - #[inline] - pub unsafe fn secondary_unchecked( - allocator: Arc, - queue_family_index: u32, - usage: CommandBufferUsage, - inheritance_info: CommandBufferInheritanceInfo, - ) -> Result, Validated> { - RecordingCommandBuffer::begin_unchecked( - allocator, - queue_family_index, - CommandBufferLevel::Secondary, - CommandBufferBeginInfo { - usage, - inheritance_info: Some(inheritance_info), - _ne: crate::NonExhaustive(()), - }, - ) - } -} - -impl RecordingCommandBuffer { - /// Actual constructor. Private. - /// - /// # Safety - /// - /// `begin_info.inheritance_info` must match `level`. - unsafe fn begin( + pub fn new( allocator: Arc, queue_family_index: u32, level: CommandBufferLevel, begin_info: CommandBufferBeginInfo, - ) -> Result, Validated> { - Self::validate_begin(allocator.device(), queue_family_index, level, &begin_info)?; + ) -> Result> { + Self::validate_new(allocator.device(), queue_family_index, level, &begin_info)?; - unsafe { Self::begin_unchecked(allocator, queue_family_index, level, begin_info) } + unsafe { Self::new_unchecked(allocator, queue_family_index, level, begin_info) } } - fn validate_begin( + fn validate_new( device: &Device, - _queue_family_index: u32, - _level: CommandBufferLevel, + queue_family_index: u32, + level: CommandBufferLevel, begin_info: &CommandBufferBeginInfo, ) -> Result<(), Box> { - begin_info - .validate(device) - .map_err(|err| err.add_context("begin_info"))?; + RawRecordingCommandBuffer::validate_new(device, queue_family_index, level, begin_info)?; Ok(()) } - #[inline] - unsafe fn begin_unchecked( + #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] + pub unsafe fn new_unchecked( allocator: Arc, queue_family_index: u32, level: CommandBufferLevel, @@ -212,28 +117,53 @@ impl RecordingCommandBuffer { } } - let inner = - RawRecordingCommandBuffer::new(allocator, queue_family_index, level, begin_info)?; + let inner = RawRecordingCommandBuffer::new_unchecked( + allocator, + queue_family_index, + level, + begin_info, + )?; Ok(RecordingCommandBuffer { inner, commands: Vec::new(), builder_state, - _data: PhantomData, }) } - unsafe fn end_unchecked( - mut self, - ) -> Result< - ( - RawCommandBuffer, - Vec>, - CommandBufferResourcesUsage, - SecondaryCommandBufferResourcesUsage, - ), - Validated, - > { + /// Ends the recording, returning a command buffer which can be submitted. + #[inline] + pub fn end(self) -> Result, Validated> { + self.validate_end()?; + + unsafe { self.end_unchecked() } + } + + fn validate_end(&self) -> Result<(), Box> { + if self.level() == CommandBufferLevel::Primary && self.builder_state.render_pass.is_some() { + return Err(Box::new(ValidationError { + problem: "a render pass instance is still active".into(), + vuids: &["VUID-vkEndCommandBuffer-commandBuffer-00060"], + ..Default::default() + })); + } + + if !self.builder_state.queries.is_empty() { + return Err(Box::new(ValidationError { + problem: "a query is still active".into(), + vuids: &["VUID-vkEndCommandBuffer-commandBuffer-00061"], + ..Default::default() + })); + } + + // TODO: + // VUID-vkEndCommandBuffer-commandBuffer-01815 + + Ok(()) + } + + #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] + pub unsafe fn end_unchecked(mut self) -> Result, Validated> { let mut auto_sync_state = AutoSyncState::new( self.device().clone(), self.inner.level(), @@ -298,65 +228,6 @@ impl RecordingCommandBuffer { debug_assert!(barriers.is_empty()); - Ok(( - self.inner.end()?, - self.commands - .into_iter() - .map(|(_, record_func)| record_func) - .collect(), - resources_usage, - secondary_resources_usage, - )) - } -} - -impl RecordingCommandBuffer { - /// Ends the recording, returning a command buffer which can be submitted. - pub fn end(self) -> Result, Validated> { - if self.builder_state.render_pass.is_some() { - return Err(Box::new(ValidationError { - problem: "a render pass instance is still active".into(), - vuids: &["VUID-vkEndCommandBuffer-commandBuffer-00060"], - ..Default::default() - }) - .into()); - } - - if !self.builder_state.queries.is_empty() { - return Err(Box::new(ValidationError { - problem: "a query is still active".into(), - vuids: &["VUID-vkEndCommandBuffer-commandBuffer-00061"], - ..Default::default() - }) - .into()); - } - - // TODO: - // VUID-vkEndCommandBuffer-commandBuffer-01815 - - let (inner, keep_alive_objects, resources_usage, _) = unsafe { self.end_unchecked()? }; - - Ok(Arc::new(PrimaryAutoCommandBuffer { - inner, - _keep_alive_objects: keep_alive_objects, - resources_usage, - state: Mutex::new(Default::default()), - })) - } -} - -impl RecordingCommandBuffer { - /// Ends the recording, returning a command buffer which can be submitted. - pub fn end(self) -> Result, Validated> { - if !self.builder_state.queries.is_empty() { - return Err(Box::new(ValidationError { - problem: "a query is still active".into(), - vuids: &["VUID-vkEndCommandBuffer-commandBuffer-00061"], - ..Default::default() - }) - .into()); - } - let submit_state = match self.inner.usage() { CommandBufferUsage::MultipleSubmit => SubmitState::ExclusiveUse { in_use: AtomicBool::new(false), @@ -367,18 +238,28 @@ impl RecordingCommandBuffer { }, }; - let (inner, keep_alive_objects, _, resources_usage) = unsafe { self.end_unchecked()? }; - - Ok(Arc::new(SecondaryAutoCommandBuffer { - inner, - _keep_alive_objects: keep_alive_objects, + Ok(Arc::new(CommandBuffer { + inner: self.inner.end()?, + _keep_alive_objects: self + .commands + .into_iter() + .map(|(_, record_func)| record_func) + .collect(), resources_usage, + secondary_resources_usage, + state: Mutex::new(Default::default()), submit_state, })) } + + /// Returns the level of the command buffer. + #[inline] + pub fn level(&self) -> CommandBufferLevel { + self.inner.level() + } } -impl RecordingCommandBuffer { +impl RecordingCommandBuffer { pub(in crate::command_buffer) fn add_command( &mut self, name: &'static str, @@ -428,7 +309,8 @@ impl RecordingCommandBuffer { } } -unsafe impl DeviceOwned for RecordingCommandBuffer { +unsafe impl DeviceOwned for RecordingCommandBuffer { + #[inline] fn device(&self) -> &Arc { self.inner.device() } diff --git a/vulkano/src/command_buffer/auto/mod.rs b/vulkano/src/command_buffer/auto/mod.rs index cbd6b93d..8056688b 100644 --- a/vulkano/src/command_buffer/auto/mod.rs +++ b/vulkano/src/command_buffer/auto/mod.rs @@ -63,9 +63,9 @@ pub(in crate::command_buffer) use self::builder::{ }; use super::{ sys::{RawCommandBuffer, RawRecordingCommandBuffer}, - CommandBufferInheritanceInfo, CommandBufferResourcesUsage, CommandBufferState, - CommandBufferUsage, ResourceInCommand, SecondaryCommandBufferResourcesUsage, - SecondaryResourceUseRef, + CommandBufferInheritanceInfo, CommandBufferLevel, CommandBufferResourcesUsage, + CommandBufferState, CommandBufferUsage, ResourceInCommand, + SecondaryCommandBufferResourcesUsage, SecondaryResourceUseRef, }; use crate::{ buffer::Subbuffer, @@ -86,67 +86,17 @@ use std::{ mod builder; -pub struct PrimaryAutoCommandBuffer { +pub struct CommandBuffer { inner: RawCommandBuffer, + // TODO: Remove all of this. _keep_alive_objects: Vec>, resources_usage: CommandBufferResourcesUsage, + secondary_resources_usage: SecondaryCommandBufferResourcesUsage, state: Mutex, -} - -unsafe impl VulkanObject for PrimaryAutoCommandBuffer { - type Handle = ash::vk::CommandBuffer; - - #[inline] - fn handle(&self) -> Self::Handle { - self.inner.handle() - } -} - -unsafe impl DeviceOwned for PrimaryAutoCommandBuffer { - #[inline] - fn device(&self) -> &Arc { - self.inner.device() - } -} - -impl Debug for PrimaryAutoCommandBuffer { - fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { - f.debug_struct("PrimaryAutoCommandBuffer") - .field("inner", &self.inner) - .finish_non_exhaustive() - } -} - -impl PrimaryAutoCommandBuffer { - /// Returns the queue family index of this command buffer. - #[inline] - pub fn queue_family_index(&self) -> u32 { - self.inner.queue_family_index() - } - - /// Returns the usage of this command buffer. - #[inline] - pub fn usage(&self) -> CommandBufferUsage { - self.inner.usage() - } - - pub(crate) fn state(&self) -> MutexGuard<'_, CommandBufferState> { - self.state.lock() - } - - pub(crate) fn resources_usage(&self) -> &CommandBufferResourcesUsage { - &self.resources_usage - } -} - -pub struct SecondaryAutoCommandBuffer { - inner: RawCommandBuffer, - _keep_alive_objects: Vec>, - resources_usage: SecondaryCommandBufferResourcesUsage, submit_state: SubmitState, } -unsafe impl VulkanObject for SecondaryAutoCommandBuffer { +unsafe impl VulkanObject for CommandBuffer { type Handle = ash::vk::CommandBuffer; #[inline] @@ -155,47 +105,71 @@ unsafe impl VulkanObject for SecondaryAutoCommandBuffer { } } -unsafe impl DeviceOwned for SecondaryAutoCommandBuffer { +unsafe impl DeviceOwned for CommandBuffer { #[inline] fn device(&self) -> &Arc { self.inner.device() } } -impl Debug for SecondaryAutoCommandBuffer { +impl Debug for CommandBuffer { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { - f.debug_struct("SecondaryAutoCommandBuffer") + f.debug_struct("CommandBuffer") .field("inner", &self.inner) .finish_non_exhaustive() } } -impl SecondaryAutoCommandBuffer { +impl CommandBuffer { /// Returns the inner raw command buffer. #[inline] pub fn inner(&self) -> &RawCommandBuffer { &self.inner } + /// Returns the queue family index of this command buffer. + #[inline] + pub fn queue_family_index(&self) -> u32 { + self.inner.queue_family_index() + } + + /// Returns the level of the command buffer. + #[inline] + pub fn level(&self) -> CommandBufferLevel { + self.inner.level() + } + /// Returns the usage of this command buffer. #[inline] pub fn usage(&self) -> CommandBufferUsage { self.inner.usage() } - /// Returns a `CommandBufferInheritance` value describing the properties that the command - /// buffer inherits from its parent primary command buffer. + /// Returns the inheritance info of the command buffer, if it is a secondary command buffer. #[inline] - pub fn inheritance_info(&self) -> &CommandBufferInheritanceInfo { - self.inner.inheritance_info().as_ref().unwrap() + pub fn inheritance_info(&self) -> Option<&CommandBufferInheritanceInfo> { + self.inner.inheritance_info() + } + + pub(crate) fn state(&self) -> MutexGuard<'_, CommandBufferState> { + debug_assert_eq!(self.level(), CommandBufferLevel::Primary); + + self.state.lock() + } + + pub(crate) fn resources_usage(&self) -> &CommandBufferResourcesUsage { + debug_assert_eq!(self.level(), CommandBufferLevel::Primary); + + &self.resources_usage } /// Checks whether this command buffer is allowed to be recorded to a command buffer, /// and if so locks it. /// /// If you call this function, then you should call `unlock` afterwards. - #[inline] - pub fn lock_record(&self) -> Result<(), Box> { + pub(crate) fn lock_record(&self) -> Result<(), Box> { + debug_assert_eq!(self.level(), CommandBufferLevel::Secondary); + match self.submit_state { SubmitState::OneTime { ref already_submitted, @@ -236,8 +210,9 @@ impl SecondaryAutoCommandBuffer { /// # Safety /// /// Must not be called if you haven't called `lock_record` before. - #[inline] - pub unsafe fn unlock(&self) { + pub(crate) unsafe fn unlock(&self) { + debug_assert_eq!(self.level(), CommandBufferLevel::Secondary); + match self.submit_state { SubmitState::OneTime { ref already_submitted, @@ -252,8 +227,8 @@ impl SecondaryAutoCommandBuffer { }; } - pub(crate) fn resources_usage(&self) -> &SecondaryCommandBufferResourcesUsage { - &self.resources_usage + pub(crate) fn secondary_resources_usage(&self) -> &SecondaryCommandBufferResourcesUsage { + &self.secondary_resources_usage } } @@ -336,7 +311,8 @@ mod tests { buffer::{Buffer, BufferCreateInfo, BufferUsage}, command_buffer::{ allocator::{StandardCommandBufferAllocator, StandardCommandBufferAllocatorCreateInfo}, - BufferCopy, CommandBufferUsage, CopyBufferInfoTyped, RecordingCommandBuffer, + BufferCopy, CommandBufferBeginInfo, CommandBufferLevel, CommandBufferUsage, + CopyBufferInfoTyped, RecordingCommandBuffer, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, @@ -364,10 +340,14 @@ mod tests { Default::default(), )); - RecordingCommandBuffer::primary( + RecordingCommandBuffer::new( allocator, queue.queue_family_index(), - CommandBufferUsage::MultipleSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::MultipleSubmit, + ..Default::default() + }, ) .unwrap(); } @@ -430,10 +410,14 @@ mod tests { device, Default::default(), )); - let mut cbb = RecordingCommandBuffer::primary( + let mut cbb = RecordingCommandBuffer::new( cb_allocator, queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); @@ -476,20 +460,28 @@ mod tests { )); // Make a secondary CB that doesn't support simultaneous use. - let builder = RecordingCommandBuffer::secondary( + let builder = RecordingCommandBuffer::new( cb_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::MultipleSubmit, - Default::default(), + CommandBufferLevel::Secondary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::MultipleSubmit, + inheritance_info: Some(Default::default()), + ..Default::default() + }, ) .unwrap(); let secondary = builder.end().unwrap(); { - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( cb_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::SimultaneousUse, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::SimultaneousUse, + ..Default::default() + }, ) .unwrap(); @@ -502,19 +494,27 @@ mod tests { } { - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( cb_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::SimultaneousUse, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::SimultaneousUse, + ..Default::default() + }, ) .unwrap(); builder.execute_commands(secondary.clone()).unwrap(); let cb1 = builder.end().unwrap(); - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( cb_allocator, queue.queue_family_index(), - CommandBufferUsage::SimultaneousUse, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::SimultaneousUse, + ..Default::default() + }, ) .unwrap(); @@ -553,10 +553,14 @@ mod tests { device, Default::default(), )); - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( cb_allocator, queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); @@ -611,10 +615,14 @@ mod tests { device, Default::default(), )); - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( cb_allocator, queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); @@ -644,10 +652,14 @@ mod tests { ..Default::default() }, )); - let cbb = RecordingCommandBuffer::primary( + let cbb = RecordingCommandBuffer::new( cb_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); @@ -680,11 +692,15 @@ mod tests { // Two secondary command buffers that both write to the buffer let secondary = (0..2) .map(|_| { - let mut builder = RecordingCommandBuffer::secondary( + let mut builder = RecordingCommandBuffer::new( cb_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::SimultaneousUse, - Default::default(), + CommandBufferLevel::Secondary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::SimultaneousUse, + inheritance_info: Some(Default::default()), + ..Default::default() + }, ) .unwrap(); builder @@ -695,10 +711,15 @@ mod tests { .collect::>(); { - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( cb_allocator.clone(), queue.queue_family_index(), - CommandBufferUsage::SimultaneousUse, + CommandBufferLevel::Secondary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::SimultaneousUse, + inheritance_info: Some(Default::default()), + ..Default::default() + }, ) .unwrap(); @@ -718,10 +739,15 @@ mod tests { } { - let mut builder = RecordingCommandBuffer::primary( + let mut builder = RecordingCommandBuffer::new( cb_allocator, queue.queue_family_index(), - CommandBufferUsage::SimultaneousUse, + CommandBufferLevel::Secondary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::SimultaneousUse, + inheritance_info: Some(Default::default()), + ..Default::default() + }, ) .unwrap(); @@ -745,10 +771,14 @@ mod tests { device.clone(), Default::default(), )); - let mut sync = RecordingCommandBuffer::primary( + let mut sync = RecordingCommandBuffer::new( cb_allocator, queue.queue_family_index(), - CommandBufferUsage::MultipleSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::MultipleSubmit, + ..Default::default() + }, ) .unwrap(); @@ -784,10 +814,14 @@ mod tests { device.clone(), Default::default(), )); - let mut sync = RecordingCommandBuffer::primary( + let mut sync = RecordingCommandBuffer::new( cb_allocator, queue.queue_family_index(), - CommandBufferUsage::MultipleSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::MultipleSubmit, + ..Default::default() + }, ) .unwrap(); let set_layout = DescriptorSetLayout::new( diff --git a/vulkano/src/command_buffer/commands/acceleration_structure.rs b/vulkano/src/command_buffer/commands/acceleration_structure.rs index 30635373..d8ccea56 100644 --- a/vulkano/src/command_buffer/commands/acceleration_structure.rs +++ b/vulkano/src/command_buffer/commands/acceleration_structure.rs @@ -24,7 +24,7 @@ use smallvec::SmallVec; use std::{mem::size_of, sync::Arc}; /// # Commands to do operations on acceleration structures. -impl RecordingCommandBuffer { +impl RecordingCommandBuffer { /// Builds or updates an acceleration structure. /// /// # Safety diff --git a/vulkano/src/command_buffer/commands/bind_push.rs b/vulkano/src/command_buffer/commands/bind_push.rs index 6d952ad7..5b8ffdc6 100644 --- a/vulkano/src/command_buffer/commands/bind_push.rs +++ b/vulkano/src/command_buffer/commands/bind_push.rs @@ -21,7 +21,7 @@ use std::{cmp::min, ffi::c_void, mem::size_of, ptr, sync::Arc}; /// # Commands to bind or push state for pipeline execution commands. /// /// These commands require a queue with a pipeline type that uses the given state. -impl RecordingCommandBuffer { +impl RecordingCommandBuffer { /// Binds descriptor sets for future dispatch or draw calls. pub fn bind_descriptor_sets( &mut self, diff --git a/vulkano/src/command_buffer/commands/clear.rs b/vulkano/src/command_buffer/commands/clear.rs index 34b082ae..8e9c7459 100644 --- a/vulkano/src/command_buffer/commands/clear.rs +++ b/vulkano/src/command_buffer/commands/clear.rs @@ -14,7 +14,7 @@ use smallvec::{smallvec, SmallVec}; use std::{mem::size_of_val, sync::Arc}; /// # Commands to fill resources with new data. -impl RecordingCommandBuffer { +impl RecordingCommandBuffer { /// Clears a color image with a specific value. pub fn clear_color_image( &mut self, diff --git a/vulkano/src/command_buffer/commands/copy.rs b/vulkano/src/command_buffer/commands/copy.rs index 300af70f..3b7af68e 100644 --- a/vulkano/src/command_buffer/commands/copy.rs +++ b/vulkano/src/command_buffer/commands/copy.rs @@ -20,7 +20,7 @@ use std::{ }; /// # Commands to transfer data between resources. -impl RecordingCommandBuffer { +impl RecordingCommandBuffer { /// Copies data from a buffer to another buffer. /// /// # Panics diff --git a/vulkano/src/command_buffer/commands/debug.rs b/vulkano/src/command_buffer/commands/debug.rs index 9e0bbbe8..0286a2d6 100644 --- a/vulkano/src/command_buffer/commands/debug.rs +++ b/vulkano/src/command_buffer/commands/debug.rs @@ -11,7 +11,7 @@ use std::ffi::CString; /// These commands all require the [`ext_debug_utils`] extension to be enabled on the instance. /// /// [`ext_debug_utils`]: crate::instance::InstanceExtensions::ext_debug_utils -impl RecordingCommandBuffer { +impl RecordingCommandBuffer { /// Opens a command buffer debug label region. pub fn begin_debug_utils_label( &mut self, diff --git a/vulkano/src/command_buffer/commands/dynamic_state.rs b/vulkano/src/command_buffer/commands/dynamic_state.rs index c96fd13d..142d4491 100644 --- a/vulkano/src/command_buffer/commands/dynamic_state.rs +++ b/vulkano/src/command_buffer/commands/dynamic_state.rs @@ -23,7 +23,7 @@ use std::ops::RangeInclusive; /// # Commands to set dynamic state for pipelines. /// /// These commands require a queue with a pipeline type that uses the given state. -impl RecordingCommandBuffer { +impl RecordingCommandBuffer { // Helper function for dynamic state setting. fn validate_graphics_pipeline_fixed_state( &self, diff --git a/vulkano/src/command_buffer/commands/pipeline.rs b/vulkano/src/command_buffer/commands/pipeline.rs index b20024ad..a3d467fe 100644 --- a/vulkano/src/command_buffer/commands/pipeline.rs +++ b/vulkano/src/command_buffer/commands/pipeline.rs @@ -44,7 +44,7 @@ macro_rules! vuids { /// # Commands to execute a bound pipeline. /// /// Dispatch commands require a compute queue, draw commands require a graphics queue. -impl RecordingCommandBuffer { +impl RecordingCommandBuffer { /// Perform a single compute operation using a compute pipeline. /// /// A compute pipeline must have been bound using diff --git a/vulkano/src/command_buffer/commands/query.rs b/vulkano/src/command_buffer/commands/query.rs index 325e044c..44884d82 100644 --- a/vulkano/src/command_buffer/commands/query.rs +++ b/vulkano/src/command_buffer/commands/query.rs @@ -13,7 +13,7 @@ use crate::{ use std::{ops::Range, sync::Arc}; /// # Commands related to queries. -impl RecordingCommandBuffer { +impl RecordingCommandBuffer { /// Begins a query. /// /// The query will be active until [`end_query`](Self::end_query) is called for the same query. diff --git a/vulkano/src/command_buffer/commands/render_pass.rs b/vulkano/src/command_buffer/commands/render_pass.rs index 04cb55d6..c7076bef 100644 --- a/vulkano/src/command_buffer/commands/render_pass.rs +++ b/vulkano/src/command_buffer/commands/render_pass.rs @@ -24,7 +24,7 @@ use std::{cmp::min, ops::Range, sync::Arc}; /// # Commands for render passes. /// /// These commands require a graphics queue. -impl RecordingCommandBuffer { +impl RecordingCommandBuffer { /// Begins a render pass using a render pass object and framebuffer. /// /// You must call this or `begin_rendering` before you can record draw commands. @@ -328,7 +328,7 @@ impl RecordingCommandBuffer { } } -impl RecordingCommandBuffer { +impl RecordingCommandBuffer { /// Begins a render pass without a render pass object or framebuffer. /// /// You must call this or `begin_render_pass` before you can record draw commands. diff --git a/vulkano/src/command_buffer/commands/secondary.rs b/vulkano/src/command_buffer/commands/secondary.rs index 786f8d41..b78bf3e6 100644 --- a/vulkano/src/command_buffer/commands/secondary.rs +++ b/vulkano/src/command_buffer/commands/secondary.rs @@ -2,8 +2,8 @@ use crate::{ command_buffer::{ auto::{RenderPassStateType, Resource, ResourceUseRef2}, sys::{RawCommandBuffer, RawRecordingCommandBuffer}, - CommandBufferInheritanceRenderPassType, CommandBufferLevel, RecordingCommandBuffer, - ResourceInCommand, SecondaryAutoCommandBuffer, SecondaryCommandBufferBufferUsage, + CommandBuffer, CommandBufferInheritanceRenderPassType, CommandBufferLevel, + RecordingCommandBuffer, ResourceInCommand, SecondaryCommandBufferBufferUsage, SecondaryCommandBufferImageUsage, SecondaryCommandBufferResourcesUsage, SubpassContents, }, device::{DeviceOwned, QueueFlags}, @@ -17,7 +17,7 @@ use std::{cmp::min, iter, sync::Arc}; /// /// These commands can be called on any queue that can execute the commands recorded in the /// secondary command buffer. -impl RecordingCommandBuffer { +impl RecordingCommandBuffer { /// Executes a secondary command buffer. /// /// If the `flags` that `command_buffer` was created with are more restrictive than those of @@ -25,7 +25,7 @@ impl RecordingCommandBuffer { /// with `Flags::OneTimeSubmit` will set `self`'s flags to `Flags::OneTimeSubmit` also. pub fn execute_commands( &mut self, - command_buffer: Arc, + command_buffer: Arc, ) -> Result<&mut Self, Box> { let command_buffer = DropUnlockCommandBuffer::new(command_buffer)?; self.validate_execute_commands(iter::once(&**command_buffer))?; @@ -41,7 +41,7 @@ impl RecordingCommandBuffer { // TODO ^ would be nice if this just worked without errors pub fn execute_commands_from_vec( &mut self, - command_buffers: Vec>, + command_buffers: Vec>, ) -> Result<&mut Self, Box> { let command_buffers: SmallVec<[_; 4]> = command_buffers .into_iter() @@ -55,7 +55,7 @@ impl RecordingCommandBuffer { fn validate_execute_commands<'a>( &self, - command_buffers: impl Iterator + Clone, + command_buffers: impl Iterator + Clone, ) -> Result<(), Box> { self.inner .validate_execute_commands(command_buffers.clone().map(|cb| cb.inner()))?; @@ -89,17 +89,16 @@ impl RecordingCommandBuffer { } for (command_buffer_index, command_buffer) in command_buffers.enumerate() { + let inheritance_info = command_buffer.inheritance_info().unwrap(); + if let Some(render_pass_state) = &self.builder_state.render_pass { - let inheritance_render_pass = command_buffer - .inheritance_info() - .render_pass - .as_ref() - .ok_or_else(|| { + let inheritance_render_pass = + inheritance_info.render_pass.as_ref().ok_or_else(|| { Box::new(ValidationError { problem: format!( "a render pass instance is active, but \ - `command_buffers[{}].inheritance_info().render_pass` is `None`", - command_buffer_index + `command_buffers[{}].inheritance_info().render_pass` is `None`", + command_buffer_index, ) .into(), vuids: &["VUID-vkCmdExecuteCommands-pCommandBuffers-00096"], @@ -375,7 +374,7 @@ impl RecordingCommandBuffer { // VUID-vkCmdExecuteCommands-pCommandBuffers-06535 // VUID-vkCmdExecuteCommands-pCommandBuffers-06536 } else { - if command_buffer.inheritance_info().render_pass.is_some() { + if inheritance_info.render_pass.is_some() { return Err(Box::new(ValidationError { context: format!( "command_buffers[{}].inheritance_info().render_pass", @@ -392,10 +391,8 @@ impl RecordingCommandBuffer { for state in self.builder_state.queries.values() { match state.query_pool.query_type() { QueryType::Occlusion => { - let inherited_flags = command_buffer - .inheritance_info() - .occlusion_query - .ok_or_else(|| { + let inherited_flags = + inheritance_info.occlusion_query.ok_or_else(|| { Box::new(ValidationError { context: format!( "command_buffers[{}].inheritance_info().occlusion_query", @@ -426,8 +423,7 @@ impl RecordingCommandBuffer { } } &QueryType::PipelineStatistics(state_flags) => { - let inherited_flags = - command_buffer.inheritance_info().query_statistics_flags; + let inherited_flags = inheritance_info.query_statistics_flags; if !inherited_flags.contains(state_flags) { return Err(Box::new(ValidationError { @@ -461,7 +457,7 @@ impl RecordingCommandBuffer { #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] pub unsafe fn execute_commands_unchecked( &mut self, - command_buffers: SmallVec<[Arc; 4]>, + command_buffers: SmallVec<[Arc; 4]>, ) -> &mut Self { self.execute_commands_locked( command_buffers @@ -487,7 +483,7 @@ impl RecordingCommandBuffer { .flat_map(|(index, command_buffer)| { let index = index as u32; let SecondaryCommandBufferResourcesUsage { buffers, images } = - command_buffer.resources_usage(); + command_buffer.secondary_resources_usage(); (buffers.iter().map(move |usage| { let &SecondaryCommandBufferBufferUsage { @@ -672,22 +668,23 @@ impl RawRecordingCommandBuffer { } } -struct DropUnlockCommandBuffer(Arc); +struct DropUnlockCommandBuffer(Arc); impl DropUnlockCommandBuffer { - fn new(command_buffer: Arc) -> Result> { + fn new(command_buffer: Arc) -> Result> { command_buffer.lock_record()?; Ok(Self(command_buffer)) } } impl std::ops::Deref for DropUnlockCommandBuffer { - type Target = Arc; + type Target = Arc; fn deref(&self) -> &Self::Target { &self.0 } } + unsafe impl SafeDeref for DropUnlockCommandBuffer {} impl Drop for DropUnlockCommandBuffer { diff --git a/vulkano/src/command_buffer/mod.rs b/vulkano/src/command_buffer/mod.rs index 914f3dc6..cf2cace2 100644 --- a/vulkano/src/command_buffer/mod.rs +++ b/vulkano/src/command_buffer/mod.rs @@ -2,9 +2,9 @@ //! //! With Vulkan, to get the device to perform work, even relatively simple tasks, you must create a //! command buffer. A command buffer is a list of commands that will executed by the device. -//! You must first record commands to a command buffer builder, then build it into an actual -//! command buffer, and then it can be used. Depending on how a command buffer is created, it can -//! be used only once, or reused many times. +//! You must first record commands to a recording command buffer, then end the recording to turn it +//! into an actual command buffer, and then it can be used. Depending on how a command buffer is +//! created, it can be used only once, or reused many times. //! //! # Command pools and allocators //! @@ -22,10 +22,10 @@ //! //! There are two levels of command buffers: //! -//! - [`PrimaryAutoCommandBuffer`] can be executed on a queue, and is the main command buffer type. +//! - A primary command buffer can be executed on a queue, and is the main command buffer level. //! It cannot be executed within another command buffer. -//! - [`SecondaryAutoCommandBuffer`] can only be executed within a primary command buffer, not -//! directly on a queue. +//! - A secondary command buffer can only be executed within a primary command buffer, not directly +//! on a queue. //! //! Using secondary command buffers, there is slightly more overhead than using primary command //! buffers alone, but there are also advantages. A single command buffer cannot be recorded @@ -41,18 +41,19 @@ //! To record a new command buffer, the most direct way is to create a new //! [`RecordingCommandBuffer`]. You can then call methods on this object to record new commands to //! the command buffer. When you are done recording, you call [`end`] to finalise the command -//! buffer and turn it into either a [`PrimaryAutoCommandBuffer`] or a -//! [`SecondaryAutoCommandBuffer`]. +//! buffer and turn it into a [`CommandBuffer`]. //! //! # Submitting a primary command buffer //! -//! Once a primary command buffer is recorded and built, you can submit the -//! [`PrimaryAutoCommandBuffer`] to a queue. Submitting a command buffer returns an object that -//! implements the [`GpuFuture`] trait and that represents the moment when the execution will end -//! on the GPU. +//! Once a primary command buffer has finished recording, you can submit the [`CommandBuffer`] to a +//! queue. Submitting a command buffer returns an object that implements the [`GpuFuture`] trait +//! and that represents the moment when the execution will end on the GPU. //! //! ``` -//! use vulkano::command_buffer::{CommandBufferUsage, RecordingCommandBuffer, SubpassContents}; +//! use vulkano::command_buffer::{ +//! CommandBufferBeginInfo, CommandBufferLevel, CommandBufferUsage, RecordingCommandBuffer, +//! SubpassContents, +//! }; //! //! # let device: std::sync::Arc = return; //! # let queue: std::sync::Arc = return; @@ -61,10 +62,11 @@ //! # let graphics_pipeline: std::sync::Arc = return; //! # let command_buffer_allocator: std::sync::Arc = return; //! # -//! let cb = RecordingCommandBuffer::primary( +//! let cb = RecordingCommandBuffer::new( //! command_buffer_allocator.clone(), //! queue.queue_family_index(), -//! CommandBufferUsage::MultipleSubmit, +//! CommandBufferLevel::Primary, +//! CommandBufferBeginInfo::default(), //! ) //! .unwrap() //! .begin_render_pass(render_pass_begin_info, Default::default()) @@ -90,11 +92,12 @@ //! [`GpuFuture`]: crate::sync::GpuFuture pub use self::{ - auto::{PrimaryAutoCommandBuffer, RecordingCommandBuffer, SecondaryAutoCommandBuffer}, + auto::{CommandBuffer, RecordingCommandBuffer}, commands::{ acceleration_structure::*, clear::*, copy::*, debug::*, dynamic_state::*, pipeline::*, query::*, render_pass::*, secondary::*, sync::*, }, + sys::CommandBufferBeginInfo, traits::{CommandBufferExecError, CommandBufferExecFuture}, }; use crate::{ @@ -788,7 +791,7 @@ pub struct CommandBufferSubmitInfo { /// The command buffer to execute. /// /// There is no default value. - pub command_buffer: Arc, + pub command_buffer: Arc, pub _ne: crate::NonExhaustive, } @@ -796,7 +799,7 @@ pub struct CommandBufferSubmitInfo { impl CommandBufferSubmitInfo { /// Returns a `CommandBufferSubmitInfo` with the specified `command_buffer`. #[inline] - pub fn new(command_buffer: Arc) -> Self { + pub fn new(command_buffer: Arc) -> Self { Self { command_buffer, _ne: crate::NonExhaustive(()), @@ -812,6 +815,15 @@ impl CommandBufferSubmitInfo { // VUID? assert_eq!(device, command_buffer.device().as_ref()); + if self.command_buffer.level() != CommandBufferLevel::Primary { + return Err(Box::new(ValidationError { + context: "command_buffer".into(), + problem: "is not a primary command buffer".into(), + vuids: &["VUID-VkCommandBufferSubmitInfo-commandBuffer-03890"], + ..Default::default() + })); + } + Ok(()) } } diff --git a/vulkano/src/command_buffer/sys.rs b/vulkano/src/command_buffer/sys.rs index e1fcf4a2..4f3bc045 100644 --- a/vulkano/src/command_buffer/sys.rs +++ b/vulkano/src/command_buffer/sys.rs @@ -35,12 +35,46 @@ pub struct RawRecordingCommandBuffer { impl RawRecordingCommandBuffer { /// Allocates and begins recording a new command buffer. - /// - /// # Safety - /// - /// - `begin_info` must be valid. #[inline] - pub unsafe fn new( + pub fn new( + allocator: Arc, + queue_family_index: u32, + level: CommandBufferLevel, + begin_info: CommandBufferBeginInfo, + ) -> Result> { + Self::validate_new(allocator.device(), queue_family_index, level, &begin_info)?; + + unsafe { Self::new_unchecked(allocator, queue_family_index, level, begin_info) } + } + + pub(super) fn validate_new( + device: &Device, + _queue_family_index: u32, + level: CommandBufferLevel, + begin_info: &CommandBufferBeginInfo, + ) -> Result<(), Box> { + // VUID-vkBeginCommandBuffer-commandBuffer-00049 + // VUID-vkBeginCommandBuffer-commandBuffer-00050 + // Guaranteed by `CommandBufferAllocator`. + + if level == CommandBufferLevel::Secondary && begin_info.inheritance_info.is_none() { + return Err(Box::new(ValidationError { + context: "begin_info.inheritance_info".into(), + problem: "is `None` while `level` is `CommandBufferLevel::Secondary`".into(), + vuids: &["VUID-vkBeginCommandBuffer-commandBuffer-00051"], + ..Default::default() + })); + } + + begin_info + .validate(device) + .map_err(|err| err.add_context("begin_info"))?; + + Ok(()) + } + + #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] + pub unsafe fn new_unchecked( allocator: Arc, queue_family_index: u32, level: CommandBufferLevel, @@ -169,13 +203,11 @@ impl RawRecordingCommandBuffer { /// Ends the recording, returning a command buffer which can be submitted. #[inline] - pub fn end(self) -> Result { - unsafe { - let fns = self.device().fns(); - (fns.v1_0.end_command_buffer)(self.handle()) - .result() - .map_err(VulkanError::from)?; - } + pub unsafe fn end(self) -> Result { + let fns = self.device().fns(); + (fns.v1_0.end_command_buffer)(self.handle()) + .result() + .map_err(VulkanError::from)?; Ok(RawCommandBuffer { inner: self }) } diff --git a/vulkano/src/command_buffer/traits.rs b/vulkano/src/command_buffer/traits.rs index 8a96fe59..5d0a0a70 100644 --- a/vulkano/src/command_buffer/traits.rs +++ b/vulkano/src/command_buffer/traits.rs @@ -1,4 +1,4 @@ -use super::{CommandBufferSubmitInfo, PrimaryAutoCommandBuffer, SemaphoreSubmitInfo, SubmitInfo}; +use super::{CommandBuffer, CommandBufferSubmitInfo, SemaphoreSubmitInfo, SubmitInfo}; use crate::{ buffer::Buffer, device::{Device, DeviceOwned, Queue}, @@ -26,7 +26,7 @@ use std::{ thread, }; -impl PrimaryAutoCommandBuffer { +impl CommandBuffer { /// Executes this command buffer on a queue. /// /// This function returns an object that implements the [`GpuFuture`] trait. See the @@ -121,7 +121,7 @@ where F: GpuFuture, { previous: F, - command_buffer: Arc, + command_buffer: Arc, queue: Arc, // True if the command buffer has already been submitted. // If flush is called multiple times, we want to block so that only one flushing is executed. diff --git a/vulkano/src/pipeline/compute.rs b/vulkano/src/pipeline/compute.rs index d8ef0b60..7458d97f 100644 --- a/vulkano/src/pipeline/compute.rs +++ b/vulkano/src/pipeline/compute.rs @@ -445,7 +445,8 @@ mod tests { use crate::{ buffer::{Buffer, BufferCreateInfo, BufferUsage}, command_buffer::{ - allocator::StandardCommandBufferAllocator, CommandBufferUsage, RecordingCommandBuffer, + allocator::StandardCommandBufferAllocator, CommandBufferBeginInfo, CommandBufferLevel, + CommandBufferUsage, RecordingCommandBuffer, }, descriptor_set::{ allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet, @@ -556,10 +557,14 @@ mod tests { device.clone(), Default::default(), )); - let mut cbb = RecordingCommandBuffer::primary( + let mut cbb = RecordingCommandBuffer::new( cb_allocator, queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); cbb.bind_pipeline_compute(pipeline.clone()) @@ -703,10 +708,14 @@ mod tests { device.clone(), Default::default(), )); - let mut cbb = RecordingCommandBuffer::primary( + let mut cbb = RecordingCommandBuffer::new( cb_allocator, queue.queue_family_index(), - CommandBufferUsage::OneTimeSubmit, + CommandBufferLevel::Primary, + CommandBufferBeginInfo { + usage: CommandBufferUsage::OneTimeSubmit, + ..Default::default() + }, ) .unwrap(); cbb.bind_pipeline_compute(pipeline.clone()) diff --git a/vulkano/src/swapchain/mod.rs b/vulkano/src/swapchain/mod.rs index 3699abba..5f6eda8a 100644 --- a/vulkano/src/swapchain/mod.rs +++ b/vulkano/src/swapchain/mod.rs @@ -233,7 +233,7 @@ //! # let mut swapchain: ::std::sync::Arc = return; //! // let mut (swapchain, images) = Swapchain::new(...); //! loop { -//! # let mut command_buffer: ::std::sync::Arc<::vulkano::command_buffer::PrimaryAutoCommandBuffer> = return; +//! # let mut command_buffer: ::std::sync::Arc<::vulkano::command_buffer::CommandBuffer> = return; //! let (image_index, suboptimal, acquire_future) //! = swapchain::acquire_next_image(swapchain.clone(), None).unwrap(); //! diff --git a/vulkano/src/sync/future/mod.rs b/vulkano/src/sync/future/mod.rs index 620cb401..faa16cb2 100644 --- a/vulkano/src/sync/future/mod.rs +++ b/vulkano/src/sync/future/mod.rs @@ -91,9 +91,9 @@ use super::{fence::Fence, semaphore::Semaphore}; use crate::{ buffer::{Buffer, BufferState}, command_buffer::{ - CommandBufferExecError, CommandBufferExecFuture, CommandBufferResourcesUsage, - CommandBufferState, CommandBufferSubmitInfo, CommandBufferUsage, PrimaryAutoCommandBuffer, - SubmitInfo, + CommandBuffer, CommandBufferExecError, CommandBufferExecFuture, + CommandBufferResourcesUsage, CommandBufferState, CommandBufferSubmitInfo, + CommandBufferUsage, SubmitInfo, }, device::{DeviceOwned, Queue}, image::{Image, ImageLayout, ImageState}, @@ -242,7 +242,7 @@ pub unsafe trait GpuFuture: DeviceOwned { fn then_execute( self, queue: Arc, - command_buffer: Arc, + command_buffer: Arc, ) -> Result, CommandBufferExecError> where Self: Sized, @@ -256,7 +256,7 @@ pub unsafe trait GpuFuture: DeviceOwned { /// > `CommandBuffer` trait. fn then_execute_same_queue( self, - command_buffer: Arc, + command_buffer: Arc, ) -> Result, CommandBufferExecError> where Self: Sized,