Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/compiler/nir/nir_intrinsics_indices_h.py
4545 views
1
2
template = """\
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
<%
31
data_type = index.c_data_type
32
name = index.name
33
enum = "NIR_INTRINSIC_" + name.upper()
34
%>
35
36
static inline ${data_type}
37
nir_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
51
static inline void
52
nir_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
val._pad = 0; /* clear padding bits */
58
STATIC_ASSERT(sizeof(instr->const_index[0]) == sizeof(val));
59
memcpy(&instr->const_index[info->index_map[${enum}] - 1], &val, sizeof(val));
60
% else:
61
instr->const_index[info->index_map[${enum}] - 1] = val;
62
% endif
63
}
64
65
static inline bool
66
nir_intrinsic_has_${name}(const nir_intrinsic_instr *instr)
67
{
68
const nir_intrinsic_info *info = &nir_intrinsic_infos[instr->intrinsic];
69
return info->index_map[${enum}] > 0;
70
}
71
% endfor
72
73
#endif /* _NIR_INTRINSICS_INDICES_ */"""
74
75
from nir_intrinsics import INTR_INDICES
76
from mako.template import Template
77
import argparse
78
import os
79
80
81
def main():
82
parser = argparse.ArgumentParser()
83
parser.add_argument('--outdir', required=True,
84
help='Directory to put the generated files in')
85
86
args = parser.parse_args()
87
88
path = os.path.join(args.outdir, 'nir_intrinsics_indices.h')
89
with open(path, 'wb') as f:
90
f.write(Template(template, output_encoding='utf-8').render(INTR_INDICES=INTR_INDICES))
91
92
if __name__ == '__main__':
93
main()
94
95
96