Crafter.Graphics/examples/SponzaBench
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Jorijn van der Graaf bcdc885de8
feat(device): applications ask for the device features their shaders use
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>
2026-10-31 06:40:02 +01:00
..
closesthit.glsl SPDX license update 2026-07-22 18:09:06 +02:00
main.cpp feat(device): applications ask for the device features their shaders use 2026-10-31 06:40:02 +01:00
miss.glsl SPDX license update 2026-07-22 18:09:06 +02:00
project.cpp SPDX license update 2026-07-22 18:09:06 +02:00
raygen.glsl SPDX license update 2026-07-22 18:09:06 +02:00
README.md docs: where the NVIDIA descriptor-heap faults stand on 615.78.08 2026-10-19 03:03:17 +02:00
run-bench.sh SPDX license update 2026-07-22 18:09:06 +02:00

SponzaBench — measuring the post-#40 performance work

This example exists to answer issue #155: starting with #40 a lot of performance-related issues were merged — what is the net performance gain, measured in a representative scene (Sponza)?

It is a headless benchmark harness built around the native Vulkan Sponza ray-tracing scene. Same asset bundle and camera as examples/Sponza, but instead of opening an interactive window it times the work and prints machine-readable BENCH … lines, then exits.

What it measures

  • setup — process start through the first command submission: asset decompression, BLAS build per mesh group, the multi-instance TLAS, the RT pipeline, GPU memory placement and the descriptor writes. This is the window most of the post-#40 native perf work acts on.
  • frames — a warmup followed by a measured loop calling Window::Render(), reporting per-frame wall-clock stats and throughput.

Unlike the interactive Sponza example — which is single-material on native because of the hit-shader dynamic-descriptor_heap-index driver fault, fixed in NVIDIA 615.78.08 (see examples/Sponza/README.md) — SponzaBench's closest-hit shades from barycentric coordinates and samples no texture, so it can build the full multi-mesh atrium (25 mesh groups, ~262 k triangles) as one multi-instance TLAS. The albedo is still decompressed and uploaded during setup (to keep that path in the measurement) but is not bound.

Running

cd examples/SponzaBench
crafter-build                       # native Vulkan
# from the produced bin dir:
VK_LOADER_LAYERS_DISABLE='~all~' \
CRAFTER_PRESENT_IMMEDIATE=1 \
BENCH_WARMUP=200 BENCH_FRAMES=2000 BENCH_MESHES=25 ./SponzaBench

run-bench.sh <bindir> <label> <meshes> <reps> [--cold] runs it N times and reports the median / min / max of each metric.

Environment knobs:

var effect
CRAFTER_PRESENT_IMMEDIATE=1 uncapped present mode — without it FIFO pins frame time to the compositor's vblank (~60 Hz) and steady-state throughput can't be seen.
VK_LOADER_LAYERS_DISABLE='~all~' disable the validation layer. The engine enables Khronos validation and GPU-assisted validation unconditionally; that adds large, version-dependent overhead and must be off for a representative measurement.
BENCH_WARMUP / BENCH_FRAMES warmup and measured frame counts (default 200 / 2000).
BENCH_MESHES cap on mesh groups loaded (default: all 25). A small cap shrinks GPU work so per-frame CPU cost dominates; the full scene is GPU-traversal bound.
BENCH_CLEAN_EXIT=1 exit via std::exit (runs atexit, which writes the #69 pipeline cache) instead of the default hard _Exit. Used once to seed pipeline_cache.bin for a warm-cache measurement.

Results — #40 vs current master

Measured on this repo's CI box: NVIDIA RTX 4090, driver 610.43.02, 1280×720, validation disabled, IMMEDIATE present, 200 warmup + 2000 measured frames, median of 9 runs. "#40" is commit 1451e3a (the #40 merge); "HEAD" is current master. The same SponzaBench sources were built against each library revision (a git worktree at #40).

Full atrium — 25 meshes / ~262 k triangles (GPU-traversal bound)

metric #40 HEAD Δ
setup (cold) ms 322.7 316.6 −1.9 %
setup (warm pipeline cache, #69) ms 322.7¹ 313.9 −2.7 %
throughput fps 7 560 7 637 +1.0 %
frame time p50 ms 0.1311 0.1298 −1.0 %
peak host RSS (cold) MB 336.0 344.2 +2.4 %
peak host RSS (warm cache) MB 336.0¹ 332.0 −1.2 %

¹ #40 predates the disk pipeline cache (#69), so its setup is always the cold-compile path.

Light scene — 1 mesh (deliberately CPU-bound)

metric #40 HEAD Δ
throughput fps 15 022 15 237 +1.4 %
frame time p50 ms 0.0662 0.0650 −1.8 %

Interpretation

The net measured gain in a static Sponza RT scene is small: ~1–2 % faster frames, ~2–3 % faster setup, and roughly flat host memory. That is an honest result, and the reason is what Sponza exercises, not that the perf work was ineffective:

  • Most post-#40 PRs don't touch this workload. The largest block is UI / text rendering (shaped-run cache, font-atlas dirty uploads, the UI compute-shader rewrites — #46–#57, #61, #122–#129, #132). Sponza has no UI, so those contribute zero. A second block optimises per-frame dynamic uploads (TLAS dirty-tracking #118, deforming-mesh refit #119, the staging ring #120). A static scene builds its TLAS once and never re-uploads, so these don't fire in steady state either. WebGPU-only (#130/#131/#133) and Win32-only (#134) PRs don't apply to a native Vulkan build at all.
  • The PRs that do apply act on setup and memory, not frame time. Device-local placement (#65/#72/#73/#75), staging release (#66/#67/#114), the pipeline cache (#69) and the deferred-deletion queue (#101/#116) move setup cost and peak memory — which is exactly where the measured ~2–3 % setup change and the warm-cache RSS drop show up. The pipeline cache itself saves ~3 ms here (one RT pipeline) and, more visibly, ~12 MB of peak RSS by skipping the cold shader-compile allocations.
  • Steady-state frame time is GPU-traversal bound. With 262 k triangles the per-frame CPU work (barrier scoping #48/#115, cached heap-bind structs #42/#43) is hidden behind GPU traversal, so it can't move the frame time. Shrinking the scene until it is CPU-bound (the light scene above) surfaces the per-frame CPU savings — and even then they are only ~1.8 %, because that CPU path was already cheap.

Takeaway: the post-#40 work is real but concentrated in UI/text and per-frame dynamic-upload paths; a static, UI-less RT scene is the wrong workload to see most of it. To quantify the UI/text gains a separate benchmark over a text-heavy UIRenderer scene (or an animated/deforming scene for the dynamic-upload PRs) would be needed.

Caveats / notes

  • The stock examples/Sponza native path does not currently compile against the (unpinned) Vulkan-Headers main: the VkResourceDescriptorDataEXT union no longer has the pCombinedImageSampler member the example uses. SponzaBench sidesteps this by not binding a combined image+sampler. (Pre-existing, unrelated to #155 — worth a follow-up to port Sponza to the split sampled-image + sampler-heap model the engine's own UI renderer already uses.)
  • Numbers are CPU/GPU specific. Re-run run-bench.sh locally for your hardware; the deltas between revisions are the point, not the absolute figures.