From 93a6b6119b6b65c4f6b00ca12d745e21b679c82f Mon Sep 17 00:00:00 2001 From: skallweitNV <64953474+skallweitNV@users.noreply.github.com> Date: Fri, 27 Jan 2023 20:53:57 +0100 Subject: Add ASAN support + fixes (#2614) * Add ASAN support to premake * Fix StringRepresentation when ASAN is enabled * Fix deep recursion in slang-generate * Fix hello-world example * Fix gpu-printing example * Linux fix * Try fixing linux * Add missing include --- examples/hello-world/vulkan-api.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'examples/hello-world/vulkan-api.cpp') diff --git a/examples/hello-world/vulkan-api.cpp b/examples/hello-world/vulkan-api.cpp index 529ca7196..d2d8aefa6 100644 --- a/examples/hello-world/vulkan-api.cpp +++ b/examples/hello-world/vulkan-api.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #if SLANG_WINDOWS_FAMILY @@ -51,6 +52,24 @@ int initializeVulkanDevice(VulkanAPI& api) if (!api.vkCreateInstance) return -1; + // Enable validation layer if available. + std::vector layers; +#ifdef ENABLE_VALIDATION_LAYER + uint32_t propertyCount; + if (api.vkEnumerateInstanceLayerProperties(&propertyCount, nullptr) != 0) + return -1; + std::vector< VkLayerProperties> properties(propertyCount); + if (api.vkEnumerateInstanceLayerProperties(&propertyCount, properties.data()) != 0) + return -1; + for (const auto& p : properties) + { + if (strcmp(p.layerName, "VK_LAYER_KHRONOS_validation") == 0) + { + layers.push_back("VK_LAYER_KHRONOS_validation"); + } + } +#endif + // Create Vulkan Instance. VkApplicationInfo applicationInfo = {VK_STRUCTURE_TYPE_APPLICATION_INFO}; applicationInfo.pApplicationName = "slang-hello-world"; @@ -66,10 +85,6 @@ int initializeVulkanDevice(VulkanAPI& api) instanceCreateInfo.pApplicationInfo = &applicationInfo; instanceCreateInfo.enabledExtensionCount = SLANG_COUNT_OF(instanceExtensions); instanceCreateInfo.ppEnabledExtensionNames = &instanceExtensions[0]; - std::vector layers; -#ifdef ENABLE_VALIDATION_LAYER - layers.push_back("VK_LAYER_KHRONOS_validation"); -#endif if (layers.size()) { instanceCreateInfo.ppEnabledLayerNames = &layers[0]; -- cgit v1.2.3