Skip to content

Commit abe345b

Browse files
merge: sync main mesh caching while preserving frozen image evidence
2 parents 2ca6450 + eb1e7c1 commit abe345b

6 files changed

Lines changed: 166 additions & 4 deletions

File tree

‎AGENTS.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ performs this setup. Its results are source diagnostics, not visual certificatio
7373
## Codebase navigation and knowledge tools
7474

7575
- Negative warp powers (2026-10-08): patch0015 supplies original CPU negative effective zoom through instance-owned attribute9, after per-pixel/per-frame float conversion. Preserve raw equation values, positive GPU arithmetic, nonfinite fractional results and prepared replay; no epsilon, absolute value or NaN-to-zero policy. Exact Tulip source `c897d686…` retains 33 NaNs/frame and its 30-frame published/candidate replay is byte-identical. Defined nested exponents1/2/3 fail baseline UV controls and pass after correction. See [bounded evidence](docs/superpowers/evidence/tulip-negative-zoom-power/README.md). Current warp uses eight active attributes and four extra bytes/vertex. Normal/sanitizer renderer37/37 and JVM137 pass; 329 host controls, fresh recursive both-ABI debug core and strict MkDocs also pass. External review/CI/merge/publication gates remain separate until recorded. Do not clear the source predictor's unresolved fractional-power guard or resume its shared random run from this evidence.
76+
- Mesh initialization cache (2026-10-08): patch 0016 stores the viewport size in `PerPixelMesh`/`FinalComposite`, so their static mesh data (and the warp mesh's vertex/index upload) is built once per size or grid change instead of every frame. Image output is unchanged; on the AM6 (Android 9, 32-bit) the pinned `$$$ Royal - Mashup (102).milk` run at 1080p/30 fps used about 12% less process CPU (two runs per side, silence; GPU time unmeasured). Evidence: `docs/superpowers/evidence/mesh-init-cache/README.md`. Profile APKs: the installable file is `app/build/outputs/apk/profile/app-profile.apk` (`app/build/intermediates/apk/profile/` can be stale); install with `adb install -t`.
7677

7778
- BrainStain legacy compatibility (2026-10-08): patch 0014 respects authored `fShader` in legacy echo/gamma output and restores mode-1 alpha ×1.25 before clamp and open-strip topology, following MilkDrop 2.25c. Keep custom composite hue behaviour and preset assets unchanged. See [focused evidence](docs/superpowers/evidence/brainstain-dark-output/README.md); predictor agreement alone does not establish MilkDrop correctness. Three independent controls fail before/pass after; 37 normal renderer controls, 329 host controls, both-ABI release builds and 137 JVM tests pass. First-frame black is explained by the authored echo crop despite bright raw feedback. All 37 sanitizer renderer controls also pass; macOS skips the separate EGL/GLES transition-overlay test. The fresh recursive debug-core build and strict MkDocs pass. External review, CI, merge and release gates remain open at this checkpoint.
7879

@@ -529,3 +530,11 @@ Proof label portability (2026-10-08): capture/verifier use the committed bitmap
529530
font under tools/patch-proof/assets, without default-font/FreeType selection.
530531
Label-only comparison reconstruction records its font/image identity separately
531532
from the original producer; framebuffer payloads remain unchanged.
533+
534+
PR55 main60 synchronization (2026-10-08): main eb1e7c16 adds0016; preserve the
535+
15-patch image checkpoint at120547f3 and link the separate AM6 performance
536+
evidence, as selected by the user. All16 patches apply in an isolated export.
537+
137 proof controls, native engine/JNI checks,37 ASan/UBSan regression cases on
538+
macOS OpenGL and strict MkDocs pass. The separate EGL transition-overlay check
539+
was not run on macOS. These checks do not turn the frozen images into16-patch
540+
GPU certification.

‎core/src/test/native/projectm-regressions/warp_rotation_test.cpp‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,55 @@ static void Feedback(TextureManager& textures, bool perPixel, bool preparedRepla
281281
}
282282
}
283283

284+
// The mesh keeps its static vertices and indices between frames. A reused instance must still
285+
// match a fresh one after viewport (aspect) and grid changes: stale radius/angle or indices fail.
286+
static void MeshCacheControls(TextureManager& textures)
287+
{
288+
struct Layout { int x, y, gridX, gridY; };
289+
const std::array<Layout, 5> layouts{{{64, 48, 8, 6}, {64, 48, 8, 6}, {48, 64, 8, 6}, {48, 64, 12, 6}, {64, 48, 8, 6}}};
290+
for (bool custom : {false, true})
291+
for (bool perPixel : {false, true})
292+
{
293+
Control reused(textures, custom, perPixel);
294+
for (const Layout& layout : layouts)
295+
{
296+
Control fresh(textures, custom, perPixel);
297+
Pixels expected, actual;
298+
std::vector<float> expectedAngles, actualAngles;
299+
for (Control* control : {&fresh, &reused})
300+
{
301+
auto& context = control->state.renderContext;
302+
context.viewportSizeX = layout.x; context.viewportSizeY = layout.y;
303+
context.aspectX = layout.y > layout.x ? float(layout.x) / layout.y : 1.f;
304+
context.aspectY = layout.x > layout.y ? float(layout.y) / layout.x : 1.f;
305+
context.invAspectX = 1.f / context.aspectX; context.invAspectY = 1.f / context.aspectY;
306+
context.perPixelMeshX = layout.gridX; context.perPixelMeshY = layout.gridY;
307+
powerObserved = false;
308+
powerDrawElements = glad_glDrawElements;
309+
glad_glDrawElements = ObservePowerDraw;
310+
Pixels pixels;
311+
try { pixels = control->Draw(0.4, perPixel); }
312+
catch (...) { glad_glDrawElements = powerDrawElements; throw; }
313+
glad_glDrawElements = powerDrawElements;
314+
Check(powerObserved, "mesh cache control did not draw");
315+
(control == &fresh ? expected : actual) = pixels;
316+
(control == &fresh ? expectedAngles : actualAngles) = powerRadii;
317+
}
318+
Check(expectedAngles == actualAngles, "reused mesh kept stale radius/angle after a viewport or grid change");
319+
Check(expected == actual, "reused mesh drew differently from a fresh mesh");
320+
}
321+
}
322+
std::cout << "mesh cache: reused mesh matches fresh mesh across viewport and grid changes\n";
323+
}
324+
284325
int main()
285326
{
286327
try
287328
{
288329
GLContext gl;
289330
TextureManager textures(std::vector<std::string>{});
290331
PowerUploadControls(textures);
332+
MeshCacheControls(textures);
291333
std::cout << glGetString(GL_RENDERER) << '\n';
292334
for (bool preparedReplay : {false, true})
293335
for (bool custom : {false, true})

‎docs/UPSTREAM_PATCH_VALUE.md‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# What our current projectM patches change
22

3-
This page compares upstream projectM 4.2 development with our library. Each section
4-
shows the rendered difference and explains its cause. The locked 15 current patches are
3+
This page shows what our library changes compared with upstream projectM 4.2
4+
development, using images and short explanations. The16 current patches are
55
listed in build order; older patch history is kept in the evidence archive.
66

77
## Single-page comparison overview
@@ -12,7 +12,7 @@ A middle column, where present, removes one patch to isolate its effect. Generat
1212
controls are labeled; a rejected render is an error panel, not a black screenshot.
1313

1414
Earlier images use our 13-patch snapshot `654815d8`; 0014 uses the current 14-patch
15-
snapshot `41ec3fc1`. The publication scope is locked to main `120547f3`, including0015. Earlier captures retain their original snapshot identities;Reference lines and0003,0011 and0015 now have locked15-patch comparisons.
15+
snapshot `41ec3fc1`. The image-comparison checkpoint stays frozen at main `120547f3`, including0015; main’s later0016 is documented from its separate performance evidence. Earlier captures retain their original snapshot identities;Reference lines and0003,0011 and0015 now have locked15-patch comparisons.
1616
The upstream renderer matches master `e98fca85`; capture adjustments and source
1717
identities are recorded in the [evidence record](superpowers/evidence/current-patch-proof/README.md).
1818

@@ -288,6 +288,20 @@ and its recorded frames remain unchanged. It must not be presented as fixed.
288288
[Locked-source comparison and checks](superpowers/evidence/current-patch-proof/components/locked15-power/README.md) ·
289289
[Patch source](../tools/projectm-patches/0015-warp-negative-zoom-cpu-power.patch).
290290

291+
## 0016 — Mesh initialization caching
292+
293+
Upstream rebuilt the warp and final-composite grids every frame because it never
294+
saved the viewport size used by its cache check. This patch saves the size and
295+
rebuilds/uploads static mesh data only when the viewport or grid changes.
296+
297+
On the AM6, **Royal — Mashup (102)** at1080p/30fps used11.8% less process CPU in two
298+
40-second runs per side, with silence. GPU time and4K were not measured. Existing
299+
host controls check reused versus fresh mesh data; no on-device image comparison
300+
was run. This later main optimization is included without expanding the frozen
301+
15-patch capture checkpoint.
302+
[Performance evidence](superpowers/evidence/mesh-init-cache/README.md) ·
303+
[Patch source](../tools/projectm-patches/0016-cache-mesh-init-per-viewport.patch).
304+
291305
## Supporting evidence and remaining work
292306

293307
[Full-resolution images, inputs and verification](superpowers/evidence/current-patch-proof/README.md)

‎docs/superpowers/evidence/current-patch-proof/README.md‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Original image captures and integrity audit recorded, 2026-10-07. [PR #55](https://github.com/johnneerdael/ProjectM-TV/pull/55) tracks final repository review and publication. Original capture source is `654815d8`; all 13 ordered
44
patch hashes are in [series.json](series.json). The main
55
[patch reference](../../../UPSTREAM_PATCH_VALUE.md) now covers the locked 15-patch
6-
publication inventory at `120547f3`, recorded in [current-series.json](current-series.json).
6+
capture inventory at `120547f3`, recorded in [current-series.json](current-series.json).
77
The [archived assessment](pre-rewrite-assessment.md) preserves earlier attribution.
88

99
## Current-main synchronization
@@ -22,6 +22,11 @@ with retained execution evidence. The [complete evaluator comparison](components
2222
checks all three roles separately. Revalidation of other affected earlier
2323
witnesses remains pending.
2424

25+
Main synchronization to `eb1e7c16` adds0016 mesh initialization caching. The
26+
existing15-patch workers and captures stay frozen by agreement;0016 uses its
27+
[separate AM6 performance evidence](../mesh-init-cache/README.md). It is not
28+
credited as a new GPU image comparison or silently added to current-series.json.
29+
2530
## Comparison contract
2631

2732
Use a dedicated Android TV API36 AVD, `CurrentPatchProofTV36`, serial
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Mesh initialization cache (patch 0016)
2+
3+
Measured 2026-10-08 on the user-authorized Ugoos AM6 (`192.168.50.80`, Android 9, 32-bit `armeabi-v7a`, Mali-G52),
4+
profile build of this repository (`:app:assembleProfile`), user 0, default settings (Auto resolution, 30 fps cap),
5+
pinned preset `$$$ Royal - Mashup (102).milk` (`debug.projectmtv.preset`, cleared afterwards), no audio playing.
6+
Baseline = `main` at `120547f3`; candidate = same plus patch 0016.
7+
8+
simpleperf `cpu-clock -f 1000 -g` on the app process, 40 s per run, only runs that stayed at `surface=1920x1080` / 30 fps:
9+
10+
| | samples (ms of CPU in 40 s) |
11+
|---|---|
12+
| baseline run 1 / 2 | 8,619 / 8,455 |
13+
| candidate run 1 / 2 | 7,706 / 7,352 |
14+
15+
Mean 8,537 → 7,529 ms (−11.8 %). In the baseline `PerPixelMesh::InitializeMesh`, `FinalComposite::InitializeMesh`,
16+
`VertexIndexArray::operator[]` and the `hypotf`/`atan2f`/`atanf` calls they make accounted for roughly 12 % of samples;
17+
in the candidate `InitializeMesh` no longer appears and `hypotf` falls to 0.5 %.
18+
19+
Limits: one preset, one device, silence, two runs per side; run-to-run spread is about 2 %. GPU time and
20+
4K/Native resolution were not measured. A first baseline run was not comparable because Auto raised the resolution
21+
mid-run. Pixel identity is established by the host tests and the `MeshCacheControls` control in
22+
`warp_rotation_test.cpp` (a reused mesh matches a fresh mesh across viewport and grid changes), not by on-device image comparison.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
From: ProjectM TV contributors
2+
Subject: [PATCH] Build the warp and composite meshes once per viewport size
3+
4+
PerPixelMesh and FinalComposite compare the viewport against m_viewportWidth/Height
5+
to skip rebuilding their static mesh data, but nothing ever stored those values. Both
6+
meshes were therefore rebuilt every frame: per-vertex hypotf/atan2f, the full index
7+
list, and (warp mesh) the vertex positions and index buffer uploaded again.
8+
Record the viewport size when the data is built; the warp mesh uploads its static
9+
vertices and indices only after a rebuild. The values written are unchanged, so the
10+
rendered image is identical; only the repeated CPU work and uploads are removed.
11+
12+
---
13+
diff --git a/src/libprojectM/MilkdropPreset/FinalComposite.cpp b/src/libprojectM/MilkdropPreset/FinalComposite.cpp
14+
index 18209831e..f07c802c4 100644
15+
--- a/src/libprojectM/MilkdropPreset/FinalComposite.cpp
16+
+++ b/src/libprojectM/MilkdropPreset/FinalComposite.cpp
17+
@@ -139,6 +139,10 @@ void FinalComposite::InitializeMesh(const PresetState& presetState)
18+
return;
19+
}
20+
21+
+ // The grid only depends on the viewport size: build it once per size, not every frame.
22+
+ m_viewportWidth = presetState.renderContext.viewportSizeX;
23+
+ m_viewportHeight = presetState.renderContext.viewportSizeY;
24+
+
25+
float const dividedByX = 1.0f / static_cast<float>(compositeGridWidth - 2);
26+
float const dividedByY = 1.0f / static_cast<float>(compositeGridHeight - 2);
27+
28+
diff --git a/src/libprojectM/MilkdropPreset/PerPixelMesh.cpp b/src/libprojectM/MilkdropPreset/PerPixelMesh.cpp
29+
index e3332dad6..c67423e87 100644
30+
--- a/src/libprojectM/MilkdropPreset/PerPixelMesh.cpp
31+
+++ b/src/libprojectM/MilkdropPreset/PerPixelMesh.cpp
32+
@@ -158,6 +158,12 @@ void PerPixelMesh::InitializeMesh(const PresetState& presetState)
33+
const float aspectX = presetState.renderContext.aspectX;
34+
const float aspectY = presetState.renderContext.aspectY;
35+
36+
+ // Remember what the static mesh data is built for, so it is only rebuilt and uploaded again
37+
+ // when the viewport or the grid changes, not every frame.
38+
+ m_viewportWidth = presetState.renderContext.viewportSizeX;
39+
+ m_viewportHeight = presetState.renderContext.viewportSizeY;
40+
+ m_meshDirty = true;
41+
+
42+
// Either viewport size or mesh size changed, reinitialize the vertices.
43+
auto& vertices = m_warpMesh.Vertices();
44+
int vertexIndex{0};
45+
@@ -313,7 +319,12 @@ void PerPixelMesh::CalculateMesh(const PresetState& presetState, const PerFrameC
46+
}
47+
}
48+
49+
- m_warpMesh.Update();
50+
+ // Vertex positions and indices only change when InitializeMesh() rebuilt them.
51+
+ if (m_meshDirty)
52+
+ {
53+
+ m_warpMesh.Update();
54+
+ m_meshDirty = false;
55+
+ }
56+
m_radiusAngleBuffer.Update();
57+
m_zoomRotWarpBuffer.Update();
58+
m_centerBuffer.Update();
59+
diff --git a/src/libprojectM/MilkdropPreset/PerPixelMesh.hpp b/src/libprojectM/MilkdropPreset/PerPixelMesh.hpp
60+
index 0b589bc54..ef866120e 100644
61+
--- a/src/libprojectM/MilkdropPreset/PerPixelMesh.hpp
62+
+++ b/src/libprojectM/MilkdropPreset/PerPixelMesh.hpp
63+
@@ -146,6 +146,7 @@ private:
64+
65+
int m_viewportWidth{}; //!< Last known viewport width.
66+
int m_viewportHeight{}; //!< Last known viewport height.
67+
+ bool m_meshDirty{true}; //!< Vertex positions and indices must be uploaded before the next draw.
68+
69+
Renderer::Mesh m_warpMesh; //!< The Warp effect mesh
70+
Renderer::VertexBuffer<RadiusAngle> m_radiusAngleBuffer{Renderer::VertexBufferUsage::StreamDraw}; //!< Vertex attribute buffer for radius and angle values.

0 commit comments

Comments
 (0)