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

Unify all buffer types #2127

Merged
merged 29 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1f89cf9
`CpuBufferPool` revamp
marc0246 Nov 2, 2022
6f0af80
Fix oopsie
marc0246 Nov 3, 2022
7ec4f6f
Fix docs
marc0246 Nov 3, 2022
0f0bed2
Merge branch 'master' into cpu-pool-revamp
marc0246 Nov 5, 2022
6821eb2
Merge branch 'master' into buffer-unification
marc0246 Dec 24, 2022
a2cc1b8
Merge branch 'master' into buffer-unification
marc0246 Dec 28, 2022
24be1f6
Merge branch 'master' into buffer-unification
marc0246 Jan 4, 2023
f9e7309
Add `Subbuffer`
marc0246 Jan 6, 2023
c48c057
Move `Buffer` to `buffer` module
marc0246 Jan 6, 2023
7c4ccfc
Replace all buffer types with `Subbuffer`
marc0246 Jan 6, 2023
4147b1d
Add constraints to `Index` and `QueryResultElement` traits
marc0246 Jan 6, 2023
97c9ce3
Fix oopsies
marc0246 Jan 6, 2023
c935946
Fix examples
marc0246 Jan 6, 2023
253c9c8
Fix doc tests
marc0246 Jan 6, 2023
a188e09
Rename `_unsized` to `_slice`
marc0246 Jan 6, 2023
15a722e
Rename `CpuBufferAllocator`
marc0246 Jan 6, 2023
a819b2c
Implement `DeviceOwned` for `SubbufferAllocator`
marc0246 Jan 6, 2023
351af37
Use better generic type params
marc0246 Jan 10, 2023
8c86f8e
Fix requirement message
marc0246 Jan 10, 2023
33e22e7
Fix docs
marc0246 Jan 10, 2023
06d29f6
Fix missing buffer alignment for texel buffer usage
marc0246 Jan 10, 2023
67962d7
Add more docs to `Subbuffer`
marc0246 Jan 10, 2023
00fa2de
Add more utility functions to `Subbuffer`
marc0246 Jan 11, 2023
4a95e07
Remove superfluous `dst_offset`s
marc0246 Jan 11, 2023
d3ca3a9
Murder `FillBufferInfo`
marc0246 Jan 11, 2023
bceeac4
Fix example
marc0246 Jan 11, 2023
4a2f7d7
Add `Subbuffer::range`
marc0246 Jan 11, 2023
7d77e91
Fix wrong atom size alignment check
marc0246 Jan 11, 2023
b1cdbb7
Specify all fields in create infos derived from `BufferAllocateInfo`
marc0246 Jan 12, 2023
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
10 changes: 6 additions & 4 deletions examples/src/bin/basic-compute-shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// GPU", or *GPGPU*. This is what this example demonstrates.

use vulkano::{
buffer::{BufferUsage, CpuAccessibleBuffer},
buffer::{Buffer, BufferAllocateInfo, BufferUsage},
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
},
Expand Down Expand Up @@ -156,10 +156,12 @@ fn main() {
// Iterator that produces the data.
let data_iter = 0..65536u32;
// Builds the buffer and fills it with this iterator.
CpuAccessibleBuffer::from_iter(
Buffer::from_iter(
&memory_allocator,
BufferUsage::STORAGE_BUFFER,
false,
BufferAllocateInfo {
buffer_usage: BufferUsage::STORAGE_BUFFER,
..Default::default()
},
data_iter,
)
.unwrap()
Expand Down
12 changes: 7 additions & 5 deletions examples/src/bin/buffer-allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// notice may not be copied, modified, or distributed except
// according to those terms.

// Modified triangle example to show `CpuBufferAllocator`.
// Modified triangle example to show `SubbufferAllocator`.

use bytemuck::{Pod, Zeroable};
use std::{
Expand All @@ -16,7 +16,7 @@ use std::{
};
use vulkano::{
buffer::{
allocator::{CpuBufferAllocator, CpuBufferAllocatorCreateInfo},
allocator::{SubbufferAllocator, SubbufferAllocatorCreateInfo},
BufferUsage,
},
command_buffer::{
Expand Down Expand Up @@ -165,9 +165,9 @@ fn main() {

// Using a buffer allocator allows multiple buffers to be "in-flight" simultaneously and is
// suited to highly dynamic data like vertex, index and uniform buffers.
let buffer_allocator = CpuBufferAllocator::new(
let buffer_allocator = SubbufferAllocator::new(
memory_allocator,
CpuBufferAllocatorCreateInfo {
SubbufferAllocatorCreateInfo {
// We want to use the allocated subbuffers as vertex buffers.
buffer_usage: BufferUsage::VERTEX_BUFFER,
..Default::default()
Expand Down Expand Up @@ -336,7 +336,9 @@ fn main() {
let num_vertices = data.len() as u32;

// Allocate a new subbuffer using the buffer allocator.
let buffer = buffer_allocator.from_iter(data.iter().copied()).unwrap();
let buffer = buffer_allocator.allocate_slice(data.len() as _).unwrap();
buffer.write().unwrap().copy_from_slice(&data);

let mut builder = AutoCommandBufferBuilder::primary(
&command_buffer_allocator,
queue.queue_family_index(),
Expand Down
22 changes: 11 additions & 11 deletions examples/src/bin/deferred/frame/ambient_lighting_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use std::sync::Arc;
use vulkano::{
buffer::{BufferUsage, CpuAccessibleBuffer, TypedBufferAccess},
buffer::{Buffer, BufferAllocateInfo, BufferUsage, Subbuffer},
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder,
CommandBufferInheritanceInfo, CommandBufferUsage, SecondaryAutoCommandBuffer,
Expand Down Expand Up @@ -37,7 +37,7 @@ use super::LightingVertex;
/// Allows applying an ambient lighting to a scene.
pub struct AmbientLightingSystem {
gfx_queue: Arc<Queue>,
vertex_buffer: Arc<CpuAccessibleBuffer<[LightingVertex]>>,
vertex_buffer: Subbuffer<[LightingVertex]>,
subpass: Subpass,
pipeline: Arc<GraphicsPipeline>,
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
Expand Down Expand Up @@ -66,15 +66,15 @@ impl AmbientLightingSystem {
position: [3.0, -1.0],
},
];
let vertex_buffer = {
CpuAccessibleBuffer::from_iter(
memory_allocator,
BufferUsage::VERTEX_BUFFER,
false,
vertices,
)
.expect("failed to create buffer")
};
let vertex_buffer = Buffer::from_iter(
memory_allocator,
BufferAllocateInfo {
buffer_usage: BufferUsage::VERTEX_BUFFER,
..Default::default()
},
vertices,
)
.expect("failed to create buffer");

let pipeline = {
let vs = vs::load(gfx_queue.device().clone()).expect("failed to create shader module");
Expand Down
12 changes: 7 additions & 5 deletions examples/src/bin/deferred/frame/directional_lighting_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use cgmath::Vector3;
use std::sync::Arc;
use vulkano::{
buffer::{BufferUsage, CpuAccessibleBuffer, TypedBufferAccess},
buffer::{Buffer, BufferAllocateInfo, BufferUsage, Subbuffer},
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder,
CommandBufferInheritanceInfo, CommandBufferUsage, SecondaryAutoCommandBuffer,
Expand Down Expand Up @@ -38,7 +38,7 @@ use super::LightingVertex;
/// Allows applying a directional light source to a scene.
pub struct DirectionalLightingSystem {
gfx_queue: Arc<Queue>,
vertex_buffer: Arc<CpuAccessibleBuffer<[LightingVertex]>>,
vertex_buffer: Subbuffer<[LightingVertex]>,
subpass: Subpass,
pipeline: Arc<GraphicsPipeline>,
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
Expand Down Expand Up @@ -68,10 +68,12 @@ impl DirectionalLightingSystem {
},
];
let vertex_buffer = {
CpuAccessibleBuffer::from_iter(
Buffer::from_iter(
memory_allocator,
BufferUsage::VERTEX_BUFFER,
false,
BufferAllocateInfo {
buffer_usage: BufferUsage::VERTEX_BUFFER,
..Default::default()
},
vertices,
)
.expect("failed to create buffer")
Expand Down
22 changes: 11 additions & 11 deletions examples/src/bin/deferred/frame/point_lighting_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use cgmath::{Matrix4, Vector3};
use std::sync::Arc;
use vulkano::{
buffer::{BufferUsage, CpuAccessibleBuffer, TypedBufferAccess},
buffer::{Buffer, BufferAllocateInfo, BufferUsage, Subbuffer},
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder,
CommandBufferInheritanceInfo, CommandBufferUsage, SecondaryAutoCommandBuffer,
Expand All @@ -37,7 +37,7 @@ use super::LightingVertex;

pub struct PointLightingSystem {
gfx_queue: Arc<Queue>,
vertex_buffer: Arc<CpuAccessibleBuffer<[LightingVertex]>>,
vertex_buffer: Subbuffer<[LightingVertex]>,
subpass: Subpass,
pipeline: Arc<GraphicsPipeline>,
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
Expand Down Expand Up @@ -66,15 +66,15 @@ impl PointLightingSystem {
position: [3.0, -1.0],
},
];
let vertex_buffer = {
CpuAccessibleBuffer::from_iter(
memory_allocator,
BufferUsage::VERTEX_BUFFER,
false,
vertices,
)
.expect("failed to create buffer")
};
let vertex_buffer = Buffer::from_iter(
memory_allocator,
BufferAllocateInfo {
buffer_usage: BufferUsage::VERTEX_BUFFER,
..Default::default()
},
vertices,
)
.expect("failed to create buffer");

let pipeline = {
let vs = vs::load(gfx_queue.device().clone()).expect("failed to create shader module");
Expand Down
22 changes: 11 additions & 11 deletions examples/src/bin/deferred/triangle_draw_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use bytemuck::{Pod, Zeroable};
use std::sync::Arc;
use vulkano::{
buffer::{BufferUsage, CpuAccessibleBuffer, TypedBufferAccess},
buffer::{Buffer, BufferAllocateInfo, BufferUsage, Subbuffer},
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder,
CommandBufferInheritanceInfo, CommandBufferUsage, SecondaryAutoCommandBuffer,
Expand All @@ -31,7 +31,7 @@ use vulkano::{

pub struct TriangleDrawSystem {
gfx_queue: Arc<Queue>,
vertex_buffer: Arc<CpuAccessibleBuffer<[TriangleVertex]>>,
vertex_buffer: Subbuffer<[TriangleVertex]>,
subpass: Subpass,
pipeline: Arc<GraphicsPipeline>,
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
Expand All @@ -56,15 +56,15 @@ impl TriangleDrawSystem {
position: [0.25, -0.1],
},
];
let vertex_buffer = {
CpuAccessibleBuffer::from_iter(
memory_allocator,
BufferUsage::VERTEX_BUFFER,
false,
vertices,
)
.expect("failed to create buffer")
};
let vertex_buffer = Buffer::from_iter(
memory_allocator,
BufferAllocateInfo {
buffer_usage: BufferUsage::VERTEX_BUFFER,
..Default::default()
},
vertices,
)
.expect("failed to create buffer");

let pipeline = {
let vs = vs::load(gfx_queue.device().clone()).expect("failed to create shader module");
Expand Down
20 changes: 12 additions & 8 deletions examples/src/bin/dynamic-buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use std::{iter::repeat, mem::size_of};
use vulkano::{
buffer::{BufferUsage, CpuAccessibleBuffer},
buffer::{Buffer, BufferAllocateInfo, BufferUsage},
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
},
Expand Down Expand Up @@ -164,18 +164,22 @@ fn main() {
aligned_data
};

let input_buffer = CpuAccessibleBuffer::from_iter(
let input_buffer = Buffer::from_iter(
&memory_allocator,
BufferUsage::UNIFORM_BUFFER,
false,
aligned_data.into_iter(),
BufferAllocateInfo {
buffer_usage: BufferUsage::UNIFORM_BUFFER,
..Default::default()
},
aligned_data,
)
.unwrap();

let output_buffer = CpuAccessibleBuffer::from_iter(
let output_buffer = Buffer::from_iter(
&memory_allocator,
BufferUsage::STORAGE_BUFFER,
false,
BufferAllocateInfo {
buffer_usage: BufferUsage::STORAGE_BUFFER,
..Default::default()
},
(0..12).map(|_| 0u32),
)
.unwrap();
Expand Down
10 changes: 6 additions & 4 deletions examples/src/bin/dynamic-local-size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use std::{fs::File, io::BufWriter, path::Path};
use vulkano::{
buffer::{BufferUsage, CpuAccessibleBuffer},
buffer::{Buffer, BufferAllocateInfo, BufferUsage},
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
CopyImageToBufferInfo,
Expand Down Expand Up @@ -223,10 +223,12 @@ fn main() {
)
.unwrap();

let buf = CpuAccessibleBuffer::from_iter(
let buf = Buffer::from_iter(
&memory_allocator,
BufferUsage::TRANSFER_DST,
false,
BufferAllocateInfo {
buffer_usage: BufferUsage::TRANSFER_DST,
..Default::default()
},
(0..1024 * 1024 * 4).map(|_| 0u8),
)
.unwrap();
Expand Down
12 changes: 7 additions & 5 deletions examples/src/bin/gl-interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod linux {
time::Instant,
};
use vulkano::{
buffer::{BufferUsage, CpuAccessibleBuffer, TypedBufferAccess},
buffer::{Buffer, BufferAllocateInfo, BufferUsage, Subbuffer},
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder,
CommandBufferUsage, RenderPassBeginInfo, SemaphoreSubmitInfo, SubmitInfo,
Expand Down Expand Up @@ -409,7 +409,7 @@ mod linux {
Arc<vulkano::sampler::Sampler>,
Arc<GraphicsPipeline>,
StandardMemoryAllocator,
Arc<CpuAccessibleBuffer<[MyVertex]>>,
Subbuffer<[MyVertex]>,
) {
let library = VulkanLibrary::new().unwrap();
let required_extensions = vulkano_win::required_extensions(&library);
Expand Down Expand Up @@ -567,10 +567,12 @@ mod linux {
position: [0.5, 0.5],
},
];
let vertex_buffer = CpuAccessibleBuffer::<[MyVertex]>::from_iter(
let vertex_buffer = Buffer::from_iter(
&memory_allocator,
BufferUsage::VERTEX_BUFFER,
false,
BufferAllocateInfo {
buffer_usage: BufferUsage::VERTEX_BUFFER,
..Default::default()
},
vertices,
)
.unwrap();
Expand Down
18 changes: 11 additions & 7 deletions examples/src/bin/image-self-copy-blit/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use bytemuck::{Pod, Zeroable};
use std::{io::Cursor, sync::Arc};
use vulkano::{
buffer::{BufferUsage, CpuAccessibleBuffer, TypedBufferAccess},
buffer::{Buffer, BufferAllocateInfo, BufferUsage},
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, BlitImageInfo,
BufferImageCopy, ClearColorImageInfo, CommandBufferUsage, CopyBufferToImageInfo,
Expand Down Expand Up @@ -182,10 +182,12 @@ fn main() {
position: [0.5, 0.5],
},
];
let vertex_buffer = CpuAccessibleBuffer::<[Vertex]>::from_iter(
let vertex_buffer = Buffer::from_iter(
&memory_allocator,
BufferUsage::VERTEX_BUFFER,
false,
BufferAllocateInfo {
buffer_usage: BufferUsage::VERTEX_BUFFER,
..Default::default()
},
vertices,
)
.unwrap();
Expand Down Expand Up @@ -243,10 +245,12 @@ fn main() {
)
.unwrap();

let buffer = CpuAccessibleBuffer::from_iter(
let buffer = Buffer::from_iter(
&memory_allocator,
BufferUsage::TRANSFER_SRC,
false,
BufferAllocateInfo {
buffer_usage: BufferUsage::TRANSFER_SRC,
..Default::default()
},
image_data,
)
.unwrap();
Expand Down
10 changes: 6 additions & 4 deletions examples/src/bin/image/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use bytemuck::{Pod, Zeroable};
use std::{io::Cursor, sync::Arc};
use vulkano::{
buffer::{BufferUsage, CpuAccessibleBuffer, TypedBufferAccess},
buffer::{Buffer, BufferAllocateInfo, BufferUsage},
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
PrimaryCommandBufferAbstract, RenderPassBeginInfo, SubpassContents,
Expand Down Expand Up @@ -180,10 +180,12 @@ fn main() {
position: [0.5, 0.5],
},
];
let vertex_buffer = CpuAccessibleBuffer::<[Vertex]>::from_iter(
let vertex_buffer = Buffer::from_iter(
&memory_allocator,
BufferUsage::VERTEX_BUFFER,
false,
BufferAllocateInfo {
buffer_usage: BufferUsage::VERTEX_BUFFER,
..Default::default()
},
vertices,
)
.unwrap();
Expand Down
Loading