local -> material bind group layout

This commit is contained in:
Carter Anderson 2020-01-08 09:07:49 -08:00
parent 86a467f0f3
commit 62364660de
5 changed files with 20 additions and 23 deletions

View file

@ -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()));

View file

@ -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();

View file

@ -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);

View file

@ -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,
],
});

View file

@ -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 <Write<Material>>::query().filter(!component::<Instanced>()).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 {