diff options
| author | skallweitNV <64953474+skallweitNV@users.noreply.github.com> | 2023-01-27 20:53:57 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-27 11:53:57 -0800 |
| commit | 93a6b6119b6b65c4f6b00ca12d745e21b679c82f (patch) | |
| tree | 53bc1a3360d34ae6d15318eebf07245367387b9d /examples/hello-world/vulkan-api.cpp | |
| parent | 9f6b6fb9f1bdde8ef01640257544f0e3c9db9076 (diff) | |
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
Diffstat (limited to 'examples/hello-world/vulkan-api.cpp')
| -rw-r--r-- | examples/hello-world/vulkan-api.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
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 <stdlib.h> #include <stdio.h> #include <assert.h> +#include <string.h> #include <vector> #if SLANG_WINDOWS_FAMILY @@ -51,6 +52,24 @@ int initializeVulkanDevice(VulkanAPI& api) if (!api.vkCreateInstance) return -1; + // Enable validation layer if available. + std::vector<const char*> 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<const char*> layers; -#ifdef ENABLE_VALIDATION_LAYER - layers.push_back("VK_LAYER_KHRONOS_validation"); -#endif if (layers.size()) { instanceCreateInfo.ppEnabledLayerNames = &layers[0]; |
