diff --git a/blade-graphics/src/derive.rs b/blade-graphics/src/derive.rs index 12906e09..6fabfb31 100644 --- a/blade-graphics/src/derive.rs +++ b/blade-graphics/src/derive.rs @@ -2,7 +2,7 @@ use std::mem; use super::{ResourceIndex, ShaderBinding, VertexFormat}; -pub trait HasShaderBinding: super::ShaderBindable { +pub trait HasShaderBinding { const TYPE: ShaderBinding; } impl HasShaderBinding for T { diff --git a/blade-graphics/src/gles/command.rs b/blade-graphics/src/gles/command.rs index 2159057e..0e2d6470 100644 --- a/blade-graphics/src/gles/command.rs +++ b/blade-graphics/src/gles/command.rs @@ -271,6 +271,9 @@ impl Drop for super::PassEncoder<'_, T> { #[hidden_trait::expose] impl crate::traits::TransferEncoder for super::PassEncoder<'_, ()> { + type BufferPiece = crate::BufferPiece; + type TexturePiece = crate::TexturePiece; + fn fill_buffer(&mut self, dst: crate::BufferPiece, size: u64, value: u8) { self.commands.push(super::Command::FillBuffer { dst: dst.into(), @@ -337,6 +340,10 @@ impl crate::traits::TransferEncoder for super::PassEncoder<'_, ()> { #[hidden_trait::expose] impl crate::traits::AccelerationStructureEncoder for super::PassEncoder<'_, ()> { + type AccelerationStructure = crate::AccelerationStructure; + type AccelerationStructureMesh = crate::AccelerationStructureMesh; + type BufferPiece = crate::BufferPiece; + fn build_bottom_level( &mut self, _acceleration_structure: super::AccelerationStructure, @@ -379,6 +386,8 @@ impl crate::traits::ComputePipelineEncoder for super::PipelineEncoder<'_> { #[hidden_trait::expose] impl crate::traits::RenderPipelineEncoder for super::PipelineEncoder<'_> { + type BufferPiece = crate::BufferPiece; + fn set_scissor_rect(&mut self, rect: &crate::ScissorRect) { self.commands.push(super::Command::SetScissor(rect.clone())); } diff --git a/blade-graphics/src/lib.rs b/blade-graphics/src/lib.rs index 3976a7e1..32e1f16a 100644 --- a/blade-graphics/src/lib.rs +++ b/blade-graphics/src/lib.rs @@ -585,7 +585,7 @@ pub enum ShaderBinding { Plain { size: u32 }, } -pub trait ShaderBindable: Clone + Copy { +pub trait ShaderBindable: Clone + Copy + derive::HasShaderBinding { fn bind_to(&self, context: &mut PipelineContext, index: u32); } diff --git a/blade-graphics/src/metal/command.rs b/blade-graphics/src/metal/command.rs index fdcd2f07..20f9769d 100644 --- a/blade-graphics/src/metal/command.rs +++ b/blade-graphics/src/metal/command.rs @@ -221,6 +221,9 @@ impl super::CommandEncoder { #[hidden_trait::expose] impl crate::traits::TransferEncoder for super::TransferCommandEncoder<'_> { + type BufferPiece = crate::BufferPiece; + type TexturePiece = crate::TexturePiece; + fn fill_buffer(&mut self, dst: crate::BufferPiece, size: u64, value: u8) { let range = metal::NSRange { location: dst.offset, @@ -315,6 +318,10 @@ impl Drop for super::TransferCommandEncoder<'_> { impl crate::traits::AccelerationStructureEncoder for super::AccelerationStructureCommandEncoder<'_> { + type AccelerationStructure = crate::AccelerationStructure; + type AccelerationStructureMesh = crate::AccelerationStructureMesh; + type BufferPiece = crate::BufferPiece; + fn build_bottom_level( &mut self, acceleration_structure: super::AccelerationStructure, @@ -515,6 +522,8 @@ impl crate::traits::PipelineEncoder for super::RenderPipelineContext<'_> { #[hidden_trait::expose] impl crate::traits::RenderPipelineEncoder for super::RenderPipelineContext<'_> { + type BufferPiece = crate::BufferPiece; + fn set_scissor_rect(&mut self, rect: &crate::ScissorRect) { let scissor = metal::MTLScissorRect { x: rect.x as _, diff --git a/blade-graphics/src/traits.rs b/blade-graphics/src/traits.rs index 365127d3..d09013eb 100644 --- a/blade-graphics/src/traits.rs +++ b/blade-graphics/src/traits.rs @@ -37,52 +37,54 @@ pub trait CommandDevice { } pub trait TransferEncoder { - fn fill_buffer(&mut self, dst: super::BufferPiece, size: u64, value: u8); - fn copy_buffer_to_buffer( - &mut self, - src: super::BufferPiece, - dst: super::BufferPiece, - size: u64, - ); + type BufferPiece: Send + Sync + Clone + Copy + Debug; + type TexturePiece: Send + Sync + Clone + Copy + Debug; + + fn fill_buffer(&mut self, dst: Self::BufferPiece, size: u64, value: u8); + fn copy_buffer_to_buffer(&mut self, src: Self::BufferPiece, dst: Self::BufferPiece, size: u64); fn copy_texture_to_texture( &mut self, - src: super::TexturePiece, - dst: super::TexturePiece, + src: Self::TexturePiece, + dst: Self::TexturePiece, size: super::Extent, ); fn copy_buffer_to_texture( &mut self, - src: super::BufferPiece, + src: Self::BufferPiece, bytes_per_row: u32, - dst: super::TexturePiece, + dst: Self::TexturePiece, size: super::Extent, ); fn copy_texture_to_buffer( &mut self, - src: super::TexturePiece, - dst: super::BufferPiece, + src: Self::TexturePiece, + dst: Self::BufferPiece, bytes_per_row: u32, size: super::Extent, ); } pub trait AccelerationStructureEncoder { + type AccelerationStructure: Send + Sync + Clone + Debug; + type AccelerationStructureMesh: Send + Sync + Clone + Debug; + type BufferPiece: Send + Sync + Clone + Copy + Debug; + fn build_bottom_level( &mut self, - acceleration_structure: crate::AccelerationStructure, - meshes: &[super::AccelerationStructureMesh], - scratch_data: super::BufferPiece, + acceleration_structure: Self::AccelerationStructure, + meshes: &[Self::AccelerationStructureMesh], + scratch_data: Self::BufferPiece, ); fn build_top_level( &mut self, - acceleration_structure: crate::AccelerationStructure, - bottom_level: &[crate::AccelerationStructure], + acceleration_structure: Self::AccelerationStructure, + bottom_level: &[Self::AccelerationStructure], instance_count: u32, - instance_data: super::BufferPiece, - scratch_data: super::BufferPiece, + instance_data: Self::BufferPiece, + scratch_data: Self::BufferPiece, ); } @@ -95,9 +97,11 @@ pub trait ComputePipelineEncoder: PipelineEncoder { } pub trait RenderPipelineEncoder: PipelineEncoder { + type BufferPiece: Send + Sync + Clone + Copy + Debug; + //TODO: reconsider exposing this here fn set_scissor_rect(&mut self, rect: &super::ScissorRect); - fn bind_vertex(&mut self, index: u32, vertex_buf: super::BufferPiece); + fn bind_vertex(&mut self, index: u32, vertex_buf: Self::BufferPiece); fn draw( &mut self, first_vertex: u32, @@ -107,18 +111,18 @@ pub trait RenderPipelineEncoder: PipelineEncoder { ); fn draw_indexed( &mut self, - index_buf: super::BufferPiece, + index_buf: Self::BufferPiece, index_type: super::IndexType, index_count: u32, base_vertex: i32, start_instance: u32, instance_count: u32, ); - fn draw_indirect(&mut self, indirect_buf: super::BufferPiece); + fn draw_indirect(&mut self, indirect_buf: Self::BufferPiece); fn draw_indexed_indirect( &mut self, - index_buf: crate::BufferPiece, + index_buf: Self::BufferPiece, index_type: crate::IndexType, - indirect_buf: super::BufferPiece, + indirect_buf: Self::BufferPiece, ); } diff --git a/blade-graphics/src/vulkan/command.rs b/blade-graphics/src/vulkan/command.rs index b43f5203..1206d9b2 100644 --- a/blade-graphics/src/vulkan/command.rs +++ b/blade-graphics/src/vulkan/command.rs @@ -450,6 +450,9 @@ impl super::CommandEncoder { #[hidden_trait::expose] impl crate::traits::TransferEncoder for super::TransferCommandEncoder<'_> { + type BufferPiece = crate::BufferPiece; + type TexturePiece = crate::TexturePiece; + fn fill_buffer(&mut self, dst: crate::BufferPiece, size: u64, value: u8) { let value_u32 = (value as u32) * 0x1010101; unsafe { @@ -545,6 +548,10 @@ impl crate::traits::TransferEncoder for super::TransferCommandEncoder<'_> { impl crate::traits::AccelerationStructureEncoder for super::AccelerationStructureCommandEncoder<'_> { + type AccelerationStructure = crate::AccelerationStructure; + type AccelerationStructureMesh = crate::AccelerationStructureMesh; + type BufferPiece = crate::BufferPiece; + fn build_bottom_level( &mut self, acceleration_structure: super::AccelerationStructure, @@ -737,6 +744,8 @@ impl crate::traits::ComputePipelineEncoder for super::PipelineEncoder<'_, '_> { #[hidden_trait::expose] impl crate::traits::RenderPipelineEncoder for super::PipelineEncoder<'_, '_> { + type BufferPiece = crate::BufferPiece; + fn set_scissor_rect(&mut self, rect: &crate::ScissorRect) { let vk_scissor = vk::Rect2D { offset: vk::Offset2D {