Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Layer Settings API to framework, improve batch mode error recovery, fix macOS issues #1084

Merged
merged 30 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
86cdbd4
Add infrastructure to support Vulkan layer settings extension and API
SRSaunders Jun 24, 2024
1598028
shader_debugprintf: Enable debugPrintfEXT using layer settings API vs…
SRSaunders Jun 24, 2024
74f7b3b
descriptor_indexing: On macOS enable Metal Argument Buffers via layer…
SRSaunders Jun 24, 2024
d743304
Fix CMakeLists.txt find dxc logic - check for Vulkan_dxc_EXECUTABLE n…
SRSaunders Jun 24, 2024
4dfe595
Enable VK_ENABLE_BETA_EXTENSIONS on Apple platforms for VK_KHR_portab…
SRSaunders Jun 25, 2024
d05acf0
Batch mode: Reset target environment to default prior to each sample;…
SRSaunders Jun 25, 2024
b3a6730
Don't create app bundle on macOS in order to match build/run document…
SRSaunders Jun 25, 2024
9ed9279
Add .DS_Store to .gitignore for macOS cleanliness
SRSaunders Jun 25, 2024
d942a92
shader_debugprintf: Override get_validation_layers() and allow layer …
SRSaunders Jun 26, 2024
b3befb9
Batch mode: Improve error recovery by using throw std::runtime_error(…
SRSaunders Jun 27, 2024
ba11c99
Batch mode: Improve error recovery for async_compute, fragment_shader…
SRSaunders Jun 27, 2024
f848365
Merge branch 'KhronosGroup:main' into layer-settings
SRSaunders Jul 1, 2024
e3d4c16
CMakeLists: Move project() definition before find_package(Vulkan) to …
SRSaunders Jul 1, 2024
6342fc0
Remove HLSL shader compilation warning when VULKAN_SDK is not found
SRSaunders Jul 3, 2024
5321236
Modify macOS run documentation to include possibilty of arm64 hosts
SRSaunders Jul 3, 2024
65d0f7a
shader_debugprintf: Check for VK_EXT_layer_settings at runtime for ba…
SRSaunders Jul 3, 2024
7c0195a
Fix CI warnings for Doxygen and Copyright dates
SRSaunders Jul 4, 2024
8caca90
Fix CI warnings for files identified by clang-format
SRSaunders Jul 5, 2024
4f20ae6
Merge branch 'KhronosGroup:main' into layer-settings
SRSaunders Jul 9, 2024
1710d24
Incorporate initial feedback from @asuessenbach
SRSaunders Jul 9, 2024
4f43430
Remove #if defined(VK_EXT_layer_settings) guards from layer settings …
SRSaunders Jul 10, 2024
d4b43c0
pipeline_cache sample: Replace VK_CHECK in destructor with explicit e…
SRSaunders Jul 11, 2024
4a21178
descriptor_indexing and shader_debugprintf: Small changes to support …
SRSaunders Jul 11, 2024
5457a82
Incorporate subsequent feedback from @asuessenbach
SRSaunders Jul 12, 2024
fcf6826
Try to fix clang-format issues with async_compute.cpp and pipeline_ca…
SRSaunders Jul 12, 2024
6e73f7c
Use VKB_ENABLE_PORTABILITY vs. VK_ENABLE_BETA_EXTENSIONS to guard por…
SRSaunders Jul 19, 2024
c756611
Remove duplicates and reuse runtime checks for VK_KHR_portability_enu…
SRSaunders Jul 21, 2024
c3cece1
Remove descriptor_indexing sample workaround for Apple Vulkan SDKs > …
SRSaunders Jul 21, 2024
98acbe7
Update shader_debugprintf README to describe layer settings method of…
SRSaunders Jul 22, 2024
1e3e85b
Use Vulkan_dxc_exe_FOUND where possible, use Vulkan_dxc_EXECUTABLE in…
SRSaunders Jul 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ tests/system_test/tmp
output/*
.mypy_cache
tags
.DS_Store

# vim backup and temp files
*~
Expand Down
17 changes: 8 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ endif()

cmake_minimum_required(VERSION 3.16)

project(vulkan_samples)

# search for Vulkan SDK
find_package(Vulkan)

if(VULKAN_FOUND)
if(Vulkan_FOUND)
if(NOT Vulkan_dxc_EXECUTABLE)
find_program(Vulkan_dxc_EXECUTABLE
NAMES dxc
Expand All @@ -46,20 +48,17 @@ if(VULKAN_FOUND)
"$ENV{VULKAN_SDK}/bin"
)
endif()
if(DEFINED Vulkan_dxc_EXECUTABLE)
message("Found DirectX Shader Compiler under ${Vulkan_dxc_EXECUTABLE}")
elseif()
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")
if(Vulkan_dxc_EXECUTABLE)
SRSaunders marked this conversation as resolved.
Show resolved Hide resolved
message(STATUS "Found DirectX Shader Compiler under ${Vulkan_dxc_EXECUTABLE}")
else()
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.")
unset(Vulkan_dxc_EXECUTABLE CACHE)
SRSaunders marked this conversation as resolved.
Show resolved Hide resolved
endif()
else()
message("VULKAN_SDK path not found, HLSL shaders won't be compiled")
endif()

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

project(vulkan_samples)

if(MSVC AND (DEFINED CMAKE_C_COMPILER_LAUNCHER))
message(DEBUG "Setting MSVC flags to /Z7 for ccache compatibility. Current flags: ${CMAKE_CXX_FLAGS_DEBUG}")
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
Expand Down
20 changes: 9 additions & 11 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,15 @@ if(ANDROID)
endif()

add_library(${PROJECT_NAME} SHARED ${SRC})
elseif (APPLE)
if(IOS)
list(REMOVE_AT SRC 0)
list(APPEND SRC
${CMAKE_CURRENT_SOURCE_DIR}/ios/main.mm
${CMAKE_CURRENT_SOURCE_DIR}/ios/AppDelegate.h
${CMAKE_CURRENT_SOURCE_DIR}/ios/AppDelegate.m
${CMAKE_CURRENT_SOURCE_DIR}/ios/ViewController.h
${CMAKE_CURRENT_SOURCE_DIR}/ios/ViewController.mm
)
endif ()
elseif(IOS)
gpx1000 marked this conversation as resolved.
Show resolved Hide resolved
list(REMOVE_AT SRC 0)
list(APPEND SRC
${CMAKE_CURRENT_SOURCE_DIR}/ios/main.mm
${CMAKE_CURRENT_SOURCE_DIR}/ios/AppDelegate.h
${CMAKE_CURRENT_SOURCE_DIR}/ios/AppDelegate.m
${CMAKE_CURRENT_SOURCE_DIR}/ios/ViewController.h
${CMAKE_CURRENT_SOURCE_DIR}/ios/ViewController.mm
)
add_executable(${PROJECT_NAME} MACOSX_BUNDLE ${SRC})
else()
add_executable(${PROJECT_NAME} WIN32 ${SRC})
Expand Down
9 changes: 2 additions & 7 deletions bldsys/cmake/global_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,10 @@ endif()

if(APPLE)
cmake_minimum_required(VERSION 3.24)
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)
gpx1000 marked this conversation as resolved.
Show resolved Hide resolved
if(IOS)
set(CMAKE_XCODE_GENERATE_SCHEME TRUE)
endif ()
find_package(Vulkan)
if(Vulkan_VERSION GREATER_EQUAL 1.3)
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)
else()
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)
endif()
endif()
endif()

set(VKB_WARNINGS_AS_ERRORS ON CACHE BOOL "Enable Warnings as Errors")
Expand Down
2 changes: 1 addition & 1 deletion docs/build.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ cmake --build build/mac --config Release --target vulkan_samples -j4
`Step 3.` Run the *Vulkan Samples* application to display the help message

----
./build/mac/app/bin/Release/x86_64/vulkan_samples --help
./build/mac/app/bin/Release/<x86_64|arm64>/vulkan_samples --help
----

== iOS
Expand Down
2 changes: 1 addition & 1 deletion framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ if(${VKB_VULKAN_DEBUG})
endif()

if(${VKB_ENABLE_PORTABILITY})
message(STATUS "Vulkan Portability extension is enabled")
message(STATUS "Vulkan Portability Enumeration and Portability Subset extensions are enabled")
target_compile_definitions(${PROJECT_NAME} PUBLIC VKB_ENABLE_PORTABILITY)
endif()

Expand Down
17 changes: 8 additions & 9 deletions framework/common/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,14 @@ class VulkanException : public std::runtime_error
} // namespace vkb

/// @brief Helper macro to test the result of Vulkan calls which can return an error.
#define VK_CHECK(x) \
SRSaunders marked this conversation as resolved.
Show resolved Hide resolved
do \
{ \
VkResult err = x; \
if (err) \
{ \
LOGE("Detected Vulkan error: {}", vkb::to_string(err)); \
abort(); \
} \
#define VK_CHECK(x) \
do \
{ \
VkResult err = x; \
if (err) \
{ \
throw std::runtime_error("Detected Vulkan error: " + vkb::to_string(err)); \
} \
} while (0)

#define ASSERT_VK_HANDLE(handle) \
Expand Down
7 changes: 7 additions & 0 deletions framework/common/strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,13 @@ const std::string to_string(VkResult result)
STR(ERROR_INCOMPATIBLE_DRIVER);
STR(ERROR_TOO_MANY_OBJECTS);
STR(ERROR_FORMAT_NOT_SUPPORTED);
STR(ERROR_FRAGMENTED_POOL);
STR(ERROR_UNKNOWN);
STR(ERROR_OUT_OF_POOL_MEMORY);
STR(ERROR_INVALID_EXTERNAL_HANDLE);
STR(ERROR_FRAGMENTATION);
STR(ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS);
STR(PIPELINE_COMPILE_REQUIRED);
STR(ERROR_SURFACE_LOST_KHR);
STR(ERROR_NATIVE_WINDOW_IN_USE_KHR);
STR(SUBOPTIMAL_KHR);
Expand Down
19 changes: 17 additions & 2 deletions framework/core/hpp_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ bool enable_all_extensions(const std::vector<const char *> required_
HPPInstance::HPPInstance(const std::string &application_name,
const std::unordered_map<const char *, bool> &required_extensions,
const std::vector<const char *> &required_validation_layers,
const std::vector<vk::LayerSettingEXT> &required_layer_settings,
bool headless,
uint32_t api_version)
{
Expand All @@ -211,7 +212,7 @@ HPPInstance::HPPInstance(const std::string &applicati

#if (defined(VKB_ENABLE_PORTABILITY))
enable_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, available_instance_extensions, enabled_extensions);
enable_extension(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME, available_instance_extensions, enabled_extensions);
bool portability_enumeration_available = enable_extension(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME, available_instance_extensions, enabled_extensions);
#endif

#ifdef USE_VALIDATION_LAYER_FEATURES
Expand Down Expand Up @@ -326,7 +327,10 @@ HPPInstance::HPPInstance(const std::string &applicati
#endif

#if (defined(VKB_ENABLE_PORTABILITY))
instance_info.flags |= vk::InstanceCreateFlagBits::eEnumeratePortabilityKHR;
if (portability_enumeration_available)
{
instance_info.flags |= vk::InstanceCreateFlagBits::eEnumeratePortabilityKHR;
}
#endif

#ifdef USE_VALIDATION_LAYER_FEATURES
Expand All @@ -347,6 +351,17 @@ HPPInstance::HPPInstance(const std::string &applicati
}
#endif

vk::LayerSettingsCreateInfoEXT layerSettingsCreateInfo;

// If layer settings extension enabled by sample, then activate layer settings during instance creation
if (std::find(enabled_extensions.begin(), enabled_extensions.end(), VK_EXT_LAYER_SETTINGS_EXTENSION_NAME) != enabled_extensions.end())
{
layerSettingsCreateInfo.settingCount = static_cast<uint32_t>(required_layer_settings.size());
layerSettingsCreateInfo.pSettings = required_layer_settings.data();
layerSettingsCreateInfo.pNext = instance_info.pNext;
instance_info.pNext = &layerSettingsCreateInfo;
}

// Create the Vulkan instance
handle = vk::createInstance(instance_info);

Expand Down
4 changes: 3 additions & 1 deletion framework/core/hpp_instance.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved.
/* Copyright (c) 2022-2024, NVIDIA CORPORATION. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -53,13 +53,15 @@ class HPPInstance
* @param application_name The name of the application
* @param required_extensions The extensions requested to be enabled
* @param required_validation_layers The validation layers to be enabled
* @param required_layer_settings The layer settings to be enabled
* @param headless Whether the application is requesting a headless setup or not
* @param api_version The Vulkan API version that the instance will be using
* @throws runtime_error if the required extensions and validation layers are not found
*/
HPPInstance(const std::string &application_name,
const std::unordered_map<const char *, bool> &required_extensions = {},
const std::vector<const char *> &required_validation_layers = {},
const std::vector<vk::LayerSettingEXT> &required_layer_settings = {},
bool headless = false,
uint32_t api_version = VK_API_VERSION_1_0);

Expand Down
19 changes: 17 additions & 2 deletions framework/core/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ bool enable_all_extensions(const std::vector<const char *> required_ex
Instance::Instance(const std::string &application_name,
const std::unordered_map<const char *, bool> &required_extensions,
const std::vector<const char *> &required_validation_layers,
const std::vector<VkLayerSettingEXT> &required_layer_settings,
bool headless,
uint32_t api_version)
{
Expand Down Expand Up @@ -215,7 +216,7 @@ Instance::Instance(const std::string &application_nam

#if (defined(VKB_ENABLE_PORTABILITY))
enable_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, available_instance_extensions, enabled_extensions);
enable_extension(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME, available_instance_extensions, enabled_extensions);
bool portability_enumeration_available = enable_extension(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME, available_instance_extensions, enabled_extensions);
#endif

#ifdef USE_VALIDATION_LAYER_FEATURES
Expand Down Expand Up @@ -350,7 +351,10 @@ Instance::Instance(const std::string &application_nam
#endif

#if (defined(VKB_ENABLE_PORTABILITY))
instance_info.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
if (portability_enumeration_available)
{
instance_info.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
}
#endif

// Some of the specialized layers need to be enabled explicitly
Expand All @@ -376,6 +380,17 @@ Instance::Instance(const std::string &application_nam
}
#endif

VkLayerSettingsCreateInfoEXT layerSettingsCreateInfo{VK_STRUCTURE_TYPE_LAYER_SETTINGS_CREATE_INFO_EXT};

// If layer settings extension enabled by sample, then activate layer settings during instance creation
if (std::find(enabled_extensions.begin(), enabled_extensions.end(), VK_EXT_LAYER_SETTINGS_EXTENSION_NAME) != enabled_extensions.end())
{
layerSettingsCreateInfo.settingCount = static_cast<uint32_t>(required_layer_settings.size());
layerSettingsCreateInfo.pSettings = required_layer_settings.data();
layerSettingsCreateInfo.pNext = instance_info.pNext;
instance_info.pNext = &layerSettingsCreateInfo;
}

// Create the Vulkan instance
VkResult result = vkCreateInstance(&instance_info, nullptr, &handle);

Expand Down
2 changes: 2 additions & 0 deletions framework/core/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ class Instance
* @param application_name The name of the application
* @param required_extensions The extensions requested to be enabled
* @param required_validation_layers The validation layers to be enabled
* @param required_layer_settings The layer settings to be enabled
* @param headless Whether the application is requesting a headless setup or not
* @param api_version The Vulkan API version that the instance will be using
* @throws runtime_error if the required extensions and validation layers are not found
*/
Instance(const std::string &application_name,
const std::unordered_map<const char *, bool> &required_extensions = {},
const std::vector<const char *> &required_validation_layers = {},
const std::vector<VkLayerSettingEXT> &required_layer_settings = {},
bool headless = false,
uint32_t api_version = VK_API_VERSION_1_0);

Expand Down
32 changes: 17 additions & 15 deletions framework/platform/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "core/util/logging.hpp"
#include "filesystem/legacy.h"
#include "force_close/force_close.h"
#include "glsl_compiler.h"
#include "platform/parsers/CLI11.h"
#include "platform/plugins/plugin.h"
#include "vulkan_sample.h"
Expand Down Expand Up @@ -142,8 +143,7 @@ ExitCode Platform::main_loop_frame()
{
if (!start_app())
{
LOGE("Failed to load requested application");
return ExitCode::FatalError;
throw std::runtime_error("Failed to load requested application");
}

// Compensate for load times of the app by rendering the first frame pre-emptively
Expand All @@ -169,17 +169,17 @@ ExitCode Platform::main_loop_frame()

on_app_error(active_app->get_name());

if (app_requested())
{
LOGI("Attempting to load next application");
}
else
{
if (app_requested())
{
LOGI("Attempting to load next application");
}
else
{
set_last_error(e.what());
return ExitCode::FatalError;
}
}
}
return ExitCode::FatalError;
}
}
}

return ExitCode::Success;
}
Expand All @@ -200,8 +200,7 @@ ExitCode Platform::main_loop()
{
if (!start_app())
{
LOGE("Failed to load requested application");
return ExitCode::FatalError;
throw std::runtime_error("Failed to load requested application");
}

// Compensate for load times of the app by rendering the first frame pre-emptively
Expand Down Expand Up @@ -233,7 +232,7 @@ ExitCode Platform::main_loop()
}
else
{
set_last_error(e.what());
set_last_error(e.what());
return ExitCode::FatalError;
}
}
Expand Down Expand Up @@ -443,6 +442,9 @@ bool Platform::start_app()
active_app->finish();
}

// Reset target environment to default prior to each sample to properly support batch mode
vkb::GLSLCompiler::reset_target_environment();

active_app = requested_app_info->create();

if (!active_app)
Expand Down
5 changes: 3 additions & 2 deletions framework/rendering/hpp_render_context.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
/* Copyright (c) 2023-2024, NVIDIA CORPORATION. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -310,7 +310,8 @@ void HPPRenderContext::begin_frame()
}
}

if (result != vk::Result::eSuccess)
// eSuboptimalKHR can legitimately occur in batch mode when exiting certain samples (e.g. afbc, msaa, surface_rotation, swapchain_images)
if (result != vk::Result::eSuccess && result != vk::Result::eSuboptimalKHR)
{
prev_frame.reset();
return;
Expand Down
7 changes: 4 additions & 3 deletions framework/rendering/render_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ void RenderContext::begin_frame()
}
}

if (result != VK_SUCCESS)
// VK_SUBOPTIMAL_KHR can legitimately occur in batch mode when exiting certain samples (e.g. afbc, msaa, surface_rotation, swapchain_images)
if (result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR)
{
prev_frame.reset();
return;
Expand Down Expand Up @@ -375,7 +376,7 @@ VkSemaphore RenderContext::submit(const Queue &queue, const std::vector<CommandB

VkFence fence = frame.request_fence();

queue.submit({submit_info}, fence);
VK_CHECK(queue.submit({submit_info}, fence));

return signal_semaphore;
}
Expand All @@ -394,7 +395,7 @@ void RenderContext::submit(const Queue &queue, const std::vector<CommandBuffer *

VkFence fence = frame.request_fence();

queue.submit({submit_info}, fence);
VK_CHECK(queue.submit({submit_info}, fence));
}

void RenderContext::wait_frame()
Expand Down
Loading
Loading