@geastack/gea3d 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,6 +16,7 @@
16
16
  #include "pixel.h"
17
17
 
18
18
  #include <algorithm>
19
+ #include <atomic>
19
20
  #include <climits>
20
21
  #include <cmath>
21
22
  #include <cstring>
@@ -37,6 +38,9 @@
37
38
  #include "freertos/FreeRTOS.h"
38
39
  #include "freertos/semphr.h"
39
40
  #include "freertos/task.h"
41
+ #include "esp_memory_utils.h"
42
+ #include "esp_heap_caps.h"
43
+ #include "freertos/idf_additions.h"
40
44
  #define GEA3D_ASYNC_PRESENT 1
41
45
  #else
42
46
  #define GEA3D_ASYNC_PRESENT 0
@@ -406,6 +410,21 @@ struct Renderer {
406
410
  };
407
411
 
408
412
  Renderer g_renderer;
413
+ // Bumped each time a frame slot is rebuilt; keys the per-frame strip lists.
414
+ std::uint32_t g_frameSerial[2] = {0, 0};
415
+ // Per frame slot, a content hash of each kBandHashRows-row band: what its
416
+ // primitives draw there, in draw order. A composited frame marks dirty only
417
+ // the bands that differ from the frame on screen.
418
+ // The band height is the painter's strip height when it stages strips
419
+ // (g_stripRowsHint), so dirty runs start where strips do and every strip
420
+ // reads one prebuilt band list; 8 rows until it is known.
421
+ constexpr int kBandHashRows = 8;
422
+ std::atomic<int> g_stripRowsHint{0};
423
+ int g_bandHashRows[2] = {kBandHashRows, kBandHashRows};
424
+ int g_shownBandHashRows = kBandHashRows;
425
+ std::vector<std::uint64_t> g_bandHash[2];
426
+ std::vector<std::uint64_t> g_shownBandHash;
427
+ bool g_shownBandHashValid = false;
409
428
 
410
429
  // Fast memory for the raster. On the STM32F7 the heap and framebuffers are
411
430
  // SDRAM (framebuffers write-through), so two band buffers fill the zero-wait
@@ -482,8 +501,13 @@ RayHit g_rayHit;
482
501
 
483
502
  // ---------------------------------------------------------------- helpers
484
503
 
504
+ #if GEA3D_XTENSA_FPU
505
+ // No float max on Xtensa: the builtin is an fmaxf call.
506
+ GEA3D_INLINE float maxFloat(float a, float b) { return a > b || b != b ? a : b; }
507
+ #else
485
508
  // VMAXNM on FPv5: no float compare stalls the pipeline.
486
509
  GEA3D_INLINE float maxFloat(float a, float b) { return __builtin_fmaxf(a, b); }
510
+ #endif
487
511
 
488
512
  // 0..255 by truncation; clamped in integer registers (USAT), not with float
489
513
  // compares.
@@ -610,7 +634,7 @@ GEA3D_INLINE float fogFactor(float distance)
610
634
  const Environment &env = g_renderer.environment;
611
635
  if (env.fog == 1) {
612
636
  if (env.fogFar <= env.fogNear) return 1.0f;
613
- return clampFloat((env.fogFar - distance) / (env.fogFar - env.fogNear), 0.0f, 1.0f);
637
+ return clampFloat((env.fogFar - distance) * raster::detail::reciprocal(env.fogFar - env.fogNear), 0.0f, 1.0f);
614
638
  }
615
639
  if (env.fog == 2) {
616
640
  const float d = env.fogDensity * distance;
@@ -644,14 +668,14 @@ GEA3D_INLINE void project(const View &v, float x, float y, float z, std::int32_t
644
668
  const float cy = p[1] * x + p[5] * y + p[9] * z + p[13];
645
669
  float cw = p[3] * x + p[7] * y + p[11] * z + p[15];
646
670
  if (cw < 0.000001f && cw > -0.000001f) cw = 0.000001f;
647
- const float invW = 1.0f / cw;
671
+ const float invW = raster::detail::reciprocal(cw);
648
672
  const float fx = clampFloat((cx * invW + 1.0f) * v.halfW, -kCoordLimit, kCoordLimit);
649
673
  const float fy = clampFloat((1.0f - cy * invW) * v.halfH, -kCoordLimit, kCoordLimit);
650
674
  *sx = roundToInt(fx * 16.0f);
651
675
  *sy = roundToInt(fy * 16.0f);
652
676
  if (v.orthographic) {
653
677
  const float range = v.far - v.near;
654
- *depth = range > 0.0f ? clampFloat(1.0f - (-z - v.near) / range, 0.0f, 1.0f) : 1.0f;
678
+ *depth = range > 0.0f ? clampFloat(1.0f - (-z - v.near) * raster::detail::reciprocal(range), 0.0f, 1.0f) : 1.0f;
655
679
  } else {
656
680
  *depth = clampFloat(v.near * invW, 0.0f, 1.0f);
657
681
  }
@@ -1390,6 +1414,7 @@ void sortFrame()
1390
1414
  Renderer &r = g_renderer;
1391
1415
  raster::Frame &frame = r.frame();
1392
1416
  const int n = frame.count;
1417
+ for (int i = 0; i < n; i++) raster::prepareTriangle(frame.prims[i]);
1393
1418
  frame.order.resize(static_cast<std::size_t>(n));
1394
1419
  r.keys.resize(static_cast<std::size_t>(n));
1395
1420
  r.bucketStarts.assign(2 * (kDepthBuckets + 1), 0);
@@ -1548,6 +1573,24 @@ void rasterizeInto(const raster::Frame &frame, Pixel *base, int stride, int x0,
1548
1573
 
1549
1574
  Bands &bands = g_renderer.bands;
1550
1575
  const int width = x1 - x0 + 1;
1576
+ #if GEA3D_ASYNC_PRESENT && !defined(GEA3D_BAND_ROWS)
1577
+ // A target in PSRAM (the ESP32-P4's swapped scanout buffers) takes the
1578
+ // raster in bands of internal RAM, painter's order, each copied out in one
1579
+ // sequential pass: coverage mode straight into PSRAM cost the CrowPanel 5.0
1580
+ // ~65 ms of a Lantern frame, the same figure painter's order in fast
1581
+ // memory cut to ~20 ms on the 7.0.
1582
+ if (width > bands.width && !esp_ptr_internal(base + static_cast<std::ptrdiff_t>(y0) * stride + x0)) {
1583
+ constexpr int kEspBandRows = 32;
1584
+ const int bandWidth = std::max(width, frame.width);
1585
+ Pixel *pixels = static_cast<Pixel *>(heap_caps_aligned_alloc(16, static_cast<std::size_t>(bandWidth) * kEspBandRows * sizeof(Pixel), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT));
1586
+ if (pixels) {
1587
+ if (bands.pixels) heap_caps_free(bands.pixels);
1588
+ bands.pixels = pixels;
1589
+ bands.width = bandWidth;
1590
+ bands.rows = kEspBandRows;
1591
+ }
1592
+ }
1593
+ #endif
1551
1594
  if (!bands.pixels || width > bands.width) {
1552
1595
  raster::Rasterizer rasterizer(frame, g_renderer.scratch, base, stride, x0, y0, x1, y1);
1553
1596
  rasterizer.run();
@@ -1589,6 +1632,171 @@ void rasterizeInto(const raster::Frame &frame, Pixel *base, int stride, int x0,
1589
1632
  #endif
1590
1633
  }
1591
1634
 
1635
+ #if GEA3D_ASYNC_PRESENT
1636
+ // A target in internal RAM (the display's staged strip) takes painter's order
1637
+ // straight into it: the background, then the region's primitives back to
1638
+ // front. Coverage mode suits slow target memory only; in fast memory its
1639
+ // per-pixel coverage bits, and the depth scratch it zeroes for every region
1640
+ // once anything blends, cost more than the overdraw they save (Neon Drift on
1641
+ // the CrowPanel 7.0: 66 -> 19.5 ms of raster a frame).
1642
+ // The UI paints the underlay in strips of one height, top to bottom, every
1643
+ // frame: each strip's primitives come from bands of that height built once
1644
+ // per frame, not from a scan of every primitive per strip.
1645
+ struct StripLists {
1646
+ const raster::Frame *frame = nullptr;
1647
+ std::uint32_t serial = 0;
1648
+ int rows = 0;
1649
+ Bands bands;
1650
+ };
1651
+ // One per frame slot: the build core fills the building frame's lists for
1652
+ // the strip height the painter last used (g_stripRowsHint), so the painter
1653
+ // core no longer spends ~0.75 ms a frame on them.
1654
+ StripLists g_stripLists[2];
1655
+ void prebuildStripLists(const raster::Frame &frame, int slot)
1656
+ {
1657
+ const int rows = g_stripRowsHint.load(std::memory_order_relaxed);
1658
+ if (rows <= 0 || slot < 0 || slot > 1) return;
1659
+ StripLists &cache = g_stripLists[slot];
1660
+ cache.bands.rows = rows;
1661
+ buildBandLists(frame, 0, frame.height - 1, cache.bands);
1662
+ cache.frame = &frame;
1663
+ cache.serial = g_frameSerial[slot];
1664
+ cache.rows = rows;
1665
+ }
1666
+
1667
+ // Second-core share of a staged strip (rasterizePainterInPlace). Lantern on
1668
+ // the CrowPanel 5.0 spent ~18 ms a frame painting strips on one core while
1669
+ // the other built the next frame in ~14 ms; the helper paints the lower 3/8
1670
+ // of each strip there, above the build, and Lantern went from ~27 to ~30 fps.
1671
+ // Measured and dropped: half of each strip (the helper's raster and the build
1672
+ // contend for the shared cache: the build took 32 ms instead of 21), and
1673
+ // chunks claimed by work stealing at or below the build's priority (the
1674
+ // helper got 16-20% of the chunks, mid-chunk preemption left this core
1675
+ // waiting on it, and three rasterizers per strip re-walked the band list).
1676
+ #ifndef GEA3D_SPLIT_STRIPS
1677
+ #if defined(CONFIG_IDF_TARGET_ESP32P4)
1678
+ #define GEA3D_SPLIT_STRIPS 1
1679
+ #else
1680
+ #define GEA3D_SPLIT_STRIPS 0
1681
+ #endif
1682
+ #endif
1683
+ #ifndef GEA3D_SPLIT_EIGHTHS
1684
+ #define GEA3D_SPLIT_EIGHTHS 3
1685
+ #endif
1686
+ constexpr int kSplitMinRows = 8;
1687
+ struct SplitJob {
1688
+ const raster::Frame *frame;
1689
+ raster::BandList list;
1690
+ Pixel *base;
1691
+ int stride, x0, y0, x1, y1;
1692
+ };
1693
+ SplitJob g_splitJob{};
1694
+ raster::Scratch g_splitScratch;
1695
+ SemaphoreHandle_t g_splitWork = nullptr;
1696
+ SemaphoreHandle_t g_splitDone = nullptr;
1697
+ TaskHandle_t g_splitTask = nullptr;
1698
+ bool g_splitFailed = false;
1699
+
1700
+ void splitTaskMain(void *)
1701
+ {
1702
+ for (;;) {
1703
+ xSemaphoreTake(g_splitWork, portMAX_DELAY);
1704
+ const SplitJob job = g_splitJob;
1705
+ raster::Rasterizer lower(*job.frame, g_splitScratch, job.base, job.stride, job.x0, job.y0, job.x1, job.y1, raster::Occlusion::kPainter);
1706
+ lower.runPainter(job.list);
1707
+ xSemaphoreGive(g_splitDone);
1708
+ }
1709
+ }
1710
+
1711
+ bool ensureSplitTask()
1712
+ {
1713
+ if (!GEA3D_SPLIT_STRIPS || portNUM_PROCESSORS < 2) return false;
1714
+ if (g_splitTask) return true;
1715
+ if (g_splitFailed) return false;
1716
+ g_splitFailed = true;
1717
+ g_splitWork = xSemaphoreCreateBinary();
1718
+ g_splitDone = xSemaphoreCreateBinary();
1719
+ if (!g_splitWork || !g_splitDone) return false;
1720
+ const BaseType_t core = xPortGetCoreID() == 0 ? 1 : 0;
1721
+ const UBaseType_t priority = uxTaskPriorityGet(nullptr) + 1;
1722
+ if (xTaskCreatePinnedToCore(splitTaskMain, "gea3d_split", 6144, nullptr, priority, &g_splitTask, core) != pdPASS || !g_splitTask) {
1723
+ g_splitTask = nullptr;
1724
+ return false;
1725
+ }
1726
+ g_splitFailed = false;
1727
+ return true;
1728
+ }
1729
+
1730
+ // Paints rows y0..y1 of a staged strip with the helper; false when the strip
1731
+ // is too short to share or there is no helper.
1732
+ bool paintShared(const raster::Frame &frame, const raster::BandList &list, Pixel *base, int stride, int x0, int y0, int x1, int y1)
1733
+ {
1734
+ const int rows = y1 - y0 + 1;
1735
+ if (rows < kSplitMinRows || !ensureSplitTask()) return false;
1736
+ const int mid = y1 + 1 - (rows * GEA3D_SPLIT_EIGHTHS) / 8;
1737
+ g_splitJob = SplitJob{&frame, list, base, stride, x0, mid, x1, y1};
1738
+ xSemaphoreGive(g_splitWork);
1739
+ raster::Rasterizer upper(frame, g_renderer.scratch, base, stride, x0, y0, x1, mid - 1, raster::Occlusion::kPainter);
1740
+ upper.runPainter(list);
1741
+ xSemaphoreTake(g_splitDone, portMAX_DELAY);
1742
+ return true;
1743
+ }
1744
+
1745
+ bool rasterizePainterInPlace(const raster::Frame &frame, Pixel *base, int stride, int x0, int y0, int x1, int y1)
1746
+ {
1747
+ if (!esp_ptr_internal(base + static_cast<std::ptrdiff_t>(y0) * stride + x0)) return false;
1748
+ x1 = std::min(x1, frame.width - 1);
1749
+ y1 = std::min(y1, frame.height - 1);
1750
+ if (x0 > x1 || y0 > y1) return true;
1751
+
1752
+ const int rows = y1 - y0 + 1;
1753
+ // The tallest full-width strip is the staging height (a run's first and
1754
+ // last strips can be shorter; narrower boxes stage taller strips): the
1755
+ // next builds hash bands and prebuild lists at it.
1756
+ if (x0 == 0 && x1 == frame.width - 1 && rows > g_stripRowsHint.load(std::memory_order_relaxed)) g_stripRowsHint.store(rows, std::memory_order_relaxed);
1757
+ const std::ptrdiff_t slot = &frame - g_renderer.frames;
1758
+ raster::BandList list{nullptr, 0, 0};
1759
+ bool listed = false;
1760
+ if (slot >= 0 && slot < 2) {
1761
+ StripLists &cache = g_stripLists[slot];
1762
+ const std::uint32_t serial = g_frameSerial[slot];
1763
+ bool fresh = cache.frame == &frame && cache.serial == serial && cache.rows > 0;
1764
+ if (!fresh && y0 % rows == 0) {
1765
+ cache.bands.rows = rows;
1766
+ buildBandLists(frame, 0, frame.height - 1, cache.bands);
1767
+ cache.frame = &frame;
1768
+ cache.serial = serial;
1769
+ cache.rows = rows;
1770
+ fresh = true;
1771
+ }
1772
+ // Any strip inside one band reads that band's list (the build core
1773
+ // made it, at the staging height); the extra primitives clip away. A
1774
+ // strip across two bands (a UI dirty box moved its start) scans.
1775
+ if (fresh && y0 / cache.rows == y1 / cache.rows) {
1776
+ list = bandList(cache.bands, y0 / cache.rows);
1777
+ listed = true;
1778
+ }
1779
+ }
1780
+ if (!listed) {
1781
+ std::vector<std::int32_t> &items = g_renderer.bands.items;
1782
+ items.clear();
1783
+ int opaque = 0;
1784
+ for (int i = 0; i < frame.count; i++) {
1785
+ const int first = static_cast<std::int16_t>(frame.rows[i] & 0xFFFFu);
1786
+ const int last = static_cast<std::int16_t>(frame.rows[i] >> 16);
1787
+ if (last < y0 || first > y1) continue;
1788
+ items.push_back(frame.order[static_cast<std::size_t>(i)]);
1789
+ opaque += i < frame.opaqueCount;
1790
+ }
1791
+ list = raster::BandList{items.data(), static_cast<int>(items.size()), opaque};
1792
+ }
1793
+ if (paintShared(frame, list, base, stride, x0, y0, x1, y1)) return true;
1794
+ raster::Rasterizer rasterizer(frame, g_renderer.scratch, base, stride, x0, y0, x1, y1, raster::Occlusion::kPainter);
1795
+ rasterizer.runPainter(list);
1796
+ return true;
1797
+ }
1798
+ #endif
1799
+
1592
1800
  // Display::flushRectsRasterized chunk: pixels hold rows [oy, oy + h) of a
1593
1801
  // full-width band, so the chunk width is its stride.
1594
1802
  void rasterChunk(Pixel *pixels, int width, int height, int ox, int oy, void *user)
@@ -1672,18 +1880,78 @@ void paintUnderlay(int x0, int y0, int x1, int y1, void *user)
1672
1880
  if (x0 > x1 || y0 > y1) return;
1673
1881
 
1674
1882
  const int stride = canvas->strideBytes() / static_cast<int>(sizeof(Pixel));
1883
+ #if GEA3D_ASYNC_PRESENT
1884
+ if (rasterizePainterInPlace(*static_cast<const raster::Frame *>(user), canvas->pixels(), stride, x0, y0, x1, y1)) return;
1885
+ #endif
1675
1886
  rasterizeInto(*static_cast<const raster::Frame *>(user), canvas->pixels(), stride, x0, y0, x1, y1);
1676
1887
  }
1677
1888
 
1678
- bool presentUnderlay(raster::Frame &frame)
1679
- {
1680
- if (!gea::framework::display::Underlay::composited()) return false;
1681
-
1682
- auto *canvas = pd::Display::canvas();
1683
- if (!canvas || frame.width <= 0 || frame.height <= 0) return false;
1889
+ // The display's draw canvas for state only (the dirty box), where the target
1890
+ // splits it from pixel access. A double-buffered panel readies its back buffer
1891
+ // the first time Display::canvas() is asked for, copying every stale pixel in
1892
+ // from the front; asked here, before the UI's refresh can say it repaints the
1893
+ // whole frame, that was a full-screen PSRAM copy every frame.
1894
+ extern "C" gea::framework::graphics::Canvas *gea_display_state_canvas() __attribute__((weak));
1895
+
1896
+ // `hash` is the frame's band hashes, or null when it has none: then every
1897
+ // row is dirty. Rows whose bands match the frame on screen stay as they are,
1898
+ // so the UI repaints, recomposites and copies out only what moved.
1899
+ bool presentUnderlay(raster::Frame &frame, const std::vector<std::uint64_t> *hash = nullptr)
1900
+ {
1901
+ if (!gea::framework::display::Underlay::composited()) {
1902
+ g_shownBandHashValid = false;
1903
+ return false;
1904
+ }
1905
+
1906
+ auto *canvas = gea_display_state_canvas ? gea_display_state_canvas() : nullptr;
1907
+ if (!canvas) canvas = pd::Display::canvas();
1908
+ if (!canvas || frame.width <= 0 || frame.height <= 0) {
1909
+ g_shownBandHashValid = false;
1910
+ return false;
1911
+ }
1912
+
1913
+ // Changed bands as row runs; unchanged bands between them stay clean, so
1914
+ // a frame whose motion sits in a few separate bands repaints only those.
1915
+ constexpr int kMaxRuns = 8;
1916
+ int runFirst[kMaxRuns];
1917
+ int runLast[kMaxRuns];
1918
+ int runs = 0;
1919
+ const int hashRows = hash ? g_bandHashRows[hash == &g_bandHash[1] ? 1 : 0] : kBandHashRows;
1920
+ if (hash && g_shownBandHashValid && g_shownBandHashRows == hashRows && g_shownBandHash.size() == hash->size() && gea::framework::display::Underlay::active()) {
1921
+ const int bands = static_cast<int>(hash->size());
1922
+ for (int b = 0; b < bands; b++) {
1923
+ if ((*hash)[b] == g_shownBandHash[b]) continue;
1924
+ if (runs > 0 && runLast[runs - 1] == b - 1) {
1925
+ runLast[runs - 1] = b;
1926
+ } else if (runs < kMaxRuns) {
1927
+ runFirst[runs] = runLast[runs] = b;
1928
+ runs++;
1929
+ } else {
1930
+ runLast[runs - 1] = b; // out of runs: extend the last one
1931
+ }
1932
+ }
1933
+ for (int k = 0; k < runs; k++) {
1934
+ runFirst[k] *= hashRows;
1935
+ runLast[k] = std::min(frame.height - 1, (runLast[k] + 1) * hashRows - 1);
1936
+ }
1937
+ } else {
1938
+ runFirst[0] = 0;
1939
+ runLast[0] = frame.height - 1;
1940
+ runs = 1;
1941
+ }
1942
+ if (hash) {
1943
+ g_shownBandHash = *hash;
1944
+ g_shownBandHashRows = hashRows;
1945
+ g_shownBandHashValid = true;
1946
+ } else {
1947
+ g_shownBandHashValid = false;
1948
+ }
1684
1949
 
1685
1950
  gea::framework::display::Underlay::set(paintUnderlay, &frame, 0, 0, frame.width - 1, frame.height - 1);
1686
- canvas->markDirty(0, 0, frame.width - 1, frame.height - 1);
1951
+ // A background colour fills the frame before any triangle: every pixel of
1952
+ // it is written, so the UI's refresh need not restore what was there.
1953
+ gea::framework::display::Underlay::setOpaque(frame.background.mode != raster::kBackgroundNone);
1954
+ for (int k = 0; k < runs; k++) canvas->markDirty(0, runFirst[k], frame.width - 1, runLast[k]);
1687
1955
  return true;
1688
1956
  }
1689
1957
  #endif
@@ -1739,7 +2007,8 @@ void waitForPresent() {}
1739
2007
  #endif
1740
2008
 
1741
2009
  // Hands the built frame to its destination. Returns false when rejected.
1742
- bool present()
2010
+ // `hash`: the frame's band hashes, when it has them (drawScene builds).
2011
+ bool present(const std::vector<std::uint64_t> *hash = nullptr)
1743
2012
  {
1744
2013
  Renderer &r = g_renderer;
1745
2014
  raster::Frame &frame = r.frame();
@@ -1754,7 +2023,7 @@ bool present()
1754
2023
  #else
1755
2024
  #if GEA3D_UNDERLAY
1756
2025
  waitForPresent();
1757
- if (presentUnderlay(frame)) {
2026
+ if (presentUnderlay(frame, hash)) {
1758
2027
  r.stats.composited = 1;
1759
2028
  return true;
1760
2029
  }
@@ -1787,23 +2056,107 @@ void setBackground(raster::Background &background, double bgColor)
1787
2056
  std::memcpy(background.bottom, background.top, sizeof(background.top));
1788
2057
  }
1789
2058
 
2059
+
2060
+ #if GEA3D_ASYNC_PRESENT && GEA3D_UNDERLAY && !GEA3D_PRESENT_COMMANDS
2061
+ // Frame build on the other core. drawScene presents the frame built during
2062
+ // the previous call and hands this call's build to a task pinned beside the
2063
+ // display's row worker, below it in priority: the build (world matrices,
2064
+ // transform, clip, sort) overlaps the UI's strip loop instead of preceding it,
2065
+ // for one frame of latency. The build reads nodes, buffers, geometries and
2066
+ // materials and writes world matrices, so every other entry point waits for
2067
+ // it first; the painter reads only the shown frame, the band lists and the
2068
+ // raster scratch, none of which the build touches.
2069
+ #define GEA3D_ASYNC_BUILD 1
2070
+ extern "C" void gea_render_worker_block_when_idle(bool on) __attribute__((weak));
2071
+
2072
+ struct BuildJob {
2073
+ int scene = -1;
2074
+ int camera = -1;
2075
+ int width = 0;
2076
+ int height = 0;
2077
+ };
2078
+
2079
+ TaskHandle_t g_buildTask = nullptr;
2080
+ SemaphoreHandle_t g_buildWork = nullptr;
2081
+ SemaphoreHandle_t g_buildDone = nullptr;
2082
+ BuildJob g_buildJob;
2083
+ bool g_buildInFlight = false;
2084
+ // The presented frame's stats while the next build overwrites the live ones.
2085
+ Stats g_shownStats;
2086
+ bool g_buildFailed = false;
2087
+ // The slot holding a finished frame not yet presented, or -1.
2088
+ int g_readyFrame = -1;
2089
+
2090
+ void buildFrame(int scene, int camera, int width, int height);
2091
+
2092
+ void buildTaskMain(void *)
2093
+ {
2094
+ for (;;) {
2095
+ xSemaphoreTake(g_buildWork, portMAX_DELAY);
2096
+ buildFrame(g_buildJob.scene, g_buildJob.camera, g_buildJob.width, g_buildJob.height);
2097
+ g_renderer.stats.composited = 1;
2098
+ xSemaphoreGive(g_buildDone);
2099
+ }
2100
+ }
2101
+
2102
+ bool ensureBuildTask()
2103
+ {
2104
+ if (g_buildTask) return true;
2105
+ if (g_buildFailed) return false;
2106
+ g_buildFailed = true;
2107
+ g_buildWork = xSemaphoreCreateBinary();
2108
+ g_buildDone = xSemaphoreCreateBinary();
2109
+ if (!g_buildWork || !g_buildDone) return false;
2110
+ const BaseType_t core = xPortGetCoreID() == 0 ? 1 : 0;
2111
+ const UBaseType_t own = uxTaskPriorityGet(nullptr);
2112
+ const UBaseType_t priority = own > 1 ? own - 1 : 1;
2113
+ BaseType_t ok = xTaskCreatePinnedToCore(buildTaskMain, "gea3d_build", 8192, nullptr, priority, &g_buildTask, core);
2114
+ if (ok != pdPASS || !g_buildTask) {
2115
+ g_buildTask = nullptr;
2116
+ ok = xTaskCreatePinnedToCoreWithCaps(buildTaskMain, "gea3d_build", 8192, nullptr, priority, &g_buildTask, core, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
2117
+ }
2118
+ if (ok != pdPASS || !g_buildTask) {
2119
+ g_buildTask = nullptr;
2120
+ return false;
2121
+ }
2122
+ if (gea_render_worker_block_when_idle) gea_render_worker_block_when_idle(true);
2123
+ g_buildFailed = false;
2124
+ return true;
2125
+ }
2126
+
2127
+ void waitBuild()
2128
+ {
2129
+ if (!g_buildInFlight) return;
2130
+ xSemaphoreTake(g_buildDone, portMAX_DELAY);
2131
+ g_buildInFlight = false;
2132
+ }
2133
+
2134
+ #define GEA3D_SYNC_BUILD() waitBuild()
2135
+ #else
2136
+ #define GEA3D_ASYNC_BUILD 0
2137
+ #define GEA3D_SYNC_BUILD() ((void)0)
2138
+ #endif
2139
+
1790
2140
  } // namespace
1791
2141
 
1792
2142
  // ================================================================ buffers
1793
2143
 
1794
2144
  double createBuffer()
1795
2145
  {
2146
+ GEA3D_SYNC_BUILD();
1796
2147
  return allocate(g_buffers);
1797
2148
  }
1798
2149
 
1799
2150
  void deleteBuffer(double buffer)
1800
2151
  {
2152
+ GEA3D_SYNC_BUILD();
1801
2153
  Buffer *slot = lookup(g_buffers, buffer);
1802
2154
  if (slot) *slot = Buffer();
1803
2155
  }
1804
2156
 
1805
2157
  void bufferDataF32Raw(double buffer, const float *data, std::size_t count)
1806
2158
  {
2159
+ GEA3D_SYNC_BUILD();
1807
2160
  Buffer *slot = lookup(g_buffers, buffer);
1808
2161
  if (!slot) return;
1809
2162
  slot->f32.assign(data, data + count);
@@ -1812,6 +2165,7 @@ void bufferDataF32Raw(double buffer, const float *data, std::size_t count)
1812
2165
 
1813
2166
  void bufferDataU32Raw(double buffer, const std::uint32_t *data, std::size_t count)
1814
2167
  {
2168
+ GEA3D_SYNC_BUILD();
1815
2169
  Buffer *slot = lookup(g_buffers, buffer);
1816
2170
  if (!slot) return;
1817
2171
  slot->u32.assign(data, data + count);
@@ -1822,17 +2176,20 @@ void bufferDataU32Raw(double buffer, const std::uint32_t *data, std::size_t coun
1822
2176
 
1823
2177
  double createGeometry()
1824
2178
  {
2179
+ GEA3D_SYNC_BUILD();
1825
2180
  return allocate(g_geometries);
1826
2181
  }
1827
2182
 
1828
2183
  void deleteGeometry(double geometry)
1829
2184
  {
2185
+ GEA3D_SYNC_BUILD();
1830
2186
  Geometry *slot = lookup(g_geometries, geometry);
1831
2187
  if (slot) *slot = Geometry();
1832
2188
  }
1833
2189
 
1834
2190
  void geometryBuffers(double geometry, double position, double index, double color, double normal)
1835
2191
  {
2192
+ GEA3D_SYNC_BUILD();
1836
2193
  Geometry *slot = lookup(g_geometries, geometry);
1837
2194
  if (!slot) return;
1838
2195
  slot->position = static_cast<int>(position);
@@ -1844,17 +2201,20 @@ void geometryBuffers(double geometry, double position, double index, double colo
1844
2201
 
1845
2202
  double createMaterial()
1846
2203
  {
2204
+ GEA3D_SYNC_BUILD();
1847
2205
  return allocate(g_materials);
1848
2206
  }
1849
2207
 
1850
2208
  void deleteMaterial(double material)
1851
2209
  {
2210
+ GEA3D_SYNC_BUILD();
1852
2211
  Material *slot = lookup(g_materials, material);
1853
2212
  if (slot) *slot = Material();
1854
2213
  }
1855
2214
 
1856
2215
  void materialSet(double material, double shade, double r, double g, double b, double opacity, double side, double flags, double size)
1857
2216
  {
2217
+ GEA3D_SYNC_BUILD();
1858
2218
  Material *slot = lookup(g_materials, material);
1859
2219
  if (!slot) return;
1860
2220
  slot->shade = static_cast<int>(shade);
@@ -1870,6 +2230,7 @@ void materialSet(double material, double shade, double r, double g, double b, do
1870
2230
 
1871
2231
  double createNode(double kind)
1872
2232
  {
2233
+ GEA3D_SYNC_BUILD();
1873
2234
  const int id = allocate(g_nodes);
1874
2235
  g_nodes[static_cast<std::size_t>(id)].kind = static_cast<int>(kind);
1875
2236
  return id;
@@ -1877,6 +2238,7 @@ double createNode(double kind)
1877
2238
 
1878
2239
  void deleteNode(double node)
1879
2240
  {
2241
+ GEA3D_SYNC_BUILD();
1880
2242
  Node *slot = lookup(g_nodes, node);
1881
2243
  if (!slot) return;
1882
2244
 
@@ -1888,6 +2250,7 @@ void deleteNode(double node)
1888
2250
 
1889
2251
  void nodeParent(double node, double parent)
1890
2252
  {
2253
+ GEA3D_SYNC_BUILD();
1891
2254
  if (!lookup(g_nodes, node)) return;
1892
2255
 
1893
2256
  const int id = static_cast<int>(node);
@@ -1901,6 +2264,7 @@ void nodeParent(double node, double parent)
1901
2264
 
1902
2265
  void nodeTransform(double node, double px, double py, double pz, double qx, double qy, double qz, double qw, double sx, double sy, double sz)
1903
2266
  {
2267
+ GEA3D_SYNC_BUILD();
1904
2268
  Node *slot = lookup(g_nodes, node);
1905
2269
  if (!slot) return;
1906
2270
  const float position[3] = {static_cast<float>(px), static_cast<float>(py), static_cast<float>(pz)};
@@ -1920,6 +2284,7 @@ void nodeTransform(double node, double px, double py, double pz, double qx, doub
1920
2284
 
1921
2285
  void nodeMatrixRaw(double node, const float *elements, std::size_t count)
1922
2286
  {
2287
+ GEA3D_SYNC_BUILD();
1923
2288
  Node *slot = lookup(g_nodes, node);
1924
2289
  if (!slot || count < 16) return;
1925
2290
  // An unchanged matrix keeps the cached world matrices.
@@ -1932,6 +2297,7 @@ void nodeMatrixRaw(double node, const float *elements, std::size_t count)
1932
2297
 
1933
2298
  void nodeFlags(double node, double visible, double frustumCulled, double renderOrder)
1934
2299
  {
2300
+ GEA3D_SYNC_BUILD();
1935
2301
  Node *slot = lookup(g_nodes, node);
1936
2302
  if (!slot) return;
1937
2303
  slot->visible = visible != 0;
@@ -1941,6 +2307,7 @@ void nodeFlags(double node, double visible, double frustumCulled, double renderO
1941
2307
 
1942
2308
  void nodeGeometry(double node, double geometry, double material)
1943
2309
  {
2310
+ GEA3D_SYNC_BUILD();
1944
2311
  Node *slot = lookup(g_nodes, node);
1945
2312
  if (!slot) return;
1946
2313
  slot->geometry = static_cast<int>(geometry);
@@ -1949,6 +2316,7 @@ void nodeGeometry(double node, double geometry, double material)
1949
2316
 
1950
2317
  void nodeInstances(double node, double matrices, double colors, double count)
1951
2318
  {
2319
+ GEA3D_SYNC_BUILD();
1952
2320
  Node *slot = lookup(g_nodes, node);
1953
2321
  if (!slot) return;
1954
2322
  slot->instanced = true;
@@ -1959,6 +2327,7 @@ void nodeInstances(double node, double matrices, double colors, double count)
1959
2327
 
1960
2328
  void nodeLight(double node, double kind, double r, double g, double b, double intensity, double groundR, double groundG, double groundB, double distance, double decay)
1961
2329
  {
2330
+ GEA3D_SYNC_BUILD();
1962
2331
  Node *slot = lookup(g_nodes, node);
1963
2332
  if (!slot) return;
1964
2333
  slot->lightKind = static_cast<int>(kind);
@@ -1975,6 +2344,7 @@ void nodeLight(double node, double kind, double r, double g, double b, double in
1975
2344
 
1976
2345
  void nodeLightTarget(double node, double x, double y, double z)
1977
2346
  {
2347
+ GEA3D_SYNC_BUILD();
1978
2348
  Node *slot = lookup(g_nodes, node);
1979
2349
  if (!slot) return;
1980
2350
  slot->target[0] = static_cast<float>(x);
@@ -1984,6 +2354,7 @@ void nodeLightTarget(double node, double x, double y, double z)
1984
2354
 
1985
2355
  void cameraProjectionRaw(double node, const float *elements, std::size_t count, double near, double far)
1986
2356
  {
2357
+ GEA3D_SYNC_BUILD();
1987
2358
  Node *slot = lookup(g_nodes, node);
1988
2359
  if (!slot || count < 16) return;
1989
2360
  std::memcpy(slot->projection, elements, sizeof(slot->projection));
@@ -1993,6 +2364,7 @@ void cameraProjectionRaw(double node, const float *elements, std::size_t count,
1993
2364
 
1994
2365
  void sceneEnvironment(double scene, double background, double top, double bottom, double fog, double fogColor, double fogNear, double fogFar, double fogDensity)
1995
2366
  {
2367
+ GEA3D_SYNC_BUILD();
1996
2368
  Node *slot = lookup(g_nodes, scene);
1997
2369
  if (!slot) return;
1998
2370
 
@@ -2015,17 +2387,20 @@ void sceneEnvironment(double scene, double background, double top, double bottom
2015
2387
 
2016
2388
  void renderOptions(double depthBuffer, double capacity)
2017
2389
  {
2390
+ GEA3D_SYNC_BUILD();
2018
2391
  g_renderer.depthBuffer = depthBuffer != 0;
2019
2392
  if (capacity >= 64) g_renderer.capacity = static_cast<int>(capacity);
2020
2393
  }
2021
2394
 
2022
2395
  void renderTarget(double surface)
2023
2396
  {
2397
+ GEA3D_SYNC_BUILD();
2024
2398
  g_renderer.surface = static_cast<int>(surface);
2025
2399
  }
2026
2400
 
2027
2401
  double createSurface(double width, double height)
2028
2402
  {
2403
+ GEA3D_SYNC_BUILD();
2029
2404
  const int w = static_cast<int>(width);
2030
2405
  const int h = static_cast<int>(height);
2031
2406
  if (w <= 0 || h <= 0 || g_surfaces.count >= 8) return -1;
@@ -2045,36 +2420,145 @@ double createSurface(double width, double height)
2045
2420
  return id;
2046
2421
  }
2047
2422
 
2048
- double drawScene(double scene, double camera, double width, double height)
2423
+ namespace {
2424
+ GEA3D_INLINE std::uint64_t mixHash(std::uint64_t h, std::uint64_t v)
2425
+ {
2426
+ h ^= v + 0x9E3779B97F4A7C15ull + (h << 6) + (h >> 2);
2427
+ return h * 0xBF58476D1CE4E5B9ull;
2428
+ }
2429
+
2430
+ std::uint64_t primHash(const raster::Prim &p, bool opaque, bool withDepth, bool withKey)
2049
2431
  {
2050
- Node *sceneNode = lookup(g_nodes, scene);
2051
- Node *cameraNode = lookup(g_nodes, camera);
2052
- if (!sceneNode || !cameraNode) return 0;
2432
+ std::uint64_t h = 0xCBF29CE484222325ull;
2433
+ for (int k = 0; k < 3; k++) h = mixHash(h, (static_cast<std::uint64_t>(static_cast<std::uint32_t>(p.x[k])) << 32) | static_cast<std::uint32_t>(p.y[k]));
2434
+ h = mixHash(h, static_cast<std::uint64_t>(p.r[0]) | static_cast<std::uint64_t>(p.r[1]) << 8 | static_cast<std::uint64_t>(p.r[2]) << 16 |
2435
+ static_cast<std::uint64_t>(p.g[0]) << 24 | static_cast<std::uint64_t>(p.g[1]) << 32 | static_cast<std::uint64_t>(p.g[2]) << 40 |
2436
+ static_cast<std::uint64_t>(p.b[0]) << 48 | static_cast<std::uint64_t>(p.b[1]) << 56);
2437
+ h = mixHash(h, static_cast<std::uint64_t>(p.b[2]) | static_cast<std::uint64_t>(p.type) << 8 | static_cast<std::uint64_t>(p.flags) << 16 |
2438
+ static_cast<std::uint64_t>(p.alpha) << 24 | static_cast<std::uint64_t>(p.width) << 32 | static_cast<std::uint64_t>(p.color) << 40 |
2439
+ static_cast<std::uint64_t>(opaque) << 56);
2440
+ if (withDepth) {
2441
+ std::uint32_t d[3];
2442
+ std::memcpy(d, p.depth, sizeof(d));
2443
+ h = mixHash(h, (static_cast<std::uint64_t>(d[0]) << 32) | d[1]);
2444
+ h = mixHash(h, d[2]);
2445
+ }
2446
+ if (withKey) {
2447
+ std::uint32_t key;
2448
+ std::memcpy(&key, &p.key, sizeof(key));
2449
+ h = mixHash(h, key);
2450
+ }
2451
+ return h;
2452
+ }
2053
2453
 
2454
+ // Band hashes of a sorted frame. Depth matters only to a depth-tested frame,
2455
+ // and the sort key only where blended primitives interleave by it.
2456
+ void hashBands(const raster::Frame &frame, std::vector<std::uint64_t> &out, int bandRows)
2457
+ {
2458
+ const int bands = frame.height > 0 ? (frame.height + bandRows - 1) / bandRows : 0;
2459
+ std::uint64_t seed = mixHash(0x84222325CBF29CE4ull, static_cast<std::uint64_t>(frame.width) << 32 | static_cast<std::uint32_t>(frame.height));
2460
+ const raster::Background &bg = frame.background;
2461
+ seed = mixHash(seed, static_cast<std::uint64_t>(bg.mode) | static_cast<std::uint64_t>(bg.top[0]) << 8 | static_cast<std::uint64_t>(bg.top[1]) << 16 |
2462
+ static_cast<std::uint64_t>(bg.top[2]) << 24 | static_cast<std::uint64_t>(bg.bottom[0]) << 32 |
2463
+ static_cast<std::uint64_t>(bg.bottom[1]) << 40 | static_cast<std::uint64_t>(bg.bottom[2]) << 48 |
2464
+ static_cast<std::uint64_t>(frame.depthBuffer) << 56);
2465
+ out.assign(static_cast<std::size_t>(bands), seed);
2466
+ const bool withDepth = frame.depthBuffer;
2467
+ const bool withKey = frame.blendCount > 0;
2468
+ for (int i = 0; i < frame.count; i++) {
2469
+ const int first = maxInt(static_cast<std::int16_t>(frame.rows[i] & 0xFFFFu), 0);
2470
+ const int last = minInt(static_cast<std::int16_t>(frame.rows[i] >> 16), frame.height - 1);
2471
+ if (first > last) continue;
2472
+ const std::uint64_t h = primHash(frame.prims[frame.order[static_cast<std::size_t>(i)]], i < frame.opaqueCount, withDepth, withKey);
2473
+ for (int b = first / bandRows; b <= last / bandRows; b++) out[static_cast<std::size_t>(b)] = mixHash(out[static_cast<std::size_t>(b)], h);
2474
+ }
2475
+ }
2476
+
2477
+ // Builds the scene into frames[building] (no present).
2478
+ void buildFrame(int scene, int camera, int width, int height)
2479
+ {
2480
+ Node &sceneNode = g_nodes[static_cast<std::size_t>(scene)];
2481
+ Node &cameraNode = g_nodes[static_cast<std::size_t>(camera)];
2054
2482
  Renderer &r = g_renderer;
2055
- beginFrameState(static_cast<int>(width), static_cast<int>(height));
2483
+ beginFrameState(width, height);
2056
2484
  r.legacyActive = false;
2057
2485
  raster::Frame &frame = r.frame();
2058
- r.environment = sceneNode->environment;
2486
+ r.environment = sceneNode.environment;
2059
2487
  frame.background = r.environment.background;
2060
2488
 
2061
- collect(static_cast<int>(scene));
2489
+ collect(scene);
2062
2490
 
2063
- ensureWorld(static_cast<int>(camera));
2064
- math::invertAffine(r.view.view, cameraNode->world);
2065
- setProjection(cameraNode->projection, cameraNode->near, cameraNode->far);
2491
+ ensureWorld(camera);
2492
+ math::invertAffine(r.view.view, cameraNode.world);
2493
+ setProjection(cameraNode.projection, cameraNode.near, cameraNode.far);
2066
2494
 
2067
2495
  for (const int id : r.lightNodes) addLight(g_nodes[static_cast<std::size_t>(id)]);
2068
2496
  for (const int id : r.drawables) drawNode(g_nodes[static_cast<std::size_t>(id)]);
2069
2497
 
2070
2498
  sortFrame();
2071
- const int count = frame.count;
2072
- return present() ? count : -1;
2499
+ r.stats.primitives = frame.count;
2500
+ {
2501
+ const int hint = g_stripRowsHint.load(std::memory_order_relaxed);
2502
+ g_bandHashRows[r.building] = hint >= 4 && hint <= 32 ? hint : kBandHashRows;
2503
+ }
2504
+ hashBands(frame, g_bandHash[r.building], g_bandHashRows[r.building]);
2505
+ g_frameSerial[r.building]++;
2506
+ #if GEA3D_ASYNC_PRESENT
2507
+ prebuildStripLists(frame, r.building);
2508
+ #endif
2509
+ }
2510
+ } // namespace
2511
+
2512
+ double drawScene(double scene, double camera, double width, double height)
2513
+ {
2514
+ GEA3D_SYNC_BUILD();
2515
+ if (!lookup(g_nodes, scene) || !lookup(g_nodes, camera)) return 0;
2516
+ const int sceneId = static_cast<int>(scene);
2517
+ const int cameraId = static_cast<int>(camera);
2518
+ const int w = static_cast<int>(width);
2519
+ const int h = static_cast<int>(height);
2520
+ Renderer &r = g_renderer;
2521
+
2522
+ #if GEA3D_ASYNC_BUILD
2523
+ if (r.surface < 0 && gea::framework::display::Underlay::composited() && ensureBuildTask()) {
2524
+ if (g_readyFrame < 0) {
2525
+ // First frame (or after a synchronous one): nothing built ahead.
2526
+ waitForPresent();
2527
+ buildFrame(sceneId, cameraId, w, h);
2528
+ g_readyFrame = r.building;
2529
+ }
2530
+ raster::Frame &shown = r.frames[g_readyFrame];
2531
+ if (shown.width != w || shown.height != h || !presentUnderlay(shown, &g_bandHash[g_readyFrame])) {
2532
+ g_readyFrame = -1;
2533
+ } else {
2534
+ const int count = shown.count;
2535
+ g_shownStats = r.stats;
2536
+ g_shownStats.composited = 1;
2537
+ r.building = g_readyFrame ^ 1;
2538
+ g_buildJob = BuildJob{sceneId, cameraId, w, h};
2539
+ g_buildInFlight = true;
2540
+ g_readyFrame = r.building;
2541
+ xSemaphoreGive(g_buildWork);
2542
+ return count;
2543
+ }
2544
+ } else {
2545
+ g_readyFrame = -1;
2546
+ }
2547
+ #endif
2548
+
2549
+ buildFrame(sceneId, cameraId, w, h);
2550
+ const int count = r.frame().count;
2551
+ return present(&g_bandHash[r.building]) ? count : -1;
2073
2552
  }
2074
2553
 
2075
2554
  double stat(double which)
2076
2555
  {
2556
+ // The shown frame's counts: no wait for the build running ahead.
2557
+ #if GEA3D_ASYNC_BUILD
2558
+ const Stats &s = g_buildInFlight ? g_shownStats : g_renderer.stats;
2559
+ #else
2077
2560
  const Stats &s = g_renderer.stats;
2561
+ #endif
2078
2562
  switch (static_cast<int>(which)) {
2079
2563
  case 0: return s.submitted;
2080
2564
  case 1: return s.nearRejected;
@@ -2093,6 +2577,7 @@ double stat(double which)
2093
2577
 
2094
2578
  double raycast(double node, double ox, double oy, double oz, double dx, double dy, double dz, double near, double far)
2095
2579
  {
2580
+ GEA3D_SYNC_BUILD();
2096
2581
  Node *slot = lookup(g_nodes, node);
2097
2582
  if (!slot || slot->kind != kNodeMesh) return 0;
2098
2583
  Geometry *geometry = lookup(g_geometries, slot->geometry);
@@ -2163,6 +2648,7 @@ double raycast(double node, double ox, double oy, double oz, double dx, double d
2163
2648
 
2164
2649
  double rayResult(double which)
2165
2650
  {
2651
+ GEA3D_SYNC_BUILD();
2166
2652
  switch (static_cast<int>(which)) {
2167
2653
  case 0: return g_rayHit.distance;
2168
2654
  case 1: return g_rayHit.point[0];
@@ -2178,6 +2664,7 @@ double rayResult(double which)
2178
2664
 
2179
2665
  void beginFrameRaw(const float *projection, std::size_t count, double near, double bgColor, double viewportW, double viewportH)
2180
2666
  {
2667
+ GEA3D_SYNC_BUILD();
2181
2668
  Renderer &r = g_renderer;
2182
2669
  beginFrameState(static_cast<int>(viewportW), static_cast<int>(viewportH));
2183
2670
  r.legacyActive = true;
@@ -2191,6 +2678,7 @@ void beginFrameRaw(const float *projection, std::size_t count, double near, doub
2191
2678
 
2192
2679
  void ambientLight(double r, double g, double b)
2193
2680
  {
2681
+ GEA3D_SYNC_BUILD();
2194
2682
  Lights &lights = g_renderer.lights;
2195
2683
  lights.ambient[0] += static_cast<float>(r);
2196
2684
  lights.ambient[1] += static_cast<float>(g);
@@ -2199,6 +2687,7 @@ void ambientLight(double r, double g, double b)
2199
2687
 
2200
2688
  void directionalLight(double x, double y, double z, double r, double g, double b)
2201
2689
  {
2690
+ GEA3D_SYNC_BUILD();
2202
2691
  Lights &lights = g_renderer.lights;
2203
2692
  float direction[3] = {static_cast<float>(x), static_cast<float>(y), static_cast<float>(z)};
2204
2693
  if (lights.directionalCount >= kMaxLights || !math::normalize3(direction)) return;
@@ -2221,6 +2710,7 @@ void drawElementsRaw(double positionBuffer,
2221
2710
  double baseB,
2222
2711
  double doubleSide)
2223
2712
  {
2713
+ GEA3D_SYNC_BUILD();
2224
2714
  if (!g_renderer.legacyActive || modelViewCount < 16) return;
2225
2715
  const Buffer *positions = bufferAt(static_cast<int>(positionBuffer));
2226
2716
  if (!positions) return;
@@ -2251,6 +2741,7 @@ void drawElementsRaw(double positionBuffer,
2251
2741
 
2252
2742
  double endFrame()
2253
2743
  {
2744
+ GEA3D_SYNC_BUILD();
2254
2745
  if (!g_renderer.legacyActive) return 0;
2255
2746
  g_renderer.legacyActive = false;
2256
2747
  sortFrame();