Search code examples
webgpuwgsl

WebGPU WGLSL error occurs following outdated tutorials: "access mode 'write' is not valid for the 'storage' address space"


Note: I've answered my own question here, and am posting so that others in the same situation may benefit.

I was following along with various WebGPU tutorials, in particular for compute shaders, these articles in particular: https://web.dev/gpu-compute/ and https://surma.dev/things/webgpu/ -- and obviously the WebGPU specifications have been adjusted since these articles were last updated.

The first error I encountered, was in WGSL, that @stage(compute) had been deprecated in favor of @compute -- this was an easy fix :)

However, the next error, had me stumped:

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]).

Another message was also output:

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;

Solution

  • The fix is simply replacing the following WGSL line:

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

    With the following fix:

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

    I managed to figure this out based on a table in this section of the WGSL specification