遵循旧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
相关产品推荐
相关产品推荐

