Skip to content

Commit

Permalink
Enable per-layer API version and extensions
Browse files Browse the repository at this point in the history
This PR adds the ability for each layer to set a minimum API version
and set of extra instance/device extensions that are needed.

Handlers are included for enabling VK_EXT_debug_utils and 
VK_KHR_timeline_semaphore, and the mechanism can be extended.

The support layer uses this enable the extensions it needs to 
implement queue serialization.
  • Loading branch information
solidpixel authored Jan 20, 2025
1 parent 2ced999 commit ad0271b
Show file tree
Hide file tree
Showing 20 changed files with 766 additions and 75 deletions.
5 changes: 4 additions & 1 deletion generator/vk_layer/source/device.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: MIT
* ----------------------------------------------------------------------------
* Copyright (c) 2024 Arm Limited
* Copyright (c) 2024-2025 Arm Limited
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -39,6 +39,9 @@
*/
static std::unordered_map<void*, std::unique_ptr<Device>> g_devices;

/* See header for documentation. */
const std::vector<std::string> Device::extraExtensions { };

/* See header for documentation. */
void Device::store(
VkDevice handle,
Expand Down
18 changes: 12 additions & 6 deletions generator/vk_layer/source/device.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: MIT
* ----------------------------------------------------------------------------
* Copyright (c) 2024 Arm Limited
* Copyright (c) 2024-2025 Arm Limited
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -132,6 +132,17 @@ class Device
~Device() = default;

public:
/**
* @brief The driver function dispatch table.
*/
DeviceDispatchTable driver {};

/**
* @brief The minimum set of device extensions needed by this layer.
*/
static const std::vector<std::string> extraExtensions;

private:
/**
* @brief The instance this device is created with.
*/
Expand All @@ -146,9 +157,4 @@ class Device
* @brief The device handle this device is created with.
*/
const VkDevice device;

/**
* @brief The driver function dispatch table.
*/
DeviceDispatchTable driver {};
};
10 changes: 9 additions & 1 deletion generator/vk_layer/source/instance.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: MIT
* ----------------------------------------------------------------------------
* Copyright (c) 2024 Arm Limited
* Copyright (c) 2024-2025 Arm Limited
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -34,6 +34,14 @@
*/
static std::unordered_map<void*, std::unique_ptr<Instance>> g_instances;

/* See header for documentation. */
const APIVersion Instance::minAPIVersion { 1, 1 };

/* See header for documentation. */
const std::vector<std::string> Instance::extraExtensions {
"VK_EXT_debug_utils"
};

/* See header for documentation. */
void Instance::store(
VkInstance handle,
Expand Down
12 changes: 11 additions & 1 deletion generator/vk_layer/source/instance.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: MIT
* ----------------------------------------------------------------------------
* Copyright (c) 2024 Arm Limited
* Copyright (c) 2024-2025 Arm Limited
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -131,4 +131,14 @@ class Instance
* @brief The driver function dispatch table.
*/
InstanceDispatchTable driver {};

/**
* @brief The minimum API version needed by this layer.
*/
static const APIVersion minAPIVersion;

/**
* @brief The minimum set of instance extensions needed by this layer.
*/
static const std::vector<std::string> extraExtensions;
};
5 changes: 4 additions & 1 deletion layer_example/source/device.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: MIT
* ----------------------------------------------------------------------------
* Copyright (c) 2024 Arm Limited
* Copyright (c) 2024-2025 Arm Limited
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -39,6 +39,9 @@
*/
static std::unordered_map<void*, std::unique_ptr<Device>> g_devices;

/* See header for documentation. */
const std::vector<std::string> Device::extraExtensions { };

/* See header for documentation. */
void Device::store(
VkDevice handle,
Expand Down
18 changes: 12 additions & 6 deletions layer_example/source/device.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: MIT
* ----------------------------------------------------------------------------
* Copyright (c) 2024 Arm Limited
* Copyright (c) 2024-2025 Arm Limited
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -132,6 +132,17 @@ class Device
~Device() = default;

public:
/**
* @brief The driver function dispatch table.
*/
DeviceDispatchTable driver {};

/**
* @brief The minimum set of device extensions needed by this layer.
*/
static const std::vector<std::string> extraExtensions;

private:
/**
* @brief The instance this device is created with.
*/
Expand All @@ -146,9 +157,4 @@ class Device
* @brief The device handle this device is created with.
*/
const VkDevice device;

/**
* @brief The driver function dispatch table.
*/
DeviceDispatchTable driver {};
};
10 changes: 9 additions & 1 deletion layer_example/source/instance.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: MIT
* ----------------------------------------------------------------------------
* Copyright (c) 2024 Arm Limited
* Copyright (c) 2024-2025 Arm Limited
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -34,6 +34,14 @@
*/
static std::unordered_map<void*, std::unique_ptr<Instance>> g_instances;

/* See header for documentation. */
const APIVersion Instance::minAPIVersion { 1, 1 };

/* See header for documentation. */
const std::vector<std::string> Instance::extraExtensions {
"VK_EXT_debug_utils"
};

/* See header for documentation. */
void Instance::store(
VkInstance handle,
Expand Down
12 changes: 11 additions & 1 deletion layer_example/source/instance.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: MIT
* ----------------------------------------------------------------------------
* Copyright (c) 2024 Arm Limited
* Copyright (c) 2024-2025 Arm Limited
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -131,4 +131,14 @@ class Instance
* @brief The driver function dispatch table.
*/
InstanceDispatchTable driver {};

/**
* @brief The minimum API version needed by this layer.
*/
static const APIVersion minAPIVersion;

/**
* @brief The minimum set of instance extensions needed by this layer.
*/
static const std::vector<std::string> extraExtensions;
};
26 changes: 26 additions & 0 deletions layer_gpu_support/source/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
*/
static std::unordered_map<void*, std::unique_ptr<Device>> g_devices;

/* See header for documentation. */
const std::vector<std::string> Device::extraExtensions {
"VK_KHR_timeline_semaphore"
};

/* See header for documentation. */
void Device::store(
VkDevice handle,
Expand Down Expand Up @@ -88,4 +93,25 @@ Device::Device(
device(_device)
{
initDriverDeviceDispatchTable(device, nlayerGetProcAddress, driver);

VkSemaphoreTypeCreateInfo timelineCreateInfo {
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_TYPE_CREATE_INFO,
.pNext = nullptr,
.semaphoreType = VK_SEMAPHORE_TYPE_TIMELINE,
.initialValue = queueSerializationTimelineSemCount
};

VkSemaphoreCreateInfo createInfo {
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
.pNext = &timelineCreateInfo,
.flags = 0
};

auto result = driver.vkCreateSemaphore(
device, &createInfo, nullptr, &queueSerializationTimelineSem);
if (result != VK_SUCCESS)
{
LAYER_ERR("Failed vkCreateSemaphore() for queue serialization");
queueSerializationTimelineSem = nullptr;
}
}
26 changes: 21 additions & 5 deletions layer_gpu_support/source/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,27 @@ class Device
*/
const Instance* instance;

/**
* @brief The driver function dispatch table.
*/
DeviceDispatchTable driver {};

/**
* @brief The minimum set of device extensions needed by this layer.
*/
static const std::vector<std::string> extraExtensions;

/**
* @brief The timeline sem use for queue serialization.
*/
VkSemaphore queueSerializationTimelineSem { nullptr };

/**
* @brief The current timeline sem target value the next use waits for.
*/
uint64_t queueSerializationTimelineSemCount { 0 };

private:
/**
* @brief The physical device this device is created with.
*/
Expand All @@ -146,9 +167,4 @@ class Device
* @brief The device handle this device is created with.
*/
const VkDevice device;

/**
* @brief The driver function dispatch table.
*/
DeviceDispatchTable driver {};
};
8 changes: 8 additions & 0 deletions layer_gpu_support/source/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
*/
static std::unordered_map<void*, std::unique_ptr<Instance>> g_instances;

/* See header for documentation. */
const APIVersion Instance::minAPIVersion { 1, 1 };

/* See header for documentation. */
const std::vector<std::string> Instance::extraExtensions {
"VK_EXT_debug_utils"
};

/* See header for documentation. */
void Instance::store(
VkInstance handle,
Expand Down
10 changes: 10 additions & 0 deletions layer_gpu_support/source/instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,14 @@ class Instance
* @brief The layer configuration.
*/
const LayerConfig config;

/**
* @brief The minimum API version needed by this layer.
*/
static const APIVersion minAPIVersion;

/**
* @brief The minimum set of instance extensions needed by this layer.
*/
static const std::vector<std::string> extraExtensions;
};
Loading

0 comments on commit ad0271b

Please sign in to comment.