chassis: Handle GetDevProcAddr of Inst funcs
Calling GetDeviceProcAddress on an instance function should return
null. Added flag to funcptr_map.
Change-Id: I49fb4c1d2d4ae55c76f9ae647689ad6703cf5df9
diff --git a/scripts/layer_chassis_generator.py b/scripts/layer_chassis_generator.py
index e901a3f..82a2486 100644
--- a/scripts/layer_chassis_generator.py
+++ b/scripts/layer_chassis_generator.py
@@ -489,8 +489,12 @@
{VK_EXT_DEBUG_MARKER_EXTENSION_NAME, VK_EXT_DEBUG_MARKER_SPEC_VERSION},
};
-extern const std::unordered_map<std::string, void*> name_to_funcptr_map;
+typedef struct {
+ bool is_instance_api;
+ void* funcptr;
+} function_data;
+extern const std::unordered_map<std::string, function_data> name_to_funcptr_map;
// Manually written functions
@@ -724,7 +728,11 @@
}
const auto &item = name_to_funcptr_map.find(funcName);
if (item != name_to_funcptr_map.end()) {
- return reinterpret_cast<PFN_vkVoidFunction>(item->second);
+ if (item->second.is_instance_api) {
+ return nullptr;
+ } else {
+ return reinterpret_cast<PFN_vkVoidFunction>(item->second.funcptr);
+ }
}
auto &table = layer_data->device_dispatch_table;
if (!table.GetDeviceProcAddr) return nullptr;
@@ -734,7 +742,7 @@
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance instance, const char *funcName) {
const auto &item = name_to_funcptr_map.find(funcName);
if (item != name_to_funcptr_map.end()) {
- return reinterpret_cast<PFN_vkVoidFunction>(item->second);
+ return reinterpret_cast<PFN_vkVoidFunction>(item->second.funcptr);
}
auto layer_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map);
auto &table = layer_data->instance_dispatch_table;
@@ -1531,8 +1539,8 @@
self.newline()
if not self.header:
# Record intercepted procedures
- write('// Map of all APIs to be intercepted by this layer', file=self.outFile)
- write('const std::unordered_map<std::string, void*> name_to_funcptr_map = {', file=self.outFile)
+ write('// Map of intercepted ApiName to its associated function data', file=self.outFile)
+ write('const std::unordered_map<std::string, function_data> name_to_funcptr_map = {', file=self.outFile)
write('\n'.join(self.intercepts), file=self.outFile)
write('};\n', file=self.outFile)
self.newline()
@@ -1649,18 +1657,24 @@
self.layer_factory += '#endif\n'
return
+ is_instance = 'false'
+ dispatchable_type = cmdinfo.elem.find('param/type').text
+ if dispatchable_type in ["VkPhysicalDevice", "VkInstance"] or name == 'vkCreateInstance':
+ is_instance = 'true'
+
if name in self.manual_functions:
if 'ValidationCache' not in name:
- self.intercepts += [ ' {"%s", (void*)%s},' % (name,name[2:]) ]
+ self.intercepts += [ ' {"%s", {%s, (void*)%s}},' % (name, is_instance, name[2:]) ]
else:
self.intercepts += [ '#ifdef BUILD_CORE_VALIDATION' ]
- self.intercepts += [ ' {"%s", (void*)%s},' % (name,name[2:]) ]
+
+ self.intercepts += [ ' {"%s", {%s, (void*)%s}},' % (name, is_instance, name[2:]) ]
self.intercepts += [ '#endif' ]
return
# Record that the function will be intercepted
if (self.featureExtraProtect != None):
self.intercepts += [ '#ifdef %s' % self.featureExtraProtect ]
- self.intercepts += [ ' {"%s", (void*)%s},' % (name,name[2:]) ]
+ self.intercepts += [ ' {"%s", {%s, (void*)%s}},' % (name, is_instance, name[2:]) ]
if (self.featureExtraProtect != None):
self.intercepts += [ '#endif' ]
OutputGenerator.genCmd(self, cmdinfo, name, alias)
@@ -1669,15 +1683,7 @@
self.appendSection('command', '')
self.appendSection('command', '%s {' % decls[0][:-1])
# Setup common to call wrappers. First parameter is always dispatchable
- dispatchable_type = cmdinfo.elem.find('param/type').text
dispatchable_name = cmdinfo.elem.find('param/name').text
- # Default to device
- device_or_instance = 'device'
- dispatch_table_name = 'VkLayerDispatchTable'
- # Set to instance as necessary
- if dispatchable_type in ["VkPhysicalDevice", "VkInstance"] or name == 'vkCreateInstance':
- device_or_instance = 'instance'
- dispatch_table_name = 'VkLayerInstanceDispatchTable'
self.appendSection('command', ' auto layer_data = GetLayerDataPtr(get_dispatch_key(%s), layer_data_map);' % (dispatchable_name))
api_function_name = cmdinfo.elem.attrib.get('name')
params = cmdinfo.elem.findall('param/name')