From 1d8afb58f0a6ec0262b96021a6e2c30fecf27a67 Mon Sep 17 00:00:00 2001 From: polymonster Date: Fri, 17 Oct 2025 15:25:47 +0100 Subject: [PATCH 1/2] - wip --- plugins/ecs_examples/src/bindless_material.rs | 2 +- plugins/ecs_examples/src/bindless_texture.rs | 2 +- plugins/ecs_examples/src/blend_states.rs | 2 +- plugins/ecs_examples/src/cubemap.rs | 2 +- .../ecs_examples/src/directional_lights.rs | 2 +- plugins/ecs_examples/src/draw.rs | 2 +- .../src/draw_cbuffer_instanced.rs | 2 +- plugins/ecs_examples/src/draw_indexed.rs | 2 +- plugins/ecs_examples/src/draw_indirect.rs | 2 +- .../ecs_examples/src/draw_push_constants.rs | 2 +- .../src/draw_vertex_buffer_instanced.rs | 2 +- plugins/ecs_examples/src/dynamic_cubemap.rs | 2 +- plugins/ecs_examples/src/error_tests.rs | 2 +- plugins/ecs_examples/src/examples.rs | 2 +- plugins/ecs_examples/src/generate_mip_maps.rs | 2 +- .../ecs_examples/src/geometry_primitives.rs | 2 +- .../ecs_examples/src/gpu_frustum_culling.rs | 2 +- plugins/ecs_examples/src/lib.rs | 31 ++++++++++--------- .../src/multiple_render_targets.rs | 2 +- plugins/ecs_examples/src/omni_shadow_map.rs | 2 +- plugins/ecs_examples/src/pbr.rs | 2 +- plugins/ecs_examples/src/point_lights.rs | 2 +- plugins/ecs_examples/src/raster_states.rs | 2 +- plugins/ecs_examples/src/raytraced_shadows.rs | 2 +- .../ecs_examples/src/raytracing_pipeline.rs | 2 +- .../ecs_examples/src/read_write_texture.rs | 2 +- plugins/ecs_examples/src/shadow_map.rs | 2 +- plugins/ecs_examples/src/spot_lights.rs | 2 +- .../src/tangent_space_normal_maps.rs | 2 +- plugins/ecs_examples/src/texture2d_array.rs | 2 +- plugins/ecs_examples/src/texture3d.rs | 2 +- plugins/export_macros/src/lib.rs | 18 ++++++----- 32 files changed, 58 insertions(+), 51 deletions(-) diff --git a/plugins/ecs_examples/src/bindless_material.rs b/plugins/ecs_examples/src/bindless_material.rs index 04b35f2d..9aafb687 100644 --- a/plugins/ecs_examples/src/bindless_material.rs +++ b/plugins/ecs_examples/src/bindless_material.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] /// /// Bindless Material diff --git a/plugins/ecs_examples/src/bindless_texture.rs b/plugins/ecs_examples/src/bindless_texture.rs index 02bf8084..6964af5d 100644 --- a/plugins/ecs_examples/src/bindless_texture.rs +++ b/plugins/ecs_examples/src/bindless_texture.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] /// /// Bindless Texture diff --git a/plugins/ecs_examples/src/blend_states.rs b/plugins/ecs_examples/src/blend_states.rs index 981a22e3..cf1c4215 100644 --- a/plugins/ecs_examples/src/blend_states.rs +++ b/plugins/ecs_examples/src/blend_states.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] /// /// Blend States diff --git a/plugins/ecs_examples/src/cubemap.rs b/plugins/ecs_examples/src/cubemap.rs index 8a76c97b..68221455 100644 --- a/plugins/ecs_examples/src/cubemap.rs +++ b/plugins/ecs_examples/src/cubemap.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] /// /// Cubemap diff --git a/plugins/ecs_examples/src/directional_lights.rs b/plugins/ecs_examples/src/directional_lights.rs index 3270e70c..4298971e 100644 --- a/plugins/ecs_examples/src/directional_lights.rs +++ b/plugins/ecs_examples/src/directional_lights.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] use crate::prelude::*; diff --git a/plugins/ecs_examples/src/draw.rs b/plugins/ecs_examples/src/draw.rs index ef9937cd..6c568714 100644 --- a/plugins/ecs_examples/src/draw.rs +++ b/plugins/ecs_examples/src/draw.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] /// /// Draw diff --git a/plugins/ecs_examples/src/draw_cbuffer_instanced.rs b/plugins/ecs_examples/src/draw_cbuffer_instanced.rs index 4a07da83..7a116b2a 100644 --- a/plugins/ecs_examples/src/draw_cbuffer_instanced.rs +++ b/plugins/ecs_examples/src/draw_cbuffer_instanced.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] /// /// Draw cbuffer Instanced diff --git a/plugins/ecs_examples/src/draw_indexed.rs b/plugins/ecs_examples/src/draw_indexed.rs index 1120438f..3ef7cb0e 100644 --- a/plugins/ecs_examples/src/draw_indexed.rs +++ b/plugins/ecs_examples/src/draw_indexed.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] /// /// Draw Indexed diff --git a/plugins/ecs_examples/src/draw_indirect.rs b/plugins/ecs_examples/src/draw_indirect.rs index 1e8fd993..264bfaf3 100644 --- a/plugins/ecs_examples/src/draw_indirect.rs +++ b/plugins/ecs_examples/src/draw_indirect.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] /// /// Draw Indirect diff --git a/plugins/ecs_examples/src/draw_push_constants.rs b/plugins/ecs_examples/src/draw_push_constants.rs index edc76a57..b17a90ac 100644 --- a/plugins/ecs_examples/src/draw_push_constants.rs +++ b/plugins/ecs_examples/src/draw_push_constants.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] /// /// Draw Push Constants diff --git a/plugins/ecs_examples/src/draw_vertex_buffer_instanced.rs b/plugins/ecs_examples/src/draw_vertex_buffer_instanced.rs index 81e18291..1641d888 100644 --- a/plugins/ecs_examples/src/draw_vertex_buffer_instanced.rs +++ b/plugins/ecs_examples/src/draw_vertex_buffer_instanced.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] /// /// Draw Vertex Buffer Instanced diff --git a/plugins/ecs_examples/src/dynamic_cubemap.rs b/plugins/ecs_examples/src/dynamic_cubemap.rs index f7d5431b..badd0e8c 100644 --- a/plugins/ecs_examples/src/dynamic_cubemap.rs +++ b/plugins/ecs_examples/src/dynamic_cubemap.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] /// /// Dynamic Cubemap diff --git a/plugins/ecs_examples/src/error_tests.rs b/plugins/ecs_examples/src/error_tests.rs index 96b8205a..46e8cf13 100644 --- a/plugins/ecs_examples/src/error_tests.rs +++ b/plugins/ecs_examples/src/error_tests.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] use crate::prelude::*; diff --git a/plugins/ecs_examples/src/examples.rs b/plugins/ecs_examples/src/examples.rs index b5a08873..55c243a4 100644 --- a/plugins/ecs_examples/src/examples.rs +++ b/plugins/ecs_examples/src/examples.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] use crate::prelude::*; diff --git a/plugins/ecs_examples/src/generate_mip_maps.rs b/plugins/ecs_examples/src/generate_mip_maps.rs index c812c6f8..f85a6c58 100644 --- a/plugins/ecs_examples/src/generate_mip_maps.rs +++ b/plugins/ecs_examples/src/generate_mip_maps.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] /// /// Generate Mip Maps diff --git a/plugins/ecs_examples/src/geometry_primitives.rs b/plugins/ecs_examples/src/geometry_primitives.rs index 5a3f3e21..c45d162a 100644 --- a/plugins/ecs_examples/src/geometry_primitives.rs +++ b/plugins/ecs_examples/src/geometry_primitives.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] /// /// Geometry Primitives diff --git a/plugins/ecs_examples/src/gpu_frustum_culling.rs b/plugins/ecs_examples/src/gpu_frustum_culling.rs index d5b74e17..fa267d5e 100644 --- a/plugins/ecs_examples/src/gpu_frustum_culling.rs +++ b/plugins/ecs_examples/src/gpu_frustum_culling.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] use crate::prelude::*; diff --git a/plugins/ecs_examples/src/lib.rs b/plugins/ecs_examples/src/lib.rs index 9dfefbec..5c8cdfef 100644 --- a/plugins/ecs_examples/src/lib.rs +++ b/plugins/ecs_examples/src/lib.rs @@ -243,6 +243,7 @@ pub fn batch_bindless_draw_data( pub fn render_meshes_bindless( pmfx: &Res, view: &pmfx::View, + cmd_buf: &mut ::CmdBuf, queries: ( Query<(&InstanceBuffer, &MeshComponent)>, Query<(&MeshComponent, &WorldMatrix), Without> @@ -256,20 +257,20 @@ pub fn render_meshes_bindless( let camera = pmfx.get_camera_constants(&view.camera)?; let pipeline = pmfx.get_render_pipeline_for_format(&view.view_pipeline, fmt)?; - view.cmd_buf.set_render_pipeline(&pipeline); + cmd_buf.set_render_pipeline(&pipeline); // bind view push constants let slot = pipeline.get_pipeline_slot(0, 0, gfx::DescriptorType::PushConstants); if let Some(slot) = slot { - view.cmd_buf.push_render_constants(slot.index, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); - view.cmd_buf.push_render_constants(slot.index, 4, 16, gfx::as_u8_slice(&camera.view_position)); + cmd_buf.push_render_constants(slot.index, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); + cmd_buf.push_render_constants(slot.index, 4, 16, gfx::as_u8_slice(&camera.view_position)); } // bind the world buffer info let world_buffer_info = pmfx.get_world_buffer_info(); let slot = pipeline.get_pipeline_slot(2, 0, gfx::DescriptorType::PushConstants); if let Some(slot) = slot { - view.cmd_buf.push_render_constants( + cmd_buf.push_render_constants( slot.index, gfx::num_32bit_constants(&world_buffer_info), 0, gfx::as_u8_slice(&world_buffer_info)); } @@ -278,7 +279,7 @@ pub fn render_meshes_bindless( if let Some(slot) = using_slot { for i in 0..view.use_indices.len() { let num_constants = gfx::num_32bit_constants(&view.use_indices[i]); - view.cmd_buf.push_compute_constants( + cmd_buf.push_compute_constants( 0, num_constants, i as u32 * num_constants, @@ -288,14 +289,14 @@ pub fn render_meshes_bindless( } // bind the shader resource heap - view.cmd_buf.set_heap(pipeline, &pmfx.shader_heap); + cmd_buf.set_heap(pipeline, &pmfx.shader_heap); // instance batch draw calls for (instance_batch, mesh) in &instance_draw_query { - view.cmd_buf.set_index_buffer(&mesh.0.ib); - view.cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); - view.cmd_buf.set_vertex_buffer(&instance_batch.buffer, 1); - view.cmd_buf.draw_indexed_instanced(mesh.0.num_indices, instance_batch.instance_count, 0, 0, 0); + cmd_buf.set_index_buffer(&mesh.0.ib); + cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); + cmd_buf.set_vertex_buffer(&instance_batch.buffer, 1); + cmd_buf.draw_indexed_instanced(mesh.0.num_indices, instance_batch.instance_count, 0, 0, 0); } // single draw calls @@ -303,16 +304,17 @@ pub fn render_meshes_bindless( // set the world matrix push constants let slot = pipeline.get_pipeline_slot(1, 0, gfx::DescriptorType::PushConstants); if let Some(slot) = slot { - view.cmd_buf.push_render_constants(slot.index, 12, 0, &world_matrix.0); + cmd_buf.push_render_constants(slot.index, 12, 0, &world_matrix.0); } - view.cmd_buf.set_index_buffer(&mesh.0.ib); - view.cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); - view.cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); + cmd_buf.set_index_buffer(&mesh.0.ib); + cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); + cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); } Ok(()) } +/* ///Renders all meshes generically with a single pipeline which and be specified in the .pmfx view #[no_mangle] #[export_render_fn] @@ -693,6 +695,7 @@ pub fn get_demos_ecs_examples() -> Vec { "raytraced_shadows" ] } +*/ pub mod prelude { #[doc(hidden)] diff --git a/plugins/ecs_examples/src/multiple_render_targets.rs b/plugins/ecs_examples/src/multiple_render_targets.rs index 07f0df8a..44150a63 100644 --- a/plugins/ecs_examples/src/multiple_render_targets.rs +++ b/plugins/ecs_examples/src/multiple_render_targets.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] /// /// Multiple Render Targets diff --git a/plugins/ecs_examples/src/omni_shadow_map.rs b/plugins/ecs_examples/src/omni_shadow_map.rs index 393ea855..81016e7a 100644 --- a/plugins/ecs_examples/src/omni_shadow_map.rs +++ b/plugins/ecs_examples/src/omni_shadow_map.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] /// /// Omni Shadow Map diff --git a/plugins/ecs_examples/src/pbr.rs b/plugins/ecs_examples/src/pbr.rs index a890554e..e7ccc577 100644 --- a/plugins/ecs_examples/src/pbr.rs +++ b/plugins/ecs_examples/src/pbr.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] /// /// Cubemap diff --git a/plugins/ecs_examples/src/point_lights.rs b/plugins/ecs_examples/src/point_lights.rs index 6c6031f1..40d66b42 100644 --- a/plugins/ecs_examples/src/point_lights.rs +++ b/plugins/ecs_examples/src/point_lights.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] use crate::prelude::*; diff --git a/plugins/ecs_examples/src/raster_states.rs b/plugins/ecs_examples/src/raster_states.rs index 2f144c9d..641fa662 100644 --- a/plugins/ecs_examples/src/raster_states.rs +++ b/plugins/ecs_examples/src/raster_states.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] /// /// Raster States diff --git a/plugins/ecs_examples/src/raytraced_shadows.rs b/plugins/ecs_examples/src/raytraced_shadows.rs index ecd297e1..acf29158 100644 --- a/plugins/ecs_examples/src/raytraced_shadows.rs +++ b/plugins/ecs_examples/src/raytraced_shadows.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] /// /// Raytraced Shadows diff --git a/plugins/ecs_examples/src/raytracing_pipeline.rs b/plugins/ecs_examples/src/raytracing_pipeline.rs index a90979bb..0bc36508 100644 --- a/plugins/ecs_examples/src/raytracing_pipeline.rs +++ b/plugins/ecs_examples/src/raytracing_pipeline.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] use hotline_rs::gfx::{CpuAccessFlags, RaytracingTLAS}; diff --git a/plugins/ecs_examples/src/read_write_texture.rs b/plugins/ecs_examples/src/read_write_texture.rs index 2c194b76..391d5134 100644 --- a/plugins/ecs_examples/src/read_write_texture.rs +++ b/plugins/ecs_examples/src/read_write_texture.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] /// /// Read-Write Texture diff --git a/plugins/ecs_examples/src/shadow_map.rs b/plugins/ecs_examples/src/shadow_map.rs index 57948d2a..586b6d95 100644 --- a/plugins/ecs_examples/src/shadow_map.rs +++ b/plugins/ecs_examples/src/shadow_map.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] /// /// Shadow Map diff --git a/plugins/ecs_examples/src/spot_lights.rs b/plugins/ecs_examples/src/spot_lights.rs index 4180f816..099f8150 100644 --- a/plugins/ecs_examples/src/spot_lights.rs +++ b/plugins/ecs_examples/src/spot_lights.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] // // Spot Lights diff --git a/plugins/ecs_examples/src/tangent_space_normal_maps.rs b/plugins/ecs_examples/src/tangent_space_normal_maps.rs index 23978f0d..87bd6758 100644 --- a/plugins/ecs_examples/src/tangent_space_normal_maps.rs +++ b/plugins/ecs_examples/src/tangent_space_normal_maps.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] /// /// Tangent Space Normal Maps diff --git a/plugins/ecs_examples/src/texture2d_array.rs b/plugins/ecs_examples/src/texture2d_array.rs index d48cdb6d..7f2ad41a 100644 --- a/plugins/ecs_examples/src/texture2d_array.rs +++ b/plugins/ecs_examples/src/texture2d_array.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] /// /// Texture2D Array diff --git a/plugins/ecs_examples/src/texture3d.rs b/plugins/ecs_examples/src/texture3d.rs index 01291dc4..b6b08cdf 100644 --- a/plugins/ecs_examples/src/texture3d.rs +++ b/plugins/ecs_examples/src/texture3d.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "windows")] +#![cfg(target_os = "macos")] /// /// Texture3D diff --git a/plugins/export_macros/src/lib.rs b/plugins/export_macros/src/lib.rs index 100f0d07..c25bd91e 100644 --- a/plugins/export_macros/src/lib.rs +++ b/plugins/export_macros/src/lib.rs @@ -150,7 +150,7 @@ pub fn export_render_fn(attr: TokenStream, item: TokenStream) -> TokenStream { let parsed = parse_fn(&item); // emit code to move function args into closure and pass them to function - let (moves, pass) = emit_moves_and_pass_args(&parsed, &vec!["pmfx :: View"]); + let (moves, pass) = emit_moves_and_pass_args(&parsed, &vec!["pmfx :: View", "< gfx_platform :: Device as Device > :: CmdBuf"]); let order = emit_update_order(attr, "SystemSets :: Render"); let render_closure = quote! { @@ -161,18 +161,20 @@ pub fn export_render_fn(attr: TokenStream, item: TokenStream) -> TokenStream { let err = match view { Ok(v) => { let mut view = v.lock().unwrap(); + + let mut cmd_buf = view.cmd_buf.clone(); let col = view.colour_hash; - view.cmd_buf.begin_event(col, &view_name); + cmd_buf.begin_event(col, &view_name); - view.cmd_buf.begin_render_pass(&view.pass); - view.cmd_buf.set_viewport(&view.viewport); - view.cmd_buf.set_scissor_rect(&view.scissor_rect); + cmd_buf.begin_render_pass(&view.pass); + cmd_buf.set_viewport(&view.viewport); + cmd_buf.set_scissor_rect(&view.scissor_rect); let result = fn_name(fn_args); - view.cmd_buf.end_render_pass(); - view.cmd_buf.end_event(); + cmd_buf.end_render_pass(); + cmd_buf.end_event(); result } Err(v) => { @@ -197,6 +199,8 @@ pub fn export_render_fn(attr: TokenStream, item: TokenStream) -> TokenStream { .replace("fn_attr", &order) .to_string(); + println!("{}", export_fn); + // output the original item plus the generated export function let export_tokens : TokenStream = export_fn.parse().unwrap(); let input = parse_macro_input!(item as ItemFn); From 76ec1155f1cbd91d08fbee4d3e0e6b864c04c5c9 Mon Sep 17 00:00:00 2001 From: polymonster Date: Fri, 17 Oct 2025 16:44:06 +0100 Subject: [PATCH 2/2] - fixup ecs render and compute fn mutability issues with cmdbuf --- plugins/ecs/src/lib.rs | 2 - plugins/ecs_examples/src/bindless_material.rs | 2 +- plugins/ecs_examples/src/bindless_texture.rs | 19 ++-- plugins/ecs_examples/src/blend_states.rs | 19 ++-- plugins/ecs_examples/src/cubemap.rs | 19 ++-- .../ecs_examples/src/directional_lights.rs | 2 +- plugins/ecs_examples/src/draw.rs | 11 ++- .../src/draw_cbuffer_instanced.rs | 15 +-- plugins/ecs_examples/src/draw_indexed.rs | 13 +-- plugins/ecs_examples/src/draw_indirect.rs | 15 +-- .../ecs_examples/src/draw_push_constants.rs | 2 +- .../src/draw_vertex_buffer_instanced.rs | 17 ++-- plugins/ecs_examples/src/dynamic_cubemap.rs | 40 ++++---- plugins/ecs_examples/src/error_tests.rs | 2 +- plugins/ecs_examples/src/examples.rs | 2 +- plugins/ecs_examples/src/generate_mip_maps.rs | 2 +- .../ecs_examples/src/geometry_primitives.rs | 2 +- .../ecs_examples/src/gpu_frustum_culling.rs | 32 ++++--- plugins/ecs_examples/src/lib.rs | 96 ++++++++++--------- .../src/multiple_render_targets.rs | 2 +- plugins/ecs_examples/src/omni_shadow_map.rs | 6 +- plugins/ecs_examples/src/pbr.rs | 23 ++--- plugins/ecs_examples/src/point_lights.rs | 2 +- plugins/ecs_examples/src/raster_states.rs | 17 ++-- plugins/ecs_examples/src/raytraced_shadows.rs | 2 +- .../ecs_examples/src/raytracing_pipeline.rs | 22 ++--- .../ecs_examples/src/read_write_texture.rs | 2 +- plugins/ecs_examples/src/shadow_map.rs | 2 +- plugins/ecs_examples/src/spot_lights.rs | 2 +- .../src/tangent_space_normal_maps.rs | 19 ++-- plugins/ecs_examples/src/texture2d_array.rs | 19 ++-- plugins/ecs_examples/src/texture3d.rs | 21 ++-- plugins/export_macros/src/lib.rs | 19 ++-- src/gfx/d3d12.rs | 2 +- 34 files changed, 245 insertions(+), 227 deletions(-) diff --git a/plugins/ecs/src/lib.rs b/plugins/ecs/src/lib.rs index eda0017c..d2c3d061 100644 --- a/plugins/ecs/src/lib.rs +++ b/plugins/ecs/src/lib.rs @@ -6,8 +6,6 @@ use hotline_rs::prelude::*; use maths_rs::prelude::*; use bevy_ecs::prelude::*; - -use bevy_ecs::schedule::SystemConfig; use bevy_ecs::schedule::SystemConfigs; use std::collections::HashMap; diff --git a/plugins/ecs_examples/src/bindless_material.rs b/plugins/ecs_examples/src/bindless_material.rs index 9aafb687..04b35f2d 100644 --- a/plugins/ecs_examples/src/bindless_material.rs +++ b/plugins/ecs_examples/src/bindless_material.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] /// /// Bindless Material diff --git a/plugins/ecs_examples/src/bindless_texture.rs b/plugins/ecs_examples/src/bindless_texture.rs index 6964af5d..9d2b2b5f 100644 --- a/plugins/ecs_examples/src/bindless_texture.rs +++ b/plugins/ecs_examples/src/bindless_texture.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] /// /// Bindless Texture @@ -152,6 +152,7 @@ pub fn setup_bindless_texture( pub fn draw_meshes_bindless_texture( pmfx: &Res, view: &pmfx::View, + cmd_buf: &mut ::CmdBuf, mesh_draw_query: Query<(&WorldMatrix, &MeshComponent, &TextureInstance)>) -> Result<(), hotline_rs::Error> { let pmfx = &pmfx; @@ -159,18 +160,18 @@ pub fn draw_meshes_bindless_texture( let pipeline = pmfx.get_render_pipeline_for_format(&view.view_pipeline, fmt)?; let camera = pmfx.get_camera_constants(&view.camera)?; - view.cmd_buf.set_render_pipeline(pipeline); - view.cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); + cmd_buf.set_render_pipeline(pipeline); + cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); - view.cmd_buf.set_heap(pipeline, &pmfx.shader_heap); + cmd_buf.set_heap(pipeline, &pmfx.shader_heap); for (world_matrix, mesh, texture) in &mesh_draw_query { - view.cmd_buf.push_render_constants(1, 12, 0, &world_matrix.0); - view.cmd_buf.push_render_constants(1, 1, 16, gfx::as_u8_slice(&texture.0)); + cmd_buf.push_render_constants(1, 12, 0, &world_matrix.0); + cmd_buf.push_render_constants(1, 1, 16, gfx::as_u8_slice(&texture.0)); - view.cmd_buf.set_index_buffer(&mesh.0.ib); - view.cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); - view.cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); + cmd_buf.set_index_buffer(&mesh.0.ib); + cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); + cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); } Ok(()) diff --git a/plugins/ecs_examples/src/blend_states.rs b/plugins/ecs_examples/src/blend_states.rs index cf1c4215..0a93e115 100644 --- a/plugins/ecs_examples/src/blend_states.rs +++ b/plugins/ecs_examples/src/blend_states.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] /// /// Blend States @@ -107,6 +107,7 @@ pub fn setup_blend_states( pub fn render_meshes_pipeline_coloured( pmfx: &Res, view: &pmfx::View, + cmd_buf: &mut ::CmdBuf, mesh_draw_query: Query<(&WorldMatrix, &MeshComponent, &PipelineComponent, &Colour)>) -> Result<(), hotline_rs::Error> { let pmfx = &pmfx; @@ -116,14 +117,14 @@ pub fn render_meshes_pipeline_coloured( for (world_matrix, mesh, pipeline, colour) in &mesh_draw_query { // set pipeline per mesh let pipeline = pmfx.get_render_pipeline_for_format(&pipeline.0, fmt)?; - view.cmd_buf.set_render_pipeline(pipeline); - view.cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); - view.cmd_buf.push_render_constants(1, 12, 0, &world_matrix.0); - view.cmd_buf.push_render_constants(1, 4, 12, &colour.0); - - view.cmd_buf.set_index_buffer(&mesh.0.ib); - view.cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); - view.cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); + cmd_buf.set_render_pipeline(pipeline); + cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); + cmd_buf.push_render_constants(1, 12, 0, &world_matrix.0); + cmd_buf.push_render_constants(1, 4, 12, &colour.0); + + cmd_buf.set_index_buffer(&mesh.0.ib); + cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); + cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); } Ok(()) diff --git a/plugins/ecs_examples/src/cubemap.rs b/plugins/ecs_examples/src/cubemap.rs index 68221455..084a0cc7 100644 --- a/plugins/ecs_examples/src/cubemap.rs +++ b/plugins/ecs_examples/src/cubemap.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] /// /// Cubemap @@ -70,25 +70,26 @@ pub fn setup_cubemap( pub fn render_meshes_cubemap( pmfx: &Res, view: &pmfx::View, + cmd_buf: &mut ::CmdBuf, mesh_draw_query: Query<(&WorldMatrix, &MeshComponent, &TextureInstance)>) -> Result<(), hotline_rs::Error> { let fmt = view.pass.get_format_hash(); let pipeline = pmfx.get_render_pipeline_for_format(&view.view_pipeline, fmt)?; let camera = pmfx.get_camera_constants(&view.camera)?; - view.cmd_buf.set_render_pipeline(pipeline); - view.cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); + cmd_buf.set_render_pipeline(pipeline); + cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); - view.cmd_buf.set_heap(pipeline, &pmfx.shader_heap); + cmd_buf.set_heap(pipeline, &pmfx.shader_heap); let mut mip = 0; for (world_matrix, mesh, cubemap) in &mesh_draw_query { - view.cmd_buf.push_render_constants(1, 12, 0, &world_matrix.0); - view.cmd_buf.push_render_constants(1, 2, 16, gfx::as_u8_slice(&[cubemap.0, mip, 0, 0])); + cmd_buf.push_render_constants(1, 12, 0, &world_matrix.0); + cmd_buf.push_render_constants(1, 2, 16, gfx::as_u8_slice(&[cubemap.0, mip, 0, 0])); - view.cmd_buf.set_index_buffer(&mesh.0.ib); - view.cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); - view.cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); + cmd_buf.set_index_buffer(&mesh.0.ib); + cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); + cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); mip += 1; } diff --git a/plugins/ecs_examples/src/directional_lights.rs b/plugins/ecs_examples/src/directional_lights.rs index 4298971e..3270e70c 100644 --- a/plugins/ecs_examples/src/directional_lights.rs +++ b/plugins/ecs_examples/src/directional_lights.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] use crate::prelude::*; diff --git a/plugins/ecs_examples/src/draw.rs b/plugins/ecs_examples/src/draw.rs index 6c568714..ff0c2a99 100644 --- a/plugins/ecs_examples/src/draw.rs +++ b/plugins/ecs_examples/src/draw.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] /// /// Draw @@ -49,18 +49,19 @@ pub fn setup_draw( pub fn draw_meshes( pmfx: &Res, view: &pmfx::View, + cmd_buf: &mut ::CmdBuf, mesh_draw_query: Query<(&WorldMatrix, &MeshComponent)>) -> Result<(), hotline_rs::Error> { let fmt = view.pass.get_format_hash(); let pipeline = pmfx.get_render_pipeline_for_format(&view.view_pipeline, fmt)?; let camera = pmfx.get_camera_constants(&view.camera)?; - view.cmd_buf.set_render_pipeline(pipeline); - view.cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); + cmd_buf.set_render_pipeline(pipeline); + cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); for (_, mesh) in &mesh_draw_query { - view.cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); - view.cmd_buf.draw_instanced(3, 1, 0, 0); + cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); + cmd_buf.draw_instanced(3, 1, 0, 0); } Ok(()) diff --git a/plugins/ecs_examples/src/draw_cbuffer_instanced.rs b/plugins/ecs_examples/src/draw_cbuffer_instanced.rs index 7a116b2a..dfd3335e 100644 --- a/plugins/ecs_examples/src/draw_cbuffer_instanced.rs +++ b/plugins/ecs_examples/src/draw_cbuffer_instanced.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] /// /// Draw cbuffer Instanced @@ -97,6 +97,7 @@ pub fn setup_draw_cbuffer_instanced( pub fn draw_meshes_cbuffer_instanced( pmfx: &Res, view: &pmfx::View, + cmd_buf: &mut ::CmdBuf, instance_draw_query: Query<(&InstanceBuffer, &MeshComponent, &PipelineComponent)> ) -> Result<(), hotline_rs::Error> { @@ -107,13 +108,13 @@ pub fn draw_meshes_cbuffer_instanced( for (instance_batch, mesh, pipeline) in &instance_draw_query { // set pipeline per batch let pipeline = pmfx.get_render_pipeline_for_format(&pipeline.0, fmt)?; - view.cmd_buf.set_render_pipeline(pipeline); - view.cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); + cmd_buf.set_render_pipeline(pipeline); + cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); // bind the constant buffer (cbv) on the slot for b1, space0 specified in the shader let pipeline_slot = pipeline.get_pipeline_slot(1, 0, gfx::DescriptorType::ConstantBuffer); if let Some(pipeline_slot) = pipeline_slot { - view.cmd_buf.set_binding( + cmd_buf.set_binding( pipeline, instance_batch.heap.as_ref().unwrap(), pipeline_slot.index, @@ -122,9 +123,9 @@ pub fn draw_meshes_cbuffer_instanced( } // bind vb, ib and draw instanced - view.cmd_buf.set_index_buffer(&mesh.0.ib); - view.cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); - view.cmd_buf.draw_indexed_instanced(mesh.0.num_indices, instance_batch.instance_count, 0, 0, 0); + cmd_buf.set_index_buffer(&mesh.0.ib); + cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); + cmd_buf.draw_indexed_instanced(mesh.0.num_indices, instance_batch.instance_count, 0, 0, 0); } Ok(()) diff --git a/plugins/ecs_examples/src/draw_indexed.rs b/plugins/ecs_examples/src/draw_indexed.rs index 3ef7cb0e..33b55d6b 100644 --- a/plugins/ecs_examples/src/draw_indexed.rs +++ b/plugins/ecs_examples/src/draw_indexed.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] /// /// Draw Indexed @@ -47,19 +47,20 @@ pub fn setup_draw_indexed( pub fn draw_meshes_indexed( pmfx: &Res, view: &pmfx::View, + cmd_buf: &mut ::CmdBuf, mesh_draw_query: Query<(&WorldMatrix, &MeshComponent)>) -> Result<(), hotline_rs::Error> { let fmt = view.pass.get_format_hash(); let pipeline = pmfx.get_render_pipeline_for_format(&view.view_pipeline, fmt)?; let camera = pmfx.get_camera_constants(&view.camera)?; - view.cmd_buf.set_render_pipeline(pipeline); - view.cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); + cmd_buf.set_render_pipeline(pipeline); + cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); for (_, mesh) in &mesh_draw_query { - view.cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); - view.cmd_buf.set_index_buffer(&mesh.0.ib); - view.cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); + cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); + cmd_buf.set_index_buffer(&mesh.0.ib); + cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); } Ok(()) diff --git a/plugins/ecs_examples/src/draw_indirect.rs b/plugins/ecs_examples/src/draw_indirect.rs index 264bfaf3..dd6761b8 100644 --- a/plugins/ecs_examples/src/draw_indirect.rs +++ b/plugins/ecs_examples/src/draw_indirect.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] /// /// Draw Indirect @@ -114,6 +114,7 @@ pub fn setup_draw_indirect( pub fn draw_meshes_indirect( pmfx: &Res, view: &pmfx::View, + cmd_buf: &mut ::CmdBuf, mesh_draw_indirect_query: Query<(&WorldMatrix, &MeshComponent, &CommandSignatureComponent, &BufferComponent)>) -> Result<(), hotline_rs::Error> { @@ -121,15 +122,15 @@ pub fn draw_meshes_indirect( let pipeline = pmfx.get_render_pipeline_for_format(&view.view_pipeline, fmt)?; let camera = pmfx.get_camera_constants(&view.camera)?; - view.cmd_buf.set_render_pipeline(pipeline); - view.cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); + cmd_buf.set_render_pipeline(pipeline); + cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); for (world_matrix, mesh, command, args) in &mesh_draw_indirect_query { - view.cmd_buf.push_render_constants(1, 12, 0, &world_matrix.0); - view.cmd_buf.set_index_buffer(&mesh.0.ib); - view.cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); + cmd_buf.push_render_constants(1, 12, 0, &world_matrix.0); + cmd_buf.set_index_buffer(&mesh.0.ib); + cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); - view.cmd_buf.execute_indirect( + cmd_buf.execute_indirect( &command.0, 1, &args.0, diff --git a/plugins/ecs_examples/src/draw_push_constants.rs b/plugins/ecs_examples/src/draw_push_constants.rs index b17a90ac..edc76a57 100644 --- a/plugins/ecs_examples/src/draw_push_constants.rs +++ b/plugins/ecs_examples/src/draw_push_constants.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] /// /// Draw Push Constants diff --git a/plugins/ecs_examples/src/draw_vertex_buffer_instanced.rs b/plugins/ecs_examples/src/draw_vertex_buffer_instanced.rs index 1641d888..ace7fb02 100644 --- a/plugins/ecs_examples/src/draw_vertex_buffer_instanced.rs +++ b/plugins/ecs_examples/src/draw_vertex_buffer_instanced.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] /// /// Draw Vertex Buffer Instanced @@ -88,6 +88,7 @@ pub fn setup_draw_vertex_buffer_instanced( pub fn draw_meshes_vertex_buffer_instanced( pmfx: &Res, view: &pmfx::View, + cmd_buf: &mut ::CmdBuf, instance_draw_query: Query<(&InstanceBuffer, &MeshComponent, &PipelineComponent)> ) -> Result<(), hotline_rs::Error> { @@ -98,13 +99,13 @@ pub fn draw_meshes_vertex_buffer_instanced( for (instance_batch, mesh, pipeline) in &instance_draw_query { // set pipeline per mesh let pipeline = pmfx.get_render_pipeline_for_format(&pipeline.0, fmt)?; - view.cmd_buf.set_render_pipeline(pipeline); - view.cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); - view.cmd_buf.set_heap(pipeline, &pmfx.shader_heap); - view.cmd_buf.set_index_buffer(&mesh.0.ib); - view.cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); - view.cmd_buf.set_vertex_buffer(&instance_batch.buffer, 1); - view.cmd_buf.draw_indexed_instanced(mesh.0.num_indices, instance_batch.instance_count, 0, 0, 0); + cmd_buf.set_render_pipeline(pipeline); + cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); + cmd_buf.set_heap(pipeline, &pmfx.shader_heap); + cmd_buf.set_index_buffer(&mesh.0.ib); + cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); + cmd_buf.set_vertex_buffer(&instance_batch.buffer, 1); + cmd_buf.draw_indexed_instanced(mesh.0.num_indices, instance_batch.instance_count, 0, 0, 0); } Ok(()) diff --git a/plugins/ecs_examples/src/dynamic_cubemap.rs b/plugins/ecs_examples/src/dynamic_cubemap.rs index badd0e8c..0dd36e89 100644 --- a/plugins/ecs_examples/src/dynamic_cubemap.rs +++ b/plugins/ecs_examples/src/dynamic_cubemap.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] /// /// Dynamic Cubemap @@ -63,7 +63,7 @@ pub fn setup_dynamic_cubemap( let dist = rand::distributions::Uniform::from(0..orbit_meshes.len()); let num_primitves = 32; - for i in 0..num_primitves { + for _ in 0..num_primitves { let rv = normalize(vec3f(rng.gen(), rng.gen(), rng.gen()) * 2.0 - 1.0); let rr = vec3f(rng.gen(), rng.gen(), rng.gen()) * f32::tau(); let offset : f32 = 20.0 + rng.gen::() * 20.0; @@ -102,24 +102,23 @@ pub fn orbit_meshes( pub fn render_orbit_meshes( pmfx: &Res, view: &pmfx::View, + cmd_buf: &mut ::CmdBuf, mesh_draw_query: Query<(&WorldMatrix, &MeshComponent), Without>) -> Result<(), hotline_rs::Error> { let fmt = view.pass.get_format_hash(); let pipeline = pmfx.get_render_pipeline_for_format(&view.view_pipeline, fmt)?; let camera = pmfx.get_camera_constants(&view.camera)?; - view.cmd_buf.set_render_pipeline(pipeline); - view.cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); + cmd_buf.set_render_pipeline(pipeline); + cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); - view.cmd_buf.set_heap(pipeline, &pmfx.shader_heap); + cmd_buf.set_heap(pipeline, &pmfx.shader_heap); - let mut mip = 0; for (world_matrix, mesh) in &mesh_draw_query { - view.cmd_buf.push_render_constants(1, 12, 0, &world_matrix.0); - view.cmd_buf.set_index_buffer(&mesh.0.ib); - view.cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); - view.cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); - mip += 1; + cmd_buf.push_render_constants(1, 12, 0, &world_matrix.0); + cmd_buf.set_index_buffer(&mesh.0.ib); + cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); + cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); } Ok(()) @@ -130,26 +129,27 @@ pub fn render_orbit_meshes( pub fn render_meshes_cubemap_reflect( pmfx: &Res, view: &pmfx::View, + cmd_buf: &mut ::CmdBuf, mesh_draw_query: Query<(&WorldMatrix, &MeshComponent, &TextureInstance)>) -> Result<(), hotline_rs::Error> { let fmt = view.pass.get_format_hash(); let pipeline = pmfx.get_render_pipeline_for_format(&view.view_pipeline, fmt)?; let camera = pmfx.get_camera_constants(&view.camera)?; - view.cmd_buf.set_render_pipeline(pipeline); - view.cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); - view.cmd_buf.push_render_constants(0, 4, 16, gfx::as_u8_slice(&camera.view_position)); + cmd_buf.set_render_pipeline(pipeline); + cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); + cmd_buf.push_render_constants(0, 4, 16, gfx::as_u8_slice(&camera.view_position)); - view.cmd_buf.set_heap(pipeline, &pmfx.shader_heap); + cmd_buf.set_heap(pipeline, &pmfx.shader_heap); let mut mip = 0; for (world_matrix, mesh, cubemap) in &mesh_draw_query { - view.cmd_buf.push_render_constants(1, 12, 0, &world_matrix.0); - view.cmd_buf.push_render_constants(1, 2, 16, gfx::as_u8_slice(&[cubemap.0, mip, 0, 0])); + cmd_buf.push_render_constants(1, 12, 0, &world_matrix.0); + cmd_buf.push_render_constants(1, 2, 16, gfx::as_u8_slice(&[cubemap.0, mip, 0, 0])); - view.cmd_buf.set_index_buffer(&mesh.0.ib); - view.cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); - view.cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); + cmd_buf.set_index_buffer(&mesh.0.ib); + cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); + cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); mip += 1; } diff --git a/plugins/ecs_examples/src/error_tests.rs b/plugins/ecs_examples/src/error_tests.rs index 46e8cf13..96b8205a 100644 --- a/plugins/ecs_examples/src/error_tests.rs +++ b/plugins/ecs_examples/src/error_tests.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] use crate::prelude::*; diff --git a/plugins/ecs_examples/src/examples.rs b/plugins/ecs_examples/src/examples.rs index 55c243a4..b5a08873 100644 --- a/plugins/ecs_examples/src/examples.rs +++ b/plugins/ecs_examples/src/examples.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] use crate::prelude::*; diff --git a/plugins/ecs_examples/src/generate_mip_maps.rs b/plugins/ecs_examples/src/generate_mip_maps.rs index f85a6c58..c812c6f8 100644 --- a/plugins/ecs_examples/src/generate_mip_maps.rs +++ b/plugins/ecs_examples/src/generate_mip_maps.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] /// /// Generate Mip Maps diff --git a/plugins/ecs_examples/src/geometry_primitives.rs b/plugins/ecs_examples/src/geometry_primitives.rs index c45d162a..5a3f3e21 100644 --- a/plugins/ecs_examples/src/geometry_primitives.rs +++ b/plugins/ecs_examples/src/geometry_primitives.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] /// /// Geometry Primitives diff --git a/plugins/ecs_examples/src/gpu_frustum_culling.rs b/plugins/ecs_examples/src/gpu_frustum_culling.rs index fa267d5e..ed885c56 100644 --- a/plugins/ecs_examples/src/gpu_frustum_culling.rs +++ b/plugins/ecs_examples/src/gpu_frustum_culling.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] use crate::prelude::*; @@ -332,12 +332,13 @@ pub fn swirling_meshes( pub fn dispatch_compute_frustum_cull( pmfx: &Res, pass: &mut pmfx::ComputePass, + cmd_buf: &mut ::CmdBuf, indirect_draw_query: Query<&DrawIndirectComponent>) -> Result<(), hotline_rs::Error> { for indirect_draw in &indirect_draw_query { // clears the counter - pass.cmd_buf.transition_barrier(&gfx::TransitionBarrier { + cmd_buf.transition_barrier(&gfx::TransitionBarrier { texture: None, buffer: Some(&indirect_draw.dynamic_buffer), state_before: gfx::ResourceState::IndirectArgument, @@ -345,9 +346,9 @@ pub fn dispatch_compute_frustum_cull( }); let offset = indirect_draw.dynamic_buffer.get_counter_offset().unwrap(); - pass.cmd_buf.copy_buffer_region(&indirect_draw.dynamic_buffer, offset, &indirect_draw.counter_reset, 0, std::mem::size_of::()); + cmd_buf.copy_buffer_region(&indirect_draw.dynamic_buffer, offset, &indirect_draw.counter_reset, 0, std::mem::size_of::()); - pass.cmd_buf.transition_barrier(&gfx::TransitionBarrier { + cmd_buf.transition_barrier(&gfx::TransitionBarrier { texture: None, buffer: Some(&indirect_draw.dynamic_buffer), state_before: gfx::ResourceState::CopyDst, @@ -356,17 +357,17 @@ pub fn dispatch_compute_frustum_cull( // run the shader to cull the entities let pipeline = pmfx.get_compute_pipeline(&pass.pass_pipline).unwrap(); - pass.cmd_buf.set_compute_pipeline(pipeline); + cmd_buf.set_compute_pipeline(pipeline); // resource index info for looking up input (draw all info) / output (culled draw call info) let slot = pipeline.get_pipeline_slot(0, 1, gfx::DescriptorType::PushConstants); if let Some(slot) = slot { // output uav - pass.cmd_buf.push_compute_constants(slot.index, 1, 0, + cmd_buf.push_compute_constants(slot.index, 1, 0, gfx::as_u8_slice(&indirect_draw.dynamic_buffer.get_uav_index().unwrap())); // input srv - pass.cmd_buf.push_compute_constants(slot.index, 1, 4, + cmd_buf.push_compute_constants(slot.index, 1, 4, gfx::as_u8_slice(&indirect_draw.arg_buffer.get_srv_index().unwrap())); } @@ -374,13 +375,13 @@ pub fn dispatch_compute_frustum_cull( let world_buffer_info = pmfx.get_world_buffer_info(); let slot = pipeline.get_pipeline_slot(2, 0, gfx::DescriptorType::PushConstants); if let Some(slot) = slot { - pass.cmd_buf.push_compute_constants( + cmd_buf.push_compute_constants( slot.index, gfx::num_32bit_constants(&world_buffer_info), 0, gfx::as_u8_slice(&world_buffer_info)); } - pass.cmd_buf.set_heap(pipeline, &pmfx.shader_heap); + cmd_buf.set_heap(pipeline, &pmfx.shader_heap); - pass.cmd_buf.dispatch( + cmd_buf.dispatch( gfx::Size3 { x: indirect_draw.max_count / pass.numthreads.x, y: pass.numthreads.y, @@ -390,7 +391,7 @@ pub fn dispatch_compute_frustum_cull( ); // transition to `IndirectArgument` - pass.cmd_buf.transition_barrier(&gfx::TransitionBarrier { + cmd_buf.transition_barrier(&gfx::TransitionBarrier { texture: None, buffer: Some(&indirect_draw.dynamic_buffer), state_before: gfx::ResourceState::UnorderedAccess, @@ -406,26 +407,27 @@ pub fn dispatch_compute_frustum_cull( pub fn draw_meshes_indirect_culling( pmfx: &Res, view: &pmfx::View, + cmd_buf: &mut ::CmdBuf, indirect_draw_query: Query<&DrawIndirectComponent>) -> Result<(), hotline_rs::Error> { let fmt = view.pass.get_format_hash(); let pipeline = pmfx.get_render_pipeline_for_format(&view.view_pipeline, fmt)?; - view.cmd_buf.set_render_pipeline(&pipeline); + cmd_buf.set_render_pipeline(&pipeline); // bind the world buffer info let world_buffer_info = pmfx.get_world_buffer_info(); let slot = pipeline.get_pipeline_slot(2, 0, gfx::DescriptorType::PushConstants); if let Some(slot) = slot { - view.cmd_buf.push_render_constants( + cmd_buf.push_render_constants( slot.index, gfx::num_32bit_constants(&world_buffer_info), 0, gfx::as_u8_slice(&world_buffer_info)); } - view.cmd_buf.set_heap(pipeline, &pmfx.shader_heap); + cmd_buf.set_heap(pipeline, &pmfx.shader_heap); for indirect_draw in &indirect_draw_query { - view.cmd_buf.execute_indirect( + cmd_buf.execute_indirect( &indirect_draw.signature, indirect_draw.max_count, &indirect_draw.dynamic_buffer, diff --git a/plugins/ecs_examples/src/lib.rs b/plugins/ecs_examples/src/lib.rs index 5c8cdfef..34aee2f3 100644 --- a/plugins/ecs_examples/src/lib.rs +++ b/plugins/ecs_examples/src/lib.rs @@ -276,7 +276,7 @@ pub fn render_meshes_bindless( // bind resource uses let using_slot = pipeline.get_pipeline_slot(0, 1, gfx::DescriptorType::PushConstants); - if let Some(slot) = using_slot { + if let Some(_) = using_slot { for i in 0..view.use_indices.len() { let num_constants = gfx::num_32bit_constants(&view.use_indices[i]); cmd_buf.push_compute_constants( @@ -314,13 +314,13 @@ pub fn render_meshes_bindless( Ok(()) } -/* ///Renders all meshes generically with a single pipeline which and be specified in the .pmfx view #[no_mangle] #[export_render_fn] pub fn render_meshes( pmfx: &Res, view: &pmfx::View, + cmd_buf: &mut ::CmdBuf, queries: ( Query<(&WorldMatrix, &MeshComponent), Without>, Query<(&WorldMatrix, &MeshComponent), (With, Without)>, @@ -331,20 +331,20 @@ pub fn render_meshes( let pipeline = pmfx.get_render_pipeline_for_format(&view.view_pipeline, fmt)?; let camera = pmfx.get_camera_constants(&view.camera)?; - view.cmd_buf.set_render_pipeline(&pipeline); - view.cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); + cmd_buf.set_render_pipeline(&pipeline); + cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); let (mesh_draw_query, billboard_draw_query, cylindrical_draw_query) = queries; for (world_matrix, mesh) in &mesh_draw_query { let slot = pipeline.get_pipeline_slot(1, 0, gfx::DescriptorType::PushConstants); if let Some(slot) = slot { - view.cmd_buf.push_render_constants(slot.index, 12, 0, &world_matrix.0); + cmd_buf.push_render_constants(slot.index, 12, 0, &world_matrix.0); } - view.cmd_buf.set_index_buffer(&mesh.0.ib); - view.cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); - view.cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); + cmd_buf.set_index_buffer(&mesh.0.ib); + cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); + cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); } // billboard @@ -353,12 +353,12 @@ pub fn render_meshes( let bbmat = world_matrix.0 * Mat4f::from(inv_rot); let slot = pipeline.get_pipeline_slot(1, 0, gfx::DescriptorType::PushConstants); if let Some(slot) = slot { - view.cmd_buf.push_render_constants(slot.index, 12, 0, &bbmat); + cmd_buf.push_render_constants(slot.index, 12, 0, &bbmat); } - view.cmd_buf.set_index_buffer(&mesh.0.ib); - view.cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); - view.cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); + cmd_buf.set_index_buffer(&mesh.0.ib); + cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); + cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); } // spherical billboard @@ -372,12 +372,12 @@ pub fn render_meshes( let bbmat = world_matrix.0 * Mat4f::from(cyl_rot); let slot = pipeline.get_pipeline_slot(1, 0, gfx::DescriptorType::PushConstants); if let Some(slot) = slot { - view.cmd_buf.push_render_constants(slot.index, 12, 0, &bbmat); + cmd_buf.push_render_constants(slot.index, 12, 0, &bbmat); } - view.cmd_buf.set_index_buffer(&mesh.0.ib); - view.cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); - view.cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); + cmd_buf.set_index_buffer(&mesh.0.ib); + cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); + cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); } Ok(()) @@ -389,6 +389,7 @@ pub fn render_meshes( pub fn render_debug( pmfx: &Res, view: &pmfx::View, + cmd_buf: &mut ::CmdBuf, mut imdraw: ResMut, mut device: ResMut, session_info: ResMut, @@ -452,7 +453,7 @@ pub fn render_debug( // cameras if session_info.debug_draw_flags.contains(DebugDrawFlags::CAMERAS) { - for (name, camera) in &camera_query { + for (name, _) in &camera_query { let constants = pmfx.get_camera_constants(name)?; imdraw.add_frustum(constants.view_projection_matrix, Vec4f::white()); } @@ -462,9 +463,9 @@ pub fn render_debug( imdraw.submit(&mut device.0, bb as usize).unwrap(); // draw - view.cmd_buf.set_render_pipeline(&pipeline); - view.cmd_buf.push_render_constants(0, 16, 0, &camera.view_projection_matrix); - imdraw.draw_3d(&view.cmd_buf, bb as usize); + cmd_buf.set_render_pipeline(&pipeline); + cmd_buf.push_render_constants(0, 16, 0, &camera.view_projection_matrix); + imdraw.draw_3d(cmd_buf, bb as usize); Ok(()) } @@ -474,7 +475,9 @@ pub fn render_debug( #[export_render_fn] pub fn blit( pmfx: &Res, - view: &pmfx::View) -> Result<(), hotline_rs::Error> { + view: &pmfx::View, + cmd_buf: &mut ::CmdBuf +) -> Result<(), hotline_rs::Error> { let pmfx = &pmfx; let fmt = view.pass.get_format_hash(); @@ -487,21 +490,21 @@ pub fn blit( } let srv = view.use_indices[0].index; - view.cmd_buf.set_render_pipeline(pipeline); + cmd_buf.set_render_pipeline(pipeline); let slot = pipeline.get_pipeline_slot(0, 0, gfx::DescriptorType::PushConstants); if let Some(slot) = slot { - view.cmd_buf.push_render_constants(slot.index, 2, 0, &view.blit_dimension); + cmd_buf.push_render_constants(slot.index, 2, 0, &view.blit_dimension); } let slot = pipeline.get_pipeline_slot(1, 0, gfx::DescriptorType::ShaderResource); if let Some(slot) = slot { - view.cmd_buf.set_binding(pipeline, &pmfx.shader_heap, slot.index, srv as usize); + cmd_buf.set_binding(pipeline, &pmfx.shader_heap, slot.index, srv as usize); } - view.cmd_buf.set_index_buffer(&pmfx.0.unit_quad_mesh.ib); - view.cmd_buf.set_vertex_buffer(&pmfx.0.unit_quad_mesh.vb, 0); - view.cmd_buf.draw_indexed_instanced(6, 1, 0, 0, 0); + cmd_buf.set_index_buffer(&pmfx.0.unit_quad_mesh.ib); + cmd_buf.set_vertex_buffer(&pmfx.0.unit_quad_mesh.vb, 0); + cmd_buf.draw_indexed_instanced(6, 1, 0, 0, 0); Ok(()) } @@ -511,7 +514,9 @@ pub fn blit( #[export_render_fn] pub fn cubemap_clear( pmfx: &Res, - view: &pmfx::View) -> Result<(), hotline_rs::Error> { + view: &pmfx::View, + cmd_buf: &mut ::CmdBuf +) -> Result<(), hotline_rs::Error> { let pmfx = &pmfx; let fmt = view.pass.get_format_hash(); @@ -525,22 +530,22 @@ pub fn cubemap_clear( } let srv = view.use_indices[0].index; - view.cmd_buf.set_render_pipeline(pipeline); + cmd_buf.set_render_pipeline(pipeline); let slot = pipeline.get_pipeline_slot(0, 0, gfx::DescriptorType::PushConstants); if let Some(slot) = slot { let inv = camera.view_projection_matrix.inverse(); - view.cmd_buf.push_render_constants(slot.index, 16, 0, &inv); + cmd_buf.push_render_constants(slot.index, 16, 0, &inv); } let slot = pipeline.get_pipeline_slot(0, 0, gfx::DescriptorType::ShaderResource); if let Some(slot) = slot { - view.cmd_buf.set_binding(pipeline, &pmfx.shader_heap, slot.index, srv as usize); + cmd_buf.set_binding(pipeline, &pmfx.shader_heap, slot.index, srv as usize); } - view.cmd_buf.set_index_buffer(&pmfx.0.unit_quad_mesh.ib); - view.cmd_buf.set_vertex_buffer(&pmfx.0.unit_quad_mesh.vb, 0); - view.cmd_buf.draw_indexed_instanced(6, 1, 0, 0, 0); + cmd_buf.set_index_buffer(&pmfx.0.unit_quad_mesh.ib); + cmd_buf.set_vertex_buffer(&pmfx.0.unit_quad_mesh.vb, 0); + cmd_buf.draw_indexed_instanced(6, 1, 0, 0, 0); Ok(()) } @@ -550,17 +555,18 @@ pub fn cubemap_clear( #[export_compute_fn] pub fn dispatch_compute( pmfx: &Res, - pass: &pmfx::ComputePass + pass: &pmfx::ComputePass, + cmd_buf: &mut ::CmdBuf ) -> Result<(), hotline_rs::Error> { let pipeline = pmfx.get_compute_pipeline(&pass.pass_pipline)?; - pass.cmd_buf.set_compute_pipeline(&pipeline); + cmd_buf.set_compute_pipeline(&pipeline); let using_slot = pipeline.get_pipeline_slot(0, 1, gfx::DescriptorType::PushConstants); if let Some(slot) = using_slot { for i in 0..pass.use_indices.len() { let num_constants = gfx::num_32bit_constants(&pass.use_indices[i]); - pass.cmd_buf.push_compute_constants( + cmd_buf.push_compute_constants( slot.index, num_constants, i as u32 * num_constants, @@ -569,9 +575,9 @@ pub fn dispatch_compute( } } - pass.cmd_buf.set_heap(pipeline, &pmfx.shader_heap); + cmd_buf.set_heap(pipeline, &pmfx.shader_heap); - pass.cmd_buf.dispatch( + cmd_buf.dispatch( pass.group_count, pass.numthreads ); @@ -583,9 +589,9 @@ pub fn dispatch_compute( pub fn setup_tlas( mut device: ResMut, mut pmfx: ResMut, - mut entities_query: Query<(&mut Position, &mut Scale, &mut Rotation, &BLASComponent)>, - mut tlas_query: Query<&mut TLASComponent>, - mut commands: Commands) -> Result<(), hotline_rs::Error> { + entities_query: Query<(&mut Position, &mut Scale, &mut Rotation, &BLASComponent)>, + mut tlas_query: Query<&mut TLASComponent> +) -> Result<(), hotline_rs::Error> { // setup tlas, first time only for mut t in &mut tlas_query { @@ -628,7 +634,8 @@ pub fn update_tlas( mut device: ResMut, pmfx: &Res, pass: &mut pmfx::ComputePass, - mut entities_query: Query<(&mut Position, &mut Scale, &mut Rotation, &BLASComponent)>, + cmd_buf: &mut ::CmdBuf, + entities_query: Query<(&mut Position, &mut Scale, &mut Rotation, &BLASComponent)>, mut tlas_query: Query<&mut TLASComponent>, ) -> Result<(), hotline_rs::Error> { // update tlas @@ -653,7 +660,7 @@ pub fn update_tlas( if let Some(tlas) = t.tlas.as_ref() { let instance_buffer = device.create_raytracing_instance_buffer(&instances)?; - pass.cmd_buf.update_raytracing_tlas(tlas, &instance_buffer, instances.len(), gfx::AccelerationStructureRebuildMode::Refit); + cmd_buf.update_raytracing_tlas(tlas, &instance_buffer, instances.len(), gfx::AccelerationStructureRebuildMode::Refit); t.instance_buffer = Some(instance_buffer); } } @@ -695,7 +702,6 @@ pub fn get_demos_ecs_examples() -> Vec { "raytraced_shadows" ] } -*/ pub mod prelude { #[doc(hidden)] diff --git a/plugins/ecs_examples/src/multiple_render_targets.rs b/plugins/ecs_examples/src/multiple_render_targets.rs index 44150a63..07f0df8a 100644 --- a/plugins/ecs_examples/src/multiple_render_targets.rs +++ b/plugins/ecs_examples/src/multiple_render_targets.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] /// /// Multiple Render Targets diff --git a/plugins/ecs_examples/src/omni_shadow_map.rs b/plugins/ecs_examples/src/omni_shadow_map.rs index 81016e7a..8043493e 100644 --- a/plugins/ecs_examples/src/omni_shadow_map.rs +++ b/plugins/ecs_examples/src/omni_shadow_map.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] /// /// Omni Shadow Map @@ -161,11 +161,11 @@ pub fn setup_omni_shadow_map( pub fn animate_omni_shadow ( time: Res, mut pmfx: ResMut, - mut light_query: Query<(&mut Position, &mut Velocity, &LightComponent)>) -> Result<(), hotline_rs::Error> { + mut light_query: Query<(&mut Position, &LightComponent)>) -> Result<(), hotline_rs::Error> { let extent = 60.0; - for (mut position, mut velocity, component) in &mut light_query { + for (mut position, component) in &mut light_query { position.0 = vec3f(sin(time.accumulated), cos(time.accumulated), cos(time.accumulated)) * extent; diff --git a/plugins/ecs_examples/src/pbr.rs b/plugins/ecs_examples/src/pbr.rs index e7ccc577..ccf789e7 100644 --- a/plugins/ecs_examples/src/pbr.rs +++ b/plugins/ecs_examples/src/pbr.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] /// /// Cubemap @@ -90,6 +90,7 @@ pub fn setup_pbr( pub fn render_meshes_pbr( pmfx: &Res, view: &pmfx::View, + cmd_buf: &mut ::CmdBuf, state: &Res, mesh_draw_query: Query<(&WorldMatrix, &MeshComponent, &TextureInstance)>) -> Result<(), hotline_rs::Error> { @@ -97,11 +98,11 @@ pub fn render_meshes_pbr( let pipeline = pmfx.get_render_pipeline_for_format(&view.view_pipeline, fmt)?; let camera = pmfx.get_camera_constants(&view.camera)?; - view.cmd_buf.set_render_pipeline(pipeline); - view.cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); - view.cmd_buf.push_render_constants(0, 4, 16, gfx::as_u8_slice(&camera.view_position)); + cmd_buf.set_render_pipeline(pipeline); + cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); + cmd_buf.push_render_constants(0, 4, 16, gfx::as_u8_slice(&camera.view_position)); - view.cmd_buf.set_heap(pipeline, &pmfx.shader_heap); + cmd_buf.set_heap(pipeline, &pmfx.shader_heap); let rc = 8; let mut i = 0; @@ -115,13 +116,13 @@ pub fn render_meshes_pbr( 0.0 }; - view.cmd_buf.push_render_constants(1, 12, 0, &world_matrix.0); - view.cmd_buf.push_render_constants(1, 4, 12, gfx::as_u8_slice(&[roughness, metalness, 0.0, 0.0])); - view.cmd_buf.push_render_constants(1, 2, 16, gfx::as_u8_slice(&[cubemap.0, state.lut_srv, 0, 0])); + cmd_buf.push_render_constants(1, 12, 0, &world_matrix.0); + cmd_buf.push_render_constants(1, 4, 12, gfx::as_u8_slice(&[roughness, metalness, 0.0, 0.0])); + cmd_buf.push_render_constants(1, 2, 16, gfx::as_u8_slice(&[cubemap.0, state.lut_srv, 0, 0])); - view.cmd_buf.set_index_buffer(&mesh.0.ib); - view.cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); - view.cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); + cmd_buf.set_index_buffer(&mesh.0.ib); + cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); + cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); i += 1; } diff --git a/plugins/ecs_examples/src/point_lights.rs b/plugins/ecs_examples/src/point_lights.rs index 40d66b42..6c6031f1 100644 --- a/plugins/ecs_examples/src/point_lights.rs +++ b/plugins/ecs_examples/src/point_lights.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] use crate::prelude::*; diff --git a/plugins/ecs_examples/src/raster_states.rs b/plugins/ecs_examples/src/raster_states.rs index 641fa662..26bfadd8 100644 --- a/plugins/ecs_examples/src/raster_states.rs +++ b/plugins/ecs_examples/src/raster_states.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] /// /// Raster States @@ -75,6 +75,7 @@ pub fn setup_raster_states( pub fn render_meshes_pipeline( pmfx: &Res, view: &pmfx::View, + cmd_buf: &mut ::CmdBuf, mesh_draw_query: Query<(&WorldMatrix, &MeshComponent, &PipelineComponent)>) -> Result<(), hotline_rs::Error> { let pmfx = &pmfx; @@ -84,13 +85,13 @@ pub fn render_meshes_pipeline( for (world_matrix, mesh, pipeline) in &mesh_draw_query { // set pipeline per mesh let pipeline = pmfx.get_render_pipeline_for_format(&pipeline.0, fmt)?; - view.cmd_buf.set_render_pipeline(&pipeline); - view.cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); - view.cmd_buf.push_render_constants(1, 12, 0, &world_matrix.0); - - view.cmd_buf.set_index_buffer(&mesh.0.ib); - view.cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); - view.cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); + cmd_buf.set_render_pipeline(&pipeline); + cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); + cmd_buf.push_render_constants(1, 12, 0, &world_matrix.0); + + cmd_buf.set_index_buffer(&mesh.0.ib); + cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); + cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); } Ok(()) diff --git a/plugins/ecs_examples/src/raytraced_shadows.rs b/plugins/ecs_examples/src/raytraced_shadows.rs index acf29158..ecd297e1 100644 --- a/plugins/ecs_examples/src/raytraced_shadows.rs +++ b/plugins/ecs_examples/src/raytraced_shadows.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] /// /// Raytraced Shadows diff --git a/plugins/ecs_examples/src/raytracing_pipeline.rs b/plugins/ecs_examples/src/raytracing_pipeline.rs index 0bc36508..176debf7 100644 --- a/plugins/ecs_examples/src/raytracing_pipeline.rs +++ b/plugins/ecs_examples/src/raytracing_pipeline.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] use hotline_rs::gfx::{CpuAccessFlags, RaytracingTLAS}; @@ -198,10 +198,10 @@ pub fn setup_raytracing_pipeline_scene( #[export_compute_fn] pub fn render_meshes_raytraced( - mut device: ResMut, + device: ResMut, pmfx: &Res, pass: &pmfx::ComputePass, - entities_query: Query<(&mut Position, &mut Scale, &mut Rotation, &BLASComponent)>, + cmd_buf: &mut ::CmdBuf, tlas_query: Query<&mut TLASComponent>, ) -> Result<(), hotline_rs::Error> { let pmfx = &pmfx.0; @@ -217,36 +217,36 @@ pub fn render_meshes_raytraced( if let Some(tlas) = &t.tlas { // set pipeline let raytracing_pipeline = pmfx.get_raytracing_pipeline(&pass.pass_pipline)?; - pass.cmd_buf.set_raytracing_pipeline(&raytracing_pipeline.pipeline); + cmd_buf.set_raytracing_pipeline(&raytracing_pipeline.pipeline); let slot = raytracing_pipeline.pipeline.get_pipeline_slot(0, 0, gfx::DescriptorType::PushConstants); if let Some(slot) = slot { // camera constants let inv = camera.view_projection_matrix.inverse(); - pass.cmd_buf.push_compute_constants(slot.index, 16, 0, &inv); + cmd_buf.push_compute_constants(slot.index, 16, 0, &inv); // output uav - pass.cmd_buf.push_compute_constants(slot.index, 1, 16, gfx::as_u8_slice(&pass.use_indices[0].index)); + cmd_buf.push_compute_constants(slot.index, 1, 16, gfx::as_u8_slice(&pass.use_indices[0].index)); // scene tlas let srv0 = tlas.get_srv_index().expect("expect tlas to have an srv"); - pass.cmd_buf.push_compute_constants(slot.index, 1, 17, gfx::as_u8_slice(&srv0)); + cmd_buf.push_compute_constants(slot.index, 1, 17, gfx::as_u8_slice(&srv0)); // point light info let world_buffer_info = pmfx.get_world_buffer_info(); - pass.cmd_buf.push_compute_constants(slot.index, 2, 18, gfx::as_u8_slice(&world_buffer_info.point_light)); + cmd_buf.push_compute_constants(slot.index, 2, 18, gfx::as_u8_slice(&world_buffer_info.point_light)); } - pass.cmd_buf.set_heap(&raytracing_pipeline.pipeline, &pmfx.shader_heap); + cmd_buf.set_heap(&raytracing_pipeline.pipeline, &pmfx.shader_heap); let second_slot = raytracing_pipeline.pipeline.get_pipeline_slot(1, 0, gfx::DescriptorType::ShaderResource); if let Some(second_slot) = second_slot { let srv_buffer = t.instance_geometry_buffer.as_ref().unwrap().get_srv_index().unwrap(); - pass.cmd_buf.set_binding(&raytracing_pipeline.pipeline, &pmfx.shader_heap, second_slot.index, srv_buffer); + cmd_buf.set_binding(&raytracing_pipeline.pipeline, &pmfx.shader_heap, second_slot.index, srv_buffer); } // dispatch - pass.cmd_buf.dispatch_rays(&raytracing_pipeline.sbt, gfx::Size3 { + cmd_buf.dispatch_rays(&raytracing_pipeline.sbt, gfx::Size3 { x: output_size.0 as u32, y: output_size.1 as u32, z: 1 diff --git a/plugins/ecs_examples/src/read_write_texture.rs b/plugins/ecs_examples/src/read_write_texture.rs index 391d5134..2c194b76 100644 --- a/plugins/ecs_examples/src/read_write_texture.rs +++ b/plugins/ecs_examples/src/read_write_texture.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] /// /// Read-Write Texture diff --git a/plugins/ecs_examples/src/shadow_map.rs b/plugins/ecs_examples/src/shadow_map.rs index 586b6d95..57948d2a 100644 --- a/plugins/ecs_examples/src/shadow_map.rs +++ b/plugins/ecs_examples/src/shadow_map.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] /// /// Shadow Map diff --git a/plugins/ecs_examples/src/spot_lights.rs b/plugins/ecs_examples/src/spot_lights.rs index 099f8150..4180f816 100644 --- a/plugins/ecs_examples/src/spot_lights.rs +++ b/plugins/ecs_examples/src/spot_lights.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] // // Spot Lights diff --git a/plugins/ecs_examples/src/tangent_space_normal_maps.rs b/plugins/ecs_examples/src/tangent_space_normal_maps.rs index 87bd6758..c26b6eb7 100644 --- a/plugins/ecs_examples/src/tangent_space_normal_maps.rs +++ b/plugins/ecs_examples/src/tangent_space_normal_maps.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] /// /// Tangent Space Normal Maps @@ -52,6 +52,7 @@ pub fn setup_tangent_space_normal_maps( pub fn render_meshes_debug_tangent_space( pmfx: &Res, view: &pmfx::View, + cmd_buf: &mut ::CmdBuf, queries: ( Query<&TextureComponent>, Query<(&WorldMatrix, &MeshComponent)> @@ -62,24 +63,24 @@ pub fn render_meshes_debug_tangent_space( let pipeline = pmfx.get_render_pipeline_for_format(&view.view_pipeline, fmt)?; let camera = pmfx.get_camera_constants(&view.camera)?; - view.cmd_buf.set_render_pipeline(pipeline); - view.cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); + cmd_buf.set_render_pipeline(pipeline); + cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); - view.cmd_buf.set_heap(pipeline, &pmfx.shader_heap); + cmd_buf.set_heap(pipeline, &pmfx.shader_heap); let (texture_query, mesh_draw_query) = queries; // bind first texture if let Some(texture) = (&texture_query).into_iter().next() { let usrv = texture.get_srv_index().unwrap() as u32; - view.cmd_buf.push_render_constants(1, 1, 16, gfx::as_u8_slice(&usrv)); + cmd_buf.push_render_constants(1, 1, 16, gfx::as_u8_slice(&usrv)); } for (world_matrix, mesh) in &mesh_draw_query { - view.cmd_buf.push_render_constants(1, 12, 0, &world_matrix.0); - view.cmd_buf.set_index_buffer(&mesh.0.ib); - view.cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); - view.cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); + cmd_buf.push_render_constants(1, 12, 0, &world_matrix.0); + cmd_buf.set_index_buffer(&mesh.0.ib); + cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); + cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); } Ok(()) diff --git a/plugins/ecs_examples/src/texture2d_array.rs b/plugins/ecs_examples/src/texture2d_array.rs index 7f2ad41a..17ba433a 100644 --- a/plugins/ecs_examples/src/texture2d_array.rs +++ b/plugins/ecs_examples/src/texture2d_array.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] /// /// Texture2D Array @@ -89,16 +89,17 @@ pub fn setup_texture2d_array( pub fn render_meshes_texture2d_array( pmfx: &Res, view: &pmfx::View, + cmd_buf: &mut ::CmdBuf, mesh_query: Query<(&WorldMatrix, &MeshComponent, &TextureInstance, &AnimatedTexture), With>) -> Result<(), hotline_rs::Error> { let fmt = view.pass.get_format_hash(); let pipeline = pmfx.get_render_pipeline_for_format(&view.view_pipeline, fmt)?; let camera = pmfx.get_camera_constants(&view.camera)?; - view.cmd_buf.set_render_pipeline(pipeline); - view.cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); + cmd_buf.set_render_pipeline(pipeline); + cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); - view.cmd_buf.set_heap(pipeline, &pmfx.shader_heap); + cmd_buf.set_heap(pipeline, &pmfx.shader_heap); // spherical billboard let inv_rot = Mat3f::from(camera.view_matrix.transpose()); @@ -110,12 +111,12 @@ pub fn render_meshes_texture2d_array( for (world_matrix, mesh, texture, animated_texture) in &mesh_query { let bbmat = world_matrix.0 * Mat4f::from(cyl_rot); - view.cmd_buf.push_render_constants(1, 12, 0, &bbmat); - view.cmd_buf.push_render_constants(1, 2, 16, gfx::as_u8_slice(&[texture.0, animated_texture.frame, 0, 0])); + cmd_buf.push_render_constants(1, 12, 0, &bbmat); + cmd_buf.push_render_constants(1, 2, 16, gfx::as_u8_slice(&[texture.0, animated_texture.frame, 0, 0])); - view.cmd_buf.set_index_buffer(&mesh.0.ib); - view.cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); - view.cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); + cmd_buf.set_index_buffer(&mesh.0.ib); + cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); + cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); } Ok(()) diff --git a/plugins/ecs_examples/src/texture3d.rs b/plugins/ecs_examples/src/texture3d.rs index b6b08cdf..a275760d 100644 --- a/plugins/ecs_examples/src/texture3d.rs +++ b/plugins/ecs_examples/src/texture3d.rs @@ -1,5 +1,5 @@ // currently windows only because here we need a concrete gfx and os implementation -#![cfg(target_os = "macos")] +#![cfg(target_os = "windows")] /// /// Texture3D @@ -64,24 +64,25 @@ pub fn setup_texture3d( pub fn render_meshes_texture3d( pmfx: &Res, view: &pmfx::View, + cmd_buf: &mut ::CmdBuf, mesh_draw_query: Query<(&WorldMatrix, &MeshComponent, &TextureInstance)>) -> Result<(), hotline_rs::Error> { let fmt = view.pass.get_format_hash(); let pipeline = pmfx.get_render_pipeline_for_format(&view.view_pipeline, fmt)?; let camera = pmfx.get_camera_constants(&view.camera)?; - view.cmd_buf.set_render_pipeline(pipeline); - view.cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); - view.cmd_buf.push_render_constants(0, 4, 16, gfx::as_u8_slice(&camera.view_position)); + cmd_buf.set_render_pipeline(pipeline); + cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix)); + cmd_buf.push_render_constants(0, 4, 16, gfx::as_u8_slice(&camera.view_position)); - view.cmd_buf.set_heap(pipeline, &pmfx.shader_heap); + cmd_buf.set_heap(pipeline, &pmfx.shader_heap); for (world_matrix, mesh, tex) in &mesh_draw_query { - view.cmd_buf.push_render_constants(1, 12, 0, &world_matrix.0); - view.cmd_buf.push_render_constants(1, 2, 16, gfx::as_u8_slice(&[tex.0, 0, 0, 0])); - view.cmd_buf.set_index_buffer(&mesh.0.ib); - view.cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); - view.cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); + cmd_buf.push_render_constants(1, 12, 0, &world_matrix.0); + cmd_buf.push_render_constants(1, 2, 16, gfx::as_u8_slice(&[tex.0, 0, 0, 0])); + cmd_buf.set_index_buffer(&mesh.0.ib); + cmd_buf.set_vertex_buffer(&mesh.0.vb, 0); + cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0); } Ok(()) diff --git a/plugins/export_macros/src/lib.rs b/plugins/export_macros/src/lib.rs index c25bd91e..db7e93d0 100644 --- a/plugins/export_macros/src/lib.rs +++ b/plugins/export_macros/src/lib.rs @@ -161,20 +161,19 @@ pub fn export_render_fn(attr: TokenStream, item: TokenStream) -> TokenStream { let err = match view { Ok(v) => { let mut view = v.lock().unwrap(); - - let mut cmd_buf = view.cmd_buf.clone(); + let mut cmd_buf = std::mem::take(&mut view.cmd_buf); let col = view.colour_hash; cmd_buf.begin_event(col, &view_name); - cmd_buf.begin_render_pass(&view.pass); cmd_buf.set_viewport(&view.viewport); cmd_buf.set_scissor_rect(&view.scissor_rect); - let result = fn_name(fn_args); - cmd_buf.end_render_pass(); cmd_buf.end_event(); + + view.cmd_buf = cmd_buf; + result } Err(v) => { @@ -199,8 +198,6 @@ pub fn export_render_fn(attr: TokenStream, item: TokenStream) -> TokenStream { .replace("fn_attr", &order) .to_string(); - println!("{}", export_fn); - // output the original item plus the generated export function let export_tokens : TokenStream = export_fn.parse().unwrap(); let input = parse_macro_input!(item as ItemFn); @@ -218,7 +215,7 @@ pub fn export_compute_fn(attr: TokenStream, item: TokenStream) -> TokenStream { let parsed = parse_fn(&item); // emit code to move function args into closure and pass them to function - let (moves, pass) = emit_moves_and_pass_args(&parsed, &vec!["pmfx :: ComputePass"]); + let (moves, pass) = emit_moves_and_pass_args(&parsed, &vec!["pmfx :: ComputePass", "< gfx_platform :: Device as Device > :: CmdBuf"]); let order = emit_update_order(attr, "SystemSets :: Render"); let render_closure = quote! { @@ -230,11 +227,13 @@ pub fn export_compute_fn(attr: TokenStream, item: TokenStream) -> TokenStream { let err = match pass { Ok(p) => { let mut pass = p.lock().unwrap(); - pass.cmd_buf.begin_event(0xffffff, &pass_name); + let mut cmd_buf = std::mem::take(&mut pass.cmd_buf); + cmd_buf.begin_event(0xffffff, &pass_name); let result = fn_name(fn_args); + cmd_buf.end_event(); - pass.cmd_buf.end_event(); + pass.cmd_buf = cmd_buf; Ok(()) } diff --git a/src/gfx/d3d12.rs b/src/gfx/d3d12.rs index 1b0240c0..5b0b0027 100644 --- a/src/gfx/d3d12.rs +++ b/src/gfx/d3d12.rs @@ -176,7 +176,7 @@ pub struct RenderPipeline { lookup: RootSignatureLookup } -#[derive(Clone)] +#[derive(Clone, Default)] pub struct CmdBuf { bb_index: usize, command_allocator: Vec,