From 5d0b3b05a28b2e236d3d8aa7b6335b0be4f02eda Mon Sep 17 00:00:00 2001 From: Tim Rowley Date: Wed, 15 Mar 2017 11:58:10 -0500 Subject: swr: [rasterizer codegen] Fix generation of knobs Reviewed-by: Bruce Cherniak --- src/gallium/drivers/swr/Makefile.am | 10 +- src/gallium/drivers/swr/SConscript | 4 +- .../drivers/swr/rasterizer/codegen/gen_backends.py | 2 + .../drivers/swr/rasterizer/codegen/gen_knobs.py | 2 + .../swr/rasterizer/codegen/gen_llvm_ir_macros.py | 2 + .../codegen/templates/backend_template.cpp | 3 + .../codegen/templates/gen_builder_template.hpp | 3 + .../rasterizer/codegen/templates/knobs.template | 167 -------------------- .../codegen/templates/knobs_template.cpp | 170 +++++++++++++++++++++ 9 files changed, 189 insertions(+), 174 deletions(-) delete mode 100644 src/gallium/drivers/swr/rasterizer/codegen/templates/knobs.template create mode 100644 src/gallium/drivers/swr/rasterizer/codegen/templates/knobs_template.cpp (limited to 'src/gallium') diff --git a/src/gallium/drivers/swr/Makefile.am b/src/gallium/drivers/swr/Makefile.am index f9fda31c086..771f1a82439 100644 --- a/src/gallium/drivers/swr/Makefile.am +++ b/src/gallium/drivers/swr/Makefile.am @@ -71,19 +71,19 @@ swr_context_llvm.h: rasterizer/codegen/gen_llvm_types.py swr_context.h --input $(srcdir)/swr_context.h \ --output swr_context_llvm.h -rasterizer/codegen/gen_knobs.cpp: rasterizer/codegen/gen_knobs.py rasterizer/codegen/knob_defs.py rasterizer/codegen/templates/knobs.template +rasterizer/codegen/gen_knobs.cpp: rasterizer/codegen/gen_knobs.py rasterizer/codegen/knob_defs.py rasterizer/codegen/templates/knobs_template.cpp $(MKDIR_GEN) $(PYTHON_GEN) \ $(srcdir)/rasterizer/codegen/gen_knobs.py \ - --input $(srcdir)/rasterizer/codegen/templates/knobs.template \ + --input $(srcdir)/rasterizer/codegen/templates/knobs_template.cpp \ --output rasterizer/codegen/gen_knobs.cpp \ --gen_cpp -rasterizer/codegen/gen_knobs.h: rasterizer/codegen/gen_knobs.py rasterizer/codegen/knob_defs.py rasterizer/codegen/templates/knobs.template +rasterizer/codegen/gen_knobs.h: rasterizer/codegen/gen_knobs.py rasterizer/codegen/knob_defs.py rasterizer/codegen/templates/knobs_template.cpp $(MKDIR_GEN) $(PYTHON_GEN) \ $(srcdir)/rasterizer/codegen/gen_knobs.py \ - --input $(srcdir)/rasterizer/codegen/templates/knobs.template \ + --input $(srcdir)/rasterizer/codegen/templates/knobs_template.cpp \ --output rasterizer/codegen/gen_knobs.h \ --gen_h @@ -258,7 +258,7 @@ EXTRA_DIST = \ rasterizer/codegen/mako/runtime.py \ rasterizer/codegen/mako/template.py \ rasterizer/codegen/mako/util.py \ - rasterizer/codegen/templates/knobs.template \ + rasterizer/codegen/templates/knobs_template.cpp \ rasterizer/codegen/templates/ar_event_h.template \ rasterizer/codegen/templates/ar_event_cpp.template \ rasterizer/codegen/templates/ar_eventhandler_h.template \ diff --git a/src/gallium/drivers/swr/SConscript b/src/gallium/drivers/swr/SConscript index 6e228f43154..754e6784f2e 100644 --- a/src/gallium/drivers/swr/SConscript +++ b/src/gallium/drivers/swr/SConscript @@ -51,14 +51,14 @@ swrroot = '#src/gallium/drivers/swr/' env.CodeGenerate( target = 'rasterizer/codegen/gen_knobs.cpp', script = swrroot + 'rasterizer/codegen/gen_knobs.py', - source = 'rasterizer/codegen/templates/knobs.template', + source = 'rasterizer/codegen/templates/knobs_template.cpp', command = python_cmd + ' $SCRIPT --input $SOURCE --output $TARGET --gen_cpp' ) env.CodeGenerate( target = 'rasterizer/codegen/gen_knobs.h', script = swrroot + 'rasterizer/codegen/gen_knobs.py', - source = 'rasterizer/codegen/templates/knobs.template', + source = 'rasterizer/codegen/templates/knobs_template.cpp', command = python_cmd + ' $SCRIPT --input $SOURCE --output $TARGET --gen_h' ) diff --git a/src/gallium/drivers/swr/rasterizer/codegen/gen_backends.py b/src/gallium/drivers/swr/rasterizer/codegen/gen_backends.py index d6367ca73f1..c889ea5816e 100644 --- a/src/gallium/drivers/swr/rasterizer/codegen/gen_backends.py +++ b/src/gallium/drivers/swr/rasterizer/codegen/gen_backends.py @@ -103,6 +103,7 @@ def main(args=sys.argv[1:]): write_template_to_file( templateCpp, baseCppName % str(fileNum), + cmdline=sys.argv, fileNum=fileNum, funcList=chunkedList[fileNum]) @@ -114,6 +115,7 @@ def main(args=sys.argv[1:]): write_template_to_file( templateCmake, cmakeFile, + cmdline=sys.argv, numFiles=numFiles, baseCppName=baseCppName.replace('\\','/')) diff --git a/src/gallium/drivers/swr/rasterizer/codegen/gen_knobs.py b/src/gallium/drivers/swr/rasterizer/codegen/gen_knobs.py index 225082e7882..50afdcdd10c 100644 --- a/src/gallium/drivers/swr/rasterizer/codegen/gen_knobs.py +++ b/src/gallium/drivers/swr/rasterizer/codegen/gen_knobs.py @@ -62,6 +62,7 @@ def main(args=sys.argv[1:]): if args.gen_h: write_template_to_file(args.input, args.output, + cmdline=sys.argv, filename='gen_knobs', knobs=knob_defs.KNOBS, includes=['core/knobs_init.h', 'common/os.h', 'sstream', 'iomanip'], @@ -70,6 +71,7 @@ def main(args=sys.argv[1:]): if args.gen_cpp: write_template_to_file(args.input, args.output, + cmdline=sys.argv, filename='gen_knobs', knobs=knob_defs.KNOBS, includes=['core/knobs_init.h', 'common/os.h', 'sstream', 'iomanip'], diff --git a/src/gallium/drivers/swr/rasterizer/codegen/gen_llvm_ir_macros.py b/src/gallium/drivers/swr/rasterizer/codegen/gen_llvm_ir_macros.py index 202dadaeeab..cfd63942dc1 100644 --- a/src/gallium/drivers/swr/rasterizer/codegen/gen_llvm_ir_macros.py +++ b/src/gallium/drivers/swr/rasterizer/codegen/gen_llvm_ir_macros.py @@ -218,6 +218,7 @@ def generate_gen_h(functions, output_dir): write_template_to_file( template, output_filename, + cmdline=sys.argv, comment='Builder IR Wrappers', filename=filename, functions=templfuncs, @@ -244,6 +245,7 @@ def generate_x86_h(output_dir): write_template_to_file( template, output_filename, + cmdline=sys.argv, comment='x86 intrinsics', filename=filename, functions=functions, diff --git a/src/gallium/drivers/swr/rasterizer/codegen/templates/backend_template.cpp b/src/gallium/drivers/swr/rasterizer/codegen/templates/backend_template.cpp index bb770fa7790..4eb4ad4f2b3 100644 --- a/src/gallium/drivers/swr/rasterizer/codegen/templates/backend_template.cpp +++ b/src/gallium/drivers/swr/rasterizer/codegen/templates/backend_template.cpp @@ -26,6 +26,9 @@ // // DO NOT EDIT // +// Generation Command Line: +// ${'\n// '.join(cmdline)} +// //============================================================================ #include "core/backend.h" diff --git a/src/gallium/drivers/swr/rasterizer/codegen/templates/gen_builder_template.hpp b/src/gallium/drivers/swr/rasterizer/codegen/templates/gen_builder_template.hpp index 6a56eb11573..2e957581ac4 100644 --- a/src/gallium/drivers/swr/rasterizer/codegen/templates/gen_builder_template.hpp +++ b/src/gallium/drivers/swr/rasterizer/codegen/templates/gen_builder_template.hpp @@ -26,6 +26,9 @@ // // DO NOT EDIT // +// Generation Command Line: +// ${'\n// '.join(cmdline)} +// //============================================================================ #pragma once diff --git a/src/gallium/drivers/swr/rasterizer/codegen/templates/knobs.template b/src/gallium/drivers/swr/rasterizer/codegen/templates/knobs.template deleted file mode 100644 index 1ae45e52e74..00000000000 --- a/src/gallium/drivers/swr/rasterizer/codegen/templates/knobs.template +++ /dev/null @@ -1,167 +0,0 @@ -<% - max_len = 0 - for knob in knobs: - if len(knob[0]) > max_len: max_len = len(knob[0]) - max_len += len('KNOB_ ') - if max_len % 4: max_len += 4 - (max_len % 4) - - def space_knob(knob): - knob_len = len('KNOB_' + knob) - return ' '*(max_len - knob_len) - - def calc_max_name_len(choices_array): - _max_len = 0 - for choice in choices_array: - if len(choice['name']) > _max_len: _max_len = len(choice['name']) - - if _max_len % 4: _max_len += 4 - (_max_len % 4) - return _max_len - - def space_name(name, max_len): - name_len = len(name) - return ' '*(max_len - name_len) - - -%>/****************************************************************************** -* -* Copyright 2015-2016 -* Intel Corporation -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http ://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* -% if gen_header: -* @file ${filename}.h -% else: -* @file ${filename}.cpp -% endif -* -* @brief Dynamic Knobs for Core. -* -* ======================= AUTO GENERATED: DO NOT EDIT !!! ==================== -* -******************************************************************************/ -%if gen_header: -#pragma once -#include - -template -struct Knob -{ - const T& Value() const { return m_Value; } - const T& Value(const T& newValue) { m_Value = newValue; return Value(); } - -protected: - Knob(const T& defaultValue) : m_Value(defaultValue) {} - -private: - T m_Value; -}; - -#define DEFINE_KNOB(_name, _type, _default) \\ - - struct Knob_##_name : Knob<_type> \\ - - { \\ - - Knob_##_name() : Knob<_type>(_default) { } \\ - - static const char* Name() { return "KNOB_" #_name; } \\ - - } _name; - -#define GET_KNOB(_name) g_GlobalKnobs._name.Value() -#define SET_KNOB(_name, _newValue) g_GlobalKnobs._name.Value(_newValue) - -struct GlobalKnobs -{ - % for knob in knobs: - //----------------------------------------------------------- - // KNOB_${knob[0]} - // - % for line in knob[1]['desc']: - // ${line} - % endfor - % if knob[1].get('choices'): - <% - choices = knob[1].get('choices') - _max_len = calc_max_name_len(choices) %>// - % for i in range(len(choices)): - // ${choices[i]['name']}${space_name(choices[i]['name'], _max_len)} = ${format(choices[i]['value'], '#010x')} - % endfor - % endif - // - % if knob[1]['type'] == 'std::string': - DEFINE_KNOB(${knob[0]}, ${knob[1]['type']}, "${repr(knob[1]['default'])[1:-1]}"); - % else: - DEFINE_KNOB(${knob[0]}, ${knob[1]['type']}, ${knob[1]['default']}); - % endif - - % endfor - GlobalKnobs(); - std::string ToString(const char* optPerLinePrefix=""); -}; -extern GlobalKnobs g_GlobalKnobs; - -#undef DEFINE_KNOB - -% for knob in knobs: -#define KNOB_${knob[0]}${space_knob(knob[0])} GET_KNOB(${knob[0]}) -% endfor - -% else: -% for inc in includes: -#include <${inc}> -% endfor - -//======================================================== -// Static Data Members -//======================================================== -GlobalKnobs g_GlobalKnobs; - -//======================================================== -// Knob Initialization -//======================================================== -GlobalKnobs::GlobalKnobs() -{ - % for knob in knobs: - InitKnob(${knob[0]}); - % endfor -} - -//======================================================== -// Knob Display (Convert to String) -//======================================================== -std::string GlobalKnobs::ToString(const char* optPerLinePrefix) -{ - std::basic_stringstream str; - str << std::showbase << std::setprecision(1) << std::fixed; - - if (optPerLinePrefix == nullptr) { optPerLinePrefix = ""; } - - % for knob in knobs: - str << optPerLinePrefix << "KNOB_${knob[0]}:${space_knob(knob[0])}"; - % if knob[1]['type'] == 'bool': - str << (KNOB_${knob[0]} ? "+\n" : "-\n"); - % elif knob[1]['type'] != 'float' and knob[1]['type'] != 'std::string': - str << std::hex << std::setw(11) << std::left << KNOB_${knob[0]}; - str << std::dec << KNOB_${knob[0]} << "\n"; - % else: - str << KNOB_${knob[0]} << "\n"; - % endif - % endfor - str << std::ends; - - return str.str(); -} - -% endif diff --git a/src/gallium/drivers/swr/rasterizer/codegen/templates/knobs_template.cpp b/src/gallium/drivers/swr/rasterizer/codegen/templates/knobs_template.cpp new file mode 100644 index 00000000000..99294d2290e --- /dev/null +++ b/src/gallium/drivers/swr/rasterizer/codegen/templates/knobs_template.cpp @@ -0,0 +1,170 @@ +<% + max_len = 0 + for knob in knobs: + if len(knob[0]) > max_len: max_len = len(knob[0]) + max_len += len('KNOB_ ') + if max_len % 4: max_len += 4 - (max_len % 4) + + def space_knob(knob): + knob_len = len('KNOB_' + knob) + return ' '*(max_len - knob_len) + + def calc_max_name_len(choices_array): + _max_len = 0 + for choice in choices_array: + if len(choice['name']) > _max_len: _max_len = len(choice['name']) + + if _max_len % 4: _max_len += 4 - (_max_len % 4) + return _max_len + + def space_name(name, max_len): + name_len = len(name) + return ' '*(max_len - name_len) + + +%>/****************************************************************************** +* +* Copyright 2015-2017 +* Intel Corporation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http ://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +% if gen_header: +* @file ${filename}.h +% else: +* @file ${filename}.cpp +% endif +* +* @brief Dynamic Knobs for Core. +* +* ======================= AUTO GENERATED: DO NOT EDIT !!! ==================== +* +* Generation Command Line: +* ${'\n* '.join(cmdline)} +* +******************************************************************************/ +%if gen_header: +#pragma once +#include + +template +struct Knob +{ + const T& Value() const { return m_Value; } + const T& Value(const T& newValue) { m_Value = newValue; return Value(); } + +protected: + Knob(const T& defaultValue) : m_Value(defaultValue) {} + +private: + T m_Value; +}; + +#define DEFINE_KNOB(_name, _type, _default) \\ + + struct Knob_##_name : Knob<_type> \\ + + { \\ + + Knob_##_name() : Knob<_type>(_default) { } \\ + + static const char* Name() { return "KNOB_" #_name; } \\ + + } _name; + +#define GET_KNOB(_name) g_GlobalKnobs._name.Value() +#define SET_KNOB(_name, _newValue) g_GlobalKnobs._name.Value(_newValue) + +struct GlobalKnobs +{ + % for knob in knobs: + //----------------------------------------------------------- + // KNOB_${knob[0]} + // + % for line in knob[1]['desc']: + // ${line} + % endfor + % if knob[1].get('choices'): + <% + choices = knob[1].get('choices') + _max_len = calc_max_name_len(choices) %>// + % for i in range(len(choices)): + // ${choices[i]['name']}${space_name(choices[i]['name'], _max_len)} = ${format(choices[i]['value'], '#010x')} + % endfor + % endif + // + % if knob[1]['type'] == 'std::string': + DEFINE_KNOB(${knob[0]}, ${knob[1]['type']}, "${repr(knob[1]['default'])[1:-1]}"); + % else: + DEFINE_KNOB(${knob[0]}, ${knob[1]['type']}, ${knob[1]['default']}); + % endif + + % endfor + GlobalKnobs(); + std::string ToString(const char* optPerLinePrefix=""); +}; +extern GlobalKnobs g_GlobalKnobs; + +#undef DEFINE_KNOB + +% for knob in knobs: +#define KNOB_${knob[0]}${space_knob(knob[0])} GET_KNOB(${knob[0]}) +% endfor + +% else: +% for inc in includes: +#include <${inc}> +% endfor + +//======================================================== +// Static Data Members +//======================================================== +GlobalKnobs g_GlobalKnobs; + +//======================================================== +// Knob Initialization +//======================================================== +GlobalKnobs::GlobalKnobs() +{ + % for knob in knobs: + InitKnob(${knob[0]}); + % endfor +} + +//======================================================== +// Knob Display (Convert to String) +//======================================================== +std::string GlobalKnobs::ToString(const char* optPerLinePrefix) +{ + std::basic_stringstream str; + str << std::showbase << std::setprecision(1) << std::fixed; + + if (optPerLinePrefix == nullptr) { optPerLinePrefix = ""; } + + % for knob in knobs: + str << optPerLinePrefix << "KNOB_${knob[0]}:${space_knob(knob[0])}"; + % if knob[1]['type'] == 'bool': + str << (KNOB_${knob[0]} ? "+\n" : "-\n"); + % elif knob[1]['type'] != 'float' and knob[1]['type'] != 'std::string': + str << std::hex << std::setw(11) << std::left << KNOB_${knob[0]}; + str << std::dec << KNOB_${knob[0]} << "\n"; + % else: + str << KNOB_${knob[0]} << "\n"; + % endif + % endfor + str << std::ends; + + return str.str(); +} + +% endif -- cgit v1.2.3