aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2019-11-03 12:52:13 +0000
committergingerBill <bill@gingerbill.org>2019-11-03 12:52:13 +0000
commit57853fe1b118970e1fc7149a7f030f4152e7157d (patch)
tree0b2aa427e7dc551679c382d64017f326115ed515 /examples
parent013b3b9fb3ed07513cf0bd9e381f805df0554b06 (diff)
Add SOA Struct Layout (experimental) to demo.odin
Diffstat (limited to 'examples')
-rw-r--r--examples/demo/demo.odin71
1 files changed, 71 insertions, 0 deletions
diff --git a/examples/demo/demo.odin b/examples/demo/demo.odin
index 583d3cbd2..8dc5340c9 100644
--- a/examples/demo/demo.odin
+++ b/examples/demo/demo.odin
@@ -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();
}
}