Generally, allocating new memory may expose the leftover data of other applications running on the system. In order to address that, WebGPU conceptually initializes all the resources to zero, although in practice an implementation may skip this step if it sees the developer initializing the contents manually. This includes variables and shared workgroup memory inside shaders.
通常,分配新内存可能会暴露系统上运行的其他应用程序的剩余数据。为了解决这一问题,WebGPU在概念上将所有资源初始化为零,尽管在实践中,如果看到开发人员手动初始化内容,则实现可能会跳过此步骤。这包括着色器中的变量和共享工作组内存。
The precise mechanism of clearing the workgroup memory can differ between platforms. If the native API does not provide facilities to clear it, the WebGPU implementation transforms the compute shader to first do a clear across all invocations, synchronize them, and continue executing developer’s code.
精确清除工作组内存的机制可能因平台而异。如果本机API不提供清除功能,WebGPU实现会将计算着色器转换为首先在所有调用中执行清除,同步它们,然后继续执行开发人员的代码。