1use std::{fmt::Debug, hash::Hash};
2
3pub trait ResourceDevice {
4 type Buffer: Send + Sync + Clone + Copy + Debug + Hash + PartialEq;
5 type Texture: Send + Sync + Clone + Copy + Debug + Hash + PartialEq;
6 type TextureView: Send + Sync + Clone + Copy + Debug + Hash + PartialEq;
7 type Sampler: Send + Sync + Clone + Copy + Debug + Hash + PartialEq;
8 type AccelerationStructure: Send + Sync + Clone + Copy + Debug + Hash + PartialEq;
9
10 fn create_buffer(&self, desc: super::BufferDesc) -> Self::Buffer;
11 fn sync_buffer(&self, buffer: Self::Buffer);
12 fn destroy_buffer(&self, buffer: Self::Buffer);
13 fn create_texture(&self, desc: super::TextureDesc) -> Self::Texture;
14 fn destroy_texture(&self, texture: Self::Texture);
15 fn create_texture_view(
16 &self,
17 texture: Self::Texture,
18 desc: super::TextureViewDesc,
19 ) -> Self::TextureView;
20 fn destroy_texture_view(&self, view: Self::TextureView);
21 fn create_sampler(&self, desc: super::SamplerDesc) -> Self::Sampler;
22 fn destroy_sampler(&self, sampler: Self::Sampler);
23 fn create_acceleration_structure(
24 &self,
25 desc: super::AccelerationStructureDesc,
26 ) -> Self::AccelerationStructure;
27 fn destroy_acceleration_structure(&self, acceleration_structure: Self::AccelerationStructure);
28}
29
30pub trait ShaderDevice {
31 type ComputePipeline: Send + Sync;
32 type RenderPipeline: Send + Sync;
33
34 fn create_compute_pipeline(&self, desc: super::ComputePipelineDesc) -> Self::ComputePipeline;
35 fn destroy_compute_pipeline(&self, pipeline: &mut Self::ComputePipeline);
36 fn create_render_pipeline(&self, desc: super::RenderPipelineDesc) -> Self::RenderPipeline;
37 fn destroy_render_pipeline(&self, pipeline: &mut Self::RenderPipeline);
38}
39
40pub trait CommandDevice {
41 type CommandEncoder;
42 type SyncPoint: Clone + Debug;
43
44 fn create_command_encoder(&self, desc: super::CommandEncoderDesc) -> Self::CommandEncoder;
45 fn destroy_command_encoder(&self, encoder: &mut Self::CommandEncoder);
46 fn submit(&self, encoder: &mut Self::CommandEncoder) -> Self::SyncPoint;
47 fn wait_for(&self, sp: &Self::SyncPoint, timeout_ms: u32) -> bool;
48}
49
50pub trait CommandEncoder {
51 type Texture: Send + Sync + Clone + Copy + Debug;
52 type Frame: Send + Sync + Debug;
53 fn start(&mut self);
54 fn init_texture(&mut self, texture: Self::Texture);
55 fn present(&mut self, frame: Self::Frame);
56 fn timings(&self) -> &super::Timings;
57}
58
59pub trait TransferEncoder {
60 type BufferPiece: Send + Sync + Clone + Copy + Debug;
61 type TexturePiece: Send + Sync + Clone + Copy + Debug;
62
63 fn fill_buffer(&mut self, dst: Self::BufferPiece, size: u64, value: u8);
64 fn copy_buffer_to_buffer(&mut self, src: Self::BufferPiece, dst: Self::BufferPiece, size: u64);
65 fn copy_texture_to_texture(
66 &mut self,
67 src: Self::TexturePiece,
68 dst: Self::TexturePiece,
69 size: super::Extent,
70 );
71
72 fn copy_buffer_to_texture(
73 &mut self,
74 src: Self::BufferPiece,
75 bytes_per_row: u32,
76 dst: Self::TexturePiece,
77 size: super::Extent,
78 );
79
80 fn copy_texture_to_buffer(
81 &mut self,
82 src: Self::TexturePiece,
83 dst: Self::BufferPiece,
84 bytes_per_row: u32,
85 size: super::Extent,
86 );
87}
88
89pub trait AccelerationStructureEncoder {
90 type AccelerationStructure: Send + Sync + Clone + Debug;
91 type AccelerationStructureMesh: Send + Sync + Clone + Debug;
92 type BufferPiece: Send + Sync + Clone + Copy + Debug;
93
94 fn build_bottom_level(
95 &mut self,
96 acceleration_structure: Self::AccelerationStructure,
97 meshes: &[Self::AccelerationStructureMesh],
98 scratch_data: Self::BufferPiece,
99 );
100
101 fn build_top_level(
102 &mut self,
103 acceleration_structure: Self::AccelerationStructure,
104 bottom_level: &[Self::AccelerationStructure],
105 instance_count: u32,
106 instance_data: Self::BufferPiece,
107 scratch_data: Self::BufferPiece,
108 );
109}
110
111pub trait RenderEncoder {
112 fn set_scissor_rect(&mut self, rect: &super::ScissorRect);
113 fn set_viewport(&mut self, viewport: &super::Viewport);
114 fn set_stencil_reference(&mut self, reference: u32);
115}
116
117pub trait PipelineEncoder {
118 fn bind<D: super::ShaderData>(&mut self, group: u32, data: &D);
119}
120
121pub trait ComputePipelineEncoder: PipelineEncoder {
122 type BufferPiece: Send + Sync + Clone + Copy + Debug;
123
124 fn dispatch(&mut self, groups: [u32; 3]);
125 fn dispatch_indirect(&mut self, indirect_buf: Self::BufferPiece);
126}
127
128pub trait RenderPipelineEncoder: PipelineEncoder + RenderEncoder {
129 type BufferPiece: Send + Sync + Clone + Copy + Debug;
130
131 fn bind_vertex(&mut self, index: u32, vertex_buf: Self::BufferPiece);
133 fn draw(
134 &mut self,
135 first_vertex: u32,
136 vertex_count: u32,
137 first_instance: u32,
138 instance_count: u32,
139 );
140 fn draw_indexed(
141 &mut self,
142 index_buf: Self::BufferPiece,
143 index_type: super::IndexType,
144 index_count: u32,
145 base_vertex: i32,
146 start_instance: u32,
147 instance_count: u32,
148 );
149 fn draw_indirect(&mut self, indirect_buf: Self::BufferPiece);
150 fn draw_indexed_indirect(
151 &mut self,
152 index_buf: Self::BufferPiece,
153 index_type: crate::IndexType,
154 indirect_buf: Self::BufferPiece,
155 );
156}