The data between JS and webgpu doesn't match well

Hi:

I’m using WEBGPU, and want to input array1 to a compute shader, as code 83 below:

According to my expectations,buffer1.numbers[0] at code 148 should be equal to 1,and ground should turns to red(matching the last number in array1):

however, the ground shows black(not red),which means buffer1.numbers[0] is not equal to1(not correspond to array1)

what should I do to correspond the elements of array1 and struct Triangle{…}
what should I do to correspond the elements of array1 and struct Triangle{…}
what should I do to correspond the elements of array1 and struct Triangle{…}

the playground project: Compute shader error | Babylon.js Playground (babylonjs.com)

buffer1.numbers[0] is 0 in the PG, not 1, because there are some alignment constraints or the Triangle struct that adds a dummy float after size. So, you should have seven 0 and not six before the color value.

Also, as you create the texture with the default type, you end up using UNSIGNED_BYTE, so you should put 255 for the color value, not 1:

2 Likes

Thanks for your prompt reply.:heart:

in new PG,

I consider that the vec3 size2 in the struct Triangle correspond to 5th-7th number in array1.

why not the 4th-6th number being filled to vec3 size2? (why the 4th number is ignored? )

tell me more the details please~

new PG:https://playground.babylonjs.com/#4EQ8ZT#3

Here is a doc detailing the padding [WGSL] Proposal: Default Struct Layout · Issue #1393 · gpuweb/gpuweb · GitHub