webgpu_traits/messages/
recv.rs

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