Hash :
4d3a0f60
Author :
Date :
2020-09-11T12:36:05
GN: Componentize D3D format tables. These tables are used by both the GL and D3D11 back-ends. Also moves them to renderer_utils to be in a shared place. Bug: angleproject:3943 Change-Id: I1f5d79842396a87e795547fa03c6855d6f9c5e9a Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2405805 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Jonah Ryan-Davis <jonahr@google.com> Reviewed-by: Geoff Lang <geofflang@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
#!/usr/bin/python
# 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_dxgi_format_table.py:
# Code generation for DXGI format map.
# NOTE: don't run this script directly. Run scripts/run_code_generation.py.
from datetime import date
import sys
import angle_format
template_cpp = """// GENERATED FILE - DO NOT EDIT.
// Generated by {script_name} using data from {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
// found in the LICENSE file.
//
// DXGI format info:
// Determining metadata about a DXGI format.
#include "libANGLE/renderer/Format.h"
using namespace angle;
namespace rx
{{
namespace d3d11
{{
GLenum GetComponentType(DXGI_FORMAT dxgiFormat)
{{
switch (dxgiFormat)
{{
{component_type_cases} default:
break;
}}
UNREACHABLE();
return GL_NONE;
}}
}} // namespace d3d11
namespace d3d11_angle
{{
const Format &GetFormat(DXGI_FORMAT dxgiFormat)
{{
switch (dxgiFormat)
{{
{format_cases} default:
break;
}}
UNREACHABLE();
return Format::Get(FormatID::NONE);
}}
}} // namespace d3d11_angle
}} // namespace rx
"""
template_format_case = """ case DXGI_FORMAT_{dxgi_format}:
return {result};
"""
template_undefined_case = """ case DXGI_FORMAT_{dxgi_format}:
break;
"""
def format_case(dxgi_format, result):
return template_format_case.format(dxgi_format=dxgi_format, result=result)
def undefined_case(dxgi_format):
return template_undefined_case.format(dxgi_format=dxgi_format)
def main():
# auto_script parameters.
if len(sys.argv) > 1:
inputs = [
'angle_format.py',
'angle_format_map.json',
'dxgi_format_data.json',
]
outputs = ['dxgi_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
component_cases = ""
format_cases = ""
input_data = 'dxgi_format_data.json'
dxgi_map = angle_format.load_json(input_data)
types = {
'SNORM': 'GL_SIGNED_NORMALIZED',
'UNORM': 'GL_UNSIGNED_NORMALIZED',
'SINT': 'GL_INT',
'UINT': 'GL_UNSIGNED_INT',
'FLOAT': 'GL_FLOAT',
'SHAREDEXP': 'GL_FLOAT'
}
all_angle = angle_format.get_all_angle_formats()
for dxgi_format, a_format in sorted(dxgi_map.iteritems()):
found = [ctype in dxgi_format for ctype in types.keys()]
count = reduce((lambda a, b: int(a) + int(b)), found)
component_type = 'GL_NONE'
if count == 1:
gltype = next(gltype for ctype, gltype in types.iteritems() if ctype in dxgi_format)
component_cases += format_case(dxgi_format, gltype)
else:
component_cases += undefined_case(dxgi_format)
if a_format == "":
a_format = dxgi_format
if a_format in all_angle:
a_format = "Format::Get(FormatID::" + a_format + ")"
format_cases += format_case(dxgi_format, a_format)
else:
format_cases += undefined_case(dxgi_format)
with open('dxgi_format_map_autogen.cpp', 'wt') as out_file:
output_cpp = template_cpp.format(
script_name=sys.argv[0],
data_source_name=input_data,
copyright_year=date.today().year,
component_type_cases=component_cases,
format_cases=format_cases)
out_file.write(output_cpp)
out_file.close()
return 0
if __name__ == '__main__':
sys.exit(main())