Commit 04d3d895 by Jamie Madill

Simplify load functions table.

The indexing of the table data was mismatched with the table, causing confusion with no appreciable gain. Fix this, reducing the lines in the script and table at the same time. BUG=angleproject:1455 Change-Id: I59095ba11a416575fd2310765eaac8d368b90cab Reviewed-on: https://chromium-review.googlesource.com/367694Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 55f29a8c
......@@ -7,7 +7,10 @@
# Code generation for the load function tables used for texture formats
#
import json
import json, sys
sys.path.append('../..')
import angle_format
template = """// GENERATED FILE - DO NOT EDIT.
// Generated by gen_load_functions_table.py using data from load_functions_data.json
......@@ -102,7 +105,8 @@ internal_format_param = 'internalFormat'
dxgi_format_param = 'dxgiFormat'
dxgi_format_unknown = "DXGI_FORMAT_UNKNOWN"
def get_function_maps_string(typestr, function, requiresConversion):
def get_function_maps_string(typestr, function):
requiresConversion = str('LoadToNative<' not in function).lower()
return ' { ' + typestr + ', LoadImageFunctionInfo(' + function + ', ' + requiresConversion + ') },\n'
def get_unknown_format_string(dxgi_to_type_map, dxgi_unknown_string):
......@@ -111,24 +115,11 @@ def get_unknown_format_string(dxgi_to_type_map, dxgi_unknown_string):
table_data = ''
for unknown_type_function in dxgi_to_type_map[dxgi_unknown_string]:
table_data += get_function_maps_string(unknown_type_function['type'], unknown_type_function['loadFunction'], 'true')
for gl_type, load_function in sorted(dxgi_to_type_map[dxgi_unknown_string].iteritems()):
table_data += get_function_maps_string(gl_type, load_function)
return table_data
# Making map from dxgi to type map for a particular internalFormat
def create_dxgi_to_type_map(dst, json_data, internal_format_str):
for type_item in sorted(json_data[internal_format_str].iteritems()):
for entry_in_type_item in type_item[1]:
dxgi_format_str = entry_in_type_item['dxgiFormat']
if dxgi_format_str not in dst:
dst[dxgi_format_str] = []
type_dxgi_load_function = entry_in_type_item.copy();
type_dxgi_load_function['type'] = type_item[0]
dst[dxgi_format_str].append(type_dxgi_load_function)
def get_load_function_map_snippet(insert_map_string):
load_function_map_snippet = ''
load_function_map_snippet += ' static const std::map<GLenum, LoadImageFunctionInfo> loadFunctionsMap = {\n'
......@@ -140,43 +131,33 @@ def get_load_function_map_snippet(insert_map_string):
def parse_json_into_switch_string(json_data):
table_data = ''
for internal_format_item in sorted(json_data.iteritems()):
internal_format_str = internal_format_item[0]
table_data += ' case ' + internal_format_str + ':\n'
for internal_format, dxgi_to_type_map in sorted(json_data.iteritems()):
table_data += ' case ' + internal_format + ':\n'
table_data += ' {\n'
table_data += ' switch (' + dxgi_format_param + ')\n'
table_data += ' {\n'
dxgi_to_type_map = {};
create_dxgi_to_type_map(dxgi_to_type_map, json_data, internal_format_str)
dxgi_unknown_str = get_unknown_format_string(dxgi_to_type_map, dxgi_format_unknown);
for dxgi_format_item in sorted(dxgi_to_type_map.iteritems()):
dxgi_format_str = dxgi_format_item[0]
for dxgi_format, type_functions in sorted(dxgi_to_type_map.iteritems()):
# Main case statements
table_data += ' case ' + dxgi_format_str + ':\n'
table_data += ' case ' + dxgi_format + ':\n'
table_data += ' {\n'
insert_map_string = ''
types_already_in_loadmap = set()
for type_function in sorted(dxgi_format_item[1]):
requiresConversion = str('LoadToNative<' not in type_function['loadFunction']).lower()
insert_map_string += get_function_maps_string(type_function['type'], type_function['loadFunction'], requiresConversion)
types_already_in_loadmap.add(type_function['type'])
# DXGI_FORMAT_UNKNOWN add ons
if dxgi_format_unknown in dxgi_to_type_map:
for unknown_type_function in dxgi_to_type_map[dxgi_format_unknown]:
# Check that it's not already in the loadmap so it doesn't override the value
if unknown_type_function['type'] not in types_already_in_loadmap:
insert_map_string += get_function_maps_string(unknown_type_function['type'], unknown_type_function['loadFunction'], 'true')
for gl_type, load_function in dxgi_to_type_map[dxgi_format_unknown].iteritems():
if gl_type not in type_functions:
type_functions[gl_type] = load_function
for gl_type, load_function in sorted(type_functions.iteritems()):
insert_map_string += get_function_maps_string(gl_type, load_function)
table_data += get_load_function_map_snippet(insert_map_string)
table_data += ' }\n'
table_data += ' default:\n'
dxgi_unknown_str = get_unknown_format_string(dxgi_to_type_map, dxgi_format_unknown);
if dxgi_unknown_str:
table_data += ' {\n'
table_data += get_load_function_map_snippet(dxgi_unknown_str)
......@@ -188,16 +169,13 @@ def parse_json_into_switch_string(json_data):
return table_data
with open('load_functions_data.json') as functions_json_file:
functions_data = functions_json_file.read();
functions_json_file.close()
json_data = json.loads(functions_data)
json_data = angle_format.load_json('load_functions_data.json')
table_data = parse_json_into_switch_string(json_data)
output = template.format(internal_format = internal_format_param,
dxgi_format = dxgi_format_param,
data=table_data)
table_data = parse_json_into_switch_string(json_data)
output = template.format(internal_format = internal_format_param,
dxgi_format = dxgi_format_param,
data=table_data)
with open('load_functions_table_autogen.cpp', 'wt') as out_file:
out_file.write(output)
out_file.close()
with open('load_functions_table_autogen.cpp', 'wt') as out_file:
out_file.write(output)
out_file.close()
......@@ -189,8 +189,8 @@ const std::map<GLenum, LoadImageFunctionInfo> &GetLoadFunctionsMap(GLenum intern
case DXGI_FORMAT_B5G6R5_UNORM:
{
static const std::map<GLenum, LoadImageFunctionInfo> loadFunctionsMap = {
{ GL_UNSIGNED_SHORT_5_6_5, LoadImageFunctionInfo(LoadRGB565ToBGR565, true) },
{ GL_UNSIGNED_BYTE, LoadImageFunctionInfo(LoadToNative<GLushort,1>, false) },
{ GL_UNSIGNED_SHORT_5_6_5, LoadImageFunctionInfo(LoadRGB565ToBGR565, true) },
};
return loadFunctionsMap;
......@@ -206,8 +206,8 @@ const std::map<GLenum, LoadImageFunctionInfo> &GetLoadFunctionsMap(GLenum intern
case DXGI_FORMAT_UNKNOWN:
{
static const std::map<GLenum, LoadImageFunctionInfo> loadFunctionsMap = {
{ GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, LoadImageFunctionInfo(LoadRGB5A1ToRGBA8, true) },
{ GL_UNSIGNED_BYTE, LoadImageFunctionInfo(LoadToNative<GLubyte,4>, false) },
{ GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, LoadImageFunctionInfo(LoadRGB5A1ToRGBA8, true) },
};
return loadFunctionsMap;
......@@ -215,7 +215,7 @@ const std::map<GLenum, LoadImageFunctionInfo> &GetLoadFunctionsMap(GLenum intern
default:
{
static const std::map<GLenum, LoadImageFunctionInfo> loadFunctionsMap = {
{ GL_UNSIGNED_BYTE, LoadImageFunctionInfo(LoadToNative<GLubyte,4>, true) },
{ GL_UNSIGNED_BYTE, LoadImageFunctionInfo(LoadToNative<GLubyte,4>, false) },
{ GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, LoadImageFunctionInfo(LoadRGB5A1ToRGBA8, true) },
};
......@@ -230,8 +230,8 @@ const std::map<GLenum, LoadImageFunctionInfo> &GetLoadFunctionsMap(GLenum intern
case DXGI_FORMAT_UNKNOWN:
{
static const std::map<GLenum, LoadImageFunctionInfo> loadFunctionsMap = {
{ GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, LoadImageFunctionInfo(LoadRGBA4ToRGBA8, true) },
{ GL_UNSIGNED_BYTE, LoadImageFunctionInfo(LoadToNative<GLubyte,4>, false) },
{ GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, LoadImageFunctionInfo(LoadRGBA4ToRGBA8, true) },
};
return loadFunctionsMap;
......@@ -239,7 +239,7 @@ const std::map<GLenum, LoadImageFunctionInfo> &GetLoadFunctionsMap(GLenum intern
default:
{
static const std::map<GLenum, LoadImageFunctionInfo> loadFunctionsMap = {
{ GL_UNSIGNED_BYTE, LoadImageFunctionInfo(LoadToNative<GLubyte,4>, true) },
{ GL_UNSIGNED_BYTE, LoadImageFunctionInfo(LoadToNative<GLubyte,4>, false) },
{ GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, LoadImageFunctionInfo(LoadRGBA4ToRGBA8, true) },
};
......@@ -262,7 +262,7 @@ const std::map<GLenum, LoadImageFunctionInfo> &GetLoadFunctionsMap(GLenum intern
default:
{
static const std::map<GLenum, LoadImageFunctionInfo> loadFunctionsMap = {
{ GL_UNSIGNED_BYTE, LoadImageFunctionInfo(LoadToNative<GLubyte,4>, true) },
{ GL_UNSIGNED_BYTE, LoadImageFunctionInfo(LoadToNative<GLubyte,4>, false) },
};
return loadFunctionsMap;
......@@ -951,9 +951,9 @@ const std::map<GLenum, LoadImageFunctionInfo> &GetLoadFunctionsMap(GLenum intern
case DXGI_FORMAT_R11G11B10_FLOAT:
{
static const std::map<GLenum, LoadImageFunctionInfo> loadFunctionsMap = {
{ GL_FLOAT, LoadImageFunctionInfo(LoadRGB32FToRG11B10F, true) },
{ GL_HALF_FLOAT, LoadImageFunctionInfo(LoadRGB16FToRG11B10F, true) },
{ GL_HALF_FLOAT_OES, LoadImageFunctionInfo(LoadRGB16FToRG11B10F, true) },
{ GL_FLOAT, LoadImageFunctionInfo(LoadRGB32FToRG11B10F, true) },
{ GL_UNSIGNED_INT_10F_11F_11F_REV, LoadImageFunctionInfo(LoadToNative<GLuint,1>, false) },
};
......@@ -1553,8 +1553,8 @@ const std::map<GLenum, LoadImageFunctionInfo> &GetLoadFunctionsMap(GLenum intern
case DXGI_FORMAT_R8G8B8A8_UNORM:
{
static const std::map<GLenum, LoadImageFunctionInfo> loadFunctionsMap = {
{ GL_UNSIGNED_SHORT_5_6_5, LoadImageFunctionInfo(LoadR5G6B5ToRGBA8, true) },
{ GL_UNSIGNED_BYTE, LoadImageFunctionInfo(LoadToNative3To4<GLubyte,0xFF>, true) },
{ GL_UNSIGNED_SHORT_5_6_5, LoadImageFunctionInfo(LoadR5G6B5ToRGBA8, true) },
};
return loadFunctionsMap;
......@@ -1570,9 +1570,9 @@ const std::map<GLenum, LoadImageFunctionInfo> &GetLoadFunctionsMap(GLenum intern
case DXGI_FORMAT_B5G5R5A1_UNORM:
{
static const std::map<GLenum, LoadImageFunctionInfo> loadFunctionsMap = {
{ GL_UNSIGNED_BYTE, LoadImageFunctionInfo(LoadRGBA8ToBGR5A1, true) },
{ GL_UNSIGNED_INT_2_10_10_10_REV, LoadImageFunctionInfo(LoadRGB10A2ToBGR5A1, true) },
{ GL_UNSIGNED_SHORT_5_5_5_1, LoadImageFunctionInfo(LoadRGB5A1ToA1RGB5, true) },
{ GL_UNSIGNED_BYTE, LoadImageFunctionInfo(LoadRGBA8ToBGR5A1, true) },
};
return loadFunctionsMap;
......@@ -1580,9 +1580,9 @@ const std::map<GLenum, LoadImageFunctionInfo> &GetLoadFunctionsMap(GLenum intern
case DXGI_FORMAT_R8G8B8A8_UNORM:
{
static const std::map<GLenum, LoadImageFunctionInfo> loadFunctionsMap = {
{ GL_UNSIGNED_BYTE, LoadImageFunctionInfo(LoadToNative<GLubyte,4>, false) },
{ GL_UNSIGNED_INT_2_10_10_10_REV, LoadImageFunctionInfo(LoadRGB10A2ToRGBA8, true) },
{ GL_UNSIGNED_SHORT_5_5_5_1, LoadImageFunctionInfo(LoadRGB5A1ToRGBA8, true) },
{ GL_UNSIGNED_BYTE, LoadImageFunctionInfo(LoadToNative<GLubyte,4>, false) },
};
return loadFunctionsMap;
......@@ -1662,9 +1662,9 @@ const std::map<GLenum, LoadImageFunctionInfo> &GetLoadFunctionsMap(GLenum intern
case DXGI_FORMAT_R9G9B9E5_SHAREDEXP:
{
static const std::map<GLenum, LoadImageFunctionInfo> loadFunctionsMap = {
{ GL_FLOAT, LoadImageFunctionInfo(LoadRGB32FToRGB9E5, true) },
{ GL_HALF_FLOAT, LoadImageFunctionInfo(LoadRGB16FToRGB9E5, true) },
{ GL_HALF_FLOAT_OES, LoadImageFunctionInfo(LoadRGB16FToRGB9E5, true) },
{ GL_FLOAT, LoadImageFunctionInfo(LoadRGB32FToRGB9E5, true) },
{ GL_UNSIGNED_INT_5_9_9_9_REV, LoadImageFunctionInfo(LoadToNative<GLuint,1>, false) },
};
......@@ -1837,8 +1837,8 @@ const std::map<GLenum, LoadImageFunctionInfo> &GetLoadFunctionsMap(GLenum intern
case DXGI_FORMAT_B4G4R4A4_UNORM:
{
static const std::map<GLenum, LoadImageFunctionInfo> loadFunctionsMap = {
{ GL_UNSIGNED_SHORT_4_4_4_4, LoadImageFunctionInfo(LoadRGBA4ToARGB4, true) },
{ GL_UNSIGNED_BYTE, LoadImageFunctionInfo(LoadRGBA8ToBGRA4, true) },
{ GL_UNSIGNED_SHORT_4_4_4_4, LoadImageFunctionInfo(LoadRGBA4ToARGB4, true) },
};
return loadFunctionsMap;
......@@ -1846,8 +1846,8 @@ const std::map<GLenum, LoadImageFunctionInfo> &GetLoadFunctionsMap(GLenum intern
case DXGI_FORMAT_R8G8B8A8_UNORM:
{
static const std::map<GLenum, LoadImageFunctionInfo> loadFunctionsMap = {
{ GL_UNSIGNED_SHORT_4_4_4_4, LoadImageFunctionInfo(LoadRGBA4ToRGBA8, true) },
{ GL_UNSIGNED_BYTE, LoadImageFunctionInfo(LoadToNative<GLubyte,4>, false) },
{ GL_UNSIGNED_SHORT_4_4_4_4, LoadImageFunctionInfo(LoadRGBA4ToRGBA8, true) },
};
return loadFunctionsMap;
......
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