diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d8cd9249..93e33245a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,10 +61,20 @@ find_package( target passes native - mc # <--- Added for TargetRegistry/Triple - instcombine # <--- Added for InstCombinePass - scalaropts # <--- Added for SimplifyCFG/GVN/Reassociate - ipo # <--- Added for AlwaysInliner / RelLookupTable + # The components below are used directly by src/CodeGen (TargetRegistry, + # Triple, getDefaultTargetTriple, the AlwaysInliner, and the individual + # passes named in optimize_module). They resolve transitively through the + # monolithic LLVM dylib on macOS, but must be requested explicitly when + # LLVM is built as separate component libraries (e.g. a Linux + # BUILD_SHARED_LIBS install). + mc + targetparser + codegen + transformutils + instcombine + scalaropts + ipo + # irbuilder orcjit executionengine # Required for LLJIT runtimeDyld # Required for JIT execution @@ -77,6 +87,18 @@ add_library(bonsai_library STATIC) add_library(bonsai::library ALIAS bonsai_library) target_compile_features(bonsai_library PUBLIC cxx_std_20) + +# include/Error.h trims this prefix off __FILE__, so that the "[internal] +# Error: :" lines checked in under tests/bonsai/error/*.expect do +# not depend on the name of the directory the repository was cloned into. +# PUBLIC because bonsai_compiler and bonsai_test_runner include Error.h too; +# BUILD_INTERFACE keeps a local absolute path out of anything installed. +target_compile_definitions( + bonsai_library + PUBLIC + "$" +) + target_link_libraries(bonsai_library PUBLIC ModernLLVM::LLVM) target_sources( diff --git a/README.md b/README.md index b22e5e6d7..a1aaef46d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # bonsai +**Click [here for the PLDI 2026 Bonsai branch](https://github.com/rootjalex/bonsai/tree/ajr/pldi-benchmarks) and [here for the PLDI 2026 Scion branch](https://github.com/rootjalex/bonsai/tree/cpg/pldi-artifact).** + DSL for Recursive Geometric Queries ### Setup. diff --git a/apps/cd/cpu/fcl/cd.h b/apps/cd/cpu/fcl/cd.h index 845c39bc6..0bbcf649b 100644 --- a/apps/cd/cpu/fcl/cd.h +++ b/apps/cd/cpu/fcl/cd.h @@ -1,7 +1,7 @@ #pragma once -#include #include "runtime/bonsai_cpp.h" +#include using float3 = vector; struct Triangle { @@ -17,9 +17,9 @@ struct _tree_layout1 { } __attribute__((packed)); struct _tree_layout0 { uint32_t pCount; - Triangle* prims; + Triangle *prims; uint32_t nCount; - _tree_layout1* group0_index; + _tree_layout1 *group0_index; } __attribute__((packed)); struct _tree_layout2 { } __attribute__((packed)); @@ -33,11 +33,12 @@ struct _tree_layout5 { } __attribute__((packed)); struct _tree_layout4 { uint32_t pCount; - Triangle* prims; + Triangle *prims; uint32_t nCount; - _tree_layout5* group0_index; + _tree_layout5 *group0_index; } __attribute__((packed)); struct _tree_layout6 { } __attribute__((packed)); -set> collisions(const _tree_layout0& triangles1, const _tree_layout4& triangles2); +set> collisions(const _tree_layout0 &triangles1, + const _tree_layout4 &triangles2); diff --git a/apps/cd/cpu/fcl/cd_profiled.cpp b/apps/cd/cpu/fcl/cd_profiled.cpp index 32bc26aff..f35847408 100644 --- a/apps/cd/cpu/fcl/cd_profiled.cpp +++ b/apps/cd/cpu/fcl/cd_profiled.cpp @@ -7,169 +7,187 @@ struct AABB { }; bool intersects_AABB_AABB(const AABB a, const AABB b) { - bonsai_aabb_counter++; - const float3 low = max(a.low, b.low); - const float3 high = min(a.high, b.high); - return reduce_and(low <= high); + bonsai_aabb_counter++; + const float3 low = max(a.low, b.low); + const float3 high = min(a.high, b.high); + return reduce_and(low <= high); } -int32_t project6(const float3 ax, const float3 p1, const float3 p2, const float3 p3, const float3 q1, const float3 q2, const float3 q3) { - const float P1 = dot(ax, p1); - const float P2 = dot(ax, p2); - const float P3 = dot(ax, p3); - const float Q1 = dot(ax, q1); - const float Q2 = dot(ax, q2); - const float Q3 = dot(ax, q3); - const float mn1 = min(min(P1, P2), P3); - const float mx2 = max(max(Q1, Q2), Q3); - if (mx2 < mn1) { - return 0; - } - const float mx1 = max(max(P1, P2), P3); - const float mn2 = min(min(Q1, Q2), Q3); - if (mx1 < mn2) { - return 0; - } - return 1; +int32_t project6(const float3 ax, const float3 p1, const float3 p2, + const float3 p3, const float3 q1, const float3 q2, + const float3 q3) { + const float P1 = dot(ax, p1); + const float P2 = dot(ax, p2); + const float P3 = dot(ax, p3); + const float Q1 = dot(ax, q1); + const float Q2 = dot(ax, q2); + const float Q3 = dot(ax, q3); + const float mn1 = min(min(P1, P2), P3); + const float mx2 = max(max(Q1, Q2), Q3); + if (mx2 < mn1) { + return 0; + } + const float mx1 = max(max(P1, P2), P3); + const float mn2 = min(min(Q1, Q2), Q3); + if (mx1 < mn2) { + return 0; + } + return 1; } -bool fcl_triangle_intersect(const float3 P1, const float3 P2, const float3 P3, const float3 Q1, const float3 Q2, const float3 Q3) { - const float3 p2 = P2 - P1; - const float3 p3 = P3 - P1; - const float3 q1 = Q1 - P1; - const float3 q2 = Q2 - P1; - const float3 q3 = Q3 - P1; - const float3 e2 = p3 - p2; - const float3 n1 = cross(p2, e2); - if (project6(n1, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { - return false; - } - const float3 f1 = q2 - q1; - const float3 f2 = q3 - q2; - const float3 m1 = cross(f1, f2); - if (project6(m1, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { - return false; - } - const float3 ef11 = cross(p2, f1); - if (project6(ef11, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { - return false; - } - const float3 ef12 = cross(p2, f2); - if (project6(ef12, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { - return false; - } - const float3 f3 = q1 - q3; - const float3 ef13 = cross(p2, f3); - if (project6(ef13, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { - return false; - } - const float3 ef21 = cross(e2, f1); - if (project6(ef21, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { - return false; - } - const float3 ef22 = cross(e2, f2); - if (project6(ef22, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { - return false; - } - const float3 ef23 = cross(e2, f3); - if (project6(ef23, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { - return false; - } - const float3 e3 = -p3; - const float3 ef31 = cross(e3, f1); - if (project6(ef31, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { - return false; - } - const float3 ef32 = cross(e3, f2); - if (project6(ef32, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { - return false; - } - const float3 ef33 = cross(e3, f3); - if (project6(ef33, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { - return false; - } - const float3 g1 = cross(p2, n1); - if (project6(g1, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { - return false; - } - const float3 g2 = cross(e2, n1); - if (project6(g2, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { - return false; - } - const float3 g3 = cross(e3, n1); - if (project6(g3, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { - return false; - } - const float3 h1 = cross(f1, m1); - if (project6(h1, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { - return false; - } - const float3 h2 = cross(f2, m1); - if (project6(h2, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { - return false; - } - const float3 h3 = cross(f3, m1); - if (project6(h3, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { - return false; - } - return true; +bool fcl_triangle_intersect(const float3 P1, const float3 P2, const float3 P3, + const float3 Q1, const float3 Q2, const float3 Q3) { + const float3 p2 = P2 - P1; + const float3 p3 = P3 - P1; + const float3 q1 = Q1 - P1; + const float3 q2 = Q2 - P1; + const float3 q3 = Q3 - P1; + const float3 e2 = p3 - p2; + const float3 n1 = cross(p2, e2); + if (project6(n1, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { + return false; + } + const float3 f1 = q2 - q1; + const float3 f2 = q3 - q2; + const float3 m1 = cross(f1, f2); + if (project6(m1, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { + return false; + } + const float3 ef11 = cross(p2, f1); + if (project6(ef11, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { + return false; + } + const float3 ef12 = cross(p2, f2); + if (project6(ef12, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { + return false; + } + const float3 f3 = q1 - q3; + const float3 ef13 = cross(p2, f3); + if (project6(ef13, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { + return false; + } + const float3 ef21 = cross(e2, f1); + if (project6(ef21, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { + return false; + } + const float3 ef22 = cross(e2, f2); + if (project6(ef22, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { + return false; + } + const float3 ef23 = cross(e2, f3); + if (project6(ef23, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { + return false; + } + const float3 e3 = -p3; + const float3 ef31 = cross(e3, f1); + if (project6(ef31, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { + return false; + } + const float3 ef32 = cross(e3, f2); + if (project6(ef32, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { + return false; + } + const float3 ef33 = cross(e3, f3); + if (project6(ef33, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { + return false; + } + const float3 g1 = cross(p2, n1); + if (project6(g1, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { + return false; + } + const float3 g2 = cross(e2, n1); + if (project6(g2, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { + return false; + } + const float3 g3 = cross(e3, n1); + if (project6(g3, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { + return false; + } + const float3 h1 = cross(f1, m1); + if (project6(h1, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { + return false; + } + const float3 h2 = cross(f2, m1); + if (project6(h2, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { + return false; + } + const float3 h3 = cross(f3, m1); + if (project6(h3, float3{0.00000000f}, p2, p3, q1, q2, q3) == 0) { + return false; + } + return true; } bool intersects_Triangle_Triangle(const Triangle a, const Triangle b) { - bonsai_tri_counter++; - return fcl_triangle_intersect(a.p0, a.p1, a.p2, b.p0, b.p1, b.p2); + bonsai_tri_counter++; + return fcl_triangle_intersect(a.p0, a.p1, a.p2, b.p0, b.p1, b.p2); } -void _recloop_func0(const uint32_t triangles1_index, const uint32_t triangles2_index, const _tree_layout0& triangles1, const _tree_layout4& triangles2, set>& _dyn_alloc) { - bonsai_rec_counter++; - const _tree_layout1 _t72 = triangles1.group0_index[triangles1_index]; - const _tree_layout5 _t76 = triangles2.group0_index[triangles2_index]; - if (intersects_AABB_AABB(AABB{_t72.low, _t72.high}, AABB{_t76.low, _t76.high})) { - const uint32_t _t70 = _t72.nPrims; - if (_t70 == 0u) { - if (_t76.nPrims == 0u) { - const uint32_t _t0 = triangles1_index + 1u; - const uint32_t _t1 = triangles2_index + 1u; - _recloop_func0(_t0, _t1, triangles1, triangles2, _dyn_alloc); - const uint32_t _t6 = triangles2_index + _t76.offset; - _recloop_func0(_t0, _t6, triangles1, triangles2, _dyn_alloc); - const uint32_t _t10 = triangles1_index + _t72.offset; - _recloop_func0(_t10, _t1, triangles1, triangles2, _dyn_alloc); - _recloop_func0(_t10, _t6, triangles1, triangles2, _dyn_alloc); - } else { - _recloop_func0(triangles1_index + 1u, triangles2_index, triangles1, triangles2, _dyn_alloc); - _recloop_func0(triangles1_index + _t72.offset, triangles2_index, triangles1, triangles2, _dyn_alloc); - } - } else { - const uint32_t _t66 = _t76.nPrims; - if (_t66 == 0u) { - _recloop_func0(triangles1_index, triangles2_index + 1u, triangles1, triangles2, _dyn_alloc); - _recloop_func0(triangles1_index, triangles2_index + _t76.offset, triangles1, triangles2, _dyn_alloc); - } else { - for (uint32_t _idx0 = 0u; _idx0 < _t70; _idx0 += 1u) { - for (uint32_t _idx1 = 0u; _idx1 < _t66; _idx1 += 1u) { - const Triangle _t39 = triangles1.prims[_t72.offset + _idx0]; - const Triangle _t45 = triangles2.prims[_t76.offset + _idx1]; - if (intersects_Triangle_Triangle(_t39, _t45)) { - _dyn_alloc.push_back(std::make_tuple(_t39, _t45)); +void _recloop_func0(const uint32_t triangles1_index, + const uint32_t triangles2_index, + const _tree_layout0 &triangles1, + const _tree_layout4 &triangles2, + set> &_dyn_alloc) { + bonsai_rec_counter++; + const _tree_layout1 _t72 = triangles1.group0_index[triangles1_index]; + const _tree_layout5 _t76 = triangles2.group0_index[triangles2_index]; + if (intersects_AABB_AABB(AABB{_t72.low, _t72.high}, + AABB{_t76.low, _t76.high})) { + const uint32_t _t70 = _t72.nPrims; + if (_t70 == 0u) { + if (_t76.nPrims == 0u) { + const uint32_t _t0 = triangles1_index + 1u; + const uint32_t _t1 = triangles2_index + 1u; + _recloop_func0(_t0, _t1, triangles1, triangles2, _dyn_alloc); + const uint32_t _t6 = triangles2_index + _t76.offset; + _recloop_func0(_t0, _t6, triangles1, triangles2, _dyn_alloc); + const uint32_t _t10 = triangles1_index + _t72.offset; + _recloop_func0(_t10, _t1, triangles1, triangles2, _dyn_alloc); + _recloop_func0(_t10, _t6, triangles1, triangles2, _dyn_alloc); + } else { + _recloop_func0(triangles1_index + 1u, triangles2_index, + triangles1, triangles2, _dyn_alloc); + _recloop_func0(triangles1_index + _t72.offset, triangles2_index, + triangles1, triangles2, _dyn_alloc); + } + } else { + const uint32_t _t66 = _t76.nPrims; + if (_t66 == 0u) { + _recloop_func0(triangles1_index, triangles2_index + 1u, + triangles1, triangles2, _dyn_alloc); + _recloop_func0(triangles1_index, triangles2_index + _t76.offset, + triangles1, triangles2, _dyn_alloc); + } else { + for (uint32_t _idx0 = 0u; _idx0 < _t70; _idx0 += 1u) { + for (uint32_t _idx1 = 0u; _idx1 < _t66; _idx1 += 1u) { + const Triangle _t39 = + triangles1.prims[_t72.offset + _idx0]; + const Triangle _t45 = + triangles2.prims[_t76.offset + _idx1]; + if (intersects_Triangle_Triangle(_t39, _t45)) { + _dyn_alloc.push_back(std::make_tuple(_t39, _t45)); + } + } + } } - } } - } } - } - return; + return; } -set> _traverse_tree0(const _tree_layout0& triangles1, const _tree_layout4& triangles2) { - set> _dyn_alloc; - _recloop_func0(0u, 0u, triangles1, triangles2, _dyn_alloc); - return _dyn_alloc; +set> +_traverse_tree0(const _tree_layout0 &triangles1, + const _tree_layout4 &triangles2) { + set> _dyn_alloc; + _recloop_func0(0u, 0u, triangles1, triangles2, _dyn_alloc); + return _dyn_alloc; } -bool axis(const float3 A, const float3 extents, const float3 v0, const float3 v1, const float3 v2) { - const float R = dot(extents, abs(A)); - const float P0 = dot(v0, A); - const float P1 = dot(v1, A); - const float P2 = dot(v2, A); - const float Pmin = min(min(P0, P1), P2); - const float Pmax = max(max(P0, P1), P2); - return (-R <= Pmax) & (Pmin <= R); +bool axis(const float3 A, const float3 extents, const float3 v0, + const float3 v1, const float3 v2) { + const float R = dot(extents, abs(A)); + const float P0 = dot(v0, A); + const float P1 = dot(v1, A); + const float P2 = dot(v2, A); + const float Pmin = min(min(P0, P1), P2); + const float Pmax = max(max(P0, P1), P2); + return (-R <= Pmax) & (Pmin <= R); } -set> collisions(const _tree_layout0& triangles1, const _tree_layout4& triangles2) { - return _traverse_tree0(triangles1, triangles2); +set> +collisions(const _tree_layout0 &triangles1, const _tree_layout4 &triangles2) { + return _traverse_tree0(triangles1, triangles2); } diff --git a/apps/pbrt/cie_tables.h b/apps/pbrt/cie_tables.h index 102d3af25..64043eee0 100644 --- a/apps/pbrt/cie_tables.h +++ b/apps/pbrt/cie_tables.h @@ -13,249 +13,420 @@ inline constexpr float CIE_LAMBDA_MIN = 360.0f; inline constexpr float CIE_LAMBDA_MAX = 830.0f; inline constexpr float CIE_LAMBDA[CIE_SAMPLES] = { - 360.0f, 361.0f, 362.0f, 363.0f, 364.0f, 365.0f, 366.0f, 367.0f, - 368.0f, 369.0f, 370.0f, 371.0f, 372.0f, 373.0f, 374.0f, 375.0f, - 376.0f, 377.0f, 378.0f, 379.0f, 380.0f, 381.0f, 382.0f, 383.0f, - 384.0f, 385.0f, 386.0f, 387.0f, 388.0f, 389.0f, 390.0f, 391.0f, - 392.0f, 393.0f, 394.0f, 395.0f, 396.0f, 397.0f, 398.0f, 399.0f, - 400.0f, 401.0f, 402.0f, 403.0f, 404.0f, 405.0f, 406.0f, 407.0f, - 408.0f, 409.0f, 410.0f, 411.0f, 412.0f, 413.0f, 414.0f, 415.0f, - 416.0f, 417.0f, 418.0f, 419.0f, 420.0f, 421.0f, 422.0f, 423.0f, - 424.0f, 425.0f, 426.0f, 427.0f, 428.0f, 429.0f, 430.0f, 431.0f, - 432.0f, 433.0f, 434.0f, 435.0f, 436.0f, 437.0f, 438.0f, 439.0f, - 440.0f, 441.0f, 442.0f, 443.0f, 444.0f, 445.0f, 446.0f, 447.0f, - 448.0f, 449.0f, 450.0f, 451.0f, 452.0f, 453.0f, 454.0f, 455.0f, - 456.0f, 457.0f, 458.0f, 459.0f, 460.0f, 461.0f, 462.0f, 463.0f, - 464.0f, 465.0f, 466.0f, 467.0f, 468.0f, 469.0f, 470.0f, 471.0f, - 472.0f, 473.0f, 474.0f, 475.0f, 476.0f, 477.0f, 478.0f, 479.0f, - 480.0f, 481.0f, 482.0f, 483.0f, 484.0f, 485.0f, 486.0f, 487.0f, - 488.0f, 489.0f, 490.0f, 491.0f, 492.0f, 493.0f, 494.0f, 495.0f, - 496.0f, 497.0f, 498.0f, 499.0f, 500.0f, 501.0f, 502.0f, 503.0f, - 504.0f, 505.0f, 506.0f, 507.0f, 508.0f, 509.0f, 510.0f, 511.0f, - 512.0f, 513.0f, 514.0f, 515.0f, 516.0f, 517.0f, 518.0f, 519.0f, - 520.0f, 521.0f, 522.0f, 523.0f, 524.0f, 525.0f, 526.0f, 527.0f, - 528.0f, 529.0f, 530.0f, 531.0f, 532.0f, 533.0f, 534.0f, 535.0f, - 536.0f, 537.0f, 538.0f, 539.0f, 540.0f, 541.0f, 542.0f, 543.0f, - 544.0f, 545.0f, 546.0f, 547.0f, 548.0f, 549.0f, 550.0f, 551.0f, - 552.0f, 553.0f, 554.0f, 555.0f, 556.0f, 557.0f, 558.0f, 559.0f, - 560.0f, 561.0f, 562.0f, 563.0f, 564.0f, 565.0f, 566.0f, 567.0f, - 568.0f, 569.0f, 570.0f, 571.0f, 572.0f, 573.0f, 574.0f, 575.0f, - 576.0f, 577.0f, 578.0f, 579.0f, 580.0f, 581.0f, 582.0f, 583.0f, - 584.0f, 585.0f, 586.0f, 587.0f, 588.0f, 589.0f, 590.0f, 591.0f, - 592.0f, 593.0f, 594.0f, 595.0f, 596.0f, 597.0f, 598.0f, 599.0f, - 600.0f, 601.0f, 602.0f, 603.0f, 604.0f, 605.0f, 606.0f, 607.0f, - 608.0f, 609.0f, 610.0f, 611.0f, 612.0f, 613.0f, 614.0f, 615.0f, - 616.0f, 617.0f, 618.0f, 619.0f, 620.0f, 621.0f, 622.0f, 623.0f, - 624.0f, 625.0f, 626.0f, 627.0f, 628.0f, 629.0f, 630.0f, 631.0f, - 632.0f, 633.0f, 634.0f, 635.0f, 636.0f, 637.0f, 638.0f, 639.0f, - 640.0f, 641.0f, 642.0f, 643.0f, 644.0f, 645.0f, 646.0f, 647.0f, - 648.0f, 649.0f, 650.0f, 651.0f, 652.0f, 653.0f, 654.0f, 655.0f, - 656.0f, 657.0f, 658.0f, 659.0f, 660.0f, 661.0f, 662.0f, 663.0f, - 664.0f, 665.0f, 666.0f, 667.0f, 668.0f, 669.0f, 670.0f, 671.0f, - 672.0f, 673.0f, 674.0f, 675.0f, 676.0f, 677.0f, 678.0f, 679.0f, - 680.0f, 681.0f, 682.0f, 683.0f, 684.0f, 685.0f, 686.0f, 687.0f, - 688.0f, 689.0f, 690.0f, 691.0f, 692.0f, 693.0f, 694.0f, 695.0f, - 696.0f, 697.0f, 698.0f, 699.0f, 700.0f, 701.0f, 702.0f, 703.0f, - 704.0f, 705.0f, 706.0f, 707.0f, 708.0f, 709.0f, 710.0f, 711.0f, - 712.0f, 713.0f, 714.0f, 715.0f, 716.0f, 717.0f, 718.0f, 719.0f, - 720.0f, 721.0f, 722.0f, 723.0f, 724.0f, 725.0f, 726.0f, 727.0f, - 728.0f, 729.0f, 730.0f, 731.0f, 732.0f, 733.0f, 734.0f, 735.0f, - 736.0f, 737.0f, 738.0f, 739.0f, 740.0f, 741.0f, 742.0f, 743.0f, - 744.0f, 745.0f, 746.0f, 747.0f, 748.0f, 749.0f, 750.0f, 751.0f, - 752.0f, 753.0f, 754.0f, 755.0f, 756.0f, 757.0f, 758.0f, 759.0f, - 760.0f, 761.0f, 762.0f, 763.0f, 764.0f, 765.0f, 766.0f, 767.0f, - 768.0f, 769.0f, 770.0f, 771.0f, 772.0f, 773.0f, 774.0f, 775.0f, - 776.0f, 777.0f, 778.0f, 779.0f, 780.0f, 781.0f, 782.0f, 783.0f, - 784.0f, 785.0f, 786.0f, 787.0f, 788.0f, 789.0f, 790.0f, 791.0f, - 792.0f, 793.0f, 794.0f, 795.0f, 796.0f, 797.0f, 798.0f, 799.0f, - 800.0f, 801.0f, 802.0f, 803.0f, 804.0f, 805.0f, 806.0f, 807.0f, - 808.0f, 809.0f, 810.0f, 811.0f, 812.0f, 813.0f, 814.0f, 815.0f, - 816.0f, 817.0f, 818.0f, 819.0f, 820.0f, 821.0f, 822.0f, 823.0f, - 824.0f, 825.0f, 826.0f, 827.0f, 828.0f, 829.0f, 830.0f, + 360.0f, 361.0f, 362.0f, 363.0f, 364.0f, 365.0f, 366.0f, 367.0f, 368.0f, + 369.0f, 370.0f, 371.0f, 372.0f, 373.0f, 374.0f, 375.0f, 376.0f, 377.0f, + 378.0f, 379.0f, 380.0f, 381.0f, 382.0f, 383.0f, 384.0f, 385.0f, 386.0f, + 387.0f, 388.0f, 389.0f, 390.0f, 391.0f, 392.0f, 393.0f, 394.0f, 395.0f, + 396.0f, 397.0f, 398.0f, 399.0f, 400.0f, 401.0f, 402.0f, 403.0f, 404.0f, + 405.0f, 406.0f, 407.0f, 408.0f, 409.0f, 410.0f, 411.0f, 412.0f, 413.0f, + 414.0f, 415.0f, 416.0f, 417.0f, 418.0f, 419.0f, 420.0f, 421.0f, 422.0f, + 423.0f, 424.0f, 425.0f, 426.0f, 427.0f, 428.0f, 429.0f, 430.0f, 431.0f, + 432.0f, 433.0f, 434.0f, 435.0f, 436.0f, 437.0f, 438.0f, 439.0f, 440.0f, + 441.0f, 442.0f, 443.0f, 444.0f, 445.0f, 446.0f, 447.0f, 448.0f, 449.0f, + 450.0f, 451.0f, 452.0f, 453.0f, 454.0f, 455.0f, 456.0f, 457.0f, 458.0f, + 459.0f, 460.0f, 461.0f, 462.0f, 463.0f, 464.0f, 465.0f, 466.0f, 467.0f, + 468.0f, 469.0f, 470.0f, 471.0f, 472.0f, 473.0f, 474.0f, 475.0f, 476.0f, + 477.0f, 478.0f, 479.0f, 480.0f, 481.0f, 482.0f, 483.0f, 484.0f, 485.0f, + 486.0f, 487.0f, 488.0f, 489.0f, 490.0f, 491.0f, 492.0f, 493.0f, 494.0f, + 495.0f, 496.0f, 497.0f, 498.0f, 499.0f, 500.0f, 501.0f, 502.0f, 503.0f, + 504.0f, 505.0f, 506.0f, 507.0f, 508.0f, 509.0f, 510.0f, 511.0f, 512.0f, + 513.0f, 514.0f, 515.0f, 516.0f, 517.0f, 518.0f, 519.0f, 520.0f, 521.0f, + 522.0f, 523.0f, 524.0f, 525.0f, 526.0f, 527.0f, 528.0f, 529.0f, 530.0f, + 531.0f, 532.0f, 533.0f, 534.0f, 535.0f, 536.0f, 537.0f, 538.0f, 539.0f, + 540.0f, 541.0f, 542.0f, 543.0f, 544.0f, 545.0f, 546.0f, 547.0f, 548.0f, + 549.0f, 550.0f, 551.0f, 552.0f, 553.0f, 554.0f, 555.0f, 556.0f, 557.0f, + 558.0f, 559.0f, 560.0f, 561.0f, 562.0f, 563.0f, 564.0f, 565.0f, 566.0f, + 567.0f, 568.0f, 569.0f, 570.0f, 571.0f, 572.0f, 573.0f, 574.0f, 575.0f, + 576.0f, 577.0f, 578.0f, 579.0f, 580.0f, 581.0f, 582.0f, 583.0f, 584.0f, + 585.0f, 586.0f, 587.0f, 588.0f, 589.0f, 590.0f, 591.0f, 592.0f, 593.0f, + 594.0f, 595.0f, 596.0f, 597.0f, 598.0f, 599.0f, 600.0f, 601.0f, 602.0f, + 603.0f, 604.0f, 605.0f, 606.0f, 607.0f, 608.0f, 609.0f, 610.0f, 611.0f, + 612.0f, 613.0f, 614.0f, 615.0f, 616.0f, 617.0f, 618.0f, 619.0f, 620.0f, + 621.0f, 622.0f, 623.0f, 624.0f, 625.0f, 626.0f, 627.0f, 628.0f, 629.0f, + 630.0f, 631.0f, 632.0f, 633.0f, 634.0f, 635.0f, 636.0f, 637.0f, 638.0f, + 639.0f, 640.0f, 641.0f, 642.0f, 643.0f, 644.0f, 645.0f, 646.0f, 647.0f, + 648.0f, 649.0f, 650.0f, 651.0f, 652.0f, 653.0f, 654.0f, 655.0f, 656.0f, + 657.0f, 658.0f, 659.0f, 660.0f, 661.0f, 662.0f, 663.0f, 664.0f, 665.0f, + 666.0f, 667.0f, 668.0f, 669.0f, 670.0f, 671.0f, 672.0f, 673.0f, 674.0f, + 675.0f, 676.0f, 677.0f, 678.0f, 679.0f, 680.0f, 681.0f, 682.0f, 683.0f, + 684.0f, 685.0f, 686.0f, 687.0f, 688.0f, 689.0f, 690.0f, 691.0f, 692.0f, + 693.0f, 694.0f, 695.0f, 696.0f, 697.0f, 698.0f, 699.0f, 700.0f, 701.0f, + 702.0f, 703.0f, 704.0f, 705.0f, 706.0f, 707.0f, 708.0f, 709.0f, 710.0f, + 711.0f, 712.0f, 713.0f, 714.0f, 715.0f, 716.0f, 717.0f, 718.0f, 719.0f, + 720.0f, 721.0f, 722.0f, 723.0f, 724.0f, 725.0f, 726.0f, 727.0f, 728.0f, + 729.0f, 730.0f, 731.0f, 732.0f, 733.0f, 734.0f, 735.0f, 736.0f, 737.0f, + 738.0f, 739.0f, 740.0f, 741.0f, 742.0f, 743.0f, 744.0f, 745.0f, 746.0f, + 747.0f, 748.0f, 749.0f, 750.0f, 751.0f, 752.0f, 753.0f, 754.0f, 755.0f, + 756.0f, 757.0f, 758.0f, 759.0f, 760.0f, 761.0f, 762.0f, 763.0f, 764.0f, + 765.0f, 766.0f, 767.0f, 768.0f, 769.0f, 770.0f, 771.0f, 772.0f, 773.0f, + 774.0f, 775.0f, 776.0f, 777.0f, 778.0f, 779.0f, 780.0f, 781.0f, 782.0f, + 783.0f, 784.0f, 785.0f, 786.0f, 787.0f, 788.0f, 789.0f, 790.0f, 791.0f, + 792.0f, 793.0f, 794.0f, 795.0f, 796.0f, 797.0f, 798.0f, 799.0f, 800.0f, + 801.0f, 802.0f, 803.0f, 804.0f, 805.0f, 806.0f, 807.0f, 808.0f, 809.0f, + 810.0f, 811.0f, 812.0f, 813.0f, 814.0f, 815.0f, 816.0f, 817.0f, 818.0f, + 819.0f, 820.0f, 821.0f, 822.0f, 823.0f, 824.0f, 825.0f, 826.0f, 827.0f, + 828.0f, 829.0f, 830.0f, }; inline constexpr float CIE_X[CIE_SAMPLES] = { - 0.0001299000f, 0.0001458470f, 0.0001638021f, 0.0001840037f, 0.0002066902f, 0.0002321000f, 0.0002607280f, 0.0002930750f, - 0.0003293880f, 0.0003699140f, 0.0004149000f, 0.0004641587f, 0.0005189860f, 0.0005818540f, 0.0006552347f, 0.0007416000f, - 0.0008450296f, 0.0009645268f, 0.001094949f, 0.001231154f, 0.001368000f, 0.001502050f, 0.001642328f, 0.001802382f, - 0.001995757f, 0.002236000f, 0.002535385f, 0.002892603f, 0.003300829f, 0.003753236f, 0.004243000f, 0.004762389f, - 0.005330048f, 0.005978712f, 0.006741117f, 0.007650000f, 0.008751373f, 0.01002888f, 0.01142170f, 0.01286901f, - 0.01431000f, 0.01570443f, 0.01714744f, 0.01878122f, 0.02074801f, 0.02319000f, 0.02620736f, 0.02978248f, - 0.03388092f, 0.03846824f, 0.04351000f, 0.04899560f, 0.05502260f, 0.06171880f, 0.06921200f, 0.07763000f, - 0.08695811f, 0.09717672f, 0.1084063f, 0.1207672f, 0.1343800f, 0.1493582f, 0.1653957f, 0.1819831f, - 0.1986110f, 0.2147700f, 0.2301868f, 0.2448797f, 0.2587773f, 0.2718079f, 0.2839000f, 0.2949438f, - 0.3048965f, 0.3137873f, 0.3216454f, 0.3285000f, 0.3343513f, 0.3392101f, 0.3431213f, 0.3461296f, - 0.3482800f, 0.3495999f, 0.3501474f, 0.3500130f, 0.3492870f, 0.3480600f, 0.3463733f, 0.3442624f, - 0.3418088f, 0.3390941f, 0.3362000f, 0.3331977f, 0.3300411f, 0.3266357f, 0.3228868f, 0.3187000f, - 0.3140251f, 0.3088840f, 0.3032904f, 0.2972579f, 0.2908000f, 0.2839701f, 0.2767214f, 0.2689178f, - 0.2604227f, 0.2511000f, 0.2408475f, 0.2298512f, 0.2184072f, 0.2068115f, 0.1953600f, 0.1842136f, - 0.1733273f, 0.1626881f, 0.1522833f, 0.1421000f, 0.1321786f, 0.1225696f, 0.1132752f, 0.1042979f, - 0.09564000f, 0.08729955f, 0.07930804f, 0.07171776f, 0.06458099f, 0.05795001f, 0.05186211f, 0.04628152f, - 0.04115088f, 0.03641283f, 0.03201000f, 0.02791720f, 0.02414440f, 0.02068700f, 0.01754040f, 0.01470000f, - 0.01216179f, 0.009919960f, 0.007967240f, 0.006296346f, 0.004900000f, 0.003777173f, 0.002945320f, 0.002424880f, - 0.002236293f, 0.002400000f, 0.002925520f, 0.003836560f, 0.005174840f, 0.006982080f, 0.009300000f, 0.01214949f, - 0.01553588f, 0.01947752f, 0.02399277f, 0.02910000f, 0.03481485f, 0.04112016f, 0.04798504f, 0.05537861f, - 0.06327000f, 0.07163501f, 0.08046224f, 0.08973996f, 0.09945645f, 0.1096000f, 0.1201674f, 0.1311145f, - 0.1423679f, 0.1538542f, 0.1655000f, 0.1772571f, 0.1891400f, 0.2011694f, 0.2133658f, 0.2257499f, - 0.2383209f, 0.2510668f, 0.2639922f, 0.2771017f, 0.2904000f, 0.3038912f, 0.3175726f, 0.3314384f, - 0.3454828f, 0.3597000f, 0.3740839f, 0.3886396f, 0.4033784f, 0.4183115f, 0.4334499f, 0.4487953f, - 0.4643360f, 0.4800640f, 0.4959713f, 0.5120501f, 0.5282959f, 0.5446916f, 0.5612094f, 0.5778215f, - 0.5945000f, 0.6112209f, 0.6279758f, 0.6447602f, 0.6615697f, 0.6784000f, 0.6952392f, 0.7120586f, - 0.7288284f, 0.7455188f, 0.7621000f, 0.7785432f, 0.7948256f, 0.8109264f, 0.8268248f, 0.8425000f, - 0.8579325f, 0.8730816f, 0.8878944f, 0.9023181f, 0.9163000f, 0.9297995f, 0.9427984f, 0.9552776f, - 0.9672179f, 0.9786000f, 0.9893856f, 0.9995488f, 1.0090892f, 1.0180064f, 1.0263000f, 1.0339827f, - 1.0409860f, 1.0471880f, 1.0524667f, 1.0567000f, 1.0597944f, 1.0617992f, 1.0628068f, 1.0629096f, - 1.0622000f, 1.0607352f, 1.0584436f, 1.0552244f, 1.0509768f, 1.0456000f, 1.0390369f, 1.0313608f, - 1.0226662f, 1.0130477f, 1.0026000f, 0.9913675f, 0.9793314f, 0.9664916f, 0.9528479f, 0.9384000f, - 0.9231940f, 0.9072440f, 0.8905020f, 0.8729200f, 0.8544499f, 0.8350840f, 0.8149460f, 0.7941860f, - 0.7729540f, 0.7514000f, 0.7295836f, 0.7075888f, 0.6856022f, 0.6638104f, 0.6424000f, 0.6215149f, - 0.6011138f, 0.5811052f, 0.5613977f, 0.5419000f, 0.5225995f, 0.5035464f, 0.4847436f, 0.4661939f, - 0.4479000f, 0.4298613f, 0.4120980f, 0.3946440f, 0.3775333f, 0.3608000f, 0.3444563f, 0.3285168f, - 0.3130192f, 0.2980011f, 0.2835000f, 0.2695448f, 0.2561184f, 0.2431896f, 0.2307272f, 0.2187000f, - 0.2070971f, 0.1959232f, 0.1851708f, 0.1748323f, 0.1649000f, 0.1553667f, 0.1462300f, 0.1374900f, - 0.1291467f, 0.1212000f, 0.1136397f, 0.1064650f, 0.09969044f, 0.09333061f, 0.08740000f, 0.08190096f, - 0.07680428f, 0.07207712f, 0.06768664f, 0.06360000f, 0.05980685f, 0.05628216f, 0.05297104f, 0.04981861f, - 0.04677000f, 0.04378405f, 0.04087536f, 0.03807264f, 0.03540461f, 0.03290000f, 0.03056419f, 0.02838056f, - 0.02634484f, 0.02445275f, 0.02270000f, 0.02108429f, 0.01959988f, 0.01823732f, 0.01698717f, 0.01584000f, - 0.01479064f, 0.01383132f, 0.01294868f, 0.01212920f, 0.01135916f, 0.01062935f, 0.009938846f, 0.009288422f, - 0.008678854f, 0.008110916f, 0.007582388f, 0.007088746f, 0.006627313f, 0.006195408f, 0.005790346f, 0.005409826f, - 0.005052583f, 0.004717512f, 0.004403507f, 0.004109457f, 0.003833913f, 0.003575748f, 0.003334342f, 0.003109075f, - 0.002899327f, 0.002704348f, 0.002523020f, 0.002354168f, 0.002196616f, 0.002049190f, 0.001910960f, 0.001781438f, - 0.001660110f, 0.001546459f, 0.001439971f, 0.001340042f, 0.001246275f, 0.001158471f, 0.001076430f, 0.0009999493f, - 0.0009287358f, 0.0008624332f, 0.0008007503f, 0.0007433960f, 0.0006900786f, 0.0006405156f, 0.0005945021f, 0.0005518646f, - 0.0005124290f, 0.0004760213f, 0.0004424536f, 0.0004115117f, 0.0003829814f, 0.0003566491f, 0.0003323011f, 0.0003097586f, - 0.0002888871f, 0.0002695394f, 0.0002515682f, 0.0002348261f, 0.0002191710f, 0.0002045258f, 0.0001908405f, 0.0001780654f, - 0.0001661505f, 0.0001550236f, 0.0001446219f, 0.0001349098f, 0.0001258520f, 0.0001174130f, 0.0001095515f, 0.0001022245f, - 0.00009539445f, 0.00008902390f, 0.00008307527f, 0.00007751269f, 0.00007231304f, 0.00006745778f, 0.00006292844f, 0.00005870652f, - 0.00005477028f, 0.00005109918f, 0.00004767654f, 0.00004448567f, 0.00004150994f, 0.00003873324f, 0.00003614203f, 0.00003372352f, - 0.00003146487f, 0.00002935326f, 0.00002737573f, 0.00002552433f, 0.00002379376f, 0.00002217870f, 0.00002067383f, 0.00001927226f, - 0.00001796640f, 0.00001674991f, 0.00001561648f, 0.00001455977f, 0.00001357387f, 0.00001265436f, 0.00001179723f, 0.00001099844f, - 0.00001025398f, 0.000009559646f, 0.000008912044f, 0.000008308358f, 0.000007745769f, 0.000007221456f, 0.000006732475f, 0.000006276423f, - 0.000005851304f, 0.000005455118f, 0.000005085868f, 0.000004741466f, 0.000004420236f, 0.000004120783f, 0.000003841716f, 0.000003581652f, - 0.000003339127f, 0.000003112949f, 0.000002902121f, 0.000002705645f, 0.000002522525f, 0.000002351726f, 0.000002192415f, 0.000002043902f, - 0.000001905497f, 0.000001776509f, 0.000001656215f, 0.000001544022f, 0.000001439440f, 0.000001341977f, 0.000001251141f, + 0.0001299000f, 0.0001458470f, 0.0001638021f, 0.0001840037f, + 0.0002066902f, 0.0002321000f, 0.0002607280f, 0.0002930750f, + 0.0003293880f, 0.0003699140f, 0.0004149000f, 0.0004641587f, + 0.0005189860f, 0.0005818540f, 0.0006552347f, 0.0007416000f, + 0.0008450296f, 0.0009645268f, 0.001094949f, 0.001231154f, + 0.001368000f, 0.001502050f, 0.001642328f, 0.001802382f, + 0.001995757f, 0.002236000f, 0.002535385f, 0.002892603f, + 0.003300829f, 0.003753236f, 0.004243000f, 0.004762389f, + 0.005330048f, 0.005978712f, 0.006741117f, 0.007650000f, + 0.008751373f, 0.01002888f, 0.01142170f, 0.01286901f, + 0.01431000f, 0.01570443f, 0.01714744f, 0.01878122f, + 0.02074801f, 0.02319000f, 0.02620736f, 0.02978248f, + 0.03388092f, 0.03846824f, 0.04351000f, 0.04899560f, + 0.05502260f, 0.06171880f, 0.06921200f, 0.07763000f, + 0.08695811f, 0.09717672f, 0.1084063f, 0.1207672f, + 0.1343800f, 0.1493582f, 0.1653957f, 0.1819831f, + 0.1986110f, 0.2147700f, 0.2301868f, 0.2448797f, + 0.2587773f, 0.2718079f, 0.2839000f, 0.2949438f, + 0.3048965f, 0.3137873f, 0.3216454f, 0.3285000f, + 0.3343513f, 0.3392101f, 0.3431213f, 0.3461296f, + 0.3482800f, 0.3495999f, 0.3501474f, 0.3500130f, + 0.3492870f, 0.3480600f, 0.3463733f, 0.3442624f, + 0.3418088f, 0.3390941f, 0.3362000f, 0.3331977f, + 0.3300411f, 0.3266357f, 0.3228868f, 0.3187000f, + 0.3140251f, 0.3088840f, 0.3032904f, 0.2972579f, + 0.2908000f, 0.2839701f, 0.2767214f, 0.2689178f, + 0.2604227f, 0.2511000f, 0.2408475f, 0.2298512f, + 0.2184072f, 0.2068115f, 0.1953600f, 0.1842136f, + 0.1733273f, 0.1626881f, 0.1522833f, 0.1421000f, + 0.1321786f, 0.1225696f, 0.1132752f, 0.1042979f, + 0.09564000f, 0.08729955f, 0.07930804f, 0.07171776f, + 0.06458099f, 0.05795001f, 0.05186211f, 0.04628152f, + 0.04115088f, 0.03641283f, 0.03201000f, 0.02791720f, + 0.02414440f, 0.02068700f, 0.01754040f, 0.01470000f, + 0.01216179f, 0.009919960f, 0.007967240f, 0.006296346f, + 0.004900000f, 0.003777173f, 0.002945320f, 0.002424880f, + 0.002236293f, 0.002400000f, 0.002925520f, 0.003836560f, + 0.005174840f, 0.006982080f, 0.009300000f, 0.01214949f, + 0.01553588f, 0.01947752f, 0.02399277f, 0.02910000f, + 0.03481485f, 0.04112016f, 0.04798504f, 0.05537861f, + 0.06327000f, 0.07163501f, 0.08046224f, 0.08973996f, + 0.09945645f, 0.1096000f, 0.1201674f, 0.1311145f, + 0.1423679f, 0.1538542f, 0.1655000f, 0.1772571f, + 0.1891400f, 0.2011694f, 0.2133658f, 0.2257499f, + 0.2383209f, 0.2510668f, 0.2639922f, 0.2771017f, + 0.2904000f, 0.3038912f, 0.3175726f, 0.3314384f, + 0.3454828f, 0.3597000f, 0.3740839f, 0.3886396f, + 0.4033784f, 0.4183115f, 0.4334499f, 0.4487953f, + 0.4643360f, 0.4800640f, 0.4959713f, 0.5120501f, + 0.5282959f, 0.5446916f, 0.5612094f, 0.5778215f, + 0.5945000f, 0.6112209f, 0.6279758f, 0.6447602f, + 0.6615697f, 0.6784000f, 0.6952392f, 0.7120586f, + 0.7288284f, 0.7455188f, 0.7621000f, 0.7785432f, + 0.7948256f, 0.8109264f, 0.8268248f, 0.8425000f, + 0.8579325f, 0.8730816f, 0.8878944f, 0.9023181f, + 0.9163000f, 0.9297995f, 0.9427984f, 0.9552776f, + 0.9672179f, 0.9786000f, 0.9893856f, 0.9995488f, + 1.0090892f, 1.0180064f, 1.0263000f, 1.0339827f, + 1.0409860f, 1.0471880f, 1.0524667f, 1.0567000f, + 1.0597944f, 1.0617992f, 1.0628068f, 1.0629096f, + 1.0622000f, 1.0607352f, 1.0584436f, 1.0552244f, + 1.0509768f, 1.0456000f, 1.0390369f, 1.0313608f, + 1.0226662f, 1.0130477f, 1.0026000f, 0.9913675f, + 0.9793314f, 0.9664916f, 0.9528479f, 0.9384000f, + 0.9231940f, 0.9072440f, 0.8905020f, 0.8729200f, + 0.8544499f, 0.8350840f, 0.8149460f, 0.7941860f, + 0.7729540f, 0.7514000f, 0.7295836f, 0.7075888f, + 0.6856022f, 0.6638104f, 0.6424000f, 0.6215149f, + 0.6011138f, 0.5811052f, 0.5613977f, 0.5419000f, + 0.5225995f, 0.5035464f, 0.4847436f, 0.4661939f, + 0.4479000f, 0.4298613f, 0.4120980f, 0.3946440f, + 0.3775333f, 0.3608000f, 0.3444563f, 0.3285168f, + 0.3130192f, 0.2980011f, 0.2835000f, 0.2695448f, + 0.2561184f, 0.2431896f, 0.2307272f, 0.2187000f, + 0.2070971f, 0.1959232f, 0.1851708f, 0.1748323f, + 0.1649000f, 0.1553667f, 0.1462300f, 0.1374900f, + 0.1291467f, 0.1212000f, 0.1136397f, 0.1064650f, + 0.09969044f, 0.09333061f, 0.08740000f, 0.08190096f, + 0.07680428f, 0.07207712f, 0.06768664f, 0.06360000f, + 0.05980685f, 0.05628216f, 0.05297104f, 0.04981861f, + 0.04677000f, 0.04378405f, 0.04087536f, 0.03807264f, + 0.03540461f, 0.03290000f, 0.03056419f, 0.02838056f, + 0.02634484f, 0.02445275f, 0.02270000f, 0.02108429f, + 0.01959988f, 0.01823732f, 0.01698717f, 0.01584000f, + 0.01479064f, 0.01383132f, 0.01294868f, 0.01212920f, + 0.01135916f, 0.01062935f, 0.009938846f, 0.009288422f, + 0.008678854f, 0.008110916f, 0.007582388f, 0.007088746f, + 0.006627313f, 0.006195408f, 0.005790346f, 0.005409826f, + 0.005052583f, 0.004717512f, 0.004403507f, 0.004109457f, + 0.003833913f, 0.003575748f, 0.003334342f, 0.003109075f, + 0.002899327f, 0.002704348f, 0.002523020f, 0.002354168f, + 0.002196616f, 0.002049190f, 0.001910960f, 0.001781438f, + 0.001660110f, 0.001546459f, 0.001439971f, 0.001340042f, + 0.001246275f, 0.001158471f, 0.001076430f, 0.0009999493f, + 0.0009287358f, 0.0008624332f, 0.0008007503f, 0.0007433960f, + 0.0006900786f, 0.0006405156f, 0.0005945021f, 0.0005518646f, + 0.0005124290f, 0.0004760213f, 0.0004424536f, 0.0004115117f, + 0.0003829814f, 0.0003566491f, 0.0003323011f, 0.0003097586f, + 0.0002888871f, 0.0002695394f, 0.0002515682f, 0.0002348261f, + 0.0002191710f, 0.0002045258f, 0.0001908405f, 0.0001780654f, + 0.0001661505f, 0.0001550236f, 0.0001446219f, 0.0001349098f, + 0.0001258520f, 0.0001174130f, 0.0001095515f, 0.0001022245f, + 0.00009539445f, 0.00008902390f, 0.00008307527f, 0.00007751269f, + 0.00007231304f, 0.00006745778f, 0.00006292844f, 0.00005870652f, + 0.00005477028f, 0.00005109918f, 0.00004767654f, 0.00004448567f, + 0.00004150994f, 0.00003873324f, 0.00003614203f, 0.00003372352f, + 0.00003146487f, 0.00002935326f, 0.00002737573f, 0.00002552433f, + 0.00002379376f, 0.00002217870f, 0.00002067383f, 0.00001927226f, + 0.00001796640f, 0.00001674991f, 0.00001561648f, 0.00001455977f, + 0.00001357387f, 0.00001265436f, 0.00001179723f, 0.00001099844f, + 0.00001025398f, 0.000009559646f, 0.000008912044f, 0.000008308358f, + 0.000007745769f, 0.000007221456f, 0.000006732475f, 0.000006276423f, + 0.000005851304f, 0.000005455118f, 0.000005085868f, 0.000004741466f, + 0.000004420236f, 0.000004120783f, 0.000003841716f, 0.000003581652f, + 0.000003339127f, 0.000003112949f, 0.000002902121f, 0.000002705645f, + 0.000002522525f, 0.000002351726f, 0.000002192415f, 0.000002043902f, + 0.000001905497f, 0.000001776509f, 0.000001656215f, 0.000001544022f, + 0.000001439440f, 0.000001341977f, 0.000001251141f, }; inline constexpr float CIE_Y[CIE_SAMPLES] = { - 0.000003917000f, 0.000004393581f, 0.000004929604f, 0.000005532136f, 0.000006208245f, 0.000006965000f, 0.000007813219f, 0.000008767336f, - 0.000009839844f, 0.00001104323f, 0.00001239000f, 0.00001388641f, 0.00001555728f, 0.00001744296f, 0.00001958375f, 0.00002202000f, - 0.00002483965f, 0.00002804126f, 0.00003153104f, 0.00003521521f, 0.00003900000f, 0.00004282640f, 0.00004691460f, 0.00005158960f, - 0.00005717640f, 0.00006400000f, 0.00007234421f, 0.00008221224f, 0.00009350816f, 0.0001061361f, 0.0001200000f, 0.0001349840f, - 0.0001514920f, 0.0001702080f, 0.0001918160f, 0.0002170000f, 0.0002469067f, 0.0002812400f, 0.0003185200f, 0.0003572667f, - 0.0003960000f, 0.0004337147f, 0.0004730240f, 0.0005178760f, 0.0005722187f, 0.0006400000f, 0.0007245600f, 0.0008255000f, - 0.0009411600f, 0.001069880f, 0.001210000f, 0.001362091f, 0.001530752f, 0.001720368f, 0.001935323f, 0.002180000f, - 0.002454800f, 0.002764000f, 0.003117800f, 0.003526400f, 0.004000000f, 0.004546240f, 0.005159320f, 0.005829280f, - 0.006546160f, 0.007300000f, 0.008086507f, 0.008908720f, 0.009767680f, 0.01066443f, 0.01160000f, 0.01257317f, - 0.01358272f, 0.01462968f, 0.01571509f, 0.01684000f, 0.01800736f, 0.01921448f, 0.02045392f, 0.02171824f, - 0.02300000f, 0.02429461f, 0.02561024f, 0.02695857f, 0.02835125f, 0.02980000f, 0.03131083f, 0.03288368f, - 0.03452112f, 0.03622571f, 0.03800000f, 0.03984667f, 0.04176800f, 0.04376600f, 0.04584267f, 0.04800000f, - 0.05024368f, 0.05257304f, 0.05498056f, 0.05745872f, 0.06000000f, 0.06260197f, 0.06527752f, 0.06804208f, - 0.07091109f, 0.07390000f, 0.07701600f, 0.08026640f, 0.08366680f, 0.08723280f, 0.09098000f, 0.09491755f, - 0.09904584f, 0.1033674f, 0.1078846f, 0.1126000f, 0.1175320f, 0.1226744f, 0.1279928f, 0.1334528f, - 0.1390200f, 0.1446764f, 0.1504693f, 0.1564619f, 0.1627177f, 0.1693000f, 0.1762431f, 0.1835581f, - 0.1912735f, 0.1994180f, 0.2080200f, 0.2171199f, 0.2267345f, 0.2368571f, 0.2474812f, 0.2586000f, - 0.2701849f, 0.2822939f, 0.2950505f, 0.3085780f, 0.3230000f, 0.3384021f, 0.3546858f, 0.3716986f, - 0.3892875f, 0.4073000f, 0.4256299f, 0.4443096f, 0.4633944f, 0.4829395f, 0.5030000f, 0.5235693f, - 0.5445120f, 0.5656900f, 0.5869653f, 0.6082000f, 0.6293456f, 0.6503068f, 0.6708752f, 0.6908424f, - 0.7100000f, 0.7281852f, 0.7454636f, 0.7619694f, 0.7778368f, 0.7932000f, 0.8081104f, 0.8224962f, - 0.8363068f, 0.8494916f, 0.8620000f, 0.8738108f, 0.8849624f, 0.8954936f, 0.9054432f, 0.9148501f, - 0.9237348f, 0.9320924f, 0.9399226f, 0.9472252f, 0.9540000f, 0.9602561f, 0.9660074f, 0.9712606f, - 0.9760225f, 0.9803000f, 0.9840924f, 0.9874182f, 0.9903128f, 0.9928116f, 0.9949501f, 0.9967108f, - 0.9980983f, 0.9991120f, 0.9997482f, 1.0000000f, 0.9998567f, 0.9993046f, 0.9983255f, 0.9968987f, - 0.9950000f, 0.9926005f, 0.9897426f, 0.9864444f, 0.9827241f, 0.9786000f, 0.9740837f, 0.9691712f, - 0.9638568f, 0.9581349f, 0.9520000f, 0.9454504f, 0.9384992f, 0.9311628f, 0.9234576f, 0.9154000f, - 0.9070064f, 0.8982772f, 0.8892048f, 0.8797816f, 0.8700000f, 0.8598613f, 0.8493920f, 0.8386220f, - 0.8275813f, 0.8163000f, 0.8047947f, 0.7930820f, 0.7811920f, 0.7691547f, 0.7570000f, 0.7447541f, - 0.7324224f, 0.7200036f, 0.7074965f, 0.6949000f, 0.6822192f, 0.6694716f, 0.6566744f, 0.6438448f, - 0.6310000f, 0.6181555f, 0.6053144f, 0.5924756f, 0.5796379f, 0.5668000f, 0.5539611f, 0.5411372f, - 0.5283528f, 0.5156323f, 0.5030000f, 0.4904688f, 0.4780304f, 0.4656776f, 0.4534032f, 0.4412000f, - 0.4290800f, 0.4170360f, 0.4050320f, 0.3930320f, 0.3810000f, 0.3689184f, 0.3568272f, 0.3447768f, - 0.3328176f, 0.3210000f, 0.3093381f, 0.2978504f, 0.2865936f, 0.2756245f, 0.2650000f, 0.2547632f, - 0.2448896f, 0.2353344f, 0.2260528f, 0.2170000f, 0.2081616f, 0.1995488f, 0.1911552f, 0.1829744f, - 0.1750000f, 0.1672235f, 0.1596464f, 0.1522776f, 0.1451259f, 0.1382000f, 0.1315003f, 0.1250248f, - 0.1187792f, 0.1127691f, 0.1070000f, 0.1014762f, 0.09618864f, 0.09112296f, 0.08626485f, 0.08160000f, - 0.07712064f, 0.07282552f, 0.06871008f, 0.06476976f, 0.06100000f, 0.05739621f, 0.05395504f, 0.05067376f, - 0.04754965f, 0.04458000f, 0.04175872f, 0.03908496f, 0.03656384f, 0.03420048f, 0.03200000f, 0.02996261f, - 0.02807664f, 0.02632936f, 0.02470805f, 0.02320000f, 0.02180077f, 0.02050112f, 0.01928108f, 0.01812069f, - 0.01700000f, 0.01590379f, 0.01483718f, 0.01381068f, 0.01283478f, 0.01192000f, 0.01106831f, 0.01027339f, - 0.009533311f, 0.008846157f, 0.008210000f, 0.007623781f, 0.007085424f, 0.006591476f, 0.006138485f, 0.005723000f, - 0.005343059f, 0.004995796f, 0.004676404f, 0.004380075f, 0.004102000f, 0.003838453f, 0.003589099f, 0.003354219f, - 0.003134093f, 0.002929000f, 0.002738139f, 0.002559876f, 0.002393244f, 0.002237275f, 0.002091000f, 0.001953587f, - 0.001824580f, 0.001703580f, 0.001590187f, 0.001484000f, 0.001384496f, 0.001291268f, 0.001204092f, 0.001122744f, - 0.001047000f, 0.0009765896f, 0.0009111088f, 0.0008501332f, 0.0007932384f, 0.0007400000f, 0.0006900827f, 0.0006433100f, - 0.0005994960f, 0.0005584547f, 0.0005200000f, 0.0004839136f, 0.0004500528f, 0.0004183452f, 0.0003887184f, 0.0003611000f, - 0.0003353835f, 0.0003114404f, 0.0002891656f, 0.0002684539f, 0.0002492000f, 0.0002313019f, 0.0002146856f, 0.0001992884f, - 0.0001850475f, 0.0001719000f, 0.0001597781f, 0.0001486044f, 0.0001383016f, 0.0001287925f, 0.0001200000f, 0.0001118595f, - 0.0001043224f, 0.00009733560f, 0.00009084587f, 0.00008480000f, 0.00007914667f, 0.00007385800f, 0.00006891600f, 0.00006430267f, - 0.00006000000f, 0.00005598187f, 0.00005222560f, 0.00004871840f, 0.00004544747f, 0.00004240000f, 0.00003956104f, 0.00003691512f, - 0.00003444868f, 0.00003214816f, 0.00003000000f, 0.00002799125f, 0.00002611356f, 0.00002436024f, 0.00002272461f, 0.00002120000f, - 0.00001977855f, 0.00001845285f, 0.00001721687f, 0.00001606459f, 0.00001499000f, 0.00001398728f, 0.00001305155f, 0.00001217818f, - 0.00001136254f, 0.00001060000f, 0.000009885877f, 0.000009217304f, 0.000008592362f, 0.000008009133f, 0.000007465700f, 0.000006959567f, - 0.000006487995f, 0.000006048699f, 0.000005639396f, 0.000005257800f, 0.000004901771f, 0.000004569720f, 0.000004260194f, 0.000003971739f, - 0.000003702900f, 0.000003452163f, 0.000003218302f, 0.000003000300f, 0.000002797139f, 0.000002607800f, 0.000002431220f, 0.000002266531f, - 0.000002113013f, 0.000001969943f, 0.000001836600f, 0.000001712230f, 0.000001596228f, 0.000001488090f, 0.000001387314f, 0.000001293400f, - 0.000001205820f, 0.000001124143f, 0.000001048009f, 0.0000009770578f, 0.0000009109300f, 0.0000008492513f, 0.0000007917212f, 0.0000007380904f, - 0.0000006881098f, 0.0000006415300f, 0.0000005980895f, 0.0000005575746f, 0.0000005198080f, 0.0000004846123f, 0.0000004518100f, + 0.000003917000f, 0.000004393581f, 0.000004929604f, 0.000005532136f, + 0.000006208245f, 0.000006965000f, 0.000007813219f, 0.000008767336f, + 0.000009839844f, 0.00001104323f, 0.00001239000f, 0.00001388641f, + 0.00001555728f, 0.00001744296f, 0.00001958375f, 0.00002202000f, + 0.00002483965f, 0.00002804126f, 0.00003153104f, 0.00003521521f, + 0.00003900000f, 0.00004282640f, 0.00004691460f, 0.00005158960f, + 0.00005717640f, 0.00006400000f, 0.00007234421f, 0.00008221224f, + 0.00009350816f, 0.0001061361f, 0.0001200000f, 0.0001349840f, + 0.0001514920f, 0.0001702080f, 0.0001918160f, 0.0002170000f, + 0.0002469067f, 0.0002812400f, 0.0003185200f, 0.0003572667f, + 0.0003960000f, 0.0004337147f, 0.0004730240f, 0.0005178760f, + 0.0005722187f, 0.0006400000f, 0.0007245600f, 0.0008255000f, + 0.0009411600f, 0.001069880f, 0.001210000f, 0.001362091f, + 0.001530752f, 0.001720368f, 0.001935323f, 0.002180000f, + 0.002454800f, 0.002764000f, 0.003117800f, 0.003526400f, + 0.004000000f, 0.004546240f, 0.005159320f, 0.005829280f, + 0.006546160f, 0.007300000f, 0.008086507f, 0.008908720f, + 0.009767680f, 0.01066443f, 0.01160000f, 0.01257317f, + 0.01358272f, 0.01462968f, 0.01571509f, 0.01684000f, + 0.01800736f, 0.01921448f, 0.02045392f, 0.02171824f, + 0.02300000f, 0.02429461f, 0.02561024f, 0.02695857f, + 0.02835125f, 0.02980000f, 0.03131083f, 0.03288368f, + 0.03452112f, 0.03622571f, 0.03800000f, 0.03984667f, + 0.04176800f, 0.04376600f, 0.04584267f, 0.04800000f, + 0.05024368f, 0.05257304f, 0.05498056f, 0.05745872f, + 0.06000000f, 0.06260197f, 0.06527752f, 0.06804208f, + 0.07091109f, 0.07390000f, 0.07701600f, 0.08026640f, + 0.08366680f, 0.08723280f, 0.09098000f, 0.09491755f, + 0.09904584f, 0.1033674f, 0.1078846f, 0.1126000f, + 0.1175320f, 0.1226744f, 0.1279928f, 0.1334528f, + 0.1390200f, 0.1446764f, 0.1504693f, 0.1564619f, + 0.1627177f, 0.1693000f, 0.1762431f, 0.1835581f, + 0.1912735f, 0.1994180f, 0.2080200f, 0.2171199f, + 0.2267345f, 0.2368571f, 0.2474812f, 0.2586000f, + 0.2701849f, 0.2822939f, 0.2950505f, 0.3085780f, + 0.3230000f, 0.3384021f, 0.3546858f, 0.3716986f, + 0.3892875f, 0.4073000f, 0.4256299f, 0.4443096f, + 0.4633944f, 0.4829395f, 0.5030000f, 0.5235693f, + 0.5445120f, 0.5656900f, 0.5869653f, 0.6082000f, + 0.6293456f, 0.6503068f, 0.6708752f, 0.6908424f, + 0.7100000f, 0.7281852f, 0.7454636f, 0.7619694f, + 0.7778368f, 0.7932000f, 0.8081104f, 0.8224962f, + 0.8363068f, 0.8494916f, 0.8620000f, 0.8738108f, + 0.8849624f, 0.8954936f, 0.9054432f, 0.9148501f, + 0.9237348f, 0.9320924f, 0.9399226f, 0.9472252f, + 0.9540000f, 0.9602561f, 0.9660074f, 0.9712606f, + 0.9760225f, 0.9803000f, 0.9840924f, 0.9874182f, + 0.9903128f, 0.9928116f, 0.9949501f, 0.9967108f, + 0.9980983f, 0.9991120f, 0.9997482f, 1.0000000f, + 0.9998567f, 0.9993046f, 0.9983255f, 0.9968987f, + 0.9950000f, 0.9926005f, 0.9897426f, 0.9864444f, + 0.9827241f, 0.9786000f, 0.9740837f, 0.9691712f, + 0.9638568f, 0.9581349f, 0.9520000f, 0.9454504f, + 0.9384992f, 0.9311628f, 0.9234576f, 0.9154000f, + 0.9070064f, 0.8982772f, 0.8892048f, 0.8797816f, + 0.8700000f, 0.8598613f, 0.8493920f, 0.8386220f, + 0.8275813f, 0.8163000f, 0.8047947f, 0.7930820f, + 0.7811920f, 0.7691547f, 0.7570000f, 0.7447541f, + 0.7324224f, 0.7200036f, 0.7074965f, 0.6949000f, + 0.6822192f, 0.6694716f, 0.6566744f, 0.6438448f, + 0.6310000f, 0.6181555f, 0.6053144f, 0.5924756f, + 0.5796379f, 0.5668000f, 0.5539611f, 0.5411372f, + 0.5283528f, 0.5156323f, 0.5030000f, 0.4904688f, + 0.4780304f, 0.4656776f, 0.4534032f, 0.4412000f, + 0.4290800f, 0.4170360f, 0.4050320f, 0.3930320f, + 0.3810000f, 0.3689184f, 0.3568272f, 0.3447768f, + 0.3328176f, 0.3210000f, 0.3093381f, 0.2978504f, + 0.2865936f, 0.2756245f, 0.2650000f, 0.2547632f, + 0.2448896f, 0.2353344f, 0.2260528f, 0.2170000f, + 0.2081616f, 0.1995488f, 0.1911552f, 0.1829744f, + 0.1750000f, 0.1672235f, 0.1596464f, 0.1522776f, + 0.1451259f, 0.1382000f, 0.1315003f, 0.1250248f, + 0.1187792f, 0.1127691f, 0.1070000f, 0.1014762f, + 0.09618864f, 0.09112296f, 0.08626485f, 0.08160000f, + 0.07712064f, 0.07282552f, 0.06871008f, 0.06476976f, + 0.06100000f, 0.05739621f, 0.05395504f, 0.05067376f, + 0.04754965f, 0.04458000f, 0.04175872f, 0.03908496f, + 0.03656384f, 0.03420048f, 0.03200000f, 0.02996261f, + 0.02807664f, 0.02632936f, 0.02470805f, 0.02320000f, + 0.02180077f, 0.02050112f, 0.01928108f, 0.01812069f, + 0.01700000f, 0.01590379f, 0.01483718f, 0.01381068f, + 0.01283478f, 0.01192000f, 0.01106831f, 0.01027339f, + 0.009533311f, 0.008846157f, 0.008210000f, 0.007623781f, + 0.007085424f, 0.006591476f, 0.006138485f, 0.005723000f, + 0.005343059f, 0.004995796f, 0.004676404f, 0.004380075f, + 0.004102000f, 0.003838453f, 0.003589099f, 0.003354219f, + 0.003134093f, 0.002929000f, 0.002738139f, 0.002559876f, + 0.002393244f, 0.002237275f, 0.002091000f, 0.001953587f, + 0.001824580f, 0.001703580f, 0.001590187f, 0.001484000f, + 0.001384496f, 0.001291268f, 0.001204092f, 0.001122744f, + 0.001047000f, 0.0009765896f, 0.0009111088f, 0.0008501332f, + 0.0007932384f, 0.0007400000f, 0.0006900827f, 0.0006433100f, + 0.0005994960f, 0.0005584547f, 0.0005200000f, 0.0004839136f, + 0.0004500528f, 0.0004183452f, 0.0003887184f, 0.0003611000f, + 0.0003353835f, 0.0003114404f, 0.0002891656f, 0.0002684539f, + 0.0002492000f, 0.0002313019f, 0.0002146856f, 0.0001992884f, + 0.0001850475f, 0.0001719000f, 0.0001597781f, 0.0001486044f, + 0.0001383016f, 0.0001287925f, 0.0001200000f, 0.0001118595f, + 0.0001043224f, 0.00009733560f, 0.00009084587f, 0.00008480000f, + 0.00007914667f, 0.00007385800f, 0.00006891600f, 0.00006430267f, + 0.00006000000f, 0.00005598187f, 0.00005222560f, 0.00004871840f, + 0.00004544747f, 0.00004240000f, 0.00003956104f, 0.00003691512f, + 0.00003444868f, 0.00003214816f, 0.00003000000f, 0.00002799125f, + 0.00002611356f, 0.00002436024f, 0.00002272461f, 0.00002120000f, + 0.00001977855f, 0.00001845285f, 0.00001721687f, 0.00001606459f, + 0.00001499000f, 0.00001398728f, 0.00001305155f, 0.00001217818f, + 0.00001136254f, 0.00001060000f, 0.000009885877f, 0.000009217304f, + 0.000008592362f, 0.000008009133f, 0.000007465700f, 0.000006959567f, + 0.000006487995f, 0.000006048699f, 0.000005639396f, 0.000005257800f, + 0.000004901771f, 0.000004569720f, 0.000004260194f, 0.000003971739f, + 0.000003702900f, 0.000003452163f, 0.000003218302f, 0.000003000300f, + 0.000002797139f, 0.000002607800f, 0.000002431220f, 0.000002266531f, + 0.000002113013f, 0.000001969943f, 0.000001836600f, 0.000001712230f, + 0.000001596228f, 0.000001488090f, 0.000001387314f, 0.000001293400f, + 0.000001205820f, 0.000001124143f, 0.000001048009f, 0.0000009770578f, + 0.0000009109300f, 0.0000008492513f, 0.0000007917212f, 0.0000007380904f, + 0.0000006881098f, 0.0000006415300f, 0.0000005980895f, 0.0000005575746f, + 0.0000005198080f, 0.0000004846123f, 0.0000004518100f, }; inline constexpr float CIE_Z[CIE_SAMPLES] = { - 0.0006061000f, 0.0006808792f, 0.0007651456f, 0.0008600124f, 0.0009665928f, 0.001086000f, 0.001220586f, 0.001372729f, - 0.001543579f, 0.001734286f, 0.001946000f, 0.002177777f, 0.002435809f, 0.002731953f, 0.003078064f, 0.003486000f, - 0.003975227f, 0.004540880f, 0.005158320f, 0.005802907f, 0.006450001f, 0.007083216f, 0.007745488f, 0.008501152f, - 0.009414544f, 0.01054999f, 0.01196580f, 0.01365587f, 0.01558805f, 0.01773015f, 0.02005001f, 0.02251136f, - 0.02520288f, 0.02827972f, 0.03189704f, 0.03621000f, 0.04143771f, 0.04750372f, 0.05411988f, 0.06099803f, - 0.06785001f, 0.07448632f, 0.08136156f, 0.08915364f, 0.09854048f, 0.1102000f, 0.1246133f, 0.1417017f, - 0.1613035f, 0.1832568f, 0.2074000f, 0.2336921f, 0.2626114f, 0.2947746f, 0.3307985f, 0.3713000f, - 0.4162091f, 0.4654642f, 0.5196948f, 0.5795303f, 0.6456000f, 0.7184838f, 0.7967133f, 0.8778459f, - 0.9594390f, 1.0390501f, 1.1153673f, 1.1884971f, 1.2581233f, 1.3239296f, 1.3856000f, 1.4426352f, - 1.4948035f, 1.5421903f, 1.5848807f, 1.6229600f, 1.6564048f, 1.6852959f, 1.7098745f, 1.7303821f, - 1.7470600f, 1.7600446f, 1.7696233f, 1.7762637f, 1.7804334f, 1.7826000f, 1.7829682f, 1.7816998f, - 1.7791982f, 1.7758671f, 1.7721100f, 1.7682589f, 1.7640390f, 1.7589438f, 1.7524663f, 1.7441000f, - 1.7335595f, 1.7208581f, 1.7059369f, 1.6887372f, 1.6692000f, 1.6475287f, 1.6234127f, 1.5960223f, - 1.5645280f, 1.5281000f, 1.4861114f, 1.4395215f, 1.3898799f, 1.3387362f, 1.2876400f, 1.2374223f, - 1.1878243f, 1.1387611f, 1.0901480f, 1.0419000f, 0.9941976f, 0.9473473f, 0.9014531f, 0.8566193f, - 0.8129501f, 0.7705173f, 0.7294448f, 0.6899136f, 0.6521049f, 0.6162000f, 0.5823286f, 0.5504162f, - 0.5203376f, 0.4919673f, 0.4651800f, 0.4399246f, 0.4161836f, 0.3938822f, 0.3729459f, 0.3533000f, - 0.3348578f, 0.3175521f, 0.3013375f, 0.2861686f, 0.2720000f, 0.2588171f, 0.2464838f, 0.2347718f, - 0.2234533f, 0.2123000f, 0.2011692f, 0.1901196f, 0.1792254f, 0.1685608f, 0.1582000f, 0.1481383f, - 0.1383758f, 0.1289942f, 0.1200751f, 0.1117000f, 0.1039048f, 0.09666748f, 0.08998272f, 0.08384531f, - 0.07824999f, 0.07320899f, 0.06867816f, 0.06456784f, 0.06078835f, 0.05725001f, 0.05390435f, 0.05074664f, - 0.04775276f, 0.04489859f, 0.04216000f, 0.03950728f, 0.03693564f, 0.03445836f, 0.03208872f, 0.02984000f, - 0.02771181f, 0.02569444f, 0.02378716f, 0.02198925f, 0.02030000f, 0.01871805f, 0.01724036f, 0.01586364f, - 0.01458461f, 0.01340000f, 0.01230723f, 0.01130188f, 0.01037792f, 0.009529306f, 0.008749999f, 0.008035200f, - 0.007381600f, 0.006785400f, 0.006242800f, 0.005749999f, 0.005303600f, 0.004899800f, 0.004534200f, 0.004202400f, - 0.003900000f, 0.003623200f, 0.003370600f, 0.003141400f, 0.002934800f, 0.002749999f, 0.002585200f, 0.002438600f, - 0.002309400f, 0.002196800f, 0.002100000f, 0.002017733f, 0.001948200f, 0.001889800f, 0.001840933f, 0.001800000f, - 0.001766267f, 0.001737800f, 0.001711200f, 0.001683067f, 0.001650001f, 0.001610133f, 0.001564400f, 0.001513600f, - 0.001458533f, 0.001400000f, 0.001336667f, 0.001270000f, 0.001205000f, 0.001146667f, 0.001100000f, 0.001068800f, - 0.001049400f, 0.001035600f, 0.001021200f, 0.001000000f, 0.0009686400f, 0.0009299200f, 0.0008868800f, 0.0008425600f, - 0.0008000000f, 0.0007609600f, 0.0007236800f, 0.0006859200f, 0.0006454400f, 0.0006000000f, 0.0005478667f, 0.0004916000f, - 0.0004354000f, 0.0003834667f, 0.0003400000f, 0.0003072533f, 0.0002831600f, 0.0002654400f, 0.0002518133f, 0.0002400000f, - 0.0002295467f, 0.0002206400f, 0.0002119600f, 0.0002021867f, 0.0001900000f, 0.0001742133f, 0.0001556400f, 0.0001359600f, - 0.0001168533f, 0.0001000000f, 0.00008613333f, 0.00007460000f, 0.00006500000f, 0.00005693333f, 0.00004999999f, 0.00004416000f, - 0.00003948000f, 0.00003572000f, 0.00003264000f, 0.00003000000f, 0.00002765333f, 0.00002556000f, 0.00002364000f, 0.00002181333f, - 0.00002000000f, 0.00001813333f, 0.00001620000f, 0.00001420000f, 0.00001213333f, 0.00001000000f, 0.000007733333f, 0.000005400000f, - 0.000003200000f, 0.000001333333f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, - 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, - 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, - 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, - 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, - 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, - 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, - 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, - 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, - 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, - 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, - 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, - 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, - 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, - 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, - 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, - 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, - 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, - 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, - 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, - 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, - 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, - 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.0006061000f, 0.0006808792f, 0.0007651456f, 0.0008600124f, + 0.0009665928f, 0.001086000f, 0.001220586f, 0.001372729f, + 0.001543579f, 0.001734286f, 0.001946000f, 0.002177777f, + 0.002435809f, 0.002731953f, 0.003078064f, 0.003486000f, + 0.003975227f, 0.004540880f, 0.005158320f, 0.005802907f, + 0.006450001f, 0.007083216f, 0.007745488f, 0.008501152f, + 0.009414544f, 0.01054999f, 0.01196580f, 0.01365587f, + 0.01558805f, 0.01773015f, 0.02005001f, 0.02251136f, + 0.02520288f, 0.02827972f, 0.03189704f, 0.03621000f, + 0.04143771f, 0.04750372f, 0.05411988f, 0.06099803f, + 0.06785001f, 0.07448632f, 0.08136156f, 0.08915364f, + 0.09854048f, 0.1102000f, 0.1246133f, 0.1417017f, + 0.1613035f, 0.1832568f, 0.2074000f, 0.2336921f, + 0.2626114f, 0.2947746f, 0.3307985f, 0.3713000f, + 0.4162091f, 0.4654642f, 0.5196948f, 0.5795303f, + 0.6456000f, 0.7184838f, 0.7967133f, 0.8778459f, + 0.9594390f, 1.0390501f, 1.1153673f, 1.1884971f, + 1.2581233f, 1.3239296f, 1.3856000f, 1.4426352f, + 1.4948035f, 1.5421903f, 1.5848807f, 1.6229600f, + 1.6564048f, 1.6852959f, 1.7098745f, 1.7303821f, + 1.7470600f, 1.7600446f, 1.7696233f, 1.7762637f, + 1.7804334f, 1.7826000f, 1.7829682f, 1.7816998f, + 1.7791982f, 1.7758671f, 1.7721100f, 1.7682589f, + 1.7640390f, 1.7589438f, 1.7524663f, 1.7441000f, + 1.7335595f, 1.7208581f, 1.7059369f, 1.6887372f, + 1.6692000f, 1.6475287f, 1.6234127f, 1.5960223f, + 1.5645280f, 1.5281000f, 1.4861114f, 1.4395215f, + 1.3898799f, 1.3387362f, 1.2876400f, 1.2374223f, + 1.1878243f, 1.1387611f, 1.0901480f, 1.0419000f, + 0.9941976f, 0.9473473f, 0.9014531f, 0.8566193f, + 0.8129501f, 0.7705173f, 0.7294448f, 0.6899136f, + 0.6521049f, 0.6162000f, 0.5823286f, 0.5504162f, + 0.5203376f, 0.4919673f, 0.4651800f, 0.4399246f, + 0.4161836f, 0.3938822f, 0.3729459f, 0.3533000f, + 0.3348578f, 0.3175521f, 0.3013375f, 0.2861686f, + 0.2720000f, 0.2588171f, 0.2464838f, 0.2347718f, + 0.2234533f, 0.2123000f, 0.2011692f, 0.1901196f, + 0.1792254f, 0.1685608f, 0.1582000f, 0.1481383f, + 0.1383758f, 0.1289942f, 0.1200751f, 0.1117000f, + 0.1039048f, 0.09666748f, 0.08998272f, 0.08384531f, + 0.07824999f, 0.07320899f, 0.06867816f, 0.06456784f, + 0.06078835f, 0.05725001f, 0.05390435f, 0.05074664f, + 0.04775276f, 0.04489859f, 0.04216000f, 0.03950728f, + 0.03693564f, 0.03445836f, 0.03208872f, 0.02984000f, + 0.02771181f, 0.02569444f, 0.02378716f, 0.02198925f, + 0.02030000f, 0.01871805f, 0.01724036f, 0.01586364f, + 0.01458461f, 0.01340000f, 0.01230723f, 0.01130188f, + 0.01037792f, 0.009529306f, 0.008749999f, 0.008035200f, + 0.007381600f, 0.006785400f, 0.006242800f, 0.005749999f, + 0.005303600f, 0.004899800f, 0.004534200f, 0.004202400f, + 0.003900000f, 0.003623200f, 0.003370600f, 0.003141400f, + 0.002934800f, 0.002749999f, 0.002585200f, 0.002438600f, + 0.002309400f, 0.002196800f, 0.002100000f, 0.002017733f, + 0.001948200f, 0.001889800f, 0.001840933f, 0.001800000f, + 0.001766267f, 0.001737800f, 0.001711200f, 0.001683067f, + 0.001650001f, 0.001610133f, 0.001564400f, 0.001513600f, + 0.001458533f, 0.001400000f, 0.001336667f, 0.001270000f, + 0.001205000f, 0.001146667f, 0.001100000f, 0.001068800f, + 0.001049400f, 0.001035600f, 0.001021200f, 0.001000000f, + 0.0009686400f, 0.0009299200f, 0.0008868800f, 0.0008425600f, + 0.0008000000f, 0.0007609600f, 0.0007236800f, 0.0006859200f, + 0.0006454400f, 0.0006000000f, 0.0005478667f, 0.0004916000f, + 0.0004354000f, 0.0003834667f, 0.0003400000f, 0.0003072533f, + 0.0002831600f, 0.0002654400f, 0.0002518133f, 0.0002400000f, + 0.0002295467f, 0.0002206400f, 0.0002119600f, 0.0002021867f, + 0.0001900000f, 0.0001742133f, 0.0001556400f, 0.0001359600f, + 0.0001168533f, 0.0001000000f, 0.00008613333f, 0.00007460000f, + 0.00006500000f, 0.00005693333f, 0.00004999999f, 0.00004416000f, + 0.00003948000f, 0.00003572000f, 0.00003264000f, 0.00003000000f, + 0.00002765333f, 0.00002556000f, 0.00002364000f, 0.00002181333f, + 0.00002000000f, 0.00001813333f, 0.00001620000f, 0.00001420000f, + 0.00001213333f, 0.00001000000f, 0.000007733333f, 0.000005400000f, + 0.000003200000f, 0.000001333333f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, 0.000000000000f, + 0.000000000000f, 0.000000000000f, 0.000000000000f, }; diff --git a/apps/pbrt/render.h b/apps/pbrt/render.h index 612b249e9..7f6a6fad0 100644 --- a/apps/pbrt/render.h +++ b/apps/pbrt/render.h @@ -1,8 +1,7 @@ #pragma once -#include #include "runtime/bonsai_cpp.h" - +#include extern "C" { typedef float float3 __attribute__((ext_vector_type(3))); @@ -29,20 +28,19 @@ struct Shape { uint8_t tag; Shape_payload payload; }; -typedef uint8_t uint8_t4 __attribute__((ext_vector_type(4))); struct _tree_layout1 { float3 center; float radius; uint16_t nPrims; uint8_t axis; uint8_t pad0; - uint8_t4 split0on_nPrims; + std::array split0on_nPrims; } __attribute__((packed)); struct _tree_layout0 { uint32_t pCount; - Shape* prims; + Shape *prims; uint32_t nCount; - _tree_layout1* group0_index; + _tree_layout1 *group0_index; } __attribute__((packed)); struct _tree_layout2 { uint32_t offset; @@ -62,7 +60,8 @@ struct PerspectiveCamera { Transform render_from_camera; }; -void Shape_Sph(Shape& _ret0, const Sphere& s); -void Shape_Tri(Shape& _ret1, const Triangle& t); -void render(const PerspectiveCamera& camera, const uint32_t width, const uint32_t height, float3* out, const _tree_layout0& shapes); +void Shape_Sph(Shape &_ret0, const Sphere &s); +void Shape_Tri(Shape &_ret1, const Triangle &t); +void render(const PerspectiveCamera &camera, const uint32_t width, + const uint32_t height, float3 *out, const _tree_layout0 &shapes); } diff --git a/apps/pbrt/render_hook.cpp b/apps/pbrt/render_hook.cpp index cd94901e3..70b47f6b0 100644 --- a/apps/pbrt/render_hook.cpp +++ b/apps/pbrt/render_hook.cpp @@ -1,6 +1,7 @@ // Driver for apps/pbrt/render.bonsai, milestone 0. // -// ./build/compiler -p ssa -b cpp -i apps/pbrt/render.bonsai -o apps/pbrt/render +// ./build/compiler -p ssa -b cpp -i apps/pbrt/render.bonsai -o +// apps/pbrt/render // clang++ -std=c++20 -O3 apps/pbrt/render_hook.cpp apps/pbrt/render.o \ // -o apps/pbrt/render_runner // ./apps/pbrt/render_runner out.ppm @@ -155,10 +156,22 @@ Mat4 look_at(const Vec3 &pos, const Vec3 &look, const Vec3 &up) { const Vec3 new_up = cross(dir, right); Mat4 r = Mat4::identity(); - r.m[0][0] = right.x; r.m[0][1] = new_up.x; r.m[0][2] = dir.x; r.m[0][3] = pos.x; - r.m[1][0] = right.y; r.m[1][1] = new_up.y; r.m[1][2] = dir.y; r.m[1][3] = pos.y; - r.m[2][0] = right.z; r.m[2][1] = new_up.z; r.m[2][2] = dir.z; r.m[2][3] = pos.z; - r.m[3][0] = 0.0f; r.m[3][1] = 0.0f; r.m[3][2] = 0.0f; r.m[3][3] = 1.0f; + r.m[0][0] = right.x; + r.m[0][1] = new_up.x; + r.m[0][2] = dir.x; + r.m[0][3] = pos.x; + r.m[1][0] = right.y; + r.m[1][1] = new_up.y; + r.m[1][2] = dir.y; + r.m[1][3] = pos.y; + r.m[2][0] = right.z; + r.m[2][1] = new_up.z; + r.m[2][2] = dir.z; + r.m[2][3] = pos.z; + r.m[3][0] = 0.0f; + r.m[3][1] = 0.0f; + r.m[3][2] = 0.0f; + r.m[3][3] = 1.0f; return r; } @@ -246,22 +259,20 @@ _tree_layout0 build_bvh(std::vector &shapes) { tree.group0_index[self].axis = uint8_t(axis); const uint32_t mid = low + count / 2; - std::nth_element(shapes.begin() + low, shapes.begin() + mid, - shapes.begin() + high, - [axis](const Shape &a, const Shape &b) { - return bounds_of(a).center[axis] < - bounds_of(b).center[axis]; - }); + std::nth_element( + shapes.begin() + low, shapes.begin() + mid, shapes.begin() + high, + [axis](const Shape &a, const Shape &b) { + return bounds_of(a).center[axis] < bounds_of(b).center[axis]; + }); const uint32_t left = handle_range(low, mid, depth + 1); const uint32_t right = handle_range(mid, high, depth + 1); *reinterpret_cast( &tree.group0_index[self].split0on_nPrims) = right - self; - const Sphere merged = merge({tree.group0_index[left].center, - tree.group0_index[left].radius}, - {tree.group0_index[right].center, - tree.group0_index[right].radius}); + const Sphere merged = merge( + {tree.group0_index[left].center, tree.group0_index[left].radius}, + {tree.group0_index[right].center, tree.group0_index[right].radius}); tree.group0_index[self].center = merged.center; tree.group0_index[self].radius = merged.radius; return self; @@ -311,11 +322,15 @@ int main(int argc, char **argv) { const float aspect = float(width) / float(height); float screen_min_x, screen_max_x, screen_min_y, screen_max_y; if (aspect > 1.0f) { - screen_min_x = -aspect; screen_max_x = aspect; - screen_min_y = -1.0f; screen_max_y = 1.0f; + screen_min_x = -aspect; + screen_max_x = aspect; + screen_min_y = -1.0f; + screen_max_y = 1.0f; } else { - screen_min_x = -1.0f; screen_max_x = 1.0f; - screen_min_y = -1.0f / aspect; screen_max_y = 1.0f / aspect; + screen_min_x = -1.0f; + screen_max_x = 1.0f; + screen_min_y = -1.0f / aspect; + screen_max_y = 1.0f / aspect; } const float fov = 45.0f; @@ -330,9 +345,8 @@ int main(int argc, char **argv) { inverse(screen_from_camera) * inverse(raster_from_screen); // pbrt: the scene's camera-to-world transform. - const Mat4 render_from_camera = - look_at(Vec3{0.0f, 1.0f, 5.0f}, Vec3{0.0f, 0.0f, 0.0f}, - Vec3{0.0f, 1.0f, 0.0f}); + const Mat4 render_from_camera = look_at( + Vec3{0.0f, 1.0f, 5.0f}, Vec3{0.0f, 0.0f, 0.0f}, Vec3{0.0f, 1.0f, 0.0f}); PerspectiveCamera camera; camera.camera_from_raster = to_bonsai(camera_from_raster); @@ -359,10 +373,10 @@ int main(int argc, char **argv) { // asking an ill-posed question in the first place. const float g = 8.0f; const float y = -1.02f; - shapes.push_back(triangle_shape(float3{-g, y, -g}, float3{g, y, g}, - float3{g, y, -g})); - shapes.push_back(triangle_shape(float3{-g, y, -g}, float3{-g, y, g}, - float3{g, y, g})); + shapes.push_back( + triangle_shape(float3{-g, y, -g}, float3{g, y, g}, float3{g, y, -g})); + shapes.push_back( + triangle_shape(float3{-g, y, -g}, float3{-g, y, g}, float3{g, y, g})); _tree_layout0 tree = build_bvh(shapes); diff --git a/apps/pbrt/rgb2spec.h b/apps/pbrt/rgb2spec.h index 662b9c3ea..5fbedd691 100644 --- a/apps/pbrt/rgb2spec.h +++ b/apps/pbrt/rgb2spec.h @@ -61,8 +61,8 @@ inline double cie_interp(const double *data, double x) { // which is why the rule is fourth-order rather than trapezoidal. inline Tables init_tables() { Tables t{}; - const double h = (RGB2SPEC_CIE_LAMBDA_MAX - RGB2SPEC_CIE_LAMBDA_MIN) / - (FineSamples - 1); + const double h = + (RGB2SPEC_CIE_LAMBDA_MAX - RGB2SPEC_CIE_LAMBDA_MIN) / (FineSamples - 1); for (int i = 0; i < FineSamples; ++i) { const double lambda = RGB2SPEC_CIE_LAMBDA_MIN + i * h; diff --git a/apps/pbrt/rgb2spec_check.cpp b/apps/pbrt/rgb2spec_check.cpp index eef79b297..657f24a8e 100644 --- a/apps/pbrt/rgb2spec_check.cpp +++ b/apps/pbrt/rgb2spec_check.cpp @@ -51,11 +51,11 @@ int main() { // part of the spectrum and low elsewhere is what the sigmoid has to bend // to fit. const Case cases[] = { - {"black", 0.0f, 0.0f, 0.0f}, {"dark", 0.05f, 0.05f, 0.05f}, + {"black", 0.0f, 0.0f, 0.0f}, {"dark", 0.05f, 0.05f, 0.05f}, {"mid grey", 0.5f, 0.5f, 0.5f}, {"near white", 0.99f, 0.99f, 0.99f}, - {"red", 0.8f, 0.1f, 0.1f}, {"green", 0.1f, 0.7f, 0.2f}, - {"blue", 0.15f, 0.2f, 0.75f}, {"orange", 0.9f, 0.5f, 0.1f}, - {"cyan", 0.1f, 0.75f, 0.8f}, {"magenta", 0.75f, 0.1f, 0.7f}, + {"red", 0.8f, 0.1f, 0.1f}, {"green", 0.1f, 0.7f, 0.2f}, + {"blue", 0.15f, 0.2f, 0.75f}, {"orange", 0.9f, 0.5f, 0.1f}, + {"cyan", 0.1f, 0.75f, 0.8f}, {"magenta", 0.75f, 0.1f, 0.7f}, }; double worst = 0.0; diff --git a/apps/pbrt/rgb2spec_tables.h b/apps/pbrt/rgb2spec_tables.h index 77bf82a64..a0bb7bbbc 100644 --- a/apps/pbrt/rgb2spec_tables.h +++ b/apps/pbrt/rgb2spec_tables.h @@ -12,91 +12,135 @@ inline constexpr double RGB2SPEC_CIE_LAMBDA_MIN = 360.0; inline constexpr double RGB2SPEC_CIE_LAMBDA_MAX = 830.0; inline constexpr double RGB2SPEC_CIE_X[RGB2SPEC_CIE_SAMPLES] = { - 0.000129900000, 0.000232100000, 0.000414900000, 0.000741600000, 0.001368000000, - 0.002236000000, 0.004243000000, 0.007650000000, 0.014310000000, 0.023190000000, - 0.043510000000, 0.077630000000, 0.134380000000, 0.214770000000, 0.283900000000, - 0.328500000000, 0.348280000000, 0.348060000000, 0.336200000000, 0.318700000000, - 0.290800000000, 0.251100000000, 0.195360000000, 0.142100000000, 0.095640000000, - 0.057950010000, 0.032010000000, 0.014700000000, 0.004900000000, 0.002400000000, - 0.009300000000, 0.029100000000, 0.063270000000, 0.109600000000, 0.165500000000, - 0.225749900000, 0.290400000000, 0.359700000000, 0.433449900000, 0.512050100000, - 0.594500000000, 0.678400000000, 0.762100000000, 0.842500000000, 0.916300000000, - 0.978600000000, 1.026300000000, 1.056700000000, 1.062200000000, 1.045600000000, - 1.002600000000, 0.938400000000, 0.854449900000, 0.751400000000, 0.642400000000, - 0.541900000000, 0.447900000000, 0.360800000000, 0.283500000000, 0.218700000000, - 0.164900000000, 0.121200000000, 0.087400000000, 0.063600000000, 0.046770000000, - 0.032900000000, 0.022700000000, 0.015840000000, 0.011359160000, 0.008110916000, - 0.005790346000, 0.004109457000, 0.002899327000, 0.002049190000, 0.001439971000, - 0.000999949300, 0.000690078600, 0.000476021300, 0.000332301100, 0.000234826100, - 0.000166150500, 0.000117413000, 0.000083075270, 0.000058706520, 0.000041509940, - 0.000029353260, 0.000020673830, 0.000014559770, 0.000010253980, 0.000007221456, - 0.000005085868, 0.000003581652, 0.000002522525, 0.000001776509, 0.000001251141, + 0.000129900000, 0.000232100000, 0.000414900000, 0.000741600000, + 0.001368000000, 0.002236000000, 0.004243000000, 0.007650000000, + 0.014310000000, 0.023190000000, 0.043510000000, 0.077630000000, + 0.134380000000, 0.214770000000, 0.283900000000, 0.328500000000, + 0.348280000000, 0.348060000000, 0.336200000000, 0.318700000000, + 0.290800000000, 0.251100000000, 0.195360000000, 0.142100000000, + 0.095640000000, 0.057950010000, 0.032010000000, 0.014700000000, + 0.004900000000, 0.002400000000, 0.009300000000, 0.029100000000, + 0.063270000000, 0.109600000000, 0.165500000000, 0.225749900000, + 0.290400000000, 0.359700000000, 0.433449900000, 0.512050100000, + 0.594500000000, 0.678400000000, 0.762100000000, 0.842500000000, + 0.916300000000, 0.978600000000, 1.026300000000, 1.056700000000, + 1.062200000000, 1.045600000000, 1.002600000000, 0.938400000000, + 0.854449900000, 0.751400000000, 0.642400000000, 0.541900000000, + 0.447900000000, 0.360800000000, 0.283500000000, 0.218700000000, + 0.164900000000, 0.121200000000, 0.087400000000, 0.063600000000, + 0.046770000000, 0.032900000000, 0.022700000000, 0.015840000000, + 0.011359160000, 0.008110916000, 0.005790346000, 0.004109457000, + 0.002899327000, 0.002049190000, 0.001439971000, 0.000999949300, + 0.000690078600, 0.000476021300, 0.000332301100, 0.000234826100, + 0.000166150500, 0.000117413000, 0.000083075270, 0.000058706520, + 0.000041509940, 0.000029353260, 0.000020673830, 0.000014559770, + 0.000010253980, 0.000007221456, 0.000005085868, 0.000003581652, + 0.000002522525, 0.000001776509, 0.000001251141, }; inline constexpr double RGB2SPEC_CIE_Y[RGB2SPEC_CIE_SAMPLES] = { - 0.000003917000, 0.000006965000, 0.000012390000, 0.000022020000, 0.000039000000, - 0.000064000000, 0.000120000000, 0.000217000000, 0.000396000000, 0.000640000000, - 0.001210000000, 0.002180000000, 0.004000000000, 0.007300000000, 0.011600000000, - 0.016840000000, 0.023000000000, 0.029800000000, 0.038000000000, 0.048000000000, - 0.060000000000, 0.073900000000, 0.090980000000, 0.112600000000, 0.139020000000, - 0.169300000000, 0.208020000000, 0.258600000000, 0.323000000000, 0.407300000000, - 0.503000000000, 0.608200000000, 0.710000000000, 0.793200000000, 0.862000000000, - 0.914850100000, 0.954000000000, 0.980300000000, 0.994950100000, 1.000000000000, - 0.995000000000, 0.978600000000, 0.952000000000, 0.915400000000, 0.870000000000, - 0.816300000000, 0.757000000000, 0.694900000000, 0.631000000000, 0.566800000000, - 0.503000000000, 0.441200000000, 0.381000000000, 0.321000000000, 0.265000000000, - 0.217000000000, 0.175000000000, 0.138200000000, 0.107000000000, 0.081600000000, - 0.061000000000, 0.044580000000, 0.032000000000, 0.023200000000, 0.017000000000, - 0.011920000000, 0.008210000000, 0.005723000000, 0.004102000000, 0.002929000000, - 0.002091000000, 0.001484000000, 0.001047000000, 0.000740000000, 0.000520000000, - 0.000361100000, 0.000249200000, 0.000171900000, 0.000120000000, 0.000084800000, - 0.000060000000, 0.000042400000, 0.000030000000, 0.000021200000, 0.000014990000, - 0.000010600000, 0.000007465700, 0.000005257800, 0.000003702900, 0.000002607800, - 0.000001836600, 0.000001293400, 0.000000910930, 0.000000641530, 0.000000451810, + 0.000003917000, 0.000006965000, 0.000012390000, 0.000022020000, + 0.000039000000, 0.000064000000, 0.000120000000, 0.000217000000, + 0.000396000000, 0.000640000000, 0.001210000000, 0.002180000000, + 0.004000000000, 0.007300000000, 0.011600000000, 0.016840000000, + 0.023000000000, 0.029800000000, 0.038000000000, 0.048000000000, + 0.060000000000, 0.073900000000, 0.090980000000, 0.112600000000, + 0.139020000000, 0.169300000000, 0.208020000000, 0.258600000000, + 0.323000000000, 0.407300000000, 0.503000000000, 0.608200000000, + 0.710000000000, 0.793200000000, 0.862000000000, 0.914850100000, + 0.954000000000, 0.980300000000, 0.994950100000, 1.000000000000, + 0.995000000000, 0.978600000000, 0.952000000000, 0.915400000000, + 0.870000000000, 0.816300000000, 0.757000000000, 0.694900000000, + 0.631000000000, 0.566800000000, 0.503000000000, 0.441200000000, + 0.381000000000, 0.321000000000, 0.265000000000, 0.217000000000, + 0.175000000000, 0.138200000000, 0.107000000000, 0.081600000000, + 0.061000000000, 0.044580000000, 0.032000000000, 0.023200000000, + 0.017000000000, 0.011920000000, 0.008210000000, 0.005723000000, + 0.004102000000, 0.002929000000, 0.002091000000, 0.001484000000, + 0.001047000000, 0.000740000000, 0.000520000000, 0.000361100000, + 0.000249200000, 0.000171900000, 0.000120000000, 0.000084800000, + 0.000060000000, 0.000042400000, 0.000030000000, 0.000021200000, + 0.000014990000, 0.000010600000, 0.000007465700, 0.000005257800, + 0.000003702900, 0.000002607800, 0.000001836600, 0.000001293400, + 0.000000910930, 0.000000641530, 0.000000451810, }; inline constexpr double RGB2SPEC_CIE_Z[RGB2SPEC_CIE_SAMPLES] = { - 0.000606100000, 0.001086000000, 0.001946000000, 0.003486000000, 0.006450001000, - 0.010549990000, 0.020050010000, 0.036210000000, 0.067850010000, 0.110200000000, - 0.207400000000, 0.371300000000, 0.645600000000, 1.039050100000, 1.385600000000, - 1.622960000000, 1.747060000000, 1.782600000000, 1.772110000000, 1.744100000000, - 1.669200000000, 1.528100000000, 1.287640000000, 1.041900000000, 0.812950100000, - 0.616200000000, 0.465180000000, 0.353300000000, 0.272000000000, 0.212300000000, - 0.158200000000, 0.111700000000, 0.078249990000, 0.057250010000, 0.042160000000, - 0.029840000000, 0.020300000000, 0.013400000000, 0.008749999000, 0.005749999000, - 0.003900000000, 0.002749999000, 0.002100000000, 0.001800000000, 0.001650001000, - 0.001400000000, 0.001100000000, 0.001000000000, 0.000800000000, 0.000600000000, - 0.000340000000, 0.000240000000, 0.000190000000, 0.000100000000, 0.000049999990, - 0.000030000000, 0.000020000000, 0.000010000000, 0.000000000000, 0.000000000000, - 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, - 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, - 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, - 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, - 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, - 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, - 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, + 0.000606100000, 0.001086000000, 0.001946000000, 0.003486000000, + 0.006450001000, 0.010549990000, 0.020050010000, 0.036210000000, + 0.067850010000, 0.110200000000, 0.207400000000, 0.371300000000, + 0.645600000000, 1.039050100000, 1.385600000000, 1.622960000000, + 1.747060000000, 1.782600000000, 1.772110000000, 1.744100000000, + 1.669200000000, 1.528100000000, 1.287640000000, 1.041900000000, + 0.812950100000, 0.616200000000, 0.465180000000, 0.353300000000, + 0.272000000000, 0.212300000000, 0.158200000000, 0.111700000000, + 0.078249990000, 0.057250010000, 0.042160000000, 0.029840000000, + 0.020300000000, 0.013400000000, 0.008749999000, 0.005749999000, + 0.003900000000, 0.002749999000, 0.002100000000, 0.001800000000, + 0.001650001000, 0.001400000000, 0.001100000000, 0.001000000000, + 0.000800000000, 0.000600000000, 0.000340000000, 0.000240000000, + 0.000190000000, 0.000100000000, 0.000049999990, 0.000030000000, + 0.000020000000, 0.000010000000, 0.000000000000, 0.000000000000, + 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, + 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, + 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, + 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, + 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, + 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, + 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, + 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, + 0.000000000000, 0.000000000000, 0.000000000000, }; inline constexpr double RGB2SPEC_CIE_D65[RGB2SPEC_CIE_SAMPLES] = { - (46.6383 / 10566.864005283874576), (49.3637 / 10566.864005283874576), (52.0891 / 10566.864005283874576), (51.0323 / 10566.864005283874576), (49.9755 / 10566.864005283874576), - (52.3118 / 10566.864005283874576), (54.6482 / 10566.864005283874576), (68.7015 / 10566.864005283874576), (82.7549 / 10566.864005283874576), (87.1204 / 10566.864005283874576), - (91.486 / 10566.864005283874576), (92.4589 / 10566.864005283874576), (93.4318 / 10566.864005283874576), (90.057 / 10566.864005283874576), (86.6823 / 10566.864005283874576), - (95.7736 / 10566.864005283874576), (104.865 / 10566.864005283874576), (110.936 / 10566.864005283874576), (117.008 / 10566.864005283874576), (117.41 / 10566.864005283874576), - (117.812 / 10566.864005283874576), (116.336 / 10566.864005283874576), (114.861 / 10566.864005283874576), (115.392 / 10566.864005283874576), (115.923 / 10566.864005283874576), - (112.367 / 10566.864005283874576), (108.811 / 10566.864005283874576), (109.082 / 10566.864005283874576), (109.354 / 10566.864005283874576), (108.578 / 10566.864005283874576), - (107.802 / 10566.864005283874576), (106.296 / 10566.864005283874576), (104.79 / 10566.864005283874576), (106.239 / 10566.864005283874576), (107.689 / 10566.864005283874576), - (106.047 / 10566.864005283874576), (104.405 / 10566.864005283874576), (104.225 / 10566.864005283874576), (104.046 / 10566.864005283874576), (102.023 / 10566.864005283874576), - (100.0 / 10566.864005283874576), (98.1671 / 10566.864005283874576), (96.3342 / 10566.864005283874576), (96.0611 / 10566.864005283874576), (95.788 / 10566.864005283874576), - (92.2368 / 10566.864005283874576), (88.6856 / 10566.864005283874576), (89.3459 / 10566.864005283874576), (90.0062 / 10566.864005283874576), (89.8026 / 10566.864005283874576), - (89.5991 / 10566.864005283874576), (88.6489 / 10566.864005283874576), (87.6987 / 10566.864005283874576), (85.4936 / 10566.864005283874576), (83.2886 / 10566.864005283874576), - (83.4939 / 10566.864005283874576), (83.6992 / 10566.864005283874576), (81.863 / 10566.864005283874576), (80.0268 / 10566.864005283874576), (80.1207 / 10566.864005283874576), - (80.2146 / 10566.864005283874576), (81.2462 / 10566.864005283874576), (82.2778 / 10566.864005283874576), (80.281 / 10566.864005283874576), (78.2842 / 10566.864005283874576), - (74.0027 / 10566.864005283874576), (69.7213 / 10566.864005283874576), (70.6652 / 10566.864005283874576), (71.6091 / 10566.864005283874576), (72.979 / 10566.864005283874576), - (74.349 / 10566.864005283874576), (67.9765 / 10566.864005283874576), (61.604 / 10566.864005283874576), (65.7448 / 10566.864005283874576), (69.8856 / 10566.864005283874576), - (72.4863 / 10566.864005283874576), (75.087 / 10566.864005283874576), (69.3398 / 10566.864005283874576), (63.5927 / 10566.864005283874576), (55.0054 / 10566.864005283874576), - (46.4182 / 10566.864005283874576), (56.6118 / 10566.864005283874576), (66.8054 / 10566.864005283874576), (65.0941 / 10566.864005283874576), (63.3828 / 10566.864005283874576), - (63.8434 / 10566.864005283874576), (64.304 / 10566.864005283874576), (61.8779 / 10566.864005283874576), (59.4519 / 10566.864005283874576), (55.7054 / 10566.864005283874576), - (51.959 / 10566.864005283874576), (54.6998 / 10566.864005283874576), (57.4406 / 10566.864005283874576), (58.8765 / 10566.864005283874576), (60.3125 / 10566.864005283874576), + (46.6383 / 10566.864005283874576), (49.3637 / 10566.864005283874576), + (52.0891 / 10566.864005283874576), (51.0323 / 10566.864005283874576), + (49.9755 / 10566.864005283874576), (52.3118 / 10566.864005283874576), + (54.6482 / 10566.864005283874576), (68.7015 / 10566.864005283874576), + (82.7549 / 10566.864005283874576), (87.1204 / 10566.864005283874576), + (91.486 / 10566.864005283874576), (92.4589 / 10566.864005283874576), + (93.4318 / 10566.864005283874576), (90.057 / 10566.864005283874576), + (86.6823 / 10566.864005283874576), (95.7736 / 10566.864005283874576), + (104.865 / 10566.864005283874576), (110.936 / 10566.864005283874576), + (117.008 / 10566.864005283874576), (117.41 / 10566.864005283874576), + (117.812 / 10566.864005283874576), (116.336 / 10566.864005283874576), + (114.861 / 10566.864005283874576), (115.392 / 10566.864005283874576), + (115.923 / 10566.864005283874576), (112.367 / 10566.864005283874576), + (108.811 / 10566.864005283874576), (109.082 / 10566.864005283874576), + (109.354 / 10566.864005283874576), (108.578 / 10566.864005283874576), + (107.802 / 10566.864005283874576), (106.296 / 10566.864005283874576), + (104.79 / 10566.864005283874576), (106.239 / 10566.864005283874576), + (107.689 / 10566.864005283874576), (106.047 / 10566.864005283874576), + (104.405 / 10566.864005283874576), (104.225 / 10566.864005283874576), + (104.046 / 10566.864005283874576), (102.023 / 10566.864005283874576), + (100.0 / 10566.864005283874576), (98.1671 / 10566.864005283874576), + (96.3342 / 10566.864005283874576), (96.0611 / 10566.864005283874576), + (95.788 / 10566.864005283874576), (92.2368 / 10566.864005283874576), + (88.6856 / 10566.864005283874576), (89.3459 / 10566.864005283874576), + (90.0062 / 10566.864005283874576), (89.8026 / 10566.864005283874576), + (89.5991 / 10566.864005283874576), (88.6489 / 10566.864005283874576), + (87.6987 / 10566.864005283874576), (85.4936 / 10566.864005283874576), + (83.2886 / 10566.864005283874576), (83.4939 / 10566.864005283874576), + (83.6992 / 10566.864005283874576), (81.863 / 10566.864005283874576), + (80.0268 / 10566.864005283874576), (80.1207 / 10566.864005283874576), + (80.2146 / 10566.864005283874576), (81.2462 / 10566.864005283874576), + (82.2778 / 10566.864005283874576), (80.281 / 10566.864005283874576), + (78.2842 / 10566.864005283874576), (74.0027 / 10566.864005283874576), + (69.7213 / 10566.864005283874576), (70.6652 / 10566.864005283874576), + (71.6091 / 10566.864005283874576), (72.979 / 10566.864005283874576), + (74.349 / 10566.864005283874576), (67.9765 / 10566.864005283874576), + (61.604 / 10566.864005283874576), (65.7448 / 10566.864005283874576), + (69.8856 / 10566.864005283874576), (72.4863 / 10566.864005283874576), + (75.087 / 10566.864005283874576), (69.3398 / 10566.864005283874576), + (63.5927 / 10566.864005283874576), (55.0054 / 10566.864005283874576), + (46.4182 / 10566.864005283874576), (56.6118 / 10566.864005283874576), + (66.8054 / 10566.864005283874576), (65.0941 / 10566.864005283874576), + (63.3828 / 10566.864005283874576), (63.8434 / 10566.864005283874576), + (64.304 / 10566.864005283874576), (61.8779 / 10566.864005283874576), + (59.4519 / 10566.864005283874576), (55.7054 / 10566.864005283874576), + (51.959 / 10566.864005283874576), (54.6998 / 10566.864005283874576), + (57.4406 / 10566.864005283874576), (58.8765 / 10566.864005283874576), + (60.3125 / 10566.864005283874576), }; inline constexpr double XYZ_TO_SRGB[3][3] = { diff --git a/apps/pbrt/trace.bonsai b/apps/pbrt/trace.bonsai index 7eae0b0c8..295f7b708 100644 --- a/apps/pbrt/trace.bonsai +++ b/apps/pbrt/trace.bonsai @@ -12,7 +12,7 @@ func [[export]] trace_all(n : u32, rays : array[Ray, n]) = map(|r : Ray| trace(r schedule { tree[[Triangle]] TriangleBVH(low high : vec3f) with AABB(low, high) = | Interior(left : TriangleBVH, right : TriangleBVH) - | Leaf(data : array[Triangle]); + | Leaf(data : array[Triangle]) with data = data; triangles : TriangleBVH; diff --git a/apps/queries/2D/main.cpp b/apps/queries/2D/main.cpp index 8f21b3593..a65e992f6 100644 --- a/apps/queries/2D/main.cpp +++ b/apps/queries/2D/main.cpp @@ -19,7 +19,6 @@ bool operator==(const Point &a, const Point &b) { return (a.x == b.x) && (a.y == b.y); } - // -------- Choose one by uncommenting or defining via -D flag -------- // #define USE_UNIFORM // #define USE_NORMAL @@ -89,7 +88,8 @@ void export_to_csv(const set &input_set, const std::string &filename) { } out << "x, y\n"; // CSV header - input_set.for_each([&](const Point &point) { out << point.x << ", " << point.y << "\n"; }); + input_set.for_each( + [&](const Point &point) { out << point.x << ", " << point.y << "\n"; }); out.close(); } @@ -275,29 +275,29 @@ void verify_IntervalTree(const uint64_t input_index, if (input.group0_index[input_index].xl > prim.x) { std::cout << "Tree verification failed at index: " << input_index << " with prim = " << prim - << " and lb(x) = " << input.group0_index[input_index].xl - << std::endl; + << " and lb(x) = " + << input.group0_index[input_index].xl << std::endl; abort(); } if (input.group0_index[input_index].yl > prim.y) { std::cout << "Tree verification failed at index: " << input_index << " with prim = " << prim - << " and lb(y) = " << input.group0_index[input_index].yl - << std::endl; + << " and lb(y) = " + << input.group0_index[input_index].yl << std::endl; abort(); } if (input.group0_index[input_index].xh < prim.x) { std::cout << "Tree verification failed at index: " << input_index << " with prim = " << prim - << " and ub(x) = " << input.group0_index[input_index].xh - << std::endl; + << " and ub(x) = " + << input.group0_index[input_index].xh << std::endl; abort(); } if (input.group0_index[input_index].yh < prim.y) { std::cout << "Tree verification failed at index: " << input_index << " with prim = " << prim - << " and ub(y) = " << input.group0_index[input_index].yh - << std::endl; + << " and ub(y) = " + << input.group0_index[input_index].yh << std::endl; abort(); } } @@ -314,9 +314,10 @@ double benchmark_absd_query(const set &input, const _tree_layout0 &tree, std::cout << "Absd query, value = " << value << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries>( - "abs(x - y) <= 10", input, tree, k, m, absd_query, absd_query_fast, - linear_timedout, indexed_timedout, value); + auto [linear, indexed] = benchmark_1d_queries < PROFILE == 1, + set < Point >> ("abs(x - y) <= 10", input, tree, k, m, + absd_query, absd_query_fast, linear_timedout, + indexed_timedout, value); return static_cast(linear) / indexed; } @@ -329,9 +330,10 @@ double benchmark_absd_count_query(const set &input, std::cout << "Absd query, value = " << value << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries( - "COUNT(abs(x - y) <= 10)", input, tree, k, m, absd_count_query, - absd_count_query_fast, linear_timedout, indexed_timedout, value); + auto [linear, indexed] = benchmark_1d_queries < PROFILE == 1, + uint64_t > ("COUNT(abs(x - y) <= 10)", input, tree, k, m, + absd_count_query, absd_count_query_fast, + linear_timedout, indexed_timedout, value); return static_cast(linear) / indexed; } @@ -345,9 +347,10 @@ double benchmark_absd_count_aug_query(const set &input, std::cout << "Absd query, value = " << value << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries( - "aug COUNT(abs(x - y) <= 10)", input, tree, k, m, absd_count_query, - absd_count_query_fast_aug, linear_timedout, indexed_timedout, value); + auto [linear, indexed] = benchmark_1d_queries < PROFILE == 1, + uint64_t > ("aug COUNT(abs(x - y) <= 10)", input, tree, k, m, + absd_count_query, absd_count_query_fast_aug, + linear_timedout, indexed_timedout, value); return static_cast(linear) / indexed; } @@ -359,9 +362,10 @@ double benchmark_abss_query(const set &input, const _tree_layout0 &tree, std::cout << "Abss query, value = " << value << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries>( - "abs(x + y) <= 10", input, tree, k, m, abss_query, abss_query_fast, - linear_timedout, indexed_timedout, value); + auto [linear, indexed] = benchmark_1d_queries < PROFILE == 1, + set < Point >> ("abs(x + y) <= 10", input, tree, k, m, + abss_query, abss_query_fast, linear_timedout, + indexed_timedout, value); return static_cast(linear) / indexed; } @@ -374,9 +378,10 @@ double benchmark_abss_count_query(const set &input, std::cout << "Abss query, value = " << value << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries( - "COUNT(abs(x + y) <= 10)", input, tree, k, m, abss_count_query, - abss_count_query_fast, linear_timedout, indexed_timedout, value); + auto [linear, indexed] = benchmark_1d_queries < PROFILE == 1, + uint64_t > ("COUNT(abs(x + y) <= 10)", input, tree, k, m, + abss_count_query, abss_count_query_fast, + linear_timedout, indexed_timedout, value); return static_cast(linear) / indexed; } @@ -390,9 +395,10 @@ double benchmark_abss_count_aug_query(const set &input, std::cout << "Abss query, value = " << value << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries( - "aug COUNT(abs(x + y) <= 10)", input, tree, k, m, abss_count_query, - abss_count_query_fast_aug, linear_timedout, indexed_timedout, value); + auto [linear, indexed] = benchmark_1d_queries < PROFILE == 1, + uint64_t > ("aug COUNT(abs(x + y) <= 10)", input, tree, k, m, + abss_count_query, abss_count_query_fast_aug, + linear_timedout, indexed_timedout, value); return static_cast(linear) / indexed; } @@ -405,9 +411,10 @@ double benchmark_circle_query(const set &input, std::cout << "Circle query, value = " << value << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries>( - "x^2 + y^2 <= 100", input, tree, k, m, circle_query, circle_query_fast, - linear_timedout, indexed_timedout, value); + auto [linear, indexed] = benchmark_1d_queries < PROFILE == 1, + set < Point >> ("x^2 + y^2 <= 100", input, tree, k, m, + circle_query, circle_query_fast, + linear_timedout, indexed_timedout, value); return static_cast(linear) / indexed; } @@ -421,9 +428,10 @@ double benchmark_circle_count_query(const set &input, std::cout << "Circle query, value = " << value << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries( - "COUNT(x^2 + y^2 <= 100)", input, tree, k, m, circle_count_query, - circle_count_query_fast, linear_timedout, indexed_timedout, value); + auto [linear, indexed] = benchmark_1d_queries < PROFILE == 1, + uint64_t > ("COUNT(x^2 + y^2 <= 100)", input, tree, k, m, + circle_count_query, circle_count_query_fast, + linear_timedout, indexed_timedout, value); return static_cast(linear) / indexed; } @@ -437,9 +445,10 @@ double benchmark_circle_count_aug_query(const set &input, std::cout << "Circle query, value = " << value << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries( - "aug COUNT(x^2 + y^2 <= 100)", input, tree, k, m, circle_count_query, - circle_count_query_fast_aug, linear_timedout, indexed_timedout, value); + auto [linear, indexed] = benchmark_1d_queries < PROFILE == 1, + uint64_t > ("aug COUNT(x^2 + y^2 <= 100)", input, tree, k, m, + circle_count_query, circle_count_query_fast_aug, + linear_timedout, indexed_timedout, value); return static_cast(linear) / indexed; } diff --git a/apps/queries/count-1D/count1d_main.cpp b/apps/queries/count-1D/count1d_main.cpp index a32dc9b98..78e264a7b 100644 --- a/apps/queries/count-1D/count1d_main.cpp +++ b/apps/queries/count-1D/count1d_main.cpp @@ -220,20 +220,20 @@ double benchmark_range_query(const set &input, const _tree_layout0 &tree, << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries( - "-10 <= x <= 10", + auto [linear, indexed] = benchmark_1d_queries < PROFILE != 1, + uint64_t > ("-10 <= x <= 10", #ifdef PROFILE_UNFUSED - tree, + tree, #else - input, + input, #endif - tree, k, m, + tree, k, m, #ifdef PROFILE_UNFUSED - range_query_fast_unfused, range_query_fast, + range_query_fast_unfused, range_query_fast, #else - range_query, range_query_fast, + range_query, range_query_fast, #endif - linear_timedout, indexed_timedout, low, high); + linear_timedout, indexed_timedout, low, high); return static_cast(linear) / indexed; } @@ -245,20 +245,20 @@ double benchmark_eq_query(const set &input, const _tree_layout0 &tree, std::cout << "Equality query, value = " << value << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries( - "x == 42", + auto [linear, indexed] = benchmark_1d_queries < PROFILE != 1, + uint64_t > ("x == 42", #ifdef PROFILE_UNFUSED - tree, + tree, #else - input, + input, #endif - tree, k, m, + tree, k, m, #ifdef PROFILE_UNFUSED - eq_query_fast_unfused, eq_query_fast, + eq_query_fast_unfused, eq_query_fast, #else - eq_query, eq_query_fast, + eq_query, eq_query_fast, #endif - linear_timedout, indexed_timedout, value); + linear_timedout, indexed_timedout, value); return static_cast(linear) / indexed; } @@ -270,20 +270,20 @@ double benchmark_abs_query(const set &input, const _tree_layout0 &tree, std::cout << "Abs query, value = " << value << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries( - "abs(x) <= 10", + auto [linear, indexed] = benchmark_1d_queries < PROFILE != 1, + uint64_t > ("abs(x) <= 10", #ifdef PROFILE_UNFUSED - tree, + tree, #else - input, + input, #endif - tree, k, m, + tree, k, m, #ifdef PROFILE_UNFUSED - abs_query_fast_unfused, abs_query_fast, + abs_query_fast_unfused, abs_query_fast, #else - abs_query, abs_query_fast, + abs_query, abs_query_fast, #endif - linear_timedout, indexed_timedout, value); + linear_timedout, indexed_timedout, value); return static_cast(linear) / indexed; } @@ -295,20 +295,20 @@ double benchmark_sqr_query(const set &input, const _tree_layout0 &tree, std::cout << "Sqr query, value = " << value << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries( - "x^2 <= 100", + auto [linear, indexed] = benchmark_1d_queries < PROFILE != 1, + uint64_t > ("x^2 <= 100", #ifdef PROFILE_UNFUSED - tree, + tree, #else - input, + input, #endif - tree, k, m, + tree, k, m, #ifdef PROFILE_UNFUSED - sqr_query_fast_unfused, sqr_query_fast, + sqr_query_fast_unfused, sqr_query_fast, #else - sqr_query, sqr_query_fast, + sqr_query, sqr_query_fast, #endif - linear_timedout, indexed_timedout, value); + linear_timedout, indexed_timedout, value); return static_cast(linear) / indexed; } @@ -320,20 +320,20 @@ double benchmark_round_query(const set &input, const _tree_layout0 &tree, std::cout << "Round query, value = " << value << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries( - "round(x) == 10", + auto [linear, indexed] = benchmark_1d_queries < PROFILE != 1, + uint64_t > ("round(x) == 10", #ifdef PROFILE_UNFUSED - tree, + tree, #else - input, + input, #endif - tree, k, m, + tree, k, m, #ifdef PROFILE_UNFUSED - round_query_fast_unfused, round_query_fast, + round_query_fast_unfused, round_query_fast, #else - round_query, round_query_fast, + round_query, round_query_fast, #endif - linear_timedout, indexed_timedout, value); + linear_timedout, indexed_timedout, value); return static_cast(linear) / indexed; } @@ -345,20 +345,20 @@ double benchmark_poly_query(const set &input, const _tree_layout0 &tree, std::cout << "Poly query, value = " << value << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries( - "x^2 - 4 * x + 3 <= 0", + auto [linear, indexed] = benchmark_1d_queries < PROFILE != 1, + uint64_t > ("x^2 - 4 * x + 3 <= 0", #ifdef PROFILE_UNFUSED - tree, + tree, #else - input, + input, #endif - tree, k, m, + tree, k, m, #ifdef PROFILE_UNFUSED - poly_query_fast_unfused, poly_query_fast, + poly_query_fast_unfused, poly_query_fast, #else - poly_query, poly_query_fast, + poly_query, poly_query_fast, #endif - linear_timedout, indexed_timedout, value); + linear_timedout, indexed_timedout, value); return static_cast(linear) / indexed; } @@ -370,20 +370,20 @@ double benchmark_sqrt_query(const set &input, const _tree_layout0 &tree, std::cout << "Sqrt query, value = " << value << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries( - "sqrt(abs(x)) <= sqrt(10)", + auto [linear, indexed] = benchmark_1d_queries < PROFILE != 1, + uint64_t > ("sqrt(abs(x)) <= sqrt(10)", #ifdef PROFILE_UNFUSED - tree, + tree, #else - input, + input, #endif - tree, k, m, + tree, k, m, #ifdef PROFILE_UNFUSED - sqrt_query_fast_unfused, sqrt_query_fast, + sqrt_query_fast_unfused, sqrt_query_fast, #else - sqrt_query, sqrt_query_fast, + sqrt_query, sqrt_query_fast, #endif - linear_timedout, indexed_timedout, value); + linear_timedout, indexed_timedout, value); return static_cast(linear) / indexed; } @@ -418,20 +418,20 @@ double benchmark_stddev_query(const set &input, << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries( - "abs(x - u) > s * 3", + auto [linear, indexed] = benchmark_1d_queries < PROFILE != 1, + uint64_t > ("abs(x - u) > s * 3", #ifdef PROFILE_UNFUSED - tree, + tree, #else - input, + input, #endif - tree, k, m, + tree, k, m, #ifdef PROFILE_UNFUSED - stddev_query_fast_unfused, stddev_query_fast, + stddev_query_fast_unfused, stddev_query_fast, #else - stddev_query, stddev_query_fast, + stddev_query, stddev_query_fast, #endif - linear_timedout, indexed_timedout, mean, stddev3); + linear_timedout, indexed_timedout, mean, stddev3); return static_cast(linear) / indexed; } diff --git a/apps/queries/cp/cp_argmin.cpp b/apps/queries/cp/cp_argmin.cpp index 1d00d37bc..2fe837914 100644 --- a/apps/queries/cp/cp_argmin.cpp +++ b/apps/queries/cp/cp_argmin.cpp @@ -4,131 +4,153 @@ struct AABB { float3 high; }; -float SqDistPointAABB(const Point& pt, const AABB& a) { - const float3 v = pt.vec; - const float3 sqLow = (a.low - v) * (a.low - v); - const float3 low = select(v < a.low, sqLow, float3{0.00000000f}); - const float3 sqHigh = (v - a.high) * (v - a.high); - const float3 high = select(a.high < v, sqHigh, float3{0.00000000f}); - return reduce_add(low + high); +float SqDistPointAABB(const Point &pt, const AABB &a) { + const float3 v = pt.vec; + const float3 sqLow = (a.low - v) * (a.low - v); + const float3 low = select(v < a.low, sqLow, float3{0.00000000f}); + const float3 sqHigh = (v - a.high) * (v - a.high); + const float3 high = select(a.high < v, sqHigh, float3{0.00000000f}); + return reduce_add(low + high); } -float distmax_Point_AABB(const Point& pt, const AABB& a) { - const float3 _t1 = pt.vec; - const float3 d = min(a.low - _t1, _t1 - a.high); - return dot(d, d); +float distmax_Point_AABB(const Point &pt, const AABB &a) { + const float3 _t1 = pt.vec; + const float3 d = min(a.low - _t1, _t1 - a.high); + return dot(d, d); } -float distmin_Point_AABB(const Point& pt, const AABB& a) { - const float3 _t1 = pt.vec; - const float3 _t7 = max(max(a.low - _t1, _t1 - a.high), float3{0.00000000f}); - return dot(_t7, _t7); +float distmin_Point_AABB(const Point &pt, const AABB &a) { + const float3 _t1 = pt.vec; + const float3 _t7 = max(max(a.low - _t1, _t1 - a.high), float3{0.00000000f}); + return dot(_t7, _t7); } -std::tuple closestPointonTriangle(const Point& pt, const Triangle& tri) { - const float3 p = pt.vec; - const float3 a = tri.p0; - const float3 b = tri.p1; - const float3 c = tri.p2; - const float3 ab = b - a; - const float3 ac = c - a; - const float3 ap = p - a; - const float d1 = dot(ab, ap); - const float d2 = dot(ac, ap); - if (d1 <= 0.00000000f) { - if (d2 <= 0.00000000f) { - return std::tuple{Point{a}, Point{float3{1.00000000f, 0.00000000f, 0.00000000f}}}; +std::tuple closestPointonTriangle(const Point &pt, + const Triangle &tri) { + const float3 p = pt.vec; + const float3 a = tri.p0; + const float3 b = tri.p1; + const float3 c = tri.p2; + const float3 ab = b - a; + const float3 ac = c - a; + const float3 ap = p - a; + const float d1 = dot(ab, ap); + const float d2 = dot(ac, ap); + if (d1 <= 0.00000000f) { + if (d2 <= 0.00000000f) { + return std::tuple{ + Point{a}, Point{float3{1.00000000f, 0.00000000f, 0.00000000f}}}; + } } - } - const float3 bp = p - b; - const float d3 = dot(ab, bp); - const float d4 = dot(ac, bp); - if (0.00000000f <= d3) { - if (d4 <= d3) { - return std::tuple{Point{b}, Point{float3{0.00000000f, 1.00000000f, 0.00000000f}}}; + const float3 bp = p - b; + const float d3 = dot(ab, bp); + const float d4 = dot(ac, bp); + if (0.00000000f <= d3) { + if (d4 <= d3) { + return std::tuple{ + Point{b}, Point{float3{0.00000000f, 1.00000000f, 0.00000000f}}}; + } } - } - const float _t2 = (d1 * d4) - (d3 * d2); - if (_t2 <= 0.00000000f) { - if (0.00000000f <= d1) { - if (d3 <= 0.00000000f) { - const float _t4 = d1 / (d1 - d3); - return std::tuple{Point{a + (float3{_t4} * ab)}, Point{vector({1.00000000f - _t4, _t4, 0.00000000f})}}; - } + const float _t2 = (d1 * d4) - (d3 * d2); + if (_t2 <= 0.00000000f) { + if (0.00000000f <= d1) { + if (d3 <= 0.00000000f) { + const float _t4 = d1 / (d1 - d3); + return std::tuple{ + Point{a + (float3{_t4} * ab)}, + Point{vector( + {1.00000000f - _t4, _t4, 0.00000000f})}}; + } + } } - } - const float3 cp = p - c; - const float d5 = dot(ab, cp); - const float d6 = dot(ac, cp); - if (0.00000000f <= d6) { - if (d5 <= d6) { - return std::tuple{Point{c}, Point{float3{0.00000000f, 0.00000000f, 1.00000000f}}}; + const float3 cp = p - c; + const float d5 = dot(ab, cp); + const float d6 = dot(ac, cp); + if (0.00000000f <= d6) { + if (d5 <= d6) { + return std::tuple{ + Point{c}, Point{float3{0.00000000f, 0.00000000f, 1.00000000f}}}; + } } - } - const float _t7 = (d5 * d2) - (d1 * d6); - if (_t7 <= 0.00000000f) { - if (0.00000000f <= d2) { - if (d6 <= 0.00000000f) { - const float _t9 = d2 / (d2 - d6); - return std::tuple{Point{a + (float3{_t9} * ac)}, Point{vector({1.00000000f - _t9, 0.00000000f, _t9})}}; - } + const float _t7 = (d5 * d2) - (d1 * d6); + if (_t7 <= 0.00000000f) { + if (0.00000000f <= d2) { + if (d6 <= 0.00000000f) { + const float _t9 = d2 / (d2 - d6); + return std::tuple{ + Point{a + (float3{_t9} * ac)}, + Point{vector( + {1.00000000f - _t9, 0.00000000f, _t9})}}; + } + } } - } - const float _t12 = (d3 * d6) - (d5 * d4); - if (_t12 <= 0.00000000f) { - const float _t19 = d4 - d3; - if (0.00000000f <= _t19) { - const float _t18 = d5 - d6; - if (0.00000000f <= _t18) { - const float _t17 = _t19 / (_t19 + _t18); - return std::tuple{Point{b + (float3{_t17} * (c - b))}, Point{vector({0.00000000f, 1.00000000f - _t17, _t17})}}; - } + const float _t12 = (d3 * d6) - (d5 * d4); + if (_t12 <= 0.00000000f) { + const float _t19 = d4 - d3; + if (0.00000000f <= _t19) { + const float _t18 = d5 - d6; + if (0.00000000f <= _t18) { + const float _t17 = _t19 / (_t19 + _t18); + return std::tuple{ + Point{b + (float3{_t17} * (c - b))}, + Point{vector( + {0.00000000f, 1.00000000f - _t17, _t17})}}; + } + } } - } - const float _t22 = 1.00000000f / ((_t12 + _t7) + _t2); - const float v = _t7 * _t22; - const float w = _t2 * _t22; - const float u = _t12 * _t22; - return std::tuple{Point{(a + (ab * float3{v})) + (ac * float3{w})}, Point{vector({u, v, w})}}; + const float _t22 = 1.00000000f / ((_t12 + _t7) + _t2); + const float v = _t7 * _t22; + const float w = _t2 * _t22; + const float u = _t12 * _t22; + return std::tuple{ + Point{(a + (ab * float3{v})) + (ac * float3{w})}, + Point{vector({u, v, w})}}; } -float distmin_Point_Triangle(const Point& p, const Triangle& tri) { - const std::tuple pts = closestPointonTriangle(p, tri); - const float3 _t3 = p.vec - std::get<0>(pts).vec; - return dot(_t3, _t3); +float distmin_Point_Triangle(const Point &p, const Triangle &tri) { + const std::tuple pts = closestPointonTriangle(p, tri); + const float3 _t3 = p.vec - std::get<0>(pts).vec; + return dot(_t3, _t3); } -Triangle _traverse_tree0(const Point& p, const _tree_layout0& tris) { - std::tuple _best0 = std::tuple{std::numeric_limits::infinity(), Triangle{}}; - int32_t _queue_count0 = 1; - uint32_t _queue0[64]; - _queue0[0] = 0u; - do { - _queue_count0 -= 1; - const uint32_t& tris_index = _queue0[_queue_count0]; - const _tree_layout1* _t85 = tris.group0_index; - const _tree_layout1& _t86 = _t85[tris_index]; - const AABB _t91 = AABB{_t86.low, _t86.high}; - if (distmin_Point_AABB(p, _t91) < std::get<0>(_best0)) { - const uint32_t _t84 = _t86.nPrims; - if (_t84 == 0u) { - _best0 = argmin(_best0, std::tuple{distmax_Point_AABB(p, _t91), Triangle{}}); - const uint32_t _t11 = tris_index + _t86.offset; - const uint32_t _t18 = tris_index + 1u; - const bool _sort_cmp0 = distmin_Point_AABB(p, AABB{_t85[_t11].low, _t85[_t11].high}) < distmin_Point_AABB(p, AABB{_t85[_t18].low, _t85[_t18].high}); - const uint32_t _sort_tmp0 = (_sort_cmp0 ? _t18 : _t11); - const uint32_t _sort_tmp1 = (_sort_cmp0 ? _t11 : _t18); - _queue0[_queue_count0] = _sort_tmp0; - _queue0[_queue_count0 + 1] = _sort_tmp1; - _queue_count0 += 2; - } else { - for (uint32_t _idx0 = 0u; _idx0 < _t84; _idx0 += 1u) { - const Triangle& _t77 = tris.prims[_t86.offset + _idx0]; - const float _t78 = distmin_Point_Triangle(p, _t77); - if (_t78 < std::get<0>(_best0)) { - _best0 = std::tuple{_t78, _t77}; - } +Triangle _traverse_tree0(const Point &p, const _tree_layout0 &tris) { + std::tuple _best0 = std::tuple{ + std::numeric_limits::infinity(), Triangle{}}; + int32_t _queue_count0 = 1; + uint32_t _queue0[64]; + _queue0[0] = 0u; + do { + _queue_count0 -= 1; + const uint32_t &tris_index = _queue0[_queue_count0]; + const _tree_layout1 *_t85 = tris.group0_index; + const _tree_layout1 &_t86 = _t85[tris_index]; + const AABB _t91 = AABB{_t86.low, _t86.high}; + if (distmin_Point_AABB(p, _t91) < std::get<0>(_best0)) { + const uint32_t _t84 = _t86.nPrims; + if (_t84 == 0u) { + _best0 = argmin( + _best0, std::tuple{ + distmax_Point_AABB(p, _t91), Triangle{}}); + const uint32_t _t11 = tris_index + _t86.offset; + const uint32_t _t18 = tris_index + 1u; + const bool _sort_cmp0 = + distmin_Point_AABB(p, + AABB{_t85[_t11].low, _t85[_t11].high}) < + distmin_Point_AABB(p, + AABB{_t85[_t18].low, _t85[_t18].high}); + const uint32_t _sort_tmp0 = (_sort_cmp0 ? _t18 : _t11); + const uint32_t _sort_tmp1 = (_sort_cmp0 ? _t11 : _t18); + _queue0[_queue_count0] = _sort_tmp0; + _queue0[_queue_count0 + 1] = _sort_tmp1; + _queue_count0 += 2; + } else { + for (uint32_t _idx0 = 0u; _idx0 < _t84; _idx0 += 1u) { + const Triangle &_t77 = tris.prims[_t86.offset + _idx0]; + const float _t78 = distmin_Point_Triangle(p, _t77); + if (_t78 < std::get<0>(_best0)) { + _best0 = std::tuple{_t78, _t77}; + } + } + } } - } - } - } while (_queue_count0 != 0); - return std::get<1>(_best0); + } while (_queue_count0 != 0); + return std::get<1>(_best0); } -Triangle closest(const Point& p, const _tree_layout0& tris) { - return _traverse_tree0(p, tris); +Triangle closest(const Point &p, const _tree_layout0 &tris) { + return _traverse_tree0(p, tris); } diff --git a/apps/queries/cp/cp_minimum.cpp b/apps/queries/cp/cp_minimum.cpp index 914ab62eb..82f1c4d0f 100644 --- a/apps/queries/cp/cp_minimum.cpp +++ b/apps/queries/cp/cp_minimum.cpp @@ -4,148 +4,169 @@ struct AABB { float3 high; }; -float SqDistPointAABB(const Point& pt, const AABB& a) { - const float3 v = pt.vec; - const float3 sqLow = (a.low - v) * (a.low - v); - const float3 low = select(v < a.low, sqLow, float3{0.00000000f}); - const float3 sqHigh = (v - a.high) * (v - a.high); - const float3 high = select(a.high < v, sqHigh, float3{0.00000000f}); - return reduce_add(low + high); +float SqDistPointAABB(const Point &pt, const AABB &a) { + const float3 v = pt.vec; + const float3 sqLow = (a.low - v) * (a.low - v); + const float3 low = select(v < a.low, sqLow, float3{0.00000000f}); + const float3 sqHigh = (v - a.high) * (v - a.high); + const float3 high = select(a.high < v, sqHigh, float3{0.00000000f}); + return reduce_add(low + high); } -float distmax_Point_AABB(const Point& pt, const AABB& a) { - const float3 _t1 = pt.vec; - const float3 d = min(a.low - _t1, _t1 - a.high); - return dot(d, d); +float distmax_Point_AABB(const Point &pt, const AABB &a) { + const float3 _t1 = pt.vec; + const float3 d = min(a.low - _t1, _t1 - a.high); + return dot(d, d); } -float distmin_Point_AABB(const Point& pt, const AABB& a) { - const float3 _t1 = pt.vec; - const float3 _t7 = max(max(a.low - _t1, _t1 - a.high), float3{0.00000000f}); - return dot(_t7, _t7); +float distmin_Point_AABB(const Point &pt, const AABB &a) { + const float3 _t1 = pt.vec; + const float3 _t7 = max(max(a.low - _t1, _t1 - a.high), float3{0.00000000f}); + return dot(_t7, _t7); } -std::tuple closestPointonTriangle(const Point& pt, const Triangle& tri) { - const float3 p = pt.vec; - const float3 a = tri.p0; - const float3 b = tri.p1; - const float3 c = tri.p2; - const float3 ab = b - a; - const float3 ac = c - a; - const float3 ap = p - a; - const float d1 = dot(ab, ap); - const float d2 = dot(ac, ap); - if (d1 <= 0.00000000f) { - if (d2 <= 0.00000000f) { - return std::tuple{Point{a}, Point{float3{1.00000000f, 0.00000000f, 0.00000000f}}}; +std::tuple closestPointonTriangle(const Point &pt, + const Triangle &tri) { + const float3 p = pt.vec; + const float3 a = tri.p0; + const float3 b = tri.p1; + const float3 c = tri.p2; + const float3 ab = b - a; + const float3 ac = c - a; + const float3 ap = p - a; + const float d1 = dot(ab, ap); + const float d2 = dot(ac, ap); + if (d1 <= 0.00000000f) { + if (d2 <= 0.00000000f) { + return std::tuple{ + Point{a}, Point{float3{1.00000000f, 0.00000000f, 0.00000000f}}}; + } } - } - const float3 bp = p - b; - const float d3 = dot(ab, bp); - const float d4 = dot(ac, bp); - if (0.00000000f <= d3) { - if (d4 <= d3) { - return std::tuple{Point{b}, Point{float3{0.00000000f, 1.00000000f, 0.00000000f}}}; + const float3 bp = p - b; + const float d3 = dot(ab, bp); + const float d4 = dot(ac, bp); + if (0.00000000f <= d3) { + if (d4 <= d3) { + return std::tuple{ + Point{b}, Point{float3{0.00000000f, 1.00000000f, 0.00000000f}}}; + } } - } - const float _t2 = (d1 * d4) - (d3 * d2); - if (_t2 <= 0.00000000f) { - if (0.00000000f <= d1) { - if (d3 <= 0.00000000f) { - const float _t4 = d1 / (d1 - d3); - return std::tuple{Point{a + (float3{_t4} * ab)}, Point{vector({1.00000000f - _t4, _t4, 0.00000000f})}}; - } + const float _t2 = (d1 * d4) - (d3 * d2); + if (_t2 <= 0.00000000f) { + if (0.00000000f <= d1) { + if (d3 <= 0.00000000f) { + const float _t4 = d1 / (d1 - d3); + return std::tuple{ + Point{a + (float3{_t4} * ab)}, + Point{vector( + {1.00000000f - _t4, _t4, 0.00000000f})}}; + } + } } - } - const float3 cp = p - c; - const float d5 = dot(ab, cp); - const float d6 = dot(ac, cp); - if (0.00000000f <= d6) { - if (d5 <= d6) { - return std::tuple{Point{c}, Point{float3{0.00000000f, 0.00000000f, 1.00000000f}}}; + const float3 cp = p - c; + const float d5 = dot(ab, cp); + const float d6 = dot(ac, cp); + if (0.00000000f <= d6) { + if (d5 <= d6) { + return std::tuple{ + Point{c}, Point{float3{0.00000000f, 0.00000000f, 1.00000000f}}}; + } } - } - const float _t7 = (d5 * d2) - (d1 * d6); - if (_t7 <= 0.00000000f) { - if (0.00000000f <= d2) { - if (d6 <= 0.00000000f) { - const float _t9 = d2 / (d2 - d6); - return std::tuple{Point{a + (float3{_t9} * ac)}, Point{vector({1.00000000f - _t9, 0.00000000f, _t9})}}; - } + const float _t7 = (d5 * d2) - (d1 * d6); + if (_t7 <= 0.00000000f) { + if (0.00000000f <= d2) { + if (d6 <= 0.00000000f) { + const float _t9 = d2 / (d2 - d6); + return std::tuple{ + Point{a + (float3{_t9} * ac)}, + Point{vector( + {1.00000000f - _t9, 0.00000000f, _t9})}}; + } + } } - } - const float _t12 = (d3 * d6) - (d5 * d4); - if (_t12 <= 0.00000000f) { - const float _t19 = d4 - d3; - if (0.00000000f <= _t19) { - const float _t18 = d5 - d6; - if (0.00000000f <= _t18) { - const float _t17 = _t19 / (_t19 + _t18); - return std::tuple{Point{b + (float3{_t17} * (c - b))}, Point{vector({0.00000000f, 1.00000000f - _t17, _t17})}}; - } + const float _t12 = (d3 * d6) - (d5 * d4); + if (_t12 <= 0.00000000f) { + const float _t19 = d4 - d3; + if (0.00000000f <= _t19) { + const float _t18 = d5 - d6; + if (0.00000000f <= _t18) { + const float _t17 = _t19 / (_t19 + _t18); + return std::tuple{ + Point{b + (float3{_t17} * (c - b))}, + Point{vector( + {0.00000000f, 1.00000000f - _t17, _t17})}}; + } + } } - } - const float _t22 = 1.00000000f / ((_t12 + _t7) + _t2); - const float v = _t7 * _t22; - const float w = _t2 * _t22; - const float u = _t12 * _t22; - return std::tuple{Point{(a + (ab * float3{v})) + (ac * float3{w})}, Point{vector({u, v, w})}}; + const float _t22 = 1.00000000f / ((_t12 + _t7) + _t2); + const float v = _t7 * _t22; + const float w = _t2 * _t22; + const float u = _t12 * _t22; + return std::tuple{ + Point{(a + (ab * float3{v})) + (ac * float3{w})}, + Point{vector({u, v, w})}}; } -float distmin_Point_Triangle(const Point& p, const Triangle& tri) { - const std::tuple pts = closestPointonTriangle(p, tri); - const float3 _t3 = p.vec - std::get<0>(pts).vec; - return dot(_t3, _t3); +float distmin_Point_Triangle(const Point &p, const Triangle &tri) { + const std::tuple pts = closestPointonTriangle(p, tri); + const float3 _t3 = p.vec - std::get<0>(pts).vec; + return dot(_t3, _t3); } -float _traverse_tree0(const Point& p, const _tree_layout0& tris) { - float _best0 = std::numeric_limits::infinity(); - int32_t _queue_count0 = 1; - uint32_t _queue0[64]; - _queue0[0] = 0u; - do { - _queue_count0 -= 1; - const uint32_t& tris_index = _queue0[_queue_count0]; - const _tree_layout1* _t533 = tris.group0_index; - const _tree_layout1& _t534 = _t533[tris_index]; - if (distmin_Point_AABB(p, AABB{_t534.low, _t534.high}) < _best0) { - const uint32_t _t532 = _t534.nPrims; - if (_t532 == 0u) { - const uint32_t _t1 = tris_index + 1u; - const _tree_layout1& _t2 = _t533[_t1]; - const AABB _t8 = AABB{_t2.low, _t2.high}; - const float _t9 = distmax_Point_AABB(p, _t8); - const uint32_t _t14 = tris_index + _t534.offset; - const _tree_layout1& _t15 = _t533[_t14]; - const AABB _t24 = AABB{_t15.low, _t15.high}; - const float _t25 = distmax_Point_AABB(p, _t24); - _best0 = min(_best0, max(_t9, _t25)); - const float _t512 = distmin_Point_AABB(p, _t24); - if (_t9 < _t512) { - _queue0[_queue_count0] = _t1; - _queue_count0 += 1; - } else { - const float _t486 = distmin_Point_AABB(p, _t8); - if (_t25 < _t486) { - _queue0[_queue_count0] = _t14; - _queue_count0 += 1; - } else { - const bool _sort_cmp0 = _t512 < _t486; - const bool _t165 = (_t486 < _t512) | ((_t486 == _t512) & (_t9 < _t25)); - const uint32_t _sort_tmp0 = (_sort_cmp0 ? (_t165 ? _t14 : _t1) : (_t165 ? _t1 : _t14)); - const uint32_t _sort_tmp1 = (_sort_cmp0 ? (_t165 ? _t1 : _t14) : (_t165 ? _t14 : _t1)); - _queue0[_queue_count0] = _sort_tmp0; - _queue0[_queue_count0 + 1] = _sort_tmp1; - _queue_count0 += 2; - } +float _traverse_tree0(const Point &p, const _tree_layout0 &tris) { + float _best0 = std::numeric_limits::infinity(); + int32_t _queue_count0 = 1; + uint32_t _queue0[64]; + _queue0[0] = 0u; + do { + _queue_count0 -= 1; + const uint32_t &tris_index = _queue0[_queue_count0]; + const _tree_layout1 *_t533 = tris.group0_index; + const _tree_layout1 &_t534 = _t533[tris_index]; + if (distmin_Point_AABB(p, AABB{_t534.low, _t534.high}) < _best0) { + const uint32_t _t532 = _t534.nPrims; + if (_t532 == 0u) { + const uint32_t _t1 = tris_index + 1u; + const _tree_layout1 &_t2 = _t533[_t1]; + const AABB _t8 = AABB{_t2.low, _t2.high}; + const float _t9 = distmax_Point_AABB(p, _t8); + const uint32_t _t14 = tris_index + _t534.offset; + const _tree_layout1 &_t15 = _t533[_t14]; + const AABB _t24 = AABB{_t15.low, _t15.high}; + const float _t25 = distmax_Point_AABB(p, _t24); + _best0 = min(_best0, max(_t9, _t25)); + const float _t512 = distmin_Point_AABB(p, _t24); + if (_t9 < _t512) { + _queue0[_queue_count0] = _t1; + _queue_count0 += 1; + } else { + const float _t486 = distmin_Point_AABB(p, _t8); + if (_t25 < _t486) { + _queue0[_queue_count0] = _t14; + _queue_count0 += 1; + } else { + const bool _sort_cmp0 = _t512 < _t486; + const bool _t165 = + (_t486 < _t512) | ((_t486 == _t512) & (_t9 < _t25)); + const uint32_t _sort_tmp0 = + (_sort_cmp0 ? (_t165 ? _t14 : _t1) + : (_t165 ? _t1 : _t14)); + const uint32_t _sort_tmp1 = + (_sort_cmp0 ? (_t165 ? _t1 : _t14) + : (_t165 ? _t14 : _t1)); + _queue0[_queue_count0] = _sort_tmp0; + _queue0[_queue_count0 + 1] = _sort_tmp1; + _queue_count0 += 2; + } + } + } else { + for (uint32_t _idx0 = 0u; _idx0 < _t532; _idx0 += 1u) { + const float _t526 = distmin_Point_Triangle( + p, tris.prims[_t534.offset + _idx0]); + if (_t526 < _best0) { + _best0 = min(_best0, _t526); + } + } + } } - } else { - for (uint32_t _idx0 = 0u; _idx0 < _t532; _idx0 += 1u) { - const float _t526 = distmin_Point_Triangle(p, tris.prims[_t534.offset + _idx0]); - if (_t526 < _best0) { - _best0 = min(_best0, _t526); - } - } - } - } - } while (_queue_count0 != 0); - return _best0; + } while (_queue_count0 != 0); + return _best0; } -float closest(const Point& p, const _tree_layout0& tris) { - return _traverse_tree0(p, tris); +float closest(const Point &p, const _tree_layout0 &tris) { + return _traverse_tree0(p, tris); } diff --git a/apps/queries/cp/main.cpp b/apps/queries/cp/main.cpp index fa53635f4..c5d5fe674 100644 --- a/apps/queries/cp/main.cpp +++ b/apps/queries/cp/main.cpp @@ -1,5 +1,5 @@ -#include "runtime/bonsai_cpp.h" #include "cp_gen.h" +#include "runtime/bonsai_cpp.h" #include @@ -26,8 +26,9 @@ std::vector load_obj(const std::string &object) { // std::string object_path = "apps/queries/rt/" + object + ".obj"; // std::string material_path = "apps/queries/rt/" + object; - // std::string object_path = "/Users/ajroot/Downloads/xxx/" + object + ".obj"; - // std::string material_path = "/Users/ajroot/Downloads/xxx/" + object; + // std::string object_path = "/Users/ajroot/Downloads/xxx/" + object + + // ".obj"; std::string material_path = "/Users/ajroot/Downloads/xxx/" + + // object; std::string object_path = object + ".obj"; std::string material_path = object; @@ -81,7 +82,9 @@ std::vector load_obj(const std::string &object) { } _tree_layout0 copy_tree(fcpw::Aggregate<3> *aggregate) { - auto bvh_ptr = dynamic_cast, fcpw::Triangle>*>(aggregate); + auto bvh_ptr = + dynamic_cast, fcpw::Triangle> *>( + aggregate); if (!bvh_ptr) { std::cerr << "Error: Aggregate is not a BVH<3>!\n"; std::abort(); @@ -90,8 +93,8 @@ _tree_layout0 copy_tree(fcpw::Aggregate<3> *aggregate) { _tree_layout0 tree; tree.nCount = static_cast(bvh_ptr->flatTree.size()); if (tree.nCount > 0) { - tree.group0_index = - static_cast<_tree_layout1*>(malloc(sizeof(_tree_layout1) * tree.nCount)); + tree.group0_index = static_cast<_tree_layout1 *>( + malloc(sizeof(_tree_layout1) * tree.nCount)); if (!tree.group0_index) { std::cerr << "Malloc (nodes) failed" << std::endl; abort(); @@ -106,7 +109,10 @@ _tree_layout0 copy_tree(fcpw::Aggregate<3> *aggregate) { tree.group0_index[i].high[1] = bvh_ptr->flatTree[i].box.pMax[1]; tree.group0_index[i].high[2] = bvh_ptr->flatTree[i].box.pMax[2]; tree.group0_index[i].nPrims = bvh_ptr->flatTree[i].nReferences; - tree.group0_index[i].offset = (tree.group0_index[i].nPrims == 0) ? bvh_ptr->flatTree[i].secondChildOffset : bvh_ptr->flatTree[i].referenceOffset; + tree.group0_index[i].offset = + (tree.group0_index[i].nPrims == 0) + ? bvh_ptr->flatTree[i].secondChildOffset + : bvh_ptr->flatTree[i].referenceOffset; } } else { std::cerr << "Copying empty tree from FCPW " << std::endl; @@ -115,32 +121,51 @@ _tree_layout0 copy_tree(fcpw::Aggregate<3> *aggregate) { tree.pCount = static_cast(bvh_ptr->primitives.size()); if (tree.pCount > 0) { - tree.prims = static_cast(malloc(sizeof(Triangle) * tree.pCount)); + tree.prims = + static_cast(malloc(sizeof(Triangle) * tree.pCount)); if (!tree.prims) { std::cerr << "Malloc (triangles) failed" << std::endl; abort(); } for (uint32_t i = 0; i < tree.pCount; ++i) { const auto soup = bvh_ptr->primitives[i]->soup; - tree.prims[i].p0.x = soup->positions[bvh_ptr->primitives[i]->indices[0]][0]; - tree.prims[i].p0.y = soup->positions[bvh_ptr->primitives[i]->indices[0]][1]; - tree.prims[i].p0.z = soup->positions[bvh_ptr->primitives[i]->indices[0]][2]; - tree.prims[i].p1.x = soup->positions[bvh_ptr->primitives[i]->indices[1]][0]; - tree.prims[i].p1.y = soup->positions[bvh_ptr->primitives[i]->indices[1]][1]; - tree.prims[i].p1.z = soup->positions[bvh_ptr->primitives[i]->indices[1]][2]; - tree.prims[i].p2.x = soup->positions[bvh_ptr->primitives[i]->indices[2]][0]; - tree.prims[i].p2.y = soup->positions[bvh_ptr->primitives[i]->indices[2]][1]; - tree.prims[i].p2.z = soup->positions[bvh_ptr->primitives[i]->indices[2]][2]; + tree.prims[i].p0.x = + soup->positions[bvh_ptr->primitives[i]->indices[0]][0]; + tree.prims[i].p0.y = + soup->positions[bvh_ptr->primitives[i]->indices[0]][1]; + tree.prims[i].p0.z = + soup->positions[bvh_ptr->primitives[i]->indices[0]][2]; + tree.prims[i].p1.x = + soup->positions[bvh_ptr->primitives[i]->indices[1]][0]; + tree.prims[i].p1.y = + soup->positions[bvh_ptr->primitives[i]->indices[1]][1]; + tree.prims[i].p1.z = + soup->positions[bvh_ptr->primitives[i]->indices[1]][2]; + tree.prims[i].p2.x = + soup->positions[bvh_ptr->primitives[i]->indices[2]][0]; + tree.prims[i].p2.y = + soup->positions[bvh_ptr->primitives[i]->indices[2]][1]; + tree.prims[i].p2.z = + soup->positions[bvh_ptr->primitives[i]->indices[2]][2]; /* - tree.prims[i].p0.x() = soup->positions[bvh_ptr->primitives[i]->indices[0]][0]; - tree.prims[i].p0.y() = soup->positions[bvh_ptr->primitives[i]->indices[0]][1]; - tree.prims[i].p0.z() = soup->positions[bvh_ptr->primitives[i]->indices[0]][2]; - tree.prims[i].p1.x() = soup->positions[bvh_ptr->primitives[i]->indices[1]][0]; - tree.prims[i].p1.y() = soup->positions[bvh_ptr->primitives[i]->indices[1]][1]; - tree.prims[i].p1.z() = soup->positions[bvh_ptr->primitives[i]->indices[1]][2]; - tree.prims[i].p2.x() = soup->positions[bvh_ptr->primitives[i]->indices[2]][0]; - tree.prims[i].p2.y() = soup->positions[bvh_ptr->primitives[i]->indices[2]][1]; - tree.prims[i].p2.z() = soup->positions[bvh_ptr->primitives[i]->indices[2]][2]; + tree.prims[i].p0.x() = + soup->positions[bvh_ptr->primitives[i]->indices[0]][0]; + tree.prims[i].p0.y() = + soup->positions[bvh_ptr->primitives[i]->indices[0]][1]; + tree.prims[i].p0.z() = + soup->positions[bvh_ptr->primitives[i]->indices[0]][2]; + tree.prims[i].p1.x() = + soup->positions[bvh_ptr->primitives[i]->indices[1]][0]; + tree.prims[i].p1.y() = + soup->positions[bvh_ptr->primitives[i]->indices[1]][1]; + tree.prims[i].p1.z() = + soup->positions[bvh_ptr->primitives[i]->indices[1]][2]; + tree.prims[i].p2.x() = + soup->positions[bvh_ptr->primitives[i]->indices[2]][0]; + tree.prims[i].p2.y() = + soup->positions[bvh_ptr->primitives[i]->indices[2]][1]; + tree.prims[i].p2.z() = + soup->positions[bvh_ptr->primitives[i]->indices[2]][2]; */ } } else { @@ -150,9 +175,6 @@ _tree_layout0 copy_tree(fcpw::Aggregate<3> *aggregate) { return tree; } - - - void verify_results(const std::vector &fcpw_distances, const std::vector &bonsai_distances, int64_t num_queries, float distance_tolerance) { @@ -341,7 +363,8 @@ int main(int argc, char *argv[]) { auto t1 = clock::now(); // auto fcpw_time = - // std::chrono::duration_cast(t1 - t0).count(); + // std::chrono::duration_cast(t1 - + // t0).count(); // std::cout << "[fcpw] tree construction : " << fcpw_time << " ms" // << std::endl; @@ -352,7 +375,8 @@ int main(int argc, char *argv[]) { // t1 = clock::now(); // auto bonsai_time = - // std::chrono::duration_cast(t1 - t0).count(); + // std::chrono::duration_cast(t1 - + // t0).count(); // std::cout << "[bonsai] tree construction : " << bonsai_time << " ms" // << std::endl; diff --git a/apps/queries/joins/dist2d/main.cpp b/apps/queries/joins/dist2d/main.cpp index 2a1987305..bf528b2ff 100644 --- a/apps/queries/joins/dist2d/main.cpp +++ b/apps/queries/joins/dist2d/main.cpp @@ -93,7 +93,8 @@ void export_to_csv(const set &input_set, const std::string &filename) { } out << "x,y\n"; // CSV header - input_set.for_each([&](const Point &point) { out << point.x << ", " << point.y << "\n"; }); + input_set.for_each( + [&](const Point &point) { out << point.x << ", " << point.y << "\n"; }); out.close(); } @@ -238,11 +239,12 @@ auto benchmark_chebyshev(const set &input0, const set &input1, std::cout << "Chebyshev query, value = " << value << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - return benchmark_join>, - set>>>( - "chebyshev", input0, input1, tree0, tree1, k, m, chebyshev, - chebyshev_single, chebyshev_dual, nested_timedout, single_timedout, - dual_timedout, value); + return benchmark_join < PROFILE == 1, set>, + set < std::tuple < Point, + set < Point >>>> ("chebyshev", input0, input1, tree0, tree1, k, m, + chebyshev, chebyshev_single, chebyshev_dual, + nested_timedout, single_timedout, dual_timedout, + value); } /* auto benchmark_cosine(const set &input0, const set &input1, const @@ -266,14 +268,15 @@ auto benchmark_donut(const set &input0, const set &input1, float value0 = 0.0001; float value1 = 0.0002; #ifndef PROFILE - std::cout << "donut query, bounds = " << value0 << ", " << value1 << std::endl; + std::cout << "donut query, bounds = " << value0 << ", " << value1 + << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - return benchmark_join>, - set>>>( - "donut", input0, input1, tree0, tree1, k, m, donut, donut_single, - donut_dual, nested_timedout, single_timedout, dual_timedout, value0, - value1); + return benchmark_join < PROFILE == 1, set>, + set < std::tuple < Point, + set < Point >>>> ("donut", input0, input1, tree0, tree1, k, m, donut, + donut_single, donut_dual, nested_timedout, + single_timedout, dual_timedout, value0, value1); } /* @@ -404,8 +407,10 @@ int main(int argc, char **argv) { } // { - // auto [nested, single, dual] = benchmark_cosine(input_set0, input_set1, input_tree0, input_tree1, k, m); - // std::cout << "cosine: (" << size << ", " << nested << ", " << build_time << ", " << single << ", " << dual << ")" << std::endl; + // auto [nested, single, dual] = benchmark_cosine(input_set0, + // input_set1, input_tree0, input_tree1, k, m); std::cout << "cosine: (" + // << size << ", " << nested << ", " << build_time << ", " << single << + // ", " << dual << ")" << std::endl; // } { @@ -437,12 +442,12 @@ int main(int argc, char **argv) { std::free(input_tree1.prims); std::free(input_tree1.group0_index); } -// #ifdef PROFILE -// for (const auto &res : results) { -// std::cout << "(\"" << res.first << "\", "; -// pretty_print_vector(res.second); -// std::cout << ")," << std::endl; -// } -// #endif + // #ifdef PROFILE + // for (const auto &res : results) { + // std::cout << "(\"" << res.first << "\", "; + // pretty_print_vector(res.second); + // std::cout << ")," << std::endl; + // } + // #endif return 0; } diff --git a/apps/queries/joins/dist2d/main_torus.cpp b/apps/queries/joins/dist2d/main_torus.cpp index 5eb3827c6..6c6dedb2f 100644 --- a/apps/queries/joins/dist2d/main_torus.cpp +++ b/apps/queries/joins/dist2d/main_torus.cpp @@ -25,16 +25,17 @@ std::ostream &operator<<(std::ostream &os, const std::tuple &p) { return os; } - -set generate_random_circle(std::mt19937 &rng, size_t size, float radius) { +set generate_random_circle(std::mt19937 &rng, size_t size, + float radius) { set result; std::uniform_real_distribution angle_dist(0.0f, 2.0f * M_PI); - std::uniform_real_distribution radius_dist(0.0f, 1.0f); // for sqrt scaling - + std::uniform_real_distribution radius_dist(0.0f, + 1.0f); // for sqrt scaling while (result.size() < size) { float theta = angle_dist(rng); - float r = radius * std::sqrt(radius_dist(rng)); // uniform sampling in circle + float r = + radius * std::sqrt(radius_dist(rng)); // uniform sampling in circle float x = r * std::cos(theta); float y = r * std::sin(theta); result.push_back(Point{x, y}); @@ -51,7 +52,8 @@ void export_to_csv(const set &input_set, const std::string &filename) { } out << "x,y\n"; // CSV header - input_set.for_each([&](const Point &point) { out << point.x << ", " << point.y << "\n"; }); + input_set.for_each( + [&](const Point &point) { out << point.x << ", " << point.y << "\n"; }); out.close(); } @@ -187,14 +189,15 @@ auto benchmark_donut(const set &input0, const set &input1, float value0 = 10; float value1 = 20; #ifndef PROFILE - std::cout << "donut query, bounds = " << value0 << ", " << value1 << std::endl; + std::cout << "donut query, bounds = " << value0 << ", " << value1 + << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - return benchmark_join>, - set>>>( - "donut", input0, input1, tree0, tree1, k, m, donut, donut_single, - donut_dual, nested_timedout, single_timedout, dual_timedout, value0, - value1); + return benchmark_join < PROFILE == 1, set>, + set < std::tuple < Point, + set < Point >>>> ("donut", input0, input1, tree0, tree1, k, m, donut, + donut_single, donut_dual, nested_timedout, + single_timedout, dual_timedout, value0, value1); } template @@ -213,7 +216,7 @@ void pretty_print_vector(const std::vector &vec) { // #define EXPORT 1 -int main(int argc, char** argv) { +int main(int argc, char **argv) { const int k = 7; // total runs const int m = 1; // number of fastest and slowest to drop diff --git a/apps/queries/joins/main.cpp b/apps/queries/joins/main.cpp index 4623a0404..259fe371d 100644 --- a/apps/queries/joins/main.cpp +++ b/apps/queries/joins/main.cpp @@ -93,7 +93,8 @@ void export_to_csv(const set &input_set, const std::string &filename) { } out << "x, y\n"; // CSV header - input_set.for_each([&](const Point &point) { out << point.x << ", " << point.y << "\n"; }); + input_set.for_each( + [&](const Point &point) { out << point.x << ", " << point.y << "\n"; }); out.close(); } @@ -231,8 +232,7 @@ _tree_layout0 build_tree(const set &input) { return tree; } -void verify_scan(const uint64_t input_index, - const _tree_layout0 input, +void verify_scan(const uint64_t input_index, const _tree_layout0 input, float xlow, float xhigh) { if (input.group0_index[input_index].nPrims == 0u) { verify_scan(input_index + 1u, input, xlow, xhigh); @@ -255,31 +255,32 @@ void verify_scan(const uint64_t input_index, if (xlow > prim.x) { std::cout << "Tree verification failed at index: " << input_index << " with prim = " << prim - << " and lb(x) = " << xlow - << std::endl; + << " and lb(x) = " << xlow << std::endl; abort(); } if (xhigh < prim.x) { std::cout << "Tree verification failed at index: " << input_index << " with prim = " << prim - << " and ub(x) = " << xhigh - << std::endl; + << " and ub(x) = " << xhigh << std::endl; abort(); } } } - } void verify_IntervalTree(const uint64_t input_index, const _tree_layout0 input) { if (input.group0_index[input_index].nPrims == 0u) { - verify_scan(input_index + 1u, input, input.group0_index[input_index].xl, input.group0_index[input_index].xh); - verify_scan(input_index + + verify_scan(input_index + 1u, input, input.group0_index[input_index].xl, + input.group0_index[input_index].xh); + verify_scan( + input_index + (uint64_t)(reinterpret<_tree_layout2>( input.group0_index[input_index].split0on_nPrims) - .offset), input, input.group0_index[input_index].xl, input.group0_index[input_index].xh); - + .offset), + input, input.group0_index[input_index].xl, + input.group0_index[input_index].xh); + verify_IntervalTree(input_index + 1u, input); verify_IntervalTree( input_index + @@ -300,28 +301,30 @@ void verify_IntervalTree(const uint64_t input_index, if (input.group0_index[input_index].xl > prim.x) { std::cout << "Tree verification failed at index: " << input_index << " with prim = " << prim - << " and lb(x) = " << input.group0_index[input_index].xl - << std::endl; + << " and lb(x) = " + << input.group0_index[input_index].xl << std::endl; abort(); } // if (input.group0_index[input_index].yl > prim.y) { // std::cout << "Tree verification failed at index: " // << input_index << " with prim = " << prim - // << " and lb(y) = " << input.group0_index[input_index].yl + // << " and lb(y) = " << + // input.group0_index[input_index].yl // << std::endl; // abort(); // } if (input.group0_index[input_index].xh < prim.x) { std::cout << "Tree verification failed at index: " << input_index << " with prim = " << prim - << " and ub(x) = " << input.group0_index[input_index].xh - << std::endl; + << " and ub(x) = " + << input.group0_index[input_index].xh << std::endl; abort(); } // if (input.group0_index[input_index].yh < prim.y) { // std::cout << "Tree verification failed at index: " // << input_index << " with prim = " << prim - // << " and ub(y) = " << input.group0_index[input_index].yh + // << " and ub(y) = " << + // input.group0_index[input_index].yh // << std::endl; // abort(); // } @@ -331,19 +334,23 @@ void verify_IntervalTree(const uint64_t input_index, #define PROFILE 0 -auto benchmark_1d_dist_join_query(const set &input0, const set &input1, const _tree_layout0 &tree0, const _tree_layout0 &tree1, - const int k, const int m) { +auto benchmark_1d_dist_join_query(const set &input0, + const set &input1, + const _tree_layout0 &tree0, + const _tree_layout0 &tree1, const int k, + const int m) { float value = 0.001; #ifndef PROFILE std::cout << "Absd query, value = " << value << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - return benchmark_join>, set>>> - ("abs(a.x - b.x) < 0.1", input0, input1, tree0, tree1, k, m, - dist_join_1d, dist_join_1d_single, dist_join_1d_dual, value); + return benchmark_join < PROFILE == 1, set>, + set < std::tuple < Point, + set < Point >>>> ("abs(a.x - b.x) < 0.1", input0, input1, tree0, + tree1, k, m, dist_join_1d, dist_join_1d_single, + dist_join_1d_dual, value); } - template void pretty_print_vector(const std::vector &vec) { bool first = true; @@ -362,7 +369,7 @@ void pretty_print_vector(const std::vector &vec) { int main() { const int k = 3; // total runs - const int m = 0; // number of fastest and slowest to drop + const int m = 0; // number of fastest and slowest to drop // std::mt19937 rng(std::random_device{}()); // For consistent results @@ -371,11 +378,9 @@ int main() { std::vector test_sizes = { 1ull << 8, 1ull << 9, 1ull << 10, 1ull << 11, 1ull << 12, 1ull << 13, 1ull << 14, 1ull << 15, 1ull << 16, 1ull << 17, - 1ull << 18,1ull << 19, - 1ull << 20, 1ull << 21, 1ull << 22, + 1ull << 18, 1ull << 19, 1ull << 20, 1ull << 21, 1ull << 22, 1ull << 23, 1ull << 24, 1ull << 25, 1ull << 26, 1ull << 27, - 1ull << 28, 1ull << 29, 1ull << 30, 1ull << 31, (1ull << 32) - 1 - }; + 1ull << 28, 1ull << 29, 1ull << 30, 1ull << 31, (1ull << 32) - 1}; #if defined(USE_NORMAL) std::cout << "normal distribution" << std::endl; #elif defined(USE_EXPONENTIAL) @@ -434,13 +439,16 @@ int main() { // verify_IntervalTree(0, input_tree0); // verify_IntervalTree(0, input_tree1); - auto [nested, single, dual] = benchmark_1d_dist_join_query(input_set0, input_set1, input_tree0, input_tree1, k, m); + auto [nested, single, dual] = benchmark_1d_dist_join_query( + input_set0, input_set1, input_tree0, input_tree1, k, m); - #ifdef PROFILE - results[0].second.push_back((dual > 0) ? (double)nested / (double)dual : std::numeric_limits::max()); + results[0].second.push_back((dual > 0) + ? (double)nested / (double)dual + : std::numeric_limits::max()); #endif - std::cout << "(" << size << ", " << nested << ", " << build_time << ", " << single << ", " << dual << ")" << std::endl; + std::cout << "(" << size << ", " << nested << ", " << build_time << ", " + << single << ", " << dual << ")" << std::endl; std::free(input_tree0.prims); std::free(input_tree0.group0_index); diff --git a/apps/queries/joins/salary/main.cpp b/apps/queries/joins/salary/main.cpp index 4029d5ee4..41f7e00ce 100644 --- a/apps/queries/joins/salary/main.cpp +++ b/apps/queries/joins/salary/main.cpp @@ -1,6 +1,6 @@ #include -#include #include +#include #include #include #include @@ -9,7 +9,6 @@ #include "apps/queries/joins/salary/joins_gen.h" - std::vector load_csv(const std::string &filename) { std::ifstream file(filename); if (!file.is_open()) { @@ -30,17 +29,21 @@ std::vector load_csv(const std::string &filename) { std::istringstream iss(line); std::string name, dept_str, salary_str, tax_str; - if (!std::getline(iss, name, ',')) continue; - if (!std::getline(iss, dept_str, ',')) continue; - if (!std::getline(iss, salary_str, ',')) continue; - if (!std::getline(iss, tax_str, ',')) continue; + if (!std::getline(iss, name, ',')) + continue; + if (!std::getline(iss, dept_str, ',')) + continue; + if (!std::getline(iss, salary_str, ',')) + continue; + if (!std::getline(iss, tax_str, ',')) + continue; try { Employee e; e.salary = std::stof(salary_str); e.tax = std::stof(tax_str); employees.push_back(e); - } catch (const std::exception& ex) { + } catch (const std::exception &ex) { std::cout << "Warning: skipping malformed line: " << line << "\n"; } } @@ -55,7 +58,8 @@ std::vector load_csv(const std::string &filename) { _tree_layout0 build_tree(const set &input) { _tree_layout0 tree; tree.pCount = input.size(); - tree.prims = static_cast(std::malloc(sizeof(Employee) * tree.pCount)); + tree.prims = + static_cast(std::malloc(sizeof(Employee) * tree.pCount)); if (!tree.prims) { throw std::bad_alloc(); } @@ -84,20 +88,19 @@ _tree_layout0 build_tree(const set &input) { float root_min_salary = input.data.begin()->salary; float root_max_salary = input.data.begin()->salary; - float root_min_tax = input.data.begin()->tax; - float root_max_tax = input.data.begin()->tax; + float root_min_tax = input.data.begin()->tax; + float root_max_tax = input.data.begin()->tax; for (const auto &e : input.data) { root_min_salary = std::min(root_min_salary, e.salary); root_max_salary = std::max(root_max_salary, e.salary); - root_min_tax = std::min(root_min_tax, e.tax); - root_max_tax = std::max(root_max_tax, e.tax); + root_min_tax = std::min(root_min_tax, e.tax); + root_max_tax = std::max(root_max_tax, e.tax); } #endif std::function handle_range = [&](uint64_t low, uint64_t high, uint64_t depth) -> uint64_t { - uint64_t count = high - low; uint64_t this_index = next_node++; assert(this_index < tree.nCount); @@ -126,17 +129,20 @@ _tree_layout0 build_tree(const set &input) { tree.group0_index[this_index].nPrims = 0; // Choose split axis: longest dimension - bool split_on_x = (sh - sl) / (root_max_salary - root_min_salary) >= (th - tl) / (root_max_tax - root_min_tax); + bool split_on_x = (sh - sl) / (root_max_salary - root_min_salary) >= + (th - tl) / (root_max_tax - root_min_tax); // Sort on that axis if (split_on_x) { - std::sort( - tree.prims + low, tree.prims + high, - [](const Employee &a, const Employee &b) { return a.salary < b.salary; }); + std::sort(tree.prims + low, tree.prims + high, + [](const Employee &a, const Employee &b) { + return a.salary < b.salary; + }); } else { - std::sort( - tree.prims + low, tree.prims + high, - [](const Employee &a, const Employee &b) { return a.tax < b.tax; }); + std::sort(tree.prims + low, tree.prims + high, + [](const Employee &a, const Employee &b) { + return a.tax < b.tax; + }); } #ifdef USE_APPROX_SAH @@ -187,7 +193,7 @@ _tree_layout0 build_tree(const set &input) { } // TODO: carry over timeouts? -int main(int argc, char** argv) { +int main(int argc, char **argv) { if (argc < 2) { std::cerr << "Usage: " << argv[0] << " \n"; return 1; @@ -204,7 +210,9 @@ int main(int argc, char** argv) { const auto tree = build_tree(employees); auto end = std::chrono::high_resolution_clock::now(); - auto build_time = std::chrono::duration_cast(end - start).count(); + auto build_time = + std::chrono::duration_cast(end - start) + .count(); bool nested_timedout = (employees.size() >= 262144), single_timedout = false, dual_timedout = false; diff --git a/apps/queries/range/range_main.cpp b/apps/queries/range/range_main.cpp index 01f1212cc..b99e5ea4f 100644 --- a/apps/queries/range/range_main.cpp +++ b/apps/queries/range/range_main.cpp @@ -212,9 +212,10 @@ double benchmark_range_query(const set &input, const _tree_layout0 &tree, << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries>( - "range_query", input, tree, k, m, range_query, range_query_fast, - linear_timedout, indexed_timedout, low, high); + auto [linear, indexed] = benchmark_1d_queries < PROFILE != 1, + set < float >> ("range_query", input, tree, k, m, range_query, + range_query_fast, linear_timedout, + indexed_timedout, low, high); return static_cast(linear) / indexed; } @@ -226,9 +227,10 @@ double benchmark_eq_query(const set &input, const _tree_layout0 &tree, std::cout << "Equality query, value = " << value << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries>( - "eq_query", input, tree, k, m, eq_query, eq_query_fast, linear_timedout, - indexed_timedout, value); + auto [linear, indexed] = benchmark_1d_queries < PROFILE != 1, + set < float >> ("eq_query", input, tree, k, m, eq_query, + eq_query_fast, linear_timedout, + indexed_timedout, value); return static_cast(linear) / indexed; } @@ -240,9 +242,10 @@ double benchmark_abs_query(const set &input, const _tree_layout0 &tree, std::cout << "Abs query, value = " << value << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries>( - "abs_query", input, tree, k, m, abs_query, abs_query_fast, - linear_timedout, indexed_timedout, value); + auto [linear, indexed] = benchmark_1d_queries < PROFILE != 1, + set < float >> ("abs_query", input, tree, k, m, abs_query, + abs_query_fast, linear_timedout, + indexed_timedout, value); return static_cast(linear) / indexed; } @@ -254,9 +257,10 @@ double benchmark_sqr_query(const set &input, const _tree_layout0 &tree, std::cout << "Sqr query, value = " << value << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries>( - "sqr_query", input, tree, k, m, sqr_query, sqr_query_fast, - linear_timedout, indexed_timedout, value); + auto [linear, indexed] = benchmark_1d_queries < PROFILE != 1, + set < float >> ("sqr_query", input, tree, k, m, sqr_query, + sqr_query_fast, linear_timedout, + indexed_timedout, value); return static_cast(linear) / indexed; } @@ -268,9 +272,10 @@ double benchmark_round_query(const set &input, const _tree_layout0 &tree, std::cout << "Round query, value = " << value << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries>( - "round_query", input, tree, k, m, round_query, round_query_fast, - linear_timedout, indexed_timedout, value); + auto [linear, indexed] = benchmark_1d_queries < PROFILE != 1, + set < float >> ("round_query", input, tree, k, m, round_query, + round_query_fast, linear_timedout, + indexed_timedout, value); return static_cast(linear) / indexed; } @@ -282,9 +287,10 @@ double benchmark_poly_query(const set &input, const _tree_layout0 &tree, std::cout << "Poly query, value = " << value << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries>( - "poly_query", input, tree, k, m, poly_query, poly_query_fast, - linear_timedout, indexed_timedout, value); + auto [linear, indexed] = benchmark_1d_queries < PROFILE != 1, + set < float >> ("poly_query", input, tree, k, m, poly_query, + poly_query_fast, linear_timedout, + indexed_timedout, value); return static_cast(linear) / indexed; } @@ -296,9 +302,10 @@ double benchmark_sqrt_query(const set &input, const _tree_layout0 &tree, std::cout << "Sqrt query, value = " << value << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries>( - "sqrt_query", input, tree, k, m, sqrt_query, sqrt_query_fast, - linear_timedout, indexed_timedout, value); + auto [linear, indexed] = benchmark_1d_queries < PROFILE != 1, + set < float >> ("sqrt_query", input, tree, k, m, sqrt_query, + sqrt_query_fast, linear_timedout, + indexed_timedout, value); return static_cast(linear) / indexed; } @@ -333,9 +340,11 @@ double benchmark_stddev_query(const set &input, << std::endl; std::cout << "Input size: " << input.size() << std::endl; #endif - auto [linear, indexed] = benchmark_1d_queries>( - "stddev_query", input, tree, k, m, stddev_query, stddev_query_fast, - linear_timedout, indexed_timedout, mean, stddev3); + auto [linear, indexed] = benchmark_1d_queries < PROFILE != 1, + set < float >> ("stddev_query", input, tree, k, m, + stddev_query, stddev_query_fast, + linear_timedout, indexed_timedout, mean, + stddev3); return static_cast(linear) / indexed; } diff --git a/apps/queries/rt/main.cpp b/apps/queries/rt/main.cpp index 03346102c..2d121385e 100644 --- a/apps/queries/rt/main.cpp +++ b/apps/queries/rt/main.cpp @@ -171,7 +171,9 @@ bool global_tree_built = false; _tree_layout0 global_tree; _tree_layout0 copy_tree(fcpw::Aggregate<3> *aggregate) { - auto bvh_ptr = dynamic_cast, fcpw::Triangle>*>(aggregate); + auto bvh_ptr = + dynamic_cast, fcpw::Triangle> *>( + aggregate); if (!bvh_ptr) { std::cerr << "Error: Aggregate is not a BVH<3>!\n"; std::abort(); @@ -180,8 +182,8 @@ _tree_layout0 copy_tree(fcpw::Aggregate<3> *aggregate) { _tree_layout0 tree; tree.nCount = static_cast(bvh_ptr->flatTree.size()); if (tree.nCount > 0) { - tree.group0_index = - static_cast<_tree_layout1*>(malloc(sizeof(_tree_layout1) * tree.nCount)); + tree.group0_index = static_cast<_tree_layout1 *>( + malloc(sizeof(_tree_layout1) * tree.nCount)); if (!tree.group0_index) { std::cerr << "Malloc (nodes) failed" << std::endl; abort(); @@ -208,22 +210,32 @@ _tree_layout0 copy_tree(fcpw::Aggregate<3> *aggregate) { tree.pCount = static_cast(bvh_ptr->primitives.size()); if (tree.pCount > 0) { - tree.prims = static_cast(malloc(sizeof(Triangle) * tree.pCount)); + tree.prims = + static_cast(malloc(sizeof(Triangle) * tree.pCount)); if (!tree.prims) { std::cerr << "Malloc (triangles) failed" << std::endl; abort(); } for (uint32_t i = 0; i < tree.pCount; ++i) { const auto soup = bvh_ptr->primitives[i]->soup; - tree.prims[i].p0.x = soup->positions[bvh_ptr->primitives[i]->indices[0]][0]; - tree.prims[i].p0.y = soup->positions[bvh_ptr->primitives[i]->indices[0]][1]; - tree.prims[i].p0.z = soup->positions[bvh_ptr->primitives[i]->indices[0]][2]; - tree.prims[i].p1.x = soup->positions[bvh_ptr->primitives[i]->indices[1]][0]; - tree.prims[i].p1.y = soup->positions[bvh_ptr->primitives[i]->indices[1]][1]; - tree.prims[i].p1.z = soup->positions[bvh_ptr->primitives[i]->indices[1]][2]; - tree.prims[i].p2.x = soup->positions[bvh_ptr->primitives[i]->indices[2]][0]; - tree.prims[i].p2.y = soup->positions[bvh_ptr->primitives[i]->indices[2]][1]; - tree.prims[i].p2.z = soup->positions[bvh_ptr->primitives[i]->indices[2]][2]; + tree.prims[i].p0.x = + soup->positions[bvh_ptr->primitives[i]->indices[0]][0]; + tree.prims[i].p0.y = + soup->positions[bvh_ptr->primitives[i]->indices[0]][1]; + tree.prims[i].p0.z = + soup->positions[bvh_ptr->primitives[i]->indices[0]][2]; + tree.prims[i].p1.x = + soup->positions[bvh_ptr->primitives[i]->indices[1]][0]; + tree.prims[i].p1.y = + soup->positions[bvh_ptr->primitives[i]->indices[1]][1]; + tree.prims[i].p1.z = + soup->positions[bvh_ptr->primitives[i]->indices[1]][2]; + tree.prims[i].p2.x = + soup->positions[bvh_ptr->primitives[i]->indices[2]][0]; + tree.prims[i].p2.y = + soup->positions[bvh_ptr->primitives[i]->indices[2]][1]; + tree.prims[i].p2.z = + soup->positions[bvh_ptr->primitives[i]->indices[2]][2]; } } else { std::cerr << "No triangles?" << std::endl; @@ -482,7 +494,7 @@ tree.nCount << "allocated\n"; // 1:1 match with FCPW's Bvh_SurfaceArea: // https://github.com/rohan-sawhney/fcpw/blob/e36bc9b34af6088fb78ddbb6a93e26686779678a/include/fcpw/utilities/scene_data.h#L21 _tree_layout0 build_triangles(std::vector &triangles, int leaf_size, - int max_tree_depth, int nBuckets = 8) { + int max_tree_depth, int nBuckets = 8) { constexpr auto MAX = std::numeric_limits::max(); struct BucketInfo { @@ -700,7 +712,7 @@ _tree_layout0 build_triangles(std::vector &triangles, int leaf_size, nodes[index].offset = right - index; #ifdef AJR_PROFILE - interior_count++; + interior_count++; #endif return index; }; @@ -710,14 +722,15 @@ _tree_layout0 build_triangles(std::vector &triangles, int leaf_size, #ifdef AJR_PROFILE std::cout << "Bonsai tree build: node_count = " << nodes.size() << "\n"; std::cout << " leaf_count = " << leaf_count << "\n"; - std::cout << " interior_count = " << interior_count << "\n"; + std::cout << " interior_count = " << interior_count + << "\n"; #endif _tree_layout0 tree; tree.nCount = static_cast(nodes.size()); if (tree.nCount > 0) { - tree.group0_index = - static_cast<_tree_layout1*>(malloc(sizeof(_tree_layout1) * tree.nCount)); + tree.group0_index = static_cast<_tree_layout1 *>( + malloc(sizeof(_tree_layout1) * tree.nCount)); if (!tree.group0_index) { std::cerr << "Malloc (nodes) failed" << std::endl; abort(); @@ -734,7 +747,8 @@ _tree_layout0 build_triangles(std::vector &triangles, int leaf_size, tree.pCount = static_cast(triangles.size()); if (tree.pCount > 0) { - tree.prims = static_cast(malloc(sizeof(Triangle) * tree.pCount)); + tree.prims = + static_cast(malloc(sizeof(Triangle) * tree.pCount)); if (!tree.prims) { std::cerr << "Malloc (triangles) failed" << std::endl; abort(); @@ -761,9 +775,11 @@ void run_bonsai(const std::string &obj_dir, const std::string &object, assert(!triangles.empty()); auto t0 = clock::now(); - auto tree = global_tree_built ? global_tree : build_triangles(triangles, 4, 64); + auto tree = + global_tree_built ? global_tree : build_triangles(triangles, 4, 64); auto t1 = clock::now(); - auto trace_time = std::chrono::duration_cast(t1 - t0).count(); + auto trace_time = + std::chrono::duration_cast(t1 - t0).count(); // std::cout << "Bonsai build time : " << trace_time << " ms\n"; bool timedout = false; @@ -987,7 +1003,9 @@ void run_cgal(const std::string &obj_dir, const std::string &object, std::vector triangles; triangles.reserve(tris.size()); for (const auto &t : tris) { - triangles.emplace_back(cgalPoint(t.p0.x, t.p0.y, t.p0.z), cgalPoint(t.p1.x, t.p1.y, t.p1.z), cgalPoint(t.p2.x, t.p2.y, t.p2.z)); + triangles.emplace_back(cgalPoint(t.p0.x, t.p0.y, t.p0.z), + cgalPoint(t.p1.x, t.p1.y, t.p1.z), + cgalPoint(t.p2.x, t.p2.y, t.p2.z)); } tris.clear(); @@ -1021,11 +1039,11 @@ void run_cgal(const std::string &obj_dir, const std::string &object, rays.reserve(bRays.size()); for (const auto &r : bRays) { - rays.emplace_back(cgalPoint(r.o.x, r.o.y, r.o.z), cgalKernel::Direction_3(r.d.x, r.d.y, r.d.z)); + rays.emplace_back(cgalPoint(r.o.x, r.o.y, r.o.z), + cgalKernel::Direction_3(r.d.x, r.d.y, r.d.z)); } bRays.clear(); - if (is_first_run) { for (int i = 0; i < std::min(rays.size(), 512u); ++i) (void)tree.first_intersection(rays[i]); // warmup diff --git a/apps/queries/rt/rt_profile.cpp b/apps/queries/rt/rt_profile.cpp index f3666cce9..9c57dc638 100644 --- a/apps/queries/rt/rt_profile.cpp +++ b/apps/queries/rt/rt_profile.cpp @@ -15,163 +15,170 @@ struct TriangleIntersection { }; std::optional intersectsp_ray_aabb(const Ray r, const AABB b) { - const float3 invDir = float3{1.00000000f} / r.d; - const float3 t0 = (b.low - r.o) * invDir; - const float3 t1 = (b.high - r.o) * invDir; - const float3 tNear = min(t0, t1); - const float3 tFar = max(t0, t1); - const float _t0 = max(0.00000000f, reduce_max(tNear)); - const float tFarMin = reduce_min(tFar); - if (tFarMin < _t0) { - return std::nullopt; - } - return (std::optional)(FInterval{_t0, tFarMin}); + const float3 invDir = float3{1.00000000f} / r.d; + const float3 t0 = (b.low - r.o) * invDir; + const float3 t1 = (b.high - r.o) * invDir; + const float3 tNear = min(t0, t1); + const float3 tFar = max(t0, t1); + const float _t0 = max(0.00000000f, reduce_max(tNear)); + const float tFarMin = reduce_min(tFar); + if (tFarMin < _t0) { + return std::nullopt; + } + return (std::optional)(FInterval{_t0, tFarMin}); } float distmin_Ray_AABB(const Ray r, const AABB b) { - const std::optional interval = intersectsp_ray_aabb(r, b); - if (interval.has_value()) { - const FInterval extract = *interval; - return extract.low; - } - return -std::numeric_limits::infinity(); + const std::optional interval = intersectsp_ray_aabb(r, b); + if (interval.has_value()) { + const FInterval extract = *interval; + return extract.low; + } + return -std::numeric_limits::infinity(); } std::optional intersectsp_ray_tri(const Ray r, const Triangle tri) { - const float epsilon = 0.00000006f; - const float3 pa = tri.p0; - const float3 pb = tri.p1; - const float3 pc = tri.p2; - const float3 v1 = pb - pa; - const float3 v2 = pc - pa; - const float3 _t0 = r.d; - const float3 _t1 = cross(_t0, v2); - const float det = dot(v1, _t1); - if (abs(det) <= epsilon) { - return std::nullopt; - } - const float invDet = 1.00000000f / det; - const float3 _t3 = r.o - pa; - const float _t5 = dot(_t3, _t1) * invDet; - if ((_t5 < 0.00000000f) || (1.00000000f < _t5)) { - return std::nullopt; - } - const float3 q = cross(_t3, v1); - const float _t8 = dot(_t0, q) * invDet; - if ((_t8 < 0.00000000f) || (1.00000000f < (_t5 + _t8))) { - return std::nullopt; - } - const float _t10 = dot(v2, q) * invDet; - if (0.00000000f <= _t10) { - if (_t10 <= r.tmax) { - return std::make_optional(_t10); + const float epsilon = 0.00000006f; + const float3 pa = tri.p0; + const float3 pb = tri.p1; + const float3 pc = tri.p2; + const float3 v1 = pb - pa; + const float3 v2 = pc - pa; + const float3 _t0 = r.d; + const float3 _t1 = cross(_t0, v2); + const float det = dot(v1, _t1); + if (abs(det) <= epsilon) { + return std::nullopt; + } + const float invDet = 1.00000000f / det; + const float3 _t3 = r.o - pa; + const float _t5 = dot(_t3, _t1) * invDet; + if ((_t5 < 0.00000000f) || (1.00000000f < _t5)) { + return std::nullopt; + } + const float3 q = cross(_t3, v1); + const float _t8 = dot(_t0, q) * invDet; + if ((_t8 < 0.00000000f) || (1.00000000f < (_t5 + _t8))) { + return std::nullopt; + } + const float _t10 = dot(v2, q) * invDet; + if (0.00000000f <= _t10) { + if (_t10 <= r.tmax) { + return std::make_optional(_t10); + } } - } - return std::nullopt; + return std::nullopt; } float distmin_Ray_Triangle(const Ray ray, const Triangle tri) { - const std::optional isect = intersectsp_ray_tri(ray, tri); - if (isect.has_value()) { - return *isect; - } else { - return std::numeric_limits::infinity(); - } + const std::optional isect = intersectsp_ray_tri(ray, tri); + if (isect.has_value()) { + return *isect; + } else { + return std::numeric_limits::infinity(); + } } bool intersects_Ray_AABB(const Ray r, const AABB b) { #ifdef AJR_PROFILE - distmin_aabb_counter++; + distmin_aabb_counter++; #endif - const std::optional interval = intersectsp_ray_aabb(r, b); - if (interval.has_value()) { - const FInterval extract = *interval; - return (extract.low < r.tmax) & (0.00000000f < extract.high); - } - return false; + const std::optional interval = intersectsp_ray_aabb(r, b); + if (interval.has_value()) { + const FInterval extract = *interval; + return (extract.low < r.tmax) & (0.00000000f < extract.high); + } + return false; } bool intersects_Ray_Triangle(const Ray ray, const Triangle tri) { #ifdef AJR_PROFILE - distmin_triangle_counter++; + distmin_triangle_counter++; #endif - return intersectsp_ray_tri(ray, tri).has_value(); -} -std::optional _traverse_tree0(const Ray ray, const _tree_layout0& triangles) { - std::tuple _best0 = std::make_tuple(std::numeric_limits::infinity(), Triangle{}); - int32_t _queue_count0 = 1; - uint32_t _queue0[128]; - _queue0[0] = 0u; - do { - _queue_count0 -= 1; - const uint32_t triangles_index = _queue0[_queue_count0]; - const _tree_layout1 _t45 = triangles.group0_index[triangles_index]; - const AABB _t50 = AABB{_t45.low, _t45.high}; - if (intersects_Ray_AABB(ray, _t50)) { - if (distmin_Ray_AABB(ray, _t50) < std::get<0>(_best0)) { - const uint32_t _t35 = _t45.nPrims; - if (_t35 == 0u) { - _queue0[_queue_count0] = triangles_index + 1u; - _queue0[_queue_count0 + 1] = triangles_index + _t45.offset; - _queue_count0 += 2; - } else { - for (uint32_t _idx0 = 0u; _idx0 < _t35; _idx0 += 1u) { - const Triangle _t29 = triangles.prims[_t45.offset + _idx0]; - if (intersects_Ray_Triangle(ray, _t29)) { - const float _t22 = distmin_Ray_Triangle(ray, _t29); - if (_t22 < std::get<0>(_best0)) { - _best0 = std::make_tuple(_t22, _t29); - } + return intersectsp_ray_tri(ray, tri).has_value(); +} +std::optional _traverse_tree0(const Ray ray, + const _tree_layout0 &triangles) { + std::tuple _best0 = + std::make_tuple(std::numeric_limits::infinity(), Triangle{}); + int32_t _queue_count0 = 1; + uint32_t _queue0[128]; + _queue0[0] = 0u; + do { + _queue_count0 -= 1; + const uint32_t triangles_index = _queue0[_queue_count0]; + const _tree_layout1 _t45 = triangles.group0_index[triangles_index]; + const AABB _t50 = AABB{_t45.low, _t45.high}; + if (intersects_Ray_AABB(ray, _t50)) { + if (distmin_Ray_AABB(ray, _t50) < std::get<0>(_best0)) { + const uint32_t _t35 = _t45.nPrims; + if (_t35 == 0u) { + _queue0[_queue_count0] = triangles_index + 1u; + _queue0[_queue_count0 + 1] = triangles_index + _t45.offset; + _queue_count0 += 2; + } else { + for (uint32_t _idx0 = 0u; _idx0 < _t35; _idx0 += 1u) { + const Triangle _t29 = + triangles.prims[_t45.offset + _idx0]; + if (intersects_Ray_Triangle(ray, _t29)) { + const float _t22 = distmin_Ray_Triangle(ray, _t29); + if (_t22 < std::get<0>(_best0)) { + _best0 = std::make_tuple(_t22, _t29); + } + } + } + } } - } } - } - } - } while (_queue_count0 != 0); - return ((std::get<0>(_best0) != std::numeric_limits::infinity()) ? std::make_optional(std::get<1>(_best0)) : std::nullopt); + } while (_queue_count0 != 0); + return ((std::get<0>(_best0) != std::numeric_limits::infinity()) + ? std::make_optional(std::get<1>(_best0)) + : std::nullopt); } float prod_diff(const float a, const float b, const float c, const float d) { - const float cd = c * d; - const float diff = fma(a, b, -cd); - const float err = fma(-c, d, cd); - return diff + err; + const float cd = c * d; + const float diff = fma(a, b, -cd); + const float err = fma(-c, d, cd); + return diff + err; } float3 cross_(const float3 v0, const float3 v1) { - const float _t0 = v0[1u]; - const float _t1 = v1[2u]; - const float _t2 = v0[2u]; - const float _t3 = v1[1u]; - const float _t5 = v1[0u]; - const float _t6 = v0[0u]; - return vector({prod_diff(_t0, _t1, _t2, _t3), prod_diff(_t2, _t5, _t6, _t1), prod_diff(_t6, _t3, _t0, _t5)}); + const float _t0 = v0[1u]; + const float _t1 = v1[2u]; + const float _t2 = v0[2u]; + const float _t3 = v1[1u]; + const float _t5 = v1[0u]; + const float _t6 = v0[0u]; + return vector({prod_diff(_t0, _t1, _t2, _t3), + prod_diff(_t2, _t5, _t6, _t1), + prod_diff(_t6, _t3, _t0, _t5)}); } float distmax_Ray_AABB(const Ray r, const AABB b) { - const std::optional interval = intersectsp_ray_aabb(r, b); - if (interval.has_value()) { - const FInterval extract = *interval; - return extract.high; - } - return std::numeric_limits::infinity(); + const std::optional interval = intersectsp_ray_aabb(r, b); + if (interval.has_value()) { + const FInterval extract = *interval; + return extract.high; + } + return std::numeric_limits::infinity(); } float distmax_Ray_Triangle(const Ray ray, const Triangle tri) { - const std::optional isect = intersectsp_ray_tri(ray, tri); - if (isect.has_value()) { - return *isect; - } else { - return -std::numeric_limits::infinity(); - } + const std::optional isect = intersectsp_ray_tri(ray, tri); + if (isect.has_value()) { + return *isect; + } else { + return -std::numeric_limits::infinity(); + } } float gamma(const int32_t n) { - const float _t1 = (float)(n) * 0.00000006f; - return _t1 / (1.00000000f - _t1); + const float _t1 = (float)(n) * 0.00000006f; + return _t1 / (1.00000000f - _t1); } float orient3d(const float3 a, const float3 b, const float3 c, const float3 d) { - const float3 ad = a - d; - const float3 bd = b - d; - const float3 cd = c - d; - return dot(ad, cross(bd, cd)); + const float3 ad = a - d; + const float3 bd = b - d; + const float3 cd = c - d; + return dot(ad, cross(bd, cd)); } bool point_in_triangle(const float3 p, const Triangle t, const float3 q) { - return ((orient3d(p, q, t.p0, t.p1) <= 0.00000000f) && (orient3d(p, q, t.p1, t.p2) <= 0.00000000f)) && (orient3d(p, q, t.p2, t.p0) <= 0.00000000f); -} -float sqlen(const float3 v) { - return reduce_add(v * v); + return ((orient3d(p, q, t.p0, t.p1) <= 0.00000000f) && + (orient3d(p, q, t.p1, t.p2) <= 0.00000000f)) && + (orient3d(p, q, t.p2, t.p0) <= 0.00000000f); } -std::optional trace(const Ray ray, const _tree_layout0& triangles) { - return _traverse_tree0(ray, triangles); +float sqlen(const float3 v) { return reduce_add(v * v); } +std::optional trace(const Ray ray, const _tree_layout0 &triangles) { + return _traverse_tree0(ray, triangles); } diff --git a/apps/queries/rt/rt_profile.h b/apps/queries/rt/rt_profile.h index 40d7277cc..294824db6 100644 --- a/apps/queries/rt/rt_profile.h +++ b/apps/queries/rt/rt_profile.h @@ -1,7 +1,7 @@ #pragma once -#include #include "runtime/bonsai_cpp.h" +#include #ifdef AJR_PROFILE inline uint32_t distmin_aabb_counter = 0; @@ -39,9 +39,9 @@ struct _tree_layout1 { } __attribute__((packed)); struct _tree_layout0 { uint32_t pCount; - Triangle* prims; + Triangle *prims; uint32_t nCount; - _tree_layout1* group0_index; + _tree_layout1 *group0_index; } __attribute__((packed)); struct _tree_layout2 { } __attribute__((packed)); @@ -53,4 +53,4 @@ struct Ray { float tmax = std::numeric_limits::infinity(); }; -std::optional trace(const Ray ray, const _tree_layout0& triangles); +std::optional trace(const Ray ray, const _tree_layout0 &triangles); diff --git a/apps/rtiow/cpu/compare.sh b/apps/rtiow/cpu/compare.sh index e0dcd1352..74a13e42b 100755 --- a/apps/rtiow/cpu/compare.sh +++ b/apps/rtiow/cpu/compare.sh @@ -26,13 +26,12 @@ OUT="${OUT:-$PREFIX/compare-out}" rm -rf "$OUT" mkdir -p "$OUT" -# The checked-in schedule splits the image loop across threads with -# `cpu_thread`, which generates calls to libdispatch -- a macOS library, so it -# does not link elsewhere -- and which the SSA pipeline does not implement -# anyway. Both sides are built from a copy without it, so that what is being -# compared is the two pipelines and not two different schedules. +# The checked-in schedule collapses the image loops and binds the result to +# CPU threads, which only the SSA pipeline implements. Both sides are built +# from a copy without it, so that what is being compared is the two pipelines +# and not two different schedules. SRC="$OUT/scene.bonsai" -sed '/image.split/,/cpu_thread/d' "$PREFIX/main.bonsai" > "$SRC" +sed '/image.collapse/,/bind(/d' "$PREFIX/main.bonsai" > "$SRC" build() { #