Hash :
0f34f3f2
Author :
Date :
2019-03-11T10:18:57
Use auto_script in run_code_generation. Cleans up the generator scripts to prepare for listing outputs in the generated hashes file. Also reorganizes the scripts somewhat to make them a bit more maintainable. Bug: angleproject:3227 Change-Id: If40946c2004941d3f6cd51d5521c7db8cc0b52df Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1512052 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: 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 210
#!/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_vk_format_table.py:
# Code generation for vk format map. See vk_format_map.json for data source.
# NOTE: don't run this script directly. Run scripts/run_code_generation.py.
from datetime import date
import json
import math
import pprint
import os
import re
import sys
sys.path.append('..')
import angle_format
template_table_autogen_cpp = """// GENERATED FILE - DO NOT EDIT.
// Generated by {script_name} using data from {input_file_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.
//
// {out_file_name}:
// Queries for full Vulkan format information based on GL format.
#include "libANGLE/renderer/vulkan/vk_format_utils.h"
#include "image_util/copyimage.h"
#include "image_util/generatemip.h"
#include "image_util/loadimage.h"
using namespace angle;
namespace rx
{{
namespace vk
{{
void Format::initialize(RendererVk *renderer,
const angle::Format &angleFormat)
{{
switch (angleFormat.id)
{{
{format_case_data}
default:
UNREACHABLE();
break;
}}
}}
}} // namespace vk
}} // namespace rx
"""
empty_format_entry_template = """case angle::FormatID::{format_id}:
// This format is not implemented in Vulkan.
break;
"""
format_entry_template = """case angle::FormatID::{format_id}:
internalFormat = {internal_format};
{texture_template}
{buffer_template}
break;
"""
texture_basic_template = """textureFormatID = {texture};
vkTextureFormat = {vk_texture_format};
textureInitializerFunction = {texture_initializer};"""
texture_struct_template="{{{texture}, {vk_texture_format}, {texture_initializer}}}"
texture_fallback_template = """{{
static constexpr TextureFormatInitInfo kInfo[] = {{{texture_list}}};
initTextureFallback(renderer, kInfo, ArraySize(kInfo));
}}"""
buffer_basic_template = """bufferFormatID = {buffer};
vkBufferFormat = {vk_buffer_format};
vkBufferFormatIsPacked = {vk_buffer_format_is_packed};
vertexLoadFunction = {vertex_load_function};
vertexLoadRequiresConversion = {vertex_load_converts};"""
buffer_struct_template="""{{{buffer}, {vk_buffer_format}, {vk_buffer_format_is_packed},
{vertex_load_function}, {vertex_load_converts}}}"""
buffer_fallback_template = """{{
static constexpr BufferFormatInitInfo kInfo[] = {{{buffer_list}}};
initBufferFallback(renderer, kInfo, ArraySize(kInfo));
}}"""
def is_packed(format_id):
return "true" if "_PACK" in format_id else "false"
def gen_format_case(angle, internal_format, vk_json_data):
vk_map = vk_json_data["map"]
vk_overrides = vk_json_data["overrides"]
vk_fallbacks = vk_json_data["fallbacks"]
args = dict(
format_id=angle,
internal_format=internal_format,
texture_template="",
buffer_template="")
if ((angle not in vk_map) and (angle not in vk_overrides) and
(angle not in vk_fallbacks)) or angle == 'NONE':
return empty_format_entry_template.format(**args)
def get_formats(format, type):
format = vk_overrides.get(format, {}).get(type, format)
if format not in vk_map:
return []
fallbacks = vk_fallbacks.get(format, {}).get(type, [])
if not isinstance(fallbacks, list):
fallbacks = [fallbacks]
return [format] + fallbacks
def texture_args(format):
return dict(
texture="angle::FormatID::" + format,
vk_texture_format=vk_map[format],
texture_initializer=angle_format.get_internal_format_initializer(
internal_format, format))
def buffer_args(format):
return dict(
buffer="angle::FormatID::" + format,
vk_buffer_format=vk_map[format],
vk_buffer_format_is_packed=is_packed(vk_map[format]),
vertex_load_function=angle_format.get_vertex_copy_function(
angle, format),
vertex_load_converts='false' if angle == format else 'true',
)
textures = get_formats(angle, "texture")
if len(textures) == 1:
args.update(texture_template=texture_basic_template)
args.update(texture_args(textures[0]))
elif len(textures) > 1:
args.update(
texture_template=texture_fallback_template,
texture_list=", ".join(
texture_struct_template.format(**texture_args(i))
for i in textures))
buffers = get_formats(angle, "buffer")
if len(buffers) == 1:
args.update(buffer_template=buffer_basic_template)
args.update(buffer_args(buffers[0]))
elif len(buffers) > 1:
args.update(
buffer_template=buffer_fallback_template,
buffer_list=", ".join(
buffer_struct_template.format(**buffer_args(i)) for i in buffers))
return format_entry_template.format(**args).format(**args)
def main():
input_file_name = 'vk_format_map.json'
out_file_name = 'vk_format_table_autogen.cpp'
# auto_script parameters.
if len(sys.argv) > 1:
inputs = [
'../angle_format.py',
'../angle_format_map.json',
input_file_name
]
outputs = [out_file_name]
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
angle_to_gl = angle_format.load_inverse_table(os.path.join('..', 'angle_format_map.json'))
vk_json_data = angle_format.load_json(input_file_name)
vk_cases = [gen_format_case(angle, gl, vk_json_data)
for angle, gl in sorted(angle_to_gl.iteritems())]
output_cpp = template_table_autogen_cpp.format(
copyright_year = date.today().year,
format_case_data = "\n".join(vk_cases),
script_name = __file__,
out_file_name = out_file_name,
input_file_name = input_file_name)
with open(out_file_name, 'wt') as out_file:
out_file.write(output_cpp)
out_file.close()
return 0
if __name__ == '__main__':
sys.exit(main())