summaryrefslogtreecommitdiffstats
path: root/tools/gfx/vulkan/render-vk.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2020-10-02 12:53:29 -0700
committerGitHub <noreply@github.com>2020-10-02 12:53:29 -0700
commit24ecd1fa2f37f3c4949989b53562e8f85833a8f6 (patch)
treee9f56c63d53db4b02fc454f6f9e3642e857ede1c /tools/gfx/vulkan/render-vk.cpp
parentaadf6002783b88ea79c30a2f908270685b6c3d27 (diff)
Use new vulkan debug layer. (#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>
Diffstat (limited to 'tools/gfx/vulkan/render-vk.cpp')
-rw-r--r--tools/gfx/vulkan/render-vk.cpp49
1 files changed, 46 insertions, 3 deletions
diff --git a/tools/gfx/vulkan/render-vk.cpp b/tools/gfx/vulkan/render-vk.cpp
index 28567a3b8..b312d4b23 100644
--- a/tools/gfx/vulkan/render-vk.cpp
+++ b/tools/gfx/vulkan/render-vk.cpp
@@ -944,9 +944,52 @@ SlangResult VKRenderer::initialize(const Desc& desc, void* inWindowHandle)
instanceCreateInfo.ppEnabledExtensionNames = &instanceExtensions[0];
#if ENABLE_VALIDATION_LAYER
- const char* layerNames[] = { "VK_LAYER_LUNARG_standard_validation" };
- instanceCreateInfo.enabledLayerCount = SLANG_COUNT_OF(layerNames);
- instanceCreateInfo.ppEnabledLayerNames = layerNames;
+ // Depending on driver version, validation layer may or may not exist.
+ // Newer drivers comes with "VK_LAYER_KHRONOS_validation", while older
+ // drivers provide only the deprecated
+ // "VK_LAYER_LUNARG_standard_validation" layer.
+ // We will check what layers are available, and use the newer
+ // "VK_LAYER_KHRONOS_validation" layer when possible.
+ uint32_t layerCount;
+ m_api.vkEnumerateInstanceLayerProperties(&layerCount, nullptr);
+
+ List<VkLayerProperties> availableLayers;
+ availableLayers.setCount(layerCount);
+ m_api.vkEnumerateInstanceLayerProperties(&layerCount, availableLayers.getBuffer());
+
+ const char* layerNames[] = { nullptr };
+ for (auto& layer : availableLayers)
+ {
+ if (strncmp(
+ layer.layerName,
+ "VK_LAYER_KHRONOS_validation",
+ sizeof("VK_LAYER_KHRONOS_validation")) == 0)
+ {
+ layerNames[0] = "VK_LAYER_KHRONOS_validation";
+ break;
+ }
+ }
+ // On older drivers, only "VK_LAYER_LUNARG_standard_validation" exists,
+ // so we try to use it if we can't find "VK_LAYER_KHRONOS_validation".
+ if (!layerNames[0])
+ {
+ for (auto& layer : availableLayers)
+ {
+ if (strncmp(
+ layer.layerName,
+ "VK_LAYER_LUNARG_standard_validation",
+ sizeof("VK_LAYER_LUNARG_standard_validation")) == 0)
+ {
+ layerNames[0] = "VK_LAYER_LUNARG_standard_validation";
+ break;
+ }
+ }
+ }
+ if (layerNames[0])
+ {
+ instanceCreateInfo.enabledLayerCount = SLANG_COUNT_OF(layerNames);
+ instanceCreateInfo.ppEnabledLayerNames = layerNames;
+ }
#endif
SLANG_VK_RETURN_ON_FAIL(m_api.vkCreateInstance(&instanceCreateInfo, nullptr, &instance));