1#!/usr/bin/env python3 2COPYRIGHT = """\ 3/* 4 * Copyright 2024 Intel Corporation 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 */ 26""" 27 28import argparse 29import os 30import sys 31 32from mako.template import Template 33from mako import exceptions 34 35sys.path.append(f"{os.path.dirname(sys.argv[0])}/../dev") 36import intel_device_info 37 38template = COPYRIGHT + """ 39 40/* DO NOT EDIT - This file generated automatically by intel_device_serialize_c.py script */ 41 42#include "dev/intel_device_info.h" 43#include "brw_compiler.h" 44#define SHA_UPDATE_FIELD(field) _mesa_sha1_update(ctx, &devinfo->field, sizeof(devinfo->field)) 45 46void 47brw_device_sha1_update(struct mesa_sha1 *ctx, 48 const struct intel_device_info *devinfo) { 49% for member in compiler_fields: 50% if member.ray_tracing_field: 51 if (devinfo->has_ray_tracing) 52 SHA_UPDATE_FIELD(${member.name}); 53% else: 54 SHA_UPDATE_FIELD(${member.name}); 55% endif 56% endfor 57} 58 59#undef SHA_UPDATE_FIELD 60 61""" 62 63def main(): 64 """print intel_device_serialize.c at the specified path""" 65 parser = argparse.ArgumentParser() 66 parser.add_argument('--outdir', required=True, 67 help='Directory to put the generated files in') 68 args = parser.parse_args() 69 path = os.path.join(args.outdir, 'brw_device_sha1_gen.c') 70 device_members = intel_device_info.TYPES_BY_NAME["intel_device_info"].members 71 compiler_fields = [field for field in device_members if field.compiler_field] 72 with open(path, 'w', encoding='utf-8') as f: 73 try: 74 f.write(Template(template).render(compiler_fields=compiler_fields)) 75 except: 76 print(exceptions.text_error_template().render(compiler_fields=compiler_fields)) 77 78if __name__ == "__main__": 79 main() 80