Skip to content

Commit 5144804

Browse files
committed
hello_xr: Minor tweaks in vulkan plugin around lifetimes.
1 parent f68aff4 commit 5144804

1 file changed

Lines changed: 24 additions & 20 deletions

File tree

src/tests/hello_xr/graphicsplugin_vulkan.cpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,8 @@ struct VulkanGraphicsPlugin : public IGraphicsPlugin {
12291229

12301230
std::vector<std::string> GetInstanceExtensions() const override { return {XR_KHR_VULKAN_ENABLE_EXTENSION_NAME}; }
12311231

1232+
// Note: The output must not outlive the input - this modifies the input and returns a collection of views into that modified
1233+
// input!
12321234
std::vector<const char*> ParseExtensionString(char* names) {
12331235
std::vector<const char*> list;
12341236
while (*names != 0) {
@@ -1263,30 +1265,32 @@ struct VulkanGraphicsPlugin : public IGraphicsPlugin {
12631265
CHECK_XRCMD(
12641266
pfnGetVulkanInstanceExtensionsKHR(instance, systemId, extensionNamesSize, &extensionNamesSize, &extensionNames[0]));
12651267

1266-
std::vector<const char*> extensions = ParseExtensionString(&extensionNames[0]);
1267-
extensions.push_back("VK_EXT_debug_report");
1268+
{
1269+
// Note: This cannot outlive the extensionNames above, since it's just a collection of views into that string!
1270+
std::vector<const char*> extensions = ParseExtensionString(&extensionNames[0]);
1271+
extensions.push_back("VK_EXT_debug_report");
12681272

1269-
std::vector<const char*> layers;
1273+
std::vector<const char*> layers;
12701274
#if defined(_DEBUG)
1271-
layers.push_back("VK_LAYER_LUNARG_standard_validation");
1275+
layers.push_back("VK_LAYER_LUNARG_standard_validation");
12721276
#endif
12731277

1274-
VkApplicationInfo appInfo{VK_STRUCTURE_TYPE_APPLICATION_INFO};
1275-
appInfo.pApplicationName = "hello_xr";
1276-
appInfo.applicationVersion = 1;
1277-
appInfo.pEngineName = "hello_xr";
1278-
appInfo.engineVersion = 1;
1279-
appInfo.apiVersion = VK_API_VERSION_1_0;
1280-
1281-
VkInstanceCreateInfo instInfo{VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO};
1282-
instInfo.pApplicationInfo = &appInfo;
1283-
instInfo.enabledLayerCount = (uint32_t)layers.size();
1284-
instInfo.ppEnabledLayerNames = layers.empty() ? nullptr : layers.data();
1285-
instInfo.enabledExtensionCount = (uint32_t)extensions.size();
1286-
instInfo.ppEnabledExtensionNames = extensions.empty() ? nullptr : extensions.data();
1287-
1288-
CHECK_VKCMD(vkCreateInstance(&instInfo, nullptr, &m_vkInstance));
1289-
1278+
VkApplicationInfo appInfo{VK_STRUCTURE_TYPE_APPLICATION_INFO};
1279+
appInfo.pApplicationName = "hello_xr";
1280+
appInfo.applicationVersion = 1;
1281+
appInfo.pEngineName = "hello_xr";
1282+
appInfo.engineVersion = 1;
1283+
appInfo.apiVersion = VK_API_VERSION_1_0;
1284+
1285+
VkInstanceCreateInfo instInfo{VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO};
1286+
instInfo.pApplicationInfo = &appInfo;
1287+
instInfo.enabledLayerCount = (uint32_t)layers.size();
1288+
instInfo.ppEnabledLayerNames = layers.empty() ? nullptr : layers.data();
1289+
instInfo.enabledExtensionCount = (uint32_t)extensions.size();
1290+
instInfo.ppEnabledExtensionNames = extensions.empty() ? nullptr : extensions.data();
1291+
1292+
CHECK_VKCMD(vkCreateInstance(&instInfo, nullptr, &m_vkInstance));
1293+
}
12901294
vkCreateDebugReportCallbackEXT =
12911295
(PFN_vkCreateDebugReportCallbackEXT)vkGetInstanceProcAddr(m_vkInstance, "vkCreateDebugReportCallbackEXT");
12921296
vkDestroyDebugReportCallbackEXT =

0 commit comments

Comments
 (0)