Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

std::mem::{size_of[val],align_of[val]} are in the prelude now; use 'em #2647

Merged
merged 1 commit into from
Feb 9, 2025
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
2 changes: 1 addition & 1 deletion examples/dynamic-buffers/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,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, sync::Arc};
use std::{iter::repeat, sync::Arc};
use vulkano::{
buffer::{Buffer, BufferCreateInfo, BufferUsage},
command_buffer::{
Expand Down
2 changes: 1 addition & 1 deletion examples/ray-tracing-auto/scene.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::App;
use glam::{Mat4, Vec3};
use std::{iter, mem::size_of, sync::Arc};
use std::{iter, sync::Arc};
use vulkano::{
acceleration_structure::{
AccelerationStructure, AccelerationStructureBuildGeometryInfo,
Expand Down
2 changes: 1 addition & 1 deletion examples/ray-tracing/scene.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{App, RenderContext};
use glam::{Mat4, Vec3};
use std::{iter, mem::size_of, sync::Arc};
use std::{iter, sync::Arc};
use vulkano::{
acceleration_structure::{
AccelerationStructure, AccelerationStructureBuildGeometryInfo,
Expand Down
4 changes: 2 additions & 2 deletions vulkano-taskgraph/src/command_buffer/commands/bind_push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
};
use ash::vk;
use smallvec::SmallVec;
use std::{ffi::c_void, mem, ptr, sync::Arc};
use std::{ffi::c_void, ptr, sync::Arc};
use vulkano::{
self,
buffer::{Buffer, BufferContents, IndexType},
Expand Down Expand Up @@ -244,7 +244,7 @@ impl RecordingCommandBuffer<'_> {
layout,
offset,
<*const _>::cast(values),
mem::size_of_val(values) as u32,
size_of_val(values) as u32,
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions vulkano-taskgraph/src/command_buffer/commands/clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
Id,
};
use smallvec::SmallVec;
use std::{ffi::c_void, mem};
use std::ffi::c_void;
use vulkano::{
buffer::{Buffer, BufferContents},
device::DeviceOwned,
Expand Down Expand Up @@ -186,7 +186,7 @@ impl RecordingCommandBuffer<'_> {
dst_buffer,
dst_offset,
<*const _>::cast(data),
mem::size_of_val(data) as DeviceSize,
size_of_val(data) as DeviceSize,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
DeviceSize, Requires, RequiresAllOf, RequiresOneOf, ValidationError, VulkanObject,
};
use smallvec::SmallVec;
use std::{mem::size_of, sync::Arc};
use std::sync::Arc;

/// # Commands to do operations on acceleration structures.
impl<L> AutoCommandBufferBuilder<L> {
Expand Down
2 changes: 1 addition & 1 deletion vulkano/src/command_buffer/commands/bind_push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
};
use ash::vk;
use smallvec::SmallVec;
use std::{cmp::min, ffi::c_void, mem::size_of, ptr, sync::Arc};
use std::{cmp::min, ffi::c_void, ptr, sync::Arc};

/// # Commands to bind or push state for pipeline execution commands.
///
Expand Down
2 changes: 1 addition & 1 deletion vulkano/src/command_buffer/commands/clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
};
use ash::vk;
use smallvec::{smallvec, SmallVec};
use std::{mem::size_of_val, sync::Arc};
use std::sync::Arc;

/// # Commands to fill resources with new data.
impl<L> AutoCommandBufferBuilder<L> {
Expand Down
1 change: 0 additions & 1 deletion vulkano/src/command_buffer/commands/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use ash::vk;
use smallvec::{smallvec, SmallVec};
use std::{
cmp::{max, min},
mem::size_of,
sync::Arc,
};

Expand Down
2 changes: 1 addition & 1 deletion vulkano/src/command_buffer/commands/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::{
sync::{PipelineStageAccess, PipelineStageAccessFlags},
DeviceSize, Requires, RequiresAllOf, RequiresOneOf, ValidationError, Version, VulkanObject,
};
use std::{mem::size_of, sync::Arc};
use std::sync::Arc;

macro_rules! vuids {
($vuid_type:ident, $($id:literal),+ $(,)?) => {
Expand Down
4 changes: 2 additions & 2 deletions vulkano/src/command_buffer/commands/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ impl RecordingCommandBuffer {

// VUID-vkCmdCopyQueryPoolResults-flags-00822
// VUID-vkCmdCopyQueryPoolResults-flags-00823
debug_assert!(destination.offset() % std::mem::size_of::<T>() as DeviceSize == 0);
debug_assert!(destination.offset() % size_of::<T>() as DeviceSize == 0);

if queries.end < queries.start {
return Err(Box::new(ValidationError {
Expand Down Expand Up @@ -1031,7 +1031,7 @@ impl RecordingCommandBuffer {
T: QueryResultElement,
{
let per_query_len = query_pool.result_len(flags);
let stride = per_query_len * std::mem::size_of::<T>() as DeviceSize;
let stride = per_query_len * size_of::<T>() as DeviceSize;

let fns = self.device().fns();
unsafe {
Expand Down
10 changes: 5 additions & 5 deletions vulkano/src/memory/alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ use std::{
#[repr(transparent)]
pub struct DeviceAlignment(AlignmentEnum);

const _: () = assert!(mem::size_of::<DeviceAlignment>() == mem::size_of::<DeviceSize>());
const _: () = assert!(mem::align_of::<DeviceAlignment>() == mem::align_of::<DeviceSize>());
const _: () = assert!(size_of::<DeviceAlignment>() == size_of::<DeviceSize>());
const _: () = assert!(align_of::<DeviceAlignment>() == align_of::<DeviceSize>());

const _: () = assert!(mem::size_of::<DeviceSize>() >= mem::size_of::<usize>());
const _: () = assert!(size_of::<DeviceSize>() >= size_of::<usize>());

impl DeviceAlignment {
/// The smallest possible alignment, 1.
Expand All @@ -32,14 +32,14 @@ impl DeviceAlignment {
#[inline]
pub const fn of<T>() -> Self {
// SAFETY: rustc guarantees that the alignment of types is a power of two.
unsafe { DeviceAlignment::new_unchecked(mem::align_of::<T>() as DeviceSize) }
unsafe { DeviceAlignment::new_unchecked(align_of::<T>() as DeviceSize) }
}

/// Returns the alignment for a value.
#[inline]
pub fn of_val<T: ?Sized>(value: &T) -> Self {
// SAFETY: rustc guarantees that the alignment of types is a power of two.
unsafe { DeviceAlignment::new_unchecked(mem::align_of_val(value) as DeviceSize) }
unsafe { DeviceAlignment::new_unchecked(align_of_val(value) as DeviceSize) }
}

/// Tries to create a `DeviceAlignment` from a [`DeviceSize`], returning [`None`] if it's not a
Expand Down
3 changes: 1 addition & 2 deletions vulkano/src/memory/allocator/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::{
error::Error,
fmt::{Debug, Display, Formatter, Result as FmtResult},
hash::Hash,
mem,
num::NonZero,
};

Expand All @@ -18,7 +17,7 @@ pub struct DeviceLayout {
alignment: DeviceAlignment,
}

const _: () = assert!(mem::size_of::<DeviceSize>() >= mem::size_of::<usize>());
const _: () = assert!(size_of::<DeviceSize>() >= size_of::<usize>());
const _: () = assert!(DeviceLayout::MAX_SIZE >= isize::MAX as DeviceSize);

impl DeviceLayout {
Expand Down
12 changes: 3 additions & 9 deletions vulkano/src/pipeline/graphics/vertex_input/collection.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::buffer::Subbuffer;
use std::mem::{self, ManuallyDrop};
use std::mem::ManuallyDrop;

/// A collection of vertex buffers.
pub trait VertexBuffersCollection {
Expand All @@ -23,14 +23,8 @@ impl<T: ?Sized> VertexBuffersCollection for Subbuffer<T> {

impl<T: ?Sized> VertexBuffersCollection for Vec<Subbuffer<T>> {
fn into_vec(self) -> Vec<Subbuffer<[u8]>> {
assert_eq!(
mem::size_of::<Subbuffer<T>>(),
mem::size_of::<Subbuffer<[u8]>>(),
);
assert_eq!(
mem::align_of::<Subbuffer<T>>(),
mem::align_of::<Subbuffer<[u8]>>(),
);
assert_eq!(size_of::<Subbuffer<T>>(), size_of::<Subbuffer<[u8]>>());
assert_eq!(align_of::<Subbuffer<T>>(), align_of::<Subbuffer<[u8]>>());

let mut this = ManuallyDrop::new(self);
let cap = this.capacity();
Expand Down
2 changes: 1 addition & 1 deletion vulkano/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl QueryPool {
T: QueryResultElement,
{
let per_query_len = self.result_len(flags);
let stride = per_query_len * std::mem::size_of::<T>() as DeviceSize;
let stride = per_query_len * size_of::<T>() as DeviceSize;

let fns = self.device.fns();
let result = unsafe {
Expand Down