|
@@ -1279,6 +1279,76 @@ range_statements_with_multiple_return_values :: proc() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+soa_struct_layout :: proc() {
|
|
|
+ // IMPORTANT NOTE(bill, 2019-11-03): This feature is subject to be changed/removed
|
|
|
+ fmt.println("\n#SOA Struct Layout");
|
|
|
+
|
|
|
+ {
|
|
|
+ Vector3 :: struct {x, y, z: f32};
|
|
|
+
|
|
|
+ N :: 2;
|
|
|
+ v_aos: [N]Vector3;
|
|
|
+ v_aos[0].x = 1;
|
|
|
+ v_aos[0].y = 4;
|
|
|
+ v_aos[0].z = 9;
|
|
|
+
|
|
|
+ fmt.println(len(v_aos));
|
|
|
+ fmt.println(v_aos[0]);
|
|
|
+ fmt.println(v_aos[0].x);
|
|
|
+ fmt.println(&v_aos[0].x);
|
|
|
+
|
|
|
+ v_aos[1] = {0, 3, 4};
|
|
|
+ v_aos[1].x = 2;
|
|
|
+ fmt.println(v_aos[1]);
|
|
|
+ fmt.println(v_aos);
|
|
|
+
|
|
|
+ v_soa: intrinsics.soa_struct(N, Vector3);
|
|
|
+
|
|
|
+ v_soa[0].x = 1;
|
|
|
+ v_soa[0].y = 4;
|
|
|
+ v_soa[0].z = 9;
|
|
|
+
|
|
|
+
|
|
|
+ // Same syntax as AOS and treat as if it was an array
|
|
|
+ fmt.println(len(v_soa));
|
|
|
+ fmt.println(v_soa[0]);
|
|
|
+ fmt.println(v_soa[0].x);
|
|
|
+ v_soa[1] = {0, 3, 4};
|
|
|
+ v_soa[1].x = 2;
|
|
|
+ fmt.println(v_soa[1]);
|
|
|
+
|
|
|
+ // Can use SOA syntax if necessary
|
|
|
+ v_soa.x[0] = 1;
|
|
|
+ v_soa.y[0] = 4;
|
|
|
+ v_soa.z[0] = 9;
|
|
|
+ fmt.println(v_soa.x[0]);
|
|
|
+
|
|
|
+ // Same pointer addresses with both syntaxes
|
|
|
+ assert(&v_soa[0].x == &v_soa.x[0]);
|
|
|
+
|
|
|
+
|
|
|
+ // Same fmt printing
|
|
|
+ fmt.println(v_aos);
|
|
|
+ fmt.println(v_soa);
|
|
|
+ }
|
|
|
+ {
|
|
|
+ // Works with arrays of length <= 4 which have the implicit fields xyzw/rgba
|
|
|
+ Vector3 :: distinct [3]f32;
|
|
|
+
|
|
|
+ N :: 2;
|
|
|
+ v_aos: [N]Vector3;
|
|
|
+ v_aos[0].x = 1;
|
|
|
+ v_aos[0].y = 4;
|
|
|
+ v_aos[0].z = 9;
|
|
|
+
|
|
|
+ v_soa: intrinsics.soa_struct(N, Vector3);
|
|
|
+
|
|
|
+ v_soa[0].x = 1;
|
|
|
+ v_soa[0].y = 4;
|
|
|
+ v_soa[0].z = 9;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
main :: proc() {
|
|
|
when true {
|
|
|
extra_general_stuff();
|
|
@@ -1303,6 +1373,7 @@ main :: proc() {
|
|
|
where_clauses();
|
|
|
ranged_fields_for_array_compound_literals();
|
|
|
range_statements_with_multiple_return_values();
|
|
|
+ soa_struct_layout();
|
|
|
}
|
|
|
}
|
|
|
|