From e277913e22a064606a87e2aaf0e190b30b47cd7f Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Tue, 21 Apr 2026 23:30:35 +0200 Subject: [PATCH] BufferProvider: start planning for the memory handling part MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As staring point, it is clear that the `BufferStore` side of the implementation will rely on a similar structure with a thread-local base service — which in this case will have to maintain a small pool of recently used buffer allocations... --- src/vault/mem/local-buffer-stage.hpp | 2 +- src/vault/mem/local-buffer-store.hpp | 53 +++++ src/vault/mem/local-mem-pool.hpp | 55 +++++ tests/47engine.tests | 10 + tests/vault/mem/local-buffer-store-test.cpp | 94 +++++++++ tests/vault/mem/local-mem-pool-test.cpp | 94 +++++++++ wiki/thinkPad.ichthyo.mm | 215 +++++++++++++++++--- 7 files changed, 494 insertions(+), 29 deletions(-) create mode 100644 src/vault/mem/local-buffer-store.hpp create mode 100644 src/vault/mem/local-mem-pool.hpp create mode 100644 tests/vault/mem/local-buffer-store-test.cpp create mode 100644 tests/vault/mem/local-mem-pool-test.cpp diff --git a/src/vault/mem/local-buffer-stage.hpp b/src/vault/mem/local-buffer-stage.hpp index 722089b19..fe172eeb1 100644 --- a/src/vault/mem/local-buffer-stage.hpp +++ b/src/vault/mem/local-buffer-stage.hpp @@ -1,5 +1,5 @@ /* - SIMPLE-BUFFER-STATE-REGISTRY.hpp - buffer state management with thread-local sub-services + LOCAL-BUFFER-STAGE.hpp - buffer state management with thread-local sub-services Copyright (C) 2026 Hermann Vosseler diff --git a/src/vault/mem/local-buffer-store.hpp b/src/vault/mem/local-buffer-store.hpp new file mode 100644 index 000000000..0dc4c67eb --- /dev/null +++ b/src/vault/mem/local-buffer-store.hpp @@ -0,0 +1,53 @@ +/* + LOCAL-BUFFER-STORE.hpp - buffer memory handling with thread-local sub-services + + Copyright (C) + 2026 Hermann Vosseler + +  **Lumiera** is free software; you can redistribute it and/or modify it +  under the terms of the GNU General Public License as published by the +  Free Software Foundation; either version 2 of the License, or (at your +  option) any later version. See the file COPYING for further details. + +*/ + +/** @file local-buffer-store.hpp + ** Production-grade implementation of engine::BufferProvider memory handling. + ** + ** @see LocalBufferStore_test + ** @see buffer-provider.hpp + ** @see buffer-provider-protocol-test.cpp + ** @see simple-buffer-state-registry.hpp + */ + +#ifndef VAULT_MEM_LOCAL_BUFFER_STORE_H +#define VAULT_MEM_LOCAL_BUFFER_STORE_H + + +#include "vault/mem/buffer-provider-setup.hpp" +#include "vault/mem/buffhandle.hpp" ///////////////TODO +#include "lib/local-slice.hpp" +#include "lib/depend.hpp" + + +namespace vault { +namespace mem { + + + + /** + * @todo type comment + */ + class LocalBufferStore + : public BufferProviderSetup::Store + { + + public: + LocalBufferStore() + { } + }; + + + +}} // namespace vault::mem +#endif /*VAULT_MEM_LOCAL_BUFFER_STORE_H*/ diff --git a/src/vault/mem/local-mem-pool.hpp b/src/vault/mem/local-mem-pool.hpp new file mode 100644 index 000000000..6a1a5d8bb --- /dev/null +++ b/src/vault/mem/local-mem-pool.hpp @@ -0,0 +1,55 @@ +/* + LOCAL-MEM-POOL.hpp - working pool of buffer allocations for local reuse + + Copyright (C) + 2026 Hermann Vosseler + +  **Lumiera** is free software; you can redistribute it and/or modify it +  under the terms of the GNU General Public License as published by the +  Free Software Foundation; either version 2 of the License, or (at your +  option) any later version. See the file COPYING for further details. + +*/ + +/** @file local-mem-pool.hpp + ** A local cache of buffer allocations to facilitate reuse of memory in a worker. + ** + ** @see local-mem-pool-test.cpp + ** @see local-buffer-store.hpp + ** @see buffer-provider.hpp + ** @see buffer-provider-protocol-test.cpp + ** @see simple-buffer-state-registry.hpp + */ + +#ifndef VAULT_MEM_LOCAL_MEM_POOL_H +#define VAULT_MEM_LOCAL_MEM_POOL_H + + +//#include "vault/mem/buffer-provider-setup.hpp" +//#include "vault/mem/engine-buffer-metadata.hpp" +//#include "vault/mem/buffer-metadata.hpp" +#include "vault/mem/buffhandle.hpp" //////////////TODO +//#include "lib/local-slice.hpp" +//#include "lib/depend.hpp" + + +namespace vault { +namespace mem { + + + + /** + * Low-level Building block for Render Engine memory management. + */ + class LocalMemPool + { + + public: + LocalMemPool() + { } + }; + + + +}} // namespace vault::mem +#endif /*VAULT_MEM_LOCAL_MEM_POOL_H*/ diff --git a/tests/47engine.tests b/tests/47engine.tests index 5cac7d571..de0a389b5 100644 --- a/tests/47engine.tests +++ b/tests/47engine.tests @@ -77,6 +77,16 @@ return: 0 END +TEST "Local buffer memory handling" LocalBufferStore_test < + +  **Lumiera** is free software; you can redistribute it and/or modify it +  under the terms of the GNU General Public License as published by the +  Free Software Foundation; either version 2 of the License, or (at your +  option) any later version. See the file COPYING for further details. + +* *****************************************************************/ + +/** @file local-buffer-store-test.cpp + ** unit test \ref LocalBufferStore_test + */ + + +#include "test/run.hpp" +#include "test/test-helper.hpp" +//#include "vault/mem/engine-buffer-metadata.hpp" +#include "vault/mem/local-buffer-store.hpp" +//#include "lib/depend-inject.hpp" +//#include "lib/thread.hpp" +//#include "lib/error.hpp" + + +//using std::this_thread::yield; +//using lib::Thread; + +namespace vault { +namespace mem { +namespace test { + +// using LERR_(LOGIC); +// using LERR_(LIFECYCLE); + + + namespace { // Test helper + +// template +// Buff* +// mark_as_Buffer(X& something) +// { +// return reinterpret_cast (std::addressof(something)); +// } +// + } + + + + + + + /**************************************************************************//** + * @test verify worker memory handling that relies on a thread-local allocator. + */ + class LocalBufferStore_test : public Test + { + + virtual void + run (Arg) + { + seedRand(); + + verify_DataTransfer(); + verify_lulz(); + } + + + + /** @test */ + void + verify_DataTransfer() + { + } + + + + /** @test + */ + void + verify_lulz() + { + } + }; + + + /** Register this test class... */ + LAUNCHER (LocalBufferStore_test, "unit engine"); + + + +}}} // namespace vault::mem::test diff --git a/tests/vault/mem/local-mem-pool-test.cpp b/tests/vault/mem/local-mem-pool-test.cpp new file mode 100644 index 000000000..1146791cd --- /dev/null +++ b/tests/vault/mem/local-mem-pool-test.cpp @@ -0,0 +1,94 @@ +/* + LocalMemPool(Test) - verify low-level handling of buffer blocks in a local pool + + Copyright (C) + 2026, Hermann Vosseler + +  **Lumiera** is free software; you can redistribute it and/or modify it +  under the terms of the GNU General Public License as published by the +  Free Software Foundation; either version 2 of the License, or (at your +  option) any later version. See the file COPYING for further details. + +* *****************************************************************/ + +/** @file local-mem-pool-test.cpp + ** unit test \ref LocalMemPool_test + */ + + +#include "test/run.hpp" +#include "test/test-helper.hpp" +//#include "vault/mem/engine-buffer-metadata.hpp" +#include "vault/mem/local-mem-pool.hpp" +//#include "lib/depend-inject.hpp" +//#include "lib/thread.hpp" +//#include "lib/error.hpp" + + +//using std::this_thread::yield; +//using lib::Thread; + +namespace vault { +namespace mem { +namespace test { + +// using LERR_(LOGIC); +// using LERR_(LIFECYCLE); + + + namespace { // Test helper + +// template +// Buff* +// mark_as_Buffer(X& something) +// { +// return reinterpret_cast (std::addressof(something)); +// } +// + } + + + + + + + /**********************************************************************//** + * @test verify handling of prospective buffer allocations in a local pool. + */ + class LocalMemPool_test : public Test + { + + virtual void + run (Arg) + { + seedRand(); + + verify_blah(); + verify_lolz(); + } + + + + /** @test */ + void + verify_blah() + { + } + + + + /** @test + */ + void + verify_lolz() + { + } + }; + + + /** Register this test class... */ + LAUNCHER (LocalMemPool_test, "unit engine"); + + + +}}} // namespace vault::mem::test diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index c3f3a6a00..ce9a39b40 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -74191,7 +74191,8 @@ - + + @@ -104114,7 +104115,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + @@ -143866,8 +143867,9 @@ StM_bind(Builder<R1> b1, Extension<R1,R2> extension) - - + + + @@ -143876,9 +143878,10 @@ StM_bind(Builder<R1> b1, Extension<R1,R2> extension)

+
- + @@ -143887,6 +143890,8 @@ StM_bind(Builder<R1> b1, Extension<R1,R2> extension)

+ + @@ -143899,7 +143904,7 @@ StM_bind(Builder<R1> b1, Extension<R1,R2> extension) - + @@ -143908,6 +143913,8 @@ StM_bind(Builder<R1> b1, Extension<R1,R2> extension)

+ +
@@ -144148,6 +144155,7 @@ StM_bind(Builder<R1> b1, Extension<R1,R2> extension) +
@@ -144223,7 +144231,7 @@ StM_bind(Builder<R1> b1, Extension<R1,R2> extension) - + @@ -144238,7 +144246,7 @@ StM_bind(Builder<R1> b1, Extension<R1,R2> extension)

- +
@@ -144248,8 +144256,8 @@ StM_bind(Builder<R1> b1, Extension<R1,R2> extension) - - + + @@ -144300,7 +144308,7 @@ StM_bind(Builder<R1> b1, Extension<R1,R2> extension) - + @@ -144309,6 +144317,11 @@ StM_bind(Builder<R1> b1, Extension<R1,R2> extension)

+ +
+ + + @@ -144328,7 +144341,8 @@ StM_bind(Builder<R1> b1, Extension<R1,R2> extension) - + + @@ -144364,7 +144378,7 @@ StM_bind(Builder<R1> b1, Extension<R1,R2> extension) - + @@ -144405,13 +144419,18 @@ StM_bind(Builder<R1> b1, Extension<R1,R2> extension) - - + + - + + + + + - + + @@ -144488,7 +144507,7 @@ StM_bind(Builder<R1> b1, Extension<R1,R2> extension) - + @@ -144565,7 +144584,7 @@ StM_bind(Builder<R1> b1, Extension<R1,R2> extension) - + @@ -144584,12 +144603,13 @@ StM_bind(Builder<R1> b1, Extension<R1,R2> extension) - - - + + + + - + @@ -144636,16 +144656,129 @@ StM_bind(Builder<R1> b1, Extension<R1,R2> extension) - + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ ...was mich tatsächlich etwas verblüfft, aber es geht wohl grade glatt auf (und das bestätigt m.E. auch das API-Design) +

+ + +
+ +
+
+ + + + + + + + + + + + + +

+ dort gibt es die Syntax watch(blockFlow), für den Zugang zu einem Diagnostic-Wrapper, der als friend deklariert ist, aber im Prod-Betrieb einfach nicht vorhanden ist. Durch ein solches Schema kann man sich bis in kritische Details hinein das Verhalten eines production-Grade Memory-Managers anschauen, ohne spezielle Mocks und Stubs einsetzen zu müssen. +

+ + +
+
+ + + + + + +

+ Mit »zweite Ausbaustufe« meine ich, daß ein lokaler Pool da ist. Auch wenn dann später auch noch ein Austausch von Datenblöcken die direkte Allokation ergänzt. +

+

+ +

+

+ Demnach muß ich von Anfang an eine solche Pool-Struktur vorsehen, obschon er zu Beginn niemals passiv Speicher vorhält +

+ + +
+
+
+ + + + + + + +

+ Diese Komponente entspricht also den BufferMetadata im LocalBufferStage: es ist ein technischer Implementierungs-Service, auf dessen Basis das BufferStore-API durch Abstraktion realisiert werden kann +

+ + +
+
+ + + + + + + + + + + + +

+ in Ticket #1366 (und auch oben in der Mindmap) habe ich definiert, wie ein gutes Framework aussehen sollte. Aber das ist mehr eine Wunschliste — was gebraucht würde wäre ein Satz kohärenter Concepts, denn es geht grade nicht darum, eine einzige »Library-Implementierung« zu schaffen; vielmehr geht es darum, die diversen Library-Container und Frameworks so unter einen Hut zu bekommen, daß sie composable werden. +

+ + +
+
+ + + + + +
- - + + @@ -144716,8 +144849,34 @@ StM_bind(Builder<R1> b1, Extension<R1,R2> extension) + + + + + + +

+ Stand: bis auf weiteres bereits fertig +

+ + +
+ + + + + +

+ Das erscheint bereits elaboriert genug, um damit eine echte Render-Engine zu betreiben. Wobei festzuhalten ist, daß das genze Konzept mit den hierarchiscen Metadaten bisher eine »frei drehende Idee« ist, und einer gründlichen Kritik unterzogen werden sollte. +

+ + +
+
+
+ + - @@ -167563,7 +167722,7 @@ std::cout << tmpl.render({"what", "World"}) << s - +