Skip to content

Commit 24ecd1f

Browse files
Use new vulkan debug layer. (shader-slang#1566)
* Use new vulkan debug layer. * Try use VK_LAYER_KHRONOS_validation when it exists. Co-authored-by: Tim Foley <tim.foley.is@gmail.com>
1 parent aadf600 commit 24ecd1f

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

tools/gfx/vulkan/render-vk.cpp

+46-3
Original file line numberDiff line numberDiff line change
@@ -944,9 +944,52 @@ SlangResult VKRenderer::initialize(const Desc& desc, void* inWindowHandle)
944944
instanceCreateInfo.ppEnabledExtensionNames = &instanceExtensions[0];
945945

946946
#if ENABLE_VALIDATION_LAYER
947-
const char* layerNames[] = { "VK_LAYER_LUNARG_standard_validation" };
948-
instanceCreateInfo.enabledLayerCount = SLANG_COUNT_OF(layerNames);
949-
instanceCreateInfo.ppEnabledLayerNames = layerNames;
947+
// Depending on driver version, validation layer may or may not exist.
948+
// Newer drivers comes with "VK_LAYER_KHRONOS_validation", while older
949+
// drivers provide only the deprecated
950+
// "VK_LAYER_LUNARG_standard_validation" layer.
951+
// We will check what layers are available, and use the newer
952+
// "VK_LAYER_KHRONOS_validation" layer when possible.
953+
uint32_t layerCount;
954+
m_api.vkEnumerateInstanceLayerProperties(&layerCount, nullptr);
955+
956+
List<VkLayerProperties> availableLayers;
957+
availableLayers.setCount(layerCount);
958+
m_api.vkEnumerateInstanceLayerProperties(&layerCount, availableLayers.getBuffer());
959+
960+
const char* layerNames[] = { nullptr };
961+
for (auto& layer : availableLayers)
962+
{
963+
if (strncmp(
964+
layer.layerName,
965+
"VK_LAYER_KHRONOS_validation",
966+
sizeof("VK_LAYER_KHRONOS_validation")) == 0)
967+
{
968+
layerNames[0] = "VK_LAYER_KHRONOS_validation";
969+
break;
970+
}
971+
}
972+
// On older drivers, only "VK_LAYER_LUNARG_standard_validation" exists,
973+
// so we try to use it if we can't find "VK_LAYER_KHRONOS_validation".
974+
if (!layerNames[0])
975+
{
976+
for (auto& layer : availableLayers)
977+
{
978+
if (strncmp(
979+
layer.layerName,
980+
"VK_LAYER_LUNARG_standard_validation",
981+
sizeof("VK_LAYER_LUNARG_standard_validation")) == 0)
982+
{
983+
layerNames[0] = "VK_LAYER_LUNARG_standard_validation";
984+
break;
985+
}
986+
}
987+
}
988+
if (layerNames[0])
989+
{
990+
instanceCreateInfo.enabledLayerCount = SLANG_COUNT_OF(layerNames);
991+
instanceCreateInfo.ppEnabledLayerNames = layerNames;
992+
}
950993
#endif
951994

952995
SLANG_VK_RETURN_ON_FAIL(m_api.vkCreateInstance(&instanceCreateInfo, nullptr, &instance));

tools/gfx/vulkan/vk-api.h

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace gfx {
88
#define VK_API_GLOBAL_PROCS(x) \
99
x(vkGetInstanceProcAddr) \
1010
x(vkCreateInstance) \
11+
x(vkEnumerateInstanceLayerProperties) \
1112
/* */
1213

1314
#define VK_API_INSTANCE_PROCS_OPT(x) \

0 commit comments

Comments
 (0)