misc: Add create_info struct to CreateInstance()
authorJon Ashburn <jon@lunarg.com>
Sat, 4 Apr 2015 20:52:07 +0000 (14:52 -0600)
committerChia-I Wu <olv@lunarg.com>
Thu, 16 Apr 2015 09:33:29 +0000 (17:33 +0800)
Allows extnesion or layer enablement at CreateInstance
Khronos Bug 13637

demos/cube.c
demos/tri.c
demos/xglinfo.c
icd/nulldrv/nulldrv.c
include/xgl.h
layers/glave_snapshot.c
layers/param_checker.cpp
loader/loader.c
xgl.py

index e8f174c..b356bc3 100644 (file)
@@ -1731,6 +1731,14 @@ static void demo_init_xgl(struct demo *demo)
         .engineVersion = 0,
         .apiVersion = XGL_API_VERSION,
     };
+    const XGL_INSTANCE_CREATE_INFO inst_info = {
+        .sType = XGL_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
+        .pNext = NULL,
+        .pAppInfo = &app,
+        .pAllocCb = NULL,
+        .extensionCount = 0,
+        .ppEnabledExtensionNames = NULL,
+    };
     const XGL_WSI_X11_CONNECTION_INFO connection = {
         .pConnection = demo->connection,
         .root = demo->screen->root,
@@ -1759,7 +1767,7 @@ static void demo_init_xgl(struct demo *demo)
     size_t data_size;
     uint32_t queue_count;
 
-    err = xglCreateInstance(&app, NULL, &demo->inst);
+    err = xglCreateInstance(&inst_info, &demo->inst);
     if (err == XGL_ERROR_INCOMPATIBLE_DRIVER) {
         printf("Cannot find a compatible Vulkan installable client driver "
                "(ICD).\nExiting ...\n");
@@ -1768,6 +1776,7 @@ static void demo_init_xgl(struct demo *demo)
     } else {
         assert(!err);
     }
+
     err = xglEnumerateGpus(demo->inst, 1, &gpu_count, &demo->gpu);
     assert(!err && gpu_count == 1);
 
index b702cab..1dfd5c9 100644 (file)
@@ -1253,6 +1253,14 @@ static void demo_init_xgl(struct demo *demo)
         .engineVersion = 0,
         .apiVersion = XGL_API_VERSION,
     };
+    const XGL_INSTANCE_CREATE_INFO inst_info = {
+        .sType = XGL_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
+        .pNext = NULL,
+        .pAppInfo = &app,
+        .pAllocCb = NULL,
+        .extensionCount = 0,
+        .ppEnabledExtensionNames = NULL,
+    };
     const XGL_WSI_X11_CONNECTION_INFO connection = {
         .pConnection = demo->connection,
         .root = demo->screen->root,
@@ -1281,7 +1289,7 @@ static void demo_init_xgl(struct demo *demo)
     size_t data_size;
     uint32_t queue_count;
 
-    err = xglCreateInstance(&app, NULL, &demo->inst);
+    err = xglCreateInstance(&inst_info, &demo->inst);
     if (err == XGL_ERROR_INCOMPATIBLE_DRIVER) {
         printf("Cannot find a compatible Vulkan installable client driver "
                "(ICD).\nExiting ...\n");
@@ -1290,6 +1298,7 @@ static void demo_init_xgl(struct demo *demo)
     } else {
         assert(!err);
     }
+
     err = xglEnumerateGpus(demo->inst, 1, &gpu_count, &demo->gpu);
     assert(!err && gpu_count == 1);
 
index 76d70c5..ace6d03 100644 (file)
@@ -652,19 +652,28 @@ int main(int argc, char **argv)
         .engineVersion = 1,
         .apiVersion = XGL_API_VERSION,
     };
+    static const XGL_INSTANCE_CREATE_INFO inst_info = {
+        .sType = XGL_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
+        .pNext = NULL,
+        .pAppInfo = &app_info,
+        .pAllocCb = NULL,
+        .extensionCount = 0,
+        .ppEnabledExtensionNames = NULL,
+    };
     struct app_gpu gpus[MAX_GPUS];
     XGL_PHYSICAL_GPU objs[MAX_GPUS];
     XGL_INSTANCE inst;
     uint32_t gpu_count, i;
     XGL_RESULT err;
 
-    err = xglCreateInstance(&app_info, NULL, &inst);
+    err = xglCreateInstance(&inst_info, &inst);
     if (err == XGL_ERROR_INCOMPATIBLE_DRIVER) {
         printf("Cannot find a compatible Vulkan installable client driver "
                "(ICD).\nExiting ...\n");
         fflush(stdout);
         exit(1);
     } else if (err) {
+
         ERR_EXIT(err);
     }
     err = xglEnumerateGpus(inst, MAX_GPUS, &gpu_count, objs);
index 43a35af..0769fc8 100644 (file)
@@ -1492,8 +1492,7 @@ ICD_EXPORT XGL_RESULT XGLAPI xglOpenPeerMemory(
 }
 
 ICD_EXPORT XGL_RESULT XGLAPI xglCreateInstance(
-    const XGL_APPLICATION_INFO*                 pAppInfo,
-    const XGL_ALLOC_CALLBACKS*                  pAllocCb,
+    const XGL_INSTANCE_CREATE_INFO*             pCreateInfo,
     XGL_INSTANCE*                               pInstance)
 {
     NULLDRV_LOG_FUNC;
index 92fb1cc..28c32d0 100644 (file)
@@ -1056,9 +1056,9 @@ typedef enum _XGL_STRUCTURE_TYPE
     XGL_STRUCTURE_TYPE_UPDATE_AS_COPY                       = 53,
     XGL_STRUCTURE_TYPE_MEMORY_ALLOC_BUFFER_INFO             = 54,
     XGL_STRUCTURE_TYPE_MEMORY_ALLOC_IMAGE_INFO              = 55,
-
+    XGL_STRUCTURE_TYPE_INSTANCE_CREATE_INFO                 = 56,
     XGL_STRUCTURE_TYPE_BEGIN_RANGE                          = XGL_STRUCTURE_TYPE_APPLICATION_INFO,
-    XGL_STRUCTURE_TYPE_END_RANGE                            = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_IMAGE_INFO,
+    XGL_STRUCTURE_TYPE_END_RANGE                            = XGL_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
     XGL_NUM_STRUCTURE_TYPE                                  = (XGL_STRUCTURE_TYPE_END_RANGE - XGL_STRUCTURE_TYPE_BEGIN_RANGE + 1),
     XGL_MAX_ENUM(_XGL_STRUCTURE_TYPE)
 } XGL_STRUCTURE_TYPE;
@@ -1411,6 +1411,17 @@ typedef struct _XGL_DEVICE_CREATE_INFO
     XGL_FLAGS                               flags;                      // XGL_DEVICE_CREATE_FLAGS
 } XGL_DEVICE_CREATE_INFO;
 
+typedef struct _XGL_INSTANCE_CREATE_INFO
+{
+    XGL_STRUCTURE_TYPE                      sType;                      // Should be XGL_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
+    const void*                             pNext;                      // Pointer to next structure
+    const XGL_APPLICATION_INFO*             pAppInfo;
+    const XGL_ALLOC_CALLBACKS*              pAllocCb;
+    uint32_t                                extensionCount;
+    const char*const*                       ppEnabledExtensionNames;    // layer or extension name to be enabled
+} XGL_INSTANCE_CREATE_INFO;
+
+// can be added to XGL_DEVICE_CREATE_INFO or XGL_INSTANCE_CREATE_INFO via pNext
 typedef struct _XGL_LAYER_CREATE_INFO
 {
     XGL_STRUCTURE_TYPE                      sType;                      // Should be XGL_STRUCTURE_TYPE_LAYER_CREATE_INFO
@@ -2252,7 +2263,7 @@ typedef struct _XGL_DISPATCH_INDIRECT_CMD
 
 // ------------------------------------------------------------------------------------------------
 // API functions
-typedef XGL_RESULT (XGLAPI *xglCreateInstanceType)(const XGL_APPLICATION_INFO* pAppInfo, const XGL_ALLOC_CALLBACKS* pAllocCb, XGL_INSTANCE* pInstance);
+typedef XGL_RESULT (XGLAPI *xglCreateInstanceType)(const XGL_INSTANCE_CREATE_INFO* pCreateInfo, XGL_INSTANCE* pInstance);
 typedef XGL_RESULT (XGLAPI *xglDestroyInstanceType)(XGL_INSTANCE instance);
 typedef XGL_RESULT (XGLAPI *xglEnumerateGpusType)(XGL_INSTANCE instance, uint32_t maxGpus, uint32_t* pGpuCount, XGL_PHYSICAL_GPU* pGpus);
 typedef XGL_RESULT (XGLAPI *xglGetGpuInfoType)(XGL_PHYSICAL_GPU gpu, XGL_PHYSICAL_GPU_INFO_TYPE infoType, size_t* pDataSize, void* pData);
@@ -2372,8 +2383,7 @@ typedef void       (XGLAPI *xglCmdEndRenderPassType)(XGL_CMD_BUFFER cmdBuffer, X
 // GPU initialization
 
 XGL_RESULT XGLAPI xglCreateInstance(
-    const XGL_APPLICATION_INFO*                 pAppInfo,
-    const XGL_ALLOC_CALLBACKS*                  pAllocCb,
+    const XGL_INSTANCE_CREATE_INFO*             pCreateInfo,
     XGL_INSTANCE*                               pInstance);
 
 XGL_RESULT XGLAPI xglDestroyInstance(
index 3af9744..e757f2b 100644 (file)
@@ -463,11 +463,11 @@ static void initGlaveSnapshot(void)
 //=============================================================================
 // vulkan entrypoints
 //=============================================================================
-XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateInstance(const XGL_APPLICATION_INFO* pAppInfo, const XGL_ALLOC_CALLBACKS* pAllocCb, XGL_INSTANCE* pInstance)
+XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateInstance(const XGL_INSTANCE_CREATE_INFO* pCreateInfo, XGL_INSTANCE* pInstance)
 {
-    XGL_RESULT result = nextTable.CreateInstance(pAppInfo, pAllocCb, pInstance);
+    XGL_RESULT result = nextTable.CreateInstance(pCreateInfo, pInstance);
     loader_platform_thread_lock_mutex(&objLock);
-
+    snapshot_insert_object(&s_delta, *pInstance, XGL_OBJECT_TYPE_INSTANCE);
     loader_platform_thread_unlock_mutex(&objLock);
     return result;
 }
index 6da0f0c..ebfe65f 100644 (file)
@@ -123,10 +123,10 @@ void PostCreateInstance(XGL_RESULT result, XGL_INSTANCE* pInstance)
     }
 }
 
-XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateInstance(const XGL_APPLICATION_INFO* pAppInfo, const XGL_ALLOC_CALLBACKS* pAllocCb, XGL_INSTANCE* pInstance)
+XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateInstance(const XGL_INSTANCE_CREATE_INFO* pCreateInfo, XGL_INSTANCE* pInstance)
 {
-    PreCreateInstance(pAppInfo, pAllocCb);
-    XGL_RESULT result = nextTable.CreateInstance(pAppInfo, pAllocCb, pInstance);
+    PreCreateInstance(pCreateInfo->pAppInfo, pCreateInfo->pAllocCb);
+    XGL_RESULT result = nextTable.CreateInstance(pCreateInfo, pInstance);
     PostCreateInstance(result, pInstance);
     return result;
 }
index 556c2b3..7ea486a 100644 (file)
@@ -858,9 +858,8 @@ extern uint32_t loader_activate_layers(XGL_PHYSICAL_GPU gpu, const XGL_DEVICE_CR
 }
 
 LOADER_EXPORT XGL_RESULT XGLAPI xglCreateInstance(
-        const XGL_APPLICATION_INFO*                 pAppInfo,
-        const XGL_ALLOC_CALLBACKS*                  pAllocCb,
-        XGL_INSTANCE*                               pInstance)
+        const XGL_INSTANCE_CREATE_INFO*         pCreateInfo,
+        XGL_INSTANCE*                           pInstance)
 {
     static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_icd);
     static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_layer);
@@ -888,7 +887,7 @@ LOADER_EXPORT XGL_RESULT XGLAPI xglCreateInstance(
     while (scanned_icds) {
         icd = loader_icd_add(ptr_instance, scanned_icds);
         if (icd) {
-            res = scanned_icds->CreateInstance(pAppInfo, pAllocCb,
+            res = scanned_icds->CreateInstance(pCreateInfo,
                                            &(scanned_icds->instance));
             if (res != XGL_SUCCESS)
             {
diff --git a/xgl.py b/xgl.py
index 1b372f0..3a2d728 100644 (file)
--- a/xgl.py
+++ b/xgl.py
@@ -218,8 +218,7 @@ core = Extension(
     ],
     protos=[
         Proto("XGL_RESULT", "CreateInstance",
-            [Param("const XGL_APPLICATION_INFO*", "pAppInfo"),
-             Param("const XGL_ALLOC_CALLBACKS*", "pAllocCb"),
+            [Param("const XGL_INSTANCE_CREATE_INFO*", "pCreateInfo"),
              Param("XGL_INSTANCE*", "pInstance")]),
 
         Proto("XGL_RESULT", "DestroyInstance",