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

[Merged by Bors] - Shader defs can now have a value #5900

Closed
wants to merge 15 commits into from
Prev Previous commit
Next Next commit
convert from &str rather than String
  • Loading branch information
mockersf committed Nov 18, 2022
commit 0d55ab70be2b06afeaf1e11df284366861761ab5
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/pbr_material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ impl Material for StandardMaterial {
.as_mut()
.unwrap()
.shader_defs
.push(String::from("STANDARDMATERIAL_NORMAL_MAP").into());
.push("STANDARDMATERIAL_NORMAL_MAP".into());
}
descriptor.primitive.cull_mode = key.bind_group_data.cull_mode;
if let Some(label) = &mut descriptor.label {
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 @@ -329,7 +329,7 @@ impl SpecializedMeshPipeline for ShadowPipeline {
if layout.contains(Mesh::ATTRIBUTE_JOINT_INDEX)
&& layout.contains(Mesh::ATTRIBUTE_JOINT_WEIGHT)
{
shader_defs.push(String::from("SKINNED").into());
shader_defs.push("SKINNED".into());
vertex_attributes.push(Mesh::ATTRIBUTE_JOINT_INDEX.at_shader_location(4));
vertex_attributes.push(Mesh::ATTRIBUTE_JOINT_WEIGHT.at_shader_location(5));
bind_group_layout.push(self.skinned_mesh_layout.clone());
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_pbr/src/render/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,12 +581,12 @@ impl SpecializedMeshPipeline for MeshPipeline {
let mut vertex_attributes = Vec::new();

if layout.contains(Mesh::ATTRIBUTE_POSITION) {
shader_defs.push(String::from("VERTEX_POSITIONS").into());
shader_defs.push("VERTEX_POSITIONS".into());
vertex_attributes.push(Mesh::ATTRIBUTE_POSITION.at_shader_location(0));
}

if layout.contains(Mesh::ATTRIBUTE_NORMAL) {
shader_defs.push(String::from("VERTEX_NORMALS").into());
shader_defs.push("VERTEX_NORMALS".into());
vertex_attributes.push(Mesh::ATTRIBUTE_NORMAL.at_shader_location(1));
}

Expand All @@ -596,25 +596,25 @@ impl SpecializedMeshPipeline for MeshPipeline {
));

if layout.contains(Mesh::ATTRIBUTE_UV_0) {
shader_defs.push(String::from("VERTEX_UVS").into());
shader_defs.push("VERTEX_UVS".into());
vertex_attributes.push(Mesh::ATTRIBUTE_UV_0.at_shader_location(2));
}

if layout.contains(Mesh::ATTRIBUTE_TANGENT) {
shader_defs.push(String::from("VERTEX_TANGENTS").into());
shader_defs.push("VERTEX_TANGENTS".into());
vertex_attributes.push(Mesh::ATTRIBUTE_TANGENT.at_shader_location(3));
}

if layout.contains(Mesh::ATTRIBUTE_COLOR) {
shader_defs.push(String::from("VERTEX_COLORS").into());
shader_defs.push("VERTEX_COLORS".into());
vertex_attributes.push(Mesh::ATTRIBUTE_COLOR.at_shader_location(4));
}

let mut bind_group_layout = vec![self.view_layout.clone()];
if layout.contains(Mesh::ATTRIBUTE_JOINT_INDEX)
&& layout.contains(Mesh::ATTRIBUTE_JOINT_WEIGHT)
{
shader_defs.push(String::from("SKINNED").into());
shader_defs.push("SKINNED".into());
vertex_attributes.push(Mesh::ATTRIBUTE_JOINT_INDEX.at_shader_location(5));
vertex_attributes.push(Mesh::ATTRIBUTE_JOINT_WEIGHT.at_shader_location(6));
bind_group_layout.push(self.skinned_mesh_layout.clone());
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_render/src/render_resource/pipeline_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ pub enum ShaderDefVal {
Int(String, i32),
}

impl From<String> for ShaderDefVal {
fn from(key: String) -> Self {
ShaderDefVal::Bool(key, true)
impl From<&str> for ShaderDefVal {
fn from(key: &str) -> Self {
ShaderDefVal::Bool(key.to_string(), true)
}
}

Expand Down
19 changes: 8 additions & 11 deletions crates/bevy_render/src/render_resource/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ fn vertex(
let result = processor
.process(
&Shader::from_wgsl(WGSL),
&["TEXTURE".to_string().into()],
&["TEXTURE".into()],
&HashMap::default(),
&HashMap::default(),
)
Expand Down Expand Up @@ -1049,7 +1049,7 @@ fn vertex(
let result = processor
.process(
&Shader::from_wgsl(WGSL_NESTED_IFDEF),
&["TEXTURE".to_string().into()],
&["TEXTURE".into()],
&HashMap::default(),
&HashMap::default(),
)
Expand Down Expand Up @@ -1091,7 +1091,7 @@ fn vertex(
let result = processor
.process(
&Shader::from_wgsl(WGSL_NESTED_IFDEF_ELSE),
&["TEXTURE".to_string().into()],
&["TEXTURE".into()],
&HashMap::default(),
&HashMap::default(),
)
Expand Down Expand Up @@ -1211,7 +1211,7 @@ fn vertex(
let result = processor
.process(
&Shader::from_wgsl(WGSL_NESTED_IFDEF),
&["ATTRIBUTE".to_string().into()],
&["ATTRIBUTE".into()],
&HashMap::default(),
&HashMap::default(),
)
Expand Down Expand Up @@ -1253,7 +1253,7 @@ fn vertex(
let result = processor
.process(
&Shader::from_wgsl(WGSL_NESTED_IFDEF),
&["TEXTURE".to_string().into(), "ATTRIBUTE".to_string().into()],
&["TEXTURE".into(), "ATTRIBUTE".into()],
&HashMap::default(),
&HashMap::default(),
)
Expand Down Expand Up @@ -1300,10 +1300,7 @@ fn in_main_present() { }
let result = processor
.process(
&Shader::from_wgsl(INPUT),
&[
"MAIN_PRESENT".to_string().into(),
"IMPORT_PRESENT".to_string().into(),
],
&["MAIN_PRESENT".into(), "IMPORT_PRESENT".into()],
&shaders,
&import_handles,
)
Expand Down Expand Up @@ -1358,7 +1355,7 @@ fn in_main() { }
let result = processor
.process(
&Shader::from_wgsl(INPUT),
&["DEEP".to_string().into()],
&["DEEP".into()],
&shaders,
&import_handles,
)
Expand Down Expand Up @@ -1416,7 +1413,7 @@ fn baz() { }
let result = processor
.process(
&Shader::from_wgsl(INPUT),
&["FOO".to_string().into()],
&["FOO".into()],
&shaders,
&import_handles,
)
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_sprite/src/mesh2d/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,27 +351,27 @@ impl SpecializedMeshPipeline for Mesh2dPipeline {
let mut vertex_attributes = Vec::new();

if layout.contains(Mesh::ATTRIBUTE_POSITION) {
shader_defs.push(String::from("VERTEX_POSITIONS").into());
shader_defs.push("VERTEX_POSITIONS".into());
vertex_attributes.push(Mesh::ATTRIBUTE_POSITION.at_shader_location(0));
}

if layout.contains(Mesh::ATTRIBUTE_NORMAL) {
shader_defs.push(String::from("VERTEX_NORMALS").into());
shader_defs.push("VERTEX_NORMALS".into());
vertex_attributes.push(Mesh::ATTRIBUTE_NORMAL.at_shader_location(1));
}

if layout.contains(Mesh::ATTRIBUTE_UV_0) {
shader_defs.push(String::from("VERTEX_UVS").into());
shader_defs.push("VERTEX_UVS".into());
vertex_attributes.push(Mesh::ATTRIBUTE_UV_0.at_shader_location(2));
}

if layout.contains(Mesh::ATTRIBUTE_TANGENT) {
shader_defs.push(String::from("VERTEX_TANGENTS").into());
shader_defs.push("VERTEX_TANGENTS".into());
vertex_attributes.push(Mesh::ATTRIBUTE_TANGENT.at_shader_location(3));
}

if layout.contains(Mesh::ATTRIBUTE_COLOR) {
shader_defs.push(String::from("VERTEX_COLORS").into());
shader_defs.push("VERTEX_COLORS".into());
vertex_attributes.push(Mesh::ATTRIBUTE_COLOR.at_shader_location(4));
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_sprite/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl SpecializedRenderPipeline for SpritePipeline {

let mut shader_defs = Vec::new();
if key.contains(SpritePipelineKey::COLORED) {
shader_defs.push("COLORED".to_string().into());
shader_defs.push("COLORED".into());
}

if key.contains(SpritePipelineKey::TONEMAP_IN_SHADER) {
Expand Down