1 2template = """\ 3/* Copyright (C) 2018 Red Hat 4 * Copyright (C) 2020 Valve 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 "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice (including the next 14 * paragraph) shall be included in all copies or substantial portions of the 15 * Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 23 * IN THE SOFTWARE. 24 */ 25 26#ifndef _NIR_INTRINSICS_INDICES_ 27#define _NIR_INTRINSICS_INDICES_ 28 29% for index in INTR_INDICES: 30<% 31data_type = index.c_data_type 32name = index.name 33enum = "NIR_INTRINSIC_" + name.upper() 34%> 35 36static inline ${data_type} 37nir_intrinsic_${name}(const nir_intrinsic_instr *instr) 38{ 39 const nir_intrinsic_info *info = &nir_intrinsic_infos[instr->intrinsic]; 40 assert(info->index_map[${enum}] > 0); 41% if "struct" in data_type: 42 ${data_type} res; 43 STATIC_ASSERT(sizeof(instr->const_index[0]) == sizeof(res)); 44 memcpy(&res, &instr->const_index[info->index_map[${enum}] - 1], sizeof(res)); 45 return res; 46% else: 47 return (${data_type})instr->const_index[info->index_map[${enum}] - 1]; 48% endif 49} 50 51static inline void 52nir_intrinsic_set_${name}(nir_intrinsic_instr *instr, ${data_type} val) 53{ 54 const nir_intrinsic_info *info = &nir_intrinsic_infos[instr->intrinsic]; 55 assert(info->index_map[${enum}] > 0); 56% if "struct" in data_type: 57% if name == "io_semantics": 58 val._pad = 0; /* clear padding bits */ 59% endif 60 STATIC_ASSERT(sizeof(instr->const_index[0]) == sizeof(val)); 61 memcpy(&instr->const_index[info->index_map[${enum}] - 1], &val, sizeof(val)); 62% else: 63 instr->const_index[info->index_map[${enum}] - 1] = val; 64% endif 65} 66 67static inline bool 68nir_intrinsic_has_${name}(const nir_intrinsic_instr *instr) 69{ 70 const nir_intrinsic_info *info = &nir_intrinsic_infos[instr->intrinsic]; 71 return info->index_map[${enum}] > 0; 72} 73% endfor 74 75#endif /* _NIR_INTRINSICS_INDICES_ */""" 76 77from nir_intrinsics import INTR_INDICES 78from mako.template import Template 79import argparse 80import os 81 82 83def main(): 84 parser = argparse.ArgumentParser() 85 parser.add_argument('--outdir', required=True, 86 help='Directory to put the generated files in') 87 88 args = parser.parse_args() 89 90 path = os.path.join(args.outdir, 'nir_intrinsics_indices.h') 91 with open(path, 'w') as f: 92 f.write(Template(template).render(INTR_INDICES=INTR_INDICES)) 93 94if __name__ == '__main__': 95 main() 96 97