Crafter.Graphics/examples/RTVolume
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
..
aabbs.comp.glsl SPDX license update 2026-07-22 18:09:06 +02:00
aabbs.comp.wgsl SPDX license update 2026-07-22 18:09:06 +02:00
anyhit.glsl SPDX license update 2026-07-22 18:09:06 +02:00
anyhit.wgsl SPDX license update 2026-07-22 18:09:06 +02:00
closesthit.glsl SPDX license update 2026-07-22 18:09:06 +02:00
closesthit.wgsl SPDX license update 2026-07-22 18:09:06 +02:00
intersection.glsl SPDX license update 2026-07-22 18:09:06 +02:00
intersection.wgsl 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
miss.wgsl 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
raygen.wgsl SPDX license update 2026-07-22 18:09:06 +02:00
README.md test(vulkan-rt): port RTVolume example to native Vulkan (#33) 2026-06-13 00:17:37 +00:00
resolve.wgsl SPDX license update 2026-07-22 18:09:06 +02:00

RTVolume

Ray tracing of procedural (AABB) geometry with an any-hit cut-out on both backends — software WebGPU (issue #13) and native Vulkan hardware RT (issue #33).

A 3×3×3 grid of unit boxes is registered as an AABB BLAS (Mesh::BuildProcedural — VK_GEOMETRY_TYPE_AABBS_KHR on Vulkan, the software AABB-leaf path on WebGPU). The hit group is procedural (RTShaderGroupType::ProceduralHitGroup / VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_KHR) carrying:

  • intersection.wgsl / intersection.glsl — analytic ray–sphere test that turns each box into a radius-1 sphere (runs once per box the ray enters);
  • anyhit.wgsl / anyhit.glsl — ignores the intersection for half the cells of a spherical checkerboard, so the ray passes through and the background / spheres behind show through (the visible proof any-hit runs);
  • closesthit.wgsl / closesthit.glsl — normal-based Lambert shading, tinted per instance.

The geometry is registered non-opaque and the instances clear their force-opaque flag, which is what lets the any-hit shader run. Flip the instance flag to kRTGeometryInstanceForceOpaque (or build the mesh with opaque = true) to skip any-hit and see solid spheres.

WebGPU/DOM (free camera, WASD + mouse):

crafter-build --target=wasm32-wasip1 -r

Native Vulkan (fixed camera in raygen.glsl):

crafter-build -r