17ec681f3Smrg/* 27ec681f3Smrg * Copyright © Microsoft Corporation 37ec681f3Smrg * 47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 57ec681f3Smrg * copy of this software and associated documentation files (the "Software"), 67ec681f3Smrg * to deal in the Software without restriction, including without limitation 77ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 87ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the 97ec681f3Smrg * Software is furnished to do so, subject to the following conditions: 107ec681f3Smrg * 117ec681f3Smrg * The above copyright notice and this permission notice (including the next 127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the 137ec681f3Smrg * Software. 147ec681f3Smrg * 157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 187ec681f3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 197ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 207ec681f3Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 217ec681f3Smrg * IN THE SOFTWARE. 227ec681f3Smrg */ 237ec681f3Smrg 247ec681f3Smrg#ifndef CLC_COMPILER_H 257ec681f3Smrg#define CLC_COMPILER_H 267ec681f3Smrg 277ec681f3Smrg#include "clc/clc.h" 287ec681f3Smrg 297ec681f3Smrg#ifdef __cplusplus 307ec681f3Smrgextern "C" { 317ec681f3Smrg#endif 327ec681f3Smrg 337ec681f3Smrg#define CLC_MAX_CONSTS 32 347ec681f3Smrg#define CLC_MAX_BINDINGS_PER_ARG 3 357ec681f3Smrg#define CLC_MAX_SAMPLERS 16 367ec681f3Smrg 377ec681f3Smrgstruct clc_printf_info { 387ec681f3Smrg unsigned num_args; 397ec681f3Smrg unsigned *arg_sizes; 407ec681f3Smrg char *str; 417ec681f3Smrg}; 427ec681f3Smrg 437ec681f3Smrgstruct clc_dxil_metadata { 447ec681f3Smrg struct { 457ec681f3Smrg unsigned offset; 467ec681f3Smrg unsigned size; 477ec681f3Smrg union { 487ec681f3Smrg struct { 497ec681f3Smrg unsigned buf_ids[CLC_MAX_BINDINGS_PER_ARG]; 507ec681f3Smrg unsigned num_buf_ids; 517ec681f3Smrg } image; 527ec681f3Smrg struct { 537ec681f3Smrg unsigned sampler_id; 547ec681f3Smrg } sampler; 557ec681f3Smrg struct { 567ec681f3Smrg unsigned buf_id; 577ec681f3Smrg } globconstptr; 587ec681f3Smrg struct { 597ec681f3Smrg unsigned sharedmem_offset; 607ec681f3Smrg } localptr; 617ec681f3Smrg }; 627ec681f3Smrg } *args; 637ec681f3Smrg unsigned kernel_inputs_cbv_id; 647ec681f3Smrg unsigned kernel_inputs_buf_size; 657ec681f3Smrg unsigned work_properties_cbv_id; 667ec681f3Smrg size_t num_uavs; 677ec681f3Smrg size_t num_srvs; 687ec681f3Smrg size_t num_samplers; 697ec681f3Smrg 707ec681f3Smrg struct { 717ec681f3Smrg void *data; 727ec681f3Smrg size_t size; 737ec681f3Smrg unsigned uav_id; 747ec681f3Smrg } consts[CLC_MAX_CONSTS]; 757ec681f3Smrg size_t num_consts; 767ec681f3Smrg 777ec681f3Smrg struct { 787ec681f3Smrg unsigned sampler_id; 797ec681f3Smrg unsigned addressing_mode; 807ec681f3Smrg unsigned normalized_coords; 817ec681f3Smrg unsigned filter_mode; 827ec681f3Smrg } const_samplers[CLC_MAX_SAMPLERS]; 837ec681f3Smrg size_t num_const_samplers; 847ec681f3Smrg size_t local_mem_size; 857ec681f3Smrg size_t priv_mem_size; 867ec681f3Smrg 877ec681f3Smrg uint16_t local_size[3]; 887ec681f3Smrg uint16_t local_size_hint[3]; 897ec681f3Smrg 907ec681f3Smrg struct { 917ec681f3Smrg unsigned info_count; 927ec681f3Smrg struct clc_printf_info *infos; 937ec681f3Smrg int uav_id; 947ec681f3Smrg } printf; 957ec681f3Smrg}; 967ec681f3Smrg 977ec681f3Smrgstruct clc_dxil_object { 987ec681f3Smrg const struct clc_kernel_info *kernel; 997ec681f3Smrg struct clc_dxil_metadata metadata; 1007ec681f3Smrg struct { 1017ec681f3Smrg void *data; 1027ec681f3Smrg size_t size; 1037ec681f3Smrg } binary; 1047ec681f3Smrg}; 1057ec681f3Smrg 1067ec681f3Smrgstruct clc_runtime_arg_info { 1077ec681f3Smrg union { 1087ec681f3Smrg struct { 1097ec681f3Smrg unsigned size; 1107ec681f3Smrg } localptr; 1117ec681f3Smrg struct { 1127ec681f3Smrg unsigned normalized_coords; 1137ec681f3Smrg unsigned addressing_mode; /* See SPIR-V spec for value meanings */ 1147ec681f3Smrg unsigned linear_filtering; 1157ec681f3Smrg } sampler; 1167ec681f3Smrg }; 1177ec681f3Smrg}; 1187ec681f3Smrg 1197ec681f3Smrgstruct clc_runtime_kernel_conf { 1207ec681f3Smrg uint16_t local_size[3]; 1217ec681f3Smrg struct clc_runtime_arg_info *args; 1227ec681f3Smrg unsigned lower_bit_size; 1237ec681f3Smrg unsigned support_global_work_id_offsets; 1247ec681f3Smrg unsigned support_workgroup_id_offsets; 1257ec681f3Smrg}; 1267ec681f3Smrg 1277ec681f3Smrgstruct clc_libclc_dxil_options { 1287ec681f3Smrg unsigned optimize; 1297ec681f3Smrg}; 1307ec681f3Smrg 1317ec681f3Smrgstruct clc_libclc * 1327ec681f3Smrgclc_libclc_new_dxil(const struct clc_logger *logger, 1337ec681f3Smrg const struct clc_libclc_dxil_options *dxil_options); 1347ec681f3Smrg 1357ec681f3Smrgbool 1367ec681f3Smrgclc_spirv_to_dxil(struct clc_libclc *lib, 1377ec681f3Smrg const struct clc_binary *linked_spirv, 1387ec681f3Smrg const struct clc_parsed_spirv *parsed_data, 1397ec681f3Smrg const char *entrypoint, 1407ec681f3Smrg const struct clc_runtime_kernel_conf *conf, 1417ec681f3Smrg const struct clc_spirv_specialization_consts *consts, 1427ec681f3Smrg const struct clc_logger *logger, 1437ec681f3Smrg struct clc_dxil_object *out_dxil); 1447ec681f3Smrg 1457ec681f3Smrgvoid clc_free_dxil_object(struct clc_dxil_object *dxil); 1467ec681f3Smrg 1477ec681f3Smrg/* This struct describes the layout of data expected in the CB bound at global_work_offset_cbv_id */ 1487ec681f3Smrgstruct clc_work_properties_data { 1497ec681f3Smrg /* Returned from get_global_offset(), and added into get_global_id() */ 1507ec681f3Smrg unsigned global_offset_x; 1517ec681f3Smrg unsigned global_offset_y; 1527ec681f3Smrg unsigned global_offset_z; 1537ec681f3Smrg /* Returned from get_work_dim() */ 1547ec681f3Smrg unsigned work_dim; 1557ec681f3Smrg /* The number of work groups being launched (i.e. the parameters to Dispatch). 1567ec681f3Smrg * If the requested global size doesn't fit in a single Dispatch, these values should 1577ec681f3Smrg * indicate the total number of groups that *should* have been launched. */ 1587ec681f3Smrg unsigned group_count_total_x; 1597ec681f3Smrg unsigned group_count_total_y; 1607ec681f3Smrg unsigned group_count_total_z; 1617ec681f3Smrg unsigned padding; 1627ec681f3Smrg /* If the requested global size doesn't fit in a single Dispatch, subsequent dispatches 1637ec681f3Smrg * should fill out these offsets to indicate how many groups have already been launched */ 1647ec681f3Smrg unsigned group_id_offset_x; 1657ec681f3Smrg unsigned group_id_offset_y; 1667ec681f3Smrg unsigned group_id_offset_z; 1677ec681f3Smrg}; 1687ec681f3Smrg 1697ec681f3Smrguint64_t clc_compiler_get_version(); 1707ec681f3Smrg 1717ec681f3Smrg#ifdef __cplusplus 1727ec681f3Smrg} 1737ec681f3Smrg#endif 1747ec681f3Smrg 1757ec681f3Smrg#endif 176