add renderable to render related queries

This commit is contained in:
Carter Anderson 2020-02-11 19:09:05 -08:00
parent d58c5e7f5c
commit f24a274a2a
14 changed files with 59 additions and 47 deletions

View file

@ -1,7 +1,4 @@
use bevy::{
prelude::*,
render::render_graph_2::{StandardMaterial},
};
use bevy::{prelude::*, render::render_graph_2::StandardMaterial};
fn main() {
AppBuilder::new().add_defaults().setup_world(setup).run();

View file

@ -1,7 +1,4 @@
use bevy::{
prelude::*,
render::render_graph_2::{ShaderUniforms, StandardMaterial},
};
use bevy::{prelude::*, render::render_graph_2::StandardMaterial};
fn main() {
AppBuilder::new().add_defaults().setup_world(setup).run();

View file

@ -1,6 +1,6 @@
use crate::{
prelude::*,
render::render_graph_2::{ShaderUniforms, StandardMaterial, Renderable},
render::render_graph_2::{Renderable, ShaderUniforms, StandardMaterial},
};
use bevy_derive::EntityArchetype;

View file

@ -22,10 +22,16 @@ impl ForwardPipeline {
impl Pipeline for ForwardPipeline {
fn initialize(&mut self, render_graph: &mut RenderGraphData, _: &mut World) {
let vs_bytes =
shader::glsl_to_spirv(include_str!("forward.vert"), shader::ShaderStage::Vertex, None);
let fs_bytes =
shader::glsl_to_spirv(include_str!("forward.frag"), shader::ShaderStage::Fragment, None);
let vs_bytes = shader::glsl_to_spirv(
include_str!("forward.vert"),
shader::ShaderStage::Vertex,
None,
);
let fs_bytes = shader::glsl_to_spirv(
include_str!("forward.frag"),
shader::ShaderStage::Fragment,
None,
);
let bind_group_layout =
render_graph

View file

@ -102,10 +102,16 @@ impl Pipeline for ShadowPipeline {
let vertex_buffer_descriptor = get_vertex_buffer_descriptor();
// Create the render pipeline
let vs_bytes =
shader::glsl_to_spirv(include_str!("shadow.vert"), shader::ShaderStage::Vertex, None);
let fs_bytes =
shader::glsl_to_spirv(include_str!("shadow.frag"), shader::ShaderStage::Fragment, None);
let vs_bytes = shader::glsl_to_spirv(
include_str!("shadow.vert"),
shader::ShaderStage::Vertex,
None,
);
let fs_bytes = shader::glsl_to_spirv(
include_str!("shadow.frag"),
shader::ShaderStage::Fragment,
None,
);
let vs_module = render_graph.device.create_shader_module(&vs_bytes);
let fs_module = render_graph.device.create_shader_module(&fs_bytes);

View file

@ -95,7 +95,8 @@ impl UiPipeline {
impl Pipeline for UiPipeline {
fn initialize(&mut self, render_graph: &mut RenderGraphData, world: &mut World) {
let vs_bytes = shader::glsl_to_spirv(include_str!("ui.vert"), shader::ShaderStage::Vertex, None);
let vs_bytes =
shader::glsl_to_spirv(include_str!("ui.vert"), shader::ShaderStage::Vertex, None);
let fs_bytes =
shader::glsl_to_spirv(include_str!("ui.frag"), shader::ShaderStage::Fragment, None);

View file

@ -2,7 +2,7 @@ use crate::{
asset::{AssetStorage, Handle, Mesh},
legion::prelude::*,
render::{
render_graph_2::{resource_name, RenderPass, ShaderUniforms},
render_graph_2::{resource_name, RenderPass, Renderable, ShaderUniforms},
Instanced,
},
};
@ -13,9 +13,13 @@ pub fn mesh_draw_target(world: &World, render_pass: &mut dyn RenderPass) {
let mut mesh_storage = world.resources.get_mut::<AssetStorage<Mesh>>().unwrap();
let mut current_mesh_id = None;
let mut current_mesh_index_length = 0;
let mesh_query =
<(Read<ShaderUniforms>, Read<Handle<Mesh>>)>::query().filter(!component::<Instanced>());
for (entity, (_shader_uniforms, mesh)) in mesh_query.iter_entities(world) {
let mesh_query = <(Read<ShaderUniforms>, Read<Handle<Mesh>>, Read<Renderable>)>::query()
.filter(!component::<Instanced>());
for (entity, (_shader_uniforms, mesh, renderable)) in mesh_query.iter_entities(world) {
if !renderable.is_visible {
continue;
}
let mut should_load_mesh = current_mesh_id == None;
if let Some(current) = current_mesh_id {
should_load_mesh = current != mesh.id;

View file

@ -6,24 +6,24 @@ mod pipeline;
mod pipeline_layout;
pub mod pipelines;
mod render_graph;
mod renderable;
mod renderer;
pub mod renderers;
mod resource;
pub mod resource_name;
pub mod resource_provider;
pub mod resource_providers;
mod uniforms;
mod uniform;
mod renderable;
mod uniforms;
pub use draw_target::*;
pub use pass::*;
pub use pipeline::*;
pub use pipeline_layout::*;
pub use render_graph::*;
pub use renderable::*;
pub use renderer::*;
pub use resource::*;
pub use resource_provider::*;
pub use uniforms::*;
pub use uniform::*;
pub use renderable::*;
pub use uniforms::*;

View file

@ -1,7 +1,7 @@
use crate::{
legion::prelude::World,
render::render_graph_2::{
resource::DynamicUniformBufferInfo, AsUniforms, Renderer, ResourceProvider,
resource::DynamicUniformBufferInfo, AsUniforms, Renderable, Renderer, ResourceProvider,
},
};
use legion::prelude::*;
@ -13,7 +13,6 @@ where
{
_marker: PhantomData<T>,
uniform_buffer_info_names: Vec<String>,
// dynamic_uniform_buffer_infos: HashMap<String, DynamicUniformBufferInfo>,
}
impl<T> UniformResourceProvider<T>
@ -22,7 +21,6 @@ where
{
pub fn new() -> Self {
UniformResourceProvider {
// dynamic_uniform_buffer_infos: HashMap::new(),
uniform_buffer_info_names: Vec::new(),
_marker: PhantomData,
}
@ -36,7 +34,7 @@ where
fn initialize(&mut self, _renderer: &mut dyn Renderer, _world: &mut World) {}
fn update(&mut self, renderer: &mut dyn Renderer, world: &mut World) {
let query = <Read<T>>::query();
let query = <(Read<T>, Read<Renderable>)>::query();
// retrieve all uniforms buffers that aren't aleady set. these are "dynamic" uniforms, which are set by the user in ShaderUniforms
// TODO: this breaks down in multiple ways:
// (SOLVED 1) resource_info will be set after the first run so this won't update.
@ -52,7 +50,7 @@ where
let mut sizes = Vec::new();
let mut counts = Vec::new();
for uniforms in query.iter(world) {
for (uniforms, _renderable) in query.iter(world) {
let uniform_layouts = uniforms.get_uniform_layouts();
for (i, uniform_info) in uniforms.get_uniform_infos().iter().enumerate() {
// only add the first time a uniform info is processed
@ -117,7 +115,7 @@ where
let alignment = wgpu::BIND_BUFFER_ALIGNMENT as usize;
let mut offset = 0usize;
let info = renderer.get_dynamic_uniform_buffer_info_mut(name).unwrap();
for (i, (entity, _uniforms)) in query.iter_entities(world).enumerate() {
for (i, (entity, _)) in query.iter_entities(world).enumerate() {
// TODO: check if index has changed. if it has, then entity should be updated
// TODO: only mem-map entities if their data has changed
// PERF: These hashmap inserts are pretty expensive (10 fps for 10000 entities)
@ -135,7 +133,7 @@ where
&mut |mapped| {
let alignment = wgpu::BIND_BUFFER_ALIGNMENT as usize;
let mut offset = 0usize;
for uniforms in query.iter(world) {
for (uniforms, _renderable) in query.iter(world) {
// TODO: check if index has changed. if it has, then entity should be updated
// TODO: only mem-map entities if their data has changed
// TODO: try getting ref first

View file

@ -44,7 +44,6 @@ pub trait AsUniforms {
fn get_shader_defs(&self) -> Option<Vec<String>>;
// TODO: support zero-copy uniforms
// fn get_uniform_bytes_ref(&self, name: &str) -> Option<&[u8]>;
}
pub trait ShaderDefSuffixProvider {

View file

@ -1,8 +1,6 @@
use crate::{
render::render_graph_2::{
use crate::render::render_graph_2::{
uniform::{AsUniforms, UniformInfo},
BindType, UniformPropertyType,
},
};
use zerocopy::AsBytes;

View file

@ -1,5 +1,5 @@
mod standard_material;
mod local_to_world;
mod standard_material;
pub use standard_material::*;
pub use local_to_world::*;
pub use standard_material::*;

View file

@ -3,7 +3,7 @@ use crate::{
math::Vec4,
render::render_graph_2::{
uniform::{AsUniforms, GetBytes, UniformInfo},
BindType, UniformPropertyType, ShaderDefSuffixProvider
BindType, ShaderDefSuffixProvider, UniformPropertyType,
},
};

View file

@ -17,7 +17,11 @@ impl Into<shaderc::ShaderKind> for ShaderStage {
}
}
pub fn glsl_to_spirv(glsl_source: &str, stage: ShaderStage, shader_defs: Option<&Vec<String>>) -> Vec<u32> {
pub fn glsl_to_spirv(
glsl_source: &str,
stage: ShaderStage,
shader_defs: Option<&Vec<String>>,
) -> Vec<u32> {
let shader_kind: shaderc::ShaderKind = stage.into();
let mut compiler = shaderc::Compiler::new().unwrap();
let mut options = shaderc::CompileOptions::new().unwrap();
@ -64,7 +68,9 @@ impl Shader {
pub fn get_spirv(&self) -> Vec<u32> {
match self.source {
ShaderSource::Spirv(ref bytes) => bytes.clone(),
ShaderSource::Glsl(ref source) => glsl_to_spirv(&source, self.stage, self.macros.as_ref()),
ShaderSource::Glsl(ref source) => {
glsl_to_spirv(&source, self.stage, self.macros.as_ref())
}
}
}