You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

遵循旧WebGPU教程遇WGSL错误:storage地址空间不支持write访问模式

WebGPU WGSL编译错误:storage地址空间的write访问模式无效

问题背景

学习WebGPU计算着色器时,参考旧教程编写代码,因WebGPU规范更新遇到两处兼容性问题:

  • 旧语法@stage(compute)已被@compute替代(该问题已自行解决)
  • 出现WGSL编译错误,具体报错信息如下:
Tint WGSL reader failure: :9:46 error: access mode 'write' is not valid for the 'storage' address space
      @group(0) @binding(2) var<storage, write> resultMatrix : Matrix;
                                                ^^^^^^^^^^^^

 - While validating [ShaderModuleDescriptor]
 - While calling [Device].CreateShaderModule([ShaderModuleDescriptor]).
1 error(s) generated while compiling the shader:
:9:46 error: access mode 'write' is not valid for the 'storage' address space
      @group(0) @binding(2) var<storage, write> resultMatrix : Matrix;

解决方法

WebGPU规范更新后,WGSL对storage地址空间的访问模式做了调整:不再支持单独的write访问标识,需根据实际需求替换为对应的访问模式:

  • 若需要读写权限(或仅写入权限):使用read_write
  • 若仅需读取权限:使用read

修改后的代码示例:

@group(0) @binding(2) var<storage, read_write> resultMatrix : Matrix;

内容的提问来源于stack exchange,提问作者ChaseMoskal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 17:15:58