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 MESA_CLC_HELPERS_H 25 #define MESA_CLC_HELPERS_H 26 27 #include "glsl_types.h" 28 29 #include "clc.h" 30 #include "util/u_string.h" 31 32 #include <assert.h> 33 #include <stddef.h> 34 #include <stdio.h> 35 #include <stdint.h> 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 void 42 clc_initialize_llvm(void); 43 44 bool 45 clc_spirv_get_kernels_info(const struct clc_binary *spvbin, 46 const struct clc_kernel_info **kernels, 47 unsigned *num_kernels, 48 const struct clc_parsed_spec_constant **spec_constants, 49 unsigned *num_spec_constants, 50 const struct clc_logger *logger); 51 52 void 53 clc_free_kernels_info(const struct clc_kernel_info *kernels, 54 unsigned num_kernels); 55 56 int 57 clc_c_to_spir(const struct clc_compile_args *args, 58 const struct clc_logger *logger, 59 struct clc_binary *out_spir, 60 struct set *dependencies); 61 62 int 63 clc_spir_to_spirv(const struct clc_binary *in_spir, 64 const struct clc_logger *logger, 65 struct clc_binary *out_spirv); 66 67 int 68 clc_c_to_spirv(const struct clc_compile_args *args, 69 const struct clc_logger *logger, 70 struct clc_binary *out_spirvl, 71 struct set *dependencies); 72 73 int 74 clc_link_spirv_binaries(const struct clc_linker_args *args, 75 const struct clc_logger *logger, 76 struct clc_binary *out_spirv); 77 78 bool 79 clc_validate_spirv(const struct clc_binary *spirv, 80 const struct clc_logger *logger, 81 const struct clc_validator_options *options); 82 83 int 84 clc_spirv_specialize(const struct clc_binary *in_spirv, 85 const struct clc_parsed_spirv *parsed_data, 86 const struct clc_spirv_specialization_consts *consts, 87 struct clc_binary *out_spirv); 88 89 void 90 clc_dump_spirv(const struct clc_binary *spvbin, FILE *f); 91 92 void 93 clc_free_spir_binary(struct clc_binary *spir); 94 95 void 96 clc_free_spirv_binary(struct clc_binary *spvbin); 97 98 #define clc_log(logger, level, fmt, ...) do { \ 99 if (!logger || !logger->level) break; \ 100 char *_msg = NULL; \ 101 int r = asprintf(&_msg, fmt, ##__VA_ARGS__); \ 102 if (r < 0) break; \ 103 assert(_msg); \ 104 logger->level(logger->priv, _msg); \ 105 free(_msg); \ 106 } while (0) 107 108 #define clc_error(logger, fmt, ...) clc_log(logger, error, fmt, ##__VA_ARGS__) 109 #define clc_warning(logger, fmt, ...) clc_log(logger, warning, fmt, ##__VA_ARGS__) 110 111 #ifdef __cplusplus 112 } 113 #endif 114 115 #endif /* MESA_CLC_HELPERS_H */ 116