2022-10-11 04:00:16 +03:00
|
|
|
#!/usr/bin/python3
|
|
|
|
#
|
|
|
|
# Copyright 2022 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_interpreter_utils.py:
|
|
|
|
# Code generator for the GLC interpreter.
|
|
|
|
# NOTE: don't run this script directly. Run scripts/run_code_generation.py.
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
|
|
|
|
import registry_xml
|
|
|
|
|
|
|
|
EXIT_SUCCESS = 0
|
|
|
|
EXIT_FAILURE = 1
|
|
|
|
|
|
|
|
BASE_PATH = '../util/capture/trace_interpreter_autogen'
|
|
|
|
|
|
|
|
CPP_TEMPLATE = """\
|
|
|
|
// GENERATED FILE - DO NOT EDIT.
|
|
|
|
// Generated by {script_name} using data from {data_source_name}.
|
|
|
|
//
|
|
|
|
// Copyright 2022 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.
|
|
|
|
//
|
|
|
|
// {file_name}.cpp:
|
|
|
|
// Helper code for trace interpreter.
|
|
|
|
|
|
|
|
#include "angle_trace_gl.h"
|
|
|
|
#include "trace_fixture.h"
|
|
|
|
#include "trace_interpreter.h"
|
|
|
|
|
|
|
|
namespace angle
|
|
|
|
{{
|
|
|
|
CallCapture ParseCallCapture(const Token &nameToken, size_t numParamTokens, const Token *paramTokens, const TraceShaderMap &shaders)
|
|
|
|
{{
|
|
|
|
{cases}
|
|
|
|
ASSERT(numParamTokens == 0);
|
|
|
|
return CallCapture(nameToken, ParamBuffer());
|
|
|
|
}}
|
|
|
|
}} // namespace angle
|
|
|
|
"""
|
|
|
|
|
|
|
|
CASE = """\
|
|
|
|
if (strcmp(nameToken, "{ep}") == 0)
|
|
|
|
{{
|
|
|
|
ParamBuffer params = ParseParameters<{pfn}>(paramTokens, shaders);
|
|
|
|
return CallCapture({call}, std::move(params));
|
|
|
|
}}
|
|
|
|
"""
|
|
|
|
|
|
|
|
FIXTURE_H = '../util/capture/trace_fixture.h'
|
|
|
|
|
|
|
|
|
|
|
|
def GetFunctionsFromFixture():
|
|
|
|
funcs = []
|
|
|
|
pattern = 'void '
|
|
|
|
with open(FIXTURE_H) as f:
|
|
|
|
lines = f.read().split('\n')
|
|
|
|
for line in lines:
|
|
|
|
if line.startswith(pattern):
|
|
|
|
funcs.append(line[len(pattern):line.find('(')])
|
|
|
|
f.close()
|
|
|
|
return sorted(funcs)
|
|
|
|
|
|
|
|
|
|
|
|
def main(cpp_output_path):
|
|
|
|
gles = registry_xml.GetGLES()
|
|
|
|
egl = registry_xml.GetEGL()
|
|
|
|
|
|
|
|
def fn(ep):
|
|
|
|
return 'std::remove_pointer<PFN%sPROC>::type' % ep.upper()
|
|
|
|
|
|
|
|
eps_and_enums = sorted(list(set(gles.GetEnums() + egl.GetEnums())))
|
|
|
|
cases = [
|
|
|
|
CASE.format(ep=ep, pfn=fn(ep), call='EntryPoint::%s' % enum)
|
|
|
|
for (enum, ep) in eps_and_enums
|
|
|
|
]
|
|
|
|
cases += [
|
|
|
|
CASE.format(ep=func, pfn='decltype(%s)' % func, call='"%s"' % func)
|
|
|
|
for func in GetFunctionsFromFixture()
|
|
|
|
]
|
|
|
|
|
|
|
|
format_args = {
|
|
|
|
'script_name': os.path.basename(sys.argv[0]),
|
|
|
|
'data_source_name': 'gl.xml and gl_angle_ext.xml',
|
|
|
|
'file_name': os.path.basename(BASE_PATH),
|
|
|
|
'cases': ''.join(cases),
|
|
|
|
}
|
|
|
|
|
|
|
|
cpp_content = CPP_TEMPLATE.format(**format_args)
|
|
|
|
cpp_output_path = registry_xml.script_relative(cpp_output_path)
|
|
|
|
with open(cpp_output_path, 'w') as f:
|
|
|
|
f.write(cpp_content)
|
|
|
|
|
|
|
|
return EXIT_SUCCESS
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2022-12-15 18:53:30 +03:00
|
|
|
inputs = registry_xml.xml_inputs + [FIXTURE_H]
|
2022-10-11 04:00:16 +03:00
|
|
|
outputs = [
|
|
|
|
'%s.cpp' % BASE_PATH,
|
|
|
|
]
|
|
|
|
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
if sys.argv[1] == 'inputs':
|
|
|
|
print(','.join(inputs))
|
|
|
|
elif sys.argv[1] == 'outputs':
|
|
|
|
print(','.join(outputs))
|
|
|
|
else:
|
|
|
|
sys.exit(main(registry_xml.script_relative(outputs[0])))
|