Hash :
904a4797
Author :
Date :
2022-02-15T10:58:07
Python3 upgrades Required to run run_code_generation.py on gLinux. Bug: angleproject:5707 Change-Id: Ifb416be6f89eb67faf43e7de66c6f9a92a5eb5e1 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3465514 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Cody Northrop <cnorthrop@google.com>
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 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
#!/usr/bin/python3
#
# Copyright 2018 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_blit11helper.py:
# Generates the code for retrieving the various blit shaders for D3D11
# NOTE: don't run this script directly. Run scripts/run_code_generation.py.
import sys, os, pprint
template_blitshader_source = """// GENERATED FILE - DO NOT EDIT.
// Generated by {script_name}.
//
// Copyright 2018 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.
//
// Blit11Helper_autogen.inc:
// Defines and retrieves blitshaders for the D3D11 backend.
namespace
{{
// Include inline shaders in the anonymous namespace to make sure no symbols are exported
{shader_includes}
}} // namespace
enum Blit11::BlitShaderOperation : unsigned int
{{
{blitshaderop_enums}
}};
enum Blit11::BlitShaderType : unsigned int
{{
{blitshadertype_enums}
}};
Blit11::BlitShaderType Blit11::getBlitShaderType(BlitShaderOperation operation, ShaderDimension dimension)
{{
switch(operation)
{{
{get_blitshaders_case_list}
default:
UNREACHABLE();
return BLITSHADER_INVALID;
}}
}}
angle::Result Blit11::mapBlitShader(const gl::Context *context,
BlitShaderType blitShaderType)
{{
switch(blitShaderType)
{{
{add_blitshader_case_list}
default:
ANGLE_HR_UNREACHABLE(GetImplAs<Context11>(context));
}}
return angle::Result::Continue;
}}
"""
template_blitshaders_gni = """# GENERATED FILE - DO NOT EDIT.
# Generated by {script_name}.
#
# Copyright 2018 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.
#
# d3d11_blit_shaders_autogen.gni:
# List of generated blit shaders for inclusion in ANGLE's build process.
libangle_d3d11_blit_shaders = [
{shader_filename_list}
]"""
template_compiled_blitshader_include = """#include "libANGLE/renderer/d3d/d3d11/shaders/compiled/{filename}\""""
template_get_blitshader_case = """ case {operation}:
switch (dimension)
{{
{get_blitshader_dimension_cases}
default:
UNREACHABLE();
return BLITSHADER_INVALID;
}}"""
template_get_blitshader_case_dimension = """ case SHADER_{dimension}:
return BLITSHADER_{blitshader};"""
template_map_blitshader_case = """ case {blitshader_name}:
ANGLE_TRY(addBlitShaderToMap(context, blitShaderType, SHADER_{dimension_upper},
ShaderData(g_PS_{compiled_shader_name}),
"Blit11 {dimension} {shader_comment} pixel shader"));
break;"""
supported_dimensions = ["2D", "3D", "2DArray"]
# field 1: BlitShaderType enum
# field 2: Name of compiled shader
# field 3: Filename of compiled shader
blitshader_data = [
("RGBAF", "PassthroughRGBA*", "passthroughrgba*11ps.h"), ("BGRAF", "PassthroughRGBA*"),
("RGBF", "PassthroughRGB*", "passthroughrgb*11ps.h"),
("RGF", "PassthroughRG*", "passthroughrg*11ps.h"),
("RF", "PassthroughR*", "passthroughr*11ps.h"),
("ALPHA", "PassthroughA*", "passthrougha*11ps.h"),
("LUMA", "PassthroughLum*", "passthroughlum*11ps.h"),
("LUMAALPHA", "PassthroughLumAlpha*", "passthroughlumalpha*11ps.h"),
("RGBAUI", "PassthroughRGBA*UI", "passthroughrgba*ui11ps.h"),
("RGBAI", "PassthroughRGBA*I", "passthroughrgba*i11ps.h"),
("RGBUI", "PassthroughRGB*UI", "passthroughrgb*ui11ps.h"),
("RGBI", "PassthroughRGB*I", "passthroughrgb*i11ps.h"),
("RGUI", "PassthroughRG*UI", "passthroughrg*ui11ps.h"),
("RGI", "PassthroughRG*I", "passthroughrg*i11ps.h"),
("RUI", "PassthroughR*UI", "passthroughr*ui11ps.h"),
("RI", "PassthroughR*I", "passthroughr*i11ps.h"),
("RGBAF_PREMULTIPLY", "FtoF_PM_RGBA_*", "multiplyalpha_ftof_pm_rgba_*_ps.h"),
("RGBAF_UNMULTIPLY", "FtoF_UM_RGBA_*", "multiplyalpha_ftof_um_rgba_*_ps.h"),
("RGBF_PREMULTIPLY", "FtoF_PM_RGB_*", "multiplyalpha_ftof_pm_rgb_*_ps.h"),
("RGBF_UNMULTIPLY", "FtoF_UM_RGB_*", "multiplyalpha_ftof_um_rgb_*_ps.h"),
("RGBAF_TOUI", "FtoU_PT_RGBA_*", "multiplyalpha_ftou_pt_rgba_*_ps.h"),
("RGBAF_TOUI_PREMULTIPLY", "FtoU_PM_RGBA_*", "multiplyalpha_ftou_pm_rgba_*_ps.h"),
("RGBAF_TOUI_UNMULTIPLY", "FtoU_UM_RGBA_*", "multiplyalpha_ftou_um_rgba_*_ps.h"),
("RGBF_TOUI", "FtoU_PT_RGB_*", "multiplyalpha_ftou_pt_rgb_*_ps.h"),
("RGBF_TOUI_PREMULTIPLY", "FtoU_PM_RGB_*", "multiplyalpha_ftou_pm_rgb_*_ps.h"),
("RGBF_TOUI_UNMULTIPLY", "FtoU_UM_RGB_*", "multiplyalpha_ftou_um_rgb_*_ps.h"),
("RGBAF_TOI", "FtoI_PT_RGBA_*", "multiplyalpha_ftoi_pt_rgba_*_ps.h"),
("RGBAF_TOI_PREMULTIPLY", "FtoI_PM_RGBA_*", "multiplyalpha_ftoi_pm_rgba_*_ps.h"),
("RGBAF_TOI_UNMULTIPLY", "FtoI_UM_RGBA_*", "multiplyalpha_ftoi_um_rgba_*_ps.h"),
("RGBF_TOI", "FtoI_PT_RGB_*", "multiplyalpha_ftoi_pt_rgb_*_ps.h"),
("RGBF_TOI_PREMULTIPLY", "FtoI_PM_RGB_*", "multiplyalpha_ftoi_pm_rgb_*_ps.h"),
("RGBF_TOI_UNMULTIPLY", "FtoI_UM_RGB_*", "multiplyalpha_ftoi_um_rgb_*_ps.h"),
("LUMAF_PREMULTIPLY", "FtoF_PM_LUMA_*", "multiplyalpha_ftof_pm_luma_*_ps.h"),
("LUMAF_UNMULTIPLY", "FtoF_UM_LUMA_*", "multiplyalpha_ftof_um_luma_*_ps.h"),
("LUMAALPHAF_PREMULTIPLY", "FtoF_PM_LUMAALPHA_*", "multiplyalpha_ftof_pm_lumaalpha_*_ps.h"),
("LUMAALPHAF_UNMULTIPLY", "FtoF_UM_LUMAALPHA_*", "multiplyalpha_ftof_um_lumaalpha_*_ps.h"),
("RGBAF_4444", "PassthroughRGBA*_4444", "passthroughrgba*_4444_11ps.h"),
("RGBAF_4444_PREMULTIPLY", "FtoF_PM_RGBA_4444_*", "multiplyalpha_ftof_pm_rgba_4444_*_ps.h"),
("RGBAF_4444_UNMULTIPLY", "FtoF_UM_RGBA_4444_*", "multiplyalpha_ftof_um_rgba_4444_*_ps.h"),
("RGBF_565", "PassthroughRGB*_565", "passthroughrgb*_565_11ps.h"),
("RGBF_565_PREMULTIPLY", "FtoF_PM_RGB_565_*", "multiplyalpha_ftof_pm_rgb_565_*_ps.h"),
("RGBF_565_UNMULTIPLY", "FtoF_UM_RGB_565_*", "multiplyalpha_ftof_um_rgb_565_*_ps.h"),
("RGBAF_5551", "PassthroughRGBA*_5551", "passthroughrgba*_5551_11ps.h"),
("RGBAF_5551_PREMULTIPLY", "FtoF_PM_RGBA_5551_*", "multiplyalpha_ftof_pm_rgba_5551_*_ps.h"),
("RGBAF_5551_UNMULTIPLY", "FtoF_UM_RGBA_5551_*", "multiplyalpha_ftof_um_rgba_5551_*_ps.h")
]
def format_shader_include(dimension, blitshader):
return template_compiled_blitshader_include.format(
filename=blitshader[2].replace("*", dimension.lower()))
def format_get_blitshader_case(operation):
dimension_cases = []
for dimension in supported_dimensions:
dimension_cases.append(format_get_blitshader_case_dimension(operation, dimension))
return template_get_blitshader_case.format(
get_blitshader_dimension_cases="\n".join([c for c in dimension_cases]),
operation=operation)
def format_get_blitshader_case_dimension(operation, dimension):
# 2D float to int shaders have not been implemented
if dimension == "2D" and operation.find("TOI") != -1:
blitshader = "INVALID"
else:
blitshader = dimension.upper() + "_" + operation
return template_get_blitshader_case_dimension.format(
dimension=dimension.upper(), blitshader=blitshader)
def format_map_blitshader_case(dimension, blitshader):
blitshader_name = "BLITSHADER_" + dimension.upper() + "_" + blitshader[0]
# 3D and 2DArray use the RGBA shader for passthrough alpha
if dimension != "2D" and blitshader[0] == "ALPHA":
compiled_shader_name = "PassthroughRGBA" + dimension
else:
compiled_shader_name = blitshader[1].replace("*", dimension)
shader_comment = compiled_shader_name.replace("_", " ")
case = template_map_blitshader_case.format(
blitshader_name=blitshader_name,
dimension=dimension,
dimension_upper=dimension.upper(),
compiled_shader_name=compiled_shader_name,
shader_comment=shader_comment,
)
return case
def format_shader_filename(dimension, blitshader):
return "shaders/compiled/" + blitshader[2].replace("*", dimension.lower()) + ","
def get_shader_includes():
includes = []
for dimension in supported_dimensions:
for blitshader in blitshader_data:
# 2D float to int shaders have not been implemented
if dimension == "2D" and blitshader[0].find("TOI") != -1:
continue
# 3D and 2DArray just use the RGBA shader for passthrough alpha
if dimension != "2D" and blitshader[0] == "ALPHA":
continue
if len(blitshader) == 3:
includes.append(format_shader_include(dimension, blitshader))
return includes
def get_blitshader_cases():
blitshader_cases = []
for blitshader in blitshader_data:
blitshader_cases.append(format_get_blitshader_case(blitshader[0]))
return blitshader_cases
def get_map_blitshader_cases():
blitshader_cases = []
for dimension in supported_dimensions:
for blitshader in blitshader_data:
# 2D float to int shaders have not been implemented
if dimension == "2D" and blitshader[0].find("TOI") != -1:
continue
blitshader_cases.append(format_map_blitshader_case(dimension, blitshader))
return blitshader_cases
def get_blitshaderop_enums():
blitshaderops = []
for blitshader in blitshader_data:
blitshaderops.append(" " + blitshader[0] + ",")
blitshaderops.append(" OPERATION_INVALID")
return blitshaderops
def get_blitshadertype_enums():
blitshaders = []
for dimension in supported_dimensions:
for blitshader in blitshader_data:
# 2D float to int shaders have not been implemented
if dimension == "2D" and blitshader[0].find("TOI") != -1:
continue
blitshaders.append(" BLITSHADER_" + dimension.upper() + "_" + blitshader[0] + ",")
blitshaders.append(" BLITSHADER_INVALID")
return blitshaders
def get_shader_filenames():
filenames = []
for dimension in supported_dimensions:
for blitshader in blitshader_data:
# 2D float to int shaders have not been implemented
if dimension == "2D" and blitshader[0].find("TOI") != -1:
continue
# 3D and 2DArray just use the RGBA shader for passthrough alpha
if dimension != "2D" and blitshader[0] == "ALPHA":
continue
if len(blitshader) == 3:
filenames.append(
(" \"d3d11/shaders/compiled/{0}\",").format(blitshader[2].replace(
"*", dimension.lower())))
return filenames
def write_inc_file(get_blitshaders_case_list, add_blitshader_case_list, shader_includes,
blitshaderop_enums, blitshadertype_enums):
content = template_blitshader_source.format(
script_name=os.path.basename(sys.argv[0]),
blitshaderop_enums=blitshaderop_enums,
blitshadertype_enums=blitshadertype_enums,
get_blitshaders_case_list=get_blitshaders_case_list,
add_blitshader_case_list=add_blitshader_case_list,
shader_includes=shader_includes)
path = os.path.join("Blit11Helper_autogen.inc")
with open(path, "w") as out:
out.write(content)
out.close()
def write_gni_file(shader_filename_list):
content = template_blitshaders_gni.format(
script_name=os.path.basename(sys.argv[0]),
shader_filename_list=shader_filename_list)
path = os.path.join("d3d11_blit_shaders_autogen.gni")
with open(path, "w") as out:
out.write(content)
out.close()
def main():
# auto_script parameters.
if len(sys.argv) > 1:
inputs = []
outputs = ['Blit11Helper_autogen.inc', 'd3d11_blit_shaders_autogen.gni']
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
map_blitshader_cases = []
shader_includes = []
blitshadertype_cases = []
blitshadertype_enums = []
blitshaderop_enums = []
shader_filenames = []
map_blitshader_cases = get_map_blitshader_cases()
shader_includes = get_shader_includes()
blitshadertype_cases = get_blitshader_cases()
blitshaderop_enums = get_blitshaderop_enums()
blitshadertype_enums = get_blitshadertype_enums()
shader_filenames = get_shader_filenames()
write_inc_file("\n".join([d for d in blitshadertype_cases]), "\n".join(
[c for c in map_blitshader_cases]), "\n".join([i for i in shader_includes]), "\n".join(
[e for e in blitshaderop_enums]), "\n".join([e for e in blitshadertype_enums]))
write_gni_file("\n".join([s for s in shader_filenames]))
return 0
if __name__ == '__main__':
sys.exit(main())