Skip to content

Commit

Permalink
Fix libddi table query code generation (#256)
Browse files Browse the repository at this point in the history
- Fixed the libddi table query code generation to correctly handle the
  check for which ddi tables are required and which are optional to be
set by the driver.

Signed-off-by: Neil R. Spruit <[email protected]>
  • Loading branch information
nrspruit authored Jan 8, 2025
1 parent 3f0fb9d commit 4fd42f5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
13 changes: 9 additions & 4 deletions scripts/templates/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1709,6 +1709,7 @@ def get_class_function_objs(specs, cname, minVersion = 0, maxVersion = 9999):
def get_class_function_objs_exp(specs, cname):
objects = []
exp_objects = []
optional = True
for s in specs:
for obj in s['objects']:
is_function = obj_traits.is_function(obj)
Expand All @@ -1718,9 +1719,11 @@ def get_class_function_objs_exp(specs, cname):
exp_objects.append(obj)
else:
objects.append(obj)
if obj.get('version',"1.0") == "1.0":
optional = False
objects = sorted(objects, key=lambda obj: (float(obj.get('version',"1.0"))*10000) + int(obj.get('ordinal',"100")))
exp_objects = sorted(exp_objects, key=lambda obj: (float(obj.get('version',"1.0"))*10000) + int(obj.get('ordinal',"100")))
return objects, exp_objects
return objects, exp_objects, optional


"""
Expand Down Expand Up @@ -1752,7 +1755,7 @@ def get_callback_table_name(namespace, tags, obj):
def get_pfntables(specs, meta, namespace, tags):
tables = []
for cname in sorted(meta['class'], key=lambda x: meta['class'][x]['ordinal']):
objs, exp_objs = get_class_function_objs_exp(specs, cname)
objs, exp_objs, optional = get_class_function_objs_exp(specs, cname)
if len(objs) > 0:
name = get_table_name(namespace, tags, objs[0])
table = "%s_%s_dditable_t"%(namespace, _camel_to_snake(name))
Expand Down Expand Up @@ -1781,7 +1784,8 @@ def get_pfntables(specs, meta, namespace, tags):
'export': export,
'pfn': pfn,
'functions': objs,
'experimental': False
'experimental': False,
'optional': optional
})
if len(exp_objs) > 0:
name = get_table_name(namespace, tags, exp_objs[0])
Expand Down Expand Up @@ -1811,7 +1815,8 @@ def get_pfntables(specs, meta, namespace, tags):
'export': export,
'pfn': pfn,
'functions': exp_objs,
'experimental': True
'experimental': True,
'optional': True
})
return tables

Expand Down
12 changes: 12 additions & 0 deletions scripts/templates/libddi.cpp.mako
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,16 @@ namespace ${x}_lib
%for tbl in th.get_pfntables(specs, meta, n, tags):
if( ${X}_RESULT_SUCCESS == result )
{
%if tbl['optional'] == True:
// Optional
auto getTable = reinterpret_cast<${tbl['pfn']}>(
GET_FUNCTION_PTR(loader, "${tbl['export']['name']}") );
getTable( ${X}_API_VERSION_CURRENT, &initial${n}DdiTable.${tbl['name']} );
%else:
auto getTable = reinterpret_cast<${tbl['pfn']}>(
GET_FUNCTION_PTR(loader, "${tbl['export']['name']}") );
result = getTable( ${X}_API_VERSION_CURRENT, &initial${n}DdiTable.${tbl['name']} );
%endif
}

%endfor
Expand All @@ -49,7 +56,12 @@ namespace ${x}_lib
%for tbl in th.get_pfntables(specs, meta, n, tags):
if( ${X}_RESULT_SUCCESS == result )
{
%if tbl['optional'] == True:
// Optional
${tbl['export']['name']}( ${X}_API_VERSION_CURRENT, &initial${n}DdiTable.${tbl['name']} );
%else:
result = ${tbl['export']['name']}( ${X}_API_VERSION_CURRENT, &initial${n}DdiTable.${tbl['name']} );
%endif
}

%endfor
Expand Down

0 comments on commit 4fd42f5

Please sign in to comment.