Path: blob/21.2-virgl/src/microsoft/compiler/dxil_module.h
4564 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/*24* See the DirectX Shader Compiler for documentation for DXIL details:25* https://github.com/Microsoft/DirectXShaderCompiler/blob/master/docs/DXIL.rst26*/2728#ifndef DXIL_MODULE_H29#define DXIL_MODULE_H3031#ifdef __cplusplus32extern "C" {33#endif3435#include "dxil_buffer.h"36#include "dxil_signature.h"3738#include "util/list.h"394041#define DXIL_SHADER_MAX_IO_ROWS 804243enum dxil_shader_kind {44DXIL_PIXEL_SHADER = 0,45DXIL_VERTEX_SHADER = 1,46DXIL_GEOMETRY_SHADER = 2,47DXIL_HULL_SHADER = 3,48DXIL_DOMAIN_SHADER = 4,49DXIL_COMPUTE_SHADER = 5,50};5152extern int debug_dxil;5354enum dxil_debug_flags {55DXIL_DEBUG_VERBOSE = 1 << 0,56DXIL_DEBUG_DUMP_BLOB = 1 << 1,57DXIL_DEBUG_TRACE = 1 << 2,58DXIL_DEBUG_DUMP_MODULE = 1 << 3,59};6061enum dxil_bin_opcode {62DXIL_BINOP_ADD = 0,63DXIL_BINOP_SUB = 1,64DXIL_BINOP_MUL = 2,65DXIL_BINOP_UDIV = 3,66DXIL_BINOP_SDIV = 4,67DXIL_BINOP_UREM = 5,68DXIL_BINOP_SREM = 6,69DXIL_BINOP_SHL = 7,70DXIL_BINOP_LSHR = 8,71DXIL_BINOP_ASHR = 9,72DXIL_BINOP_AND = 10,73DXIL_BINOP_OR = 11,74DXIL_BINOP_XOR = 12,75DXIL_BINOP_INSTR_COUNT76};7778enum dxil_cast_opcode {79DXIL_CAST_TRUNC = 0,80DXIL_CAST_ZEXT = 1,81DXIL_CAST_SEXT = 2,82DXIL_CAST_FPTOUI = 3,83DXIL_CAST_FPTOSI = 4,84DXIL_CAST_UITOFP = 5,85DXIL_CAST_SITOFP = 6,86DXIL_CAST_FPTRUNC = 7,87DXIL_CAST_FPEXT = 8,88DXIL_CAST_PTRTOINT = 9,89DXIL_CAST_INTTOPTR = 10,90DXIL_CAST_BITCAST = 11,91DXIL_CAST_ADDRSPACECAST = 12,92DXIL_CAST_INSTR_COUNT93};9495enum dxil_cmp_pred {96DXIL_FCMP_FALSE = 0,97DXIL_FCMP_OEQ = 1,98DXIL_FCMP_OGT = 2,99DXIL_FCMP_OGE = 3,100DXIL_FCMP_OLT = 4,101DXIL_FCMP_OLE = 5,102DXIL_FCMP_ONE = 6,103DXIL_FCMP_ORD = 7,104DXIL_FCMP_UNO = 8,105DXIL_FCMP_UEQ = 9,106DXIL_FCMP_UGT = 10,107DXIL_FCMP_UGE = 11,108DXIL_FCMP_ULT = 12,109DXIL_FCMP_ULE = 13,110DXIL_FCMP_UNE = 14,111DXIL_FCMP_TRUE = 15,112DXIL_ICMP_EQ = 32,113DXIL_ICMP_NE = 33,114DXIL_ICMP_UGT = 34,115DXIL_ICMP_UGE = 35,116DXIL_ICMP_ULT = 36,117DXIL_ICMP_ULE = 37,118DXIL_ICMP_SGT = 38,119DXIL_ICMP_SGE = 39,120DXIL_ICMP_SLT = 40,121DXIL_ICMP_SLE = 41,122DXIL_CMP_INSTR_COUNT123};124125enum dxil_opt_flags {126DXIL_UNSAFE_ALGEBRA = (1 << 0),127DXIL_NO_NANS = (1 << 1),128DXIL_NO_INFS = (1 << 2),129DXIL_NO_SIGNED_ZEROS = (1 << 3),130DXIL_ALLOW_RECIPROCAL = (1 << 4)131};132133struct dxil_features {134unsigned doubles : 1,135cs_4x_raw_sb : 1,136uavs_at_every_stage : 1,137use_64uavs : 1,138min_precision : 1,139dx11_1_double_extensions : 1,140dx11_1_shader_extensions : 1,141dx9_comparison_filtering : 1,142tiled_resources : 1,143stencil_ref : 1,144inner_coverage : 1,145typed_uav_load_additional_formats : 1,146rovs : 1,147array_layer_from_vs_or_ds : 1,148wave_ops : 1,149int64_ops : 1,150view_id : 1,151barycentrics : 1,152native_low_precision : 1,153shading_rate : 1,154raytracing_tier_1_1 : 1,155sampler_feedback : 1;156};157158struct dxil_shader_info {159unsigned has_out_position:1;160unsigned has_out_depth:1;161};162163struct dxil_module {164void *ralloc_ctx;165enum dxil_shader_kind shader_kind;166unsigned major_version, minor_version;167struct dxil_features feats;168unsigned raw_and_structured_buffers : 1;169struct dxil_shader_info info;170171struct dxil_buffer buf;172173unsigned num_sig_inputs;174unsigned num_sig_outputs;175unsigned num_psv_inputs;176unsigned num_psv_outputs;177178struct dxil_signature_record inputs[DXIL_SHADER_MAX_IO_ROWS];179struct dxil_signature_record outputs[DXIL_SHADER_MAX_IO_ROWS];180181struct dxil_psv_signature_element psv_inputs[DXIL_SHADER_MAX_IO_ROWS];182struct dxil_psv_signature_element psv_outputs[DXIL_SHADER_MAX_IO_ROWS];183184struct _mesa_string_buffer *sem_string_table;185struct dxil_psv_sem_index_table sem_index_table;186187struct {188unsigned abbrev_width;189intptr_t offset;190} blocks[16];191size_t num_blocks;192193struct list_head type_list;194struct list_head gvar_list;195struct list_head func_list;196struct list_head attr_set_list;197struct list_head instr_list;198struct list_head const_list;199struct list_head mdnode_list;200struct list_head md_named_node_list;201const struct dxil_type *void_type;202const struct dxil_type *int1_type, *int8_type, *int16_type,203*int32_type, *int64_type;204const struct dxil_type *float16_type, *float32_type, *float64_type;205206struct rb_tree *functions;207208int *basic_block_ids; /* maps from "user" ids to LLVM ids */209size_t num_basic_block_ids;210unsigned curr_block;211};212213struct dxil_instr;214struct dxil_value;215216void217dxil_module_init(struct dxil_module *m, void *ralloc_ctx);218219void220dxil_module_release(struct dxil_module *m);221222const struct dxil_value *223dxil_add_global_var(struct dxil_module *m, const char *name,224const struct dxil_type *type,225enum dxil_address_space as, int align,226const struct dxil_value *value);227228const struct dxil_value *229dxil_add_global_ptr_var(struct dxil_module *m, const char *name,230const struct dxil_type *type,231enum dxil_address_space as, int align,232const struct dxil_value *value);233234const struct dxil_func *235dxil_add_function_def(struct dxil_module *m, const char *name,236const struct dxil_type *type);237238const struct dxil_func *239dxil_add_function_decl(struct dxil_module *m, const char *name,240const struct dxil_type *type,241enum dxil_attr_kind attr);242243const struct dxil_type *244dxil_module_get_void_type(struct dxil_module *m);245246const struct dxil_type *247dxil_module_get_int_type(struct dxil_module *m, unsigned bit_size);248249const struct dxil_type *250dxil_module_get_float_type(struct dxil_module *m, unsigned bit_size);251252const struct dxil_type *253dxil_module_get_pointer_type(struct dxil_module *m,254const struct dxil_type *target);255256const struct dxil_type *257dxil_get_overload_type(struct dxil_module *mod, enum overload_type overload);258259const struct dxil_type *260dxil_module_get_handle_type(struct dxil_module *m);261262const struct dxil_type *263dxil_module_get_cbuf_ret_type(struct dxil_module *mod, enum overload_type overload);264265const struct dxil_type *266dxil_module_get_split_double_ret_type(struct dxil_module *mod);267268const struct dxil_type *269dxil_module_get_res_type(struct dxil_module *m, enum dxil_resource_kind kind,270enum dxil_component_type comp_type, bool readwrite);271272const struct dxil_type *273dxil_module_get_resret_type(struct dxil_module *m, enum overload_type overload);274275const struct dxil_type *276dxil_module_get_dimret_type(struct dxil_module *m);277278const struct dxil_type *279dxil_module_get_struct_type(struct dxil_module *m,280const char *name,281const struct dxil_type **elem_types,282size_t num_elem_types);283284const struct dxil_type *285dxil_module_get_array_type(struct dxil_module *m,286const struct dxil_type *elem_type,287size_t num_elems);288289const struct dxil_type *290dxil_module_get_vector_type(struct dxil_module *m,291const struct dxil_type *elem_type,292size_t num_elems);293294const struct dxil_type *295dxil_module_add_function_type(struct dxil_module *m,296const struct dxil_type *ret_type,297const struct dxil_type **arg_types,298size_t num_arg_types);299300nir_alu_type301dxil_type_to_nir_type(const struct dxil_type *type);302303bool304dxil_value_type_equal_to(const struct dxil_value *value,305const struct dxil_type *lhs);306307bool308dxil_value_type_bitsize_equal_to(const struct dxil_value *value, unsigned bitsize);309310const struct dxil_type *311dxil_value_get_type(const struct dxil_value *value);312313const struct dxil_value *314dxil_module_get_int1_const(struct dxil_module *m, bool value);315316const struct dxil_value *317dxil_module_get_int8_const(struct dxil_module *m, int8_t value);318319const struct dxil_value *320dxil_module_get_int16_const(struct dxil_module *m, int16_t value);321322const struct dxil_value *323dxil_module_get_int32_const(struct dxil_module *m, int32_t value);324325const struct dxil_value *326dxil_module_get_int64_const(struct dxil_module *m, int64_t value);327328const struct dxil_value *329dxil_module_get_int_const(struct dxil_module *m, intmax_t value,330unsigned bit_size);331332const struct dxil_value *333dxil_module_get_float16_const(struct dxil_module *m, uint16_t);334335const struct dxil_value *336dxil_module_get_float_const(struct dxil_module *m, float value);337338const struct dxil_value *339dxil_module_get_double_const(struct dxil_module *m, double value);340341const struct dxil_value *342dxil_module_get_array_const(struct dxil_module *m, const struct dxil_type *type,343const struct dxil_value **values);344345const struct dxil_value *346dxil_module_get_undef(struct dxil_module *m, const struct dxil_type *type);347348const struct dxil_mdnode *349dxil_get_metadata_string(struct dxil_module *m, const char *str);350351const struct dxil_mdnode *352dxil_get_metadata_value(struct dxil_module *m, const struct dxil_type *type,353const struct dxil_value *value);354355const struct dxil_mdnode *356dxil_get_metadata_func(struct dxil_module *m, const struct dxil_func *func);357358const struct dxil_mdnode *359dxil_get_metadata_int1(struct dxil_module *m, bool value);360361const struct dxil_mdnode *362dxil_get_metadata_int8(struct dxil_module *m, int8_t value);363364const struct dxil_mdnode *365dxil_get_metadata_int32(struct dxil_module *m, int32_t value);366367const struct dxil_mdnode *368dxil_get_metadata_int64(struct dxil_module *m, int64_t value);369370const struct dxil_mdnode *371dxil_get_metadata_node(struct dxil_module *m,372const struct dxil_mdnode *subnodes[],373size_t num_subnodes);374375bool376dxil_add_metadata_named_node(struct dxil_module *m, const char *name,377const struct dxil_mdnode *subnodes[],378size_t num_subnodes);379380const struct dxil_value *381dxil_emit_binop(struct dxil_module *m, enum dxil_bin_opcode opcode,382const struct dxil_value *op0, const struct dxil_value *op1,383enum dxil_opt_flags flags);384385const struct dxil_value *386dxil_emit_cmp(struct dxil_module *m, enum dxil_cmp_pred pred,387const struct dxil_value *op0, const struct dxil_value *op1);388389const struct dxil_value *390dxil_emit_select(struct dxil_module *m,391const struct dxil_value *op0,392const struct dxil_value *op1,393const struct dxil_value *op2);394395const struct dxil_value *396dxil_emit_extractval(struct dxil_module *m, const struct dxil_value *src,397const unsigned int index);398399const struct dxil_value *400dxil_emit_cast(struct dxil_module *m, enum dxil_cast_opcode opcode,401const struct dxil_type *type,402const struct dxil_value *value);403404bool405dxil_emit_branch(struct dxil_module *m, const struct dxil_value *cond,406unsigned true_block, unsigned false_block);407408const struct dxil_value *409dxil_instr_get_return_value(struct dxil_instr *instr);410411struct dxil_instr *412dxil_emit_phi(struct dxil_module *m, const struct dxil_type *type);413414void415dxil_phi_set_incoming(struct dxil_instr *instr,416const struct dxil_value *incoming_values[],417const unsigned incoming_blocks[],418size_t num_incoming);419420const struct dxil_value *421dxil_emit_call(struct dxil_module *m,422const struct dxil_func *func,423const struct dxil_value **args, size_t num_args);424425bool426dxil_emit_call_void(struct dxil_module *m,427const struct dxil_func *func,428const struct dxil_value **args, size_t num_args);429430bool431dxil_emit_ret_void(struct dxil_module *m);432433const struct dxil_value *434dxil_emit_alloca(struct dxil_module *m, const struct dxil_type *alloc_type,435const struct dxil_type *size_type,436const struct dxil_value *size,437unsigned int align);438439const struct dxil_value *440dxil_emit_gep_inbounds(struct dxil_module *m,441const struct dxil_value **operands,442size_t num_operands);443444const struct dxil_value *445dxil_emit_load(struct dxil_module *m, const struct dxil_value *ptr,446unsigned align,447bool is_volatile);448449bool450dxil_emit_store(struct dxil_module *m, const struct dxil_value *value,451const struct dxil_value *ptr, unsigned align,452bool is_volatile);453454const struct dxil_value *455dxil_emit_cmpxchg(struct dxil_module *m, const struct dxil_value *cmpval,456const struct dxil_value *newval,457const struct dxil_value *ptr, bool is_volatile,458enum dxil_atomic_ordering ordering,459enum dxil_sync_scope syncscope);460461const struct dxil_value *462dxil_emit_atomicrmw(struct dxil_module *m, const struct dxil_value *value,463const struct dxil_value *ptr, enum dxil_rmw_op op,464bool is_volatile, enum dxil_atomic_ordering ordering,465enum dxil_sync_scope syncscope);466467bool468dxil_emit_module(struct dxil_module *m);469470#ifdef __cplusplus471}472#endif473474#endif475476477