Skip to content

Commit

Permalink
rename Size::SIZE to ShaderSize::SHADER_SIZE
Browse files Browse the repository at this point in the history
  • Loading branch information
teoxoy committed Jul 3, 2022
1 parent 59ad0e0 commit 2b3000e
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 43 deletions.
18 changes: 9 additions & 9 deletions derive/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl FieldData {
} else {
let ty = &self.field.ty;
quote! {
<#ty as #root::Size>::SIZE.get()
<#ty as #root::ShaderSize>::SHADER_SIZE.get()
}
}
}
Expand All @@ -89,7 +89,7 @@ impl FieldData {
self.size.as_ref().map(|(size, _)| {
let size = Literal::u64_suffixed(*size as u64);
let ty = &self.field.ty;
let original_size = quote! { <#ty as #root::Size>::SIZE.get() };
let original_size = quote! { <#ty as #root::ShaderSize>::SHADER_SIZE.get() };
quote!(#size.saturating_sub(#original_size))
})
}
Expand Down Expand Up @@ -271,9 +271,9 @@ pub fn derive_shader_type(input: DeriveInput, root: &Path) -> TokenStream {
if is_runtime_sized {
quote!(#root::ShaderType + #root::RuntimeSizedArray)
} else {
quote!(#root::ShaderType + #root::Size)
quote!(#root::ShaderType + #root::ShaderSize)
},
quote!(#root::ShaderType + #root::Size),
quote!(#root::ShaderType + #root::ShaderSize),
);

let mut lifetimes = input.generics.clone();
Expand Down Expand Up @@ -319,7 +319,7 @@ pub fn derive_shader_type(input: DeriveInput, root: &Path) -> TokenStream {
#[track_caller]
#[allow(clippy::extra_unused_lifetimes)]
const fn check #impl_generics () {
let size = <#ty as #root::Size>::SIZE.get();
let size = <#ty as #root::ShaderSize>::SHADER_SIZE.get();
#root::concat_assert!(
size <= #size,
"size attribute value must be at least ", size, " (field's type size)"
Expand Down Expand Up @@ -363,7 +363,7 @@ pub fn derive_shader_type(input: DeriveInput, root: &Path) -> TokenStream {
let offset = <Self as #root::ShaderType>::METADATA.offset(#i);
let diff = offset - prev_offset;

let prev_size = <#prev_field_ty as #root::Size>::SIZE.get();
let prev_size = <#prev_field_ty as #root::ShaderSize>::SHADER_SIZE.get();
let prev_size = min_alignment.round_up(prev_size);

#root::concat_assert!(
Expand Down Expand Up @@ -542,9 +542,9 @@ pub fn derive_shader_type(input: DeriveInput, root: &Path) -> TokenStream {
}
},
false => quote! {
impl #impl_generics #root::Size for #name #ty_generics
impl #impl_generics #root::ShaderSize for #name #ty_generics
where
#( #field_types: #root::Size, )*
#( #field_types: #root::ShaderSize, )*
{}
},
};
Expand All @@ -558,7 +558,7 @@ pub fn derive_shader_type(input: DeriveInput, root: &Path) -> TokenStream {

impl #impl_generics #root::ShaderType for #name #ty_generics #where_clause
where
#( #all_other: #root::ShaderType + #root::Size, )*
#( #all_other: #root::ShaderType + #root::ShaderSize, )*
#last_field_type: #root::ShaderType,
{
type ExtraMetadata = #root::StructMetadata<#nr_of_fields>;
Expand Down
8 changes: 4 additions & 4 deletions src/core/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub trait ShaderType {
///
/// For [WGSL fixed-footprint types](https://gpuweb.github.io/gpuweb/wgsl/#fixed-footprint-types)
/// it represents [WGSL Size](https://gpuweb.github.io/gpuweb/wgsl/#alignment-and-size)
/// (equivalent to [`Size::SIZE`])
/// (equivalent to [`ShaderSize::SHADER_SIZE`])
///
/// For
/// [WGSL runtime-sized arrays](https://gpuweb.github.io/gpuweb/wgsl/#runtime-sized) and
Expand All @@ -73,7 +73,7 @@ pub trait ShaderType {
/// Returns the size of `Self` at runtime
///
/// For [WGSL fixed-footprint types](https://gpuweb.github.io/gpuweb/wgsl/#fixed-footprint-types)
/// it's equivalent to [`Self::min_size`] and [`Size::SIZE`]
/// it's equivalent to [`Self::min_size`] and [`ShaderSize::SHADER_SIZE`]
fn size(&self) -> NonZeroU64 {
Self::METADATA.min_size().0
}
Expand Down Expand Up @@ -202,9 +202,9 @@ pub trait ShaderType {
}

/// Trait implemented for all [WGSL fixed-footprint types](https://gpuweb.github.io/gpuweb/wgsl/#fixed-footprint-types)
pub trait Size: ShaderType {
pub trait ShaderSize: ShaderType {
/// Represents [WGSL Size](https://gpuweb.github.io/gpuweb/wgsl/#alignment-and-size) (equivalent to [`ShaderType::min_size`])
const SIZE: NonZeroU64 = Self::METADATA.min_size().0;
const SHADER_SIZE: NonZeroU64 = Self::METADATA.min_size().0;
}

/// Trait implemented for
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@
/// Complex
///
/// ```
/// # use crate::encase::ShaderType;
/// # use crate::encase::{ShaderType, ShaderSize};
/// #[derive(ShaderType)]
/// struct Complex<
/// 'a,
/// 'b: 'a,
/// E: 'a + ShaderType + encase::Size,
/// T: 'b + ShaderType + encase::Size,
/// E: 'a + ShaderType + ShaderSize,
/// T: 'b + ShaderType + ShaderSize,
/// const N: usize,
/// > {
/// array: [&'a mut E; N],
Expand All @@ -103,8 +103,8 @@ mod types;
mod impls;

pub use crate::core::{
CalculateSizeFor, DynamicStorageBuffer, DynamicUniformBuffer, ShaderType, Size, StorageBuffer,
UniformBuffer,
CalculateSizeFor, DynamicStorageBuffer, DynamicUniformBuffer, ShaderSize, ShaderType,
StorageBuffer, UniformBuffer,
};
pub use types::runtime_sized_array::ArrayLength;

Expand Down Expand Up @@ -163,7 +163,7 @@ pub mod private {
pub use super::utils::consume_zsts;
pub use super::utils::ArrayExt;
pub use super::CalculateSizeFor;
pub use super::ShaderSize;
pub use super::ShaderType;
pub use super::Size;
pub use const_panic::concat_assert;
}
10 changes: 5 additions & 5 deletions src/types/array.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::core::{
BufferMut, BufferRef, CreateFrom, Metadata, ReadFrom, Reader, ShaderType, Size, SizeValue,
WriteInto, Writer,
BufferMut, BufferRef, CreateFrom, Metadata, ReadFrom, Reader, ShaderSize, ShaderType,
SizeValue, WriteInto, Writer,
};

pub struct ArrayMetadata {
Expand All @@ -18,11 +18,11 @@ impl Metadata<ArrayMetadata> {
}
}

impl<T: ShaderType + Size, const N: usize> ShaderType for [T; N] {
impl<T: ShaderType + ShaderSize, const N: usize> ShaderType for [T; N] {
type ExtraMetadata = ArrayMetadata;
const METADATA: Metadata<Self::ExtraMetadata> = {
let alignment = T::METADATA.alignment();
let el_size = SizeValue::from(T::SIZE);
let el_size = SizeValue::from(T::SHADER_SIZE);

let stride = alignment.round_up_size(el_size);
let el_padding = alignment.padding_needed_for(el_size.get());
Expand Down Expand Up @@ -57,7 +57,7 @@ impl<T: ShaderType + Size, const N: usize> ShaderType for [T; N] {
};
}

impl<T: Size, const N: usize> Size for [T; N] {}
impl<T: ShaderSize, const N: usize> ShaderSize for [T; N] {}

impl<T: WriteInto, const N: usize> WriteInto for [T; N]
where
Expand Down
8 changes: 4 additions & 4 deletions src/types/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ macro_rules! impl_matrix_inner {

impl<$($generics)*> $crate::private::ShaderType for $type
where
$el_ty: $crate::private::Size,
$el_ty: $crate::private::ShaderSize,
{
type ExtraMetadata = $crate::private::MatrixMetadata;
const METADATA: $crate::private::Metadata<Self::ExtraMetadata> = {
let col_size = $crate::private::SizeValue::from(<$el_ty as $crate::private::Size>::SIZE).mul($r);
let col_size = $crate::private::SizeValue::from(<$el_ty as $crate::private::ShaderSize>::SHADER_SIZE).mul($r);
let alignment = $crate::private::AlignmentValue::from_next_power_of_two_size(col_size);
let size = alignment.round_up_size(col_size).mul($c);
let col_padding = alignment.padding_needed_for(col_size.get());
Expand All @@ -145,9 +145,9 @@ macro_rules! impl_matrix_inner {
};
}

impl<$($generics)*> $crate::private::Size for $type
impl<$($generics)*> $crate::private::ShaderSize for $type
where
$el_ty: $crate::private::Size
$el_ty: $crate::private::ShaderSize
{}

impl<$($generics)*> $crate::private::WriteInto for $type
Expand Down
8 changes: 4 additions & 4 deletions src/types/runtime_sized_array.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::{LinkedList, VecDeque};

use crate::core::{
BufferMut, BufferRef, CreateFrom, Metadata, ReadFrom, Reader, RuntimeSizedArray, Size,
BufferMut, BufferRef, CreateFrom, Metadata, ReadFrom, Reader, RuntimeSizedArray, ShaderSize,
WriteInto, Writer,
};
use crate::ShaderType;
Expand Down Expand Up @@ -36,7 +36,7 @@ impl ShaderType for ArrayLength {
const METADATA: Metadata<Self::ExtraMetadata> = Metadata::from_alignment_and_size(4, 4);
}

impl Size for ArrayLength {}
impl ShaderSize for ArrayLength {}

impl WriteInto for ArrayLength {
fn write_into<B: BufferMut>(&self, writer: &mut Writer<B>) {
Expand Down Expand Up @@ -122,13 +122,13 @@ macro_rules! impl_rts_array_inner {
(__main, $type:ty, $($generics:tt)*) => {
impl<$($generics)*> $crate::private::ShaderType for $type
where
T: $crate::private::ShaderType + $crate::private::Size,
T: $crate::private::ShaderType + $crate::private::ShaderSize,
Self: $crate::private::Length,
{
type ExtraMetadata = $crate::private::ArrayMetadata;
const METADATA: $crate::private::Metadata<Self::ExtraMetadata> = {
let alignment = T::METADATA.alignment();
let el_size = $crate::private::SizeValue::from(T::SIZE);
let el_size = $crate::private::SizeValue::from(T::SHADER_SIZE);

let stride = alignment.round_up_size(el_size);
let el_padding = alignment.padding_needed_for(el_size.get());
Expand Down
6 changes: 3 additions & 3 deletions src/types/scalar.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::core::{
BufferMut, BufferRef, CreateFrom, Metadata, ReadFrom, Reader, ShaderType, Size, WriteInto,
Writer,
BufferMut, BufferRef, CreateFrom, Metadata, ReadFrom, Reader, ShaderSize, ShaderType,
WriteInto, Writer,
};
use core::num::{NonZeroI32, NonZeroU32, Wrapping};
use core::sync::atomic::{AtomicI32, AtomicU32};
Expand All @@ -12,7 +12,7 @@ macro_rules! impl_basic_traits {
const METADATA: Metadata<Self::ExtraMetadata> = Metadata::from_alignment_and_size(4, 4);
}

impl Size for $type {}
impl ShaderSize for $type {}
};
}

Expand Down
8 changes: 4 additions & 4 deletions src/types/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ macro_rules! impl_vector_inner {

impl<$($generics)*> $crate::private::ShaderType for $type
where
$el_ty: $crate::private::Size,
$el_ty: $crate::private::ShaderSize,
{
type ExtraMetadata = ();
const METADATA: $crate::private::Metadata<Self::ExtraMetadata> = {
let size = $crate::private::SizeValue::from(<$el_ty as $crate::private::Size>::SIZE).mul($n);
let size = $crate::private::SizeValue::from(<$el_ty as $crate::private::ShaderSize>::SHADER_SIZE).mul($n);
let alignment = $crate::private::AlignmentValue::from_next_power_of_two_size(size);

$crate::private::Metadata {
Expand All @@ -125,9 +125,9 @@ macro_rules! impl_vector_inner {
};
}

impl<$($generics)*> $crate::private::Size for $type
impl<$($generics)*> $crate::private::ShaderSize for $type
where
$el_ty: $crate::private::Size
$el_ty: $crate::private::ShaderSize
{}

impl<$($generics)*> $crate::private::WriteInto for $type
Expand Down
6 changes: 3 additions & 3 deletions src/types/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ macro_rules! impl_wrapper_inner {
<T as $crate::private::ShaderType>::size(&self$($get_ref)*)
}
}
impl<$($generics)*> $crate::private::Size for $type
impl<$($generics)*> $crate::private::ShaderSize for $type
where
T: $crate::private::Size
T: $crate::private::ShaderSize
{
const SIZE: ::core::num::NonZeroU64 = T::SIZE;
const SHADER_SIZE: ::core::num::NonZeroU64 = T::SHADER_SIZE;
}

impl<$($generics)*> $crate::private::RuntimeSizedArray for $type
Expand Down
2 changes: 1 addition & 1 deletion tests/hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ struct Test {
#[derive(::encase::ShaderType)]
struct TestGeneric<
'a,
T: 'a + ::encase::ShaderType + ::encase::Size,
T: 'a + ::encase::ShaderType + ::encase::ShaderSize,
const N: ::core::primitive::usize,
> {
#[size(90)]
Expand Down

0 comments on commit 2b3000e

Please sign in to comment.