Skip to content

Commit 979bcb0

Browse files
examples: fix shader-coverage demo portability (#11623)
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.
1 parent bb47086 commit 979bcb0

4 files changed

Lines changed: 60 additions & 16 deletions

File tree

examples/shader-coverage-bvh-traversal/CMakeLists.txt

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,25 @@
33
# See the image-pipeline demo's CMakeLists.txt for the rationale on
44
# why this example uses raw Vulkan instead of slang-rhi.
55

6-
find_package(Vulkan)
7-
if(NOT Vulkan_FOUND)
8-
message(
9-
STATUS
10-
"examples: skipping shader-coverage-bvh-traversal (Vulkan SDK not found)"
11-
)
12-
return()
6+
# Vulkan headers come from Slang's bundled Vulkan-Headers submodule (the
7+
# always-available Vulkan::Headers target, see external/CMakeLists.txt), so
8+
# this demo only needs to locate the loader library at build time. Prefer the
9+
# Vulkan SDK's imported target when present; otherwise fall back to the bare
10+
# runtime loader (e.g. libvulkan.so.1) so the demo still builds on machines
11+
# that ship only the Vulkan runtime and not a -dev/SDK package.
12+
find_package(Vulkan QUIET)
13+
if(TARGET Vulkan::Vulkan)
14+
set(_vulkan_loader Vulkan::Vulkan)
15+
else()
16+
find_library(SLANG_VULKAN_LOADER NAMES vulkan vulkan-1 libvulkan.so.1)
17+
if(NOT SLANG_VULKAN_LOADER)
18+
message(
19+
STATUS
20+
"examples: skipping shader-coverage-bvh-traversal (Vulkan loader not found)"
21+
)
22+
return()
23+
endif()
24+
set(_vulkan_loader ${SLANG_VULKAN_LOADER})
1325
endif()
1426

1527
set(_asset_files
@@ -53,7 +65,7 @@ target_include_directories(
5365
)
5466
target_link_libraries(
5567
shader-coverage-bvh-traversal
56-
PRIVATE Vulkan::Vulkan slang core
68+
PRIVATE ${_vulkan_loader} Vulkan::Headers slang core
5769
)
5870
target_compile_features(shader-coverage-bvh-traversal PRIVATE cxx_std_17)
5971
set_target_properties(shader-coverage-bvh-traversal PROPERTIES FOLDER examples)

examples/shader-coverage-bvh-traversal/vk_compute_demo.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66

77
#include <cstring>
88

9+
// VK_KHR_portability_enumeration was introduced in Vulkan SDK 1.3.x headers.
10+
// Define string and flag fallbacks so the runtime detection below compiles
11+
// against any SDK version; both values are fixed by the Vulkan spec.
12+
#ifndef VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME
13+
#define VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME "VK_KHR_portability_enumeration"
14+
#endif
15+
#ifndef VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR
16+
#define VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR ((VkInstanceCreateFlagBits)0x00000001)
17+
#endif
18+
919
namespace vkdemo
1020
{
1121

examples/shader-coverage-image-pipeline/CMakeLists.txt

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,25 @@
1010
# Requires Vulkan SDK at build time for the loader (libvulkan).
1111
# Headers come from Slang's Vulkan-Headers submodule.
1212

13-
find_package(Vulkan)
14-
if(NOT Vulkan_FOUND)
15-
message(
16-
STATUS
17-
"examples: skipping shader-coverage-image-pipeline (Vulkan SDK not found)"
18-
)
19-
return()
13+
# Vulkan headers come from Slang's bundled Vulkan-Headers submodule (the
14+
# always-available Vulkan::Headers target, see external/CMakeLists.txt), so
15+
# this demo only needs to locate the loader library at build time. Prefer the
16+
# Vulkan SDK's imported target when present; otherwise fall back to the bare
17+
# runtime loader (e.g. libvulkan.so.1) so the demo still builds on machines
18+
# that ship only the Vulkan runtime and not a -dev/SDK package.
19+
find_package(Vulkan QUIET)
20+
if(TARGET Vulkan::Vulkan)
21+
set(_vulkan_loader Vulkan::Vulkan)
22+
else()
23+
find_library(SLANG_VULKAN_LOADER NAMES vulkan vulkan-1 libvulkan.so.1)
24+
if(NOT SLANG_VULKAN_LOADER)
25+
message(
26+
STATUS
27+
"examples: skipping shader-coverage-image-pipeline (Vulkan loader not found)"
28+
)
29+
return()
30+
endif()
31+
set(_vulkan_loader ${SLANG_VULKAN_LOADER})
2032
endif()
2133

2234
set(_asset_files denoise.slang gamma.slang pipeline.slang tonemap.slang)
@@ -55,7 +67,7 @@ target_include_directories(
5567
)
5668
target_link_libraries(
5769
shader-coverage-image-pipeline
58-
PRIVATE Vulkan::Vulkan slang core
70+
PRIVATE ${_vulkan_loader} Vulkan::Headers slang core
5971
)
6072
target_compile_features(shader-coverage-image-pipeline PRIVATE cxx_std_17)
6173
set_target_properties(shader-coverage-image-pipeline PROPERTIES FOLDER examples)

examples/shader-coverage-image-pipeline/vk_compute_demo.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66

77
#include <cstring>
88

9+
// VK_KHR_portability_enumeration was introduced in Vulkan SDK 1.3.x headers.
10+
// Define string and flag fallbacks so the runtime detection below compiles
11+
// against any SDK version; both values are fixed by the Vulkan spec.
12+
#ifndef VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME
13+
#define VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME "VK_KHR_portability_enumeration"
14+
#endif
15+
#ifndef VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR
16+
#define VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR ((VkInstanceCreateFlagBits)0x00000001)
17+
#endif
18+
919
namespace vkdemo
1020
{
1121

0 commit comments

Comments
 (0)