From b8b9bf40a3dacbdac12cfd56aeff5558c4d0a47f Mon Sep 17 00:00:00 2001 From: janis Date: Sun, 12 Apr 2026 20:23:45 +0200 Subject: [PATCH] more command stuff --- crates/renderer/src/lib.rs | 1 + crates/renderer/src/render_graph/commands.rs | 44 ++++++++----------- crates/renderer/src/render_graph/mod.rs | 1 + crates/renderer/src/render_graph/recorder.rs | 7 +-- crates/renderer/src/render_graph/resources.rs | 19 ++++++-- 5 files changed, 40 insertions(+), 32 deletions(-) diff --git a/crates/renderer/src/lib.rs b/crates/renderer/src/lib.rs index 158a4da..467805c 100644 --- a/crates/renderer/src/lib.rs +++ b/crates/renderer/src/lib.rs @@ -2,6 +2,7 @@ negative_impls, map_try_insert, debug_closure_helpers, + core_io_borrowed_buf, slice_partition_dedup )] diff --git a/crates/renderer/src/render_graph/commands.rs b/crates/renderer/src/render_graph/commands.rs index 45489d9..6b7319f 100644 --- a/crates/renderer/src/render_graph/commands.rs +++ b/crates/renderer/src/render_graph/commands.rs @@ -40,8 +40,8 @@ use super::resources::*; // } pub struct Copy { - pub src: Read, - pub dst: Write, + pub src: T, + pub dst: U, } impl Copy { fn side_effects_inner(&self, mut map: SideEffectMap) { @@ -273,9 +273,9 @@ impl Command for UpdateBuffer { } pub struct BeginRendering { - pub color_attachments: Vec>, - pub depth_attachment: Option>, - pub stencil_attachment: Option>, + pub color_attachments: Vec, + pub depth_attachment: Option, + pub stencil_attachment: Option, pub area: (u32, u32), pub layers: u32, } @@ -318,7 +318,7 @@ impl Command for EndRendering { fn apply(self, _recorder: &mut CommandRecorder) {} } -pub struct BindPipeline(pub Pipeline); +pub struct BindPipeline; impl Command for BindPipeline { fn side_effects(&self, _map: SideEffectMap) { @@ -329,7 +329,7 @@ impl Command for BindPipeline { } pub struct BindVertexBuffers { - pub buffers: Vec>, + pub buffers: Vec, } impl Command for BindVertexBuffers { @@ -346,7 +346,7 @@ impl Command for BindVertexBuffers { fn apply(self, _recorder: &mut CommandRecorder) {} } -pub struct BindIndexBuffer(pub Read, pub IndexFormat); +pub struct BindIndexBuffer(pub BufferSlice, pub IndexFormat); impl Command for BindIndexBuffer { fn side_effects(&self, mut map: SideEffectMap) { @@ -357,9 +357,7 @@ impl Command for BindIndexBuffer { fn apply(self, _recorder: &mut CommandRecorder) {} } -pub struct BindDescriptorSets { - pub sets: Vec, -} +pub struct BindDescriptorSets; impl Command for BindDescriptorSets { fn side_effects(&self, _map: SideEffectMap) { @@ -401,9 +399,7 @@ impl Command for SetScissor { fn apply(self, _recorder: &mut CommandRecorder) {} } -pub struct PushConstants { - pub data: Box<[u8]>, -} +pub struct PushConstants; impl Command for PushConstants { fn side_effects(&self, _map: SideEffectMap) { @@ -429,11 +425,15 @@ pub struct DrawIndexedData { } pub struct DrawIndirectData { - pub indirect_buffer: Read, + pub indirect_buffer: BufferSlice, + pub count: u32, + pub stride: u32, } pub struct DrawIndexedIndirectData { - pub indirect_buffer: Read, + pub indirect_buffer: BufferSlice, + pub count: u32, + pub stride: u32, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -445,9 +445,8 @@ pub enum IndexFormat { pub struct Draw { pub data: T, - pub vertex_buffers: Vec>, - pub index_buffer: Option<(Read, IndexFormat)>, - pub count_buffer: Option>, + pub vertex_buffers: Vec, + pub index_buffer: Option<(BufferSlice, IndexFormat)>, } impl Command for Draw { @@ -467,13 +466,6 @@ impl Command for Draw { None, ); } - if let Some(count_buffer) = &self.count_buffer { - count_buffer.side_effect( - map.reborrow(), - vk::AccessFlags2::VERTEX_ATTRIBUTE_READ, - None, - ); - } } fn apply(self, _recorder: &mut CommandRecorder) {} diff --git a/crates/renderer/src/render_graph/mod.rs b/crates/renderer/src/render_graph/mod.rs index 12016f8..14a6caa 100644 --- a/crates/renderer/src/render_graph/mod.rs +++ b/crates/renderer/src/render_graph/mod.rs @@ -4,5 +4,6 @@ mod legacy; pub use legacy::*; mod commands; +mod graph_builder; mod recorder; mod resources; diff --git a/crates/renderer/src/render_graph/recorder.rs b/crates/renderer/src/render_graph/recorder.rs index aaa85a5..79d6f71 100644 --- a/crates/renderer/src/render_graph/recorder.rs +++ b/crates/renderer/src/render_graph/recorder.rs @@ -105,6 +105,7 @@ pub struct CommandList { num_commands: u32, } +#[must_use] pub struct RenderPass<'a> { cmd_list: &'a mut CommandList, } @@ -131,9 +132,9 @@ impl CommandList { pub fn begin_rendering( &mut self, - color_attachments: Vec>, - depth_attachment: Option>, - stencil_attachment: Option>, + color_attachments: Vec, + depth_attachment: Option, + stencil_attachment: Option, area: (u32, u32), layers: u32, ) -> RenderPass<'_> { diff --git a/crates/renderer/src/render_graph/resources.rs b/crates/renderer/src/render_graph/resources.rs index cce057f..ac6ac58 100644 --- a/crates/renderer/src/render_graph/resources.rs +++ b/crates/renderer/src/render_graph/resources.rs @@ -262,7 +262,7 @@ pub struct Pipeline; pub struct DescriptorSet; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] -pub struct ResourceId(u32); +pub struct ResourceId(pub u32); #[derive(Debug, Default, Clone, Copy)] pub struct ResourceAccess { @@ -497,8 +497,21 @@ impl TextureRange { } } -pub struct Buffer(ResourceId); -pub struct Texture(ResourceId); +pub struct Buffer(pub ResourceId); + +impl Buffer { + pub fn full_slice(self) -> BufferSlice { + BufferSlice { + buffer: self, + range: BufferRange { + offset: 0, + size: u64::MAX, + }, + } + } +} + +pub struct Texture(pub ResourceId); pub struct BufferSlice { pub buffer: Buffer,