Skip to content

Commit

Permalink
layer: Use Vulkan-Utility-Libraries for dispatch tables
Browse files Browse the repository at this point in the history
The Vulkan-Utility-Libraries now provides the necessary dispatch tables
for the profiles layer. This removes the dependency on ValidationLayers.
To accomplish the switch, the StringAPIVersion function was added locally,
since it used to come from the ValidationLayers but is not currently
available in the Utility-Libraries.
  • Loading branch information
charles-lunarg committed Aug 23, 2023
1 parent 5f0a98f commit 8c8af0d
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 66 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ build-android/external
helper.cmake
Vulkan-Headers/
Vulkan-Tools/
Vulkan-ValidationLayers/
external/
profiles/test/data/VP_LUNARG_test_generated_name.json
profiles/test/data/VP_LUNARG_test_api_generated.json
Expand Down
8 changes: 0 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ find_package(VulkanHeaders REQUIRED CONFIG QUIET)

find_package(VulkanUtilityLibraries REQUIRED CONFIG QUIET)

# Search the VVL include directory using the VVL vk_layer_config.h file
find_file(VVL_INCLUDE_DIR vk_layer_config.h REQUIRED CMAKE_FIND_ROOT_PATH_BOTH)
get_filename_component(VVL_INCLUDE_DIR ${VVL_INCLUDE_DIR} DIRECTORY)

# Effectively the header files installed by VVL are part of Vulkan::Headers
# This reflects the current structure of the VulkanSDK.
target_include_directories(Vulkan::Headers INTERFACE ${VVL_INCLUDE_DIR})

find_package(valijson REQUIRED CONFIG)

find_package(jsoncpp REQUIRED CONFIG)
Expand Down
3 changes: 2 additions & 1 deletion layer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ target_sources(VkLayer_khronos_profiles PRIVATE
target_link_libraries(VkLayer_khronos_profiles PRIVATE
Vulkan::LayerSettings
Vulkan::Headers
Vulkan::UtilityHeaders
jsoncpp_static
valijson
)
Expand All @@ -110,7 +111,7 @@ add_custom_target(VpLayer_generate ALL
DEPENDS ${VULKAN_HEADERS_INSTALL_DIR}/${CMAKE_INSTALL_DATADIR}/vulkan/registry/vk.xml)
set_target_properties(VpLayer_generate PROPERTIES FOLDER "Profiles layer")
add_dependencies(VkLayer_khronos_profiles VpLayer_generate)

source_group("Python Files" FILES ${CMAKE_SOURCE_DIR}/scripts/gen_profiles_tests.py)
add_custom_target(VpLayer_generate_tests ALL
COMMAND Python3::Interpreter ${CMAKE_SOURCE_DIR}/scripts/gen_profiles_tests.py
Expand Down
45 changes: 30 additions & 15 deletions layer/vk_layer_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,26 @@
* Author: Tobin Ehlis <[email protected]>
*/
#include <assert.h>
#include <sstream>
#include <iomanip>
#include <unordered_map>
#include "generated/vk_dispatch_table_helper.h"
#include "vulkan/utility/vul_dispatch_table.h"
#include "vulkan/vk_layer.h"
#include "vk_layer_table.h"
static device_table_map tableMap;
static instance_table_map tableInstanceMap;

dispatch_key get_dispatch_key(const void *object) { return (dispatch_key) * (VulDeviceDispatchTable **)object; }

// Map lookup must be thread safe
VkLayerDispatchTable *device_dispatch_table(void *object) {
VulDeviceDispatchTable *device_dispatch_table(void *object) {
dispatch_key key = get_dispatch_key(object);
device_table_map::const_iterator it = tableMap.find((void *)key);
assert(it != tableMap.end() && "Not able to find device dispatch entry");
return it->second.get();
}

VkLayerInstanceDispatchTable *instance_dispatch_table(void *object) {
VulInstanceDispatchTable *instance_dispatch_table(void *object) {
dispatch_key key = get_dispatch_key(object);
instance_table_map::const_iterator it = tableInstanceMap.find((void *)key);
assert(it != tableInstanceMap.end() && "Not able to find instance dispatch entry");
Expand All @@ -59,14 +63,14 @@ void destroy_device_dispatch_table(dispatch_key key) { destroy_dispatch_table(ta

void destroy_instance_dispatch_table(dispatch_key key) { destroy_dispatch_table(tableInstanceMap, key); }

VkLayerDispatchTable *get_dispatch_table(device_table_map &map, void *object) {
VulDeviceDispatchTable *get_dispatch_table(device_table_map &map, void *object) {
dispatch_key key = get_dispatch_key(object);
device_table_map::const_iterator it = map.find((void *)key);
assert(it != map.end() && "Not able to find device dispatch entry");
return it->second.get();
}

VkLayerInstanceDispatchTable *get_dispatch_table(instance_table_map &map, void *object) {
VulInstanceDispatchTable *get_dispatch_table(instance_table_map &map, void *object) {
dispatch_key key = get_dispatch_key(object);
instance_table_map::const_iterator it = map.find((void *)key);
assert(it != map.end() && "Not able to find instance dispatch entry");
Expand Down Expand Up @@ -98,20 +102,20 @@ VkLayerDeviceCreateInfo *get_chain_info(const VkDeviceCreateInfo *pCreateInfo, V
* Device -> CommandBuffer or Queue
* If use the object themselves as key to map then implies Create entrypoints have to be intercepted
* and a new key inserted into map */
VkLayerInstanceDispatchTable *initInstanceTable(VkInstance instance, const PFN_vkGetInstanceProcAddr gpa, instance_table_map &map) {
VkLayerInstanceDispatchTable *pTable;
VulInstanceDispatchTable *initInstanceTable(VkInstance instance, const PFN_vkGetInstanceProcAddr gpa, instance_table_map &map) {
VulInstanceDispatchTable *pTable;
dispatch_key key = get_dispatch_key(instance);
instance_table_map::const_iterator it = map.find((void *)key);

if (it == map.end()) {
auto table = std::make_unique<VkLayerInstanceDispatchTable>();
auto table = std::make_unique<VulInstanceDispatchTable>();
pTable = table.get();
map[(void *)key] = std::move(table);
} else {
return it->second.get();
}

layer_init_instance_dispatch_table(instance, pTable, gpa);
vulInitInstanceDispatchTable(instance, pTable, gpa);

// Setup func pointers that are required but not externally exposed. These won't be added to the instance dispatch table by
// default.
Expand All @@ -120,28 +124,39 @@ VkLayerInstanceDispatchTable *initInstanceTable(VkInstance instance, const PFN_v
return pTable;
}

VkLayerInstanceDispatchTable *initInstanceTable(VkInstance instance, const PFN_vkGetInstanceProcAddr gpa) {
VulInstanceDispatchTable *initInstanceTable(VkInstance instance, const PFN_vkGetInstanceProcAddr gpa) {
return initInstanceTable(instance, gpa, tableInstanceMap);
}

VkLayerDispatchTable *initDeviceTable(VkDevice device, const PFN_vkGetDeviceProcAddr gpa, device_table_map &map) {
VkLayerDispatchTable *pTable;
VulDeviceDispatchTable *initDeviceTable(VkDevice device, const PFN_vkGetDeviceProcAddr gpa, device_table_map &map) {
VulDeviceDispatchTable *pTable;
dispatch_key key = get_dispatch_key(device);
device_table_map::const_iterator it = map.find((void *)key);

if (it == map.end()) {
auto table = std::make_unique<VkLayerDispatchTable>();
auto table = std::make_unique<VulDeviceDispatchTable>();
pTable = table.get();
map[(void *)key] = std::move(table);
} else {
return it->second.get();
}

layer_init_device_dispatch_table(device, pTable, gpa);
vulInitDeviceDispatchTable(device, pTable, gpa);

return pTable;
}

VkLayerDispatchTable *initDeviceTable(VkDevice device, const PFN_vkGetDeviceProcAddr gpa) {
VulDeviceDispatchTable *initDeviceTable(VkDevice device, const PFN_vkGetDeviceProcAddr gpa) {
return initDeviceTable(device, gpa, tableMap);
}

// Convert integer API version to a string
std::string StringAPIVersion(uint32_t version) {
std::stringstream version_name;
if (version == 0) {
return "<unrecognized>";
}
version_name << VK_API_VERSION_MAJOR(version) << "." << VK_API_VERSION_MINOR(version) << "." << VK_API_VERSION_PATCH(version)
<< " (0x" << std::setfill('0') << std::setw(8) << std::hex << version << ")";
return version_name.str();
}
26 changes: 15 additions & 11 deletions layer/vk_layer_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,29 @@

#pragma once

#include "vulkan/utility/vul_dispatch_table.h"
#include "vulkan/vk_layer.h"
#include "vulkan/vulkan.h"
#include <memory>
#include <unordered_map>
#include "utils/vk_layer_utils.h"

typedef std::unordered_map<void *, std::unique_ptr<VkLayerDispatchTable>> device_table_map;
typedef std::unordered_map<void *, std::unique_ptr<VkLayerInstanceDispatchTable>> instance_table_map;
VkLayerDispatchTable *initDeviceTable(VkDevice device, const PFN_vkGetDeviceProcAddr gpa, device_table_map &map);
VkLayerDispatchTable *initDeviceTable(VkDevice device, const PFN_vkGetDeviceProcAddr gpa);
VkLayerInstanceDispatchTable *initInstanceTable(VkInstance instance, const PFN_vkGetInstanceProcAddr gpa, instance_table_map &map);
VkLayerInstanceDispatchTable *initInstanceTable(VkInstance instance, const PFN_vkGetInstanceProcAddr gpa);
typedef std::unordered_map<void *, std::unique_ptr<VulDeviceDispatchTable>> device_table_map;
typedef std::unordered_map<void *, std::unique_ptr<VulInstanceDispatchTable>> instance_table_map;
VulDeviceDispatchTable *initDeviceTable(VkDevice device, const PFN_vkGetDeviceProcAddr gpa, device_table_map &map);
VulDeviceDispatchTable *initDeviceTable(VkDevice device, const PFN_vkGetDeviceProcAddr gpa);
VulInstanceDispatchTable *initInstanceTable(VkInstance instance, const PFN_vkGetInstanceProcAddr gpa, instance_table_map &map);
VulInstanceDispatchTable *initInstanceTable(VkInstance instance, const PFN_vkGetInstanceProcAddr gpa);

typedef void *dispatch_key;
dispatch_key get_dispatch_key(const void *object);

VkLayerDispatchTable *device_dispatch_table(void *object);
VulDeviceDispatchTable *device_dispatch_table(void *object);

VkLayerInstanceDispatchTable *instance_dispatch_table(void *object);
VulInstanceDispatchTable *instance_dispatch_table(void *object);

VkLayerDispatchTable *get_dispatch_table(device_table_map &map, void *object);
VulDeviceDispatchTable *get_dispatch_table(device_table_map &map, void *object);

VkLayerInstanceDispatchTable *get_dispatch_table(instance_table_map &map, void *object);
VulInstanceDispatchTable *get_dispatch_table(instance_table_map &map, void *object);

VkLayerInstanceCreateInfo *get_chain_info(const VkInstanceCreateInfo *pCreateInfo, VkLayerFunction func);
VkLayerDeviceCreateInfo *get_chain_info(const VkDeviceCreateInfo *pCreateInfo, VkLayerFunction func);
Expand All @@ -50,3 +51,6 @@ void destroy_device_dispatch_table(dispatch_key key);
void destroy_instance_dispatch_table(dispatch_key key);
void destroy_dispatch_table(device_table_map &map, dispatch_key key);
void destroy_dispatch_table(instance_table_map &map, dispatch_key key);

// Convert integer API version to a string
std::string StringAPIVersion(uint32_t version);
7 changes: 0 additions & 7 deletions scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,6 @@ if (VULKAN_UTILITY_LIBRARIES_INSTALL_DIR)
list(APPEND CMAKE_PREFIX_PATH ${VULKAN_UTILITY_LIBRARIES_INSTALL_DIR})
endif()

# TODO: https://github.com/KhronosGroup/Vulkan-Utility-Libraries/issues/13
# In the future profiles will NOT depend on the validation layers.
if (VULKAN_VALIDATIONLAYERS_INSTALL_DIR)
list(APPEND CMAKE_INCLUDE_PATH ${VULKAN_VALIDATIONLAYERS_INSTALL_DIR}/include/vulkan)
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} PARENT_SCOPE)
endif()

if (CMAKE_CROSSCOMPILING)
set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${CMAKE_PREFIX_PATH} PARENT_SCOPE)
else()
Expand Down
4 changes: 2 additions & 2 deletions scripts/gen_profiles_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2285,7 +2285,7 @@ class JsonLoader {
(*pToolCount)--;
}
VkLayerInstanceDispatchTable *pInstanceTable = instance_dispatch_table(physicalDevice);
VulInstanceDispatchTable *pInstanceTable = instance_dispatch_table(physicalDevice);
VkResult result = pInstanceTable->GetPhysicalDeviceToolPropertiesEXT(physicalDevice, pToolCount, pToolProperties);
if (original_pToolProperties != nullptr) {
Expand Down Expand Up @@ -2372,7 +2372,7 @@ class JsonLoader {
dt->GetPhysicalDeviceQueueFamilyProperties2(pd, &count, props.data());
} else {
dt->GetPhysicalDeviceQueueFamilyProperties2KHR(pd, &count, props.data());
}
}
for (uint32_t i = 0; i < count; ++i) {
pdd->device_queue_family_properties_[i].properties_2 = props[i];
}
Expand Down
22 changes: 1 addition & 21 deletions scripts/known_good.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"sub_dir": "Vulkan-Utility-Libraries",
"build_dir": "Vulkan-Utility-Libraries/build",
"install_dir": "Vulkan-Utility-Libraries/build/install",
"commit": "d414e86858986b0479324c706fb37a8bfb09490b",
"commit": "2bd0e0d43884f1d655d66c2195539834a113f850",
"deps": [
{
"var_name": "VULKAN_HEADERS_INSTALL_DIR",
Expand Down Expand Up @@ -43,25 +43,6 @@
"tests"
]
},
{
"name": "Vulkan-ValidationLayers",
"url": "https://github.com/KhronosGroup/Vulkan-ValidationLayers.git",
"sub_dir": "Vulkan-ValidationLayers",
"build_dir": "Vulkan-ValidationLayers/build",
"install_dir": "Vulkan-ValidationLayers/build/install",
"commit": "e6bdb8d71409a96a4174589ea195d0dc1e920625",
"deps": [
{
"var_name": "VULKAN_HEADERS_INSTALL_DIR",
"repo_name": "Vulkan-Headers"
}
],
"cmake_options": [
"-DBUILD_LAYERS=OFF",
"-DBUILD_LAYER_SUPPORT_FILES=ON",
"-DUSE_ROBIN_HOOD_HASHING=OFF"
]
},
{
"name": "jsoncpp",
"url": "https://github.com/open-source-parsers/jsoncpp.git",
Expand Down Expand Up @@ -106,7 +87,6 @@
"Vulkan-Headers": "VULKAN_HEADERS_INSTALL_DIR",
"Vulkan-Utility-Libraries": "VULKAN_UTILITY_LIBRARIES_INSTALL_DIR",
"Vulkan-Loader": "VULKAN_LOADER_INSTALL_DIR",
"Vulkan-ValidationLayers": "VULKAN_VALIDATIONLAYERS_INSTALL_DIR",
"jsoncpp": "JSONCPP_INSTALL_DIR",
"valijson": "VALIJSON_INSTALL_DIR",
"googletest": "GOOGLETEST_INSTALL_DIR"
Expand Down

0 comments on commit 8c8af0d

Please sign in to comment.