Skip to content

BufferManager: static vtable for the backends, plain functions for the shared base - #34

Merged
resetius merged 1 commit into
masterfrom
objmodel-buffer
Nov 7, 2026
Merged

resetius merged 1 commit into
masterfrom
objmodel-buffer

Conversation

@resetius

@resetius resetius commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

PRs 31–33 are merged; review only the last commit.

Part of the object model change from the tracker task: one vtbl pointer per object to a static const method table, like a C++ vptr.

BufferManager had three levels: the interface with 9 function pointers, BufferManagerBase (shared buffer array) that filled get, destroy, acquire, free, and the OpenGL/Vulkan managers that filled the rest. The base methods were never overridden, so they are plain functions now.

What changed:

  • render/buffer.h: new struct BufferManagerVtbl with the backend methods only: create, update, update_sync, read, release. struct BufferManager now holds only const struct BufferManagerVtbl* vtbl.
  • Call helpers (one-line macros): buffer_create and buffer_update (same names as the old wrapper functions, so their 33 callers do not change), plus buffer_update_sync and buffer_read.
  • render/buffer.c: the base methods are plain functions buffer_get, buffer_destroy, buffer_acquire, buffer_mgr_free (the old static functions without the trailing underscore). buffermanager_base_ctor only sets the element size. release is still called through the table.
  • opengl/buffer.c and vulkan/buffer.c: one static const struct BufferManagerVtbl buffer_vtbl each. Vulkan still has no read (NULL, as before; not implemented there).
  • Callers: models, font/font.c, and buffer_get in both pipeline backends.

No behavior change.

Verification (macOS, AppleClang, CMake + Ninja):

  • Clean rebuild: no new warnings (the same 5 as on master: one in contrib/astc-codec, four from glslc).
  • ctest: 3/3 passed.
  • Vulkan demos with VK_LAYER_KHRONOS_validation (layer load confirmed with VK_LOADER_DEBUG=layer), 10 s each: particles3, mandelbrot, stl, 0 validation messages.
  • Local test build of main.c (not in this PR): at frame 30 it sends key presses and releases for LEFT, RIGHT, UP, DOWN, A, Z, TAB and two mouse moves through the normal GLFW callbacks, then leaves the main loop after 8 s, so all free functions run. Vulkan particles3, mandelbrot, stl, gltf, triangle, torus, mandelbulb, particles, particles2 and OpenGL mandelbrot, stl, torus, triangle, mandelbulb, particles2: all exit with code 0. The logs are the same as on master after removing timings, FPS and pointer values (same buffer allocations, same validation output). On master, stl, gltf and triangle already report leaked objects at vkDestroyDevice (one message each); nothing else is reported.

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Test Results

9 tests  ±0   9 ✅ ±0   0s ⏱️ ±0s
3 suites ±0   0 💤 ±0 
3 files   ±0   0 ❌ ±0 

Results for commit e56e8ee. ± Comparison against base commit 02aa325.

♻️ This comment has been updated with latest results.

@resetius

resetius commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Independent review of head 060f8cc

Verdict: approve. One P3.

  • Virtual (vtbl): create, update, update_sync, read, release. Non-virtual plain functions from render/buffer.c: buffer_acquire, buffer_get, buffer_destroy, buffer_mgr_free. This matches what both backends actually did: they only ever overrode these five, and get/destroy/free/acquire were always set by buffermanager_base_ctor. The ctor no longer writes iface; both backends set iface.vtbl right after calling it, before the manager is used.
  • OpenGL vtbl: all 5 members. Vulkan vtbl: create, release, update, update_sync, no read, same as the old assignments (and commented in the code). The internal call b->iface.vtbl->release(...) in buffer_destroy is unchanged in meaning.
  • Call sites: all t->b->create/update/update_sync/read/free in models and font converted, plus ->get in both pipelines. No stale ->b-> call remains (only a commented-out line in font/font.c:274).
  • P3: buffer_read has no NULL check, so calling it on the Vulkan manager dereferences NULL. This is identical to the old behavior (NULL function pointer), so not a regression; the optional-method rule from the spec could be applied here later.

Build: clean CMake+Ninja (Release, -Wall -Wextra) of this head on a fresh SSH clone with submodules: builds, 98 warnings, identical set to master (no new warnings); ctest 3/3 passed.

@resetius

resetius commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Restacked on the updated PR 33; review only the last commit

@resetius

resetius commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Restacked onto master eff69ca after PR 29

@resetius

resetius commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Restacked onto master b76fe0a after PR 30.

@resetius

resetius commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Restacked onto master a33ca6c after PR 31.

@resetius

resetius commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Restacked onto master 4a501de after PRs 31–32.

@resetius

resetius commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Restacked onto master 02aa325 after PRs 31–33.

@resetius
resetius merged commit dc5812a into master Nov 7, 2026
2 checks passed
@resetius
resetius deleted the objmodel-buffer branch November 7, 2026 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant