Add feature to control 16 byte alignment of uniforms.

This commit is contained in:
Robin KAY 2022-08-23 22:16:59 +01:00
parent 2ac918d63a
commit 4fe9443feb
5 changed files with 17 additions and 5 deletions

View File

@ -26,7 +26,8 @@ bevy = { version = "0.8", default-features = false, features = [
] }
[features]
default = ["bevy_ui"]
default = ["align16", "bevy_ui"]
align16 = []
bevy_ui = ["bevy/bevy_ui", "bevy/bevy_sprite", "bevy/bevy_text"]
[[example]]

View File

@ -6,17 +6,23 @@ struct VertexInput {
};
struct OutlineViewUniform {
#ifdef ALIGN_16
@align(16)
#endif
scale: vec2<f32>,
};
struct OutlineVertexUniform {
#ifdef ALIGN_16
@align(16)
#endif
width: f32,
};
struct OutlineFragmentUniform {
#ifdef ALIGN_16
@align(16)
#endif
colour: vec4<f32>,
};

View File

@ -146,17 +146,22 @@ impl SpecializedMeshPipeline for OutlinePipeline {
);
}
}
let shader_defs = if cfg!(feature = "align16") {
vec!["ALIGN_16".to_string()]
} else {
vec![]
};
let buffers = vec![mesh_layout.get_layout(&buffer_attrs)?];
Ok(RenderPipelineDescriptor {
vertex: VertexState {
shader: shader.clone().typed::<Shader>(),
entry_point: "vertex".into(),
shader_defs: vec![],
shader_defs: shader_defs.clone(),
buffers,
},
fragment: Some(FragmentState {
shader: shader.typed::<Shader>(),
shader_defs: vec![],
shader_defs,
entry_point: "fragment".into(),
targets,
}),

View File

@ -17,7 +17,7 @@ use crate::{pipeline::OutlinePipeline, Outline};
#[derive(Clone, Component, ShaderType)]
pub struct OutlineVertexUniform {
#[align(16)]
#[cfg_attr(feature = "align16", align(16))]
pub width: f32,
}

View File

@ -15,7 +15,7 @@ use crate::pipeline::OutlinePipeline;
#[derive(Clone, Component, ShaderType)]
pub struct OutlineViewUniform {
#[align(16)]
#[cfg_attr(feature = "align16", align(16))]
scale: Vec2,
}