From 62364660deee55d56fa901f3c7cb0cd0e1eb46d3 Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Wed, 8 Jan 2020 09:07:49 -0800 Subject: [PATCH] local -> material bind group layout --- src/application.rs | 11 ----------- src/render/passes/forward/forward_pipeline.rs | 5 ++--- src/render/passes/forward_shadow/mod.rs | 4 ++-- src/render/passes/shadow/shadow_pipeline.rs | 5 ++--- .../material_resource_manager.rs | 18 ++++++++++++++---- 5 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/application.rs b/src/application.rs index 5cb4f5ed2c..6a8bc6835a 100644 --- a/src/application.rs +++ b/src/application.rs @@ -20,21 +20,10 @@ pub struct Application impl Application { fn add_default_passes(&mut self) { - let local_bind_group_layout = - self.render_graph.data.device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { - bindings: &[wgpu::BindGroupLayoutBinding { - binding: 0, - visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, - ty: wgpu::BindingType::UniformBuffer { dynamic: false }, - }], - }); - self.render_graph.add_render_resource_manager(Box::new(render_resources::MaterialResourceManager)); self.render_graph.add_render_resource_manager(Box::new(render_resources::LightResourceManager::new(10))); self.render_graph.add_render_resource_manager(Box::new(render_resources::CameraResourceManager)); - self.render_graph.data.set_bind_group_layout("local", local_bind_group_layout); - let depth_format = wgpu::TextureFormat::Depth32Float; self.render_graph.set_pass("forward", Box::new(ForwardPass::new(depth_format))); self.render_graph.set_pipeline("forward", "forward", Box::new(ForwardPipeline::new())); diff --git a/src/render/passes/forward/forward_pipeline.rs b/src/render/passes/forward/forward_pipeline.rs index f98a7bbf0c..62410adbfd 100644 --- a/src/render/passes/forward/forward_pipeline.rs +++ b/src/render/passes/forward/forward_pipeline.rs @@ -66,11 +66,10 @@ impl Pipeline for ForwardPipeline { }) }); - // TODO: fix this inline "local" - let local_bind_group_layout = render_graph.get_bind_group_layout("local").unwrap(); + let material_bind_group_layout = render_graph.get_bind_group_layout(render_resources::MATERIAL_BIND_GROUP_LAYOUT_NAME).unwrap(); let pipeline_layout = render_graph.device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - bind_group_layouts: &[&bind_group_layout, local_bind_group_layout], + bind_group_layouts: &[&bind_group_layout, material_bind_group_layout], }); let vertex_buffer_descriptor = get_vertex_buffer_descriptor(); diff --git a/src/render/passes/forward_shadow/mod.rs b/src/render/passes/forward_shadow/mod.rs index 80aed483cf..7f69c8e293 100644 --- a/src/render/passes/forward_shadow/mod.rs +++ b/src/render/passes/forward_shadow/mod.rs @@ -88,10 +88,10 @@ impl Pipeline for ForwardShadowPassNew { }) }); - let local_bind_group_layout = render_graph.get_bind_group_layout("local").unwrap(); + let material_bind_group_layout = render_graph.get_bind_group_layout(render_resources::MATERIAL_BIND_GROUP_LAYOUT_NAME).unwrap(); let pipeline_layout = render_graph.device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - bind_group_layouts: &[&bind_group_layout, local_bind_group_layout], + bind_group_layouts: &[&bind_group_layout, material_bind_group_layout], }); let vs_module = render_graph.device.create_shader_module(&vs_bytes); diff --git a/src/render/passes/shadow/shadow_pipeline.rs b/src/render/passes/shadow/shadow_pipeline.rs index 8c8a1227bf..a0f5ac32a2 100644 --- a/src/render/passes/shadow/shadow_pipeline.rs +++ b/src/render/passes/shadow/shadow_pipeline.rs @@ -38,13 +38,12 @@ impl Pipeline for ShadowPipeline { }], }); - // TODO: stop using "local" - let local_bind_group_layout = render_graph.get_bind_group_layout("local").unwrap(); + let material_bind_group_layout = render_graph.get_bind_group_layout(render_resources::MATERIAL_BIND_GROUP_LAYOUT_NAME).unwrap(); let pipeline_layout = render_graph.device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { bind_group_layouts: &[ &bind_group_layout, - local_bind_group_layout, + material_bind_group_layout, ], }); diff --git a/src/render/render_resources/material_resource_manager.rs b/src/render/render_resources/material_resource_manager.rs index a99efa0910..6f273b9dab 100644 --- a/src/render/render_resources/material_resource_manager.rs +++ b/src/render/render_resources/material_resource_manager.rs @@ -4,11 +4,22 @@ use legion::prelude::*; use std::mem; use zerocopy::AsBytes; +pub const MATERIAL_BIND_GROUP_LAYOUT_NAME: &str = "material"; + pub struct MaterialResourceManager; impl RenderResourceManager for MaterialResourceManager { - fn initialize(&self, _render_graph: &mut RenderGraphData, _world: &mut World) { + fn initialize(&self, render_graph: &mut RenderGraphData, _world: &mut World) { + let material_bind_group_layout = + render_graph.device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { + bindings: &[wgpu::BindGroupLayoutBinding { + binding: 0, + visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, + ty: wgpu::BindingType::UniformBuffer { dynamic: false }, + }], + }); + render_graph.set_bind_group_layout(MATERIAL_BIND_GROUP_LAYOUT_NAME, material_bind_group_layout); } fn update<'a>(&mut self, render_graph: &mut RenderGraphData, encoder: &'a mut wgpu::CommandEncoder, world: &mut World) { @@ -31,8 +42,7 @@ impl RenderResourceManager for MaterialResourceManager { ); } - // TODO: dont use inline local - let local_bind_group_layout = render_graph.get_bind_group_layout("local").unwrap(); + let material_bind_group_layout = render_graph.get_bind_group_layout(MATERIAL_BIND_GROUP_LAYOUT_NAME).unwrap(); for mut material in >::query().filter(!component::()).iter(world) { if let None = material.bind_group { @@ -43,7 +53,7 @@ impl RenderResourceManager for MaterialResourceManager { }); let bind_group = render_graph.device.create_bind_group(&wgpu::BindGroupDescriptor { - layout: local_bind_group_layout, + layout: material_bind_group_layout, bindings: &[wgpu::Binding { binding: 0, resource: wgpu::BindingResource::Buffer {