Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Memory (sub)allocation API 2.0 #2316

Merged
merged 9 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/src/bin/async-update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ fn main() {
},
];
let vertex_buffer = Buffer::from_iter(
&memory_allocator,
memory_allocator.clone(),
BufferCreateInfo {
usage: BufferUsage::VERTEX_BUFFER,
..Default::default()
Expand All @@ -293,7 +293,7 @@ fn main() {
let uniform_buffers = (0..swapchain.image_count())
.map(|_| {
Buffer::new_sized(
&memory_allocator,
memory_allocator.clone(),
BufferCreateInfo {
usage: BufferUsage::UNIFORM_BUFFER,
..Default::default()
Expand All @@ -312,7 +312,7 @@ fn main() {
// is used exclusively for writing, swapping the two after each update.
let textures = [(); 2].map(|_| {
Image::new(
&memory_allocator,
memory_allocator.clone(),
ImageCreateInfo {
image_type: ImageType::Dim2d,
format: Format::R8G8B8A8_UNORM,
Expand Down Expand Up @@ -714,7 +714,7 @@ fn run_worker(
// out-of-date texture is the current up-to-date texture and vice-versa, cycle repeating.
let staging_buffers = [(); 2].map(|_| {
Buffer::from_iter(
&memory_allocator,
memory_allocator.clone(),
BufferCreateInfo {
usage: BufferUsage::TRANSFER_SRC,
..Default::default()
Expand Down
5 changes: 3 additions & 2 deletions examples/src/bin/basic-compute-shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// been more or more used for general-purpose operations as well. This is called "General-Purpose
// GPU", or *GPGPU*. This is what this example demonstrates.

use std::sync::Arc;
use vulkano::{
buffer::{Buffer, BufferCreateInfo, BufferUsage},
command_buffer::{
Expand Down Expand Up @@ -158,14 +159,14 @@ fn main() {
.unwrap()
};

let memory_allocator = StandardMemoryAllocator::new_default(device.clone());
let memory_allocator = Arc::new(StandardMemoryAllocator::new_default(device.clone()));
let descriptor_set_allocator = StandardDescriptorSetAllocator::new(device.clone());
let command_buffer_allocator =
StandardCommandBufferAllocator::new(device.clone(), Default::default());

// We start by creating the buffer that will store the data.
let data_buffer = Buffer::from_iter(
&memory_allocator,
memory_allocator,
BufferCreateInfo {
usage: BufferUsage::STORAGE_BUFFER,
..Default::default()
Expand Down
4 changes: 2 additions & 2 deletions examples/src/bin/deferred/frame/ambient_lighting_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use vulkano::{
},
device::Queue,
image::view::ImageView,
memory::allocator::{AllocationCreateInfo, MemoryAllocator, MemoryTypeFilter},
memory::allocator::{AllocationCreateInfo, MemoryTypeFilter, StandardMemoryAllocator},
pipeline::{
graphics::{
color_blend::{AttachmentBlend, BlendFactor, BlendOp, ColorBlendState},
Expand Down Expand Up @@ -54,7 +54,7 @@ impl AmbientLightingSystem {
pub fn new(
gfx_queue: Arc<Queue>,
subpass: Subpass,
memory_allocator: &impl MemoryAllocator,
memory_allocator: Arc<StandardMemoryAllocator>,
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
) -> AmbientLightingSystem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use vulkano::{
},
device::Queue,
image::view::ImageView,
memory::allocator::{AllocationCreateInfo, MemoryAllocator, MemoryTypeFilter},
memory::allocator::{AllocationCreateInfo, MemoryTypeFilter, StandardMemoryAllocator},
pipeline::{
graphics::{
color_blend::{AttachmentBlend, BlendFactor, BlendOp, ColorBlendState},
Expand Down Expand Up @@ -55,7 +55,7 @@ impl DirectionalLightingSystem {
pub fn new(
gfx_queue: Arc<Queue>,
subpass: Subpass,
memory_allocator: &impl MemoryAllocator,
memory_allocator: Arc<StandardMemoryAllocator>,
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
) -> DirectionalLightingSystem {
Expand Down
4 changes: 2 additions & 2 deletions examples/src/bin/deferred/frame/point_lighting_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use vulkano::{
},
device::Queue,
image::view::ImageView,
memory::allocator::{AllocationCreateInfo, MemoryAllocator, MemoryTypeFilter},
memory::allocator::{AllocationCreateInfo, MemoryTypeFilter, StandardMemoryAllocator},
pipeline::{
graphics::{
color_blend::{AttachmentBlend, BlendFactor, BlendOp, ColorBlendState},
Expand Down Expand Up @@ -54,7 +54,7 @@ impl PointLightingSystem {
pub fn new(
gfx_queue: Arc<Queue>,
subpass: Subpass,
memory_allocator: &impl MemoryAllocator,
memory_allocator: Arc<StandardMemoryAllocator>,
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
) -> PointLightingSystem {
Expand Down
18 changes: 9 additions & 9 deletions examples/src/bin/deferred/frame/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl FrameSystem {
// will be replaced the first time we call `frame()`.
let diffuse_buffer = ImageView::new_default(
Image::new(
&memory_allocator,
memory_allocator.clone(),
ImageCreateInfo {
image_type: ImageType::Dim2d,
format: Format::A2B10G10R10_UNORM_PACK32,
Expand All @@ -172,7 +172,7 @@ impl FrameSystem {
.unwrap();
let normals_buffer = ImageView::new_default(
Image::new(
&memory_allocator,
memory_allocator.clone(),
ImageCreateInfo {
image_type: ImageType::Dim2d,
format: Format::R16G16B16A16_SFLOAT,
Expand All @@ -187,7 +187,7 @@ impl FrameSystem {
.unwrap();
let depth_buffer = ImageView::new_default(
Image::new(
&memory_allocator,
memory_allocator.clone(),
ImageCreateInfo {
image_type: ImageType::Dim2d,
format: Format::D16_UNORM,
Expand All @@ -211,21 +211,21 @@ impl FrameSystem {
let ambient_lighting_system = AmbientLightingSystem::new(
gfx_queue.clone(),
lighting_subpass.clone(),
&memory_allocator,
memory_allocator.clone(),
command_buffer_allocator.clone(),
descriptor_set_allocator.clone(),
);
let directional_lighting_system = DirectionalLightingSystem::new(
gfx_queue.clone(),
lighting_subpass.clone(),
&memory_allocator,
memory_allocator.clone(),
command_buffer_allocator.clone(),
descriptor_set_allocator.clone(),
);
let point_lighting_system = PointLightingSystem::new(
gfx_queue.clone(),
lighting_subpass,
&memory_allocator,
memory_allocator.clone(),
command_buffer_allocator.clone(),
descriptor_set_allocator,
);
Expand Down Expand Up @@ -281,7 +281,7 @@ impl FrameSystem {
// render pass their content becomes undefined.
self.diffuse_buffer = ImageView::new_default(
Image::new(
&self.memory_allocator,
self.memory_allocator.clone(),
ImageCreateInfo {
extent,
format: Format::A2B10G10R10_UNORM_PACK32,
Expand All @@ -297,7 +297,7 @@ impl FrameSystem {
.unwrap();
self.normals_buffer = ImageView::new_default(
Image::new(
&self.memory_allocator,
self.memory_allocator.clone(),
ImageCreateInfo {
extent,
format: Format::R16G16B16A16_SFLOAT,
Expand All @@ -313,7 +313,7 @@ impl FrameSystem {
.unwrap();
self.depth_buffer = ImageView::new_default(
Image::new(
&self.memory_allocator,
self.memory_allocator.clone(),
ImageCreateInfo {
extent,
format: Format::D16_UNORM,
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/deferred/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ fn main() {
let triangle_draw_system = TriangleDrawSystem::new(
queue.clone(),
frame_system.deferred_subpass(),
&memory_allocator,
memory_allocator.clone(),
command_buffer_allocator,
);

Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/deferred/triangle_draw_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl TriangleDrawSystem {
pub fn new(
gfx_queue: Arc<Queue>,
subpass: Subpass,
memory_allocator: &StandardMemoryAllocator,
memory_allocator: Arc<StandardMemoryAllocator>,
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
) -> TriangleDrawSystem {
let vertices = [
Expand Down
8 changes: 4 additions & 4 deletions examples/src/bin/dynamic-buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// Each draw or dispatch call can specify an offset into the buffer to read object data from,
// without having to rebind descriptor sets.

use std::{iter::repeat, mem::size_of};
use std::{iter::repeat, mem::size_of, sync::Arc};
use vulkano::{
buffer::{Buffer, BufferCreateInfo, BufferUsage},
command_buffer::{
Expand Down Expand Up @@ -153,7 +153,7 @@ fn main() {
.unwrap()
};

let memory_allocator = StandardMemoryAllocator::new_default(device.clone());
let memory_allocator = Arc::new(StandardMemoryAllocator::new_default(device.clone()));
let descriptor_set_allocator = StandardDescriptorSetAllocator::new(device.clone());
let command_buffer_allocator =
StandardCommandBufferAllocator::new(device.clone(), Default::default());
Expand Down Expand Up @@ -188,7 +188,7 @@ fn main() {
};

let input_buffer = Buffer::from_iter(
&memory_allocator,
memory_allocator.clone(),
BufferCreateInfo {
usage: BufferUsage::UNIFORM_BUFFER,
..Default::default()
Expand All @@ -203,7 +203,7 @@ fn main() {
.unwrap();

let output_buffer = Buffer::from_iter(
&memory_allocator,
memory_allocator,
BufferCreateInfo {
usage: BufferUsage::STORAGE_BUFFER,
..Default::default()
Expand Down
8 changes: 4 additions & 4 deletions examples/src/bin/dynamic-local-size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// Workgroup parallelism capabilities vary between GPUs and setting them properly is important to
// achieve the maximal performance that particular device can provide.

use std::{fs::File, io::BufWriter, path::Path};
use std::{fs::File, io::BufWriter, path::Path, sync::Arc};
use vulkano::{
buffer::{Buffer, BufferCreateInfo, BufferUsage},
command_buffer::{
Expand Down Expand Up @@ -209,13 +209,13 @@ fn main() {
.unwrap()
};

let memory_allocator = StandardMemoryAllocator::new_default(device.clone());
let memory_allocator = Arc::new(StandardMemoryAllocator::new_default(device.clone()));
let descriptor_set_allocator = StandardDescriptorSetAllocator::new(device.clone());
let command_buffer_allocator =
StandardCommandBufferAllocator::new(device.clone(), Default::default());

let image = Image::new(
&memory_allocator,
memory_allocator.clone(),
ImageCreateInfo {
image_type: ImageType::Dim2d,
format: Format::R8G8B8A8_UNORM,
Expand All @@ -238,7 +238,7 @@ fn main() {
.unwrap();

let buf = Buffer::from_iter(
&memory_allocator,
memory_allocator,
BufferCreateInfo {
usage: BufferUsage::TRANSFER_DST,
..Default::default()
Expand Down
13 changes: 6 additions & 7 deletions examples/src/bin/gl-interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ mod linux {
},
memory::{
allocator::{
AllocationCreateInfo, MemoryAlloc, MemoryAllocator, MemoryTypeFilter,
StandardMemoryAllocator,
AllocationCreateInfo, MemoryAllocator, MemoryTypeFilter, StandardMemoryAllocator,
},
DedicatedAllocation, DeviceMemory, ExternalMemoryHandleType, ExternalMemoryHandleTypes,
MemoryAllocateInfo,
MemoryAllocateInfo, ResourceMemory,
},
pipeline::{
graphics::{
Expand Down Expand Up @@ -159,7 +158,7 @@ mod linux {

let image = Arc::new(
raw_image
.bind_memory([MemoryAlloc::new(image_memory)])
.bind_memory([ResourceMemory::new_dedicated(image_memory)])
.map_err(|(err, _, _)| err)
.unwrap(),
);
Expand Down Expand Up @@ -464,7 +463,7 @@ mod linux {
Vec<Arc<Framebuffer>>,
Arc<Sampler>,
Arc<GraphicsPipeline>,
StandardMemoryAllocator,
Arc<StandardMemoryAllocator>,
Subbuffer<[MyVertex]>,
) {
let library = VulkanLibrary::new().unwrap();
Expand Down Expand Up @@ -600,7 +599,7 @@ mod linux {
.unwrap()
};

let memory_allocator = StandardMemoryAllocator::new_default(device.clone());
let memory_allocator = Arc::new(StandardMemoryAllocator::new_default(device.clone()));

let vertices = [
MyVertex {
Expand All @@ -617,7 +616,7 @@ mod linux {
},
];
let vertex_buffer = Buffer::from_iter(
&memory_allocator,
memory_allocator.clone(),
BufferCreateInfo {
usage: BufferUsage::VERTEX_BUFFER,
..Default::default()
Expand Down
8 changes: 4 additions & 4 deletions examples/src/bin/image-self-copy-blit/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fn main() {
.unwrap()
};

let memory_allocator = StandardMemoryAllocator::new_default(device.clone());
let memory_allocator = Arc::new(StandardMemoryAllocator::new_default(device.clone()));

#[derive(BufferContents, Vertex)]
#[repr(C)]
Expand All @@ -180,7 +180,7 @@ fn main() {
},
];
let vertex_buffer = Buffer::from_iter(
&memory_allocator,
memory_allocator.clone(),
BufferCreateInfo {
usage: BufferUsage::VERTEX_BUFFER,
..Default::default()
Expand Down Expand Up @@ -229,7 +229,7 @@ fn main() {
let extent = [info.width * 2, info.height * 2, 1];

let upload_buffer = Buffer::new_slice(
&memory_allocator,
memory_allocator.clone(),
BufferCreateInfo {
usage: BufferUsage::TRANSFER_SRC,
..Default::default()
Expand All @@ -248,7 +248,7 @@ fn main() {
.unwrap();

let image = Image::new(
&memory_allocator,
memory_allocator,
ImageCreateInfo {
format: Format::R8G8B8A8_UNORM,
extent,
Expand Down
Loading