Skip to content

Commit

Permalink
Switch to a more expressive way to specify memory usage (vulkano-rs#2264
Browse files Browse the repository at this point in the history
)

* Switch to a more expressive way to specify memory usage

* Fix tests

* Fix examples

* Forgot to adjust `SubbufferAllocatorCreateInfo::location_preference`s

* Oopsie

* Redo all of it

* Oopsie
  • Loading branch information
marc0246 authored and hakolao committed Feb 20, 2024
1 parent 6bae55e commit f578ed0
Show file tree
Hide file tree
Showing 45 changed files with 579 additions and 317 deletions.
11 changes: 7 additions & 4 deletions examples/src/bin/async-update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ use vulkano::{
Image, ImageCreateInfo, ImageType, ImageUsage,
},
instance::{Instance, InstanceCreateFlags, InstanceCreateInfo},
memory::allocator::{AllocationCreateInfo, MemoryUsage, StandardMemoryAllocator},
memory::allocator::{AllocationCreateInfo, MemoryTypeFilter, StandardMemoryAllocator},
pipeline::{
graphics::{
color_blend::ColorBlendState,
Expand Down Expand Up @@ -281,7 +281,8 @@ fn main() {
..Default::default()
},
AllocationCreateInfo {
usage: MemoryUsage::Upload,
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
vertices,
Expand All @@ -299,7 +300,8 @@ fn main() {
..Default::default()
},
AllocationCreateInfo {
usage: MemoryUsage::Upload,
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
)
Expand Down Expand Up @@ -715,7 +717,8 @@ fn run_worker(
..Default::default()
},
AllocationCreateInfo {
usage: MemoryUsage::Upload,
memory_type_filter: MemoryTypeFilter::PREFER_HOST
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
(0..TRANSFER_GRANULARITY * TRANSFER_GRANULARITY).map(|_| [0u8; 4]),
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 @@ -26,7 +26,7 @@ use vulkano::{
QueueFlags,
},
instance::{Instance, InstanceCreateFlags, InstanceCreateInfo},
memory::allocator::{AllocationCreateInfo, MemoryUsage, StandardMemoryAllocator},
memory::allocator::{AllocationCreateInfo, MemoryTypeFilter, StandardMemoryAllocator},
pipeline::{
compute::ComputePipelineCreateInfo, layout::PipelineDescriptorSetLayoutCreateInfo,
ComputePipeline, Pipeline, PipelineBindPoint, PipelineLayout,
Expand Down Expand Up @@ -171,7 +171,8 @@ fn main() {
..Default::default()
},
AllocationCreateInfo {
usage: MemoryUsage::Upload,
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_RANDOM_ACCESS,
..Default::default()
},
// Iterator that produces the data.
Expand Down
4 changes: 3 additions & 1 deletion examples/src/bin/buffer-allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use vulkano::{
},
image::{view::ImageView, Image, ImageUsage},
instance::{Instance, InstanceCreateFlags, InstanceCreateInfo},
memory::allocator::StandardMemoryAllocator,
memory::allocator::{MemoryTypeFilter, StandardMemoryAllocator},
pipeline::{
graphics::{
color_blend::ColorBlendState,
Expand Down Expand Up @@ -169,6 +169,8 @@ fn main() {
SubbufferAllocatorCreateInfo {
// We want to use the allocated subbuffers as vertex buffers.
buffer_usage: BufferUsage::VERTEX_BUFFER,
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
);
Expand Down
5 changes: 3 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, MemoryUsage},
memory::allocator::{AllocationCreateInfo, MemoryAllocator, MemoryTypeFilter},
pipeline::{
graphics::{
color_blend::{AttachmentBlend, BlendFactor, BlendOp, ColorBlendState},
Expand Down Expand Up @@ -78,7 +78,8 @@ impl AmbientLightingSystem {
..Default::default()
},
AllocationCreateInfo {
usage: MemoryUsage::Upload,
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
vertices,
Expand Down
31 changes: 15 additions & 16 deletions examples/src/bin/deferred/frame/directional_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, MemoryUsage},
memory::allocator::{AllocationCreateInfo, MemoryAllocator, MemoryTypeFilter},
pipeline::{
graphics::{
color_blend::{AttachmentBlend, BlendFactor, BlendOp, ColorBlendState},
Expand Down Expand Up @@ -72,21 +72,20 @@ impl DirectionalLightingSystem {
position: [3.0, -1.0],
},
];
let vertex_buffer = {
Buffer::from_iter(
memory_allocator,
BufferCreateInfo {
usage: BufferUsage::VERTEX_BUFFER,
..Default::default()
},
AllocationCreateInfo {
usage: MemoryUsage::Upload,
..Default::default()
},
vertices,
)
.expect("failed to create buffer")
};
let vertex_buffer = Buffer::from_iter(
memory_allocator,
BufferCreateInfo {
usage: BufferUsage::VERTEX_BUFFER,
..Default::default()
},
AllocationCreateInfo {
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
vertices,
)
.expect("failed to create buffer");

let pipeline = {
let device = gfx_queue.device();
Expand Down
5 changes: 3 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, MemoryUsage},
memory::allocator::{AllocationCreateInfo, MemoryAllocator, MemoryTypeFilter},
pipeline::{
graphics::{
color_blend::{AttachmentBlend, BlendFactor, BlendOp, ColorBlendState},
Expand Down Expand Up @@ -78,7 +78,8 @@ impl PointLightingSystem {
..Default::default()
},
AllocationCreateInfo {
usage: MemoryUsage::Upload,
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
vertices,
Expand Down
5 changes: 3 additions & 2 deletions examples/src/bin/deferred/triangle_draw_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use vulkano::{
CommandBufferInheritanceInfo, CommandBufferUsage, SecondaryAutoCommandBuffer,
},
device::Queue,
memory::allocator::{AllocationCreateInfo, MemoryUsage, StandardMemoryAllocator},
memory::allocator::{AllocationCreateInfo, MemoryTypeFilter, StandardMemoryAllocator},
pipeline::{
graphics::{
color_blend::ColorBlendState,
Expand Down Expand Up @@ -67,7 +67,8 @@ impl TriangleDrawSystem {
..Default::default()
},
AllocationCreateInfo {
usage: MemoryUsage::Upload,
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
vertices,
Expand Down
8 changes: 5 additions & 3 deletions examples/src/bin/dynamic-buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use vulkano::{
QueueFlags,
},
instance::{Instance, InstanceCreateFlags, InstanceCreateInfo},
memory::allocator::{AllocationCreateInfo, MemoryUsage, StandardMemoryAllocator},
memory::allocator::{AllocationCreateInfo, MemoryTypeFilter, StandardMemoryAllocator},
pipeline::{
compute::ComputePipelineCreateInfo, layout::PipelineDescriptorSetLayoutCreateInfo,
ComputePipeline, Pipeline, PipelineBindPoint, PipelineLayout,
Expand Down Expand Up @@ -194,7 +194,8 @@ fn main() {
..Default::default()
},
AllocationCreateInfo {
usage: MemoryUsage::Upload,
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
aligned_data,
Expand All @@ -208,7 +209,8 @@ fn main() {
..Default::default()
},
AllocationCreateInfo {
usage: MemoryUsage::Upload,
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_RANDOM_ACCESS,
..Default::default()
},
(0..12).map(|_| 0u32),
Expand Down
5 changes: 3 additions & 2 deletions examples/src/bin/dynamic-local-size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use vulkano::{
format::Format,
image::{view::ImageView, Image, ImageCreateInfo, ImageType, ImageUsage},
instance::{Instance, InstanceCreateFlags, InstanceCreateInfo, InstanceExtensions},
memory::allocator::{AllocationCreateInfo, MemoryUsage, StandardMemoryAllocator},
memory::allocator::{AllocationCreateInfo, MemoryTypeFilter, StandardMemoryAllocator},
pipeline::{
compute::ComputePipelineCreateInfo, layout::PipelineDescriptorSetLayoutCreateInfo,
ComputePipeline, Pipeline, PipelineBindPoint, PipelineLayout,
Expand Down Expand Up @@ -244,7 +244,8 @@ fn main() {
..Default::default()
},
AllocationCreateInfo {
usage: MemoryUsage::Download,
memory_type_filter: MemoryTypeFilter::PREFER_HOST
| MemoryTypeFilter::HOST_RANDOM_ACCESS,
..Default::default()
},
(0..1024 * 1024 * 4).map(|_| 0u8),
Expand Down
7 changes: 4 additions & 3 deletions examples/src/bin/gl-interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ mod linux {
},
memory::{
allocator::{
AllocationCreateInfo, MemoryAlloc, MemoryAllocator, MemoryUsage,
AllocationCreateInfo, MemoryAlloc, MemoryAllocator, MemoryTypeFilter,
StandardMemoryAllocator,
},
DedicatedAllocation, DeviceMemory, ExternalMemoryHandleType, ExternalMemoryHandleTypes,
Expand Down Expand Up @@ -139,7 +139,7 @@ mod linux {
memory_type_index: memory_allocator
.find_memory_type_index(
image_requirements.memory_type_bits,
MemoryUsage::DeviceOnly.into(),
MemoryTypeFilter::PREFER_DEVICE,
)
.unwrap(),
dedicated_allocation: Some(DedicatedAllocation::Image(&raw_image)),
Expand Down Expand Up @@ -610,7 +610,8 @@ mod linux {
..Default::default()
},
AllocationCreateInfo {
usage: MemoryUsage::Upload,
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
vertices,
Expand Down
8 changes: 5 additions & 3 deletions examples/src/bin/image-self-copy-blit/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use vulkano::{
Image, ImageCreateInfo, ImageLayout, ImageUsage,
},
instance::{Instance, InstanceCreateFlags, InstanceCreateInfo},
memory::allocator::{AllocationCreateInfo, MemoryUsage, StandardMemoryAllocator},
memory::allocator::{AllocationCreateInfo, MemoryTypeFilter, StandardMemoryAllocator},
pipeline::{
graphics::{
color_blend::ColorBlendState,
Expand Down Expand Up @@ -188,7 +188,8 @@ fn main() {
..Default::default()
},
AllocationCreateInfo {
usage: MemoryUsage::Upload,
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
vertices,
Expand Down Expand Up @@ -236,7 +237,8 @@ fn main() {
..Default::default()
},
AllocationCreateInfo {
usage: MemoryUsage::Upload,
memory_type_filter: MemoryTypeFilter::PREFER_HOST
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
(info.width * info.height * 4) as DeviceSize,
Expand Down
8 changes: 5 additions & 3 deletions examples/src/bin/image/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use vulkano::{
Image, ImageCreateInfo, ImageType, ImageUsage,
},
instance::{Instance, InstanceCreateFlags, InstanceCreateInfo},
memory::allocator::{AllocationCreateInfo, MemoryUsage, StandardMemoryAllocator},
memory::allocator::{AllocationCreateInfo, MemoryTypeFilter, StandardMemoryAllocator},
pipeline::{
graphics::{
color_blend::ColorBlendState,
Expand Down Expand Up @@ -186,7 +186,8 @@ fn main() {
..Default::default()
},
AllocationCreateInfo {
usage: MemoryUsage::Upload,
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
vertices,
Expand Down Expand Up @@ -234,7 +235,8 @@ fn main() {
..Default::default()
},
AllocationCreateInfo {
usage: MemoryUsage::Upload,
memory_type_filter: MemoryTypeFilter::PREFER_HOST
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
(info.width * info.height * 4) as DeviceSize,
Expand Down
8 changes: 5 additions & 3 deletions examples/src/bin/immutable-sampler/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use vulkano::{
Image, ImageCreateInfo, ImageType, ImageUsage,
},
instance::{Instance, InstanceCreateFlags, InstanceCreateInfo},
memory::allocator::{AllocationCreateInfo, MemoryUsage, StandardMemoryAllocator},
memory::allocator::{AllocationCreateInfo, MemoryTypeFilter, StandardMemoryAllocator},
pipeline::{
graphics::{
color_blend::ColorBlendState,
Expand Down Expand Up @@ -192,7 +192,8 @@ fn main() {
..Default::default()
},
AllocationCreateInfo {
usage: MemoryUsage::Upload,
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
vertices,
Expand Down Expand Up @@ -240,7 +241,8 @@ fn main() {
..Default::default()
},
AllocationCreateInfo {
usage: MemoryUsage::Upload,
memory_type_filter: MemoryTypeFilter::PREFER_HOST
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
(info.width * info.height * 4) as DeviceSize,
Expand Down
6 changes: 5 additions & 1 deletion examples/src/bin/indirect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use vulkano::{
},
image::{view::ImageView, Image, ImageUsage},
instance::{Instance, InstanceCreateFlags, InstanceCreateInfo},
memory::allocator::StandardMemoryAllocator,
memory::allocator::{MemoryTypeFilter, StandardMemoryAllocator},
pipeline::{
compute::ComputePipelineCreateInfo,
graphics::{
Expand Down Expand Up @@ -253,13 +253,17 @@ fn main() {
memory_allocator.clone(),
SubbufferAllocatorCreateInfo {
buffer_usage: BufferUsage::INDIRECT_BUFFER | BufferUsage::STORAGE_BUFFER,
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
);
let vertex_pool = SubbufferAllocator::new(
memory_allocator,
SubbufferAllocatorCreateInfo {
buffer_usage: BufferUsage::STORAGE_BUFFER | BufferUsage::VERTEX_BUFFER,
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
);
Expand Down
Loading

0 comments on commit f578ed0

Please sign in to comment.