1use crate::resource::*;
5use crate::types::*;
6
7pub struct GpuCommandEncoder {
11 inner: wgpu::CommandEncoder,
12}
13
14impl GpuCommandEncoder {
15 pub(crate) fn from_raw(inner: wgpu::CommandEncoder) -> Self {
16 Self { inner }
17 }
18
19 pub fn begin_render_pass<'a>(
21 &'a mut self,
22 desc: &wgpu::RenderPassDescriptor<'a>,
23 ) -> GpuRenderPass<'a> {
24 let inner = self.inner.begin_render_pass(desc);
25 GpuRenderPass::from_raw(inner)
26 }
27
28 pub fn begin_compute_pass(
30 &mut self,
31 desc: &wgpu::ComputePassDescriptor<'_>,
32 ) -> GpuComputePass<'_> {
33 let inner = self.inner.begin_compute_pass(desc);
34 GpuComputePass::from_raw(inner)
35 }
36
37 pub fn copy_buffer_to_buffer(
39 &mut self,
40 source: &GpuBuffer,
41 source_offset: BufferAddress,
42 destination: &GpuBuffer,
43 destination_offset: BufferAddress,
44 size: BufferAddress,
45 ) {
46 self.inner.copy_buffer_to_buffer(
47 source.raw(),
48 source_offset,
49 destination.raw(),
50 destination_offset,
51 size,
52 );
53 }
54
55 pub fn copy_buffer_to_texture(
57 &mut self,
58 source: wgpu::TexelCopyBufferInfo<'_>,
59 destination: wgpu::TexelCopyTextureInfo<'_>,
60 copy_size: Extent3d,
61 ) {
62 self.inner
63 .copy_buffer_to_texture(source, destination, copy_size);
64 }
65
66 pub fn copy_texture_to_buffer(
68 &mut self,
69 source: wgpu::TexelCopyTextureInfo<'_>,
70 destination: wgpu::TexelCopyBufferInfo<'_>,
71 copy_size: Extent3d,
72 ) {
73 self.inner
74 .copy_texture_to_buffer(source, destination, copy_size);
75 }
76
77 pub fn copy_texture_to_texture(
79 &mut self,
80 source: wgpu::TexelCopyTextureInfo<'_>,
81 destination: wgpu::TexelCopyTextureInfo<'_>,
82 copy_size: Extent3d,
83 ) {
84 self.inner
85 .copy_texture_to_texture(source, destination, copy_size);
86 }
87
88 pub fn finish(self) -> GpuCommandBuffer {
90 GpuCommandBuffer {
91 inner: self.inner.finish(),
92 }
93 }
94
95 pub fn raw(&self) -> &wgpu::CommandEncoder {
97 &self.inner
98 }
99
100 pub fn raw_mut(&mut self) -> &mut wgpu::CommandEncoder {
102 &mut self.inner
103 }
104}
105
106pub struct GpuCommandBuffer {
110 pub(crate) inner: wgpu::CommandBuffer,
111}
112
113impl GpuCommandBuffer {
114 pub fn into_inner(self) -> wgpu::CommandBuffer {
116 self.inner
117 }
118 pub fn raw(self) -> wgpu::CommandBuffer {
120 self.inner
121 }
122}
123
124pub struct GpuRenderPass<'a> {
128 inner: wgpu::RenderPass<'a>,
129}
130
131impl<'a> GpuRenderPass<'a> {
132 pub(crate) fn from_raw(inner: wgpu::RenderPass<'a>) -> Self {
133 Self { inner }
134 }
135
136 pub fn set_pipeline(&mut self, pipeline: &'a GpuRenderPipeline) {
138 self.inner.set_pipeline(pipeline.raw());
139 }
140
141 pub fn set_bind_group(&mut self, index: u32, bind_group: &'a GpuBindGroup, offsets: &[u32]) {
143 self.inner.set_bind_group(index, bind_group.raw(), offsets);
144 }
145
146 pub fn set_vertex_buffer(&mut self, slot: u32, buffer: &'a GpuBuffer) {
148 self.inner.set_vertex_buffer(slot, buffer.raw().slice(..));
149 }
150
151 pub fn set_vertex_buffer_range(&mut self, slot: u32, buffer_slice: wgpu::BufferSlice<'a>) {
153 self.inner.set_vertex_buffer(slot, buffer_slice);
154 }
155
156 pub fn set_index_buffer(&mut self, buffer: &'a GpuBuffer, format: IndexFormat) {
158 self.inner.set_index_buffer(buffer.raw().slice(..), format);
159 }
160
161 pub fn set_index_buffer_range(
163 &mut self,
164 buffer_slice: wgpu::BufferSlice<'a>,
165 format: IndexFormat,
166 ) {
167 self.inner.set_index_buffer(buffer_slice, format);
168 }
169
170 pub fn draw(&mut self, vertices: std::ops::Range<u32>, instances: std::ops::Range<u32>) {
172 self.inner.draw(vertices, instances);
173 }
174
175 pub fn draw_indexed(
177 &mut self,
178 indices: std::ops::Range<u32>,
179 base_vertex: i32,
180 instances: std::ops::Range<u32>,
181 ) {
182 self.inner.draw_indexed(indices, base_vertex, instances);
183 }
184
185 pub fn draw_indirect(&mut self, buffer: &'a GpuBuffer, offset: BufferAddress) {
187 self.inner.draw_indirect(buffer.raw(), offset);
188 }
189
190 pub fn draw_indexed_indirect(&mut self, buffer: &'a GpuBuffer, offset: BufferAddress) {
192 self.inner.draw_indexed_indirect(buffer.raw(), offset);
193 }
194
195 pub fn set_viewport(&mut self, x: f32, y: f32, w: f32, h: f32, min_depth: f32, max_depth: f32) {
197 self.inner.set_viewport(x, y, w, h, min_depth, max_depth);
198 }
199
200 pub fn set_scissor_rect(&mut self, x: u32, y: u32, w: u32, h: u32) {
202 self.inner.set_scissor_rect(x, y, w, h);
203 }
204
205 pub fn set_stencil_reference(&mut self, reference: u32) {
207 self.inner.set_stencil_reference(reference);
208 }
209
210 pub fn set_blend_constant(&mut self, color: Color) {
212 self.inner.set_blend_constant(color);
213 }
214
215 pub fn set_push_constants(&mut self, stages: ShaderStages, offset: u32, data: &[u8]) {
217 self.inner.set_push_constants(stages, offset, data);
218 }
219
220 pub fn raw(&self) -> &wgpu::RenderPass<'a> {
222 &self.inner
223 }
224
225 pub fn raw_mut(&mut self) -> &mut wgpu::RenderPass<'a> {
227 &mut self.inner
228 }
229}
230
231pub struct GpuComputePass<'a> {
235 inner: wgpu::ComputePass<'a>,
236}
237
238impl<'a> GpuComputePass<'a> {
239 pub(crate) fn from_raw(inner: wgpu::ComputePass<'a>) -> Self {
240 Self { inner }
241 }
242
243 pub fn set_pipeline(&mut self, pipeline: &'a GpuComputePipeline) {
245 self.inner.set_pipeline(pipeline.raw());
246 }
247
248 pub fn set_bind_group(&mut self, index: u32, bind_group: &'a GpuBindGroup, offsets: &[u32]) {
250 self.inner.set_bind_group(index, bind_group.raw(), offsets);
251 }
252
253 pub fn dispatch_workgroups(&mut self, x: u32, y: u32, z: u32) {
255 self.inner.dispatch_workgroups(x, y, z);
256 }
257
258 pub fn dispatch_workgroups_indirect(&mut self, buffer: &'a GpuBuffer, offset: BufferAddress) {
260 self.inner
261 .dispatch_workgroups_indirect(buffer.raw(), offset);
262 }
263
264 pub fn set_push_constants(&mut self, offset: u32, data: &[u8]) {
266 self.inner.set_push_constants(offset, data);
267 }
268
269 pub fn raw(&self) -> &wgpu::ComputePass<'a> {
271 &self.inner
272 }
273
274 pub fn raw_mut(&mut self) -> &mut wgpu::ComputePass<'a> {
276 &mut self.inner
277 }
278}