3
/* Copyright (C) 2018 Red Hat
4
* Copyright (C) 2020 Valve Corporation
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:
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
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
26
#ifndef _NIR_INTRINSICS_INDICES_
27
#define _NIR_INTRINSICS_INDICES_
29
% for index in INTR_INDICES:
31
data_type = index.c_data_type
33
enum = "NIR_INTRINSIC_" + name.upper()
36
static inline ${data_type}
37
nir_intrinsic_${name}(const nir_intrinsic_instr *instr)
39
const nir_intrinsic_info *info = &nir_intrinsic_infos[instr->intrinsic];
40
assert(info->index_map[${enum}] > 0);
41
% if "struct" in data_type:
43
STATIC_ASSERT(sizeof(instr->const_index[0]) == sizeof(res));
44
memcpy(&res, &instr->const_index[info->index_map[${enum}] - 1], sizeof(res));
47
return (${data_type})instr->const_index[info->index_map[${enum}] - 1];
52
nir_intrinsic_set_${name}(nir_intrinsic_instr *instr, ${data_type} val)
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 */
60
STATIC_ASSERT(sizeof(instr->const_index[0]) == sizeof(val));
61
memcpy(&instr->const_index[info->index_map[${enum}] - 1], &val, sizeof(val));
63
instr->const_index[info->index_map[${enum}] - 1] = val;
68
nir_intrinsic_has_${name}(const nir_intrinsic_instr *instr)
70
const nir_intrinsic_info *info = &nir_intrinsic_infos[instr->intrinsic];
71
return info->index_map[${enum}] > 0;
75
#endif /* _NIR_INTRINSICS_INDICES_ */"""
77
from nir_intrinsics import INTR_INDICES
78
from mako.template import Template
84
parser = argparse.ArgumentParser()
85
parser.add_argument('--outdir', required=True,
86
help='Directory to put the generated files in')
88
args = parser.parse_args()
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))
94
if __name__ == '__main__':