summaryrefslogtreecommitdiffstats
path: root/gfx/angle/src/libANGLE/renderer/gen_angle_format_table.py
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/angle/src/libANGLE/renderer/gen_angle_format_table.py')
-rwxr-xr-xgfx/angle/src/libANGLE/renderer/gen_angle_format_table.py97
1 files changed, 36 insertions, 61 deletions
diff --git a/gfx/angle/src/libANGLE/renderer/gen_angle_format_table.py b/gfx/angle/src/libANGLE/renderer/gen_angle_format_table.py
index 6b56bb40c..7356fc414 100755
--- a/gfx/angle/src/libANGLE/renderer/gen_angle_format_table.py
+++ b/gfx/angle/src/libANGLE/renderer/gen_angle_format_table.py
@@ -16,7 +16,7 @@ import re
import sys
template_autogen_h = """// GENERATED FILE - DO NOT EDIT.
-// Generated by {script_name} using data from {data_source_name}
+// Generated by gen_angle_format_table.py using data from angle_format_data.json
//
// Copyright {copyright_year} The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
@@ -35,8 +35,8 @@ enum class Format::ID
}} // namespace angle
"""
-template_autogen_inl = """// GENERATED FILE - DO NOT EDIT.
-// Generated by {script_name} using data from {data_source_name}
+template_autogen_cpp = """// GENERATED FILE - DO NOT EDIT.
+// Generated by gen_angle_format_table.py using data from angle_format_data.json
//
// Copyright {copyright_year} The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
@@ -54,21 +54,21 @@ template_autogen_inl = """// GENERATED FILE - DO NOT EDIT.
namespace angle
{{
-static constexpr rx::FastCopyFunctionMap::Entry BGRAEntry = {{GL_RGBA, GL_UNSIGNED_BYTE,
- CopyBGRA8ToRGBA8}};
-static constexpr rx::FastCopyFunctionMap BGRACopyFunctions = {{&BGRAEntry, 1}};
-static constexpr rx::FastCopyFunctionMap NoCopyFunctions;
-
-constexpr Format g_formatInfoTable[] = {{
- // clang-format off
- {{ Format::ID::NONE, GL_NONE, GL_NONE, nullptr, NoCopyFunctions, nullptr, GL_NONE, 0, 0, 0, 0, 0, 0 }},
-{angle_format_info_cases} // clang-format on
-}};
-
// static
const Format &Format::Get(ID id)
{{
- return g_formatInfoTable[static_cast<size_t>(id)];
+ // clang-format off
+ switch (id)
+ {{
+{angle_format_info_cases}
+ default:
+ UNREACHABLE();
+ break;
+ }}
+ // clang-format on
+
+ static const Format noneInfo(ID::NONE, GL_NONE, GL_NONE, nullptr, nullptr);
+ return noneInfo;
}}
}} // namespace angle
@@ -123,7 +123,14 @@ def get_color_read_function(angle_format):
}
return 'ReadColor<' + channel_struct + ', '+ component_type_map[angle_format['componentType']] + '>'
-format_entry_template = """ {{ Format::ID::{id}, {glInternalFormat}, {fboImplementationInternalFormat}, {mipGenerationFunction}, {fastCopyFunctions}, {colorReadFunction}, {namedComponentType}, {R}, {G}, {B}, {A}, {D}, {S} }},
+format_entry_template = """{space}{{
+{space} static const Format info(ID::{id},
+{space} {glInternalFormat},
+{space} {fboImplementationInternalFormat},
+{space} {mipGenerationFunction},
+{space} {colorReadFunction});
+{space} return info;
+{space}}}
"""
def get_component_type(format_id):
@@ -167,29 +174,13 @@ def get_bits(format_id):
bits[token[0]] = int(token[1:])
return bits
-def get_named_component_type(component_type):
- if component_type == "snorm":
- return "GL_SIGNED_NORMALIZED"
- elif component_type == "unorm":
- return "GL_UNSIGNED_NORMALIZED"
- elif component_type == "float":
- return "GL_FLOAT"
- elif component_type == "uint":
- return "GL_UNSIGNED_INT"
- elif component_type == "int":
- return "GL_INT"
- elif component_type == "none":
- return "GL_NONE"
- else:
- raise ValueError("Unknown component type for " + component_type)
-
def json_to_table_data(format_id, json, angle_to_gl):
table_data = ""
parsed = {
+ "space": " ",
"id": format_id,
- "fastCopyFunctions": "NoCopyFunctions",
}
for k, v in json.iteritems():
@@ -214,25 +205,14 @@ def json_to_table_data(format_id, json, angle_to_gl):
parsed["mipGenerationFunction"] = get_mip_generation_function(parsed)
parsed["colorReadFunction"] = get_color_read_function(parsed)
- for channel in "ABDGLRS":
- if parsed["bits"] != None and channel in parsed["bits"]:
- parsed[channel] = parsed["bits"][channel]
- else:
- parsed[channel] = "0"
-
- parsed["namedComponentType"] = get_named_component_type(parsed["componentType"])
-
- if format_id == "B8G8R8A8_UNORM":
- parsed["fastCopyFunctions"] = "BGRACopyFunctions"
-
return format_entry_template.format(**parsed)
-def parse_angle_format_table(all_angle, json_data, angle_to_gl):
+def parse_json_into_angle_format_switch_string(all_angle, json_data, angle_to_gl):
table_data = ''
for format_id in sorted(all_angle):
- if format_id != "NONE":
- format_info = json_data[format_id] if format_id in json_data else {}
- table_data += json_to_table_data(format_id, format_info, angle_to_gl)
+ format_info = json_data[format_id] if format_id in json_data else {}
+ table_data += ' case ID::' + format_id + ':\n'
+ table_data += json_to_table_data(format_id, format_info, angle_to_gl)
return table_data
@@ -246,27 +226,22 @@ def gen_enum_string(all_angle):
gl_to_angle = angle_format.load_forward_table('angle_format_map.json')
angle_to_gl = angle_format.load_inverse_table('angle_format_map.json')
-data_source_name = 'angle_format_data.json'
-json_data = angle_format.load_json(data_source_name)
+json_data = angle_format.load_json('angle_format_data.json')
all_angle = angle_to_gl.keys()
-angle_format_cases = parse_angle_format_table(
+angle_format_cases = parse_json_into_angle_format_switch_string(
all_angle, json_data, angle_to_gl)
-output_cpp = template_autogen_inl.format(
- script_name = sys.argv[0],
- copyright_year = date.today().year,
- angle_format_info_cases = angle_format_cases,
- data_source_name = data_source_name)
-with open('Format_table_autogen.cpp', 'wt') as out_file:
+output_cpp = template_autogen_cpp.format(
+ copyright_year=date.today().year,
+ angle_format_info_cases=angle_format_cases)
+with open('Format_autogen.cpp', 'wt') as out_file:
out_file.write(output_cpp)
out_file.close()
enum_data = gen_enum_string(all_angle)
output_h = template_autogen_h.format(
- script_name = sys.argv[0],
- copyright_year = date.today().year,
- angle_format_enum = enum_data,
- data_source_name = data_source_name)
+ copyright_year=date.today().year,
+ angle_format_enum=enum_data)
with open('Format_ID_autogen.inl', 'wt') as out_file:
out_file.write(output_h)
out_file.close()