Skip to content

Commit

Permalink
merge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Neo-Zhixing committed Jan 31, 2024
1 parent 06bb8be commit 7918073
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 48 deletions.
2 changes: 1 addition & 1 deletion examples/demo.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate ash;
extern crate vma;
extern crate vk_mem;

/*
use ash::extensions::DebugReport;
Expand Down
23 changes: 11 additions & 12 deletions src/definitions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::ffi;
use ash::vk;
use ash::vk::PhysicalDevice;
use ash::{Device, Instance};
use bitflags::bitflags;
use std::marker::PhantomData;
use std::ptr;
Expand Down Expand Up @@ -374,21 +375,20 @@ bitflags! {
}
}

pub struct AllocatorCreateInfo<'a, I, D> {
pub struct AllocatorCreateInfo<'a> {
pub(crate) inner: ffi::VmaAllocatorCreateInfo,
pub(crate) physical_device: PhysicalDevice,
pub(crate) instance: I,
pub(crate) device: D,
pub(crate) _phantom_data: PhantomData<&'a u8>,
pub(crate) device: &'a Device,
pub(crate) instance: &'a Instance,
}

impl<'a, I, D> AllocatorCreateInfo<'a, I, D>
where
I: Deref<Target = ash::Instance>,
D: Deref<Target = ash::Device>,
{
pub fn new(instance: I, device: D, physical_device: ash::vk::PhysicalDevice) -> Self {
Self {
impl<'a> AllocatorCreateInfo<'a> {
pub fn new(
instance: &'a ash::Instance,
device: &'a ash::Device,
physical_device: ash::vk::PhysicalDevice,
) -> AllocatorCreateInfo<'a> {
AllocatorCreateInfo {
inner: ffi::VmaAllocatorCreateInfo {
flags: 0,
physicalDevice: physical_device,
Expand All @@ -405,7 +405,6 @@ where
physical_device,
device,
instance,
_phantom_data: Default::default(),
}
}

Expand Down
7 changes: 1 addition & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub use virtual_block::*;
use ash::prelude::VkResult;
use ash::vk;
use std::mem;
use std::ops::Deref;

/// Main allocator object
pub struct Allocator {
Expand Down Expand Up @@ -48,11 +47,7 @@ unsafe impl Sync for Allocation {}

impl Allocator {
/// Constructor a new `Allocator` using the provided options.
pub fn new<'a, I, D>(mut create_info: AllocatorCreateInfo<'a, I, D>) -> VkResult<Self>
where
I: Deref<Target = ash::Instance>,
D: Deref<Target = ash::Device>,
{
pub fn new(mut create_info: AllocatorCreateInfo) -> VkResult<Self> {
unsafe extern "system" fn get_instance_proc_addr_stub(
_instance: ash::vk::Instance,
_p_name: *const ::std::os::raw::c_char,
Expand Down
58 changes: 29 additions & 29 deletions tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
extern crate ash;
extern crate vma;
extern crate vk_mem;

use ash::{extensions::ext::DebugUtils, vk};
use std::{os::raw::c_void, sync::Arc};
use vma::Alloc;
use vk_mem::Alloc;

fn extension_names() -> Vec<*const i8> {
vec![DebugUtils::name().as_ptr()]
Expand Down Expand Up @@ -137,10 +137,10 @@ impl TestHarness {
}
}

pub fn create_allocator(&self) -> vma::Allocator {
pub fn create_allocator(&self) -> vk_mem::Allocator {
let create_info =
vma::AllocatorCreateInfo::new(&self.instance, &self.device, self.physical_device);
vma::Allocator::new(create_info).unwrap()
vk_mem::AllocatorCreateInfo::new(&self.instance, &self.device, self.physical_device);
vk_mem::Allocator::new(create_info).unwrap()
}
}

Expand All @@ -159,8 +159,8 @@ fn create_allocator() {
fn create_gpu_buffer() {
let harness = TestHarness::new();
let allocator = harness.create_allocator();
let allocation_info = vma::AllocationCreateInfo {
usage: vma::MemoryUsage::Auto,
let allocation_info = vk_mem::AllocationCreateInfo {
usage: vk_mem::MemoryUsage::Auto,
..Default::default()
};

Expand All @@ -187,11 +187,11 @@ fn create_gpu_buffer() {
fn create_cpu_buffer_preferred() {
let harness = TestHarness::new();
let allocator = harness.create_allocator();
let allocation_info = vma::AllocationCreateInfo {
let allocation_info = vk_mem::AllocationCreateInfo {
required_flags: ash::vk::MemoryPropertyFlags::HOST_VISIBLE,
preferred_flags: ash::vk::MemoryPropertyFlags::HOST_COHERENT
| ash::vk::MemoryPropertyFlags::HOST_CACHED,
flags: vma::AllocationCreateFlags::MAPPED,
flags: vk_mem::AllocationCreateFlags::MAPPED,
..Default::default()
};
unsafe {
Expand Down Expand Up @@ -224,11 +224,11 @@ fn create_gpu_buffer_pool() {
.usage(ash::vk::BufferUsageFlags::UNIFORM_BUFFER | ash::vk::BufferUsageFlags::TRANSFER_DST)
.build();

let allocation_info = vma::AllocationCreateInfo {
let allocation_info = vk_mem::AllocationCreateInfo {
required_flags: ash::vk::MemoryPropertyFlags::HOST_VISIBLE,
preferred_flags: ash::vk::MemoryPropertyFlags::HOST_COHERENT
| ash::vk::MemoryPropertyFlags::HOST_CACHED,
flags: vma::AllocationCreateFlags::MAPPED,
flags: vk_mem::AllocationCreateFlags::MAPPED,

..Default::default()
};
Expand All @@ -238,7 +238,7 @@ fn create_gpu_buffer_pool() {
.unwrap();

// Create a pool that can have at most 2 blocks, 128 MiB each.
let pool_info = vma::PoolCreateInfo::new()
let pool_info = vk_mem::PoolCreateInfo::new()
.memory_type_index(memory_type_index)
.block_size(128 * 1024 * 1024)
.max_block_count(2);
Expand All @@ -256,8 +256,8 @@ fn create_gpu_buffer_pool() {
fn test_gpu_stats() {
let harness = TestHarness::new();
let allocator = harness.create_allocator();
let allocation_info = vma::AllocationCreateInfo {
usage: vma::MemoryUsage::Auto,
let allocation_info = vk_mem::AllocationCreateInfo {
usage: vk_mem::MemoryUsage::Auto,
..Default::default()
};

Expand Down Expand Up @@ -296,23 +296,23 @@ fn test_gpu_stats() {

#[test]
fn create_virtual_block() {
let create_info = vma::VirtualBlockCreateInfo::new()
let create_info = vk_mem::VirtualBlockCreateInfo::new()
.size(16 * 1024 * 1024)
.flags(vma::VirtualBlockCreateFlags::VMA_VIRTUAL_BLOCK_CREATE_LINEAR_ALGORITHM_BIT); // 16MB block
let _virtual_block = vma::VirtualBlock::new(create_info).expect("Couldn't create VirtualBlock");
.flags(vk_mem::VirtualBlockCreateFlags::VMA_VIRTUAL_BLOCK_CREATE_LINEAR_ALGORITHM_BIT); // 16MB block
let _virtual_block = vk_mem::VirtualBlock::new(create_info).expect("Couldn't create VirtualBlock");
}

#[test]
fn virtual_allocate_and_free() {
let create_info = vma::VirtualBlockCreateInfo::new().size(16 * 1024 * 1024); // 16MB block
let create_info = vk_mem::VirtualBlockCreateInfo::new().size(16 * 1024 * 1024); // 16MB block
let mut virtual_block =
vma::VirtualBlock::new(create_info).expect("Couldn't create VirtualBlock");
vk_mem::VirtualBlock::new(create_info).expect("Couldn't create VirtualBlock");

let allocation_info = vma::VirtualAllocationCreateInfo {
let allocation_info = vk_mem::VirtualAllocationCreateInfo {
size: 8 * 1024 * 1024,
alignment: 0,
user_data: 0,
flags: vma::VirtualAllocationCreateFlags::empty(),
flags: vk_mem::VirtualAllocationCreateFlags::empty(),
};

// Fully allocate the VirtualBlock and then free both allocations
Expand All @@ -338,16 +338,16 @@ fn virtual_allocate_and_free() {

#[test]
fn virtual_allocation_user_data() {
let create_info = vma::VirtualBlockCreateInfo::new().size(16 * 1024 * 1024); // 16MB block
let create_info = vk_mem::VirtualBlockCreateInfo::new().size(16 * 1024 * 1024); // 16MB block
let mut virtual_block =
vma::VirtualBlock::new(create_info).expect("Couldn't create VirtualBlock");
vk_mem::VirtualBlock::new(create_info).expect("Couldn't create VirtualBlock");

let user_data = Box::new(vec![12, 34, 56, 78, 90]);
let allocation_info = vma::VirtualAllocationCreateInfo {
let allocation_info = vk_mem::VirtualAllocationCreateInfo {
size: 8 * 1024 * 1024,
alignment: 0,
user_data: user_data.as_ptr() as usize,
flags: vma::VirtualAllocationCreateFlags::empty(),
flags: vk_mem::VirtualAllocationCreateFlags::empty(),
};

unsafe {
Expand All @@ -363,15 +363,15 @@ fn virtual_allocation_user_data() {

#[test]
fn virtual_block_out_of_space() {
let create_info = vma::VirtualBlockCreateInfo::new().size(16 * 1024 * 1024); // 16MB block
let create_info = vk_mem::VirtualBlockCreateInfo::new().size(16 * 1024 * 1024); // 16MB block
let mut virtual_block =
vma::VirtualBlock::new(create_info).expect("Couldn't create VirtualBlock");
vk_mem::VirtualBlock::new(create_info).expect("Couldn't create VirtualBlock");

let allocation_info = vma::VirtualAllocationCreateInfo {
let allocation_info = vk_mem::VirtualAllocationCreateInfo {
size: 16 * 1024 * 1024 + 1,
alignment: 0,
user_data: 0,
flags: vma::VirtualAllocationCreateFlags::empty(),
flags: vk_mem::VirtualAllocationCreateFlags::empty(),
};

unsafe {
Expand Down

0 comments on commit 7918073

Please sign in to comment.