MUDA
Loading...
Searching...
No Matches
aos_sub_field.inl
1namespace muda
2{
3MUDA_INLINE void SubFieldImpl<FieldEntryLayout::AoS>::build_impl()
4{
5 auto min_alignment = build_options().min_alignment;
6 auto max_alignment = build_options().max_alignment;
7 // a "Struct" is something like the following, where M/V/S are 3 different entries, has type of matrix/vector/scalar
8 //tex:
9 // $$
10 // \begin{bmatrix}
11 // M_{11} & M_{21} & M_{12} & M_{22} & V_x & V_y & V_z & S
12 // \end{bmatrix}
13 // $$
14 uint32_t struct_stride = 0; // the stride of the "Struct"
15 for(auto& e : m_entries) // in an entry, the elem type is the same (e.g. float/int/double...)
16 {
17 // elem type = float/double/int ... or User Type
18 auto elem_byte_size = e->elem_byte_size();
19 // e.g. scalar=1 vector3 = 3, vector4 = 4, matrix3x3 = 9, matrix4x4 = 16, and so on
20 auto total_elem_count_in_a_struct_member = e->shape().x * e->shape().y;
21 struct_stride = align(struct_stride, elem_byte_size, min_alignment, max_alignment);
22 // now struct_stride is the offset of the entry in the "Struct"
23 e->m_core.m_info.offset_in_struct = struct_stride;
24 struct_stride += elem_byte_size * total_elem_count_in_a_struct_member;
25 }
26 // the final stride of the "Struct" >= struct size
27 m_struct_stride = align(struct_stride, struct_stride, min_alignment, max_alignment);
28
29 for(auto& e : m_entries)
30 e->m_core.m_info.struct_stride = m_struct_stride;
31}
32
33//MUDA_INLINE void SubFieldImpl<FieldEntryLayout::AoS>::resize(size_t num_elements)
34//{
35// copy_resize_data_buffer(m_struct_stride * num_elements);
36// for(auto& e : m_entries)
37// e->m_core.m_info.elem_count = num_elements;
38//}
39
40MUDA_INLINE size_t SubFieldImpl<FieldEntryLayout::AoS>::require_total_buffer_byte_size(size_t num_element)
41{
42 return m_struct_stride * num_element;
43}
44} // namespace muda