cargo fmt
This commit is contained in:
		
							parent
							
								
									7eb99f3eb5
								
							
						
					
					
						commit
						f84e71d051
					
				| @ -1,10 +1,7 @@ | |||||||
| use bevy::prelude::*; | use bevy::prelude::*; | ||||||
| 
 | 
 | ||||||
| fn main() { | fn main() { | ||||||
|     AppBuilder::new() |     AppBuilder::new().add_defaults().setup_world(setup).run(); | ||||||
|         .add_defaults() |  | ||||||
|         .setup_world(setup) |  | ||||||
|         .run(); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[allow(dead_code)] | #[allow(dead_code)] | ||||||
|  | |||||||
| @ -2,10 +2,7 @@ use bevy::{prelude::*, serialization::*}; | |||||||
| use serde::{Deserialize, Serialize}; | use serde::{Deserialize, Serialize}; | ||||||
| use type_uuid::TypeUuid; | use type_uuid::TypeUuid; | ||||||
| fn main() { | fn main() { | ||||||
|     let app = AppBuilder::new() |     let app = AppBuilder::new().add_defaults().setup_world(setup).build(); | ||||||
|         .add_defaults() |  | ||||||
|         .setup_world(setup) |  | ||||||
|         .build(); |  | ||||||
| 
 | 
 | ||||||
|     let comp_registrations = [ComponentRegistration::of::<Test>()]; |     let comp_registrations = [ComponentRegistration::of::<Test>()]; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -25,7 +25,8 @@ fn build_move_system() -> Box<dyn Schedulable> { | |||||||
|                             -time.delta_seconds, |                             -time.delta_seconds, | ||||||
|                             time.delta_seconds, |                             time.delta_seconds, | ||||||
|                             0.0, |                             0.0, | ||||||
|                         )).into(); |                         )) | ||||||
|  |                     .into(); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         }) |         }) | ||||||
| @ -127,7 +128,8 @@ fn setup(world: &mut World) { | |||||||
|                     rng.gen_range(0.0, 1.0), |                     rng.gen_range(0.0, 1.0), | ||||||
|                     rng.gen_range(0.0, 1.0), |                     rng.gen_range(0.0, 1.0), | ||||||
|                     1.0, |                     1.0, | ||||||
|                 ).into(), |                 ) | ||||||
|  |                 .into(), | ||||||
|             }, |             }, | ||||||
|             translation: Translation::new( |             translation: Translation::new( | ||||||
|                 rng.gen_range(-50.0, 50.0), |                 rng.gen_range(-50.0, 50.0), | ||||||
|  | |||||||
| @ -1,5 +1,5 @@ | |||||||
| use crate::{ | use crate::{ | ||||||
|     asset::{Texture, Handle}, |     asset::{Handle, Texture}, | ||||||
|     math::Vec4, |     math::Vec4, | ||||||
| }; | }; | ||||||
| use zerocopy::AsBytes; | use zerocopy::AsBytes; | ||||||
|  | |||||||
| @ -1,5 +1,5 @@ | |||||||
| pub mod time; |  | ||||||
| pub mod bytes; | pub mod bytes; | ||||||
|  | pub mod time; | ||||||
| 
 | 
 | ||||||
| pub use time::Time; |  | ||||||
| pub use bytes::GetBytes; | pub use bytes::GetBytes; | ||||||
|  | pub use time::Time; | ||||||
|  | |||||||
| @ -1,5 +1,9 @@ | |||||||
| use crate::ecs::EntityArchetype; | use crate::ecs::EntityArchetype; | ||||||
| use legion::{world::{TagSet, TagLayout, IntoComponentSource}, prelude::*, filter::{Filter, ChunksetFilterData}}; | use legion::{ | ||||||
|  |     filter::{ChunksetFilterData, Filter}, | ||||||
|  |     prelude::*, | ||||||
|  |     world::{IntoComponentSource, TagLayout, TagSet}, | ||||||
|  | }; | ||||||
| 
 | 
 | ||||||
| pub trait WorldBuilderSource { | pub trait WorldBuilderSource { | ||||||
|     fn build(&mut self) -> WorldBuilder; |     fn build(&mut self) -> WorldBuilder; | ||||||
| @ -48,7 +52,7 @@ impl<'a> WorldBuilder<'a> { | |||||||
|         self |         self | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub fn add_entities<T,C>(self, tags: T, components: C) -> Self |     pub fn add_entities<T, C>(self, tags: T, components: C) -> Self | ||||||
|     where |     where | ||||||
|         T: TagSet + TagLayout + for<'b> Filter<ChunksetFilterData<'b>>, |         T: TagSet + TagLayout + for<'b> Filter<ChunksetFilterData<'b>>, | ||||||
|         C: IntoComponentSource, |         C: IntoComponentSource, | ||||||
|  | |||||||
| @ -5,8 +5,8 @@ pub use crate::{ | |||||||
|     ecs, |     ecs, | ||||||
|     ecs::{default_archetypes::*, EntityArchetype, WorldBuilder, WorldBuilderSource}, |     ecs::{default_archetypes::*, EntityArchetype, WorldBuilder, WorldBuilderSource}, | ||||||
|     render::{ |     render::{ | ||||||
|         ActiveCamera, ActiveCamera2d, Camera, CameraType, Instanced, Light, |         render_graph::{Renderable, ShaderDefSuffixProvider, StandardMaterial}, | ||||||
|         render_graph::{StandardMaterial, Renderable, ShaderDefSuffixProvider}, ColorSource |         ActiveCamera, ActiveCamera2d, Camera, CameraType, ColorSource, Instanced, Light, | ||||||
|     }, |     }, | ||||||
|     ui::{Anchors, Margins, Node}, |     ui::{Anchors, Margins, Node}, | ||||||
| }; | }; | ||||||
|  | |||||||
| @ -1,7 +1,8 @@ | |||||||
| use crate::{ | use crate::{ | ||||||
|     asset::{Handle, Texture}, |     asset::{Handle, Texture}, | ||||||
|  |     core::GetBytes, | ||||||
|     math::Vec4, |     math::Vec4, | ||||||
|     render::render_graph::ShaderDefSuffixProvider, core::GetBytes, |     render::render_graph::ShaderDefSuffixProvider, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| pub enum ColorSource { | pub enum ColorSource { | ||||||
|  | |||||||
| @ -8,9 +8,9 @@ mod light; | |||||||
| mod vertex; | mod vertex; | ||||||
| 
 | 
 | ||||||
| pub use camera::*; | pub use camera::*; | ||||||
|  | pub use color::*; | ||||||
| pub use light::*; | pub use light::*; | ||||||
| pub use shader::*; | pub use shader::*; | ||||||
| pub use color::*; |  | ||||||
| 
 | 
 | ||||||
| pub use vertex::Vertex; | pub use vertex::Vertex; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,4 +1,7 @@ | |||||||
| use crate::{asset::Handle, render::render_graph::{pipeline::PipelineDescriptor, RenderPass}}; | use crate::{ | ||||||
|  |     asset::Handle, | ||||||
|  |     render::render_graph::{pipeline::PipelineDescriptor, RenderPass}, | ||||||
|  | }; | ||||||
| use legion::prelude::World; | use legion::prelude::World; | ||||||
| 
 | 
 | ||||||
| // A set of draw calls. ex: get + draw meshes, get + draw instanced meshes, draw ui meshes, etc
 | // A set of draw calls. ex: get + draw meshes, get + draw instanced meshes, draw ui meshes, etc
 | ||||||
|  | |||||||
| @ -1,8 +1,8 @@ | |||||||
| use crate::{ | use crate::{ | ||||||
|     asset::{AssetStorage, Handle, Mesh}, |     asset::{AssetStorage, Handle, Mesh}, | ||||||
|     legion::prelude::*, |     legion::prelude::*, | ||||||
|     render::{ |     render::render_graph::{ | ||||||
|         render_graph::{resource_name, RenderPass, Renderable, PipelineDescriptor, ShaderPipelineAssignments}, |         resource_name, PipelineDescriptor, RenderPass, Renderable, ShaderPipelineAssignments, | ||||||
|     }, |     }, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -2,19 +2,23 @@ use crate::{ | |||||||
|     asset::{AssetStorage, Handle, Mesh}, |     asset::{AssetStorage, Handle, Mesh}, | ||||||
|     legion::prelude::*, |     legion::prelude::*, | ||||||
|     render::{ |     render::{ | ||||||
|         render_graph::{resource_name, RenderPass, Renderable, PipelineDescriptor}, |         render_graph::{resource_name, PipelineDescriptor, RenderPass, Renderable}, | ||||||
|         Instanced, |         Instanced, | ||||||
|     }, |     }, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| use zerocopy::AsBytes; | use zerocopy::AsBytes; | ||||||
| 
 | 
 | ||||||
| pub fn meshes_draw_target(world: &World, render_pass: &mut dyn RenderPass, _pipeline_handle: Handle<PipelineDescriptor>) { | pub fn meshes_draw_target( | ||||||
|  |     world: &World, | ||||||
|  |     render_pass: &mut dyn RenderPass, | ||||||
|  |     _pipeline_handle: Handle<PipelineDescriptor>, | ||||||
|  | ) { | ||||||
|     let mesh_storage = world.resources.get_mut::<AssetStorage<Mesh>>().unwrap(); |     let mesh_storage = world.resources.get_mut::<AssetStorage<Mesh>>().unwrap(); | ||||||
|     let mut current_mesh_id = None; |     let mut current_mesh_id = None; | ||||||
|     let mut current_mesh_index_length = 0; |     let mut current_mesh_index_length = 0; | ||||||
|     let mesh_query = <(Read<Handle<Mesh>>, Read<Renderable>)>::query() |     let mesh_query = | ||||||
|         .filter(!component::<Instanced>()); |         <(Read<Handle<Mesh>>, Read<Renderable>)>::query().filter(!component::<Instanced>()); | ||||||
|     for (entity, (mesh, renderable)) in mesh_query.iter_entities(world) { |     for (entity, (mesh, renderable)) in mesh_query.iter_entities(world) { | ||||||
|         if !renderable.is_visible { |         if !renderable.is_visible { | ||||||
|             continue; |             continue; | ||||||
|  | |||||||
| @ -1,7 +1,7 @@ | |||||||
| mod meshes_draw_target; |  | ||||||
| mod assigned_meshes_draw_target; | mod assigned_meshes_draw_target; | ||||||
|  | mod meshes_draw_target; | ||||||
| mod ui_draw_target; | mod ui_draw_target; | ||||||
| 
 | 
 | ||||||
| pub use meshes_draw_target::*; |  | ||||||
| pub use assigned_meshes_draw_target::*; | pub use assigned_meshes_draw_target::*; | ||||||
|  | pub use meshes_draw_target::*; | ||||||
| pub use ui_draw_target::*; | pub use ui_draw_target::*; | ||||||
|  | |||||||
| @ -1,12 +1,16 @@ | |||||||
| use crate::{ | use crate::{ | ||||||
|     asset::{AssetStorage, Mesh, Handle}, |     asset::{AssetStorage, Handle, Mesh}, | ||||||
|     legion::prelude::*, |     legion::prelude::*, | ||||||
|     render::render_graph::{resource_name, RenderPass, ResourceInfo, PipelineDescriptor}, |     render::render_graph::{resource_name, PipelineDescriptor, RenderPass, ResourceInfo}, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| use zerocopy::AsBytes; | use zerocopy::AsBytes; | ||||||
| 
 | 
 | ||||||
| pub fn ui_draw_target(world: &World, render_pass: &mut dyn RenderPass, _pipeline_handle: Handle<PipelineDescriptor>) { | pub fn ui_draw_target( | ||||||
|  |     world: &World, | ||||||
|  |     render_pass: &mut dyn RenderPass, | ||||||
|  |     _pipeline_handle: Handle<PipelineDescriptor>, | ||||||
|  | ) { | ||||||
|     let mesh_storage = world.resources.get_mut::<AssetStorage<Mesh>>().unwrap(); |     let mesh_storage = world.resources.get_mut::<AssetStorage<Mesh>>().unwrap(); | ||||||
|     // NOTE: this is ugly and borrowing is stupid
 |     // NOTE: this is ugly and borrowing is stupid
 | ||||||
|     let result = { |     let result = { | ||||||
|  | |||||||
| @ -1,7 +1,11 @@ | |||||||
| use crate::{asset::{AssetStorage, Handle}, render::{ | use crate::{ | ||||||
|     render_graph::{BindGroup, PipelineLayout, resource_name}, |     asset::{AssetStorage, Handle}, | ||||||
|     shader::{Shader, ShaderStages}, Vertex, |     render::{ | ||||||
| }}; |         render_graph::{resource_name, BindGroup, PipelineLayout}, | ||||||
|  |         shader::{Shader, ShaderStages}, | ||||||
|  |         Vertex, | ||||||
|  |     }, | ||||||
|  | }; | ||||||
| 
 | 
 | ||||||
| #[derive(Clone, Debug)] | #[derive(Clone, Debug)] | ||||||
| pub struct VertexBufferDescriptor { | pub struct VertexBufferDescriptor { | ||||||
| @ -87,22 +91,25 @@ impl PipelineDescriptor { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub fn get_layout(&self) -> Option<&PipelineLayout> { |     pub fn get_layout(&self) -> Option<&PipelineLayout> { | ||||||
|        match self.layout { |         match self.layout { | ||||||
|            PipelineLayoutType::Reflected(ref layout) => layout.as_ref(), |             PipelineLayoutType::Reflected(ref layout) => layout.as_ref(), | ||||||
|            PipelineLayoutType::Manual(ref layout) => Some(layout), |             PipelineLayoutType::Manual(ref layout) => Some(layout), | ||||||
|        } 
 |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub fn get_layout_mut(&mut self) -> Option<&mut PipelineLayout> { |     pub fn get_layout_mut(&mut self) -> Option<&mut PipelineLayout> { | ||||||
|        match self.layout { |         match self.layout { | ||||||
|            PipelineLayoutType::Reflected(ref mut layout) => layout.as_mut(), |             PipelineLayoutType::Reflected(ref mut layout) => layout.as_mut(), | ||||||
|            PipelineLayoutType::Manual(ref mut layout) => Some(layout), |             PipelineLayoutType::Manual(ref mut layout) => Some(layout), | ||||||
|        } 
 |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl PipelineDescriptor { | impl PipelineDescriptor { | ||||||
|     pub fn build(shader_storage: &mut AssetStorage<Shader>, vertex_shader: Shader) -> PipelineBuilder { |     pub fn build( | ||||||
|  |         shader_storage: &mut AssetStorage<Shader>, | ||||||
|  |         vertex_shader: Shader, | ||||||
|  |     ) -> PipelineBuilder { | ||||||
|         PipelineBuilder::new(shader_storage, vertex_shader) |         PipelineBuilder::new(shader_storage, vertex_shader) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @ -208,23 +215,22 @@ impl<'a> PipelineBuilder<'a> { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub fn with_standard_config(self) -> Self { |     pub fn with_standard_config(self) -> Self { | ||||||
|         self |         self.with_depth_stencil_state(wgpu::DepthStencilStateDescriptor { | ||||||
|             .with_depth_stencil_state(wgpu::DepthStencilStateDescriptor { |             format: wgpu::TextureFormat::Depth32Float, | ||||||
|                 format: wgpu::TextureFormat::Depth32Float, |             depth_write_enabled: true, | ||||||
|                 depth_write_enabled: true, |             depth_compare: wgpu::CompareFunction::Less, | ||||||
|                 depth_compare: wgpu::CompareFunction::Less, |             stencil_front: wgpu::StencilStateFaceDescriptor::IGNORE, | ||||||
|                 stencil_front: wgpu::StencilStateFaceDescriptor::IGNORE, |             stencil_back: wgpu::StencilStateFaceDescriptor::IGNORE, | ||||||
|                 stencil_back: wgpu::StencilStateFaceDescriptor::IGNORE, |             stencil_read_mask: 0, | ||||||
|                 stencil_read_mask: 0, |             stencil_write_mask: 0, | ||||||
|                 stencil_write_mask: 0, |         }) | ||||||
|             }) |         .add_color_state(wgpu::ColorStateDescriptor { | ||||||
|             .add_color_state(wgpu::ColorStateDescriptor { |             format: wgpu::TextureFormat::Bgra8UnormSrgb, | ||||||
|                 format: wgpu::TextureFormat::Bgra8UnormSrgb, |             color_blend: wgpu::BlendDescriptor::REPLACE, | ||||||
|                 color_blend: wgpu::BlendDescriptor::REPLACE, |             alpha_blend: wgpu::BlendDescriptor::REPLACE, | ||||||
|                 alpha_blend: wgpu::BlendDescriptor::REPLACE, |             write_mask: wgpu::ColorWrite::ALL, | ||||||
|                 write_mask: wgpu::ColorWrite::ALL, |         }) | ||||||
|             }) |         .add_vertex_buffer_descriptor(Vertex::get_vertex_buffer_descriptor()) | ||||||
|             .add_vertex_buffer_descriptor(Vertex::get_vertex_buffer_descriptor()) |         .add_draw_target(resource_name::draw_target::ASSIGNED_MESHES) | ||||||
|             .add_draw_target(resource_name::draw_target::ASSIGNED_MESHES) |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,10 +1,7 @@ | |||||||
| use crate::{ | use crate::{ | ||||||
|     asset::AssetStorage, |     asset::AssetStorage, | ||||||
|     render::{ |     render::{ | ||||||
|         render_graph::{ |         render_graph::{resource_name, PipelineDescriptor, RenderGraphBuilder}, | ||||||
|             resource_name, PipelineDescriptor, |  | ||||||
|             RenderGraphBuilder, |  | ||||||
|         }, |  | ||||||
|         shader::{Shader, ShaderStage}, |         shader::{Shader, ShaderStage}, | ||||||
|         Vertex, |         Vertex, | ||||||
|     }, |     }, | ||||||
| @ -32,7 +29,7 @@ impl ForwardFlatPipelineBuilder for RenderGraphBuilder { | |||||||
|             ) |             ) | ||||||
|             .with_fragment_shader(Shader::from_glsl( |             .with_fragment_shader(Shader::from_glsl( | ||||||
|                 ShaderStage::Fragment, |                 ShaderStage::Fragment, | ||||||
|                 include_str!("forward_flat.frag") |                 include_str!("forward_flat.frag"), | ||||||
|             )) |             )) | ||||||
|             .with_rasterization_state(wgpu::RasterizationStateDescriptor { |             .with_rasterization_state(wgpu::RasterizationStateDescriptor { | ||||||
|                 front_face: wgpu::FrontFace::Ccw, |                 front_face: wgpu::FrontFace::Ccw, | ||||||
|  | |||||||
| @ -2,8 +2,8 @@ use crate::{ | |||||||
|     asset::AssetStorage, |     asset::AssetStorage, | ||||||
|     render::{ |     render::{ | ||||||
|         render_graph::{ |         render_graph::{ | ||||||
|             resource_providers::RectData, |             resource_name, resource_providers::RectData, PipelineDescriptor, RenderGraphBuilder, | ||||||
|             PipelineDescriptor, RenderGraphBuilder, VertexBufferDescriptor, resource_name, |             VertexBufferDescriptor, | ||||||
|         }, |         }, | ||||||
|         shader::{Shader, ShaderStage}, |         shader::{Shader, ShaderStage}, | ||||||
|         Vertex, |         Vertex, | ||||||
| @ -31,7 +31,7 @@ impl UiPipelineBuilder for RenderGraphBuilder { | |||||||
|             ) |             ) | ||||||
|             .with_fragment_shader(Shader::from_glsl( |             .with_fragment_shader(Shader::from_glsl( | ||||||
|                 ShaderStage::Fragment, |                 ShaderStage::Fragment, | ||||||
|                 include_str!("ui.frag") |                 include_str!("ui.frag"), | ||||||
|             )) |             )) | ||||||
|             .with_rasterization_state(wgpu::RasterizationStateDescriptor { |             .with_rasterization_state(wgpu::RasterizationStateDescriptor { | ||||||
|                 front_face: wgpu::FrontFace::Ccw, |                 front_face: wgpu::FrontFace::Ccw, | ||||||
|  | |||||||
| @ -1,10 +1,13 @@ | |||||||
|  | use super::PipelineDescriptor; | ||||||
| use crate::{ | use crate::{ | ||||||
|     asset::{AssetStorage, Handle}, |     asset::{AssetStorage, Handle}, | ||||||
|     render::{render_graph::{RenderGraph, resource_name}, Shader, ShaderSource}, |     render::{ | ||||||
|  |         render_graph::{resource_name, RenderGraph}, | ||||||
|  |         Shader, ShaderSource, | ||||||
|  |     }, | ||||||
| }; | }; | ||||||
| use legion::prelude::*; | use legion::prelude::*; | ||||||
| use std::collections::{HashMap, HashSet}; | use std::collections::{HashMap, HashSet}; | ||||||
| use super::PipelineDescriptor; |  | ||||||
| 
 | 
 | ||||||
| pub struct Renderable { | pub struct Renderable { | ||||||
|     pub is_visible: bool, |     pub is_visible: bool, | ||||||
| @ -27,7 +30,8 @@ impl Default for Renderable { | |||||||
| pub struct CompiledShaderMap { | pub struct CompiledShaderMap { | ||||||
|     // TODO: need macro hash lookup
 |     // TODO: need macro hash lookup
 | ||||||
|     pub source_to_compiled: HashMap<Handle<Shader>, Vec<(HashSet<String>, Handle<Shader>)>>, |     pub source_to_compiled: HashMap<Handle<Shader>, Vec<(HashSet<String>, Handle<Shader>)>>, | ||||||
|     pub pipeline_to_macro_pipelines: HashMap<Handle<PipelineDescriptor>, Vec<(HashSet<String>, Handle<PipelineDescriptor>)>>, |     pub pipeline_to_macro_pipelines: | ||||||
|  |         HashMap<Handle<PipelineDescriptor>, Vec<(HashSet<String>, Handle<PipelineDescriptor>)>>, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl CompiledShaderMap { | impl CompiledShaderMap { | ||||||
| @ -51,14 +55,22 @@ impl ShaderPipelineAssignments { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn try_compiling_shader_with_macros(compiled_shader_map: &mut CompiledShaderMap, shader_storage: &mut AssetStorage<Shader>, renderable: &Renderable, shader_handle: &Handle<Shader>) -> Option<Handle<Shader>> { | fn try_compiling_shader_with_macros( | ||||||
|  |     compiled_shader_map: &mut CompiledShaderMap, | ||||||
|  |     shader_storage: &mut AssetStorage<Shader>, | ||||||
|  |     renderable: &Renderable, | ||||||
|  |     shader_handle: &Handle<Shader>, | ||||||
|  | ) -> Option<Handle<Shader>> { | ||||||
|     if let None = compiled_shader_map.source_to_compiled.get(shader_handle) { |     if let None = compiled_shader_map.source_to_compiled.get(shader_handle) { | ||||||
|         compiled_shader_map |         compiled_shader_map | ||||||
|             .source_to_compiled |             .source_to_compiled | ||||||
|             .insert(shader_handle.clone(), Vec::new()); |             .insert(shader_handle.clone(), Vec::new()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     let compiled_shaders = compiled_shader_map.source_to_compiled.get_mut(shader_handle).unwrap(); |     let compiled_shaders = compiled_shader_map | ||||||
|  |         .source_to_compiled | ||||||
|  |         .get_mut(shader_handle) | ||||||
|  |         .unwrap(); | ||||||
|     let shader = shader_storage.get(shader_handle).unwrap(); |     let shader = shader_storage.get(shader_handle).unwrap(); | ||||||
| 
 | 
 | ||||||
|     // don't produce new shader if the input source is already spriv
 |     // don't produce new shader if the input source is already spriv
 | ||||||
| @ -66,44 +78,84 @@ fn try_compiling_shader_with_macros(compiled_shader_map: &mut CompiledShaderMap, | |||||||
|         return None; |         return None; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if let Some((_shader_defs, compiled_shader)) = compiled_shaders.iter().find(|(shader_defs, _shader)| *shader_defs == renderable.shader_defs) { |     if let Some((_shader_defs, compiled_shader)) = compiled_shaders | ||||||
|  |         .iter() | ||||||
|  |         .find(|(shader_defs, _shader)| *shader_defs == renderable.shader_defs) | ||||||
|  |     { | ||||||
|         Some(compiled_shader.clone()) |         Some(compiled_shader.clone()) | ||||||
|     } else { |     } else { | ||||||
|         let shader_def_vec = renderable.shader_defs.iter().cloned().collect::<Vec<String>>(); |         let shader_def_vec = renderable | ||||||
|  |             .shader_defs | ||||||
|  |             .iter() | ||||||
|  |             .cloned() | ||||||
|  |             .collect::<Vec<String>>(); | ||||||
|         let compiled_shader = shader.get_spirv_shader(Some(&shader_def_vec)); |         let compiled_shader = shader.get_spirv_shader(Some(&shader_def_vec)); | ||||||
|         compiled_shaders.push((renderable.shader_defs.clone(), shader_handle.clone())); |         compiled_shaders.push((renderable.shader_defs.clone(), shader_handle.clone())); | ||||||
|         let compiled_shader_handle = shader_storage.add(compiled_shader); |         let compiled_shader_handle = shader_storage.add(compiled_shader); | ||||||
|         Some(compiled_shader_handle) |         Some(compiled_shader_handle) | ||||||
|     } |     } | ||||||
| 
 |  | ||||||
| } | } | ||||||
| pub fn update_shader_assignments(world: &mut World, render_graph: &mut RenderGraph) { | pub fn update_shader_assignments(world: &mut World, render_graph: &mut RenderGraph) { | ||||||
|     // PERF: this seems like a lot of work for things that don't change that often.
 |     // PERF: this seems like a lot of work for things that don't change that often.
 | ||||||
|     // lots of string + hashset allocations. sees uniform_resource_provider for more context
 |     // lots of string + hashset allocations. sees uniform_resource_provider for more context
 | ||||||
|     { |     { | ||||||
|         let mut shader_pipeline_assignments = world.resources.get_mut::<ShaderPipelineAssignments>().unwrap(); |         let mut shader_pipeline_assignments = world | ||||||
|  |             .resources | ||||||
|  |             .get_mut::<ShaderPipelineAssignments>() | ||||||
|  |             .unwrap(); | ||||||
|         let mut compiled_shader_map = world.resources.get_mut::<CompiledShaderMap>().unwrap(); |         let mut compiled_shader_map = world.resources.get_mut::<CompiledShaderMap>().unwrap(); | ||||||
|         let mut shader_storage = world.resources.get_mut::<AssetStorage<Shader>>().unwrap(); |         let mut shader_storage = world.resources.get_mut::<AssetStorage<Shader>>().unwrap(); | ||||||
|         let mut pipeline_descriptor_storage = world.resources.get_mut::<AssetStorage<PipelineDescriptor>>().unwrap(); |         let mut pipeline_descriptor_storage = world | ||||||
|  |             .resources | ||||||
|  |             .get_mut::<AssetStorage<PipelineDescriptor>>() | ||||||
|  |             .unwrap(); | ||||||
| 
 | 
 | ||||||
|         // reset assignments so they are updated every frame
 |         // reset assignments so they are updated every frame
 | ||||||
|         shader_pipeline_assignments.assignments = HashMap::new(); |         shader_pipeline_assignments.assignments = HashMap::new(); | ||||||
| 
 | 
 | ||||||
|         for (entity, renderable) in <Read<Renderable>>::query().iter_entities(world) { |         for (entity, renderable) in <Read<Renderable>>::query().iter_entities(world) { | ||||||
|             for pipeline_handle in renderable.pipelines.iter() { |             for pipeline_handle in renderable.pipelines.iter() { | ||||||
|                 if let None = compiled_shader_map.pipeline_to_macro_pipelines.get(pipeline_handle) { |                 if let None = compiled_shader_map | ||||||
|  |                     .pipeline_to_macro_pipelines | ||||||
|  |                     .get(pipeline_handle) | ||||||
|  |                 { | ||||||
|                     compiled_shader_map |                     compiled_shader_map | ||||||
|                         .pipeline_to_macro_pipelines |                         .pipeline_to_macro_pipelines | ||||||
|                         .insert(pipeline_handle.clone(), Vec::new()); |                         .insert(pipeline_handle.clone(), Vec::new()); | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 let final_handle = if let Some((_shader_defs, macroed_pipeline_handle)) = compiled_shader_map.pipeline_to_macro_pipelines.get_mut(pipeline_handle).unwrap().iter().find(|(shader_defs, _macroed_pipeline_handle)| *shader_defs == renderable.shader_defs) { |                 let final_handle = if let Some((_shader_defs, macroed_pipeline_handle)) = | ||||||
|  |                     compiled_shader_map | ||||||
|  |                         .pipeline_to_macro_pipelines | ||||||
|  |                         .get_mut(pipeline_handle) | ||||||
|  |                         .unwrap() | ||||||
|  |                         .iter() | ||||||
|  |                         .find(|(shader_defs, _macroed_pipeline_handle)| { | ||||||
|  |                             *shader_defs == renderable.shader_defs | ||||||
|  |                         }) { | ||||||
|                     macroed_pipeline_handle.clone() |                     macroed_pipeline_handle.clone() | ||||||
|                 } else { |                 } else { | ||||||
|                     let pipeline_descriptor = pipeline_descriptor_storage.get(pipeline_handle).unwrap(); |                     let pipeline_descriptor = | ||||||
|  |                         pipeline_descriptor_storage.get(pipeline_handle).unwrap(); | ||||||
|                     let macroed_pipeline_handle = { |                     let macroed_pipeline_handle = { | ||||||
|                         let mut macroed_vertex_handle = try_compiling_shader_with_macros(&mut compiled_shader_map, &mut shader_storage, &renderable, &pipeline_descriptor.shader_stages.vertex); |                         let mut macroed_vertex_handle = try_compiling_shader_with_macros( | ||||||
|                         let mut macroed_fragment_handle = pipeline_descriptor.shader_stages.fragment.as_ref().map(|fragment| try_compiling_shader_with_macros(&mut compiled_shader_map, &mut shader_storage, &renderable, fragment)); |                             &mut compiled_shader_map, | ||||||
|  |                             &mut shader_storage, | ||||||
|  |                             &renderable, | ||||||
|  |                             &pipeline_descriptor.shader_stages.vertex, | ||||||
|  |                         ); | ||||||
|  |                         let mut macroed_fragment_handle = pipeline_descriptor | ||||||
|  |                             .shader_stages | ||||||
|  |                             .fragment | ||||||
|  |                             .as_ref() | ||||||
|  |                             .map(|fragment| { | ||||||
|  |                                 try_compiling_shader_with_macros( | ||||||
|  |                                     &mut compiled_shader_map, | ||||||
|  |                                     &mut shader_storage, | ||||||
|  |                                     &renderable, | ||||||
|  |                                     fragment, | ||||||
|  |                                 ) | ||||||
|  |                             }); | ||||||
| 
 | 
 | ||||||
|                         if macroed_vertex_handle.is_some() || macroed_fragment_handle.is_some() { |                         if macroed_vertex_handle.is_some() || macroed_fragment_handle.is_some() { | ||||||
|                             let mut macroed_pipeline = pipeline_descriptor.clone(); |                             let mut macroed_pipeline = pipeline_descriptor.clone(); | ||||||
| @ -115,26 +167,41 @@ pub fn update_shader_assignments(world: &mut World, render_graph: &mut RenderGra | |||||||
|                                 macroed_pipeline.shader_stages.fragment = fragment; |                                 macroed_pipeline.shader_stages.fragment = fragment; | ||||||
|                             } |                             } | ||||||
| 
 | 
 | ||||||
|                             let macroed_pipeline_handle = pipeline_descriptor_storage.add(macroed_pipeline); |                             let macroed_pipeline_handle = | ||||||
|  |                                 pipeline_descriptor_storage.add(macroed_pipeline); | ||||||
|                             // TODO: get correct pass name
 |                             // TODO: get correct pass name
 | ||||||
|                             render_graph.add_pipeline(resource_name::pass::MAIN, macroed_pipeline_handle.clone()); |                             render_graph.add_pipeline( | ||||||
|  |                                 resource_name::pass::MAIN, | ||||||
|  |                                 macroed_pipeline_handle.clone(), | ||||||
|  |                             ); | ||||||
|                             macroed_pipeline_handle |                             macroed_pipeline_handle | ||||||
|                         } else { |                         } else { | ||||||
|                             pipeline_handle.clone() |                             pipeline_handle.clone() | ||||||
|                         } |                         } | ||||||
|                     }; |                     }; | ||||||
| 
 | 
 | ||||||
|                     let macro_pipelines = compiled_shader_map.pipeline_to_macro_pipelines.get_mut(pipeline_handle).unwrap(); |                     let macro_pipelines = compiled_shader_map | ||||||
|                     macro_pipelines.push((renderable.shader_defs.clone(), macroed_pipeline_handle.clone())); |                         .pipeline_to_macro_pipelines | ||||||
|  |                         .get_mut(pipeline_handle) | ||||||
|  |                         .unwrap(); | ||||||
|  |                     macro_pipelines.push(( | ||||||
|  |                         renderable.shader_defs.clone(), | ||||||
|  |                         macroed_pipeline_handle.clone(), | ||||||
|  |                     )); | ||||||
|                     macroed_pipeline_handle |                     macroed_pipeline_handle | ||||||
|                 }; |                 }; | ||||||
| 
 | 
 | ||||||
|                 // TODO: this will break down if pipeline layout changes. fix this with "autolayout"
 |                 // TODO: this will break down if pipeline layout changes. fix this with "autolayout"
 | ||||||
|                 if let None = shader_pipeline_assignments.assignments.get(&final_handle) { |                 if let None = shader_pipeline_assignments.assignments.get(&final_handle) { | ||||||
|                     shader_pipeline_assignments.assignments.insert(final_handle.clone(), Vec::new()); |                     shader_pipeline_assignments | ||||||
|  |                         .assignments | ||||||
|  |                         .insert(final_handle.clone(), Vec::new()); | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 let assignments = shader_pipeline_assignments.assignments.get_mut(&final_handle).unwrap(); |                 let assignments = shader_pipeline_assignments | ||||||
|  |                     .assignments | ||||||
|  |                     .get_mut(&final_handle) | ||||||
|  |                     .unwrap(); | ||||||
|                 assignments.push(entity); |                 assignments.push(entity); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -1,8 +1,7 @@ | |||||||
| use crate::{ | use crate::{ | ||||||
|     legion::prelude::*, |     legion::prelude::*, | ||||||
|     render::render_graph::{ |     render::render_graph::{ | ||||||
|         DynamicUniformBufferInfo, PipelineDescriptor, RenderGraph, ResourceInfo, |         DynamicUniformBufferInfo, PipelineDescriptor, RenderGraph, ResourceInfo, TextureDescriptor, | ||||||
|         TextureDescriptor, |  | ||||||
|     }, |     }, | ||||||
| }; | }; | ||||||
| use std::ops::Range; | use std::ops::Range; | ||||||
|  | |||||||
| @ -1,9 +1,10 @@ | |||||||
| use crate::{ | use crate::{ | ||||||
|  |     core::GetBytes, | ||||||
|     math::Vec4, |     math::Vec4, | ||||||
|     render::{ |     render::{ | ||||||
|         color::ColorSource, |         color::ColorSource, | ||||||
|         render_graph::{BindType, TextureViewDimension}, |         render_graph::{BindType, TextureViewDimension}, | ||||||
|     }, core::GetBytes, |     }, | ||||||
| }; | }; | ||||||
| use legion::prelude::Entity; | use legion::prelude::Entity; | ||||||
| use std::collections::HashMap; | use std::collections::HashMap; | ||||||
| @ -133,8 +134,7 @@ where | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl AsFieldBindType for Vec4 | impl AsFieldBindType for Vec4 { | ||||||
| { |  | ||||||
|     fn get_field_bind_type(&self) -> FieldBindType { |     fn get_field_bind_type(&self) -> FieldBindType { | ||||||
|         FieldBindType::Uniform |         FieldBindType::Uniform | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -1,10 +1,10 @@ | |||||||
| use crate::render::render_graph::{ | use crate::render::render_graph::{ | ||||||
|     BindGroup, BindType, Binding, UniformProperty, UniformPropertyType, TextureViewDimension |     BindGroup, BindType, Binding, TextureViewDimension, UniformProperty, UniformPropertyType, | ||||||
| }; | }; | ||||||
| use spirv_reflect::{ | use spirv_reflect::{ | ||||||
|     types::{ |     types::{ | ||||||
|         ReflectDescriptorBinding, ReflectDescriptorSet, ReflectDescriptorType, |         ReflectDescriptorBinding, ReflectDescriptorSet, ReflectDescriptorType, ReflectDimension, | ||||||
|         ReflectTypeDescription, ReflectTypeFlags, ReflectDimension, |         ReflectTypeDescription, ReflectTypeFlags, | ||||||
|     }, |     }, | ||||||
|     ShaderModule, |     ShaderModule, | ||||||
| }; | }; | ||||||
| @ -44,7 +44,7 @@ pub fn get_shader_layout(spirv_data: &[u32]) -> ShaderLayout { | |||||||
|                 entry_point: entry_point_name, |                 entry_point: entry_point_name, | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         Err(err) => panic!("Failed to reflect shader layout: {:?}", err) |         Err(err) => panic!("Failed to reflect shader layout: {:?}", err), | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -145,7 +145,11 @@ fn reflect_uniform_numeric(type_description: &ReflectTypeDescription) -> Uniform | |||||||
|         .type_flags |         .type_flags | ||||||
|         .contains(ReflectTypeFlags::MATRIX) |         .contains(ReflectTypeFlags::MATRIX) | ||||||
|     { |     { | ||||||
|         match (number_type, traits.numeric.matrix.column_count, traits.numeric.matrix.row_count) { |         match ( | ||||||
|  |             number_type, | ||||||
|  |             traits.numeric.matrix.column_count, | ||||||
|  |             traits.numeric.matrix.row_count, | ||||||
|  |         ) { | ||||||
|             (NumberType::Float, 3, 3) => UniformPropertyType::Mat3, |             (NumberType::Float, 3, 3) => UniformPropertyType::Mat3, | ||||||
|             (NumberType::Float, 4, 4) => UniformPropertyType::Mat4, |             (NumberType::Float, 4, 4) => UniformPropertyType::Mat4, | ||||||
|             (number_type, column_count, row_count) => panic!( |             (number_type, column_count, row_count) => panic!( | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Carter Anderson
						Carter Anderson