Once a GPUDevice has been obtained during an application initialization routine, we can describe the WebGPU platform as consisting of the following layers:
- User agent implementing the specification.
- Operating system with low-level native API drivers for this device.
- Actual CPU and GPU hardware.
在应用程序初始化例程中获得GPU设备后,我们可以将WebGPU平台描述为由以下层组成:
- 实现规范的用户代理。
- 此设备具有低级本机API驱动的操作系统。
- 实际的CPU和GPU硬件。
Each layer of the WebGPU platform may have different memory types that the user agent needs to consider when implementing the specification:
- The script-owned memory, such as an ArrayBuffer created by the script, is generally not accessible by a GPU driver.
- A user agent may have different processes responsible for running the content and communication to the GPU driver. In this case, it uses inter-process shared memory to transfer data.
- Dedicated GPUs have their own memory with high bandwidth, while integrated GPUs typically share memory with the system.
WebGPU平台的每一层可能有不同的内存类型,用户代理在执行规范时需要考虑:
- 脚本拥有的内存(如脚本创建的ArrayBuffer)通常不可由GPU驱动程序访问。
- 用户代理可以具有负责运行内容和与GPU驱动程序通信的不同进程。在这种情况下,它使用进程间共享内存来传输数据。
- 专用GPU拥有自己的高带宽内存,而集成GPU通常与系统共享内存。
Most physical resources are allocated in the memory of type that is efficient for computation or rendering by the GPU. When the user needs to provide new data to the GPU, the data may first need to cross the process boundary in order to reach the user agent part that communicates with the GPU driver. Then it may need to be made visible to the driver, which sometimes requires a copy into driver-allocated staging memory. Finally, it may need to be transferred to the dedicated GPU memory, potentially changing the internal layout into one that is most efficient for GPUs to operate on.
大多数物理资源都分配在GPU高效计算或渲染的内存中。当用户需要向GPU提供新数据时,数据可能首先需要跨越进程边界以到达与GPU驱动程序通信的用户代理部分。然后可能需要使其对驱动程序可见,这有时需要将副本复制到驱动程序分配的暂存内存中。最后,可能需要将其传输到专用GPU内存,从而可能会将内部布局更改为GPU操作最有效的布局。
All of these transitions are done by the WebGPU implementation of the user agent.
所有这些转换都由用户代理的WebGPU实现完成。
Note: This example describes the worst case, while in practice the implementation may not need to cross the process boundary, or may be able to expose the driver-managed memory directly to the user behind an ArrayBuffer, thus avoiding any data copies.
注: 本例描述了最坏的情况,而实际上实现可能不需要跨越进程边界,或者可能能够将驱动程序管理的内存直接暴露给ArrayBuffer后面的用户,从而避免任何数据拷贝。