nouveau/headers: Deduplicate push dump impls

Note that this changes the output so it lists the method as being in the
class where it most recently changed rather than always in the class of
the running gpu. Personally, I find this more useful than the old
behavior.

Reviewed-by: Mary Guillemard <mary@mary.zone>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37475>
This commit is contained in:
Mel Henning
2025-09-19 20:25:50 -04:00
committed by Marge Bot
parent e471f20587
commit 246b96829f
2 changed files with 51 additions and 2 deletions

View File

@@ -169,14 +169,37 @@ TEMPLATE_C = Template("""\
%endif
</%def>
<%def name="prev_cases()">
%for mthd in methods:
%if prev_methods.get(mthd.name, None) == mthd:
${cases(mthd)}
%endif
%endfor
</%def>
%if prev_nvcl:
const char *P_PARSE_${prev_nvcl}_MTHD(uint16_t idx) ATTRIBUTE_COLD;
void P_DUMP_${prev_nvcl}_MTHD_DATA(FILE *fp, uint16_t idx, uint32_t data,
const char *prefix) ATTRIBUTE_COLD;
%endif
const char*
P_PARSE_${nvcl}_MTHD(uint16_t idx)
{
switch (idx) {
%if prev_nvcl:
${prev_cases()}
return P_PARSE_${prev_nvcl}_MTHD(idx);
%endif
%for mthd in methods:
%if mthd.is_array and mthd.array_size == 0:
<% continue %>
%endif
%if prev_methods.get(mthd.name, None) == mthd:
<% continue %>
%endif
%if mthd.is_array:
%for i in range(mthd.array_size):
case ${nvcl}_${mthd.name}(${i}):
@@ -187,6 +210,7 @@ P_PARSE_${nvcl}_MTHD(uint16_t idx)
return "${nvcl}_${mthd.name}";
%endif
%endfor
default:
return "unknown method";
}
@@ -198,10 +222,20 @@ P_DUMP_${nvcl}_MTHD_DATA(FILE *fp, uint16_t idx, uint32_t data,
{
UNUSED uint32_t parsed;
switch (idx) {
%if prev_nvcl:
${prev_cases()}
P_DUMP_${prev_nvcl}_MTHD_DATA(fp, idx, data, prefix);
break;
%endif
%for mthd in methods:
%if mthd.is_array and mthd.array_size == 0:
<% continue %>
%endif
%if prev_methods.get(mthd.name, None) == mthd:
<% continue %>
%endif
${cases(mthd)}
%for field in mthd.fields:
<% field_width = field.end - field.start + 1 %>
@@ -589,6 +623,7 @@ def main():
prev_mod = None
prev_methods = {}
prev_nvcl = None
if args.prev_in_h is not None:
prev_clheader = os.path.basename(args.prev_in_h)
prev_nvcl = nvcl_for_filename(prev_clheader)
@@ -603,6 +638,7 @@ def main():
'methods': list(methods.values()),
'prev_mod': prev_mod,
'prev_methods': prev_methods,
'prev_nvcl': prev_nvcl,
'to_camel': to_camel,
'bs': '\\'
}

View File

@@ -75,12 +75,25 @@ flat_nv_classes = ''
cl_generated = []
foreach cl : nv_classes
prev_cl_h = []
prev_cl_args = []
foreach prev_cl : nv_classes
if prev_cl == cl
break
endif
if prev_cl.substring(-2) == cl.substring(-2)
prev_cl_h = 'nvidia/classes/'+prev_cl+'.h'
prev_cl_args = ['--prev-in-h', '@INPUT2@']
endif
endforeach
flat_nv_classes = flat_nv_classes + cl + ' '
cl_generated += custom_target(
cl + '.h',
input : ['class_parser.py', 'nvidia/classes/'+cl+'.h', 'util.py'],
input : ['class_parser.py', 'nvidia/classes/'+cl+'.h', prev_cl_h, 'util.py'],
output : ['nv_push_'+cl+'.h', 'nv_push_'+cl+'.c'],
command : [prog_python, '@INPUT0@', '--in-h', '@INPUT1@',
command : [prog_python, '@INPUT0@', '--in-h', '@INPUT1@', prev_cl_args,
'--out-h', '@OUTPUT0@', '--out-c', '@OUTPUT1@'],
)
endforeach