Path: blob/21.2-virgl/src/gallium/drivers/swr/rasterizer/codegen/templates/gen_knobs.h
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}.h23*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#pragma once35#include <string>3637struct KnobBase38{39private:40// Update the input string.41static void autoExpandEnvironmentVariables(std::string& text);4243protected:44// Leave input alone and return new string.45static std::string expandEnvironmentVariables(std::string const& input)46{47std::string text = input;48autoExpandEnvironmentVariables(text);49return text;50}5152template <typename T>53static T expandEnvironmentVariables(T const& input)54{55return input;56}57};5859template <typename T>60struct Knob : KnobBase61{62public:63const T& Value() const { return m_Value; }64const T& Value(T const& newValue)65{66m_Value = expandEnvironmentVariables(newValue);67return Value();68}6970private:71T m_Value;72};7374#define DEFINE_KNOB(_name, _type) \\7576struct Knob_##_name : Knob<_type> \\7778{ \\7980static const char* Name() { return "KNOB_" #_name; } \\8182static _type DefaultValue() { return (m_default); } \\8384private: \\8586static _type m_default; \\8788} _name;8990#define GET_KNOB(_name) g_GlobalKnobs._name.Value()91#define SET_KNOB(_name, _newValue) g_GlobalKnobs._name.Value(_newValue)9293struct GlobalKnobs94{95% for knob in knobs:96//-----------------------------------------------------------97// KNOB_${knob[0]}98//99% for line in knob[1]['desc']:100// ${line}101% endfor102% if knob[1].get('choices'):103<%104choices = knob[1].get('choices')105_max_len = calc_max_name_len(choices) %>//106% for i in range(len(choices)):107// ${choices[i]['name']}${space_name(choices[i]['name'], _max_len)} = ${format(choices[i]['value'], '#010x')}108% endfor109% endif110//111DEFINE_KNOB(${knob[0]}, ${knob[1]['type']});112113% endfor114115std::string ToString(const char* optPerLinePrefix="");116GlobalKnobs();117};118extern GlobalKnobs g_GlobalKnobs;119120#undef DEFINE_KNOB121122% for knob in knobs:123#define KNOB_${knob[0]}${space_knob(knob[0])} GET_KNOB(${knob[0]})124% endfor125126<%!127# Globally available python128max_len = 0129def calc_max_knob_len(knobs):130global max_len131max_len = 0132for knob in knobs:133if len(knob[0]) > max_len: max_len = len(knob[0])134max_len += len('KNOB_ ')135if max_len % 4: max_len += 4 - (max_len % 4)136137def space_knob(knob):138knob_len = len('KNOB_' + knob)139return ' '*(max_len - knob_len)140141def calc_max_name_len(choices_array):142_max_len = 0143for choice in choices_array:144if len(choice['name']) > _max_len: _max_len = len(choice['name'])145146if _max_len % 4: _max_len += 4 - (_max_len % 4)147return _max_len148149def space_name(name, max_len):150name_len = len(name)151return ' '*(max_len - name_len)152%>153// clang-format on154155156