Skip to content

cgfw events, timgui, stage graph submissions and the Presenter - #3

Open
codethinki wants to merge 68 commits into
masterfrom
_input/events
Open

codethinki wants to merge 68 commits into
masterfrom
_input/events

Conversation

@codethinki

@codethinki codethinki commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Work branch for input, ImGui and the frame flow of jvk: cgfw events, timgui, the submissions of the stage graph and the Presenter.

  • cgfw: window events, keys, axes, text and focus (window.events())
    • RGFW on current upstream with our fixes, cgfw initializes RGFW for the first window
  • timgui: ImGui and ImPlot on jvk and cgfw
    • persistent vertex and index buffers per frame slot, no buffer and no map per frame
  • jvk stage graph:
    • the jobs of the graph are submissions, a submission waits for the gpu only to free something
    • submit() and skip() store their failure, nextFrame() rethrows it, no implicit skips
    • a failed skip in ~StageGraph() logs and terminates
    • the present is a use of the image in the epilogue of the present stage, another queue family of the last use is handed over
  • jvk Presenter: one per swapchain, it orchestrates the acquire, the present and the drop of its images
    • the acquire tries vkAcquireNextImageKHR with timeout 0 in the strand, else the fallback on a driver thread
    • the presents follow the acquire order, a dropped image is reused, the presenter owns the ready points
    • the presenter tracks the pending present fences, cvk waits on no fence
    • Surface, jvk::Swapchain and Presenter know no graph, Frame::acquire() is the bridge
    • removed: PendingPresent, dev::PresentState, the present groups of the graph
  • cvk:
    • Swapchain without acquired tracking and without presented()
    • an acquire from a retired swapchain is invalid (VUID-vkAcquireNextImageKHR-swapchain-01285), a failed recreate gives no image until the next recreate
  • SamplerHeap has the lifecycle of ResourceHeap, Core holds it without std::optional
  • cth: co::all() with std::execution::seq or par (feat(coro): co::all() with std::execution::seq or par, par by default cth#36), counter_event, catching_scope (feat(coro): counter_event, catching_scope, fewer allocations in all() and detach, foreign thread shutdown, CTH_CRITICAL_MODE cth#34)
  • demos: the cube demo has a scene stage and a UI stage that record at the same time, and a frame time window
  • tests: no death tests
  • headless sway, mailbox, XRay: median frame 0.511 ms -> 0.42 ms, slow frames 10.7 % -> 5 %, the ImGui draw 0.104 ms -> 0.03 ms

- lib/rgfw: our fork on upstream main, with the fixes upstream still needs
- RGFW no longer initializes in createWindow: the first cgfw window calls RGFW_init with Vulkan, the last one RGFW_deinit
- FULLSCREEN is RGFW_windowFullscreenBorderless, the old meaning
- rgfw.cmake: pointer-warp protocol, advapi32, dl, the Vulkan platform defines for the surface types in RGFW.h
@codethinki
codethinki marked this pull request as ready for review November 21, 2026 13:34
@codethinki
codethinki marked this pull request as draft November 21, 2026 13:34
- Window::events(): the input events of the last pollEvents() as cgfw::window_event (cth::io::key_update, cth::io::axis_update, TextEvent, FocusEvent)
- keys by position with the character of the layout (RGFW_physicalToKeyChar of our fork), mouse buttons as keys
- the OS time of the events as steady_clock time points
- RGFW_MAX_EVENTS 1024: a full queue drops events
…face functions, window list, scroll

- lib/rgfw: six fix branches of our fork, each off upstream for later PRs
- rgfw.cmake: no Vulkan platform defines, RGFW.h keeps the Vulkan platform types in its implementation now
…me time

- Imgui: one per window, owns the ImGui and ImPlot contexts, the pipeline and the ImGui textures
- frame() and Frame::render(), the input of window.events(), letters and digits by the layout
- upload() and draw() for primary and secondary command buffers, the textures ready to sample before the rendering
- the shaders compiled into the library, vertex pulling, sRGB targets get linear vertex colors
- the SDK is needed for the validation layers anyway, it has glslc
- the Windows CI installs the latest Vulkan SDK
- README and AGENTS.md name the SDK (Windows) and the system packages (Linux)
…r compile

- lib/cth_cmake: GLSL language (codethinki/cth_cmake#11), glslc.cmake removed
- timgui, demos, cvk and jvk tests: shaders in OBJECT libraries, the includes come from target_include_directories
- demos and tests read the .spv files from the object folder, no copy
- cvk: Shader::compile() and the compile constructor removed, the tests load SPIR-V of the build
- jvk tests: no committed SPIR-V
…tch resolved

- jvk command buffers: base constructor, create(), wrap(State), release(), destroy(), State with the pool and the command buffer
- cvk::Swapchain: PresentFence -> WaitingFence, no deleted copy members in the wrappers
- the accepted //TODO review markers removed, their reasons stay as comments where the code does not show them
…rceTracker, barrier scopes without queue family

- jvk::Queues removed: the queues are a std::vector<Queue> of jvk::Core, Queue moves
- ResourceHeap, TimelineReactor, SamplerHeap: standard lifecycle or = default moves, the mutexes behind std::unique_ptr
- ResourceStates -> ResourceTracker, images() gives ImageMip
- nextFrame() awaits the old frame with cth::co::all
- cvk::BarrierScope without queue family: the families are fields of the image and buffer barrier infos, memory barriers are VkMemoryBarrier2, no QueueTransition() factories
- ReleasingImage, Window::destroy(RGFW_window&), Semaphore::onSubmitted(), scoped_acquire without uncaught exceptions
- the accepted //TODO review markers removed
…nt (codethinki/cth#34)

- jvk::Semaphore: no mutex, no std::unique_ptr, no waiter vector, the moves stay = default
- submitted_awaiter, onSubmitted() and the double post through the workers removed
…Queue call outside Queue

- submit(): vkQueueSubmit2 in the strand, then the marks of the jvk signals; a failed submit marks nothing
- present(): submit and vkQueuePresentKHR in one strand job, then the marks: the present order stays
- the graph: dev::SlotSubmit builds the jvk::SubmitInfo, the fallback submit goes through Queue::submit()
- the presenter: an out of date present shows in the next acquire(), no flag written after the mark
- the cvk core and the workers behind std::unique_ptr: the reactor and the heaps refer to them from the base constructor on
- the moves are = default, a created core neither moves nor takes a move assignment
…precompiled headers

- direct mode keys on the headers of clang -H, -H does not list the headers of -include
- CMake includes the precompiled header with -include: a changed header still gives a cache hit
- buildcache 0.31.7 of the Windows CI has direct mode on by default, the Linux image has it off
- removes the TEMP diagnosis steps of 9912c15
…r again

- the present job stores VK_ERROR_OUT_OF_DATE_KHR of Queue::present() in the atomic _outOfDate
- the store comes after the mark: the next acquire() can miss it, a later one recreates the swapchain
- no extra sync: acquire() keeps its wait on the mark of the last present
- before: the result was ignored, a driver that reports out of date only at the present with the same
  extent never got a recreation
…on the MSVC STL

- std::bit_width() returns int, the designated initializer of mipLevels narrows it to uint32_t
- the MSVC STL takes a non-constexpr intrinsic path outside a manifestly constant evaluated context:
  the call is no constant there, clang rejects the narrowing
- TEXTURE_MIP_LEVELS uses cvk::mip_level_count(), its initializer is manifestly constant evaluated
…the submit of its stage

- Surface::acquire(acquireStage, presentStage): the wait for the acquire in the first, the present
  after the submit of the second, returns std::optional<SwapchainImage>
- the present stage owns a dev::PendingPresent: presented by its submit job, dropped on a skip
- the end barrier goes into an epilogue command buffer, recorded after append(): no extra submit
- the submit job presents by the queue of the surface: with its own submit, present-only, or after
  a transfer of the acquire half; several surfaces present after one stage
- removed: scoped_acquire, Presenter::present(), the present jobs, the semaphore and command
  buffers of the surface
- per frame (headless MAILBOX, 2 workers): vkQueueSubmit2 2 -> 1, operator new 14 -> 10.5,
  mutex locks 26 -> 20
…rs are non-const

- submit(), present() and transfer() change the queue: they are non-const, the 11 mutable
  qualifiers are gone
- Core::queue() with deducing this: Queue& from a non-const core, Queue const& from a const one
- the holders that submit keep a Queue&: the stage slots, Surface, PendingPresent, skip_submit()
…or a quirk

- AGENTS.md: docs are for the users of the API
- cvk, jvk, cgfw, timgui: the docs of private members, anonymous namespaces and module-only dev::
  helpers removed, a // comment kept where it states a quirk (a lock, an order, a lifetime)
- the // comments on private declarations from 807efaf are ///< or /** */ docs, as everywhere
- comments inside function bodies stay //
- AGENTS.md: private members and module helpers get a doc only for a quirk the code cannot say
…cquire stage

- StageGraphConfig::waitsFor(): a wait in the same frame, directly or through other stages
- a CTH_CRITICAL in acquire(), the @pre stays in the docs
- [[gnu::pure]] on the recursive walk: gcc and clang drop it in release
… again

- reverts 2393ad7: a member function that exists only for a check makes it no normal check
- the @pre in the docs of acquire() stays, the cheap checks stay
…e gpu only to free something

- submitJob() is submission(), detachJob() is detachSubmission(), _jobs is _submissions, the
  parameters and docs follow
- the gpu wait and the cleanup run only if the submission retained images, buffers or stasis
  entries, then as early as before; else the submission ends after its submit
- Stasis::empty(pos): nothing before the position to clear
- per frame (headless MAILBOX, 2 workers): mutex locks 18 -> 14
…mplicit skips

- StageGraph::submit(), StageGraph::skip() and the Stage forms are noexcept
    - a failure stays in the graph, the stage stays UNSUBMITTED
    - the next nextFrame() rethrows the failure
- scoped_submit(Stage&): normal end -> submit(), exception -> skip()
- nextFrame() skips nothing
    - its first statement rethrows a stored failure
    - a debug check: every stage of the frame before is submitted or skipped
- ~StageGraph() skips the stages that are still UNSUBMITTED, their waiters go on
- a failed present goes to its surface, the next Surface::acquire() rethrows it
- one path for the submit and the skip of a stage
- the review markers go, the transfer counter probe stays
- the demos skip the stage when acquire() gives no image
- tests: test::fail_next_allocation(), a failed submit, a failed present, an exception
  through scoped_submit
- the stage got no submission: its waiters and _submissions.wait() would hang without a message
- the same handling as dev::skip_submit()
- a death test with a failed allocation of the skip
- removes the death tests of ~StageGraph(), Surface::acquire() and DescriptorSpan
- nothing replaces them
…hout std::optional

- base constructor, cvk::create form, create(), destroy(), optDestroy(), created()
- Core creates it with sampler counts, destroys it before the resource heap
- destroy() of both heaps: every handle and every Stasis with a cell of the heap is destroyed
- insert() and mappings() of both heaps: @pre created(), vk() has no @pre
- lifecycle tests like the ResourceHeap ones
… stage

- the epilogue uses go through append(): another family of the last use -> the last queue releases the image, the epilogue acquires it
- presentBarriers() only releases to the family of the surface queue, in a second barrier after the epilogue uses
- StageSlot::presentStates removed: the state before the release is PRESENT_STATE
- Surface::acquire(): the @pre "the last use is on the family of the present stage" removed
- Surface::acquire(): the present stage waits for every stage of the frame that uses the image
- test: a present stage of another family without a use of the image
- scene stage: waits for the acquire, the cube into the multisampled targets, resolved into the image
- ui stage: waits for the scene stage, ImGui in its own rendering that loads the image, presents
- timgui renders with one sample and no depth
- the two recordings are two tasks of one cth::co::all()
- no image: both stages skip
…cord at the same time

- lib: cth on feat/all-policy, co::all() takes std::execution::seq or par, par by default
- StageGraph::nextFrame(): both all() calls with seq, the children only wait
- cube demo: the default par posts record_scene(), record_ui() runs inline
… strand first

- Queue::tryAcquire(): vkAcquireNextImageKHR with timeout 0 in the strand, serialized with the presents
- Surface::acquire(): the try first, VK_NOT_READY, a new extent or out of date -> the fallback outside the strand
- //TEMP the try runs only after the resolve of the last image: the present state holds one image
- the Presenter replaces it in its step 2
…nd drop

- acquire(): a spare first, else the try in the strand, else the fallback on a driver thread
- the fallback blocks only within imageCount - minImageCount acquired images (VUID-01802)
- present(): in acquire order, never throws, the next acquire() rethrows the first failure
- drop(), drop(ready): instant, the image becomes a spare
- Image: move-only, its destructor drops it
- the destructor releases the spares, finished() tells when that is allowed
- cvk::Swapchain::surface()
- not used yet: jvk::Swapchain, Surface and StageGraph switch over in step 2
- removed: _acquired (std::vector<bool>), both acquired() overloads, the two CTH_CRITICAL checks, the writes
- the validation layers check the acquired images (VUID-VkPresentInfoKHR-pImageIndices-01430)
- jvk::Swapchain destroys a retired swapchain on presented() alone: no image of a retired swapchain is acquired
- jvk::Swapchain::recreate(): @pre no image of the current swapchain is acquired
- tests: hooks of the device table in place of acquired()
- an acquired swapchain image while the engine holds it, handed back exactly once
- the friend comment: the presenter owns the acquired image
- one mapped vertex and index buffer per frame slot of the graph of the stage, no map per frame
- write_lists() copies into the mapped memory, flushes the written range
- a buffer too small -> a new one with std::bit_ceil(count) elements replaces it at once, never shrinks
- Imgui::draw() is no longer const, @pre at most one draw() per frame, the stages of one graph
- removes the two speeds of the draw: a new buffer, a map and a free in every frame
- jvk::Swapchain holds a cvk::Swapchain and its Presenter per swapchain, current and retired
- a retired entry is destroyed once its Presenter::finished(), its images are erased in the graph then
- a failed recreate retires the old swapchain: no acquire until the next recreate (VUID-01285)
- Surface::acquire() is the bridge: the presenter's acquire, the stage wait, the assume, Stage::present()
- the submission of the present stage presents after its submit, a skip drops the image with its ready point
- another family: the epilogue releases, Queue::transfer() acquires and signals the present semaphore
- removed: PendingPresent, dev::PresentState, the present groups of StageGraph, Queue::tryAcquire(), the try of Surface
- Queue::present(): one image, no batching of swapchains
- docs: an acquire from a retired swapchain is invalid (VUID-01285), not VK_ERROR_OUT_OF_DATE_KHR
…on none

- cvk::Swapchain keeps the present fences but waits on none: present() resets, destroy() has @pre no fence pending
- cvk::Swapchain::presented() and WaitingFence removed: no wait or throw in a destructor on VK_ERROR_DEVICE_LOST
- jvk::Presenter: a fence is pending once its present is enqueued, VK_SUCCESS, VK_SUBOPTIMAL_KHR or a rejected but enqueued error
- a present that was not enqueued leaves no fence pending: the next present of the image and the teardown do not hang
- Presenter::waitPresents(), jvk::Swapchain::destroy() waits for the pending fences
- Surface, jvk::Swapchain and Presenter know no graph and no stages
- Presenter owns the ready points: one timeline semaphore per image, the value is the acquire number
- the present stage signals the ready point in its submit and its skip, drop() takes no ready point
- the graph erases the state of an image right before its present or drop, no erase at the retirement
- Frame::acquire(Surface&, Stage&, Stage&): the surface acquire, the stage wait, the assume, Stage::present()
- Surface::acquire() takes no stages and returns the AcquiredImage, the demos use frame.acquire()
@codethinki codethinki changed the title input: cgfw events and timgui cgfw events, timgui, stage graph submissions and the Presenter Nov 25, 2026
@codethinki
codethinki marked this pull request as ready for review November 25, 2026 10:16
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