layers: Update GetExtensionSupport() to handle queries for layer name
authorJon Ashburn <jon@lunarg.com>
Thu, 2 Apr 2015 18:06:28 +0000 (12:06 -0600)
committerChia-I Wu <olv@lunarg.com>
Thu, 16 Apr 2015 09:33:29 +0000 (17:33 +0800)
Layers now support loader querying their layer name via GetExtensionSupport
in addition to EnumerateLayers.
Also fixed bugs in ObjectTracker and DrawState to add the extensions they
support in the GetExtensionSupport queries.

Conflicts:
xgl-layer-generate.py

layers/basic.cpp
layers/draw_state.cpp
layers/mem_tracker.cpp
layers/multi.cpp
xgl-layer-generate.py

index 2f3deac0b3b09f73f25cb84880fa069eeb4e2142..627dc879d7842f16ac411e97dc249a6e79ca3473 100644 (file)
@@ -63,23 +63,33 @@ XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglLayerExtension1(XGL_DEVICE device)
 
 XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglGetExtensionSupport(XGL_PHYSICAL_GPU gpu, const char* pExtName)
 {
-    XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) gpu;
     XGL_RESULT result;
-    XGL_LAYER_DISPATCH_TABLE* pTable = initLayerTable(gpuw);
+    XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) gpu;
 
-    printf("At start of wrapped xglGetExtensionSupport() call w/ gpu: %p\n", (void*)gpu);
+    /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
     if (!strncmp(pExtName, "xglLayerExtension1", strlen("xglLayerExtension1")))
+    {
+        result = XGL_SUCCESS;
+    } else if (!strncmp(pExtName, "Basic", strlen("Basic")))
+    {
         result = XGL_SUCCESS;
-    else
+    } else if (!tableMap.empty() && (tableMap.find(gpuw) != tableMap.end()))
+    {
+        printf("At start of wrapped xglGetExtensionSupport() call w/ gpu: %p\n", (void*)gpu);
+        XGL_LAYER_DISPATCH_TABLE* pTable = tableMap[gpuw];
         result = pTable->GetExtensionSupport((XGL_PHYSICAL_GPU)gpuw->nextObject, pExtName);
-    printf("Completed wrapped xglGetExtensionSupport() call w/ gpu: %p\n", (void*)gpu);
+        printf("Completed wrapped xglGetExtensionSupport() call w/ gpu: %p\n", (void*)gpu);
+    } else
+    {
+        result = XGL_ERROR_INVALID_EXTENSION;
+    }
     return result;
 }
 
 XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglCreateDevice(XGL_PHYSICAL_GPU gpu, const XGL_DEVICE_CREATE_INFO* pCreateInfo, XGL_DEVICE* pDevice)
 {
     XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) gpu;
-    XGL_LAYER_DISPATCH_TABLE* pTable = initLayerTable(gpuw);
+    XGL_LAYER_DISPATCH_TABLE* pTable = tableMap[gpuw];
 
     printf("At start of wrapped xglCreateDevice() call w/ gpu: %p\n", (void*)gpu);
     XGL_RESULT result = pTable->CreateDevice((XGL_PHYSICAL_GPU)gpuw->nextObject, pCreateInfo, pDevice);
index c23911920a6e65aa62720d49986ca06a795289eb..503c08acf354615ae3637be82b0e75c45a1c8a43 100644 (file)
@@ -1514,6 +1514,25 @@ XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglDestroyDevice(XGL_DEVICE device)
     return result;
 }
 
+XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglGetExtensionSupport(XGL_PHYSICAL_GPU gpu, const char* pExtName)
+{
+    XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) gpu;
+    XGL_RESULT result;
+    /* This entrypoint is NOT going to init its own dispatch table since loader calls here early */
+    if (!strcmp(pExtName, "DrawState") || !strcmp(pExtName, "drawStateDumpDotFile") ||
+        !strcmp(pExtName, "drawStateDumpCommandBufferDotFile") || !strcmp(pExtName, "drawStateDumpPngFile"))
+    {
+        result = XGL_SUCCESS;
+    } else if (nextTable.GetExtensionSupport != NULL)
+    {
+        result = nextTable.GetExtensionSupport((XGL_PHYSICAL_GPU)gpuw->nextObject, pExtName);
+    } else
+    {
+        result = XGL_ERROR_INVALID_EXTENSION;
+    }
+    return result;
+}
+
 XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglEnumerateLayers(XGL_PHYSICAL_GPU gpu, size_t maxLayerCount, size_t maxStringSize, size_t* pOutLayerCount, char* const* pOutLayers, void* pReserved)
 {
     if (gpu != NULL)
@@ -2741,6 +2760,8 @@ XGL_LAYER_EXPORT void* XGLAPI xglGetProcAddr(XGL_PHYSICAL_GPU gpu, const char* f
         return (void*) xglCreateDevice;
     if (!strcmp(funcName, "xglDestroyDevice"))
         return (void*) xglDestroyDevice;
+    if (!strcmp(funcName, "xglGetExtensionSupport"))
+        return (void*) xglGetExtensionSupport;
     if (!strcmp(funcName, "xglEnumerateLayers"))
         return (void*) xglEnumerateLayers;
     if (!strcmp(funcName, "xglQueueSubmit"))
index a6bc088a5872d459edf81c991b5a595a0cfc7448..5b47bfc58ce636860b95eab1a1a8c938d6efa738 100644 (file)
@@ -865,6 +865,24 @@ XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglDestroyDevice(XGL_DEVICE device)
     return result;
 }
 
+XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglGetExtensionSupport(XGL_PHYSICAL_GPU gpu, const char* pExtName)
+{
+    XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) gpu;
+    XGL_RESULT result;
+    /* This entrypoint is NOT going to init its own dispatch table since loader calls here early */
+    if (!strcmp(pExtName, "MemTracker"))
+    {
+        result = XGL_SUCCESS;
+    } else if (nextTable.GetExtensionSupport != NULL)
+    {
+        result = nextTable.GetExtensionSupport((XGL_PHYSICAL_GPU)gpuw->nextObject, pExtName);
+    } else
+    {
+        result = XGL_ERROR_INVALID_EXTENSION;
+    }
+    return result;
+}
+
 XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglEnumerateLayers(XGL_PHYSICAL_GPU gpu, size_t maxLayerCount,
     size_t maxStringSize, size_t* pOutLayerCount, char* const* pOutLayers, void* pReserved)
 {
@@ -1900,6 +1918,8 @@ XGL_LAYER_EXPORT void* XGLAPI xglGetProcAddr(XGL_PHYSICAL_GPU gpu, const char* f
         return (void*) xglCreateDevice;
     if (!strcmp(funcName, "xglDestroyDevice"))
         return (void*) xglDestroyDevice;
+    if (!strcmp(funcName, "xglGetExtensionSupport"))
+        return (void*) xglGetExtensionSupport;
     if (!strcmp(funcName, "xglEnumerateLayers"))
         return (void*) xglEnumerateLayers;
     if (!strcmp(funcName, "xglQueueSubmit"))
index 3a5e4fccf2dc3f7a43450a570267cc103097750e..f8c2bc9ffd2b18bd12653bde1a78548a9935873d 100644 (file)
@@ -132,6 +132,8 @@ XGL_LAYER_EXPORT void * XGLAPI multi1GetProcAddr(XGL_PHYSICAL_GPU gpu, const cha
         return (void *) multi1CreateGraphicsPipeline;
     else if (!strncmp("xglStorePipeline", pName, sizeof ("xglStorePipeline")))
         return (void *) multi1StorePipeline;
+    else if (!strncmp("xglGetExtensionSupport", pName, sizeof ("xglGetExtensionSupport")))
+        return (void *) xglGetExtensionSupport;
     else {
         if (gpuw->pGPA == NULL)
             return NULL;
@@ -232,6 +234,8 @@ XGL_LAYER_EXPORT void * XGLAPI multi2GetProcAddr(XGL_PHYSICAL_GPU gpu, const cha
         return (void *) multi2CreateCommandBuffer;
     else if (!strncmp("xglBeginCommandBuffer", pName, sizeof ("xglBeginCommandBuffer")))
         return (void *) multi2BeginCommandBuffer;
+    else if (!strncmp("xglGetExtensionSupport", pName, sizeof ("xglGetExtensionSupport")))
+        return (void *) xglGetExtensionSupport;
     else {
         if (gpuw->pGPA == NULL)
             return NULL;
@@ -255,6 +259,33 @@ XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglEnumerateLayers(XGL_PHYSICAL_GPU gpu, size
     return XGL_SUCCESS;
 }
 
+XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglGetExtensionSupport(XGL_PHYSICAL_GPU gpu, const char* pExtName)
+{
+    XGL_RESULT result;
+    XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) gpu;
+
+    /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
+    if (!strncmp(pExtName, "multi1", strlen("multi1")))
+    {
+        result = XGL_SUCCESS;
+    } else if (!strncmp(pExtName, "multi2", strlen("multi2")))
+    {
+        result = XGL_SUCCESS;
+    } else if (!tableMap1.empty() && (tableMap1.find(gpuw) != tableMap1.end()))
+    {
+        XGL_LAYER_DISPATCH_TABLE* pTable = tableMap1[gpuw];
+        result = pTable->GetExtensionSupport((XGL_PHYSICAL_GPU)gpuw->nextObject, pExtName);
+    } else if (!tableMap2.empty() && (tableMap2.find(gpuw) != tableMap2.end()))
+    {
+        XGL_LAYER_DISPATCH_TABLE* pTable = tableMap2[gpuw];
+        result = pTable->GetExtensionSupport((XGL_PHYSICAL_GPU)gpuw->nextObject, pExtName);
+    } else
+    {
+        result = XGL_ERROR_INVALID_EXTENSION;
+    }
+    return result;
+}
+
 XGL_LAYER_EXPORT void * XGLAPI xglGetProcAddr(XGL_PHYSICAL_GPU gpu, const char* pName)
 {
     // to find each layers GPA routine Loader will search via "<layerName>GetProcAddr"
index 01b1dd7480fb7ef2a9a9140c0cb64f890c7e4a33..38a08899d4074bbb22b0b7cc5a643cb9fbb39c35 100755 (executable)
@@ -194,6 +194,28 @@ class Subcommand(object):
         ur_body.append('}')
         return "\n".join(ur_body)
 
+    def _gen_layer_get_extension_support(self, layer="Generic"):
+        ges_body = []
+        ges_body.append('XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglGetExtensionSupport(XGL_PHYSICAL_GPU gpu, const char* pExtName)')
+        ges_body.append('{')
+        ges_body.append('    XGL_RESULT result;')
+        ges_body.append('    XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) gpu;')
+        ges_body.append('')
+        ges_body.append('    /* This entrypoint is NOT going to init its own dispatch table since loader calls here early */')
+        ges_body.append('    if (!strncmp(pExtName, "%s", strlen("%s")))' % (layer, layer))
+        ges_body.append('    {')
+        ges_body.append('        result = XGL_SUCCESS;')
+        ges_body.append('    } else if (nextTable.GetExtensionSupport != NULL)')
+        ges_body.append('    {')
+        ges_body.append('        result = nextTable.GetExtensionSupport((XGL_PHYSICAL_GPU)gpuw->nextObject, pExtName);')
+        ges_body.append('    } else')
+        ges_body.append('    {')
+        ges_body.append('        result = XGL_ERROR_INVALID_EXTENSION;')
+        ges_body.append('    }')
+        ges_body.append('    return result;')
+        ges_body.append('}')
+        return "\n".join(ges_body)
+
     def _generate_dispatch_entrypoints(self, qual=""):
         if qual:
             qual += " "
@@ -207,8 +229,10 @@ class Subcommand(object):
                     # fill in default intercept for certain entrypoints
                     if 'DbgRegisterMsgCallback' == proto.name:
                         intercept = self._gen_layer_dbg_callback_register()
-                    if 'DbgUnregisterMsgCallback' == proto.name:
+                    elif 'DbgUnregisterMsgCallback' == proto.name:
                         intercept = self._gen_layer_dbg_callback_unregister()
+                    elif 'GetExtensionSupport' == proto.name:
+                        funcs.append(self._gen_layer_get_extension_support(self.layer_name))
                 if intercept is not None:
                     funcs.append(intercept)
                     intercepted.append(proto)
@@ -236,7 +260,6 @@ class Subcommand(object):
         body.append("    return NULL;")
         body.append("}")
         funcs.append("\n".join(body))
-
         return "\n\n".join(funcs)
 
 
@@ -374,7 +397,7 @@ class GenericLayerSubcommand(Subcommand):
         return '#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include "loader_platform.h"\n#include "xglLayer.h"\n//The following is #included again to catch certain OS-specific functions being used:\n#include "loader_platform.h"\n\n#include "layers_config.h"\n#include "layers_msg.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\n\nstatic LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);'
 
     def generate_intercept(self, proto, qual):
-        if proto.name in [ 'DbgRegisterMsgCallback', 'DbgUnregisterMsgCallback' ]:
+        if proto.name in [ 'DbgRegisterMsgCallback', 'DbgUnregisterMsgCallback' , 'GetExtensionSupport']:
             # use default version
             return None
         decl = proto.c_func(prefix="xgl", attr="XGLAPI")
@@ -614,6 +637,26 @@ class ApiDumpSubcommand(Subcommand):
                      '        return XGL_SUCCESS;\n'
                      '    }\n'
                          '}' % (qual, decl, proto.params[0].name, self.layer_name, ret_val, c_call,f_open, log_func, f_close, stmt, self.layer_name))
+        elif 'GetExtensionSupport' == proto.name:
+            c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
+            funcs.append('%s%s\n'
+                         '{\n'
+                         '    XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
+                         '    XGL_RESULT result;\n'
+                         '    /* This entrypoint is NOT going to init its own dispatch table since loader calls here early */\n'
+                         '    if (!strncmp(pExtName, "%s", strlen("%s")))\n'
+                         '    {\n'
+                         '        result = XGL_SUCCESS;\n'
+                         '    } else if (nextTable.GetExtensionSupport != NULL)\n'
+                         '    {\n'
+                         '        result = nextTable.%s;\n'
+                         '        %s    %s        %s\n'
+                         '    } else\n'
+                         '    {\n'
+                         '        result = XGL_ERROR_INVALID_EXTENSION;\n'
+                         '    }\n'
+                         '%s'
+                         '}' % (qual, decl, proto.params[0].name, self.layer_name, self.layer_name, c_call, f_open, log_func, f_close, stmt))
         elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
             funcs.append('%s%s\n'
                      '{\n'
@@ -823,6 +866,26 @@ class ApiDumpCppSubcommand(Subcommand):
                      '        return XGL_SUCCESS;\n'
                      '    }\n'
                          '}' % (qual, decl, proto.params[0].name, self.layer_name, ret_val, c_call,f_open, log_func, f_close, stmt, self.layer_name))
+        elif 'GetExtensionSupport' == proto.name:
+            c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
+            funcs.append('%s%s\n'
+                         '{\n'
+                         '    XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
+                         '    XGL_RESULT result;\n'
+                         '    /* This entrypoint is NOT going to init its own dispatch table since loader calls here early */\n'
+                         '    if (!strncmp(pExtName, "%s", strlen("%s")))\n'
+                         '    {\n'
+                         '        result = XGL_SUCCESS;\n'
+                         '    } else if (nextTable.GetExtensionSupport != NULL)\n'
+                         '    {\n'
+                         '        result = nextTable.%s;\n'
+                         '        %s    %s        %s\n'
+                         '    } else\n'
+                         '    {\n'
+                         '        result = XGL_ERROR_INVALID_EXTENSION;\n'
+                         '    }\n'
+                         '%s'
+                         '}' % (qual, decl, proto.params[0].name, self.layer_name, self.layer_name, c_call, f_open, log_func, f_close, stmt))
         elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
             funcs.append('%s%s\n'
                      '{\n'
@@ -1378,6 +1441,28 @@ class ObjectTrackerSubcommand(Subcommand):
                      '        return XGL_SUCCESS;\n'
                      '    }\n'
                          '}' % (qual, decl, proto.params[0].name, using_line, self.layer_name, ret_val, c_call, create_line, destroy_line, stmt, self.layer_name))
+        elif 'GetExtensionSupport' == proto.name:
+            c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
+            funcs.append('%s%s\n'
+                     '{\n'
+                     '    XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
+                     '    XGL_RESULT result;\n'
+                     '    /* This entrypoint is NOT going to init its own dispatch table since loader calls this early */\n'
+                     '    if (!strncmp(pExtName, "%s", strlen("%s")) ||\n'
+                     '        !strncmp(pExtName, "objTrackGetObjectCount", strlen("objTrackGetObjectCount")) ||\n'
+                     '        !strncmp(pExtName, "objTrackGetObjects", strlen("objTrackGetObjects")))\n'
+                     '    {\n'
+                     '        result = XGL_SUCCESS;\n'
+                     '    } else if (nextTable.GetExtensionSupport != NULL)\n'
+                     '    {\n'
+                     '    %s'
+                     '        result = nextTable.%s;\n'
+                     '    } else\n'
+                     '    {\n'
+                     '        result = XGL_ERROR_INVALID_EXTENSION;\n'
+                     '    }\n'
+                     '%s'
+                     '}' % (qual, decl, proto.params[0].name, self.layer_name, self.layer_name, using_line, c_call,  stmt))
         elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
             funcs.append('%s%s\n'
                      '{\n'