Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 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
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ ron = "0.7.0"
serde = { version = "1", features = ["derive"] }
# Needed to poll Task examples
futures-lite = "1.11.3"
crevice = { path = "crates/crevice", version = "0.8.0", features = ["glam"] }

[[example]]
name = "hello_world"
Expand Down
8 changes: 4 additions & 4 deletions crates/crevice/Cargo.toml → crates/bevy_crevice/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "crevice"
description = "Create GLSL-compatible versions of structs with explicitly-initialized padding"
version = "0.8.0"
name = "bevy_crevice"
description = "Create GLSL-compatible versions of structs with explicitly-initialized padding (Bevy version)"
version = "0.5.0"
edition = "2021"
authors = ["Lucien Greathouse <[email protected]>"]
documentation = "https://docs.rs/crevice"
Expand All @@ -23,7 +23,7 @@ std = []
# default-members = ["crevice-derive", "crevice-tests"]

[dependencies]
crevice-derive = { version = "0.8.0", path = "crevice-derive" }
bevy-crevice-derive = { version = "0.5.0", path = "bevy-crevice-derive" }

bytemuck = "1.4.1"
mint = "0.5.8"
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions crates/crevice/README.md → crates/bevy_crevice/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ uniform MAIN {
```

```rust
use crevice::std140::{AsStd140, Std140};
use bevy_crevice::std140::{AsStd140, Std140};

#[derive(AsStd140)]
struct MainUniform {
Expand Down Expand Up @@ -93,7 +93,7 @@ buffer POINT_LIGHTS {
```

```rust
use crevice::std140::{self, AsStd140};
use bevy_crevice::std140::{self, AsStd140};

#[derive(AsStd140)]
struct PointLight {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "crevice-derive"
description = "Derive crate for the 'crevice' crate"
version = "0.8.0"
name = "bevy-crevice-derive"
description = "Derive crate for the 'crevice' crate (Bevy version)"
version = "0.5.0"
edition = "2018"
authors = ["Lucien Greathouse <[email protected]>"]
documentation = "https://docs.rs/crevice-derive"
Expand All @@ -24,3 +24,4 @@ proc-macro = true
syn = "1.0.40"
quote = "1.0.7"
proc-macro2 = "1.0.21"
bevy_macro_utils = { path = "../../bevy_macro_utils", version = "0.5.0" }
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
use bevy_macro_utils::BevyManifest;
use proc_macro2::{Literal, TokenStream};
use quote::quote;
use syn::{parse_quote, Data, DeriveInput, Fields, Path};

pub fn emit(input: DeriveInput) -> TokenStream {
let bevy_prefix_path = BevyManifest::default()
.maybe_get_path(crate::BEVY_RENDER)
.unwrap_or_else(|| Path {
leading_colon: None,
segments: Default::default(),
});

let fields = match &input.data {
Data::Struct(data) => match &data.fields {
Fields::Named(fields) => fields,
Expand All @@ -12,8 +20,8 @@ pub fn emit(input: DeriveInput) -> TokenStream {
Data::Enum(_) | Data::Union(_) => panic!("Only structs are supported"),
};

let base_trait_path: Path = parse_quote!(::crevice::glsl::Glsl);
let struct_trait_path: Path = parse_quote!(::crevice::glsl::GlslStruct);
let base_trait_path: Path = parse_quote!(#bevy_prefix_path::bevy_crevice::glsl::Glsl);
let struct_trait_path: Path = parse_quote!(#bevy_prefix_path::bevy_crevice::glsl::GlslStruct);

let name = input.ident;
let name_str = Literal::string(&name.to_string());
Expand All @@ -23,14 +31,14 @@ pub fn emit(input: DeriveInput) -> TokenStream {
let glsl_fields = fields.named.iter().map(|field| {
let field_ty = &field.ty;
let field_name_str = Literal::string(&field.ident.as_ref().unwrap().to_string());
let field_as = quote! {<#field_ty as ::crevice::glsl::GlslArray>};
let field_as = quote! {<#field_ty as #bevy_prefix_path::bevy_crevice::glsl::GlslArray>};

quote! {
s.push_str("\t");
s.push_str(#field_as::NAME);
s.push_str(" ");
s.push_str(#field_name_str);
<#field_as::ArraySize as ::crevice::glsl::DimensionList>::push_to_string(s);
<#field_as::ArraySize as #bevy_prefix_path::bevy_crevice::glsl::DimensionList>::push_to_string(s);
s.push_str(";\n");
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bevy_macro_utils::BevyManifest;
use proc_macro2::{Span, TokenStream};
use quote::{format_ident, quote};
use syn::{parse_quote, Data, DeriveInput, Fields, Ident, Path, Type};
Expand All @@ -8,10 +9,17 @@ pub fn emit(
mod_name: &'static str,
min_struct_alignment: usize,
) -> TokenStream {
let bevy_prefix_path = BevyManifest::default()
.maybe_get_path(crate::BEVY_RENDER)
.unwrap_or_else(|| Path {
leading_colon: None,
segments: Default::default(),
});

let mod_name = Ident::new(mod_name, Span::call_site());
let trait_name = Ident::new(trait_name, Span::call_site());

let mod_path: Path = parse_quote!(::crevice::#mod_name);
let mod_path: Path = parse_quote!(#bevy_prefix_path::bevy_crevice::#mod_name);
let trait_path: Path = parse_quote!(#mod_path::#trait_name);

let as_trait_name = format_ident!("As{}", trait_name);
Expand Down Expand Up @@ -63,7 +71,7 @@ pub fn emit(

let field_alignments = fields.iter().map(|field| layout_alignment_of_ty(&field.ty));
let struct_alignment = quote! {
::crevice::internal::max_arr([
#bevy_prefix_path::bevy_crevice::internal::max_arr([
#min_struct_alignment,
#(#field_alignments,)*
])
Expand Down Expand Up @@ -139,13 +147,13 @@ pub fn emit(
// We set our target alignment to the larger of the
// alignment due to the previous field and the alignment
// requirement of the next field.
let alignment = ::crevice::internal::max(
let alignment = #bevy_prefix_path::bevy_crevice::internal::max(
#next_field_or_self_alignment,
min_alignment,
);

// Using everything we've got, compute our padding amount.
::crevice::internal::align_offset(starting_offset, alignment)
#bevy_prefix_path::bevy_crevice::internal::align_offset(starting_offset, alignment)
}
}
})
Expand Down Expand Up @@ -222,7 +230,7 @@ pub fn emit(
let size = ::core::mem::size_of::<Self>();
let align = <Self as #trait_path>::ALIGNMENT;

let zeroed: Self = ::crevice::internal::bytemuck::Zeroable::zeroed();
let zeroed: Self = #bevy_prefix_path::bevy_crevice::internal::bytemuck::Zeroable::zeroed();

#[derive(Debug)]
struct Field {
Expand Down Expand Up @@ -253,13 +261,13 @@ pub fn emit(
#pad_fn_impls
#struct_definition

unsafe impl #impl_generics ::crevice::internal::bytemuck::Zeroable for #generated_name #ty_generics #where_clause {}
unsafe impl #impl_generics ::crevice::internal::bytemuck::Pod for #generated_name #ty_generics #where_clause {}
unsafe impl #impl_generics #bevy_prefix_path::bevy_crevice::internal::bytemuck::Zeroable for #generated_name #ty_generics #where_clause {}
unsafe impl #impl_generics #bevy_prefix_path::bevy_crevice::internal::bytemuck::Pod for #generated_name #ty_generics #where_clause {}

unsafe impl #impl_generics #mod_path::#trait_name for #generated_name #ty_generics #where_clause {
const ALIGNMENT: usize = #struct_alignment;
const PAD_AT_END: bool = true;
type Padded = #padded_path<Self, {::crevice::internal::align_offset(
type Padded = #padded_path<Self, {#bevy_prefix_path::bevy_crevice::internal::align_offset(
::core::mem::size_of::<#generated_name>(),
#struct_alignment
)}>;
Expand All @@ -272,7 +280,7 @@ pub fn emit(
Self::Output {
#generated_struct_field_init

..::crevice::internal::bytemuck::Zeroable::zeroed()
..#bevy_prefix_path::bevy_crevice::internal::bytemuck::Zeroable::zeroed()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ pub fn derive_glsl_struct(input: CompilerTokenStream) -> CompilerTokenStream {

CompilerTokenStream::from(expanded)
}

const BEVY_RENDER: &str = "bevy_render";
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ edition = "2018"
wgpu-validation = ["wgpu", "naga", "futures"]

[dependencies]
crevice = { path = ".." }
crevice-derive = { path = "../crevice-derive", features = ["debug-methods"] }
bevy_crevice = { path = ".." }
bevy-crevice-derive = { path = "../bevy-crevice-derive", features = ["debug-methods"] }

anyhow = "1.0.44"
bytemuck = "1.7.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::borrow::Cow;
use std::fmt::Debug;
use std::marker::PhantomData;

use crevice::glsl::{Glsl, GlslStruct};
use crevice::std140::{AsStd140, Std140};
use crevice::std430::{AsStd430, Std430};
use bevy_crevice::glsl::{Glsl, GlslStruct};
use bevy_crevice::std140::{AsStd140, Std140};
use bevy_crevice::std430::{AsStd430, Std430};
use futures::executor::block_on;
use wgpu::util::DeviceExt;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ fn test_round_trip_primitive<T>(_value: T) {}
#[macro_use]
mod util;

use crevice::glsl::GlslStruct;
use crevice::std140::AsStd140;
use crevice::std430::AsStd430;
use bevy_crevice::glsl::GlslStruct;
use bevy_crevice::std140::AsStd140;
use bevy_crevice::std430::AsStd430;
use mint::{ColumnMatrix2, ColumnMatrix3, ColumnMatrix4, Vector2, Vector3, Vector4};

#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Defines traits and types for generating GLSL code from Rust definitions.

pub use crevice_derive::GlslStruct;
pub use bevy_crevice_derive::GlslStruct;
use std::marker::PhantomData;

/// Type-level linked list of array dimensions
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions crates/crevice/src/lib.rs → crates/bevy_crevice/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ uniform MAIN {
```

```rust
use crevice::std140::{AsStd140, Std140};
use bevy_crevice::std140::{AsStd140, Std140};

#[derive(AsStd140)]
struct MainUniform {
Expand Down Expand Up @@ -100,7 +100,7 @@ buffer POINT_LIGHTS {
```

```rust
use crevice::std140::{self, AsStd140};
use bevy_crevice::std140::{self, AsStd140};

#[derive(AsStd140)]
struct PointLight {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ pub use self::traits::*;
#[cfg(feature = "std")]
pub use self::writer::*;

pub use crevice_derive::AsStd140;
pub use bevy_crevice_derive::AsStd140;
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ buffer FROBS {
```

```
use crevice::std140::{self, AsStd140};
use bevy_crevice::std140::{self, AsStd140};

#[derive(AsStd140)]
struct Frob {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ uniform CAMERA {
```

```no_run
use crevice::std140::{AsStd140, Std140};
use bevy_crevice::std140::{AsStd140, Std140};

#[derive(AsStd140)]
struct CameraUniform {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ buffer POINT_LIGHTS {
```

```
use crevice::std140::{self, AsStd140};
use bevy_crevice::std140::{self, AsStd140};

#[derive(AsStd140)]
struct PointLight {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ pub use self::traits::*;
#[cfg(feature = "std")]
pub use self::writer::*;

pub use crevice_derive::AsStd430;
pub use bevy_crevice_derive::AsStd430;
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ buffer FROBS {
```

```
use crevice::std430::{self, AsStd430};
use bevy_crevice::std430::{self, AsStd430};

#[derive(AsStd430)]
struct Frob {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ uniform CAMERA {
```

```no_run
use crevice::std430::{AsStd430, Std430};
use bevy_crevice::std430::{AsStd430, Std430};

#[derive(AsStd430)]
struct CameraUniform {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ buffer POINT_LIGHTS {
```

```
use crevice::std430::{self, AsStd430};
use bevy_crevice::std430::{self, AsStd430};

#[derive(AsStd430)]
struct PointLight {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crevice::glsl::GlslStruct;
use crevice::std140::AsStd140;
use bevy_crevice::glsl::GlslStruct;
use bevy_crevice::std140::AsStd140;

#[test]
fn there_and_back_again() {
Expand Down
6 changes: 4 additions & 2 deletions crates/bevy_macro_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Default for BevyManifest {
}

impl BevyManifest {
pub fn get_path(&self, name: &str) -> syn::Path {
pub fn maybe_get_path(&self, name: &str) -> Option<syn::Path> {
const BEVY: &str = "bevy";
const BEVY_INTERNAL: &str = "bevy_internal";

Expand All @@ -57,7 +57,9 @@ impl BevyManifest {

deps.and_then(find_in_deps)
.or_else(|| deps_dev.and_then(find_in_deps))
.unwrap_or_else(|| get_path(name))
}
pub fn get_path(&self, name: &str) -> syn::Path {
self.maybe_get_path(name).unwrap_or_else(|| get_path(name))
}
}

Expand Down
1 change: 0 additions & 1 deletion crates/bevy_pbr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ bevy_window = { path = "../bevy_window", version = "0.5.0" }
bitflags = "1.2"
# direct dependency required for derive macro
bytemuck = { version = "1", features = ["derive"] }
crevice = { path = "../crevice", version = "0.8.0", features = ["glam"] }
wgpu = { version = "0.12.0", features = ["spirv"] }
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use bevy_ecs::system::{lifetimeless::SRes, SystemParamItem};
use bevy_math::Vec4;
use bevy_reflect::TypeUuid;
use bevy_render::{
bevy_crevice::std140::{AsStd140, Std140},
color::Color,
render_asset::{PrepareAssetError, RenderAsset, RenderAssetPlugin, RenderAssets},
render_resource::{BindGroup, Buffer, BufferInitDescriptor, BufferUsages},
renderer::RenderDevice,
texture::Image,
};
use crevice::std140::{AsStd140, Std140};
use wgpu::{BindGroupDescriptor, BindGroupEntry, BindingResource};

pub const DEFAULT_STANDARD_MATERIAL_HANDLE: HandleUntyped =
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/render/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use bevy_ecs::{
};
use bevy_math::{const_vec3, Mat4, UVec3, UVec4, Vec2, Vec3, Vec4, Vec4Swizzles};
use bevy_render::{
bevy_crevice::std140::AsStd140,
camera::{Camera, CameraProjection},
color::Color,
mesh::Mesh,
Expand All @@ -29,7 +30,6 @@ use bevy_render::{
};
use bevy_transform::components::GlobalTransform;
use bevy_utils::{tracing::warn, HashMap};
use crevice::std140::AsStd140;
use std::num::NonZeroU32;

#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemLabel)]
Expand Down
Loading