Open Bug 1916072 (webgpu-threejs) Opened 2 years ago Updated 1 month ago

ThreeJS' examples' WebGPU backend don't work

Categories

(Core :: Graphics: WebGPU, defect)

defect

Tracking

()

People

(Reporter: ErichDonGubler, Unassigned)

References

(Depends on 2 open bugs, Blocks 1 open bug, )

Details

User Story

Status and triage notes: https://hackmd.io/qNR5JQJQRamArlF1G3neBA
No description provided.

Blockers I observed:

  • The vast majority of examples are blocked by failing to parse diagnostic directives (bug 1882800).
  • Many examples emitted errors because the GPUDevice.createQuerySet API is not yet exposed (bug 1838729). Many of these crashed after these errors were emitted many times over a few seconds. 😬
  • Automatic type conversion (bug 1829879)
  • compute / particles / snow / external seems to fail on a CORS error. 😳 Not sure if that's a bug on our end yet.
  • compute / texture / pingpong has some issues with a writeTex: texture_storage_2d<rgba16float, write> argument, not sure why yet.
  • Many examples emitted errors with GPUQueue.copyExternalImageToTexture: 'source' member of GPUImageCopyExternalImage could not be converted to any of: ImageBitmap, HTMLCanvasElement, OffscreenCanvas. (ETA: bug 1921454)
  • loader / gltf / compressed and many others emitted this error: GPUDevice.createTexture: 'etc2-rgb8unorm-srgb' (value of 'format' member of GPUTextureDescriptor) is not a valid value for enumeration GPUTextureFormat. (ETA: bug 1917059)

Ah, the texture_storage_2d<…, write> error must be that our implementation of WGSL doesn't yet support the readonly_and_readwrite_storage_textures extension. Filed bug 1916464 to track this.

Depends on: 1916464
See Also: → 1914934

Ah, the GPUQueue.copyExternalImageToTexture error is bug 1921454.

Depends on: 1921454

Ah, the etc2-rgb8unorm-srgb error is bug 1917059.

Depends on: 1917059
Depends on: 1914934

As part of Bug 1914934, I checked all the other examples (158 total), 19 are still failing:

Missing unrestricted_pointer_parameters language extension (https://github.com/gfx-rs/wgpu/issues/5158)

https://threejs.org/examples/?q=webgpu#webgpu_compute_texture_pingpong

Shader validation error: Function [3] 'computePingPongWGSL' is invalid
   β”Œβ”€ compute:48:1
   β”‚
48 β”‚ β•­ fn computePingPongWGSL ( readTex: texture_storage_2d<rgba16float, read>, writeTex: texture_storage_2d<rgba16float, write>, index: u32 )  {
   β”‚                                                                            ^^^^^^^^ naga::Expression [1]
49 β”‚ β”‚
50 β”‚ β”‚                         let posX = index % 512;
51 β”‚ β”‚                         let posY = index / 512;
   Β· β”‚
55 β”‚ β”‚
56 β”‚ β”‚                         textureStore( writeTex, indexUV, vec4f( color * 1.05, 1 ) );
   β”‚ ╰────────────────────────────────────────────────────────────────────────────────────^ naga::Function [3]
   β”‚
   = Image store parameters are invalid
   = Not a global variable

i32 constructor needs to support abstract floats (https://github.com/gfx-rs/wgpu/issues/7312)

https://threejs.org/examples/?q=webgpu#webgpu_lights_tiled

Shader 'fragment' parsing error: abstract floating-point values cannot be automatically converted to integers
    β”Œβ”€ wgsl:142:192
    β”‚
142 β”‚         nodeVar13 = textureLoad( nodeUniform13, vec2<i32>( ( lightIndexes.value[ u32( ( ( ( nodeVar2.x + ( nodeVar2.y * 46.0 ) ) * 2.0 ) + f32( ( ( i ) / 4 ) ) ) ) ][ u32( ( ( i ) % 4 ) ) ] - 1 ), i32( 0.0 ) ), u32( 0u ) );
    β”‚                                                                                                                                                                                                      ^^^^^^^^^^ see msg

Odd issue

https://threejs.org/examples/?q=webgpu#webgpu_materials

Spams console with:

Uncaught TypeError: can't access property "mipLevelCount", textureData.texture is undefined

However, if you reload the window a couple of times, it starts working; sounds like the example is trying to use the texture but it hasn't been loaded yet.

importExternalTexture is missing (needed for video frame import; Bug 1827116)

https://threejs.org/examples/?q=webgpu#webgpu_materials_video

Uncaught DOMException: VideoFrame constructor: The video is not ready yet
Uncaught TypeError: device.importExternalTexture is not a function

https://threejs.org/examples/?q=webgpu#webgpu_video_frame
https://threejs.org/examples/?q=webgpu#webgpu_video_panorama

Uncaught TypeError: device.importExternalTexture is not a function

Fixed recently by https://github.com/gfx-rs/wgpu/pull/7058, should work with the next wgpu update

https://threejs.org/examples/?q=webgpu#webgpu_custom_fog_background
https://threejs.org/examples/?q=webgpu#webgpu_postprocessing_dof
https://threejs.org/examples/?q=webgpu#webgpu_reflection
https://threejs.org/examples/?q=webgpu#webgpu_skinning_instancing

Shader validation error: Entry point main at Fragment is invalid
   β”Œβ”€ fragment_Gaussian_blur:77:13
   β”‚
77 β”‚     nodeVar3 = textureLoad( nodeUniform3, vec2<u32>(tsl_coord_clampS_clamp_2dT(nodeVarying3) * vec2<f32>(nodeVar4)), u32( 0 ) );
   β”‚                ^^^^^^^^^^^ naga::Expression [42]
   β”‚
   = Expression [42] is invalid
   = Image sample or level-of-detail index's type of [41] is not an integer scalar

indirect draw (https://github.com/gfx-rs/wgpu/pull/7140)

https://threejs.org/examples/?q=webgpu#webgpu_struct_drawindirect

Uncaught TypeError: passEncoderGPU.drawIndirect is not a function

https://threejs.org/examples/?q=webgpu#webgpu_particles

Uncaught TypeError: passEncoderGPU.drawIndexedIndirect is not a function

3D render attachments (https://github.com/gfx-rs/wgpu/issues/4764)

https://threejs.org/examples/?q=webgpu#webgpu_postprocessing_3dlut
https://threejs.org/examples/?q=webgpu#webgpu_rendertarget_2d-array_3d
https://threejs.org/examples/?q=webgpu#webgpu_volume_cloud
https://threejs.org/examples/?q=webgpu#webgpu_volume_lighting
https://threejs.org/examples/?q=webgpu#webgpu_volume_lighting_rectarea
https://threejs.org/examples/?q=webgpu#webgpu_volume_perlin

Uncaptured WebGPU error: Texture usages TextureUsages(RENDER_ATTACHMENT) are not allowed on a texture of dimensions D3

2D-array render attachments (https://github.com/gfx-rs/wgpu/issues/7313)

https://threejs.org/examples/?q=webgpu#webgpu_rendertarget_2d-array_3d

In a pass parameter, caused by: The color attachment at index 0's texture view is not renderable:, caused by: The dimension of this texture view is not 2D. View dimension: D2Array
Depends on: 1952975
Depends on: 1952976
Depends on: 1930972
Depends on: 1952979
Depends on: 1952980

I've made Bugzilla entries for each of the blockers in comment 5 that are definitely WGPU's fault, and added them to this bug's dependencies. That ought to help us prioritize those issues. πŸ™‚

Even with bug 1930972, https://threejs.org/examples/?q=webgpu#webgpu_struct_drawindirect fails with:


Shader validation error: Function [0] 'compute' is invalid
   β”Œβ”€ compute:27:1
   β”‚  
27 β”‚ β•­ fn compute ( drawBuffer: ptr< storage, DrawBuffer, read_write >, )  {
28 β”‚ β”‚ 
29 β”‚ β”‚                         drawBuffer.vertexCount = 3u;
30 β”‚ β”‚                         atomicStore(&drawBuffer.instanceCount, 0u);
31 β”‚ β”‚                         drawBuffer.firstVertex = 0u;
32 β”‚ β”‚                         drawBuffer.firstInstance = 0u;
33 β”‚ β”‚                         drawBuffer.offset = 0u;
   β”‚ ╰───────────────────────────────────────────────^ naga::ir::Function [0]
   β”‚  
   = Argument 'drawBuffer' at index 0 is a pointer of space Storage { access: StorageAccess(LOAD | STORE) }, which can't be passed into functions.

That is another instance of Bug 1952974.

Depends on: 1922097
No longer depends on: 1921454
Alias: webgpu-threejs

(In reply to Teodor Tanasoaia [:teoxoy] from comment #8)

That is another instance of Bug 1952974.

Should the upstream example be adjusted to check for this extension and fail more gracefully?

Also, is it possible to improve our error message so that it might be clearer what's going on?

Flags: needinfo?(ttanasoaia)

:jrmuizel:

Should the upstream example be adjusted to check for this extension and fail more gracefully?

Absolutely. If they used requires unrestricted_pointer_parameters; in their shaders, diagnostics would be better. This bad diagnostic experience is actually one of the downsides we considered at length in the GPU for Web committee in W3C; making it so one isn't required to opt into a language sure seemed and seems like a recipe for no web authors actually doing it. πŸ˜… See also: https://www.w3.org/TR/WGSL/#language-extensions-sec

Also, is it possible to improve our error message so that it might be clearer what's going on?

Yes, though it's not clear that the effort to improve the diagnostic is significantly less than simply supporting the extension in the first place.

I'll leave the NI for Teo open in case he wants to add something.

Flags: needinfo?(ttanasoaia)

With a nightly containing bug 1962269 https://threejs.org/examples/?q=webgpu#webgpu_skinning_instancing fails with:

Shader validation error: Entry point main at Fragment is invalid
   β”Œβ”€ fragment_Gaussian_blur:77:13
   β”‚
77 β”‚     nodeVar3 = textureLoad( nodeUniform3, vec2<u32>( tsl_coord_clampS_clamp_2dT( nodeVarying3 ) * vec2<f32>( nodeVar4 ) ), u32( 0 ) );
   β”‚                ^^^^^^^^^^^ naga::ir::Expression [42]
   β”‚
   = Expression [42] is invalid
   = Image sample or level-of-detail index's type of [41] is not an integer scalar
Flags: needinfo?(jimb)

It looks like the validator is missing support for the textureLoad overloads with sample_index: u32.

https://github.com/gfx-rs/wgpu/blob/4a6a3ae1053247967b6970c8f1a9507985f9bc09/naga/src/valid/expression.rs#L663

https://github.com/gfx-rs/wgpu/pull/7058 only addressed the level params.

Depends on: 1962481
Flags: needinfo?(jimb)

Filed bug 1962481 to track the sample index typing bug.

User Story: (updated)

I tested the examples that should be fixed by Bug 1952976, Bug 1952979 and Bug 1962481 locally with the latest wgpu update (Bug 1963329) and they are all working now.

We are now down to 6 examples that don't work.

Updated triage notes: https://hackmd.io/qNR5JQJQRamArlF1G3neBA

Depends on: 1963925
Depends on: 1964057
Depends on: 1967116
No longer depends on: 1967116

I tried all examples on macOS and added the findings to the same hackmd doc.

The 2 new issues the examples are running into are: Bug 1958017 (macOS only) and Bug 1834395 (platform agnostic).

No longer blocks: webgpu-mvp-apps-macos

External texture support has landed, but these demos are still not working:

https://threejs.org/examples/?q=webgpu#webgpu_video_frame also still doesn't work, but that's expected, since bug 1749539 isn't implemented yet.

See Also: → 1982451
You need to log in before you can comment on or make changes to this bug.