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

Automatically derive Pod and Zeroable for structs generated by vulkano-shaders #2117

Merged
merged 1 commit into from
Dec 30, 2022
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
5 changes: 0 additions & 5 deletions examples/src/bin/deferred/frame/ambient_lighting_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,5 @@ void main() {
f_color.rgb = push_constants.color.rgb * in_diffuse;
f_color.a = 1.0;
}",
types_meta: {
use bytemuck::{Pod, Zeroable};

#[derive(Clone, Copy, Zeroable, Pod)]
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,5 @@ void main() {
f_color.rgb = light_percent * push_constants.color.rgb * in_diffuse;
f_color.a = 1.0;
}",
types_meta: {
use bytemuck::{Pod, Zeroable};

#[derive(Clone, Copy, Zeroable, Pod)]
},
}
}
5 changes: 0 additions & 5 deletions examples/src/bin/deferred/frame/point_lighting_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,5 @@ void main() {
f_color.rgb = push_constants.color.rgb * light_percent * in_diffuse;
f_color.a = 1.0;
}",
types_meta: {
use bytemuck::{Pod, Zeroable};

#[derive(Clone, Copy, Zeroable, Pod)]
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,5 @@ void main() {
);
imageStore(img, ivec2(gl_GlobalInvocationID.xy), write_color);
}",
types_meta: {
use bytemuck::{Pod, Zeroable};

#[derive(Clone, Copy, Zeroable, Pod)]
},
}
}
5 changes: 0 additions & 5 deletions examples/src/bin/multi_window_game_of_life/game_of_life.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,5 @@ void main() {
compute_color();
}
}",
types_meta: {
use bytemuck::{Pod, Zeroable};

#[derive(Clone, Copy, Zeroable, Pod)]
},
}
}
5 changes: 0 additions & 5 deletions examples/src/bin/push-constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@ fn main() {
}
}
",
types_meta: {
use bytemuck::{Pod, Zeroable};

#[derive(Clone, Copy, Zeroable, Pod)]
},
}
}

Expand Down
5 changes: 0 additions & 5 deletions examples/src/bin/shader-types-sharing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,6 @@ fn main() {
"
}
},
types_meta: {
use bytemuck::{Pod, Zeroable};

#[derive(Clone, Copy, Zeroable, Pod)]
},
}

// The macro will create the following things in this module:
Expand Down
5 changes: 0 additions & 5 deletions examples/src/bin/simple-particles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,6 @@ fn main() {
verticies[index].vel = vel * exp(friction * push.delta_time);
}
",
types_meta: {
use bytemuck::{Pod, Zeroable};

#[derive(Clone, Copy, Zeroable, Pod)]
},
}
}
// Vertex shader determines color and is run once per particle.
Expand Down
5 changes: 0 additions & 5 deletions examples/src/bin/teapot/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,6 @@ mod vs {
vulkano_shaders::shader! {
ty: "vertex",
path: "src/bin/teapot/vert.glsl",
types_meta: {
use bytemuck::{Pod, Zeroable};

#[derive(Clone, Copy, Zeroable, Pod)]
},
}
}

Expand Down
35 changes: 7 additions & 28 deletions vulkano-shaders/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,6 @@ enum SourceKind {

struct TypesMeta {
custom_derives: Vec<SynPath>,
clone: bool,
copy: bool,
display: bool,
debug: bool,
default: bool,
Expand All @@ -422,9 +420,12 @@ impl Default for TypesMeta {
#[inline]
fn default() -> Self {
Self {
custom_derives: vec![],
clone: true,
copy: true,
custom_derives: vec![
parse_quote! { Clone },
parse_quote! { Copy },
parse_quote! { bytemuck::Pod },
parse_quote! { bytemuck::Zeroable },
],
partial_eq: false,
debug: false,
display: false,
Expand All @@ -440,8 +441,6 @@ impl TypesMeta {
fn empty() -> Self {
Self {
custom_derives: Vec::new(),
clone: false,
copy: false,
partial_eq: false,
debug: false,
display: false,
Expand Down Expand Up @@ -780,26 +779,6 @@ impl Parse for MacroInput {
path.get_ident()
{
match derive_ident.to_string().as_str() {
"Clone" => {
if meta.default {
return Err(in_brackets
.error("Duplicate Clone derive"));
}

meta.clone = true;

false
}
"Copy" => {
if meta.copy {
return Err(in_brackets
.error("Duplicate Copy derive"));
}

meta.copy = true;

false
}
"PartialEq" => {
if meta.partial_eq {
return Err(in_brackets
Expand Down Expand Up @@ -850,7 +829,7 @@ impl Parse for MacroInput {
if meta
.custom_derives
.iter()
.any(|candidate| candidate.eq(&path))
.any(|candidate| *candidate == path)
{
return Err(
in_braces.error("Duplicate derive declaration")
Expand Down
8 changes: 0 additions & 8 deletions vulkano-shaders/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,6 @@ fn register_struct(
fn write_derives(types_meta: &TypesMeta) -> TokenStream {
let mut derives = vec![];

if types_meta.clone {
derives.push(quote! { Clone });
}

if types_meta.copy {
derives.push(quote! { Copy });
}

derives.extend(
types_meta
.custom_derives
Expand Down