[AmberScript] Adding struct support#688
Conversation
This CL adds support for the STRUCT syntax in AmberScript. STRUCTS can be used in buffers. They can be compared as expected. If no OFFSET or STRIDE data is provided we will calculate the padding and offsets based on the current layout. Fixes #544
alan-baker
left a comment
There was a problem hiding this comment.
Intentional to allow partial initialization in ParseValues
| return Result("invalid value for STRUCT member OFFSET"); | ||
|
|
||
| m->offset_in_bytes = token->AsInt32(); | ||
| } else if (token->AsString() == "ARRAY_STRIDE") { |
There was a problem hiding this comment.
Should this produce an error if the member is not an array?
| return Result("invalid value for STRUCT member ARRAY_STRIDE"); | ||
|
|
||
| m->array_stride_in_bytes = token->AsInt32(); | ||
| } else if (token->AsString() == "MATRIX_STRIDE") { |
There was a problem hiding this comment.
Same question for matrices.
|
|
||
| v.SetIntValue(token->AsUint64()); | ||
| } | ||
| ++seg_idx; |
There was a problem hiding this comment.
Just to confirm, vec4 is 4 segments? How are runtime arrays to be handled?
There was a problem hiding this comment.
A vec4 would be 4 segments, yes. My plan for runtime arrays is that you end up looping over that group of segments again. So, the start of the array will be flagged and you can have 0 or more of them as needed.
| NameData{"mat2x2"}, | ||
| NameData{"mat2x2<>"})); // NOLINT(whitespace/parens) | ||
|
|
||
| TEST_F(AmberScriptParserTest, BufferWithStructStd140) { |
There was a problem hiding this comment.
Need some tests with vectors, arrays and runtime arrays.
There was a problem hiding this comment.
Added vec test. Array and runtime array will be followups when we add the array syntax.
|
|
||
| v.SetIntValue(token->AsUint64()); | ||
| } | ||
| ++seg_idx; |
There was a problem hiding this comment.
This seems to allow partial initialization because I don't see a check that all the segments are intialized. Just want to confirm it is intentional. I haven't noticed tests for it.
There was a problem hiding this comment.
Added test. The buffer code will reject a mismatched number of items currently.
This CL adds support for the STRUCT syntax in AmberScript. STRUCTS can
be used in buffers. They can be compared as expected. If no OFFSET or
STRIDE data is provided we will calculate the padding and offsets based
on the current layout.
Fixes #544