Hash :
6937ea98
Author :
Date :
2022-09-08T14:15:10
Use base name of the generator script in various generated files Increases compiler cache hits especially in cases where the file is run during build. Bug: angleproject:7642 Change-Id: I769dae2d7cca2cf1e238531f4cb356bad41b06dd Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3880323 Reviewed-by: Kenneth Russell <kbr@chromium.org> Commit-Queue: Kenneth Russell <kbr@chromium.org> Auto-Submit: Kimmo Kinnunen <kkinnunen@apple.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
#!/usr/bin/python3
# Copyright 2016 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# gen_format_map.py:
# Code generation for GL format map. The format map matches between
# {format,type} and internal format.
# NOTE: don't run this script directly. Run scripts/run_code_generation.py.
import sys
import os
sys.path.append('renderer')
import angle_format
template_cpp = """// GENERATED FILE - DO NOT EDIT.
// Generated by {script_name} using data from {data_source_name}.
// ES3 format info from {es3_data_source_name}.
//
// Copyright 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// format_map:
// Determining the sized internal format from a (format,type) pair.
// Also check es3 format combinations for validity.
#include "angle_gl.h"
#include "common/debug.h"
namespace gl
{{
GLenum GetSizedFormatInternal(GLenum format, GLenum type)
{{
switch (format)
{{
{format_cases} case GL_NONE:
return GL_NONE;
default:
break;
}}
return GL_NONE;
}}
bool ValidES3Format(GLenum format)
{{
switch (format)
{{
{es3_format_cases} return true;
default:
return false;
}}
}}
bool ValidES3Type(GLenum type)
{{
switch (type)
{{
{es3_type_cases} return true;
default:
return false;
}}
}}
bool ValidES3FormatCombination(GLenum format, GLenum type, GLenum internalFormat)
{{
ASSERT(ValidES3Format(format) && ValidES3Type(type));
switch (format)
{{
{es3_combo_cases} default:
UNREACHABLE();
break;
}}
return false;
}}
}} // namespace gl
"""
template_format_case = """ case {format}:
switch (type)
{{
{type_cases} default:
break;
}}
break;
"""
template_simple_case = """ case {key}:
return {result};
"""
template_es3_combo_type_case = """ case {type}:
{{
switch (internalFormat)
{{
{internal_format_cases} return true;
default:
break;
}}
break;
}}
"""
def parse_type_case(type, result):
return template_simple_case.format(key=type, result=result)
def parse_format_case(format, type_map):
type_cases = ""
for type, internal_format in sorted(type_map.items()):
type_cases += parse_type_case(type, internal_format)
return template_format_case.format(format=format, type_cases=type_cases)
def main():
# auto_script parameters.
if len(sys.argv) > 1:
inputs = [
'renderer/angle_format.py', 'es3_format_type_combinations.json', 'format_map_data.json'
]
outputs = ['format_map_autogen.cpp']
if sys.argv[1] == 'inputs':
print(','.join(inputs))
elif sys.argv[1] == 'outputs':
print(','.join(outputs))
else:
print('Invalid script parameters')
return 1
return 0
input_script = 'format_map_data.json'
format_map = angle_format.load_json(input_script)
format_cases = ""
for format, type_map in sorted(format_map.items()):
format_cases += parse_format_case(format, type_map)
combo_data_file = 'es3_format_type_combinations.json'
es3_combo_data = angle_format.load_json(combo_data_file)
combo_data = [combo for sublist in es3_combo_data.values() for combo in sublist]
types = set()
formats = set()
combos = {}
for internal_format, format, type in combo_data:
types.update([type])
formats.update([format])
if format not in combos:
combos[format] = {}
if type not in combos[format]:
combos[format][type] = [internal_format]
else:
combos[format][type] += [internal_format]
es3_format_cases = ""
for format in sorted(formats):
es3_format_cases += " case " + format + ":\n"
es3_type_cases = ""
for type in sorted(types):
es3_type_cases += " case " + type + ":\n"
es3_combo_cases = ""
for format, type_combos in sorted(combos.items()):
this_type_cases = ""
for type, combos in sorted(type_combos.items()):
internal_format_cases = ""
for internal_format in combos:
internal_format_cases += " case " + internal_format + ":\n"
this_type_cases += template_es3_combo_type_case.format(
type=type, internal_format_cases=internal_format_cases)
es3_combo_cases += template_format_case.format(format=format, type_cases=this_type_cases)
with open('format_map_autogen.cpp', 'wt') as out_file:
output_cpp = template_cpp.format(
script_name=os.path.basename(sys.argv[0]),
data_source_name=input_script,
es3_data_source_name=combo_data_file,
format_cases=format_cases,
es3_format_cases=es3_format_cases,
es3_type_cases=es3_type_cases,
es3_combo_cases=es3_combo_cases)
out_file.write(output_cpp)
return 0
if __name__ == '__main__':
sys.exit(main())