Flexible camera bindings (#1689)

Alternative to #1203 and #1611

Camera bindings have historically been "hacked in". They were _required_ in all shaders and only supported a single Mat4. PBR (#1554) requires the CameraView matrix, but adding this using the "hacked" method forced users to either include all possible camera data in a single binding (#1203) or include all possible bindings (#1611).

This approach instead assigns each "active camera" its own RenderResourceBindings, which are populated by CameraNode. The PassNode then retrieves (and initializes) the relevant bind groups for all render pipelines used by visible entities. 

* Enables any number of camera bindings , including zero (with any set or binding number ... set 0 should still be used to avoid rebinds).
* Renames Camera binding to CameraViewProj
* Adds CameraView binding
This commit is contained in:
Carter Anderson 2021-03-19 20:36:40 +00:00
parent 6121e5f933
commit dd4a196329
15 changed files with 275 additions and 240 deletions

View file

@ -2,7 +2,7 @@
layout(location = 0) in vec3 Vertex_Position; layout(location = 0) in vec3 Vertex_Position;
layout(set = 0, binding = 0) uniform Camera { layout(set = 0, binding = 0) uniform CameraViewProj {
mat4 ViewProj; mat4 ViewProj;
}; };

View file

@ -14,7 +14,7 @@ layout(location = 2) in vec2 v_Uv;
layout(location = 0) out vec4 o_Target; layout(location = 0) out vec4 o_Target;
layout(set = 0, binding = 0) uniform Camera { layout(set = 0, binding = 0) uniform CameraViewProj {
mat4 ViewProj; mat4 ViewProj;
}; };

View file

@ -8,7 +8,7 @@ layout(location = 0) out vec3 v_Position;
layout(location = 1) out vec3 v_Normal; layout(location = 1) out vec3 v_Normal;
layout(location = 2) out vec2 v_Uv; layout(location = 2) out vec2 v_Uv;
layout(set = 0, binding = 0) uniform Camera { layout(set = 0, binding = 0) uniform CameraViewProj {
mat4 ViewProj; mat4 ViewProj;
}; };

View file

@ -1,3 +1,5 @@
use crate::renderer::RenderResourceBindings;
use super::Camera; use super::Camera;
use bevy_ecs::{ use bevy_ecs::{
entity::Entity, entity::Entity,
@ -5,22 +7,29 @@ use bevy_ecs::{
}; };
use bevy_utils::HashMap; use bevy_utils::HashMap;
#[derive(Debug, Default)]
pub struct ActiveCamera {
pub entity: Option<Entity>,
pub bindings: RenderResourceBindings,
}
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct ActiveCameras { pub struct ActiveCameras {
pub cameras: HashMap<String, Option<Entity>>, cameras: HashMap<String, ActiveCamera>,
} }
impl ActiveCameras { impl ActiveCameras {
pub fn add(&mut self, name: &str) { pub fn add(&mut self, name: &str) {
self.cameras.insert(name.to_string(), None); self.cameras
.insert(name.to_string(), ActiveCamera::default());
} }
pub fn set(&mut self, name: &str, entity: Entity) { pub fn get(&self, name: &str) -> Option<&ActiveCamera> {
self.cameras.insert(name.to_string(), Some(entity)); self.cameras.get(name)
} }
pub fn get(&self, name: &str) -> Option<Entity> { pub fn get_mut(&mut self, name: &str) -> Option<&mut ActiveCamera> {
self.cameras.get(name).and_then(|e| *e) self.cameras.get_mut(name)
} }
} }
@ -29,11 +38,11 @@ pub fn active_cameras_system(
query: Query<(Entity, &Camera)>, query: Query<(Entity, &Camera)>,
) { ) {
for (name, active_camera) in active_cameras.cameras.iter_mut() { for (name, active_camera) in active_cameras.cameras.iter_mut() {
if active_camera.is_none() { if active_camera.entity.is_none() {
for (camera_entity, camera) in query.iter() { for (camera_entity, camera) in query.iter() {
if let Some(ref current_name) = camera.name { if let Some(ref current_name) = camera.name {
if current_name == name { if current_name == name {
*active_camera = Some(camera_entity); active_camera.entity = Some(camera_entity);
} }
} }
} }

View file

@ -3,7 +3,7 @@ use crate::{
render_graph::{CommandQueue, Node, ResourceSlots, SystemNode}, render_graph::{CommandQueue, Node, ResourceSlots, SystemNode},
renderer::{ renderer::{
BufferId, BufferInfo, BufferMapMode, BufferUsage, RenderContext, RenderResourceBinding, BufferId, BufferInfo, BufferMapMode, BufferUsage, RenderContext, RenderResourceBinding,
RenderResourceBindings, RenderResourceContext, RenderResourceContext,
}, },
}; };
use bevy_core::AsBytes; use bevy_core::AsBytes;
@ -50,7 +50,6 @@ impl SystemNode for CameraNode {
config.0 = Some(CameraNodeState { config.0 = Some(CameraNodeState {
camera_name: self.camera_name.clone(), camera_name: self.camera_name.clone(),
command_queue: self.command_queue.clone(), command_queue: self.command_queue.clone(),
camera_buffer: None,
staging_buffer: None, staging_buffer: None,
}) })
}); });
@ -58,27 +57,33 @@ impl SystemNode for CameraNode {
} }
} }
const CAMERA_VIEW_PROJ: &str = "CameraViewProj";
const CAMERA_VIEW: &str = "CameraView";
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct CameraNodeState { pub struct CameraNodeState {
command_queue: CommandQueue, command_queue: CommandQueue,
camera_name: Cow<'static, str>, camera_name: Cow<'static, str>,
camera_buffer: Option<BufferId>,
staging_buffer: Option<BufferId>, staging_buffer: Option<BufferId>,
} }
const MATRIX_SIZE: usize = std::mem::size_of::<[[f32; 4]; 4]>();
pub fn camera_node_system( pub fn camera_node_system(
mut state: Local<CameraNodeState>, mut state: Local<CameraNodeState>,
active_cameras: Res<ActiveCameras>, mut active_cameras: ResMut<ActiveCameras>,
render_resource_context: Res<Box<dyn RenderResourceContext>>, render_resource_context: Res<Box<dyn RenderResourceContext>>,
// PERF: this write on RenderResourceAssignments will prevent this system from running in mut query: Query<(&Camera, &GlobalTransform)>,
// parallel with other systems that do the same
mut render_resource_bindings: ResMut<RenderResourceBindings>,
query: Query<(&Camera, &GlobalTransform)>,
) { ) {
let render_resource_context = &**render_resource_context; let render_resource_context = &**render_resource_context;
let (camera, global_transform) = if let Some(entity) = active_cameras.get(&state.camera_name) { let ((camera, global_transform), bindings) =
query.get(entity).unwrap() if let Some(active_camera) = active_cameras.get_mut(&state.camera_name) {
if let Some(entity) = active_camera.entity {
(query.get_mut(entity).unwrap(), &mut active_camera.bindings)
} else {
return;
}
} else { } else {
return; return;
}; };
@ -87,24 +92,8 @@ pub fn camera_node_system(
render_resource_context.map_buffer(staging_buffer, BufferMapMode::Write); render_resource_context.map_buffer(staging_buffer, BufferMapMode::Write);
staging_buffer staging_buffer
} else { } else {
let size = std::mem::size_of::<[[f32; 4]; 4]>();
let buffer = render_resource_context.create_buffer(BufferInfo {
size,
buffer_usage: BufferUsage::COPY_DST | BufferUsage::UNIFORM,
..Default::default()
});
render_resource_bindings.set(
&state.camera_name,
RenderResourceBinding::Buffer {
buffer,
range: 0..size as u64,
dynamic_index: None,
},
);
state.camera_buffer = Some(buffer);
let staging_buffer = render_resource_context.create_buffer(BufferInfo { let staging_buffer = render_resource_context.create_buffer(BufferInfo {
size, size: MATRIX_SIZE * 2,
buffer_usage: BufferUsage::COPY_SRC | BufferUsage::MAP_WRITE, buffer_usage: BufferUsage::COPY_SRC | BufferUsage::MAP_WRITE,
mapped_at_creation: true, mapped_at_creation: true,
}); });
@ -113,25 +102,74 @@ pub fn camera_node_system(
staging_buffer staging_buffer
}; };
let matrix_size = std::mem::size_of::<[[f32; 4]; 4]>(); if bindings.get(CAMERA_VIEW_PROJ).is_none() {
let camera_matrix: [f32; 16] = let buffer = render_resource_context.create_buffer(BufferInfo {
(camera.projection_matrix * global_transform.compute_matrix().inverse()).to_cols_array(); size: MATRIX_SIZE,
buffer_usage: BufferUsage::COPY_DST | BufferUsage::UNIFORM,
render_resource_context.write_mapped_buffer( ..Default::default()
staging_buffer, });
0..matrix_size as u64, bindings.set(
&mut |data, _renderer| { CAMERA_VIEW_PROJ,
data[0..matrix_size].copy_from_slice(camera_matrix.as_bytes()); RenderResourceBinding::Buffer {
buffer,
range: 0..MATRIX_SIZE as u64,
dynamic_index: None,
}, },
); );
render_resource_context.unmap_buffer(staging_buffer); }
let camera_buffer = state.camera_buffer.unwrap(); if bindings.get(CAMERA_VIEW).is_none() {
let buffer = render_resource_context.create_buffer(BufferInfo {
size: MATRIX_SIZE,
buffer_usage: BufferUsage::COPY_DST | BufferUsage::UNIFORM,
..Default::default()
});
bindings.set(
CAMERA_VIEW,
RenderResourceBinding::Buffer {
buffer,
range: 0..MATRIX_SIZE as u64,
dynamic_index: None,
},
);
}
let view = global_transform.compute_matrix();
if let Some(RenderResourceBinding::Buffer { buffer, .. }) = bindings.get(CAMERA_VIEW) {
render_resource_context.write_mapped_buffer(
staging_buffer,
0..MATRIX_SIZE as u64,
&mut |data, _renderer| {
data[0..MATRIX_SIZE].copy_from_slice(view.to_cols_array_2d().as_bytes());
},
);
state.command_queue.copy_buffer_to_buffer( state.command_queue.copy_buffer_to_buffer(
staging_buffer, staging_buffer,
0, 0,
camera_buffer, *buffer,
0, 0,
matrix_size as u64, MATRIX_SIZE as u64,
); );
} }
if let Some(RenderResourceBinding::Buffer { buffer, .. }) = bindings.get(CAMERA_VIEW_PROJ) {
let view_proj = camera.projection_matrix * view.inverse();
render_resource_context.write_mapped_buffer(
staging_buffer,
MATRIX_SIZE as u64..(2 * MATRIX_SIZE) as u64,
&mut |data, _renderer| {
data[0..MATRIX_SIZE].copy_from_slice(view_proj.to_cols_array_2d().as_bytes());
},
);
state.command_queue.copy_buffer_to_buffer(
staging_buffer,
MATRIX_SIZE as u64,
*buffer,
0,
MATRIX_SIZE as u64,
);
}
render_resource_context.unmap_buffer(staging_buffer);
}

View file

@ -9,33 +9,29 @@ use crate::{
prelude::Visible, prelude::Visible,
render_graph::{Node, ResourceSlotInfo, ResourceSlots}, render_graph::{Node, ResourceSlotInfo, ResourceSlots},
renderer::{ renderer::{
BindGroup, BindGroupId, BufferId, RenderContext, RenderResourceBindings, RenderResourceType, BindGroupId, BufferId, RenderContext, RenderResourceBindings, RenderResourceContext,
RenderResourceType,
}, },
}; };
use bevy_asset::{Assets, Handle}; use bevy_asset::{Assets, Handle};
use bevy_ecs::{ use bevy_ecs::{
query::{QueryState, ReadOnlyFetch, WorldQuery}, query::{QueryState, ReadOnlyFetch, WorldQuery},
world::World, world::{Mut, World},
}; };
use bevy_utils::tracing::debug; use bevy_utils::{tracing::debug, HashMap};
use std::{fmt, ops::Deref}; use std::fmt;
#[derive(Debug)]
struct CameraInfo {
name: String,
bind_group_id: Option<BindGroupId>,
}
pub struct PassNode<Q: WorldQuery> { pub struct PassNode<Q: WorldQuery> {
descriptor: PassDescriptor, descriptor: PassDescriptor,
inputs: Vec<ResourceSlotInfo>, inputs: Vec<ResourceSlotInfo>,
cameras: Vec<CameraInfo>, cameras: Vec<String>,
color_attachment_input_indices: Vec<Option<usize>>, color_attachment_input_indices: Vec<Option<usize>>,
color_resolve_target_indices: Vec<Option<usize>>, color_resolve_target_indices: Vec<Option<usize>>,
depth_stencil_attachment_input_index: Option<usize>, depth_stencil_attachment_input_index: Option<usize>,
default_clear_color_inputs: Vec<usize>, default_clear_color_inputs: Vec<usize>,
camera_bind_group_descriptor: BindGroupDescriptor, camera_bind_group_descriptor: BindGroupDescriptor,
query_state: Option<QueryState<Q>>, query_state: Option<QueryState<Q>>,
commands: Vec<RenderCommand>,
} }
impl<Q: WorldQuery> fmt::Debug for PassNode<Q> { impl<Q: WorldQuery> fmt::Debug for PassNode<Q> {
@ -129,14 +125,12 @@ impl<Q: WorldQuery> PassNode<Q> {
default_clear_color_inputs: Vec::new(), default_clear_color_inputs: Vec::new(),
camera_bind_group_descriptor, camera_bind_group_descriptor,
query_state: None, query_state: None,
commands: Vec::new(),
} }
} }
pub fn add_camera(&mut self, camera_name: &str) { pub fn add_camera(&mut self, camera_name: &str) {
self.cameras.push(CameraInfo { self.cameras.push(camera_name.to_string());
name: camera_name.to_string(),
bind_group_id: None,
});
} }
pub fn use_default_clear_color(&mut self, color_attachment_index: usize) { pub fn use_default_clear_color(&mut self, color_attachment_index: usize) {
@ -153,7 +147,81 @@ where
} }
fn prepare(&mut self, world: &mut World) { fn prepare(&mut self, world: &mut World) {
self.query_state.get_or_insert_with(|| world.query()); let query_state = self.query_state.get_or_insert_with(|| world.query());
let cameras = &self.cameras;
let commands = &mut self.commands;
world.resource_scope(|mut active_cameras: Mut<ActiveCameras>, world| {
let mut pipeline_camera_commands = HashMap::default();
let pipelines = world.get_resource::<Assets<PipelineDescriptor>>().unwrap();
let render_resource_context = &**world
.get_resource::<Box<dyn RenderResourceContext>>()
.unwrap();
for camera_name in cameras.iter() {
let active_camera = if let Some(active_camera) = active_cameras.get_mut(camera_name)
{
active_camera
} else {
continue;
};
let visible_entities = if let Some(entity) = active_camera.entity {
world.get::<VisibleEntities>(entity).unwrap()
} else {
continue;
};
for visible_entity in visible_entities.iter() {
if query_state.get(world, visible_entity.entity).is_err() {
// visible entity does not match the Pass query
continue;
}
let draw = if let Some(draw) = world.get::<Draw>(visible_entity.entity) {
draw
} else {
continue;
};
if let Some(visible) = world.get::<Visible>(visible_entity.entity) {
if !visible.is_visible {
continue;
}
}
for render_command in draw.render_commands.iter() {
commands.push(render_command.clone());
// whenever a new pipeline is set, ensure the relevant camera bind groups are set
if let RenderCommand::SetPipeline { pipeline } = render_command {
let bind_groups = pipeline_camera_commands
.entry(pipeline.clone_weak())
.or_insert_with(|| {
let descriptor = pipelines.get(pipeline).unwrap();
let layout = descriptor.get_layout().unwrap();
let mut commands = Vec::new();
for bind_group_descriptor in layout.bind_groups.iter() {
if let Some(bind_group) =
active_camera.bindings.update_bind_group(
bind_group_descriptor,
render_resource_context,
)
{
commands.push(RenderCommand::SetBindGroup {
index: bind_group_descriptor.index,
bind_group: bind_group.id,
dynamic_uniform_indices: bind_group
.dynamic_uniform_indices
.clone(),
})
}
}
commands
});
commands.extend(bind_groups.iter().cloned());
}
}
}
}
});
} }
fn update( fn update(
@ -163,10 +231,6 @@ where
input: &ResourceSlots, input: &ResourceSlots,
_output: &mut ResourceSlots, _output: &mut ResourceSlots,
) { ) {
let render_resource_bindings = world.get_resource::<RenderResourceBindings>().unwrap();
let pipelines = world.get_resource::<Assets<PipelineDescriptor>>().unwrap();
let active_cameras = world.get_resource::<ActiveCameras>().unwrap();
for (i, color_attachment) in self.descriptor.color_attachments.iter_mut().enumerate() { for (i, color_attachment) in self.descriptor.color_attachments.iter_mut().enumerate() {
if self.default_clear_color_inputs.contains(&i) { if self.default_clear_color_inputs.contains(&i) {
if let Some(default_clear_color) = world.get_resource::<ClearColor>() { if let Some(default_clear_color) = world.get_resource::<ClearColor>() {
@ -192,90 +256,25 @@ where
.attachment = .attachment =
TextureAttachment::Id(input.get(input_index).unwrap().get_texture().unwrap()); TextureAttachment::Id(input.get(input_index).unwrap().get_texture().unwrap());
} }
for camera_info in self.cameras.iter_mut() {
let camera_binding =
if let Some(camera_binding) = render_resource_bindings.get(&camera_info.name) {
camera_binding.clone()
} else {
continue;
};
if render_context
.resources()
.bind_group_descriptor_exists(self.camera_bind_group_descriptor.id)
{
let camera_bind_group = BindGroup::build().add_binding(0, camera_binding).finish();
render_context
.resources()
.create_bind_group(self.camera_bind_group_descriptor.id, &camera_bind_group);
camera_info.bind_group_id = Some(camera_bind_group.id);
}
}
let query_state = self.query_state.as_mut().unwrap(); let render_resource_bindings = world.get_resource::<RenderResourceBindings>().unwrap();
let cameras = &self.cameras; let pipelines = world.get_resource::<Assets<PipelineDescriptor>>().unwrap();
let camera_bind_group_descriptor = &self.camera_bind_group_descriptor;
let mut draw_state = DrawState::default();
let commands = &mut self.commands;
render_context.begin_pass( render_context.begin_pass(
&self.descriptor, &self.descriptor,
&render_resource_bindings, &render_resource_bindings,
&mut |render_pass| { &mut |render_pass| {
for camera_info in cameras.iter() { for render_command in commands.drain(..) {
let camera_bind_group_id= if let Some(bind_group_id) = camera_info.bind_group_id {
bind_group_id
} else {
continue;
};
// get an ordered list of entities visible to the camera
let visible_entities = if let Some(camera_entity) = active_cameras.get(&camera_info.name) {
world.get::<VisibleEntities>(camera_entity).unwrap()
} else {
continue;
};
// attempt to draw each visible entity
let mut draw_state = DrawState::default();
for visible_entity in visible_entities.iter() {
if query_state.get(world, visible_entity.entity).is_err() {
// visible entity does not match the Pass query
continue;
}
let draw = if let Some(draw) = world.get::<Draw>(visible_entity.entity) {
draw
} else {
continue;
};
if let Some(visible) = world.get::<Visible>(visible_entity.entity) {
if !visible.is_visible {
continue;
}
}
// each Draw component contains an ordered list of render commands. we turn those into actual render commands here
for render_command in draw.render_commands.iter() {
match render_command { match render_command {
RenderCommand::SetPipeline { pipeline } => { RenderCommand::SetPipeline { pipeline } => {
if draw_state.is_pipeline_set(pipeline.clone_weak()) { if draw_state.is_pipeline_set(pipeline.clone_weak()) {
continue; continue;
} }
render_pass.set_pipeline(pipeline); render_pass.set_pipeline(&pipeline);
let descriptor = pipelines.get(pipeline).unwrap(); let descriptor = pipelines.get(&pipeline).unwrap();
draw_state.set_pipeline(pipeline, descriptor); draw_state.set_pipeline(&pipeline, descriptor);
// try to set current camera bind group
let layout = descriptor.get_layout().unwrap();
if let Some(descriptor) = layout.get_bind_group(0) {
if descriptor == camera_bind_group_descriptor {
draw_state.set_bind_group(0, camera_bind_group_id);
render_pass.set_bind_group(
0,
descriptor.id,
camera_bind_group_id,
None
);
}
}
} }
RenderCommand::DrawIndexed { RenderCommand::DrawIndexed {
base_vertex, base_vertex,
@ -285,7 +284,7 @@ where
if draw_state.can_draw_indexed() { if draw_state.can_draw_indexed() {
render_pass.draw_indexed( render_pass.draw_indexed(
indices.clone(), indices.clone(),
*base_vertex, base_vertex,
instances.clone(), instances.clone(),
); );
} else { } else {
@ -304,46 +303,41 @@ where
offset, offset,
slot, slot,
} => { } => {
if draw_state.is_vertex_buffer_set(*slot, *buffer, *offset) { if draw_state.is_vertex_buffer_set(slot, buffer, offset) {
continue; continue;
} }
render_pass.set_vertex_buffer(*slot, *buffer, *offset); render_pass.set_vertex_buffer(slot, buffer, offset);
draw_state.set_vertex_buffer(*slot, *buffer, *offset); draw_state.set_vertex_buffer(slot, buffer, offset);
} }
RenderCommand::SetIndexBuffer { buffer, offset, index_format } => { RenderCommand::SetIndexBuffer { buffer, offset, index_format } => {
if draw_state.is_index_buffer_set(*buffer, *offset, *index_format) { if draw_state.is_index_buffer_set(buffer, offset, index_format) {
continue; continue;
} }
render_pass.set_index_buffer(*buffer, *offset, *index_format); render_pass.set_index_buffer(buffer, offset, index_format);
draw_state.set_index_buffer(*buffer, *offset, *index_format); draw_state.set_index_buffer(buffer, offset, index_format);
} }
RenderCommand::SetBindGroup { RenderCommand::SetBindGroup {
index, index,
bind_group, bind_group,
dynamic_uniform_indices, dynamic_uniform_indices,
} => { } => {
if dynamic_uniform_indices.is_none() && draw_state.is_bind_group_set(*index, *bind_group) { if dynamic_uniform_indices.is_none() && draw_state.is_bind_group_set(index, bind_group) {
continue; continue;
} }
let pipeline = pipelines.get(draw_state.pipeline.as_ref().unwrap()).unwrap(); let pipeline = pipelines.get(draw_state.pipeline.as_ref().unwrap()).unwrap();
let layout = pipeline.get_layout().unwrap(); let layout = pipeline.get_layout().unwrap();
let bind_group_descriptor = layout.get_bind_group(*index).unwrap(); let bind_group_descriptor = layout.get_bind_group(index).unwrap();
render_pass.set_bind_group( render_pass.set_bind_group(
*index, index,
bind_group_descriptor.id, bind_group_descriptor.id,
*bind_group, bind_group,
dynamic_uniform_indices dynamic_uniform_indices.as_deref()
.as_ref()
.map(|indices| indices.deref()),
); );
draw_state.set_bind_group(*index, *bind_group); draw_state.set_bind_group(index, bind_group);
} }
} }
} }
} });
}
},
);
} }
} }

View file

@ -153,23 +153,17 @@ fn reflect_binding(
_ => panic!("Unsupported bind type {:?}.", binding.descriptor_type), _ => panic!("Unsupported bind type {:?}.", binding.descriptor_type),
}; };
let mut shader_stage = match shader_stage { let shader_stage = match shader_stage {
ReflectShaderStageFlags::COMPUTE => BindingShaderStage::COMPUTE, ReflectShaderStageFlags::COMPUTE => BindingShaderStage::COMPUTE,
ReflectShaderStageFlags::VERTEX => BindingShaderStage::VERTEX, ReflectShaderStageFlags::VERTEX => BindingShaderStage::VERTEX,
ReflectShaderStageFlags::FRAGMENT => BindingShaderStage::FRAGMENT, ReflectShaderStageFlags::FRAGMENT => BindingShaderStage::FRAGMENT,
_ => panic!("Only one specified shader stage is supported."), _ => panic!("Only one specified shader stage is supported."),
}; };
let name = name.to_string();
if name == "Camera" {
shader_stage = BindingShaderStage::VERTEX | BindingShaderStage::FRAGMENT;
}
BindingDescriptor { BindingDescriptor {
index: binding.binding, index: binding.binding,
bind_type, bind_type,
name, name: name.to_string(),
shader_stage, shader_stage,
} }
} }
@ -325,7 +319,7 @@ mod tests {
layout(location = 2) in uvec4 I_TestInstancing_Property; layout(location = 2) in uvec4 I_TestInstancing_Property;
layout(location = 0) out vec4 v_Position; layout(location = 0) out vec4 v_Position;
layout(set = 0, binding = 0) uniform Camera { layout(set = 0, binding = 0) uniform CameraViewProj {
mat4 ViewProj; mat4 ViewProj;
}; };
layout(set = 1, binding = 0) uniform texture2D Texture; layout(set = 1, binding = 0) uniform texture2D Texture;
@ -381,12 +375,12 @@ mod tests {
0, 0,
vec![BindingDescriptor { vec![BindingDescriptor {
index: 0, index: 0,
name: "Camera".into(), name: "CameraViewProj".into(),
bind_type: BindType::Uniform { bind_type: BindType::Uniform {
has_dynamic_offset: false, has_dynamic_offset: false,
property: UniformProperty::Struct(vec![UniformProperty::Mat4]), property: UniformProperty::Struct(vec![UniformProperty::Mat4]),
}, },
shader_stage: BindingShaderStage::VERTEX | BindingShaderStage::FRAGMENT, shader_stage: BindingShaderStage::VERTEX,
}] }]
), ),
BindGroupDescriptor::new( BindGroupDescriptor::new(

View file

@ -2,7 +2,7 @@
layout(location = 0) in vec3 Vertex_Position; layout(location = 0) in vec3 Vertex_Position;
layout(set = 0, binding = 0) uniform Camera { layout(set = 0, binding = 0) uniform CameraViewProj {
mat4 ViewProj; mat4 ViewProj;
}; };

View file

@ -6,7 +6,7 @@ layout(location = 2) in vec2 Vertex_Uv;
layout(location = 0) out vec2 v_Uv; layout(location = 0) out vec2 v_Uv;
layout(set = 0, binding = 0) uniform Camera { layout(set = 0, binding = 0) uniform CameraViewProj {
mat4 ViewProj; mat4 ViewProj;
}; };

View file

@ -7,7 +7,7 @@ layout(location = 2) in vec2 Vertex_Uv;
layout(location = 0) out vec2 v_Uv; layout(location = 0) out vec2 v_Uv;
layout(location = 1) out vec4 v_Color; layout(location = 1) out vec4 v_Color;
layout(set = 0, binding = 0) uniform Camera { layout(set = 0, binding = 0) uniform CameraViewProj {
mat4 ViewProj; mat4 ViewProj;
}; };

View file

@ -6,7 +6,7 @@ layout(location = 2) in vec2 Vertex_Uv;
layout(location = 0) out vec2 v_Uv; layout(location = 0) out vec2 v_Uv;
layout(set = 0, binding = 0) uniform Camera { layout(set = 0, binding = 0) uniform CameraViewProj {
mat4 ViewProj; mat4 ViewProj;
}; };

View file

@ -33,7 +33,7 @@ const VERTEX_SHADER: &str = r#"
layout(location = 0) in vec3 Vertex_Position; layout(location = 0) in vec3 Vertex_Position;
layout(location = 0) out vec4 v_Position; layout(location = 0) out vec4 v_Position;
layout(set = 0, binding = 0) uniform Camera { layout(set = 0, binding = 0) uniform CameraViewProj {
mat4 ViewProj; mat4 ViewProj;
}; };
layout(set = 1, binding = 0) uniform Transform { layout(set = 1, binding = 0) uniform Transform {

View file

@ -29,7 +29,7 @@ layout(location = 0) in vec3 Vertex_Position;
layout(location = 1) in vec3 Vertex_Color; layout(location = 1) in vec3 Vertex_Color;
layout(location = 0) out vec3 v_color; layout(location = 0) out vec3 v_color;
layout(set = 0, binding = 0) uniform Camera { layout(set = 0, binding = 0) uniform CameraViewProj {
mat4 ViewProj; mat4 ViewProj;
}; };
layout(set = 1, binding = 0) uniform Transform { layout(set = 1, binding = 0) uniform Transform {

View file

@ -29,7 +29,7 @@ struct MyMaterial {
const VERTEX_SHADER: &str = r#" const VERTEX_SHADER: &str = r#"
#version 450 #version 450
layout(location = 0) in vec3 Vertex_Position; layout(location = 0) in vec3 Vertex_Position;
layout(set = 0, binding = 0) uniform Camera { layout(set = 0, binding = 0) uniform CameraViewProj {
mat4 ViewProj; mat4 ViewProj;
}; };
layout(set = 1, binding = 0) uniform Transform { layout(set = 1, binding = 0) uniform Transform {

View file

@ -37,7 +37,7 @@ struct MyMaterial {
const VERTEX_SHADER: &str = r#" const VERTEX_SHADER: &str = r#"
#version 450 #version 450
layout(location = 0) in vec3 Vertex_Position; layout(location = 0) in vec3 Vertex_Position;
layout(set = 0, binding = 0) uniform Camera { layout(set = 0, binding = 0) uniform CameraViewProj {
mat4 ViewProj; mat4 ViewProj;
}; };
layout(set = 1, binding = 0) uniform Transform { layout(set = 1, binding = 0) uniform Transform {