1 /* 2 * Copyright © Microsoft Corporation 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 24 #ifndef DXIL_FUNCTION_H 25 #define DXIL_FUNCTION_H 26 27 #define DXIL_FUNC_PARAM_INT64 'l' 28 #define DXIL_FUNC_PARAM_INT32 'i' 29 #define DXIL_FUNC_PARAM_INT16 'h' 30 #define DXIL_FUNC_PARAM_INT8 'c' 31 #define DXIL_FUNC_PARAM_BOOL 'b' 32 33 #define DXIL_FUNC_PARAM_FLOAT64 'g' 34 #define DXIL_FUNC_PARAM_FLOAT32 'f' 35 #define DXIL_FUNC_PARAM_FLOAT16 'e' 36 #define DXIL_FUNC_PARAM_HANDLE '@' 37 #define DXIL_FUNC_PARAM_POINTER '*' 38 #define DXIL_FUNC_PARAM_VOID 'v' 39 #define DXIL_FUNC_PARAM_FROM_OVERLOAD 'O' 40 #define DXIL_FUNC_PARAM_RESRET 'R' 41 #define DXIL_FUNC_PARAM_CBUF_RET 'B' 42 #define DXIL_FUNC_PARAM_DIM 'D' 43 #define DXIL_FUNC_PARAM_SPLIT_DOUBLE 'G' 44 #define DXIL_FUNC_PARAM_SAMPLE_POS 'S' 45 46 #include "dxil_module.h" 47 #include "util/rb_tree.h" 48 49 const char *dxil_overload_suffix( enum overload_type overload); 50 51 const struct dxil_type * 52 dxil_get_overload_type(struct dxil_module *mod, enum overload_type overload); 53 54 /* These functions implement a generic method for declaring functions 55 * The input parameters types are given as a string using the characters 56 * given above as identifyer for the types. Only scalars and pointers to 57 * scalars are implemented at this point. 58 * 59 * Examples: 60 * 61 * Call: dxil_alloc_func(mod, "storeData.f32", "v", "icf"); 62 * Result function: void storeData.f32(int32, int8, float32) 63 * 64 * Call: dxil_alloc_func(mod, "storeData.f32", "e", "*icf"); 65 * Result function: float16 storeData.f32(int32 *, int8, float32) 66 * 67 * Call: dxil_alloc_func(mod, "storeData.f32", "*h", "b*f"); 68 * Result function: float16 storeData.f32(bool *, float32 *) 69 * 70 */ 71 72 const struct dxil_func * 73 dxil_alloc_func(struct dxil_module *mod, const char *name, enum overload_type overload, 74 const char *retval_type_descr, const char *param_descr, enum dxil_attr_kind attr); 75 76 /* For specifically constructed return types one can also create the return type 77 * seperately and pass it as paramaer 78 */ 79 const struct dxil_func * 80 dxil_alloc_func_with_rettype(struct dxil_module *mod, const char *name, enum overload_type overload, 81 const struct dxil_type *retval_type, const char *param_descr, 82 enum dxil_attr_kind attr); 83 84 /* This call should be the usual entry point to allocate a new function type. 85 * 'name' must either be in the list of predefined functions, or a function 86 * with 'name' and 'overload' must already be allocated by using one of the above 87 * function calls. The allocated functions are searched for by using an rb_tree, so 88 * the search complexity should be O(log(n)). 89 */ 90 const struct dxil_func * 91 dxil_get_function(struct dxil_module *mod, const char *name, 92 enum overload_type overload); 93 94 #endif // DXIL_FUNCTION_H 95