Can we assign RawTexture2DArray as material texture in WebGPU?

Hi everyone,

Please see here: Babylon.js Playground

WebGPU uncaptured error (1): [object GPUValidationError] - Dimension (TextureViewDimension::e2DArray) of [TextureView “BabylonWebGPUDevice8_TextureView2D_Array3_4x4_womips_rgba8unorm_2d-array_all_InternalUniqueId8”] doesn’t match the expected dimension (TextureViewDimension::e2D)

It works in Webgl :pleading_face:

Best wishes
Joe

cc @Evgeni_Popov

Standard textures (diffuse, emissive, etc) only support a 2D texture sampler. See this post if you want to use a 2D array texture:

Note that the PG doesn’t work, because we updated how the diffuse texture is sampled. Use this one instead:

It doesn’t work in WebGL, the cube is rendered black.

Sorry for the imprecise language. It works locally for me in Webgl but fails in WebGPU. The playground is probably too minimal.

To add some more background: while I do assign a RawTexture2dArray to the materials albedoTexture property, I do not really use this directly. There are custom splat and atlas samplers that mix the final color. Anyway, reason is because if I do not assign an albedo texture to the material, a couple of variables will not be available (albedoTexture, uvAlbedoUV, uvOffset, texture params like scaling). I guess this makes sense because why would you need them if you do not assign a texture.

But I do need at least uv data for my custom textures! And for some reason, the WebGl path keeps the defines in place and WebGPU crashes.

Maybe it works in WebGL because Angle removes all references to the sampler, as you said above you don’t use this code path anyway… In WebGPU, Dawn doesn’t do that, so it’s invalid to use a 2D array texture sampler with code designed for a 2D texture sampler.

Seems to do the trick:

   const buf = new Uint8Array(4);buf.fill(0);
   material.albedoTexture = game.assetCreator.getRawTexture("TerrainMatStub", buf, 1, true);

You might be able to use it, but probably not by assigning it directly to a standard material texture slot. As far as I know, RawTexture2DArray is supported in WebGPU, while standard Babylon.js materials are mainly built for regular 2D textures. If you need to work with a texture array, you may need to use a custom material or shader to access its layers correctly. Hopefully someone with more experience on this specific use case can confirm.