Skip to content

Commit

Permalink
Error naming consistency (#2370)
Browse files Browse the repository at this point in the history
  • Loading branch information
marc0246 authored Oct 24, 2023
1 parent 755dcbc commit 9526e77
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions vulkano/src/buffer/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! Efficiently suballocates buffers into smaller subbuffers.
use super::{
sys::BufferCreateInfo, Buffer, BufferAllocateError, BufferContents, BufferMemory, BufferUsage,
sys::BufferCreateInfo, AllocateBufferError, Buffer, BufferContents, BufferMemory, BufferUsage,
Subbuffer,
};
use crate::{
Expand Down Expand Up @@ -370,7 +370,7 @@ where
DeviceLayout::from_size_alignment(self.arena_size, 1).unwrap(),
)
.map_err(|err| match err {
Validated::Error(BufferAllocateError::AllocateMemory(err)) => err,
Validated::Error(AllocateBufferError::AllocateMemory(err)) => err,
// We don't use sparse-binding, concurrent sharing or external memory, therefore the
// other errors can't happen.
_ => unreachable!("{err:?}"),
Expand Down
28 changes: 14 additions & 14 deletions vulkano/src/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl Buffer {
create_info: BufferCreateInfo,
allocation_info: AllocationCreateInfo,
data: T,
) -> Result<Subbuffer<T>, Validated<BufferAllocateError>>
) -> Result<Subbuffer<T>, Validated<AllocateBufferError>>
where
T: BufferContents,
{
Expand Down Expand Up @@ -275,7 +275,7 @@ impl Buffer {
create_info: BufferCreateInfo,
allocation_info: AllocationCreateInfo,
iter: I,
) -> Result<Subbuffer<[T]>, Validated<BufferAllocateError>>
) -> Result<Subbuffer<[T]>, Validated<AllocateBufferError>>
where
T: BufferContents,
I: IntoIterator<Item = T>,
Expand Down Expand Up @@ -310,7 +310,7 @@ impl Buffer {
allocator: Arc<dyn MemoryAllocator>,
create_info: BufferCreateInfo,
allocation_info: AllocationCreateInfo,
) -> Result<Subbuffer<T>, Validated<BufferAllocateError>>
) -> Result<Subbuffer<T>, Validated<AllocateBufferError>>
where
T: BufferContents,
{
Expand All @@ -337,7 +337,7 @@ impl Buffer {
create_info: BufferCreateInfo,
allocation_info: AllocationCreateInfo,
len: DeviceSize,
) -> Result<Subbuffer<[T]>, Validated<BufferAllocateError>>
) -> Result<Subbuffer<[T]>, Validated<AllocateBufferError>>
where
T: BufferContents,
{
Expand All @@ -356,7 +356,7 @@ impl Buffer {
create_info: BufferCreateInfo,
allocation_info: AllocationCreateInfo,
len: DeviceSize,
) -> Result<Subbuffer<T>, Validated<BufferAllocateError>>
) -> Result<Subbuffer<T>, Validated<AllocateBufferError>>
where
T: BufferContents + ?Sized,
{
Expand All @@ -383,7 +383,7 @@ impl Buffer {
mut create_info: BufferCreateInfo,
allocation_info: AllocationCreateInfo,
layout: DeviceLayout,
) -> Result<Arc<Self>, Validated<BufferAllocateError>> {
) -> Result<Arc<Self>, Validated<AllocateBufferError>> {
assert!(layout.alignment().as_devicesize() <= 64);
// TODO: Enable once sparse binding materializes
// assert!(!allocate_info.flags.contains(BufferCreateFlags::SPARSE_BINDING));
Expand All @@ -398,7 +398,7 @@ impl Buffer {

let raw_buffer =
RawBuffer::new(allocator.device().clone(), create_info).map_err(|err| match err {
Validated::Error(err) => Validated::Error(BufferAllocateError::CreateBuffer(err)),
Validated::Error(err) => Validated::Error(AllocateBufferError::CreateBuffer(err)),
Validated::ValidationError(err) => err.into(),
})?;
let mut requirements = *raw_buffer.memory_requirements();
Expand All @@ -411,11 +411,11 @@ impl Buffer {
allocation_info,
Some(DedicatedAllocation::Buffer(&raw_buffer)),
)
.map_err(BufferAllocateError::AllocateMemory)?;
.map_err(AllocateBufferError::AllocateMemory)?;
let allocation = unsafe { ResourceMemory::from_allocation(allocator, allocation) };

let buffer = raw_buffer.bind_memory(allocation).map_err(|(err, _, _)| {
err.map(BufferAllocateError::BindMemory)
err.map(AllocateBufferError::BindMemory)
.map_validation(|err| err.add_context("RawBuffer::bind_memory"))
})?;

Expand Down Expand Up @@ -569,13 +569,13 @@ impl Hash for Buffer {

/// Error that can happen when allocating a new buffer.
#[derive(Clone, Debug)]
pub enum BufferAllocateError {
pub enum AllocateBufferError {
CreateBuffer(VulkanError),
AllocateMemory(MemoryAllocatorError),
BindMemory(VulkanError),
}

impl Error for BufferAllocateError {
impl Error for AllocateBufferError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::CreateBuffer(err) => Some(err),
Expand All @@ -585,7 +585,7 @@ impl Error for BufferAllocateError {
}
}

impl Display for BufferAllocateError {
impl Display for AllocateBufferError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::CreateBuffer(_) => write!(f, "creating the buffer failed"),
Expand All @@ -595,8 +595,8 @@ impl Display for BufferAllocateError {
}
}

impl From<BufferAllocateError> for Validated<BufferAllocateError> {
fn from(err: BufferAllocateError) -> Self {
impl From<AllocateBufferError> for Validated<AllocateBufferError> {
fn from(err: AllocateBufferError) -> Self {
Self::Error(err)
}
}
Expand Down
18 changes: 9 additions & 9 deletions vulkano/src/image/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ impl Image {
allocator: Arc<dyn MemoryAllocator>,
create_info: ImageCreateInfo,
allocation_info: AllocationCreateInfo,
) -> Result<Arc<Self>, Validated<ImageAllocateError>> {
) -> Result<Arc<Self>, Validated<AllocateImageError>> {
// TODO: adjust the code below to make this safe
assert!(!create_info.flags.intersects(ImageCreateFlags::DISJOINT));

let allocation_type = create_info.tiling.into();
let raw_image =
RawImage::new(allocator.device().clone(), create_info).map_err(|err| match err {
Validated::Error(err) => Validated::Error(ImageAllocateError::CreateImage(err)),
Validated::Error(err) => Validated::Error(AllocateImageError::CreateImage(err)),
Validated::ValidationError(err) => err.into(),
})?;
let requirements = raw_image.memory_requirements()[0];
Expand All @@ -167,11 +167,11 @@ impl Image {
allocation_info,
Some(DedicatedAllocation::Image(&raw_image)),
)
.map_err(ImageAllocateError::AllocateMemory)?;
.map_err(AllocateImageError::AllocateMemory)?;
let allocation = unsafe { ResourceMemory::from_allocation(allocator, allocation) };

let image = raw_image.bind_memory([allocation]).map_err(|(err, _, _)| {
err.map(ImageAllocateError::BindMemory)
err.map(AllocateImageError::BindMemory)
.map_validation(|err| err.add_context("RawImage::bind_memory"))
})?;

Expand Down Expand Up @@ -572,13 +572,13 @@ impl Hash for Image {

/// Error that can happen when allocating a new image.
#[derive(Clone, Debug)]
pub enum ImageAllocateError {
pub enum AllocateImageError {
CreateImage(VulkanError),
AllocateMemory(MemoryAllocatorError),
BindMemory(VulkanError),
}

impl Error for ImageAllocateError {
impl Error for AllocateImageError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::CreateImage(err) => Some(err),
Expand All @@ -588,7 +588,7 @@ impl Error for ImageAllocateError {
}
}

impl Display for ImageAllocateError {
impl Display for AllocateImageError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::CreateImage(_) => write!(f, "creating the image failed"),
Expand All @@ -598,8 +598,8 @@ impl Display for ImageAllocateError {
}
}

impl From<ImageAllocateError> for Validated<ImageAllocateError> {
fn from(err: ImageAllocateError) -> Self {
impl From<AllocateImageError> for Validated<AllocateImageError> {
fn from(err: AllocateImageError) -> Self {
Self::Error(err)
}
}
Expand Down

0 comments on commit 9526e77

Please # to comment.