tri/cube: Convert GPA usage/error-checking/reporting to a macro.
authorIan Elliott <ian@lunarg.com>
Mon, 22 Jun 2015 21:07:49 +0000 (15:07 -0600)
committerIan Elliott <ian@lunarg.com>
Mon, 22 Jun 2015 21:11:29 +0000 (15:11 -0600)
demos/cube.c
demos/tri.c

index 40e18d807b9cdf45aef2d70cb1f9bb11ab187284..633cc4c7ff71315e231ae486f083015f09cbacc5 100644 (file)
    } while (0)
 #endif // _WIN32
 
+#define GET_DEVICE_PROC_ADDR(dev, entrypoint)                           \
+{                                                                       \
+    demo->fp##entrypoint = vkGetDeviceProcAddr(dev, "vk"#entrypoint);   \
+    if (demo->fp##entrypoint == NULL) {                                 \
+        ERR_EXIT("vkGetDeviceProcAddr failed to find vk"#entrypoint,    \
+                 "vkGetDeviceProcAddr Failure");                        \
+    }                                                                   \
+}
+
 /*
  * structure to track all objects related to a texture.
  */
@@ -1983,22 +1992,11 @@ static void demo_init_vk(struct demo *demo)
     err = vkCreateDevice(demo->gpu, &device, &demo->device);
     assert(!err);
 
-    demo->fpCreateSwapChainWSI = vkGetDeviceProcAddr(demo->device, "vkCreateSwapChainWSI");
-    if (demo->fpCreateSwapChainWSI == NULL)
-        ERR_EXIT("vkGetDeviceProcAddr failed to find vkCreateSwapChainWSI",
-                                 "vkGetDeviceProcAddr Failure");
-    demo->fpDestroySwapChainWSI = vkGetDeviceProcAddr(demo->device, "vkDestroySwapChainWSI");
-    if (demo->fpDestroySwapChainWSI == NULL)
-        ERR_EXIT("vkGetDeviceProcAddr failed to find vkDestroySwapChainWSI",
-                                 "vkGetDeviceProcAddr Failure");
-    demo->fpGetSwapChainInfoWSI = vkGetDeviceProcAddr(demo->device, "vkGetSwapChainInfoWSI");
-    if (demo->fpGetSwapChainInfoWSI == NULL)
-        ERR_EXIT("vkGetDeviceProcAddr failed to find vkGetSwapChainInfoWSI",
-                                 "vkGetDeviceProcAddr Failure");
-    demo->fpQueuePresentWSI = vkGetDeviceProcAddr(demo->device, "vkQueuePresentWSI");
-    if (demo->fpQueuePresentWSI == NULL)
-        ERR_EXIT("vkGetDeviceProcAddr failed to find vkQueuePresentWSI",
-                                 "vkGetDeviceProcAddr Failure");
+    GET_DEVICE_PROC_ADDR(demo->device, CreateSwapChainWSI);
+    GET_DEVICE_PROC_ADDR(demo->device, CreateSwapChainWSI);
+    GET_DEVICE_PROC_ADDR(demo->device, DestroySwapChainWSI);
+    GET_DEVICE_PROC_ADDR(demo->device, GetSwapChainInfoWSI);
+    GET_DEVICE_PROC_ADDR(demo->device, QueuePresentWSI);
 
     err = vkGetPhysicalDeviceInfo(demo->gpu, VK_PHYSICAL_DEVICE_INFO_TYPE_PROPERTIES,
                         &data_size, NULL);
index 7ab1005f3b2fa68513a380a8e3c5d890d444c810..fd24944e91ed28bd3a874997a3a6769802a9d9cc 100644 (file)
    } while (0)
 #endif // _WIN32
 
+#define GET_DEVICE_PROC_ADDR(dev, entrypoint)                           \
+{                                                                       \
+    demo->fp##entrypoint = vkGetDeviceProcAddr(dev, "vk"#entrypoint);   \
+    if (demo->fp##entrypoint == NULL) {                                 \
+        ERR_EXIT("vkGetDeviceProcAddr failed to find vk"#entrypoint,    \
+                 "vkGetDeviceProcAddr Failure");                        \
+    }                                                                   \
+}
+
 struct texture_object {
     VkSampler sampler;
 
@@ -1430,23 +1439,6 @@ static void demo_init_vk(struct demo *demo)
                  "vkCreateInstance Failure");
     }
 
-    demo->fpCreateSwapChainWSI = vkGetDeviceProcAddr(demo->device, "vkCreateSwapChainWSI");
-    if (demo->fpCreateSwapChainWSI == NULL)
-        ERR_EXIT("vkGetDeviceProcAddr failed to find vkCreateSwapChainWSI",
-                                 "vkGetDeviceProcAddr Failure");
-    demo->fpDestroySwapChainWSI = vkGetDeviceProcAddr(demo->device, "vkDestroySwapChainWSI");
-    if (demo->fpDestroySwapChainWSI == NULL)
-        ERR_EXIT("vkGetDeviceProcAddr failed to find vkDestroySwapChainWSI",
-                                 "vkGetDeviceProcAddr Failure");
-    demo->fpGetSwapChainInfoWSI = vkGetDeviceProcAddr(demo->device, "vkGetSwapChainInfoWSI");
-    if (demo->fpGetSwapChainInfoWSI == NULL)
-        ERR_EXIT("vkGetDeviceProcAddr failed to find vkGetSwapChainInfoWSI",
-                                 "vkGetDeviceProcAddr Failure");
-    demo->fpQueuePresentWSI = vkGetDeviceProcAddr(demo->device, "vkQueuePresentWSI");
-    if (demo->fpQueuePresentWSI == NULL)
-        ERR_EXIT("vkGetDeviceProcAddr failed to find vkQueuePresentWSI",
-                                 "vkGetDeviceProcAddr Failure");
-
     gpu_count = 1;
     err = vkEnumeratePhysicalDevices(demo->inst, &gpu_count, &demo->gpu);
     assert(!err && gpu_count == 1);
@@ -1454,6 +1446,12 @@ static void demo_init_vk(struct demo *demo)
     err = vkCreateDevice(demo->gpu, &device, &demo->device);
     assert(!err);
 
+    GET_DEVICE_PROC_ADDR(demo->device, CreateSwapChainWSI);
+    GET_DEVICE_PROC_ADDR(demo->device, CreateSwapChainWSI);
+    GET_DEVICE_PROC_ADDR(demo->device, DestroySwapChainWSI);
+    GET_DEVICE_PROC_ADDR(demo->device, GetSwapChainInfoWSI);
+    GET_DEVICE_PROC_ADDR(demo->device, QueuePresentWSI);
+
     err = vkGetPhysicalDeviceInfo(demo->gpu, VK_PHYSICAL_DEVICE_INFO_TYPE_PROPERTIES,
                         &data_size, NULL);
     assert(!err);