@@ -944,9 +944,52 @@ SlangResult VKRenderer::initialize(const Desc& desc, void* inWindowHandle)
944
944
instanceCreateInfo.ppEnabledExtensionNames = &instanceExtensions[0 ];
945
945
946
946
#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
+ }
950
993
#endif
951
994
952
995
SLANG_VK_RETURN_ON_FAIL (m_api.vkCreateInstance (&instanceCreateInfo, nullptr , &instance));
0 commit comments