Skip to content

Getting error that array stride is too small when it seems to be correct #2049

Answered by cwfitzgerald
smolck asked this question in Q&A
Discussion options

You must be logged in to vote

So this issue is about alignment. The notable bits are that vec4<f32> is size 16, align 16 and vec2<f32> is size 8 align 8.

  • 0: vec2<f32> -> align_up(0, 8) + 2 * 4 -> 0 + 2 * 4 = 8 = 0 bytes of padding, 8 bytes of data
  • 8: vec4<f32> -> align_up(8, 16) + 4 * 4 -> 16 + 4 * 4 = 32 = 8 bytes of padding, 16 bytes of data
  • 32: u32 -> align_up(32, 4) + 1 * 4 -> 32 + 1 * 4 = 36 = 0 bytes of padding, 4 bytes of data.
  • 36: Struct is over, but our largest member is align 16, so we're align 16 too = align_up(36, 16) = 48 = 12 bytes of padding.

So your total struct size is actually 48, and your cpu side data needs to take into account that padding too. Your cpu side code should look like

struct Cell {
   

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@smolck
Comment options

@CatCode79
Comment options

Answer selected by smolck
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants