feat(vulkan): run the compute/UI path without VK_EXT_descriptor_heap

Device::Initialize required twelve device extensions with no capability
check. Mesa Turnip (Adreno) lacks six of them: VK_EXT_descriptor_heap,
VK_KHR_shader_untyped_pointers, VK_EXT_device_fault and the three ray
tracing extensions. vkCreateDevice failed there, so not even a UI-only
program could start, although the UI path is compute-only and needs
nothing else that Turnip is missing.

The descriptor heap, ray tracing and device fault are now optional
groups, detected at start-up from the extension list and the feature
bits (Device::descriptorHeapSupported, rayTracingSupported,
deviceFaultSupported). Ray tracing needs the heap; on a device without
it the ray tracing entry points throw a message naming the cause.

Without the heap the same bindless slots live in one update-after-bind
descriptor set per frame, owned by DescriptorHeapVulkan: binding 0
storage images, 1 sampled images, 2 samplers, 3 storage buffers. Slot
allocation, the slot handles, UIDispatchHeader and the UIRenderer API
are unchanged; buffer slots simply stop being offset. Window::Render
binds that frame's set where it binds the heap, every compute pipeline
shares the heap object's pipeline layout, and push data travels as push
constants.

Each UI kernel is built twice from one source. ui-shared.glsl declares
its resources through UI_HEAP_* macros that expand to descriptor_heap
or, with CRAFTER_GRAPHICS_DESCRIPTOR_SETS defined, to set/binding.
<name>.comp.spv and <name>.comp.sets.spv ship side by side and
ComputeShader::Load picks one. The heap build of every shader is
byte-identical to before.

Breaking:
- ComputeShader::Load takes the heap as a second argument.
- DescriptorHeapVulkan is no longer copyable or movable.
- Custom UI shaders declare heap resources with the UI_HEAP_* macros
  and are registered twice in project.cpp (see the README).
- project.cpp uses Shader::defines and Shader::variant, so it needs a
  crafter-build that has them (Crafter.Build master, fe38cc1 or later).

Also:
- maintenance5 is enabled as a feature, not only as an extension:
  every VulkanBuffer already relied on VkBufferUsageFlags2CreateInfo.
- Barrier stage masks drop RAY_TRACING_SHADER on devices without ray
  tracing, and ImageVulkan::Create resolves its default consumer stage
  to COMPUTE_SHADER there.
- Window refuses a swapchain whose image count is not numFrames
  instead of writing past images[]. The limitation itself is #160.
- CRAFTER_GRAPHICS_NO_DESCRIPTOR_HEAP forces the fallback on a driver
  that has the heap, so it can be exercised on a desktop GPU.

Verified on an RTX 4090 in both modes under the validation layer, and
on a Fairphone 6 (Turnip, Adreno 810, postmarketOS), where the fallback
is the only path.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Jorijn van der Graaf 2026-10-06 17:28:46 +02:00
commit 48aa9be5ce
22 changed files with 912 additions and 110 deletions

View file

@ -833,7 +833,11 @@ void Window::Render() {
// whole pipeline, so the frame-edge barriers wait on exactly those stages
// instead of ALL_COMMANDS. Derived once here and reused for the present
// barrier below (passes don't change within a Render()).
const VkPipelineStageFlags swapWriterStages = SwapchainStageUnion(passes);
// Device::stageMask drops RAY_TRACING_SHADER on devices without ray
// tracing: the no-pass fallback and any un-narrowed pass report the
// conservative writer union, which names that stage, and a stage whose
// feature is not enabled is invalid in a barrier.
const VkPipelineStageFlags swapWriterStages = SwapchainStageUnion(passes) & Device::stageMask;
// dstAccessMask must only contain access flags supported by the dst stage
// mask (VUID-vkCmdPipelineBarrier-pImageMemoryBarriers-02820). Derive it
@ -856,7 +860,15 @@ void Window::Render() {
// buffer dictates GPU execution order, so the bind must come first.
// Pass-side dispatches still run with the same heaps bound — moving
// the bind earlier doesn't change anything for them.
if (descriptorHeap) {
if (descriptorHeap && !Device::descriptorHeapSupported) {
// Sets mode: the heap object holds one bindless descriptor set per
// frame instead of heap buffers. Every compute pipeline loaded against
// this heap shares its pipeline layout, so one bind here stays valid
// across all of them, exactly like the heap bind below.
vkCmdBindDescriptorSets(drawCmdBuffers[currentBuffer], VK_PIPELINE_BIND_POINT_COMPUTE,
descriptorHeap->pipelineLayout, 0, 1,
&descriptorHeap->sets[currentBuffer], 0, nullptr);
} else if (descriptorHeap) {
// Rebuild the cached per-frame bind structs only when the heap changes.
// The address/size of each frame's heap and the reservedRangeOffset
// bitmask are stable for a given heap, so this runs once per assignment
@ -918,8 +930,11 @@ void Window::Render() {
// serialises COMPUTE_SHADER while an RT pass on either side pulls in
// RAY_TRACING_SHADER — never the ALL_COMMANDS full-pipeline stall.
VkImageMemoryBarrier ib = BuildSwapchainInterPassBarrier(images[currentBuffer]);
// Masked like swapWriterStages above: a pass that keeps the
// default stage reports a union that names RAY_TRACING_SHADER.
vkCmdPipelineBarrier(drawCmdBuffers[currentBuffer],
passes[i]->SwapchainStage(), passes[i + 1]->SwapchainStage(),
passes[i]->SwapchainStage() & Device::stageMask,
passes[i + 1]->SwapchainStage() & Device::stageMask,
0, 0, nullptr, 0, nullptr, 1, &ib);
}
}
@ -1100,6 +1115,13 @@ void Window::CreateSwapchain()
}
uint32_t imageCount{ 0 };
Device::CheckVkResult(vkGetSwapchainImagesKHR(Device::device, swapChain, &imageCount, nullptr));
// images[] and every other per-frame array hold exactly numFrames
// entries. A driver may create more images than minImageCount asked for
// (a surface whose minimum is above numFrames must); writing them into
// images[] would run off its end, so refuse instead.
if (imageCount != numFrames) {
throw std::runtime_error(std::format("Window: the swapchain has {} images, but the frame loop is built for exactly {}", imageCount, numFrames));
}
// Get the swap chain images
Device::CheckVkResult(vkGetSwapchainImagesKHR(Device::device, swapChain, &imageCount, images));