Skip to content

Commit

Permalink
Buffer and image uploads take a command buffer instead of making one (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Rua authored Oct 8, 2022
1 parent 8409173 commit df26f81
Show file tree
Hide file tree
Showing 13 changed files with 267 additions and 229 deletions.
13 changes: 10 additions & 3 deletions examples/src/bin/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

use std::sync::Arc;
use vulkano::{
command_buffer::allocator::StandardCommandBufferAllocator,
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
},
device::{
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo,
},
Expand Down Expand Up @@ -174,6 +176,12 @@ fn main() {
let queue = queues.next().unwrap();

let command_buffer_allocator = StandardCommandBufferAllocator::new(device);
let mut command_buffer_builder = AutoCommandBufferBuilder::primary(
&command_buffer_allocator,
queue.queue_family_index(),
CommandBufferUsage::OneTimeSubmit,
)
.unwrap();

// Create an image in order to generate some additional logging:
let pixel_format = Format::R8G8B8A8_UINT;
Expand All @@ -188,8 +196,7 @@ fn main() {
dimensions,
MipmapsCount::One,
pixel_format,
&command_buffer_allocator,
queue,
&mut command_buffer_builder,
)
.unwrap();

Expand Down
31 changes: 17 additions & 14 deletions examples/src/bin/image-self-copy-blit/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,14 @@ fn main() {

let descriptor_set_allocator = StandardDescriptorSetAllocator::new(device.clone());
let command_buffer_allocator = StandardCommandBufferAllocator::new(device.clone());
let mut uploads = AutoCommandBufferBuilder::primary(
&command_buffer_allocator,
queue.queue_family_index(),
CommandBufferUsage::OneTimeSubmit,
)
.unwrap();

let (texture, tex_future) = {
let texture = {
let png_bytes = include_bytes!("image_img.png").to_vec();
let cursor = Cursor::new(png_bytes);
let decoder = png::Decoder::new(cursor);
Expand Down Expand Up @@ -248,14 +254,8 @@ fn main() {
)
.unwrap();

let mut builder = AutoCommandBufferBuilder::primary(
&command_buffer_allocator,
queue.queue_family_index(),
CommandBufferUsage::OneTimeSubmit,
)
.unwrap();
// here, we perform image copying and blitting on the same image
builder
uploads
// clear the image buffer
.clear_color_image(ClearColorImageInfo::image(image.clone()))
.unwrap()
Expand Down Expand Up @@ -312,12 +312,8 @@ fn main() {
..BlitImageInfo::images(image.clone(), image.clone())
})
.unwrap();
let command_buffer = builder.build().unwrap();

(
ImageView::new_default(image).unwrap(),
command_buffer.execute(queue.clone()).unwrap(),
)
ImageView::new_default(image).unwrap()
};

let sampler = Sampler::new(
Expand Down Expand Up @@ -359,7 +355,14 @@ fn main() {
let mut framebuffers = window_size_dependent_setup(&images, render_pass.clone(), &mut viewport);

let mut recreate_swapchain = false;
let mut previous_frame_end = Some(tex_future.boxed());
let mut previous_frame_end = Some(
uploads
.build()
.unwrap()
.execute(queue.clone())
.unwrap()
.boxed(),
);

event_loop.run(move |event, _, control_flow| match event {
Event::WindowEvent {
Expand Down
26 changes: 19 additions & 7 deletions examples/src/bin/image/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use vulkano::{
buffer::{BufferUsage, CpuAccessibleBuffer, TypedBufferAccess},
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
RenderPassBeginInfo, SubpassContents,
PrimaryCommandBuffer, RenderPassBeginInfo, SubpassContents,
},
descriptor_set::{
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
Expand Down Expand Up @@ -210,8 +210,14 @@ fn main() {

let descriptor_set_allocator = StandardDescriptorSetAllocator::new(device.clone());
let command_buffer_allocator = StandardCommandBufferAllocator::new(device.clone());
let mut uploads = AutoCommandBufferBuilder::primary(
&command_buffer_allocator,
queue.queue_family_index(),
CommandBufferUsage::OneTimeSubmit,
)
.unwrap();

let (texture, tex_future) = {
let texture = {
let png_bytes = include_bytes!("image_img.png").to_vec();
let cursor = Cursor::new(png_bytes);
let decoder = png::Decoder::new(cursor);
Expand All @@ -226,16 +232,15 @@ fn main() {
image_data.resize((info.width * info.height * 4) as usize, 0);
reader.next_frame(&mut image_data).unwrap();

let (image, future) = ImmutableImage::from_iter(
let image = ImmutableImage::from_iter(
image_data,
dimensions,
MipmapsCount::One,
Format::R8G8B8A8_SRGB,
&command_buffer_allocator,
queue.clone(),
&mut uploads,
)
.unwrap();
(ImageView::new_default(image).unwrap(), future)
ImageView::new_default(image).unwrap()
};

let sampler = Sampler::new(
Expand Down Expand Up @@ -277,7 +282,14 @@ fn main() {
let mut framebuffers = window_size_dependent_setup(&images, render_pass.clone(), &mut viewport);

let mut recreate_swapchain = false;
let mut previous_frame_end = Some(tex_future.boxed());
let mut previous_frame_end = Some(
uploads
.build()
.unwrap()
.execute(queue.clone())
.unwrap()
.boxed(),
);

event_loop.run(move |event, _, control_flow| match event {
Event::WindowEvent {
Expand Down
26 changes: 19 additions & 7 deletions examples/src/bin/immutable-sampler/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use vulkano::{
buffer::{BufferUsage, CpuAccessibleBuffer, TypedBufferAccess},
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
RenderPassBeginInfo, SubpassContents,
PrimaryCommandBuffer, RenderPassBeginInfo, SubpassContents,
},
descriptor_set::{
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
Expand Down Expand Up @@ -216,8 +216,14 @@ fn main() {

let descriptor_set_allocator = StandardDescriptorSetAllocator::new(device.clone());
let command_buffer_allocator = StandardCommandBufferAllocator::new(device.clone());
let mut uploads = AutoCommandBufferBuilder::primary(
&command_buffer_allocator,
queue.queue_family_index(),
CommandBufferUsage::OneTimeSubmit,
)
.unwrap();

let (texture, tex_future) = {
let texture = {
let png_bytes = include_bytes!("image_img.png").to_vec();
let cursor = Cursor::new(png_bytes);
let decoder = png::Decoder::new(cursor);
Expand All @@ -232,16 +238,15 @@ fn main() {
image_data.resize((info.width * info.height * 4) as usize, 0);
reader.next_frame(&mut image_data).unwrap();

let (image, future) = ImmutableImage::from_iter(
let image = ImmutableImage::from_iter(
image_data,
dimensions,
MipmapsCount::One,
Format::R8G8B8A8_SRGB,
&command_buffer_allocator,
queue.clone(),
&mut uploads,
)
.unwrap();
(ImageView::new_default(image).unwrap(), future)
ImageView::new_default(image).unwrap()
};

let sampler = Sampler::new(
Expand Down Expand Up @@ -290,7 +295,14 @@ fn main() {
let mut framebuffers = window_size_dependent_setup(&images, render_pass.clone(), &mut viewport);

let mut recreate_swapchain = false;
let mut previous_frame_end = Some(tex_future.boxed());
let mut previous_frame_end = Some(
uploads
.build()
.unwrap()
.execute(queue.clone())
.unwrap()
.boxed(),
);

event_loop.run(move |event, _, control_flow| match event {
Event::WindowEvent {
Expand Down
26 changes: 19 additions & 7 deletions examples/src/bin/push-descriptors/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use vulkano::{
buffer::{BufferUsage, CpuAccessibleBuffer, TypedBufferAccess},
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
RenderPassBeginInfo, SubpassContents,
PrimaryCommandBuffer, RenderPassBeginInfo, SubpassContents,
},
descriptor_set::WriteDescriptorSet,
device::{
Expand Down Expand Up @@ -205,8 +205,14 @@ fn main() {
.unwrap();

let command_buffer_allocator = StandardCommandBufferAllocator::new(device.clone());
let mut uploads = AutoCommandBufferBuilder::primary(
&command_buffer_allocator,
queue.queue_family_index(),
CommandBufferUsage::OneTimeSubmit,
)
.unwrap();

let (texture, tex_future) = {
let texture = {
let png_bytes = include_bytes!("image_img.png").to_vec();
let cursor = Cursor::new(png_bytes);
let decoder = png::Decoder::new(cursor);
Expand All @@ -221,16 +227,15 @@ fn main() {
image_data.resize((info.width * info.height * 4) as usize, 0);
reader.next_frame(&mut image_data).unwrap();

let (image, future) = ImmutableImage::from_iter(
let image = ImmutableImage::from_iter(
image_data,
dimensions,
MipmapsCount::One,
Format::R8G8B8A8_SRGB,
&command_buffer_allocator,
queue.clone(),
&mut uploads,
)
.unwrap();
(ImageView::new_default(image).unwrap(), future)
ImageView::new_default(image).unwrap()
};

let sampler = Sampler::new(
Expand Down Expand Up @@ -269,7 +274,14 @@ fn main() {
let mut framebuffers = window_size_dependent_setup(&images, render_pass.clone(), &mut viewport);

let mut recreate_swapchain = false;
let mut previous_frame_end = Some(tex_future.boxed());
let mut previous_frame_end = Some(
uploads
.build()
.unwrap()
.execute(queue.clone())
.unwrap()
.boxed(),
);

event_loop.run(move |event, _, control_flow| match event {
Event::WindowEvent {
Expand Down
30 changes: 19 additions & 11 deletions examples/src/bin/runtime_array/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use vulkano::{
buffer::{BufferUsage, CpuAccessibleBuffer, TypedBufferAccess},
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
RenderPassBeginInfo, SubpassContents,
PrimaryCommandBuffer, RenderPassBeginInfo, SubpassContents,
},
descriptor_set::{
allocator::StandardDescriptorSetAllocator,
Expand Down Expand Up @@ -272,6 +272,12 @@ fn main() {

let descriptor_set_allocator = StandardDescriptorSetAllocator::new(device.clone());
let command_buffer_allocator = StandardCommandBufferAllocator::new(device.clone());
let mut uploads = AutoCommandBufferBuilder::primary(
&command_buffer_allocator,
queue.queue_family_index(),
CommandBufferUsage::OneTimeSubmit,
)
.unwrap();

let mascot_texture = {
let png_bytes = include_bytes!("rust_mascot.png").to_vec();
Expand All @@ -293,11 +299,9 @@ fn main() {
dimensions,
MipmapsCount::One,
Format::R8G8B8A8_SRGB,
&command_buffer_allocator,
queue.clone(),
&mut uploads,
)
.unwrap()
.0;
.unwrap();

ImageView::new_default(image).unwrap()
};
Expand All @@ -322,11 +326,9 @@ fn main() {
dimensions,
MipmapsCount::One,
Format::R8G8B8A8_SRGB,
&command_buffer_allocator,
queue.clone(),
&mut uploads,
)
.unwrap()
.0;
.unwrap();

ImageView::new_default(image).unwrap()
};
Expand Down Expand Up @@ -410,8 +412,14 @@ fn main() {
let mut framebuffers = window_size_dependent_setup(&images, render_pass.clone(), &mut viewport);

let mut recreate_swapchain = false;
let mut previous_frame_end: Option<Box<dyn GpuFuture>> =
Some(Box::new(vulkano::sync::now(device.clone())));
let mut previous_frame_end = Some(
uploads
.build()
.unwrap()
.execute(queue.clone())
.unwrap()
.boxed(),
);

event_loop.run(move |event, _, control_flow| match event {
Event::WindowEvent {
Expand Down
Loading

0 comments on commit df26f81

Please sign in to comment.