Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into metal-clean
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed Jun 12, 2024
2 parents c812c08 + 95ba6d0 commit 8182a39
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 70 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: CI

jobs:
check_msrv:
name: Check MSRV (1.65.0)
name: Check MSRV (1.69.0)
strategy:
matrix:
include:
Expand All @@ -17,8 +17,9 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/[email protected]
- run: cargo check --workspace --all-targets --features ${{ matrix.features }} --no-default-features
- uses: dtolnay/[email protected]
# Note that examples are extempt from the MSRV check, so that they can use newer Rust features
- run: cargo check --workspace --features ${{ matrix.features }} --no-default-features

test:
name: Test Suite
Expand Down Expand Up @@ -77,8 +78,6 @@ jobs:
# is also unmaintained for 4 years depends on malloc_buf >=0.0,<0.1.0,
# allowing the 0.0.6 release to be used (but not the 1.0.0 release).
cargo update -p malloc_buf --precise 0.0.6
# Force 0.1.2, as older versions use the broken `gcc` crate
cargo update -p objc_exception --precise 0.1.2
- name: Cargo clippy with minimal-versions
run: cargo +stable clippy --workspace --all-targets --features ${{ matrix.features }} --no-default-features -- -D warnings

Expand Down
11 changes: 4 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ homepage = "https://github.com/Traverse-Research/gpu-allocator"
repository = "https://github.com/Traverse-Research/gpu-allocator"
keywords = ["vulkan", "memory", "allocator"]
documentation = "https://docs.rs/gpu-allocator/"
rust-version = "1.65"
rust-version = "1.69"

include = [
"/README.md",
Expand All @@ -28,13 +28,13 @@ thiserror = "1.0"
presser = { version = "0.3" }
# Only needed for Vulkan. Disable all default features as good practice,
# such as the ability to link/load a Vulkan library.
ash = { version = ">=0.34, <=0.37", optional = true, default-features = false, features = ["debug"] }
ash = { version = "0.38", optional = true, default-features = false, features = ["debug"] }
# Only needed for visualizer.
egui = { version = ">=0.24, <=0.27", optional = true, default-features = false }
egui_extras = { version = ">=0.24, <=0.27", optional = true, default-features = false }

[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
metal = { version = "0.27.0", default-features = false, features = ["link", "dispatch"], optional = true }
metal = { version = "0.28.0", git = "https://github.com/gfx-rs/metal-rs", rev = "0d6214f", default-features = false, features = ["link", "dispatch"], optional = true }

[target.'cfg(windows)'.dependencies]
# Only needed for public-winapi interop helpers
Expand All @@ -54,7 +54,7 @@ optional = true

[dev-dependencies]
# Enable the "loaded" feature to be able to access the Vulkan entrypoint.
ash = { version = ">=0.34,<=0.37", default-features = false, features = ["debug", "loaded"] }
ash = { version = "0.38", default-features = false, features = ["debug", "loaded"] }
env_logger = "0.10"

[target.'cfg(windows)'.dev-dependencies]
Expand Down Expand Up @@ -96,6 +96,3 @@ metal = ["dep:metal"]
public-winapi = ["dep:winapi"]

default = ["d3d12", "vulkan"]

[patch.crates-io]
metal = { git = "https://github.com/Traverse-Research/metal-rs", rev = "a354c33" }
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE-MIT)
[![LICENSE](https://img.shields.io/badge/license-apache-blue.svg?logo=apache)](LICENSE-APACHE)
[![Contributor Covenant](https://img.shields.io/badge/contributor%20covenant-v1.4%20adopted-ff69b4.svg)](../main/CODE_OF_CONDUCT.md)
[![MSRV](https://img.shields.io/badge/rustc-1.65.0+-ab6000.svg)](https://blog.rust-lang.org/2022/11/03/Rust-1.65.0.html)
[![MSRV](https://img.shields.io/badge/rustc-1.69.0+-ab6000.svg)](https://blog.rust-lang.org/2023/04/20/Rust-1.69.0.html)

[![Banner](banner.png)](https://traverseresearch.nl)

Expand Down Expand Up @@ -48,7 +48,7 @@ use gpu_allocator::vulkan::*;
use gpu_allocator::MemoryLocation;

// Setup vulkan info
let vk_info = vk::BufferCreateInfo::builder()
let vk_info = vk::BufferCreateInfo::default()
.size(512)
.usage(vk::BufferUsageFlags::STORAGE_BUFFER);

Expand Down Expand Up @@ -163,7 +163,7 @@ allocator.free(&allocation).unwrap();

## Minimum Supported Rust Version

The MSRV for this crate and the `vulkan`, `d3d12` and `metal` features is Rust 1.65. Any other features such as the `visualizer` (with all the `egui` dependencies) may have a higher requirement and are not tested in our CI.
The MSRV for this crate and the `vulkan`, `d3d12` and `metal` features is Rust 1.69. Any other features such as the `visualizer` (with all the `egui` dependencies) may have a higher requirement and are not tested in our CI.

## License

Expand Down
4 changes: 2 additions & 2 deletions README.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE-MIT)
[![LICENSE](https://img.shields.io/badge/license-apache-blue.svg?logo=apache)](LICENSE-APACHE)
[![Contributor Covenant](https://img.shields.io/badge/contributor%20covenant-v1.4%20adopted-ff69b4.svg)](../main/CODE_OF_CONDUCT.md)
[![MSRV](https://img.shields.io/badge/rustc-1.65.0+-ab6000.svg)](https://blog.rust-lang.org/2022/11/03/Rust-1.65.0.html)
[![MSRV](https://img.shields.io/badge/rustc-1.69.0+-ab6000.svg)](https://blog.rust-lang.org/2023/04/20/Rust-1.69.0.html)

[![Banner](banner.png)](https://traverseresearch.nl)

Expand All @@ -21,7 +21,7 @@ gpu-allocator = "0.26.0"

## Minimum Supported Rust Version

The MSRV for this crate and the `vulkan`, `d3d12` and `metal` features is Rust 1.65. Any other features such as the `visualizer` (with all the `egui` dependencies) may have a higher requirement and are not tested in our CI.
The MSRV for this crate and the `vulkan`, `d3d12` and `metal` features is Rust 1.69. Any other features such as the `visualizer` (with all the `egui` dependencies) may have a higher requirement and are not tested in our CI.

## License

Expand Down
10 changes: 3 additions & 7 deletions examples/d3d12-buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ fn create_d3d12_device(
)
};
match hr {
winapi::shared::winerror::S_OK => {
winerror::S_OK => {
info!("Using D3D12 feature level: {}.", feature_level_name);
Some(device)
}
winapi::shared::winerror::E_NOINTERFACE => {
winerror::E_NOINTERFACE => {
error!("ID3D12Device interface not supported.");
None
}
Expand Down Expand Up @@ -106,11 +106,7 @@ fn main() {
)
};

assert_eq!(
hr,
winapi::shared::winerror::S_OK,
"Failed to create DXGI factory",
);
assert_eq!(hr, winerror::S_OK, "Failed to create DXGI factory");
dxgi_factory
};

Expand Down
21 changes: 9 additions & 12 deletions examples/vulkan-buffer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::default::Default;
use std::ffi::CStr;

use ash::vk;
use log::info;
Expand All @@ -16,20 +15,18 @@ fn main() {

// Create Vulkan instance
let instance = {
let app_name = CStr::from_bytes_with_nul(b"Vulkan gpu-allocator test\0").unwrap();
let app_name = c"Vulkan gpu-allocator test";

let appinfo = vk::ApplicationInfo::builder()
let appinfo = vk::ApplicationInfo::default()
.application_name(app_name)
.application_version(0)
.engine_name(app_name)
.engine_version(0)
.api_version(vk::make_api_version(0, 1, 0, 0));

let layer_names_raw = [CStr::from_bytes_with_nul(b"VK_LAYER_KHRONOS_validation\0")
.unwrap()
.as_ptr()];
let layer_names_raw = [c"VK_LAYER_KHRONOS_validation".as_ptr()];

let create_info = vk::InstanceCreateInfo::builder()
let create_info = vk::InstanceCreateInfo::default()
.application_info(&appinfo)
.enabled_layer_names(&layer_names_raw);

Expand Down Expand Up @@ -74,11 +71,11 @@ fn main() {
};
let priorities = [1.0];

let queue_info = vk::DeviceQueueCreateInfo::builder()
let queue_info = vk::DeviceQueueCreateInfo::default()
.queue_family_index(queue_family_index as u32)
.queue_priorities(&priorities);

let create_info = vk::DeviceCreateInfo::builder()
let create_info = vk::DeviceCreateInfo::default()
.queue_create_infos(std::slice::from_ref(&queue_info))
.enabled_extension_names(&device_extension_names_raw)
.enabled_features(&features);
Expand All @@ -99,7 +96,7 @@ fn main() {

// Test allocating Gpu Only memory
{
let test_buffer_info = vk::BufferCreateInfo::builder()
let test_buffer_info = vk::BufferCreateInfo::default()
.size(512)
.usage(vk::BufferUsageFlags::STORAGE_BUFFER)
.sharing_mode(vk::SharingMode::EXCLUSIVE);
Expand Down Expand Up @@ -132,7 +129,7 @@ fn main() {

// Test allocating Cpu to Gpu memory
{
let test_buffer_info = vk::BufferCreateInfo::builder()
let test_buffer_info = vk::BufferCreateInfo::default()
.size(512)
.usage(vk::BufferUsageFlags::STORAGE_BUFFER)
.sharing_mode(vk::SharingMode::EXCLUSIVE);
Expand Down Expand Up @@ -165,7 +162,7 @@ fn main() {

// Test allocating Gpu to Cpu memory
{
let test_buffer_info = vk::BufferCreateInfo::builder()
let test_buffer_info = vk::BufferCreateInfo::default()
.size(512)
.usage(vk::BufferUsageFlags::STORAGE_BUFFER)
.sharing_mode(vk::SharingMode::EXCLUSIVE);
Expand Down
4 changes: 0 additions & 4 deletions src/allocator/dedicated_block_allocator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ impl SubAllocator for DedicatedBlockAllocator {
}]
}

fn size(&self) -> u64 {
self.size
}

fn allocated(&self) -> u64 {
self.allocated
}
Expand Down
4 changes: 0 additions & 4 deletions src/allocator/free_list_allocator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,6 @@ impl SubAllocator for FreeListAllocator {
.collect::<Vec<_>>()
}

fn size(&self) -> u64 {
self.size
}

fn allocated(&self) -> u64 {
self.allocated
}
Expand Down
8 changes: 0 additions & 8 deletions src/allocator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,8 @@ pub(crate) trait SubAllocator: SubAllocatorBase + std::fmt::Debug + Sync + Send
#[must_use]
fn supports_general_allocations(&self) -> bool;
#[must_use]
fn size(&self) -> u64;
#[must_use]
fn allocated(&self) -> u64;

/// Helper function: reports how much memory is available in this suballocator
#[must_use]
fn available_memory(&self) -> u64 {
self.size() - self.allocated()
}

/// Helper function: reports if the suballocator is empty (meaning, having no allocations).
#[must_use]
fn is_empty(&self) -> bool {
Expand Down
8 changes: 6 additions & 2 deletions src/d3d12/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,16 @@ pub struct AllocatorCreateDesc {
}

pub enum ResourceType<'a> {
/// Allocation equivalent to Dx12's CommittedResource.
/// Create a D3D12 [`CommittedResource`].
///
/// [`CommittedResource`]: https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12device-createcommittedresource
Committed {
heap_properties: &'a D3D12_HEAP_PROPERTIES,
heap_flags: D3D12_HEAP_FLAGS,
},
/// Allocation equivalent to Dx12's PlacedResource.
/// Create a D3D12 [`PlacedResource`].
///
/// [`PlacedResource`]: https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12device-createplacedresource
Placed,
}

Expand Down
9 changes: 3 additions & 6 deletions src/d3d12/visualizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl AllocatorVisualizer {
let mut total_allocated = 0;

for block in mem_type.memory_blocks.iter().flatten() {
total_block_size += block.sub_allocator.size();
total_block_size += block.size;
total_allocated += block.sub_allocator.allocated();
}

Expand Down Expand Up @@ -134,10 +134,7 @@ impl AllocatorVisualizer {
let Some(block) = block else { continue };

ui.collapsing(format!("Block: {}", block_idx), |ui| {
ui.label(format!(
"size: {} KiB",
block.sub_allocator.size() / 1024
));
ui.label(format!("size: {} KiB", block.size / 1024));
ui.label(format!(
"allocated: {} KiB",
block.sub_allocator.allocated() / 1024
Expand Down Expand Up @@ -205,7 +202,7 @@ impl AllocatorVisualizer {
"Memory type {}, Memory block {}, Block size: {} KiB",
window.memory_type_index,
window.block_index,
memblock.sub_allocator.size() / 1024
memblock.size / 1024
));

window
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
//! # }).unwrap();
//!
//! // Setup vulkan info
//! let vk_info = vk::BufferCreateInfo::builder()
//! let vk_info = vk::BufferCreateInfo::default()
//! .size(512)
//! .usage(vk::BufferUsageFlags::STORAGE_BUFFER);
//!
Expand Down
18 changes: 9 additions & 9 deletions src/vulkan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ unsafe impl Sync for SendSyncPtr {}
pub struct AllocatorCreateDesc {
pub instance: ash::Instance,
pub device: ash::Device,
pub physical_device: ash::vk::PhysicalDevice,
pub physical_device: vk::PhysicalDevice,
pub debug_settings: AllocatorDebugSettings,
pub buffer_device_address: bool,
pub allocation_sizes: AllocationSizes,
Expand Down Expand Up @@ -105,7 +105,7 @@ pub struct AllocatorCreateDesc {
/// let my_gpu_data: Vec<MyGpuData> = make_vertex_data();
/// ```
///
/// Depending on how the data we're copying will be used, the vulkan device may have a minimum
/// Depending on how the data we're copying will be used, the Vulkan device may have a minimum
/// alignment requirement for that data:
///
/// ```ignore
Expand Down Expand Up @@ -180,7 +180,7 @@ impl Allocation {
///
/// [`Slab`]: presser::Slab
// best to be explicit where the lifetime is coming from since we're doing unsafe things
// and relying on an inferred liftime type in the PhantomData below
// and relying on an inferred lifetime type in the PhantomData below
#[allow(clippy::needless_lifetimes)]
pub fn try_as_mapped_slab<'a>(&'a mut self) -> Option<MappedAllocationSlab<'a>> {
let mapped_ptr = self.mapped_ptr()?.cast().as_ptr();
Expand Down Expand Up @@ -352,12 +352,12 @@ impl MemoryBlock {
requires_personal_block: bool,
) -> Result<Self> {
let device_memory = {
let alloc_info = vk::MemoryAllocateInfo::builder()
let alloc_info = vk::MemoryAllocateInfo::default()
.allocation_size(size)
.memory_type_index(mem_type_index as u32);

let allocation_flags = vk::MemoryAllocateFlags::DEVICE_ADDRESS;
let mut flags_info = vk::MemoryAllocateFlagsInfo::builder().flags(allocation_flags);
let mut flags_info = vk::MemoryAllocateFlagsInfo::default().flags(allocation_flags);
// TODO(manon): Test this based on if the device has this feature enabled or not
let alloc_info = if buffer_device_address {
alloc_info.push_next(&mut flags_info)
Expand All @@ -366,7 +366,7 @@ impl MemoryBlock {
};

// Flag the memory as dedicated if required.
let mut dedicated_memory_info = vk::MemoryDedicatedAllocateInfo::builder();
let mut dedicated_memory_info = vk::MemoryDedicatedAllocateInfo::default();
let alloc_info = match allocation_scheme {
AllocationScheme::DedicatedBuffer(buffer) => {
dedicated_memory_info = dedicated_memory_info.buffer(buffer);
Expand Down Expand Up @@ -737,7 +737,7 @@ impl fmt::Debug for Allocator {

impl Allocator {
pub fn new(desc: &AllocatorCreateDesc) -> Result<Self> {
if desc.physical_device == ash::vk::PhysicalDevice::null() {
if desc.physical_device == vk::PhysicalDevice::null() {
return Err(AllocationError::InvalidAllocatorCreateDesc(
"AllocatorCreateDesc field `physical_device` is null.".into(),
));
Expand All @@ -748,8 +748,8 @@ impl Allocator {
.get_physical_device_memory_properties(desc.physical_device)
};

let memory_types = &mem_props.memory_types[..mem_props.memory_type_count as _];
let memory_heaps = mem_props.memory_heaps[..mem_props.memory_heap_count as _].to_vec();
let memory_types = &mem_props.memory_types_as_slice();
let memory_heaps = mem_props.memory_heaps_as_slice().to_vec();

if desc.debug_settings.log_memory_information {
debug!("memory type count: {}", mem_props.memory_type_count);
Expand Down

0 comments on commit 8182a39

Please sign in to comment.