Path: blob/21.2-virgl/src/gallium/drivers/swr/rasterizer/codegen/templates/gen_knobs.cpp
4574 views
/******************************************************************************1* Copyright (C) 2015-2018 Intel Corporation. All Rights Reserved.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*22* @file ${filename}.cpp23*24* @brief Dynamic Knobs for Core.25*26* ======================= AUTO GENERATED: DO NOT EDIT !!! ====================27*28* Generation Command Line:29* ${'\n * '.join(cmdline)}30*31******************************************************************************/32// clang-format off33<% calc_max_knob_len(knobs) %>34% for inc in includes:35#include <${inc}>36% endfor37#include <regex>38#include <core/utils.h>3940//========================================================41// Implementation42//========================================================43void KnobBase::autoExpandEnvironmentVariables(std::string& text)44{45size_t start;46while ((start = text.find("${'${'}")) != std::string::npos)47{48size_t end = text.find("}");49if (end == std::string::npos)50break;51const std::string var = GetEnv(text.substr(start + 2, end - start - 2));52text.replace(start, end - start + 1, var);53}54// win32 style variable replacement55while ((start = text.find("%")) != std::string::npos)56{57size_t end = text.find("%", start + 1);58if (end == std::string::npos)59break;60const std::string var = GetEnv(text.substr(start + 1, end - start - 1));61text.replace(start, end - start + 1, var);62}63}6465//========================================================66// Static Data Members67//========================================================68% for knob in knobs:69% if knob[1]['type'] == 'std::string':70${knob[1]['type']} GlobalKnobs::Knob_${knob[0]}::m_default = "${repr(knob[1]['default'])[1:-1]}";71% else:72${knob[1]['type']} GlobalKnobs::Knob_${knob[0]}::m_default = ${knob[1]['default']};73% endif74% endfor75GlobalKnobs g_GlobalKnobs;7677//========================================================78// Knob Initialization79//========================================================80GlobalKnobs::GlobalKnobs()81{82% for knob in knobs :83InitKnob(${ knob[0] });84% endfor85}8687//========================================================88// Knob Display (Convert to String)89//========================================================90std::string GlobalKnobs::ToString(const char* optPerLinePrefix)91{92std::basic_stringstream<char> str;93str << std::showbase << std::setprecision(1) << std::fixed;9495if (optPerLinePrefix == nullptr)96{97optPerLinePrefix = "";98}99100% for knob in knobs:101str << optPerLinePrefix << "KNOB_${knob[0]}:${space_knob(knob[0])}";102% if knob[1]['type'] == 'bool':103str << (KNOB_${knob[0]} ? "+\n" : "-\n");104% elif knob[1]['type'] != 'float' and knob[1]['type'] != 'std::string':105str << std::hex << std::setw(11) << std::left << KNOB_${knob[0]};106str << std::dec << KNOB_${knob[0]} << "\n";107% else:108str << KNOB_${knob[0]} << "\n";109% endif110% endfor111str << std::ends;112113return str.str();114}115<%!116# Globally available python117max_len = 0118def calc_max_knob_len(knobs):119global max_len120max_len = 0121for knob in knobs:122if len(knob[0]) > max_len: max_len = len(knob[0])123max_len += len('KNOB_ ')124if max_len % 4: max_len += 4 - (max_len % 4)125126def space_knob(knob):127knob_len = len('KNOB_' + knob)128return ' '*(max_len - knob_len)129130def calc_max_name_len(choices_array):131_max_len = 0132for choice in choices_array:133if len(choice['name']) > _max_len: _max_len = len(choice['name'])134135if _max_len % 4: _max_len += 4 - (_max_len % 4)136return _max_len137138def space_name(name, max_len):139name_len = len(name)140return ' '*(max_len - name_len)141%>142// clang-format on143144145