Skip to content

Commit fdce530

Browse files
authored
Add Layer Settings API to framework, improve batch mode error recovery, fix macOS issues (#1084)
* Add infrastructure to support Vulkan layer settings extension and API * shader_debugprintf: Enable debugPrintfEXT using layer settings API vs. create_instance() custom override * descriptor_indexing: On macOS enable Metal Argument Buffers via layer settings and work-around variable descriptor counts * Fix CMakeLists.txt find dxc logic - check for Vulkan_dxc_EXECUTABLE not DEFINED Vulkan_dxc_EXECUTABLE * Enable VK_ENABLE_BETA_EXTENSIONS on Apple platforms for VK_KHR_portability_subset extension and features * Batch mode: Reset target environment to default prior to each sample; permit VK_SUBOPTIMAL_KHR * Don't create app bundle on macOS in order to match build/run documentation * Add .DS_Store to .gitignore for macOS cleanliness * shader_debugprintf: Override get_validation_layers() and allow layer settings to work with Release builds * Batch mode: Improve error recovery by using throw std::runtime_error() vs. ExitCode::FatalError * Batch mode: Improve error recovery for async_compute, fragment_shader_barycentric, and texture_mipmap_generation samples * CMakeLists: Move project() definition before find_package(Vulkan) to setup platform default search paths for dxc * Remove HLSL shader compilation warning when VULKAN_SDK is not found * Modify macOS run documentation to include possibilty of arm64 hosts * shader_debugprintf: Check for VK_EXT_layer_settings at runtime for backwards compatibilty with older SDKs * Fix CI warnings for Doxygen and Copyright dates * Fix CI warnings for files identified by clang-format * Incorporate initial feedback from @asuessenbach * Remove #if defined(VK_EXT_layer_settings) guards from layer settings code * pipeline_cache sample: Replace VK_CHECK in destructor with explicit error handling and logging * descriptor_indexing and shader_debugprintf: Small changes to support older Vulkan SDKs * Incorporate subsequent feedback from @asuessenbach * Try to fix clang-format issues with async_compute.cpp and pipeline_cache.cpp * Use VKB_ENABLE_PORTABILITY vs. VK_ENABLE_BETA_EXTENSIONS to guard portability subset features * Remove duplicates and reuse runtime checks for VK_KHR_portability_enumeration * Remove descriptor_indexing sample workaround for Apple Vulkan SDKs > 1.3.283 * Update shader_debugprintf README to describe layer settings method of enabling debugPrintfEXT * Use Vulkan_dxc_exe_FOUND where possible, use Vulkan_dxc_EXECUTABLE in sample_helper.cmake
1 parent 3fcc530 commit fdce530

File tree

33 files changed

+423
-133
lines changed

33 files changed

+423
-133
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ tests/system_test/tmp
99
output/*
1010
.mypy_cache
1111
tags
12+
.DS_Store
1213

1314
# vim backup and temp files
1415
*~

CMakeLists.txt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,30 @@ endif()
3434

3535
cmake_minimum_required(VERSION 3.16)
3636

37+
project(vulkan_samples)
38+
3739
# search for Vulkan SDK
3840
find_package(Vulkan)
3941

40-
if(VULKAN_FOUND)
41-
if(NOT Vulkan_dxc_EXECUTABLE)
42+
if(Vulkan_FOUND)
43+
if(NOT Vulkan_dxc_exe_FOUND)
4244
find_program(Vulkan_dxc_EXECUTABLE
4345
NAMES dxc
4446
HINTS
4547
"$ENV{VULKAN_SDK}/Bin"
4648
"$ENV{VULKAN_SDK}/bin"
4749
)
4850
endif()
49-
if(DEFINED Vulkan_dxc_EXECUTABLE)
50-
message("Found DirectX Shader Compiler under ${Vulkan_dxc_EXECUTABLE}")
51-
elseif()
52-
message("Couldn't find DirectX Shader Compiler executable, make sure it is present in Vulkan SDK or add it manually via Vulkan_dxc_EXECUTABLE env variable")
51+
if(Vulkan_dxc_EXECUTABLE)
52+
message(STATUS "Found DirectX Shader Compiler under ${Vulkan_dxc_EXECUTABLE}")
53+
else()
54+
message(STATUS "Couldn't find DirectX Shader Compiler executable, make sure it is present in Vulkan SDK or add it manually via Vulkan_dxc_EXECUTABLE cmake variable. HLSL shaders won't be compiled.")
5355
endif()
54-
else()
55-
message("VULKAN_SDK path not found, HLSL shaders won't be compiled")
5656
endif()
5757

5858
# globally add VKB_DEBUG for the debug build
5959
add_compile_definitions($<$<CONFIG:DEBUG>:VKB_DEBUG>)
6060

61-
project(vulkan_samples)
62-
6361
if(MSVC AND (DEFINED CMAKE_C_COMPILER_LAUNCHER))
6462
message(DEBUG "Setting MSVC flags to /Z7 for ccache compatibility. Current flags: ${CMAKE_CXX_FLAGS_DEBUG}")
6563
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")

app/CMakeLists.txt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,15 @@ if(ANDROID)
4141
endif()
4242

4343
add_library(${PROJECT_NAME} SHARED ${SRC})
44-
elseif (APPLE)
45-
if(IOS)
46-
list(REMOVE_AT SRC 0)
47-
list(APPEND SRC
48-
${CMAKE_CURRENT_SOURCE_DIR}/ios/main.mm
49-
${CMAKE_CURRENT_SOURCE_DIR}/ios/AppDelegate.h
50-
${CMAKE_CURRENT_SOURCE_DIR}/ios/AppDelegate.m
51-
${CMAKE_CURRENT_SOURCE_DIR}/ios/ViewController.h
52-
${CMAKE_CURRENT_SOURCE_DIR}/ios/ViewController.mm
53-
)
54-
endif ()
44+
elseif(IOS)
45+
list(REMOVE_AT SRC 0)
46+
list(APPEND SRC
47+
${CMAKE_CURRENT_SOURCE_DIR}/ios/main.mm
48+
${CMAKE_CURRENT_SOURCE_DIR}/ios/AppDelegate.h
49+
${CMAKE_CURRENT_SOURCE_DIR}/ios/AppDelegate.m
50+
${CMAKE_CURRENT_SOURCE_DIR}/ios/ViewController.h
51+
${CMAKE_CURRENT_SOURCE_DIR}/ios/ViewController.mm
52+
)
5553
add_executable(${PROJECT_NAME} MACOSX_BUNDLE ${SRC})
5654
else()
5755
add_executable(${PROJECT_NAME} WIN32 ${SRC})

bldsys/cmake/global_options.cmake

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,10 @@ endif()
3333

3434
if(APPLE)
3535
cmake_minimum_required(VERSION 3.24)
36+
set(VKB_ENABLE_PORTABILITY ON CACHE BOOL "Enable portability enumeration and subset features in the framework. This is required to be set when running on Apple platforms." FORCE)
3637
if(IOS)
3738
set(CMAKE_XCODE_GENERATE_SCHEME TRUE)
38-
endif ()
39-
find_package(Vulkan)
40-
if(Vulkan_VERSION GREATER_EQUAL 1.3)
41-
set(VKB_ENABLE_PORTABILITY ON CACHE BOOL "Enable portability extension enumeration in the framework. This is required to be set if running MoltenVK and Vulkan 1.3+" FORCE)
42-
else()
43-
set(VKB_ENABLE_PORTABILITY OFF CACHE BOOL "Enable portability extension enumeration in the framework. This is required to be off if running Vulkan less than 1.3" FORCE)
44-
endif()
39+
endif()
4540
endif()
4641

4742
set(VKB_WARNINGS_AS_ERRORS ON CACHE BOOL "Enable Warnings as Errors")

bldsys/cmake/sample_helper.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ endif()
197197
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_CLANG_TIDY "${VKB_DO_CLANG_TIDY}")
198198
endif()
199199

200-
if(DEFINED Vulkan_dxc_EXECUTABLE AND DEFINED SHADERS_HLSL)
200+
if(Vulkan_dxc_EXECUTABLE AND DEFINED SHADERS_HLSL)
201201
compile_hlsl_shaders(
202202
SHADERS_HLSL ${TARGET_SHADERS_HLSL}
203203
DXC_ADDITIONAL_ARGUMENTS ${TARGET_DXC_ADDITIONAL_ARGUMENTS}

docs/build.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ cmake --build build/mac --config Release --target vulkan_samples -j4
273273
`Step 3.` Run the *Vulkan Samples* application to display the help message
274274

275275
----
276-
./build/mac/app/bin/Release/x86_64/vulkan_samples --help
276+
./build/mac/app/bin/Release/<x86_64|arm64>/vulkan_samples --help
277277
----
278278

279279
== iOS

framework/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ if(${VKB_VULKAN_DEBUG})
501501
endif()
502502

503503
if(${VKB_ENABLE_PORTABILITY})
504-
message(STATUS "Vulkan Portability extension is enabled")
504+
message(STATUS "Vulkan Portability Enumeration and Portability Subset extensions are enabled")
505505
target_compile_definitions(${PROJECT_NAME} PUBLIC VKB_ENABLE_PORTABILITY)
506506
endif()
507507

framework/common/error.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,14 @@ class VulkanException : public std::runtime_error
5454
} // namespace vkb
5555

5656
/// @brief Helper macro to test the result of Vulkan calls which can return an error.
57-
#define VK_CHECK(x) \
58-
do \
59-
{ \
60-
VkResult err = x; \
61-
if (err) \
62-
{ \
63-
LOGE("Detected Vulkan error: {}", vkb::to_string(err)); \
64-
abort(); \
65-
} \
57+
#define VK_CHECK(x) \
58+
do \
59+
{ \
60+
VkResult err = x; \
61+
if (err) \
62+
{ \
63+
throw std::runtime_error("Detected Vulkan error: " + vkb::to_string(err)); \
64+
} \
6665
} while (0)
6766

6867
#define ASSERT_VK_HANDLE(handle) \

framework/common/strings.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,13 @@ const std::string to_string(VkResult result)
686686
STR(ERROR_INCOMPATIBLE_DRIVER);
687687
STR(ERROR_TOO_MANY_OBJECTS);
688688
STR(ERROR_FORMAT_NOT_SUPPORTED);
689+
STR(ERROR_FRAGMENTED_POOL);
690+
STR(ERROR_UNKNOWN);
691+
STR(ERROR_OUT_OF_POOL_MEMORY);
692+
STR(ERROR_INVALID_EXTERNAL_HANDLE);
693+
STR(ERROR_FRAGMENTATION);
694+
STR(ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS);
695+
STR(PIPELINE_COMPILE_REQUIRED);
689696
STR(ERROR_SURFACE_LOST_KHR);
690697
STR(ERROR_NATIVE_WINDOW_IN_USE_KHR);
691698
STR(SUBOPTIMAL_KHR);

framework/core/hpp_instance.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ bool enable_all_extensions(const std::vector<const char *> required_
186186
HPPInstance::HPPInstance(const std::string &application_name,
187187
const std::unordered_map<const char *, bool> &required_extensions,
188188
const std::vector<const char *> &required_validation_layers,
189+
const std::vector<vk::LayerSettingEXT> &required_layer_settings,
189190
bool headless,
190191
uint32_t api_version)
191192
{
@@ -211,7 +212,7 @@ HPPInstance::HPPInstance(const std::string &applicati
211212

212213
#if (defined(VKB_ENABLE_PORTABILITY))
213214
enable_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, available_instance_extensions, enabled_extensions);
214-
enable_extension(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME, available_instance_extensions, enabled_extensions);
215+
bool portability_enumeration_available = enable_extension(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME, available_instance_extensions, enabled_extensions);
215216
#endif
216217

217218
#ifdef USE_VALIDATION_LAYER_FEATURES
@@ -326,7 +327,10 @@ HPPInstance::HPPInstance(const std::string &applicati
326327
#endif
327328

328329
#if (defined(VKB_ENABLE_PORTABILITY))
329-
instance_info.flags |= vk::InstanceCreateFlagBits::eEnumeratePortabilityKHR;
330+
if (portability_enumeration_available)
331+
{
332+
instance_info.flags |= vk::InstanceCreateFlagBits::eEnumeratePortabilityKHR;
333+
}
330334
#endif
331335

332336
#ifdef USE_VALIDATION_LAYER_FEATURES
@@ -347,6 +351,17 @@ HPPInstance::HPPInstance(const std::string &applicati
347351
}
348352
#endif
349353

354+
vk::LayerSettingsCreateInfoEXT layerSettingsCreateInfo;
355+
356+
// If layer settings extension enabled by sample, then activate layer settings during instance creation
357+
if (std::find(enabled_extensions.begin(), enabled_extensions.end(), VK_EXT_LAYER_SETTINGS_EXTENSION_NAME) != enabled_extensions.end())
358+
{
359+
layerSettingsCreateInfo.settingCount = static_cast<uint32_t>(required_layer_settings.size());
360+
layerSettingsCreateInfo.pSettings = required_layer_settings.data();
361+
layerSettingsCreateInfo.pNext = instance_info.pNext;
362+
instance_info.pNext = &layerSettingsCreateInfo;
363+
}
364+
350365
// Create the Vulkan instance
351366
handle = vk::createInstance(instance_info);
352367

0 commit comments

Comments
 (0)