Skip to content

Commit

Permalink
Automatically derive Pod and Zeroable for structs generated by vu…
Browse files Browse the repository at this point in the history
…lkano-shaders (#2117)
  • Loading branch information
Rua authored Dec 30, 2022
1 parent daa139d commit 41a3773
Show file tree
Hide file tree
Showing 11 changed files with 7 additions and 81 deletions.
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 @@ -210,10 +210,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 @@ -235,10 +235,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 @@ -267,10 +267,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 @@ -262,11 +262,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 @@ -419,8 +419,6 @@ enum SourceKind {

struct TypesMeta {
custom_derives: Vec<SynPath>,
clone: bool,
copy: bool,
display: bool,
debug: bool,
default: bool,
Expand All @@ -433,9 +431,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 @@ -451,8 +452,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 @@ -791,26 +790,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 @@ -861,7 +840,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

0 comments on commit 41a3773

Please sign in to comment.