Path: blob/21.2-virgl/src/microsoft/clc/clc_compiler.h
4560 views
/*1* Copyright © Microsoft Corporation2*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*/2223#ifndef CLC_COMPILER_H24#define CLC_COMPILER_H2526#ifdef __cplusplus27extern "C" {28#endif2930#include <stddef.h>31#include <stdint.h>3233struct clc_named_value {34const char *name;35const char *value;36};3738struct clc_compile_args {39const struct clc_named_value *headers;40unsigned num_headers;41struct clc_named_value source;42const char * const *args;43unsigned num_args;44};4546struct clc_linker_args {47const struct clc_object * const *in_objs;48unsigned num_in_objs;49unsigned create_library;50};5152typedef void (*clc_msg_callback)(void *priv, const char *msg);5354struct clc_logger {55void *priv;56clc_msg_callback error;57clc_msg_callback warning;58};5960struct spirv_binary {61uint32_t *data;62size_t size;63};6465enum clc_kernel_arg_type_qualifier {66CLC_KERNEL_ARG_TYPE_CONST = 1 << 0,67CLC_KERNEL_ARG_TYPE_RESTRICT = 1 << 1,68CLC_KERNEL_ARG_TYPE_VOLATILE = 1 << 2,69};7071enum clc_kernel_arg_access_qualifier {72CLC_KERNEL_ARG_ACCESS_READ = 1 << 0,73CLC_KERNEL_ARG_ACCESS_WRITE = 1 << 1,74};7576enum clc_kernel_arg_address_qualifier {77CLC_KERNEL_ARG_ADDRESS_PRIVATE,78CLC_KERNEL_ARG_ADDRESS_CONSTANT,79CLC_KERNEL_ARG_ADDRESS_LOCAL,80CLC_KERNEL_ARG_ADDRESS_GLOBAL,81};8283struct clc_kernel_arg {84const char *name;85const char *type_name;86unsigned type_qualifier;87unsigned access_qualifier;88enum clc_kernel_arg_address_qualifier address_qualifier;89};9091enum clc_vec_hint_type {92CLC_VEC_HINT_TYPE_CHAR = 0,93CLC_VEC_HINT_TYPE_SHORT = 1,94CLC_VEC_HINT_TYPE_INT = 2,95CLC_VEC_HINT_TYPE_LONG = 3,96CLC_VEC_HINT_TYPE_HALF = 4,97CLC_VEC_HINT_TYPE_FLOAT = 5,98CLC_VEC_HINT_TYPE_DOUBLE = 699};100101struct clc_kernel_info {102const char *name;103size_t num_args;104const struct clc_kernel_arg *args;105106unsigned vec_hint_size;107enum clc_vec_hint_type vec_hint_type;108};109110struct clc_object {111struct spirv_binary spvbin;112const struct clc_kernel_info *kernels;113unsigned num_kernels;114};115116#define CLC_MAX_CONSTS 32117#define CLC_MAX_BINDINGS_PER_ARG 3118#define CLC_MAX_SAMPLERS 16119120struct clc_printf_info {121unsigned num_args;122unsigned *arg_sizes;123char *str;124};125126struct clc_dxil_metadata {127struct {128unsigned offset;129unsigned size;130union {131struct {132unsigned buf_ids[CLC_MAX_BINDINGS_PER_ARG];133unsigned num_buf_ids;134} image;135struct {136unsigned sampler_id;137} sampler;138struct {139unsigned buf_id;140} globconstptr;141struct {142unsigned sharedmem_offset;143} localptr;144};145} *args;146unsigned kernel_inputs_cbv_id;147unsigned kernel_inputs_buf_size;148unsigned work_properties_cbv_id;149size_t num_uavs;150size_t num_srvs;151size_t num_samplers;152153struct {154void *data;155size_t size;156unsigned uav_id;157} consts[CLC_MAX_CONSTS];158size_t num_consts;159160struct {161unsigned sampler_id;162unsigned addressing_mode;163unsigned normalized_coords;164unsigned filter_mode;165} const_samplers[CLC_MAX_SAMPLERS];166size_t num_const_samplers;167size_t local_mem_size;168size_t priv_mem_size;169170uint16_t local_size[3];171uint16_t local_size_hint[3];172173struct {174unsigned info_count;175struct clc_printf_info *infos;176int uav_id;177} printf;178};179180struct clc_dxil_object {181const struct clc_kernel_info *kernel;182struct clc_dxil_metadata metadata;183struct {184void *data;185size_t size;186} binary;187};188189struct clc_context {190const void *libclc_nir;191};192193struct clc_context_options {194unsigned optimize;195};196197struct clc_context *clc_context_new(const struct clc_logger *logger, const struct clc_context_options *options);198199void clc_free_context(struct clc_context *ctx);200201void clc_context_serialize(struct clc_context *ctx, void **serialized, size_t *size);202void clc_context_free_serialized(void *serialized);203struct clc_context *clc_context_deserialize(void *serialized, size_t size);204205struct clc_object *206clc_compile(struct clc_context *ctx,207const struct clc_compile_args *args,208const struct clc_logger *logger);209210struct clc_object *211clc_link(struct clc_context *ctx,212const struct clc_linker_args *args,213const struct clc_logger *logger);214215void clc_free_object(struct clc_object *obj);216217struct clc_runtime_arg_info {218union {219struct {220unsigned size;221} localptr;222struct {223unsigned normalized_coords;224unsigned addressing_mode; /* See SPIR-V spec for value meanings */225unsigned linear_filtering;226} sampler;227};228};229230struct clc_runtime_kernel_conf {231uint16_t local_size[3];232struct clc_runtime_arg_info *args;233unsigned lower_bit_size;234unsigned support_global_work_id_offsets;235unsigned support_workgroup_id_offsets;236};237238struct clc_dxil_object *239clc_to_dxil(struct clc_context *ctx,240const struct clc_object *obj,241const char *entrypoint,242const struct clc_runtime_kernel_conf *conf,243const struct clc_logger *logger);244245void clc_free_dxil_object(struct clc_dxil_object *dxil);246247/* This struct describes the layout of data expected in the CB bound at global_work_offset_cbv_id */248struct clc_work_properties_data {249/* Returned from get_global_offset(), and added into get_global_id() */250unsigned global_offset_x;251unsigned global_offset_y;252unsigned global_offset_z;253/* Returned from get_work_dim() */254unsigned work_dim;255/* The number of work groups being launched (i.e. the parameters to Dispatch).256* If the requested global size doesn't fit in a single Dispatch, these values should257* indicate the total number of groups that *should* have been launched. */258unsigned group_count_total_x;259unsigned group_count_total_y;260unsigned group_count_total_z;261unsigned padding;262/* If the requested global size doesn't fit in a single Dispatch, subsequent dispatches263* should fill out these offsets to indicate how many groups have already been launched */264unsigned group_id_offset_x;265unsigned group_id_offset_y;266unsigned group_id_offset_z;267};268269uint64_t clc_compiler_get_version();270271#ifdef __cplusplus272}273#endif274275#endif276277278