Skip to content

examples: fix shader-coverage demo portability#11623

Merged
jvepsalainen-nv merged 3 commits into
shader-slang:masterfrom
jvepsalainen-nv:fix-shader-coverage-compatibility
Jun 16, 2026
Merged

examples: fix shader-coverage demo portability#11623
jvepsalainen-nv merged 3 commits into
shader-slang:masterfrom
jvepsalainen-nv:fix-shader-coverage-compatibility

Conversation

@jvepsalainen-nv

Copy link
Copy Markdown
Contributor

The two shader-coverage demos relied entirely on find_package(Vulkan) for both the loader and headers, and skipped themselves if either was missing. This left them unbuildable on machines that ship only the Vulkan runtime loader (no -dev/SDK package) and on older Vulkan headers.

  • CMakeLists: source headers from Slang's bundled Vulkan::Headers target, and fall back to locating the runtime loader (libvulkan.so.1) when find_package(Vulkan) is unavailable, instead of skipping the example.
  • vk_compute_demo.cpp: guard the VK_KHR_portability_enumeration references behind #if defined so headers older than 1.3.x still compile.

The two shader-coverage demos relied entirely on find_package(Vulkan) for
both the loader and headers, and skipped themselves if either was missing.
This left them unbuildable on machines that ship only the Vulkan runtime
loader (no -dev/SDK package) and on older Vulkan headers.

- CMakeLists: source headers from Slang's bundled Vulkan::Headers target,
  and fall back to locating the runtime loader (libvulkan.so.1) when
  find_package(Vulkan) is unavailable, instead of skipping the example.
- vk_compute_demo.cpp: guard the VK_KHR_portability_enumeration references
  behind #if defined so headers older than 1.3.x still compile.
@jvepsalainen-nv jvepsalainen-nv self-assigned this Jun 16, 2026
@jvepsalainen-nv jvepsalainen-nv requested a review from a team as a code owner June 16, 2026 08:35
@jvepsalainen-nv jvepsalainen-nv requested review from bmillsNV and removed request for a team June 16, 2026 08:35
@jvepsalainen-nv jvepsalainen-nv added the pr: non-breaking PRs without breaking changes label Jun 16, 2026
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

An error occurred during the review process. Please try again later.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: cb968da9-b0a0-4aec-826e-6b2ef59270cb

📥 Commits

Reviewing files that changed from the base of the PR and between 1b88b5f and 2052ba5.

📒 Files selected for processing (2)
  • examples/shader-coverage-bvh-traversal/vk_compute_demo.cpp
  • examples/shader-coverage-image-pipeline/vk_compute_demo.cpp

📝 Walkthrough

Walkthrough

Both shader-coverage-bvh-traversal and shader-coverage-image-pipeline examples are updated to discover the Vulkan loader flexibly at CMake configure time and to provide compile-time fallback definitions for portability-enumeration extension macros for older Vulkan header compatibility.

Changes

Vulkan Compatibility Hardening

Layer / File(s) Summary
Flexible Vulkan loader discovery in CMake
examples/shader-coverage-bvh-traversal/CMakeLists.txt, examples/shader-coverage-image-pipeline/CMakeLists.txt
Both build files replace the hard dependency on Vulkan::Vulkan with a two-step probe: find_package(Vulkan QUIET) for the imported target, then a find_library fallback for vulkan/vulkan-1/libvulkan.so.1. If no loader is found the example is skipped via return(). Link steps are updated to use ${_vulkan_loader} alongside explicit Vulkan::Headers.
Compile-time fallback macros for portability-enumeration
examples/shader-coverage-bvh-traversal/vk_compute_demo.cpp, examples/shader-coverage-image-pipeline/vk_compute_demo.cpp
Both C++ source files add #ifndef-guarded fallback definitions for VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME and VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR to allow compilation against older Vulkan headers that do not provide these macros.

Suggested reviewers

  • bmillsNV
  • jkiviluoto-nv
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'examples: fix shader-coverage demo portability' directly addresses the main objective of the PR: improving portability of the shader-coverage demos to work on systems with runtime-only Vulkan installations.
Description check ✅ Passed The description accurately explains the problem (demos unbuildable on runtime-only Vulkan systems) and details the two main solutions (CMakeLists fallback logic and vk_compute_demo.cpp compatibility guards).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: d96819e4-72bd-4c5b-b08a-e82fca89c54d

📥 Commits

Reviewing files that changed from the base of the PR and between a214f7d and 1b88b5f.

📒 Files selected for processing (4)
  • examples/shader-coverage-bvh-traversal/CMakeLists.txt
  • examples/shader-coverage-bvh-traversal/vk_compute_demo.cpp
  • examples/shader-coverage-image-pipeline/CMakeLists.txt
  • examples/shader-coverage-image-pipeline/vk_compute_demo.cpp

Comment thread examples/shader-coverage-bvh-traversal/vk_compute_demo.cpp Outdated
Comment thread examples/shader-coverage-image-pipeline/CMakeLists.txt
Comment thread examples/shader-coverage-image-pipeline/vk_compute_demo.cpp Outdated
@jvepsalainen-nv jvepsalainen-nv changed the title examples: make shader-coverage demos build without a Vulkan -dev package examples: fix shader-coverage demo portability Jun 16, 2026

@jvepsalainen-nv jvepsalainen-nv left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Sonnet 4.6-authored clarity review:

This is a focused, well-described build-compatibility fix. The PR description matches the diff, the changes are symmetric across both examples, and the new comment blocks generally explain the approach well. Four clarity gaps remain in the newly added code:

Immediate fix: The image-pipeline CMakeLists still has a file-level comment saying "Requires Vulkan SDK at build time for the loader (libvulkan)." The PR's purpose is exactly the opposite—the SDK is now optional—so that line is now a direct contradiction of the new fallback logic.

Medium priority: The find_library NAMES list (vulkan vulkan-1 libvulkan.so.1) has a non-obvious entry: libvulkan.so.1 works as an exact-filename lookup in CMake (bypassing the normal lib/.so wrapping) to find the versioned soname on systems without a .so development symlink. Without a note, a future maintainer could mistake it for a typo or not understand why vulkan alone is insufficient. Similarly, _vulkan_loader can hold either an imported CMake target (with transitive include dirs) or a bare filesystem path (without), and the correctness of the fallback depends on Vulkan::Headers always being present in the link line—that invariant is implicit.

Lower priority: The portability-enumeration comment says "the runtime detection runs wherever the extension is available," but "available" is ambiguous: the detection loop is inside the #if guard, so it only runs when the header defines the macro, not wherever the GPU runtime supports the extension. On old headers + portability-capable GPU, portability enumeration is silently not requested. A few word changes would close that gap.

Comment thread examples/shader-coverage-image-pipeline/CMakeLists.txt
Comment thread examples/shader-coverage-bvh-traversal/CMakeLists.txt
Comment thread examples/shader-coverage-bvh-traversal/vk_compute_demo.cpp Outdated
Comment thread examples/shader-coverage-bvh-traversal/CMakeLists.txt
skiminki-nv
skiminki-nv previously approved these changes Jun 16, 2026
@jvepsalainen-nv jvepsalainen-nv added this pull request to the merge queue Jun 16, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 16, 2026
// VK_KHR_portability_enumeration is only defined by Vulkan headers >= 1.3.x.
// Guard the references so older headers (e.g. on some Linux CI runners) still
// compile; the runtime detection runs wherever the extension is available.
#if defined(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the example still going to work/function without this extension?
If yes, why do we need to use the extension?
If no, should we stop the execution here when the extension is not available?

This code change looks like a temporary bandaid rather than a proper fix.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extensions are needed for macOS compatibility. The #if defined() guards were placed at the wrong layer. They fixed the compile error but silently stripped the runtime portability detection on old-header machines, which would have broken macOS/MoltenVK with an SDK < 1.3.x.

@jvepsalainen-nv jvepsalainen-nv added this pull request to the merge queue Jun 16, 2026
@jvepsalainen-nv jvepsalainen-nv removed this pull request from the merge queue due to a manual request Jun 16, 2026
The #if defined(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME) guards
fixed the compile error on old Vulkan SDK headers but silently removed
the runtime portability detection on those headers — breaking macOS /
MoltenVK on any machine with an SDK older than 1.3.x.

The correct fix is to define local fallback constants when the header
doesn't provide them. Both values are fixed by the Vulkan spec, so
hardcoding them as fallbacks is safe across all SDK versions. The
runtime detection and flag assignment are now always compiled and
always run; on old-header Linux the strcmp never matches at runtime
(the extension isn't present there), so hasPortabilityEnum stays false
and behaviour is unchanged.

Also removes the (void)hasPortabilityEnum bandaid that the usage guards
had introduced.

@skiminki-nv skiminki-nv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jvepsalainen-nv jvepsalainen-nv added this pull request to the merge queue Jun 16, 2026
Merged via the queue into shader-slang:master with commit 89841d2 Jun 16, 2026
47 checks passed
if(TARGET Vulkan::Vulkan)
set(_vulkan_loader Vulkan::Vulkan)
else()
find_library(SLANG_VULKAN_LOADER NAMES vulkan vulkan-1 libvulkan.so.1)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reported problem was a build failure.
I don't understand why we need to find VulkanSDK files to resolve the compile time errors.
Slang already ahs external/SPIRV-{headers,tools} directories to compile any spirv/vulkan related compilation.
We shouldn't need to find files from vulkan sdk for compilation error.

jvepsalainen-nv added a commit that referenced this pull request Jun 22, 2026
The two shader-coverage demos relied entirely on find_package(Vulkan)
for both the loader and headers, and skipped themselves if either was
missing. This left them unbuildable on machines that ship only the
Vulkan runtime loader (no -dev/SDK package) and on older Vulkan headers.

- CMakeLists: source headers from Slang's bundled Vulkan::Headers
target, and fall back to locating the runtime loader (libvulkan.so.1)
when find_package(Vulkan) is unavailable, instead of skipping the
example.
- vk_compute_demo.cpp: guard the VK_KHR_portability_enumeration
references behind #if defined so headers older than 1.3.x still compile.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: non-breaking PRs without breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants