At a resize RebuildSwapchain sent wp_viewport.set_destination for the
new size at once, and the configure listener, which had called it,
acknowledged the configure and committed the surface. The destination
is the surface's size, and it is state the next wl_surface.commit
applies whatever buffer is attached then. That commit was the
listener's, or the one a consumer makes to ask for a frame callback,
and it put the old frame at the new size, where it stayed until the
consumer's next frame brought a buffer of that size (#199). The
acknowledgement named that commit as the answer to the configure. And
the rebuild ran inside libwayland's dispatch: the consumer's loop stood
still in it, each new size before a frame cost a swapchain, and a
Vulkan error there was thrown from inside the dispatch, where the `try`
a consumer has around Update() does not cover it (#200).
Window: the configure listener keeps a new size (deferredLogicalWidth
and Height, surface-local) and, where a frame is owed, the serial
(unackedConfigure), and makes no Vulkan call. Render() takes what waits
at its two boundaries (RebuildIfDeferred) and makes the swapchain again
where that calls for one: first thing, for what came since the last
frame, and after its present, as before, for what its listeners and the
present asked for, and now for a size configured while they ran. Right
before its present a frame sends what the surface is to take with its
buffer (SendFrameSurfaceState): the destination, when the surface's
size is not the one last sent (sentLogicalWidth and Height), and the
acknowledgement of the configure it answers, the last one when several
came. The present's commit then applies them together with the buffer.
The constructor sends no destination: the window's first frame does.
The surface's size is state of the window for that, beside the buffers'
(logicalWidth and Height; logicalConfigured says which of the two sizes
the window was given). TakeDeferredSize makes a configured size the
surface's, unchanged, and works the pixels out of it with the scale of
that moment. MatchSizesToScale does the same before every swapchain is
made, and for a window the application sized (the constructor's size,
Resize) works the surface's size out of the pixels, which is what
RebuildSwapchain and the constructor did when they sent the
destination. The destination is that state as it is and not ceil(width
/ scale) at the present, because the scale is the compositor's to
change in any dispatch: between a configure and the frame that takes
it, and in the middle of a frame, when a listener reads the clipboard
or makes a window. And a size and a scale that change together can come
to the pixels the swapchain has: then no swapchain is made, and the
frame still brings the surface its size with the acknowledgement.
With that the destination of a configured size is the size itself,
where it was worked back from the pixels and could come out larger
(392x796 at 2.85 came back as 393x797), and a configure at the size the
surface has leaves a window the compositor sized alone while the scale
stays what it was, where it could make the window grow again (#201). A
window the application sized, configured at the size its surface has,
takes the pixels for that size once where its own do not come to it
(320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left
alone in the same way. That much of #201 comes with this change, since
the state it asks for is the one this needs. The buffers' size is still
rounded up, where the protocol rounds half away from zero: the rest of
#201.
A swapchain RebuildSwapchain made for another reason after the scale
changed (a present mode, a present that found the swapchain out of
date) applied the new scale by working the destination out again from
the pixels. It still does for a window the application sized. A window
the compositor sized keeps the surface's size and takes the pixels for
it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's
lines and sent no destination: it calls RebuildSwapchain now, and so
settles the two sizes as the other rebuilds do.
Of a Resize and a configured size the one asked for last is taken, as
when the listener resized on the spot: a configure with a size clears a
Resize that waits for its frame's present, also when its size is the
one the window has, and Resize clears a configured size that waits.
A configure that asks for nothing new while nothing is owed is
acknowledged in the listener, as before. One that comes while a size
waits, or while the surface does not show the window as it is (a
swapchain still to be made, one that has presented no frame yet, a size
not sent yet), waits for that frame. One for the size the window has,
when nothing else is owed, is acknowledged at once and takes the wait
away with it, as an acknowledgement of a serial older than the last is
a protocol error. A frame being recorded when a size comes does not
acknowledge it while that size waits; when a Resize later in the frame
takes the size's place, that frame does. The listener still commits,
which applies whatever else is pending on the surface, such as a
request for a frame callback that StartUpdate made after a frame.
For consumers: onResize for a compositor's resize fires from inside
Render(), before the onUpdate of the frame that brings the size, with
the queue idle and no frame being recorded, as Resize fires it; until
that frame the window keeps its old size on screen. A window that draws
on demand took onResize as its cue to ask for a frame, and gets
onFrameOwed for it: the Wayland backend's alone, fired from the
configure after onToplevelState, and only for a window that is still
there after that event's listeners, whenever the configure leaves a
frame owed. A size the surface does not have yet that comes to the
pixels the window has (the scale changed with it) fires onFrameOwed and
no onResize. Resize and SetPresentMode outside a frame rebuild at once
as they did, and there too the surface takes the new size with the next
frame. A rebuild that throws stays pending, since RebuildSwapchain
clears swapchainRebuildPending only once the swapchain is made, and the
next Render() tries it again. The README, the consumer notes and the
guide's gotchas say so, and the bug-prover lens section lists the
pending surface state and the scale among the re-entry contexts.
Examples: InputSystem and the native mains of VulkanTriangle, RTVolume
and Sponza drew one frame and then only ran the event loop, so nothing
would have answered a compositor's resize of their windows. They call
StartUpdate after that frame, as the examples that draw every frame do.
Not changed: a scale that changes by itself still reaches the buffers
and the surface only with the next swapchain or the next configured
size (#165); the first configure's size (#166); and Win32's WM_SIZE,
which still rebuilds from the window procedure. A window under
StartUpdate on the compositor's clock still draws from its frame
callback, so for it the rebuild, like every frame's Vulkan call, stays
inside libwayland's dispatch; one on its own clock is updated by
StartSync's loop after the dispatch, as before. #200 is answered for a
consumer that calls Update() itself. A present that fails after
SendFrameSurfaceState leaves what that sent pending for the surface's
next commit, whoever makes it.
Tests: ConfigureResize feeds the configure callbacks of a window whose
surfaces are proxies on a wl_display over a socketpair, as
ToplevelState does, with a made-up swapchain handle and no device,
steps the two ends of a frame, and reads the requests off the wire: a
configure for a new size sends one bare commit; the frame sends the
destination and the acknowledgement before its present, once; several
configures before a frame cost one of each, of the last serial; a
configure for nothing new, or back to the window's size, is
acknowledged in the listener, and the serial that waited never is; a
frame being recorded when a size comes does not acknowledge it while
the size waits, and does once a Resize has taken its place; the
window's first frame and the first at any new size of the surface bring
the destination, and a configure before it waits, and so does one for
the size a rebuild that threw is still pending for, and one that comes
after a present that found the swapchain out of date, whose surface
state is not sent a second time; without a viewport the acknowledgement
still waits. The destination is the configured size when the scale
changes before the frame, when it changes between the frame's start and
its present, and when the size and the scale together come to the
swapchain's pixels, in either order of the two events, which makes no
swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is
that size, and three more configures at it change nothing. A swapchain
made after the scale changed keeps a configured window's surface size
and an application-sized window's pixels. Of a Resize and a configured
size the later one is taken, also when it is the size the window has.
onFrameOwed fires after onToplevelState and not for a window its
listener destroyed; every acknowledgement names a later serial than the
one before.
ResizeViewport runs a window against the compositor with WAYLAND_DEBUG
set and stderr in a file, and replays the log, which has the driver's
attach and commit too: at every commit the destination in effect
belongs to the buffer in effect, to within a surface-local pixel, and
every acknowledgement of a configure that asked for a size, once the
surface has a buffer, is committed with a buffer of that size in effect
and with that size itself as the destination, through a Resize with a
commit before the next frame, a size the compositor configures (the
window asks to be maximized), and one it configures while the frame
loop of StartUpdate runs (the window asks to be restored), which that
loop takes and answers by itself. Where the compositor configures no
other size at that request, the step is a SKIP, and the test holds the
log to it: no configure for another size came. `ResizeViewport
--keyboard` is the manual probe for a phone: it asks for text input and
takes it back three times (SetTextInput), which is what brings a
phone's on-screen keyboard up and down, and holds the resizes that
makes to the same checks.
Window
- CreateSwapchain asked for exactly numFrames (3) images whatever the
surface said, read them into a three-element array, and keyed the
command buffers, the fences and the descriptor-heap copy holding "its"
swapchain image by the acquired image index. A swapchain of another
size fell back to FIFO (asked for MAILBOX or IMMEDIATE) or threw, and a
surface whose minimum is above three got a create info below it
(#160). Mesa's MAILBOX needs four images: Turnip on phoc, llvmpipe on
any Wayland compositor.
- The present mode is picked first, then the swapchain is sized by
SwapchainCapabilities: the surface's counts for that mode where the
instance has surface_maintenance1. With swapchain_maintenance1 the
swapchain names its mode (VkSwapchainPresentModesCreateInfoKHR), which
is what makes the mode's own count the one that applies, at creation and
to the forward progress of a UINT64_MAX acquire; without it the stricter
of the mode's and the surface's counts for all modes. It asks for
numFrames or that minimum where more, never past the maximum
(SwapchainMinImageCount). Turnip's FIFO keeps its three images and
MAILBOX gets four. The FIFO fallback and presentModeUnfit are gone.
- images, imageViewInfos (was imageViews: they are create-infos), the made
imageViews that descriptor sets take, imageInitialised and the
render-finished semaphores are per image, as many as the driver made.
The views are made once per swapchain. The semaphores only grow, since
a present of the old swapchain may still wait on one.
- Frames in flight stay numFrames, keyed by currentFrame, frameCounter %
numFrames: the command buffer, the fence, the acquire semaphore, the
heap copy (or set), RenderingElement3D::tlases, the frameIdx a pass is
recorded with. currentImage is the acquired image. currentBuffer is
gone, so code that used it stops compiling instead of picking the wrong
one; RenderPass::Record's frameIdx keeps its name and is now the frame
slot, as RenderPass.cppm says.
- The frame's fence is waited before the acquire. The acquire semaphores
need no spare then, and a frame waits for exactly the one numFrames
before it, which the deletion queue and the staging rings count on and
fences keyed by image did not promise once images come back out of
order. The swapchain slots are written before the fence is reset.
- From the acquire to the present the window is recording: a Resize or
SetPresentMode from a listener (a VSync key ticked in onUpdate) takes
effect after the present, through RebuildSwapchain, together with a
present that found the swapchain out of date. Rebuilding mid-frame used
to destroy the image the frame was drawing into; with images sized per
swapchain it would also index past the new one's end.
DescriptorHeapVulkan
- Frames and images pair up differently from frame to frame, so no heap
copy can keep one swapchain image. AddSwapchainSlot(slot, window) lists
an image slot as that window's swapchain image, and Window::Render
writes the image a frame acquired into its window's listed slots in that
frame's copy, or its set, before onUpdate, skipping a slot that holds it
already. A slot is one window's, so two windows can share a heap without
writing each other's slots under each other's frames in flight. A slot
listed during a frame its window records is written at once. A slot past
the heap's image slots, an empty ImageSlot's 0xFFFF among them, is
refused. Freeing a slot unlists it, as does initialising the heap in
either binding model. WriteImageSet, the one use of which this
replaces, is gone, and with it the per-frame dimension of setImageViews.
Device
- VK_KHR_surface_maintenance1 (or EXT) and VK_KHR_get_surface_capabilities2
are enabled where the loader has them (surfaceMaintenance1Supported,
vkGetPhysicalDeviceSurfaceCapabilities2KHR), and the matching
swapchain_maintenance1 with its feature where the device has it
(swapchainMaintenance1Supported).
- DistinctGpus groups the physical devices by GPU as CRAFTER_GRAPHICS_DEVICE
numbers them, for ChooseGpu and tests.
UI
- UIRenderer lists its output slot instead of writing every copy itself,
and again on every resize; the resize listener is gone on both
backends. The headers' frameIdx is currentFrame.
Examples
- VulkanTriangle, Sponza, SponzaBench and RTVolume list their output slot
and write only the per-frame TLASes. They wrote imageViews[f] into copy
f once, which a resize left pointing at destroyed images.
Tests
- SwapchainImageCount: SwapchainMinImageCount on the numbers drivers
report; every offered mode keeps its mode and gets what the window asks
for; every frame presents the colour it drew, read back a texel per
frame; a switch and a resize asked for during a frame wait for its
present; a slot listed during a frame holds its image at once; two
windows on one heap draw their own colours. The frame checks run again
in child processes, through CRAFTER_GRAPHICS_DEVICE, on a GPU whose
swapchains have more images than frames (this one, else llvmpipe), in
each binding model the parent didn't cover; a child skips only for a GPU
that can't run the library, and checks it runs the model it was asked
for.
- FrameLoopSync checks the frame slot follows the frame counter and counts
the swapchain's own images. HeapASRead, HeapDynamicIndexHit and
RTPassPushData list their swapchain slot and drop their resize rewrites.
Docs
- README, AGENTS.md and AGENTS.consumer.md: frames and images, the
swapchain slots, rebuilds held to the present, the new optional groups.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
examples/Sponza no longer built natively (#164). Its closest-hit declared a
descriptor_heap sampler2D, which glslang has rejected since c8253623
("Reject descriptor_heap combined image samplers"), and main.cpp wrote it
through VkResourceDescriptorDataEXT::pCombinedImageSampler, which that union
no longer has: the descriptor heap has no combined image samplers. Both went
unnoticed because nothing builds the examples.
Sponza
- closesthit.glsl declares texture2D and sampler heap arrays and joins them
where it samples, as ui-shared.glsl and HeapDynamicIndexHit do. The
sampler slot is a second spec constant beside the image slot, so the
shader assumes nothing about where the host put it, and a constant index
keeps the example running on NVIDIA 610.43.02 (see its README). The
comment no longer says the image slot is offset by bufferStartElement;
only buffer slots are.
- main.cpp gives the heap a sampler slot, writes the albedo as a
SAMPLED_IMAGE from a view create-info, and writes the sampler into the
sampler heap from a VkSamplerCreateInfo with vkWriteSamplerDescriptorsEXT,
as UIRenderer::RegisterSampler does. SamplerVulkan's VkSampler had no use
left. The sampler keeps its linear filtering and repeat addressing and
drops anisotropy, which a hit shader cannot use: it samples at LOD 0,
without derivatives.
Docs
- README.md and examples/Sponza/README.md quote the new declarations, and
the Sponza README says why the texture and the sampler are two
descriptors. Its texture2DArray materials pattern declared a
descriptor_heap sampler2DArray, which glslang rejects as well; it now
joins a texture2DArray and a sampler.
- examples/SponzaBench/README.md drops its caveat that Sponza does not
compile.
Tests
- ExampleShaders compiles every GLSL shader under examples/ with glslang as
crafter-build does for the example (Vulkan rules, SPIR-V 1.4, shaders/ on
the include path, and the descriptor-set build where the example
registers one), so a glslang that starts rejecting one fails a test
rather than an example build nobody runs. It fails on Sponza's old
closest-hit and needs glslang only.
Closes#164.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Device
- Device::Initialize(required, optional) takes DeviceFeatures, the five
core feature structs vulkan10 to vulkan14. The library enables only what
its own shaders and code use. Device::enabledFeatures says what was
enabled, supportedFeatures what the GPU has, apiVersion the version in
use.
- shaderInt16, shaderFloat16, storageBuffer16BitAccess, scalarBlockLayout
and the uniform-buffer, storage-buffer and storage-image non-uniform
indexing bits are no longer enabled for everyone. An application whose
shaders take uint16_t spec constants passes
{.vulkan10 = {.shaderInt16 = VK_TRUE}}. scalarBlockLayout stays on with
the NVIDIA workaround, whose TLAS address may sit in a struct's tail
padding.
- Every GPU is weighed before one is chosen: Vulkan 1.3, the swapchain and,
below 1.4, maintenance5 extensions, the library's needs, the required
features. One that can't run the application is skipped, saying why when
it ranks higher. A CPU device runs it only when nothing else is listed,
and CRAFTER_GRAPHICS_DEVICE never falls back. A GPU two drivers both list
is tried through each.
- When no GPU qualifies, Initialize throws naming each GPU's gaps. It
destroys the instance it made, before any Wayland connection, so it can
be called again asking for less.
- maintenance5 is vulkan14's on a 1.4 GPU and VK_KHR_maintenance5's below.
CRAFTER_GRAPHICS_NO_VULKAN_1_4 runs as a 1.3 application, to exercise
that path on a 1.4 GPU.
- VK_KHR_spirv_1_4 and VK_KHR_shader_float_controls, core since 1.2, are no
longer enabled, nor VK_EXT_shader_atomic_float, which was enabled without
its feature struct. memoryDecompression's feature bit is queried before
it is enabled.
Shaders
- VulkanShader checks a module's capabilities, declared directly or
implicitly, against the enabled core features, the GPU's subgroup
operations and the optional groups, and throws naming the field to pass,
or saying the GPU lacks it. The tables are generated from vk.xml and
SPIR-V's grammar.
- WorkaroundNvidiaAS::Patch sized a row-major matrix push member by its
columns, so the TLAS address could land inside it.
Window
- The swapchain format is one whose own feature flags allow storage reads
and writes without a format, which since Vulkan 1.3 each format says for
itself; shaderStorageImageRead/WriteWithoutFormat are no longer required.
Tests
- DeviceFeatures: ResolveFeatures, ChooseDevice and CheckShaderCapabilities,
without a GPU.
- FeatureRequests: required and optional features end to end, the 1.3
path, and a retry after a refusal.
- PushConstantRewrite: a row-major mat3x4 push member.
- HeapASRead, HeapDynamicIndexHit, RTPassPushData and the ray-tracing
examples ask for the features their shaders use.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds the minimal WebGPU-backend surface an HDR bloom/post chain needs:
1. wgpuCreateStorageImage2D + StorageImage2D<>: runtime rgba16float (or
other format) textures with STORAGE_BINDING|TEXTURE_BINDING usage, no
CompressedTextureAsset upload — GPU-produced HDR targets.
2. UICustomBindingKind::StorageTexture (kind 5): write-only storage-texture
binding carrying a texel format (the freed UICustomBinding::format byte),
wired through all three binding paths (UI custom / RT / plain compute).
Float textures already sample via SampledTexture (sampleType float).
3. PipelineRTWebGPU::Init(..., hdrOutputFormat): RESOLVE writes the linear
accumulator into a user rgba16float texture (RTPass::outTexHandle)
instead of the rgba8unorm canvas, leaving the composite→swapchain pass to
the app. Default RGBA8Unorm keeps the canvas path byte-identical.
Existing RT examples updated for the _pad→format field rename; the default
paths are unchanged (verified RTStress builds + renders).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Restructure Sponza for the wavefront model: raygen emits the primary ray;
closesthit (in SHADE) gathers albedo/normal, accumulates ambient, and
emits a shadow ray carrying the pending direct term; miss adds the sky
(primary) or the direct term (shadow miss). resolve.wgsl applies the same
Reinhard+gamma the megakernel raygen did inline. User bindings moved to
group 3 (groups 0..2 reserved). RTPass maxDepth=2.
Renders the atrium correctly through the wavefront pipeline (textures,
two-sided shading, sun+ambient, shadows, tonemap).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>