"Fossies" - the Fresh Open Source Software Archive

Member "mesa-20.1.8/src/gallium/drivers/swr/rasterizer/codegen/templates/gen_knobs.h" (16 Sep 2020, 4631 Bytes) of package /linux/misc/mesa-20.1.8.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "gen_knobs.h" see the Fossies "Dox" file reference documentation.

    1 /******************************************************************************
    2  * Copyright (C) 2015-2018 Intel Corporation.   All Rights Reserved.
    3  *
    4  * Permission is hereby granted, free of charge, to any person obtaining a
    5  * copy of this software and associated documentation files (the "Software"),
    6  * to deal in the Software without restriction, including without limitation
    7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
    8  * and/or sell copies of the Software, and to permit persons to whom the
    9  * Software is furnished to do so, subject to the following conditions:
   10  *
   11  * The above copyright notice and this permission notice (including the next
   12  * paragraph) shall be included in all copies or substantial portions of the
   13  * Software.
   14  *
   15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
   18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
   20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
   21  * IN THE SOFTWARE.
   22  *
   23  * @file ${filename}.h
   24  *
   25  * @brief Dynamic Knobs for Core.
   26  *
   27  * ======================= AUTO GENERATED: DO NOT EDIT !!! ====================
   28  *
   29  * Generation Command Line:
   30  *  ${'\n *    '.join(cmdline)}
   31  *
   32  ******************************************************************************/
   33 // clang-format off
   34 <% calc_max_knob_len(knobs) %>
   35 #pragma once
   36 #include <string>
   37 
   38 struct KnobBase
   39 {
   40 private:
   41     // Update the input string.
   42     static void autoExpandEnvironmentVariables(std::string& text);
   43 
   44 protected:
   45     // Leave input alone and return new string.
   46     static std::string expandEnvironmentVariables(std::string const& input)
   47     {
   48         std::string text = input;
   49         autoExpandEnvironmentVariables(text);
   50         return text;
   51     }
   52 
   53     template <typename T>
   54     static T expandEnvironmentVariables(T const& input)
   55     {
   56         return input;
   57     }
   58 };
   59 
   60 template <typename T>
   61 struct Knob : KnobBase
   62 {
   63 public:
   64     const T& Value() const { return m_Value; }
   65     const T& Value(T const& newValue)
   66     {
   67         m_Value = expandEnvironmentVariables(newValue);
   68         return Value();
   69     }
   70 
   71 private:
   72     T m_Value;
   73 };
   74 
   75 #define DEFINE_KNOB(_name, _type)                               \\
   76 
   77     struct Knob_##_name : Knob<_type>                           \\
   78 
   79     {                                                           \\
   80 
   81         static const char* Name() { return "KNOB_" #_name; }    \\
   82 
   83         static _type DefaultValue() { return (m_default); }     \\
   84 
   85     private:                                                    \\
   86 
   87         static _type m_default;                                 \\
   88 
   89     } _name;
   90 
   91 #define GET_KNOB(_name)             g_GlobalKnobs._name.Value()
   92 #define SET_KNOB(_name, _newValue)  g_GlobalKnobs._name.Value(_newValue)
   93 
   94 struct GlobalKnobs
   95 {
   96     % for knob in knobs:
   97     //-----------------------------------------------------------
   98     // KNOB_${knob[0]}
   99     //
  100     % for line in knob[1]['desc']:
  101     // ${line}
  102     % endfor
  103     % if knob[1].get('choices'):
  104     <%
  105     choices = knob[1].get('choices')
  106     _max_len = calc_max_name_len(choices) %>//
  107     % for i in range(len(choices)):
  108     //     ${choices[i]['name']}${space_name(choices[i]['name'], _max_len)} = ${format(choices[i]['value'], '#010x')}
  109     % endfor
  110     % endif
  111     //
  112     DEFINE_KNOB(${knob[0]}, ${knob[1]['type']});
  113 
  114     % endfor
  115 
  116     std::string ToString(const char* optPerLinePrefix="");
  117     GlobalKnobs();
  118 };
  119 extern GlobalKnobs g_GlobalKnobs;
  120 
  121 #undef DEFINE_KNOB
  122 
  123 % for knob in knobs:
  124 #define KNOB_${knob[0]}${space_knob(knob[0])} GET_KNOB(${knob[0]})
  125 % endfor
  126 
  127 <%!
  128     # Globally available python 
  129     max_len = 0
  130     def calc_max_knob_len(knobs):
  131         global max_len
  132         max_len = 0
  133         for knob in knobs:
  134             if len(knob[0]) > max_len: max_len = len(knob[0])
  135         max_len += len('KNOB_ ')
  136         if max_len % 4: max_len += 4 - (max_len % 4)
  137 
  138     def space_knob(knob):
  139         knob_len = len('KNOB_' + knob)
  140         return ' '*(max_len - knob_len)
  141 
  142     def calc_max_name_len(choices_array):
  143         _max_len = 0
  144         for choice in choices_array:
  145             if len(choice['name']) > _max_len: _max_len = len(choice['name'])
  146 
  147         if _max_len % 4: _max_len += 4 - (_max_len % 4)
  148         return _max_len
  149 
  150     def space_name(name, max_len):
  151         name_len = len(name)
  152         return ' '*(max_len - name_len)
  153 %>
  154 // clang-format on