Commit 55e98210 by Jamie Madill Committed by Commit Bot

Make global ES3 formats STL map a switch.

This eliminates another global std::map, and replaces it with a json generated switch. This should be better for threading, better on memory use, and faster. BUG=angleproject:1389 BUG=angleproject:1459 Change-Id: I1d289637c00783690ec8ea743ea2aa17b0ab8e50 Reviewed-on: https://chromium-review.googlesource.com/394234Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 5878f832
......@@ -293,6 +293,11 @@ VertexFormatType GetVertexFormatType(const VertexAttribute &attrib);
VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType);
const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType);
// Implemented in format_map_autogen.cpp
bool ValidES3Format(GLenum format);
bool ValidES3Type(GLenum type);
bool ValidES3FormatCombination(GLenum format, GLenum type, GLenum internalFormat);
} // namespace gl
#endif // LIBANGLE_FORMATUTILS_H_
......@@ -15,6 +15,7 @@ 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 {copyright_year} The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
......@@ -22,6 +23,7 @@ template_cpp = """// GENERATED FILE - DO NOT EDIT.
//
// 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"
......@@ -43,6 +45,42 @@ GLenum GetSizedFormatInternal(GLenum format, GLenum type)
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
"""
......@@ -56,13 +94,25 @@ template_format_case = """ case {format}:
"""
template_type_case = """ case {type}:
return {internal_format};
template_simple_case = """ case {key}:
return {result};
"""
def parse_type_case(type, internal_format):
return template_type_case.format(
type = type, internal_format = internal_format)
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 = ""
......@@ -80,11 +130,58 @@ format_cases = ""
for format, type_map in sorted(format_map.iteritems()):
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 combos.iteritems():
this_type_cases = ""
for type, combos in type_combos.iteritems():
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 = sys.argv[0],
data_source_name = input_script,
es3_data_source_name = combo_data_file,
copyright_year = date.today().year,
format_cases = format_cases)
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)
out_file.close()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment