diff --git a/crates/bevy_render/src/pipeline/binding.rs b/crates/bevy_render/src/pipeline/binding.rs index dba9ddefdf..064c9247d6 100644 --- a/crates/bevy_render/src/pipeline/binding.rs +++ b/crates/bevy_render/src/pipeline/binding.rs @@ -1,12 +1,21 @@ use super::UniformProperty; use crate::texture::{TextureComponentType, TextureFormat, TextureViewDimension}; +bitflags::bitflags! { + pub struct BindingShaderStage: u32 { + const VERTEX = 1; + const FRAGMENT = 2; + const COMPUTE = 4; + } +} + + #[derive(Hash, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] pub struct BindingDescriptor { pub name: String, pub index: u32, pub bind_type: BindType, - // TODO: ADD SHADER STAGE VISIBILITY + pub shader_stage: BindingShaderStage, } #[derive(Hash, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] diff --git a/crates/bevy_render/src/render_graph/nodes/pass_node.rs b/crates/bevy_render/src/render_graph/nodes/pass_node.rs index f6d8cbbdc4..7dc17568fb 100644 --- a/crates/bevy_render/src/render_graph/nodes/pass_node.rs +++ b/crates/bevy_render/src/render_graph/nodes/pass_node.rs @@ -4,6 +4,7 @@ use crate::{ pass::{ClearColor, LoadOp, PassDescriptor, TextureAttachment}, pipeline::{ BindGroupDescriptor, BindType, BindingDescriptor, PipelineDescriptor, UniformProperty, + BindingShaderStage, }, render_graph::{Node, ResourceSlotInfo, ResourceSlots}, renderer::{ @@ -78,6 +79,7 @@ impl PassNode { dynamic: false, properties: vec![UniformProperty::Struct(vec![UniformProperty::Mat4])], }, + shader_stage: BindingShaderStage::VERTEX | BindingShaderStage::FRAGMENT, }], ); diff --git a/crates/bevy_render/src/renderer/render_resource/render_resource_bindings.rs b/crates/bevy_render/src/renderer/render_resource/render_resource_bindings.rs index a910c797f4..ad12252a44 100644 --- a/crates/bevy_render/src/renderer/render_resource/render_resource_bindings.rs +++ b/crates/bevy_render/src/renderer/render_resource/render_resource_bindings.rs @@ -261,7 +261,7 @@ impl Default for RenderResourceBindingsId { #[cfg(test)] mod tests { use super::*; - use crate::pipeline::{BindType, BindingDescriptor, UniformProperty}; + use crate::pipeline::{BindType, BindingDescriptor, UniformProperty, BindingShaderStage}; #[test] fn test_bind_groups() { @@ -275,6 +275,7 @@ mod tests { dynamic: false, properties: vec![UniformProperty::Struct(vec![UniformProperty::Mat4])], }, + shader_stage: BindingShaderStage::VERTEX | BindingShaderStage::FRAGMENT, }, BindingDescriptor { index: 1, @@ -283,6 +284,7 @@ mod tests { dynamic: false, properties: vec![UniformProperty::Float], }, + shader_stage: BindingShaderStage::VERTEX | BindingShaderStage::FRAGMENT, }, ], ); diff --git a/crates/bevy_render/src/shader/shader_reflect.rs b/crates/bevy_render/src/shader/shader_reflect.rs index 83f17650ac..c71b4dcb92 100644 --- a/crates/bevy_render/src/shader/shader_reflect.rs +++ b/crates/bevy_render/src/shader/shader_reflect.rs @@ -1,7 +1,7 @@ use crate::{ pipeline::{ BindGroupDescriptor, BindType, BindingDescriptor, InputStepMode, UniformProperty, - VertexAttributeDescriptor, VertexBufferDescriptor, VertexFormat, + VertexAttributeDescriptor, VertexBufferDescriptor, VertexFormat, BindingShaderStage, }, texture::{TextureComponentType, TextureViewDimension}, }; @@ -204,6 +204,8 @@ fn reflect_binding(binding: &ReflectDescriptorBinding) -> BindingDescriptor { index: binding.binding, bind_type, name: name.to_string(), + // TODO: We should be able to detect which shader program the binding is being used in.. + shader_stage: BindingShaderStage::VERTEX | BindingShaderStage::FRAGMENT, } } @@ -414,6 +416,7 @@ mod tests { UniformProperty::Mat4 ])], }, + shader_stage: BindingShaderStage::VERTEX | BindingShaderStage::FRAGMENT, }] ), BindGroupDescriptor::new( @@ -426,6 +429,7 @@ mod tests { dimension: TextureViewDimension::D2, component_type: TextureComponentType::Float, }, + shader_stage: BindingShaderStage::VERTEX | BindingShaderStage::FRAGMENT, }] ), ]