1use arrayvec::ArrayVec;
9use base::Epoch;
10use base::generic_channel::{
11 GenericCallback, GenericOneshotSender, GenericSender, GenericSharedMemory,
12};
13use base::id::PipelineId;
14use pixels::SharedSnapshot;
15use serde::{Deserialize, Serialize};
16use webrender_api::ImageKey;
17use webrender_api::euclid::default::Size2D;
18use webrender_api::units::DeviceIntSize;
19use wgpu_core::Label;
20use wgpu_core::binding_model::{
21 BindGroupDescriptor, BindGroupLayoutDescriptor, PipelineLayoutDescriptor,
22};
23use wgpu_core::command::{
24 RenderBundleDescriptor, RenderBundleEncoder, RenderPassColorAttachment,
25 RenderPassDepthStencilAttachment, TexelCopyBufferInfo, TexelCopyTextureInfo,
26};
27use wgpu_core::device::HostMap;
28pub use wgpu_core::id::markers::{
29 ComputePassEncoder as ComputePass, RenderPassEncoder as RenderPass,
30};
31use wgpu_core::id::{
32 AdapterId, BindGroupId, BindGroupLayoutId, BufferId, CommandBufferId, CommandEncoderId,
33 ComputePassEncoderId, ComputePipelineId, DeviceId, PipelineLayoutId, QuerySetId, QueueId,
34 RenderBundleId, RenderPassEncoderId, RenderPipelineId, SamplerId, ShaderModuleId, TextureId,
35 TextureViewId,
36};
37pub use wgpu_core::id::{
38 ComputePassEncoderId as ComputePassId, RenderPassEncoderId as RenderPassId,
39};
40use wgpu_core::instance::RequestAdapterOptions;
41use wgpu_core::pipeline::{ComputePipelineDescriptor, RenderPipelineDescriptor};
42use wgpu_core::resource::{
43 BufferAccessError, BufferDescriptor, SamplerDescriptor, TextureDescriptor,
44 TextureViewDescriptor,
45};
46use wgpu_types::{
47 BufferAddress, CommandBufferDescriptor, CommandEncoderDescriptor, DeviceDescriptor, Extent3d,
48 TexelCopyBufferLayout,
49};
50
51use crate::{
52 ContextConfiguration, Error, ErrorFilter, Mapping, PRESENTATION_BUFFER_COUNT, RenderCommand,
53 ShaderCompilationInfo, WebGPUAdapter, WebGPUAdapterResponse, WebGPUComputePipelineResponse,
54 WebGPUContextId, WebGPUDeviceResponse, WebGPUPoppedErrorScopeResponse,
55 WebGPURenderPipelineResponse,
56};
57
58#[derive(Debug, Deserialize, Serialize)]
59pub struct PendingTexture {
60 pub texture_id: TextureId,
61 pub encoder_id: CommandEncoderId,
62 pub configuration: ContextConfiguration,
63}
64
65#[derive(Debug, Deserialize, Serialize)]
66pub enum WebGPURequest {
67 SetImageKey {
68 context_id: WebGPUContextId,
69 image_key: ImageKey,
70 },
71 BufferMapAsync {
72 callback: GenericCallback<Result<Mapping, BufferAccessError>>,
73 buffer_id: BufferId,
74 device_id: DeviceId,
75 host_map: HostMap,
76 offset: u64,
77 size: Option<u64>,
78 },
79 CommandEncoderFinish {
80 command_encoder_id: CommandEncoderId,
81 device_id: DeviceId,
82 desc: CommandBufferDescriptor<Label<'static>>,
83 },
84 CopyBufferToBuffer {
85 command_encoder_id: CommandEncoderId,
86 source_id: BufferId,
87 source_offset: BufferAddress,
88 destination_id: BufferId,
89 destination_offset: BufferAddress,
90 size: BufferAddress,
91 },
92 CopyBufferToTexture {
93 command_encoder_id: CommandEncoderId,
94 source: TexelCopyBufferInfo,
95 destination: TexelCopyTextureInfo,
96 copy_size: Extent3d,
97 },
98 CopyTextureToBuffer {
99 command_encoder_id: CommandEncoderId,
100 source: TexelCopyTextureInfo,
101 destination: TexelCopyBufferInfo,
102 copy_size: Extent3d,
103 },
104 CopyTextureToTexture {
105 command_encoder_id: CommandEncoderId,
106 source: TexelCopyTextureInfo,
107 destination: TexelCopyTextureInfo,
108 copy_size: Extent3d,
109 },
110 CreateBindGroup {
111 device_id: DeviceId,
112 bind_group_id: BindGroupId,
113 descriptor: BindGroupDescriptor<'static>,
114 },
115 CreateBindGroupLayout {
116 device_id: DeviceId,
117 bind_group_layout_id: BindGroupLayoutId,
118 descriptor: Option<BindGroupLayoutDescriptor<'static>>,
119 },
120 CreateBuffer {
121 device_id: DeviceId,
122 buffer_id: BufferId,
123 descriptor: BufferDescriptor<'static>,
124 },
125 CreateCommandEncoder {
126 device_id: DeviceId,
127 command_encoder_id: CommandEncoderId,
128 desc: CommandEncoderDescriptor<Label<'static>>,
129 },
130 CreateComputePipeline {
131 device_id: DeviceId,
132 compute_pipeline_id: ComputePipelineId,
133 descriptor: ComputePipelineDescriptor<'static>,
134 implicit_ids: Option<(PipelineLayoutId, Vec<BindGroupLayoutId>)>,
135 async_sender: Option<GenericCallback<WebGPUComputePipelineResponse>>,
137 },
138 CreatePipelineLayout {
139 device_id: DeviceId,
140 pipeline_layout_id: PipelineLayoutId,
141 descriptor: PipelineLayoutDescriptor<'static>,
142 },
143 CreateRenderPipeline {
144 device_id: DeviceId,
145 render_pipeline_id: RenderPipelineId,
146 descriptor: RenderPipelineDescriptor<'static>,
147 implicit_ids: Option<(PipelineLayoutId, Vec<BindGroupLayoutId>)>,
148 async_sender: Option<GenericCallback<WebGPURenderPipelineResponse>>,
150 },
151 CreateSampler {
152 device_id: DeviceId,
153 sampler_id: SamplerId,
154 descriptor: SamplerDescriptor<'static>,
155 },
156 CreateShaderModule {
157 device_id: DeviceId,
158 program_id: ShaderModuleId,
159 program: String,
160 label: Option<String>,
161 callback: GenericCallback<Option<ShaderCompilationInfo>>,
162 },
163 CreateContext {
165 buffer_ids: ArrayVec<BufferId, PRESENTATION_BUFFER_COUNT>,
166 size: DeviceIntSize,
167 sender: GenericSender<WebGPUContextId>,
168 },
169 Present {
171 context_id: WebGPUContextId,
172 pending_texture: Option<PendingTexture>,
173 size: Size2D<u32>,
174 canvas_epoch: Epoch,
175 },
176 GetImage {
179 context_id: WebGPUContextId,
180 pending_texture: Option<PendingTexture>,
181 sender: GenericSender<SharedSnapshot>,
182 },
183 ValidateTextureDescriptor {
184 device_id: DeviceId,
185 texture_id: TextureId,
186 descriptor: TextureDescriptor<'static>,
187 },
188 DestroyContext {
189 context_id: WebGPUContextId,
190 },
191 CreateTexture {
192 device_id: DeviceId,
193 texture_id: TextureId,
194 descriptor: TextureDescriptor<'static>,
195 },
196 CreateTextureView {
197 texture_id: TextureId,
198 texture_view_id: TextureViewId,
199 device_id: DeviceId,
200 descriptor: Option<TextureViewDescriptor<'static>>,
201 },
202 DestroyBuffer(BufferId),
203 DestroyDevice(DeviceId),
204 DestroyTexture(TextureId),
205 DropTexture(TextureId),
206 DropAdapter(AdapterId),
207 DropDevice(DeviceId),
208 DropBuffer(BufferId),
209 DropPipelineLayout(PipelineLayoutId),
210 DropComputePipeline(ComputePipelineId),
211 DropRenderPipeline(RenderPipelineId),
212 DropBindGroup(BindGroupId),
213 DropBindGroupLayout(BindGroupLayoutId),
214 DropCommandBuffer(CommandBufferId),
215 DropTextureView(TextureViewId),
216 DropSampler(SamplerId),
217 DropShaderModule(ShaderModuleId),
218 DropRenderBundle(RenderBundleId),
219 DropQuerySet(QuerySetId),
220 DropComputePass(ComputePassEncoderId),
221 DropRenderPass(RenderPassEncoderId),
222 Exit(GenericOneshotSender<()>),
223 RenderBundleEncoderFinish {
224 render_bundle_encoder: RenderBundleEncoder,
225 descriptor: RenderBundleDescriptor<'static>,
226 render_bundle_id: RenderBundleId,
227 device_id: DeviceId,
228 },
229 RequestAdapter {
230 sender: GenericCallback<WebGPUAdapterResponse>,
231 options: RequestAdapterOptions,
232 adapter_id: AdapterId,
233 },
234 RequestDevice {
235 sender: GenericCallback<WebGPUDeviceResponse>,
236 adapter_id: WebGPUAdapter,
237 descriptor: DeviceDescriptor<Option<String>>,
238 device_id: DeviceId,
239 queue_id: QueueId,
240 pipeline_id: PipelineId,
241 },
242 BeginComputePass {
244 command_encoder_id: CommandEncoderId,
245 compute_pass_id: ComputePassId,
246 label: Label<'static>,
247 device_id: DeviceId,
248 },
249 ComputePassSetPipeline {
250 compute_pass_id: ComputePassId,
251 pipeline_id: ComputePipelineId,
252 device_id: DeviceId,
253 },
254 ComputePassSetBindGroup {
255 compute_pass_id: ComputePassId,
256 index: u32,
257 bind_group_id: BindGroupId,
258 offsets: Vec<u32>,
259 device_id: DeviceId,
260 },
261 ComputePassDispatchWorkgroups {
262 compute_pass_id: ComputePassId,
263 x: u32,
264 y: u32,
265 z: u32,
266 device_id: DeviceId,
267 },
268 ComputePassDispatchWorkgroupsIndirect {
269 compute_pass_id: ComputePassId,
270 buffer_id: BufferId,
271 offset: u64,
272 device_id: DeviceId,
273 },
274 EndComputePass {
275 compute_pass_id: ComputePassId,
276 device_id: DeviceId,
277 command_encoder_id: CommandEncoderId,
278 },
279 BeginRenderPass {
281 command_encoder_id: CommandEncoderId,
282 render_pass_id: RenderPassId,
283 label: Label<'static>,
284 color_attachments: Vec<Option<RenderPassColorAttachment>>,
285 depth_stencil_attachment: Option<RenderPassDepthStencilAttachment>,
286 device_id: DeviceId,
287 },
288 RenderPassCommand {
289 render_pass_id: RenderPassId,
290 render_command: RenderCommand,
291 device_id: DeviceId,
292 },
293 EndRenderPass {
294 render_pass_id: RenderPassId,
295 device_id: DeviceId,
296 command_encoder_id: CommandEncoderId,
297 },
298 Submit {
299 device_id: DeviceId,
300 queue_id: QueueId,
301 command_buffers: Vec<CommandBufferId>,
302 },
303 UnmapBuffer {
304 buffer_id: BufferId,
305 mapping: Option<Mapping>,
307 },
308 WriteBuffer {
309 device_id: DeviceId,
310 queue_id: QueueId,
311 buffer_id: BufferId,
312 buffer_offset: u64,
313 data: GenericSharedMemory,
314 },
315 WriteTexture {
316 device_id: DeviceId,
317 queue_id: QueueId,
318 texture_cv: TexelCopyTextureInfo,
319 data_layout: TexelCopyBufferLayout,
320 size: Extent3d,
321 data: GenericSharedMemory,
322 },
323 QueueOnSubmittedWorkDone {
324 sender: GenericCallback<()>,
325 queue_id: QueueId,
326 },
327 PushErrorScope {
328 device_id: DeviceId,
329 filter: ErrorFilter,
330 },
331 DispatchError {
332 device_id: DeviceId,
333 error: Error,
334 },
335 PopErrorScope {
336 device_id: DeviceId,
337 callback: GenericCallback<WebGPUPoppedErrorScopeResponse>,
338 },
339 ComputeGetBindGroupLayout {
340 device_id: DeviceId,
341 pipeline_id: ComputePipelineId,
342 index: u32,
343 id: BindGroupLayoutId,
344 },
345 RenderGetBindGroupLayout {
346 device_id: DeviceId,
347 pipeline_id: RenderPipelineId,
348 index: u32,
349 id: BindGroupLayoutId,
350 },
351}