1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright 2017 Red Hat Inc. 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 12bf215546Sopenharmony_ci * all copies or substantial portions of the Software. 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18bf215546Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19bf215546Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20bf215546Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 21bf215546Sopenharmony_ci * 22bf215546Sopenharmony_ci * Authors: Karol Herbst <kherbst@redhat.com> 23bf215546Sopenharmony_ci */ 24bf215546Sopenharmony_ci 25bf215546Sopenharmony_ci#include "compiler/nir/nir.h" 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci#include "util/u_debug.h" 28bf215546Sopenharmony_ci#include "util/u_prim.h" 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci#include "nv50_ir.h" 31bf215546Sopenharmony_ci#include "nv50_ir_from_common.h" 32bf215546Sopenharmony_ci#include "nv50_ir_lowering_helper.h" 33bf215546Sopenharmony_ci#include "nv50_ir_target.h" 34bf215546Sopenharmony_ci#include "nv50_ir_util.h" 35bf215546Sopenharmony_ci#include "tgsi/tgsi_from_mesa.h" 36bf215546Sopenharmony_ci 37bf215546Sopenharmony_ci#include <unordered_map> 38bf215546Sopenharmony_ci#include <cstring> 39bf215546Sopenharmony_ci#include <list> 40bf215546Sopenharmony_ci#include <vector> 41bf215546Sopenharmony_ci 42bf215546Sopenharmony_cinamespace { 43bf215546Sopenharmony_ci 44bf215546Sopenharmony_ciusing namespace nv50_ir; 45bf215546Sopenharmony_ci 46bf215546Sopenharmony_ciint 47bf215546Sopenharmony_citype_size(const struct glsl_type *type, bool bindless) 48bf215546Sopenharmony_ci{ 49bf215546Sopenharmony_ci return glsl_count_attribute_slots(type, false); 50bf215546Sopenharmony_ci} 51bf215546Sopenharmony_ci 52bf215546Sopenharmony_cistatic void 53bf215546Sopenharmony_cifunction_temp_type_info(const struct glsl_type *type, unsigned *size, unsigned *align) 54bf215546Sopenharmony_ci{ 55bf215546Sopenharmony_ci assert(glsl_type_is_vector_or_scalar(type)); 56bf215546Sopenharmony_ci 57bf215546Sopenharmony_ci if (glsl_type_is_scalar(type)) { 58bf215546Sopenharmony_ci glsl_get_natural_size_align_bytes(type, size, align); 59bf215546Sopenharmony_ci } else { 60bf215546Sopenharmony_ci unsigned comp_size = glsl_type_is_boolean(type) ? 4 : glsl_get_bit_size(type) / 8; 61bf215546Sopenharmony_ci unsigned length = glsl_get_vector_elements(type); 62bf215546Sopenharmony_ci 63bf215546Sopenharmony_ci *size = comp_size * length; 64bf215546Sopenharmony_ci *align = 0x10; 65bf215546Sopenharmony_ci } 66bf215546Sopenharmony_ci} 67bf215546Sopenharmony_ci 68bf215546Sopenharmony_ciclass Converter : public ConverterCommon 69bf215546Sopenharmony_ci{ 70bf215546Sopenharmony_cipublic: 71bf215546Sopenharmony_ci Converter(Program *, nir_shader *, nv50_ir_prog_info *, nv50_ir_prog_info_out *); 72bf215546Sopenharmony_ci 73bf215546Sopenharmony_ci bool run(); 74bf215546Sopenharmony_ciprivate: 75bf215546Sopenharmony_ci typedef std::vector<LValue*> LValues; 76bf215546Sopenharmony_ci typedef std::unordered_map<unsigned, LValues> NirDefMap; 77bf215546Sopenharmony_ci typedef std::unordered_map<unsigned, nir_load_const_instr*> ImmediateMap; 78bf215546Sopenharmony_ci typedef std::unordered_map<unsigned, BasicBlock*> NirBlockMap; 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_ci CacheMode convert(enum gl_access_qualifier); 81bf215546Sopenharmony_ci TexTarget convert(glsl_sampler_dim, bool isArray, bool isShadow); 82bf215546Sopenharmony_ci LValues& convert(nir_alu_dest *); 83bf215546Sopenharmony_ci BasicBlock* convert(nir_block *); 84bf215546Sopenharmony_ci LValues& convert(nir_dest *); 85bf215546Sopenharmony_ci SVSemantic convert(nir_intrinsic_op); 86bf215546Sopenharmony_ci Value* convert(nir_load_const_instr*, uint8_t); 87bf215546Sopenharmony_ci LValues& convert(nir_register *); 88bf215546Sopenharmony_ci LValues& convert(nir_ssa_def *); 89bf215546Sopenharmony_ci 90bf215546Sopenharmony_ci Value* getSrc(nir_alu_src *, uint8_t component = 0); 91bf215546Sopenharmony_ci Value* getSrc(nir_register *, uint8_t); 92bf215546Sopenharmony_ci Value* getSrc(nir_src *, uint8_t, bool indirect = false); 93bf215546Sopenharmony_ci Value* getSrc(nir_ssa_def *, uint8_t); 94bf215546Sopenharmony_ci 95bf215546Sopenharmony_ci // returned value is the constant part of the given source (either the 96bf215546Sopenharmony_ci // nir_src or the selected source component of an intrinsic). Even though 97bf215546Sopenharmony_ci // this is mostly an optimization to be able to skip indirects in a few 98bf215546Sopenharmony_ci // cases, sometimes we require immediate values or set some fileds on 99bf215546Sopenharmony_ci // instructions (e.g. tex) in order for codegen to consume those. 100bf215546Sopenharmony_ci // If the found value has not a constant part, the Value gets returned 101bf215546Sopenharmony_ci // through the Value parameter. 102bf215546Sopenharmony_ci uint32_t getIndirect(nir_src *, uint8_t, Value *&); 103bf215546Sopenharmony_ci // isScalar indicates that the addressing is scalar, vec4 addressing is 104bf215546Sopenharmony_ci // assumed otherwise 105bf215546Sopenharmony_ci uint32_t getIndirect(nir_intrinsic_instr *, uint8_t s, uint8_t c, Value *&, 106bf215546Sopenharmony_ci bool isScalar = false); 107bf215546Sopenharmony_ci 108bf215546Sopenharmony_ci uint32_t getSlotAddress(nir_intrinsic_instr *, uint8_t idx, uint8_t slot); 109bf215546Sopenharmony_ci 110bf215546Sopenharmony_ci void setInterpolate(nv50_ir_varying *, 111bf215546Sopenharmony_ci uint8_t, 112bf215546Sopenharmony_ci bool centroid, 113bf215546Sopenharmony_ci unsigned semantics); 114bf215546Sopenharmony_ci 115bf215546Sopenharmony_ci Instruction *loadFrom(DataFile, uint8_t, DataType, Value *def, uint32_t base, 116bf215546Sopenharmony_ci uint8_t c, Value *indirect0 = NULL, 117bf215546Sopenharmony_ci Value *indirect1 = NULL, bool patch = false); 118bf215546Sopenharmony_ci void storeTo(nir_intrinsic_instr *, DataFile, operation, DataType, 119bf215546Sopenharmony_ci Value *src, uint8_t idx, uint8_t c, Value *indirect0 = NULL, 120bf215546Sopenharmony_ci Value *indirect1 = NULL); 121bf215546Sopenharmony_ci 122bf215546Sopenharmony_ci bool isFloatType(nir_alu_type); 123bf215546Sopenharmony_ci bool isSignedType(nir_alu_type); 124bf215546Sopenharmony_ci bool isResultFloat(nir_op); 125bf215546Sopenharmony_ci bool isResultSigned(nir_op); 126bf215546Sopenharmony_ci 127bf215546Sopenharmony_ci DataType getDType(nir_alu_instr *); 128bf215546Sopenharmony_ci DataType getDType(nir_intrinsic_instr *); 129bf215546Sopenharmony_ci DataType getDType(nir_op, uint8_t); 130bf215546Sopenharmony_ci 131bf215546Sopenharmony_ci DataFile getFile(nir_intrinsic_op); 132bf215546Sopenharmony_ci 133bf215546Sopenharmony_ci std::vector<DataType> getSTypes(nir_alu_instr *); 134bf215546Sopenharmony_ci DataType getSType(nir_src &, bool isFloat, bool isSigned); 135bf215546Sopenharmony_ci 136bf215546Sopenharmony_ci operation getOperation(nir_intrinsic_op); 137bf215546Sopenharmony_ci operation getOperation(nir_op); 138bf215546Sopenharmony_ci operation getOperation(nir_texop); 139bf215546Sopenharmony_ci operation preOperationNeeded(nir_op); 140bf215546Sopenharmony_ci 141bf215546Sopenharmony_ci int getSubOp(nir_intrinsic_op); 142bf215546Sopenharmony_ci int getSubOp(nir_op); 143bf215546Sopenharmony_ci 144bf215546Sopenharmony_ci CondCode getCondCode(nir_op); 145bf215546Sopenharmony_ci 146bf215546Sopenharmony_ci bool assignSlots(); 147bf215546Sopenharmony_ci bool parseNIR(); 148bf215546Sopenharmony_ci 149bf215546Sopenharmony_ci bool visit(nir_alu_instr *); 150bf215546Sopenharmony_ci bool visit(nir_block *); 151bf215546Sopenharmony_ci bool visit(nir_cf_node *); 152bf215546Sopenharmony_ci bool visit(nir_function *); 153bf215546Sopenharmony_ci bool visit(nir_if *); 154bf215546Sopenharmony_ci bool visit(nir_instr *); 155bf215546Sopenharmony_ci bool visit(nir_intrinsic_instr *); 156bf215546Sopenharmony_ci bool visit(nir_jump_instr *); 157bf215546Sopenharmony_ci bool visit(nir_load_const_instr*); 158bf215546Sopenharmony_ci bool visit(nir_loop *); 159bf215546Sopenharmony_ci bool visit(nir_ssa_undef_instr *); 160bf215546Sopenharmony_ci bool visit(nir_tex_instr *); 161bf215546Sopenharmony_ci 162bf215546Sopenharmony_ci // tex stuff 163bf215546Sopenharmony_ci unsigned int getNIRArgCount(TexInstruction::Target&); 164bf215546Sopenharmony_ci 165bf215546Sopenharmony_ci nir_shader *nir; 166bf215546Sopenharmony_ci 167bf215546Sopenharmony_ci NirDefMap ssaDefs; 168bf215546Sopenharmony_ci NirDefMap regDefs; 169bf215546Sopenharmony_ci ImmediateMap immediates; 170bf215546Sopenharmony_ci NirBlockMap blocks; 171bf215546Sopenharmony_ci unsigned int curLoopDepth; 172bf215546Sopenharmony_ci unsigned int curIfDepth; 173bf215546Sopenharmony_ci 174bf215546Sopenharmony_ci BasicBlock *exit; 175bf215546Sopenharmony_ci Value *zero; 176bf215546Sopenharmony_ci Instruction *immInsertPos; 177bf215546Sopenharmony_ci 178bf215546Sopenharmony_ci int clipVertexOutput; 179bf215546Sopenharmony_ci 180bf215546Sopenharmony_ci union { 181bf215546Sopenharmony_ci struct { 182bf215546Sopenharmony_ci Value *position; 183bf215546Sopenharmony_ci } fp; 184bf215546Sopenharmony_ci }; 185bf215546Sopenharmony_ci}; 186bf215546Sopenharmony_ci 187bf215546Sopenharmony_ciConverter::Converter(Program *prog, nir_shader *nir, nv50_ir_prog_info *info, 188bf215546Sopenharmony_ci nv50_ir_prog_info_out *info_out) 189bf215546Sopenharmony_ci : ConverterCommon(prog, info, info_out), 190bf215546Sopenharmony_ci nir(nir), 191bf215546Sopenharmony_ci curLoopDepth(0), 192bf215546Sopenharmony_ci curIfDepth(0), 193bf215546Sopenharmony_ci exit(NULL), 194bf215546Sopenharmony_ci immInsertPos(NULL), 195bf215546Sopenharmony_ci clipVertexOutput(-1) 196bf215546Sopenharmony_ci{ 197bf215546Sopenharmony_ci zero = mkImm((uint32_t)0); 198bf215546Sopenharmony_ci} 199bf215546Sopenharmony_ci 200bf215546Sopenharmony_ciBasicBlock * 201bf215546Sopenharmony_ciConverter::convert(nir_block *block) 202bf215546Sopenharmony_ci{ 203bf215546Sopenharmony_ci NirBlockMap::iterator it = blocks.find(block->index); 204bf215546Sopenharmony_ci if (it != blocks.end()) 205bf215546Sopenharmony_ci return it->second; 206bf215546Sopenharmony_ci 207bf215546Sopenharmony_ci BasicBlock *bb = new BasicBlock(func); 208bf215546Sopenharmony_ci blocks[block->index] = bb; 209bf215546Sopenharmony_ci return bb; 210bf215546Sopenharmony_ci} 211bf215546Sopenharmony_ci 212bf215546Sopenharmony_cibool 213bf215546Sopenharmony_ciConverter::isFloatType(nir_alu_type type) 214bf215546Sopenharmony_ci{ 215bf215546Sopenharmony_ci return nir_alu_type_get_base_type(type) == nir_type_float; 216bf215546Sopenharmony_ci} 217bf215546Sopenharmony_ci 218bf215546Sopenharmony_cibool 219bf215546Sopenharmony_ciConverter::isSignedType(nir_alu_type type) 220bf215546Sopenharmony_ci{ 221bf215546Sopenharmony_ci return nir_alu_type_get_base_type(type) == nir_type_int; 222bf215546Sopenharmony_ci} 223bf215546Sopenharmony_ci 224bf215546Sopenharmony_cibool 225bf215546Sopenharmony_ciConverter::isResultFloat(nir_op op) 226bf215546Sopenharmony_ci{ 227bf215546Sopenharmony_ci const nir_op_info &info = nir_op_infos[op]; 228bf215546Sopenharmony_ci if (info.output_type != nir_type_invalid) 229bf215546Sopenharmony_ci return isFloatType(info.output_type); 230bf215546Sopenharmony_ci 231bf215546Sopenharmony_ci ERROR("isResultFloat not implemented for %s\n", nir_op_infos[op].name); 232bf215546Sopenharmony_ci assert(false); 233bf215546Sopenharmony_ci return true; 234bf215546Sopenharmony_ci} 235bf215546Sopenharmony_ci 236bf215546Sopenharmony_cibool 237bf215546Sopenharmony_ciConverter::isResultSigned(nir_op op) 238bf215546Sopenharmony_ci{ 239bf215546Sopenharmony_ci switch (op) { 240bf215546Sopenharmony_ci // there is no umul and we get wrong results if we treat all muls as signed 241bf215546Sopenharmony_ci case nir_op_imul: 242bf215546Sopenharmony_ci case nir_op_inot: 243bf215546Sopenharmony_ci return false; 244bf215546Sopenharmony_ci default: 245bf215546Sopenharmony_ci const nir_op_info &info = nir_op_infos[op]; 246bf215546Sopenharmony_ci if (info.output_type != nir_type_invalid) 247bf215546Sopenharmony_ci return isSignedType(info.output_type); 248bf215546Sopenharmony_ci ERROR("isResultSigned not implemented for %s\n", nir_op_infos[op].name); 249bf215546Sopenharmony_ci assert(false); 250bf215546Sopenharmony_ci return true; 251bf215546Sopenharmony_ci } 252bf215546Sopenharmony_ci} 253bf215546Sopenharmony_ci 254bf215546Sopenharmony_ciDataType 255bf215546Sopenharmony_ciConverter::getDType(nir_alu_instr *insn) 256bf215546Sopenharmony_ci{ 257bf215546Sopenharmony_ci if (insn->dest.dest.is_ssa) 258bf215546Sopenharmony_ci return getDType(insn->op, insn->dest.dest.ssa.bit_size); 259bf215546Sopenharmony_ci else 260bf215546Sopenharmony_ci return getDType(insn->op, insn->dest.dest.reg.reg->bit_size); 261bf215546Sopenharmony_ci} 262bf215546Sopenharmony_ci 263bf215546Sopenharmony_ciDataType 264bf215546Sopenharmony_ciConverter::getDType(nir_intrinsic_instr *insn) 265bf215546Sopenharmony_ci{ 266bf215546Sopenharmony_ci bool isFloat, isSigned; 267bf215546Sopenharmony_ci switch (insn->intrinsic) { 268bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_fadd: 269bf215546Sopenharmony_ci case nir_intrinsic_global_atomic_fadd: 270bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_fadd: 271bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_fadd: 272bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_fadd: 273bf215546Sopenharmony_ci isFloat = true; 274bf215546Sopenharmony_ci isSigned = false; 275bf215546Sopenharmony_ci break; 276bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_imax: 277bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_imin: 278bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_imax: 279bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_imin: 280bf215546Sopenharmony_ci isFloat = false; 281bf215546Sopenharmony_ci isSigned = true; 282bf215546Sopenharmony_ci break; 283bf215546Sopenharmony_ci default: 284bf215546Sopenharmony_ci isFloat = false; 285bf215546Sopenharmony_ci isSigned = false; 286bf215546Sopenharmony_ci break; 287bf215546Sopenharmony_ci } 288bf215546Sopenharmony_ci 289bf215546Sopenharmony_ci if (insn->dest.is_ssa) 290bf215546Sopenharmony_ci return typeOfSize(insn->dest.ssa.bit_size / 8, isFloat, isSigned); 291bf215546Sopenharmony_ci else 292bf215546Sopenharmony_ci return typeOfSize(insn->dest.reg.reg->bit_size / 8, isFloat, isSigned); 293bf215546Sopenharmony_ci} 294bf215546Sopenharmony_ci 295bf215546Sopenharmony_ciDataType 296bf215546Sopenharmony_ciConverter::getDType(nir_op op, uint8_t bitSize) 297bf215546Sopenharmony_ci{ 298bf215546Sopenharmony_ci DataType ty = typeOfSize(bitSize / 8, isResultFloat(op), isResultSigned(op)); 299bf215546Sopenharmony_ci if (ty == TYPE_NONE) { 300bf215546Sopenharmony_ci ERROR("couldn't get Type for op %s with bitSize %u\n", nir_op_infos[op].name, bitSize); 301bf215546Sopenharmony_ci assert(false); 302bf215546Sopenharmony_ci } 303bf215546Sopenharmony_ci return ty; 304bf215546Sopenharmony_ci} 305bf215546Sopenharmony_ci 306bf215546Sopenharmony_cistd::vector<DataType> 307bf215546Sopenharmony_ciConverter::getSTypes(nir_alu_instr *insn) 308bf215546Sopenharmony_ci{ 309bf215546Sopenharmony_ci const nir_op_info &info = nir_op_infos[insn->op]; 310bf215546Sopenharmony_ci std::vector<DataType> res(info.num_inputs); 311bf215546Sopenharmony_ci 312bf215546Sopenharmony_ci for (uint8_t i = 0; i < info.num_inputs; ++i) { 313bf215546Sopenharmony_ci if (info.input_types[i] != nir_type_invalid) { 314bf215546Sopenharmony_ci res[i] = getSType(insn->src[i].src, isFloatType(info.input_types[i]), isSignedType(info.input_types[i])); 315bf215546Sopenharmony_ci } else { 316bf215546Sopenharmony_ci ERROR("getSType not implemented for %s idx %u\n", info.name, i); 317bf215546Sopenharmony_ci assert(false); 318bf215546Sopenharmony_ci res[i] = TYPE_NONE; 319bf215546Sopenharmony_ci break; 320bf215546Sopenharmony_ci } 321bf215546Sopenharmony_ci } 322bf215546Sopenharmony_ci 323bf215546Sopenharmony_ci return res; 324bf215546Sopenharmony_ci} 325bf215546Sopenharmony_ci 326bf215546Sopenharmony_ciDataType 327bf215546Sopenharmony_ciConverter::getSType(nir_src &src, bool isFloat, bool isSigned) 328bf215546Sopenharmony_ci{ 329bf215546Sopenharmony_ci uint8_t bitSize; 330bf215546Sopenharmony_ci if (src.is_ssa) 331bf215546Sopenharmony_ci bitSize = src.ssa->bit_size; 332bf215546Sopenharmony_ci else 333bf215546Sopenharmony_ci bitSize = src.reg.reg->bit_size; 334bf215546Sopenharmony_ci 335bf215546Sopenharmony_ci DataType ty = typeOfSize(bitSize / 8, isFloat, isSigned); 336bf215546Sopenharmony_ci if (ty == TYPE_NONE) { 337bf215546Sopenharmony_ci const char *str; 338bf215546Sopenharmony_ci if (isFloat) 339bf215546Sopenharmony_ci str = "float"; 340bf215546Sopenharmony_ci else if (isSigned) 341bf215546Sopenharmony_ci str = "int"; 342bf215546Sopenharmony_ci else 343bf215546Sopenharmony_ci str = "uint"; 344bf215546Sopenharmony_ci ERROR("couldn't get Type for %s with bitSize %u\n", str, bitSize); 345bf215546Sopenharmony_ci assert(false); 346bf215546Sopenharmony_ci } 347bf215546Sopenharmony_ci return ty; 348bf215546Sopenharmony_ci} 349bf215546Sopenharmony_ci 350bf215546Sopenharmony_ciDataFile 351bf215546Sopenharmony_ciConverter::getFile(nir_intrinsic_op op) 352bf215546Sopenharmony_ci{ 353bf215546Sopenharmony_ci switch (op) { 354bf215546Sopenharmony_ci case nir_intrinsic_load_global: 355bf215546Sopenharmony_ci case nir_intrinsic_store_global: 356bf215546Sopenharmony_ci case nir_intrinsic_load_global_constant: 357bf215546Sopenharmony_ci return FILE_MEMORY_GLOBAL; 358bf215546Sopenharmony_ci case nir_intrinsic_load_scratch: 359bf215546Sopenharmony_ci case nir_intrinsic_store_scratch: 360bf215546Sopenharmony_ci return FILE_MEMORY_LOCAL; 361bf215546Sopenharmony_ci case nir_intrinsic_load_shared: 362bf215546Sopenharmony_ci case nir_intrinsic_store_shared: 363bf215546Sopenharmony_ci return FILE_MEMORY_SHARED; 364bf215546Sopenharmony_ci case nir_intrinsic_load_kernel_input: 365bf215546Sopenharmony_ci return FILE_SHADER_INPUT; 366bf215546Sopenharmony_ci default: 367bf215546Sopenharmony_ci ERROR("couldn't get DateFile for op %s\n", nir_intrinsic_infos[op].name); 368bf215546Sopenharmony_ci assert(false); 369bf215546Sopenharmony_ci } 370bf215546Sopenharmony_ci return FILE_NULL; 371bf215546Sopenharmony_ci} 372bf215546Sopenharmony_ci 373bf215546Sopenharmony_cioperation 374bf215546Sopenharmony_ciConverter::getOperation(nir_op op) 375bf215546Sopenharmony_ci{ 376bf215546Sopenharmony_ci switch (op) { 377bf215546Sopenharmony_ci // basic ops with float and int variants 378bf215546Sopenharmony_ci case nir_op_fabs: 379bf215546Sopenharmony_ci case nir_op_iabs: 380bf215546Sopenharmony_ci return OP_ABS; 381bf215546Sopenharmony_ci case nir_op_fadd: 382bf215546Sopenharmony_ci case nir_op_iadd: 383bf215546Sopenharmony_ci return OP_ADD; 384bf215546Sopenharmony_ci case nir_op_iand: 385bf215546Sopenharmony_ci return OP_AND; 386bf215546Sopenharmony_ci case nir_op_ifind_msb: 387bf215546Sopenharmony_ci case nir_op_ufind_msb: 388bf215546Sopenharmony_ci return OP_BFIND; 389bf215546Sopenharmony_ci case nir_op_fceil: 390bf215546Sopenharmony_ci return OP_CEIL; 391bf215546Sopenharmony_ci case nir_op_fcos: 392bf215546Sopenharmony_ci return OP_COS; 393bf215546Sopenharmony_ci case nir_op_f2f32: 394bf215546Sopenharmony_ci case nir_op_f2f64: 395bf215546Sopenharmony_ci case nir_op_f2i32: 396bf215546Sopenharmony_ci case nir_op_f2i64: 397bf215546Sopenharmony_ci case nir_op_f2u32: 398bf215546Sopenharmony_ci case nir_op_f2u64: 399bf215546Sopenharmony_ci case nir_op_i2f32: 400bf215546Sopenharmony_ci case nir_op_i2f64: 401bf215546Sopenharmony_ci case nir_op_i2i32: 402bf215546Sopenharmony_ci case nir_op_i2i64: 403bf215546Sopenharmony_ci case nir_op_u2f32: 404bf215546Sopenharmony_ci case nir_op_u2f64: 405bf215546Sopenharmony_ci case nir_op_u2u32: 406bf215546Sopenharmony_ci case nir_op_u2u64: 407bf215546Sopenharmony_ci return OP_CVT; 408bf215546Sopenharmony_ci case nir_op_fddx: 409bf215546Sopenharmony_ci case nir_op_fddx_coarse: 410bf215546Sopenharmony_ci case nir_op_fddx_fine: 411bf215546Sopenharmony_ci return OP_DFDX; 412bf215546Sopenharmony_ci case nir_op_fddy: 413bf215546Sopenharmony_ci case nir_op_fddy_coarse: 414bf215546Sopenharmony_ci case nir_op_fddy_fine: 415bf215546Sopenharmony_ci return OP_DFDY; 416bf215546Sopenharmony_ci case nir_op_fdiv: 417bf215546Sopenharmony_ci case nir_op_idiv: 418bf215546Sopenharmony_ci case nir_op_udiv: 419bf215546Sopenharmony_ci return OP_DIV; 420bf215546Sopenharmony_ci case nir_op_fexp2: 421bf215546Sopenharmony_ci return OP_EX2; 422bf215546Sopenharmony_ci case nir_op_ffloor: 423bf215546Sopenharmony_ci return OP_FLOOR; 424bf215546Sopenharmony_ci case nir_op_ffma: 425bf215546Sopenharmony_ci /* No FMA op pre-nvc0 */ 426bf215546Sopenharmony_ci if (info->target < 0xc0) 427bf215546Sopenharmony_ci return OP_MAD; 428bf215546Sopenharmony_ci return OP_FMA; 429bf215546Sopenharmony_ci case nir_op_flog2: 430bf215546Sopenharmony_ci return OP_LG2; 431bf215546Sopenharmony_ci case nir_op_fmax: 432bf215546Sopenharmony_ci case nir_op_imax: 433bf215546Sopenharmony_ci case nir_op_umax: 434bf215546Sopenharmony_ci return OP_MAX; 435bf215546Sopenharmony_ci case nir_op_pack_64_2x32_split: 436bf215546Sopenharmony_ci return OP_MERGE; 437bf215546Sopenharmony_ci case nir_op_fmin: 438bf215546Sopenharmony_ci case nir_op_imin: 439bf215546Sopenharmony_ci case nir_op_umin: 440bf215546Sopenharmony_ci return OP_MIN; 441bf215546Sopenharmony_ci case nir_op_fmod: 442bf215546Sopenharmony_ci case nir_op_imod: 443bf215546Sopenharmony_ci case nir_op_umod: 444bf215546Sopenharmony_ci case nir_op_frem: 445bf215546Sopenharmony_ci case nir_op_irem: 446bf215546Sopenharmony_ci return OP_MOD; 447bf215546Sopenharmony_ci case nir_op_fmul: 448bf215546Sopenharmony_ci case nir_op_imul: 449bf215546Sopenharmony_ci case nir_op_imul_high: 450bf215546Sopenharmony_ci case nir_op_umul_high: 451bf215546Sopenharmony_ci return OP_MUL; 452bf215546Sopenharmony_ci case nir_op_fneg: 453bf215546Sopenharmony_ci case nir_op_ineg: 454bf215546Sopenharmony_ci return OP_NEG; 455bf215546Sopenharmony_ci case nir_op_inot: 456bf215546Sopenharmony_ci return OP_NOT; 457bf215546Sopenharmony_ci case nir_op_ior: 458bf215546Sopenharmony_ci return OP_OR; 459bf215546Sopenharmony_ci case nir_op_fpow: 460bf215546Sopenharmony_ci return OP_POW; 461bf215546Sopenharmony_ci case nir_op_frcp: 462bf215546Sopenharmony_ci return OP_RCP; 463bf215546Sopenharmony_ci case nir_op_frsq: 464bf215546Sopenharmony_ci return OP_RSQ; 465bf215546Sopenharmony_ci case nir_op_fsat: 466bf215546Sopenharmony_ci return OP_SAT; 467bf215546Sopenharmony_ci case nir_op_feq32: 468bf215546Sopenharmony_ci case nir_op_ieq32: 469bf215546Sopenharmony_ci case nir_op_fge32: 470bf215546Sopenharmony_ci case nir_op_ige32: 471bf215546Sopenharmony_ci case nir_op_uge32: 472bf215546Sopenharmony_ci case nir_op_flt32: 473bf215546Sopenharmony_ci case nir_op_ilt32: 474bf215546Sopenharmony_ci case nir_op_ult32: 475bf215546Sopenharmony_ci case nir_op_fneu32: 476bf215546Sopenharmony_ci case nir_op_ine32: 477bf215546Sopenharmony_ci return OP_SET; 478bf215546Sopenharmony_ci case nir_op_ishl: 479bf215546Sopenharmony_ci return OP_SHL; 480bf215546Sopenharmony_ci case nir_op_ishr: 481bf215546Sopenharmony_ci case nir_op_ushr: 482bf215546Sopenharmony_ci return OP_SHR; 483bf215546Sopenharmony_ci case nir_op_fsin: 484bf215546Sopenharmony_ci return OP_SIN; 485bf215546Sopenharmony_ci case nir_op_fsqrt: 486bf215546Sopenharmony_ci return OP_SQRT; 487bf215546Sopenharmony_ci case nir_op_ftrunc: 488bf215546Sopenharmony_ci return OP_TRUNC; 489bf215546Sopenharmony_ci case nir_op_ixor: 490bf215546Sopenharmony_ci return OP_XOR; 491bf215546Sopenharmony_ci default: 492bf215546Sopenharmony_ci ERROR("couldn't get operation for op %s\n", nir_op_infos[op].name); 493bf215546Sopenharmony_ci assert(false); 494bf215546Sopenharmony_ci return OP_NOP; 495bf215546Sopenharmony_ci } 496bf215546Sopenharmony_ci} 497bf215546Sopenharmony_ci 498bf215546Sopenharmony_cioperation 499bf215546Sopenharmony_ciConverter::getOperation(nir_texop op) 500bf215546Sopenharmony_ci{ 501bf215546Sopenharmony_ci switch (op) { 502bf215546Sopenharmony_ci case nir_texop_tex: 503bf215546Sopenharmony_ci return OP_TEX; 504bf215546Sopenharmony_ci case nir_texop_lod: 505bf215546Sopenharmony_ci return OP_TXLQ; 506bf215546Sopenharmony_ci case nir_texop_txb: 507bf215546Sopenharmony_ci return OP_TXB; 508bf215546Sopenharmony_ci case nir_texop_txd: 509bf215546Sopenharmony_ci return OP_TXD; 510bf215546Sopenharmony_ci case nir_texop_txf: 511bf215546Sopenharmony_ci case nir_texop_txf_ms: 512bf215546Sopenharmony_ci return OP_TXF; 513bf215546Sopenharmony_ci case nir_texop_tg4: 514bf215546Sopenharmony_ci return OP_TXG; 515bf215546Sopenharmony_ci case nir_texop_txl: 516bf215546Sopenharmony_ci return OP_TXL; 517bf215546Sopenharmony_ci case nir_texop_query_levels: 518bf215546Sopenharmony_ci case nir_texop_texture_samples: 519bf215546Sopenharmony_ci case nir_texop_txs: 520bf215546Sopenharmony_ci return OP_TXQ; 521bf215546Sopenharmony_ci default: 522bf215546Sopenharmony_ci ERROR("couldn't get operation for nir_texop %u\n", op); 523bf215546Sopenharmony_ci assert(false); 524bf215546Sopenharmony_ci return OP_NOP; 525bf215546Sopenharmony_ci } 526bf215546Sopenharmony_ci} 527bf215546Sopenharmony_ci 528bf215546Sopenharmony_cioperation 529bf215546Sopenharmony_ciConverter::getOperation(nir_intrinsic_op op) 530bf215546Sopenharmony_ci{ 531bf215546Sopenharmony_ci switch (op) { 532bf215546Sopenharmony_ci case nir_intrinsic_emit_vertex: 533bf215546Sopenharmony_ci return OP_EMIT; 534bf215546Sopenharmony_ci case nir_intrinsic_end_primitive: 535bf215546Sopenharmony_ci return OP_RESTART; 536bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_add: 537bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_add: 538bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_and: 539bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_and: 540bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_comp_swap: 541bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_comp_swap: 542bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_exchange: 543bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_exchange: 544bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_imax: 545bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_imax: 546bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_umax: 547bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_umax: 548bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_imin: 549bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_imin: 550bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_umin: 551bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_umin: 552bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_or: 553bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_or: 554bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_xor: 555bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_xor: 556bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_inc_wrap: 557bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_inc_wrap: 558bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_dec_wrap: 559bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_dec_wrap: 560bf215546Sopenharmony_ci return OP_SUREDP; 561bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_load: 562bf215546Sopenharmony_ci case nir_intrinsic_image_load: 563bf215546Sopenharmony_ci return OP_SULDP; 564bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_samples: 565bf215546Sopenharmony_ci case nir_intrinsic_image_samples: 566bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_size: 567bf215546Sopenharmony_ci case nir_intrinsic_image_size: 568bf215546Sopenharmony_ci return OP_SUQ; 569bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_store: 570bf215546Sopenharmony_ci case nir_intrinsic_image_store: 571bf215546Sopenharmony_ci return OP_SUSTP; 572bf215546Sopenharmony_ci default: 573bf215546Sopenharmony_ci ERROR("couldn't get operation for nir_intrinsic_op %u\n", op); 574bf215546Sopenharmony_ci assert(false); 575bf215546Sopenharmony_ci return OP_NOP; 576bf215546Sopenharmony_ci } 577bf215546Sopenharmony_ci} 578bf215546Sopenharmony_ci 579bf215546Sopenharmony_cioperation 580bf215546Sopenharmony_ciConverter::preOperationNeeded(nir_op op) 581bf215546Sopenharmony_ci{ 582bf215546Sopenharmony_ci switch (op) { 583bf215546Sopenharmony_ci case nir_op_fcos: 584bf215546Sopenharmony_ci case nir_op_fsin: 585bf215546Sopenharmony_ci return OP_PRESIN; 586bf215546Sopenharmony_ci default: 587bf215546Sopenharmony_ci return OP_NOP; 588bf215546Sopenharmony_ci } 589bf215546Sopenharmony_ci} 590bf215546Sopenharmony_ci 591bf215546Sopenharmony_ciint 592bf215546Sopenharmony_ciConverter::getSubOp(nir_op op) 593bf215546Sopenharmony_ci{ 594bf215546Sopenharmony_ci switch (op) { 595bf215546Sopenharmony_ci case nir_op_imul_high: 596bf215546Sopenharmony_ci case nir_op_umul_high: 597bf215546Sopenharmony_ci return NV50_IR_SUBOP_MUL_HIGH; 598bf215546Sopenharmony_ci case nir_op_ishl: 599bf215546Sopenharmony_ci case nir_op_ishr: 600bf215546Sopenharmony_ci case nir_op_ushr: 601bf215546Sopenharmony_ci return NV50_IR_SUBOP_SHIFT_WRAP; 602bf215546Sopenharmony_ci default: 603bf215546Sopenharmony_ci return 0; 604bf215546Sopenharmony_ci } 605bf215546Sopenharmony_ci} 606bf215546Sopenharmony_ci 607bf215546Sopenharmony_ciint 608bf215546Sopenharmony_ciConverter::getSubOp(nir_intrinsic_op op) 609bf215546Sopenharmony_ci{ 610bf215546Sopenharmony_ci switch (op) { 611bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_add: 612bf215546Sopenharmony_ci case nir_intrinsic_global_atomic_add: 613bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_add: 614bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_add: 615bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_add: 616bf215546Sopenharmony_ci return NV50_IR_SUBOP_ATOM_ADD; 617bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_fadd: 618bf215546Sopenharmony_ci case nir_intrinsic_global_atomic_fadd: 619bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_fadd: 620bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_fadd: 621bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_fadd: 622bf215546Sopenharmony_ci return NV50_IR_SUBOP_ATOM_ADD; 623bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_and: 624bf215546Sopenharmony_ci case nir_intrinsic_global_atomic_and: 625bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_and: 626bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_and: 627bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_and: 628bf215546Sopenharmony_ci return NV50_IR_SUBOP_ATOM_AND; 629bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_comp_swap: 630bf215546Sopenharmony_ci case nir_intrinsic_global_atomic_comp_swap: 631bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_comp_swap: 632bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_comp_swap: 633bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_comp_swap: 634bf215546Sopenharmony_ci return NV50_IR_SUBOP_ATOM_CAS; 635bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_exchange: 636bf215546Sopenharmony_ci case nir_intrinsic_global_atomic_exchange: 637bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_exchange: 638bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_exchange: 639bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_exchange: 640bf215546Sopenharmony_ci return NV50_IR_SUBOP_ATOM_EXCH; 641bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_or: 642bf215546Sopenharmony_ci case nir_intrinsic_global_atomic_or: 643bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_or: 644bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_or: 645bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_or: 646bf215546Sopenharmony_ci return NV50_IR_SUBOP_ATOM_OR; 647bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_imax: 648bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_umax: 649bf215546Sopenharmony_ci case nir_intrinsic_global_atomic_imax: 650bf215546Sopenharmony_ci case nir_intrinsic_global_atomic_umax: 651bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_imax: 652bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_umax: 653bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_imax: 654bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_umax: 655bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_imax: 656bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_umax: 657bf215546Sopenharmony_ci return NV50_IR_SUBOP_ATOM_MAX; 658bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_imin: 659bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_umin: 660bf215546Sopenharmony_ci case nir_intrinsic_global_atomic_imin: 661bf215546Sopenharmony_ci case nir_intrinsic_global_atomic_umin: 662bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_imin: 663bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_umin: 664bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_imin: 665bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_umin: 666bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_imin: 667bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_umin: 668bf215546Sopenharmony_ci return NV50_IR_SUBOP_ATOM_MIN; 669bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_xor: 670bf215546Sopenharmony_ci case nir_intrinsic_global_atomic_xor: 671bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_xor: 672bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_xor: 673bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_xor: 674bf215546Sopenharmony_ci return NV50_IR_SUBOP_ATOM_XOR; 675bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_inc_wrap: 676bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_inc_wrap: 677bf215546Sopenharmony_ci return NV50_IR_SUBOP_ATOM_INC; 678bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_dec_wrap: 679bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_dec_wrap: 680bf215546Sopenharmony_ci return NV50_IR_SUBOP_ATOM_DEC; 681bf215546Sopenharmony_ci 682bf215546Sopenharmony_ci case nir_intrinsic_group_memory_barrier: 683bf215546Sopenharmony_ci case nir_intrinsic_memory_barrier: 684bf215546Sopenharmony_ci case nir_intrinsic_memory_barrier_buffer: 685bf215546Sopenharmony_ci case nir_intrinsic_memory_barrier_image: 686bf215546Sopenharmony_ci return NV50_IR_SUBOP_MEMBAR(M, GL); 687bf215546Sopenharmony_ci case nir_intrinsic_memory_barrier_shared: 688bf215546Sopenharmony_ci return NV50_IR_SUBOP_MEMBAR(M, CTA); 689bf215546Sopenharmony_ci 690bf215546Sopenharmony_ci case nir_intrinsic_vote_all: 691bf215546Sopenharmony_ci return NV50_IR_SUBOP_VOTE_ALL; 692bf215546Sopenharmony_ci case nir_intrinsic_vote_any: 693bf215546Sopenharmony_ci return NV50_IR_SUBOP_VOTE_ANY; 694bf215546Sopenharmony_ci case nir_intrinsic_vote_ieq: 695bf215546Sopenharmony_ci return NV50_IR_SUBOP_VOTE_UNI; 696bf215546Sopenharmony_ci default: 697bf215546Sopenharmony_ci return 0; 698bf215546Sopenharmony_ci } 699bf215546Sopenharmony_ci} 700bf215546Sopenharmony_ci 701bf215546Sopenharmony_ciCondCode 702bf215546Sopenharmony_ciConverter::getCondCode(nir_op op) 703bf215546Sopenharmony_ci{ 704bf215546Sopenharmony_ci switch (op) { 705bf215546Sopenharmony_ci case nir_op_feq32: 706bf215546Sopenharmony_ci case nir_op_ieq32: 707bf215546Sopenharmony_ci return CC_EQ; 708bf215546Sopenharmony_ci case nir_op_fge32: 709bf215546Sopenharmony_ci case nir_op_ige32: 710bf215546Sopenharmony_ci case nir_op_uge32: 711bf215546Sopenharmony_ci return CC_GE; 712bf215546Sopenharmony_ci case nir_op_flt32: 713bf215546Sopenharmony_ci case nir_op_ilt32: 714bf215546Sopenharmony_ci case nir_op_ult32: 715bf215546Sopenharmony_ci return CC_LT; 716bf215546Sopenharmony_ci case nir_op_fneu32: 717bf215546Sopenharmony_ci return CC_NEU; 718bf215546Sopenharmony_ci case nir_op_ine32: 719bf215546Sopenharmony_ci return CC_NE; 720bf215546Sopenharmony_ci default: 721bf215546Sopenharmony_ci ERROR("couldn't get CondCode for op %s\n", nir_op_infos[op].name); 722bf215546Sopenharmony_ci assert(false); 723bf215546Sopenharmony_ci return CC_FL; 724bf215546Sopenharmony_ci } 725bf215546Sopenharmony_ci} 726bf215546Sopenharmony_ci 727bf215546Sopenharmony_ciConverter::LValues& 728bf215546Sopenharmony_ciConverter::convert(nir_alu_dest *dest) 729bf215546Sopenharmony_ci{ 730bf215546Sopenharmony_ci return convert(&dest->dest); 731bf215546Sopenharmony_ci} 732bf215546Sopenharmony_ci 733bf215546Sopenharmony_ciConverter::LValues& 734bf215546Sopenharmony_ciConverter::convert(nir_dest *dest) 735bf215546Sopenharmony_ci{ 736bf215546Sopenharmony_ci if (dest->is_ssa) 737bf215546Sopenharmony_ci return convert(&dest->ssa); 738bf215546Sopenharmony_ci if (dest->reg.indirect) { 739bf215546Sopenharmony_ci ERROR("no support for indirects."); 740bf215546Sopenharmony_ci assert(false); 741bf215546Sopenharmony_ci } 742bf215546Sopenharmony_ci return convert(dest->reg.reg); 743bf215546Sopenharmony_ci} 744bf215546Sopenharmony_ci 745bf215546Sopenharmony_ciConverter::LValues& 746bf215546Sopenharmony_ciConverter::convert(nir_register *reg) 747bf215546Sopenharmony_ci{ 748bf215546Sopenharmony_ci assert(!reg->num_array_elems); 749bf215546Sopenharmony_ci 750bf215546Sopenharmony_ci NirDefMap::iterator it = regDefs.find(reg->index); 751bf215546Sopenharmony_ci if (it != regDefs.end()) 752bf215546Sopenharmony_ci return it->second; 753bf215546Sopenharmony_ci 754bf215546Sopenharmony_ci LValues newDef(reg->num_components); 755bf215546Sopenharmony_ci for (uint8_t i = 0; i < reg->num_components; i++) 756bf215546Sopenharmony_ci newDef[i] = getScratch(std::max(4, reg->bit_size / 8)); 757bf215546Sopenharmony_ci return regDefs[reg->index] = newDef; 758bf215546Sopenharmony_ci} 759bf215546Sopenharmony_ci 760bf215546Sopenharmony_ciConverter::LValues& 761bf215546Sopenharmony_ciConverter::convert(nir_ssa_def *def) 762bf215546Sopenharmony_ci{ 763bf215546Sopenharmony_ci NirDefMap::iterator it = ssaDefs.find(def->index); 764bf215546Sopenharmony_ci if (it != ssaDefs.end()) 765bf215546Sopenharmony_ci return it->second; 766bf215546Sopenharmony_ci 767bf215546Sopenharmony_ci LValues newDef(def->num_components); 768bf215546Sopenharmony_ci for (uint8_t i = 0; i < def->num_components; i++) 769bf215546Sopenharmony_ci newDef[i] = getSSA(std::max(4, def->bit_size / 8)); 770bf215546Sopenharmony_ci return ssaDefs[def->index] = newDef; 771bf215546Sopenharmony_ci} 772bf215546Sopenharmony_ci 773bf215546Sopenharmony_ciValue* 774bf215546Sopenharmony_ciConverter::getSrc(nir_alu_src *src, uint8_t component) 775bf215546Sopenharmony_ci{ 776bf215546Sopenharmony_ci if (src->abs || src->negate) { 777bf215546Sopenharmony_ci ERROR("modifiers currently not supported on nir_alu_src\n"); 778bf215546Sopenharmony_ci assert(false); 779bf215546Sopenharmony_ci } 780bf215546Sopenharmony_ci return getSrc(&src->src, src->swizzle[component]); 781bf215546Sopenharmony_ci} 782bf215546Sopenharmony_ci 783bf215546Sopenharmony_ciValue* 784bf215546Sopenharmony_ciConverter::getSrc(nir_register *reg, uint8_t idx) 785bf215546Sopenharmony_ci{ 786bf215546Sopenharmony_ci NirDefMap::iterator it = regDefs.find(reg->index); 787bf215546Sopenharmony_ci if (it == regDefs.end()) 788bf215546Sopenharmony_ci return convert(reg)[idx]; 789bf215546Sopenharmony_ci return it->second[idx]; 790bf215546Sopenharmony_ci} 791bf215546Sopenharmony_ci 792bf215546Sopenharmony_ciValue* 793bf215546Sopenharmony_ciConverter::getSrc(nir_src *src, uint8_t idx, bool indirect) 794bf215546Sopenharmony_ci{ 795bf215546Sopenharmony_ci if (src->is_ssa) 796bf215546Sopenharmony_ci return getSrc(src->ssa, idx); 797bf215546Sopenharmony_ci 798bf215546Sopenharmony_ci if (src->reg.indirect) { 799bf215546Sopenharmony_ci if (indirect) 800bf215546Sopenharmony_ci return getSrc(src->reg.indirect, idx); 801bf215546Sopenharmony_ci ERROR("no support for indirects."); 802bf215546Sopenharmony_ci assert(false); 803bf215546Sopenharmony_ci return NULL; 804bf215546Sopenharmony_ci } 805bf215546Sopenharmony_ci 806bf215546Sopenharmony_ci return getSrc(src->reg.reg, idx); 807bf215546Sopenharmony_ci} 808bf215546Sopenharmony_ci 809bf215546Sopenharmony_ciValue* 810bf215546Sopenharmony_ciConverter::getSrc(nir_ssa_def *src, uint8_t idx) 811bf215546Sopenharmony_ci{ 812bf215546Sopenharmony_ci ImmediateMap::iterator iit = immediates.find(src->index); 813bf215546Sopenharmony_ci if (iit != immediates.end()) 814bf215546Sopenharmony_ci return convert((*iit).second, idx); 815bf215546Sopenharmony_ci 816bf215546Sopenharmony_ci NirDefMap::iterator it = ssaDefs.find(src->index); 817bf215546Sopenharmony_ci if (it == ssaDefs.end()) { 818bf215546Sopenharmony_ci ERROR("SSA value %u not found\n", src->index); 819bf215546Sopenharmony_ci assert(false); 820bf215546Sopenharmony_ci return NULL; 821bf215546Sopenharmony_ci } 822bf215546Sopenharmony_ci return it->second[idx]; 823bf215546Sopenharmony_ci} 824bf215546Sopenharmony_ci 825bf215546Sopenharmony_ciuint32_t 826bf215546Sopenharmony_ciConverter::getIndirect(nir_src *src, uint8_t idx, Value *&indirect) 827bf215546Sopenharmony_ci{ 828bf215546Sopenharmony_ci nir_const_value *offset = nir_src_as_const_value(*src); 829bf215546Sopenharmony_ci 830bf215546Sopenharmony_ci if (offset) { 831bf215546Sopenharmony_ci indirect = NULL; 832bf215546Sopenharmony_ci return offset[0].u32; 833bf215546Sopenharmony_ci } 834bf215546Sopenharmony_ci 835bf215546Sopenharmony_ci indirect = getSrc(src, idx, true); 836bf215546Sopenharmony_ci return 0; 837bf215546Sopenharmony_ci} 838bf215546Sopenharmony_ci 839bf215546Sopenharmony_ciuint32_t 840bf215546Sopenharmony_ciConverter::getIndirect(nir_intrinsic_instr *insn, uint8_t s, uint8_t c, Value *&indirect, bool isScalar) 841bf215546Sopenharmony_ci{ 842bf215546Sopenharmony_ci int32_t idx = nir_intrinsic_base(insn) + getIndirect(&insn->src[s], c, indirect); 843bf215546Sopenharmony_ci 844bf215546Sopenharmony_ci if (indirect && !isScalar) 845bf215546Sopenharmony_ci indirect = mkOp2v(OP_SHL, TYPE_U32, getSSA(4, FILE_ADDRESS), indirect, loadImm(NULL, 4)); 846bf215546Sopenharmony_ci return idx; 847bf215546Sopenharmony_ci} 848bf215546Sopenharmony_ci 849bf215546Sopenharmony_cistatic void 850bf215546Sopenharmony_civert_attrib_to_tgsi_semantic(gl_vert_attrib slot, unsigned *name, unsigned *index) 851bf215546Sopenharmony_ci{ 852bf215546Sopenharmony_ci assert(name && index); 853bf215546Sopenharmony_ci 854bf215546Sopenharmony_ci if (slot >= VERT_ATTRIB_MAX) { 855bf215546Sopenharmony_ci ERROR("invalid varying slot %u\n", slot); 856bf215546Sopenharmony_ci assert(false); 857bf215546Sopenharmony_ci return; 858bf215546Sopenharmony_ci } 859bf215546Sopenharmony_ci 860bf215546Sopenharmony_ci if (slot >= VERT_ATTRIB_GENERIC0 && 861bf215546Sopenharmony_ci slot < VERT_ATTRIB_GENERIC0 + VERT_ATTRIB_GENERIC_MAX) { 862bf215546Sopenharmony_ci *name = TGSI_SEMANTIC_GENERIC; 863bf215546Sopenharmony_ci *index = slot - VERT_ATTRIB_GENERIC0; 864bf215546Sopenharmony_ci return; 865bf215546Sopenharmony_ci } 866bf215546Sopenharmony_ci 867bf215546Sopenharmony_ci if (slot >= VERT_ATTRIB_TEX0 && 868bf215546Sopenharmony_ci slot < VERT_ATTRIB_TEX0 + VERT_ATTRIB_TEX_MAX) { 869bf215546Sopenharmony_ci *name = TGSI_SEMANTIC_TEXCOORD; 870bf215546Sopenharmony_ci *index = slot - VERT_ATTRIB_TEX0; 871bf215546Sopenharmony_ci return; 872bf215546Sopenharmony_ci } 873bf215546Sopenharmony_ci 874bf215546Sopenharmony_ci switch (slot) { 875bf215546Sopenharmony_ci case VERT_ATTRIB_COLOR0: 876bf215546Sopenharmony_ci *name = TGSI_SEMANTIC_COLOR; 877bf215546Sopenharmony_ci *index = 0; 878bf215546Sopenharmony_ci break; 879bf215546Sopenharmony_ci case VERT_ATTRIB_COLOR1: 880bf215546Sopenharmony_ci *name = TGSI_SEMANTIC_COLOR; 881bf215546Sopenharmony_ci *index = 1; 882bf215546Sopenharmony_ci break; 883bf215546Sopenharmony_ci case VERT_ATTRIB_EDGEFLAG: 884bf215546Sopenharmony_ci *name = TGSI_SEMANTIC_EDGEFLAG; 885bf215546Sopenharmony_ci *index = 0; 886bf215546Sopenharmony_ci break; 887bf215546Sopenharmony_ci case VERT_ATTRIB_FOG: 888bf215546Sopenharmony_ci *name = TGSI_SEMANTIC_FOG; 889bf215546Sopenharmony_ci *index = 0; 890bf215546Sopenharmony_ci break; 891bf215546Sopenharmony_ci case VERT_ATTRIB_NORMAL: 892bf215546Sopenharmony_ci *name = TGSI_SEMANTIC_NORMAL; 893bf215546Sopenharmony_ci *index = 0; 894bf215546Sopenharmony_ci break; 895bf215546Sopenharmony_ci case VERT_ATTRIB_POS: 896bf215546Sopenharmony_ci *name = TGSI_SEMANTIC_POSITION; 897bf215546Sopenharmony_ci *index = 0; 898bf215546Sopenharmony_ci break; 899bf215546Sopenharmony_ci case VERT_ATTRIB_POINT_SIZE: 900bf215546Sopenharmony_ci *name = TGSI_SEMANTIC_PSIZE; 901bf215546Sopenharmony_ci *index = 0; 902bf215546Sopenharmony_ci break; 903bf215546Sopenharmony_ci default: 904bf215546Sopenharmony_ci ERROR("unknown vert attrib slot %u\n", slot); 905bf215546Sopenharmony_ci assert(false); 906bf215546Sopenharmony_ci break; 907bf215546Sopenharmony_ci } 908bf215546Sopenharmony_ci} 909bf215546Sopenharmony_ci 910bf215546Sopenharmony_civoid 911bf215546Sopenharmony_ciConverter::setInterpolate(nv50_ir_varying *var, 912bf215546Sopenharmony_ci uint8_t mode, 913bf215546Sopenharmony_ci bool centroid, 914bf215546Sopenharmony_ci unsigned semantic) 915bf215546Sopenharmony_ci{ 916bf215546Sopenharmony_ci switch (mode) { 917bf215546Sopenharmony_ci case INTERP_MODE_FLAT: 918bf215546Sopenharmony_ci var->flat = 1; 919bf215546Sopenharmony_ci break; 920bf215546Sopenharmony_ci case INTERP_MODE_NONE: 921bf215546Sopenharmony_ci if (semantic == TGSI_SEMANTIC_COLOR) 922bf215546Sopenharmony_ci var->sc = 1; 923bf215546Sopenharmony_ci else if (semantic == TGSI_SEMANTIC_POSITION) 924bf215546Sopenharmony_ci var->linear = 1; 925bf215546Sopenharmony_ci break; 926bf215546Sopenharmony_ci case INTERP_MODE_NOPERSPECTIVE: 927bf215546Sopenharmony_ci var->linear = 1; 928bf215546Sopenharmony_ci break; 929bf215546Sopenharmony_ci case INTERP_MODE_SMOOTH: 930bf215546Sopenharmony_ci break; 931bf215546Sopenharmony_ci } 932bf215546Sopenharmony_ci var->centroid = centroid; 933bf215546Sopenharmony_ci} 934bf215546Sopenharmony_ci 935bf215546Sopenharmony_cistatic uint16_t 936bf215546Sopenharmony_cicalcSlots(const glsl_type *type, Program::Type stage, const shader_info &info, 937bf215546Sopenharmony_ci bool input, const nir_variable *var) 938bf215546Sopenharmony_ci{ 939bf215546Sopenharmony_ci if (!type->is_array()) 940bf215546Sopenharmony_ci return type->count_attribute_slots(false); 941bf215546Sopenharmony_ci 942bf215546Sopenharmony_ci uint16_t slots; 943bf215546Sopenharmony_ci switch (stage) { 944bf215546Sopenharmony_ci case Program::TYPE_GEOMETRY: 945bf215546Sopenharmony_ci slots = type->count_attribute_slots(false); 946bf215546Sopenharmony_ci if (input) 947bf215546Sopenharmony_ci slots /= info.gs.vertices_in; 948bf215546Sopenharmony_ci break; 949bf215546Sopenharmony_ci case Program::TYPE_TESSELLATION_CONTROL: 950bf215546Sopenharmony_ci case Program::TYPE_TESSELLATION_EVAL: 951bf215546Sopenharmony_ci // remove first dimension 952bf215546Sopenharmony_ci if (var->data.patch || (!input && stage == Program::TYPE_TESSELLATION_EVAL)) 953bf215546Sopenharmony_ci slots = type->count_attribute_slots(false); 954bf215546Sopenharmony_ci else 955bf215546Sopenharmony_ci slots = type->fields.array->count_attribute_slots(false); 956bf215546Sopenharmony_ci break; 957bf215546Sopenharmony_ci default: 958bf215546Sopenharmony_ci slots = type->count_attribute_slots(false); 959bf215546Sopenharmony_ci break; 960bf215546Sopenharmony_ci } 961bf215546Sopenharmony_ci 962bf215546Sopenharmony_ci return slots; 963bf215546Sopenharmony_ci} 964bf215546Sopenharmony_ci 965bf215546Sopenharmony_cistatic uint8_t 966bf215546Sopenharmony_cigetMaskForType(const glsl_type *type, uint8_t slot) { 967bf215546Sopenharmony_ci uint16_t comp = type->without_array()->components(); 968bf215546Sopenharmony_ci comp = comp ? comp : 4; 969bf215546Sopenharmony_ci 970bf215546Sopenharmony_ci if (glsl_base_type_is_64bit(type->without_array()->base_type)) { 971bf215546Sopenharmony_ci comp *= 2; 972bf215546Sopenharmony_ci if (comp > 4) { 973bf215546Sopenharmony_ci if (slot % 2) 974bf215546Sopenharmony_ci comp -= 4; 975bf215546Sopenharmony_ci else 976bf215546Sopenharmony_ci comp = 4; 977bf215546Sopenharmony_ci } 978bf215546Sopenharmony_ci } 979bf215546Sopenharmony_ci 980bf215546Sopenharmony_ci return (1 << comp) - 1; 981bf215546Sopenharmony_ci} 982bf215546Sopenharmony_ci 983bf215546Sopenharmony_cibool Converter::assignSlots() { 984bf215546Sopenharmony_ci unsigned name; 985bf215546Sopenharmony_ci unsigned index; 986bf215546Sopenharmony_ci 987bf215546Sopenharmony_ci info->io.viewportId = -1; 988bf215546Sopenharmony_ci info->io.mul_zero_wins = nir->info.use_legacy_math_rules; 989bf215546Sopenharmony_ci info_out->numInputs = 0; 990bf215546Sopenharmony_ci info_out->numOutputs = 0; 991bf215546Sopenharmony_ci info_out->numSysVals = 0; 992bf215546Sopenharmony_ci 993bf215546Sopenharmony_ci uint8_t i; 994bf215546Sopenharmony_ci BITSET_FOREACH_SET(i, nir->info.system_values_read, SYSTEM_VALUE_MAX) { 995bf215546Sopenharmony_ci info_out->sv[info_out->numSysVals].sn = tgsi_get_sysval_semantic(i); 996bf215546Sopenharmony_ci info_out->sv[info_out->numSysVals].si = 0; 997bf215546Sopenharmony_ci info_out->sv[info_out->numSysVals].input = 0; 998bf215546Sopenharmony_ci 999bf215546Sopenharmony_ci switch (i) { 1000bf215546Sopenharmony_ci case SYSTEM_VALUE_VERTEX_ID: 1001bf215546Sopenharmony_ci info_out->sv[info_out->numSysVals].input = 1; 1002bf215546Sopenharmony_ci info_out->io.vertexId = info_out->numSysVals; 1003bf215546Sopenharmony_ci break; 1004bf215546Sopenharmony_ci case SYSTEM_VALUE_INSTANCE_ID: 1005bf215546Sopenharmony_ci info_out->sv[info_out->numSysVals].input = 1; 1006bf215546Sopenharmony_ci info_out->io.instanceId = info_out->numSysVals; 1007bf215546Sopenharmony_ci break; 1008bf215546Sopenharmony_ci case SYSTEM_VALUE_TESS_LEVEL_INNER: 1009bf215546Sopenharmony_ci case SYSTEM_VALUE_TESS_LEVEL_OUTER: 1010bf215546Sopenharmony_ci info_out->sv[info_out->numSysVals].patch = 1; 1011bf215546Sopenharmony_ci break; 1012bf215546Sopenharmony_ci default: 1013bf215546Sopenharmony_ci break; 1014bf215546Sopenharmony_ci } 1015bf215546Sopenharmony_ci 1016bf215546Sopenharmony_ci info_out->numSysVals += 1; 1017bf215546Sopenharmony_ci } 1018bf215546Sopenharmony_ci 1019bf215546Sopenharmony_ci if (prog->getType() == Program::TYPE_COMPUTE) 1020bf215546Sopenharmony_ci return true; 1021bf215546Sopenharmony_ci 1022bf215546Sopenharmony_ci nir_foreach_shader_in_variable(var, nir) { 1023bf215546Sopenharmony_ci const glsl_type *type = var->type; 1024bf215546Sopenharmony_ci int slot = var->data.location; 1025bf215546Sopenharmony_ci uint16_t slots = calcSlots(type, prog->getType(), nir->info, true, var); 1026bf215546Sopenharmony_ci uint32_t vary = var->data.driver_location; 1027bf215546Sopenharmony_ci assert(vary + slots <= NV50_CODEGEN_MAX_VARYINGS); 1028bf215546Sopenharmony_ci 1029bf215546Sopenharmony_ci switch(prog->getType()) { 1030bf215546Sopenharmony_ci case Program::TYPE_FRAGMENT: 1031bf215546Sopenharmony_ci tgsi_get_gl_varying_semantic((gl_varying_slot)slot, true, 1032bf215546Sopenharmony_ci &name, &index); 1033bf215546Sopenharmony_ci for (uint16_t i = 0; i < slots; ++i) { 1034bf215546Sopenharmony_ci setInterpolate(&info_out->in[vary + i], var->data.interpolation, 1035bf215546Sopenharmony_ci var->data.centroid | var->data.sample, name); 1036bf215546Sopenharmony_ci } 1037bf215546Sopenharmony_ci break; 1038bf215546Sopenharmony_ci case Program::TYPE_GEOMETRY: 1039bf215546Sopenharmony_ci tgsi_get_gl_varying_semantic((gl_varying_slot)slot, true, 1040bf215546Sopenharmony_ci &name, &index); 1041bf215546Sopenharmony_ci break; 1042bf215546Sopenharmony_ci case Program::TYPE_TESSELLATION_CONTROL: 1043bf215546Sopenharmony_ci case Program::TYPE_TESSELLATION_EVAL: 1044bf215546Sopenharmony_ci tgsi_get_gl_varying_semantic((gl_varying_slot)slot, true, 1045bf215546Sopenharmony_ci &name, &index); 1046bf215546Sopenharmony_ci if (var->data.patch && name == TGSI_SEMANTIC_PATCH) 1047bf215546Sopenharmony_ci info_out->numPatchConstants = MAX2(info_out->numPatchConstants, index + slots); 1048bf215546Sopenharmony_ci break; 1049bf215546Sopenharmony_ci case Program::TYPE_VERTEX: 1050bf215546Sopenharmony_ci if (slot >= VERT_ATTRIB_GENERIC0 && slot < VERT_ATTRIB_GENERIC0 + VERT_ATTRIB_GENERIC_MAX) 1051bf215546Sopenharmony_ci slot = VERT_ATTRIB_GENERIC0 + vary; 1052bf215546Sopenharmony_ci vert_attrib_to_tgsi_semantic((gl_vert_attrib)slot, &name, &index); 1053bf215546Sopenharmony_ci switch (name) { 1054bf215546Sopenharmony_ci case TGSI_SEMANTIC_EDGEFLAG: 1055bf215546Sopenharmony_ci info_out->io.edgeFlagIn = vary; 1056bf215546Sopenharmony_ci break; 1057bf215546Sopenharmony_ci default: 1058bf215546Sopenharmony_ci break; 1059bf215546Sopenharmony_ci } 1060bf215546Sopenharmony_ci break; 1061bf215546Sopenharmony_ci default: 1062bf215546Sopenharmony_ci ERROR("unknown shader type %u in assignSlots\n", prog->getType()); 1063bf215546Sopenharmony_ci return false; 1064bf215546Sopenharmony_ci } 1065bf215546Sopenharmony_ci 1066bf215546Sopenharmony_ci for (uint16_t i = 0u; i < slots; ++i, ++vary) { 1067bf215546Sopenharmony_ci nv50_ir_varying *v = &info_out->in[vary]; 1068bf215546Sopenharmony_ci 1069bf215546Sopenharmony_ci v->patch = var->data.patch; 1070bf215546Sopenharmony_ci v->sn = name; 1071bf215546Sopenharmony_ci v->si = index + i; 1072bf215546Sopenharmony_ci v->mask |= getMaskForType(type, i) << var->data.location_frac; 1073bf215546Sopenharmony_ci } 1074bf215546Sopenharmony_ci info_out->numInputs = std::max<uint8_t>(info_out->numInputs, vary); 1075bf215546Sopenharmony_ci } 1076bf215546Sopenharmony_ci 1077bf215546Sopenharmony_ci nir_foreach_shader_out_variable(var, nir) { 1078bf215546Sopenharmony_ci const glsl_type *type = var->type; 1079bf215546Sopenharmony_ci int slot = var->data.location; 1080bf215546Sopenharmony_ci uint16_t slots = calcSlots(type, prog->getType(), nir->info, false, var); 1081bf215546Sopenharmony_ci uint32_t vary = var->data.driver_location; 1082bf215546Sopenharmony_ci 1083bf215546Sopenharmony_ci assert(vary < NV50_CODEGEN_MAX_VARYINGS); 1084bf215546Sopenharmony_ci 1085bf215546Sopenharmony_ci switch(prog->getType()) { 1086bf215546Sopenharmony_ci case Program::TYPE_FRAGMENT: 1087bf215546Sopenharmony_ci tgsi_get_gl_frag_result_semantic((gl_frag_result)slot, &name, &index); 1088bf215546Sopenharmony_ci switch (name) { 1089bf215546Sopenharmony_ci case TGSI_SEMANTIC_COLOR: 1090bf215546Sopenharmony_ci if (!var->data.fb_fetch_output) 1091bf215546Sopenharmony_ci info_out->prop.fp.numColourResults++; 1092bf215546Sopenharmony_ci if (var->data.location == FRAG_RESULT_COLOR && 1093bf215546Sopenharmony_ci nir->info.outputs_written & BITFIELD64_BIT(var->data.location)) 1094bf215546Sopenharmony_ci info_out->prop.fp.separateFragData = true; 1095bf215546Sopenharmony_ci // sometimes we get FRAG_RESULT_DATAX with data.index 0 1096bf215546Sopenharmony_ci // sometimes we get FRAG_RESULT_DATA0 with data.index X 1097bf215546Sopenharmony_ci index = index == 0 ? var->data.index : index; 1098bf215546Sopenharmony_ci break; 1099bf215546Sopenharmony_ci case TGSI_SEMANTIC_POSITION: 1100bf215546Sopenharmony_ci info_out->io.fragDepth = vary; 1101bf215546Sopenharmony_ci info_out->prop.fp.writesDepth = true; 1102bf215546Sopenharmony_ci break; 1103bf215546Sopenharmony_ci case TGSI_SEMANTIC_SAMPLEMASK: 1104bf215546Sopenharmony_ci info_out->io.sampleMask = vary; 1105bf215546Sopenharmony_ci break; 1106bf215546Sopenharmony_ci default: 1107bf215546Sopenharmony_ci break; 1108bf215546Sopenharmony_ci } 1109bf215546Sopenharmony_ci break; 1110bf215546Sopenharmony_ci case Program::TYPE_GEOMETRY: 1111bf215546Sopenharmony_ci case Program::TYPE_TESSELLATION_CONTROL: 1112bf215546Sopenharmony_ci case Program::TYPE_TESSELLATION_EVAL: 1113bf215546Sopenharmony_ci case Program::TYPE_VERTEX: 1114bf215546Sopenharmony_ci tgsi_get_gl_varying_semantic((gl_varying_slot)slot, true, 1115bf215546Sopenharmony_ci &name, &index); 1116bf215546Sopenharmony_ci 1117bf215546Sopenharmony_ci if (var->data.patch && name != TGSI_SEMANTIC_TESSINNER && 1118bf215546Sopenharmony_ci name != TGSI_SEMANTIC_TESSOUTER) 1119bf215546Sopenharmony_ci info_out->numPatchConstants = MAX2(info_out->numPatchConstants, index + slots); 1120bf215546Sopenharmony_ci 1121bf215546Sopenharmony_ci switch (name) { 1122bf215546Sopenharmony_ci case TGSI_SEMANTIC_CLIPDIST: 1123bf215546Sopenharmony_ci info_out->io.genUserClip = -1; 1124bf215546Sopenharmony_ci break; 1125bf215546Sopenharmony_ci case TGSI_SEMANTIC_CLIPVERTEX: 1126bf215546Sopenharmony_ci clipVertexOutput = vary; 1127bf215546Sopenharmony_ci break; 1128bf215546Sopenharmony_ci case TGSI_SEMANTIC_EDGEFLAG: 1129bf215546Sopenharmony_ci info_out->io.edgeFlagOut = vary; 1130bf215546Sopenharmony_ci break; 1131bf215546Sopenharmony_ci case TGSI_SEMANTIC_POSITION: 1132bf215546Sopenharmony_ci if (clipVertexOutput < 0) 1133bf215546Sopenharmony_ci clipVertexOutput = vary; 1134bf215546Sopenharmony_ci break; 1135bf215546Sopenharmony_ci default: 1136bf215546Sopenharmony_ci break; 1137bf215546Sopenharmony_ci } 1138bf215546Sopenharmony_ci break; 1139bf215546Sopenharmony_ci default: 1140bf215546Sopenharmony_ci ERROR("unknown shader type %u in assignSlots\n", prog->getType()); 1141bf215546Sopenharmony_ci return false; 1142bf215546Sopenharmony_ci } 1143bf215546Sopenharmony_ci 1144bf215546Sopenharmony_ci for (uint16_t i = 0u; i < slots; ++i, ++vary) { 1145bf215546Sopenharmony_ci nv50_ir_varying *v = &info_out->out[vary]; 1146bf215546Sopenharmony_ci v->patch = var->data.patch; 1147bf215546Sopenharmony_ci v->sn = name; 1148bf215546Sopenharmony_ci v->si = index + i; 1149bf215546Sopenharmony_ci v->mask |= getMaskForType(type, i) << var->data.location_frac; 1150bf215546Sopenharmony_ci 1151bf215546Sopenharmony_ci if (nir->info.outputs_read & 1ull << slot) 1152bf215546Sopenharmony_ci v->oread = 1; 1153bf215546Sopenharmony_ci } 1154bf215546Sopenharmony_ci info_out->numOutputs = std::max<uint8_t>(info_out->numOutputs, vary); 1155bf215546Sopenharmony_ci } 1156bf215546Sopenharmony_ci 1157bf215546Sopenharmony_ci if (info_out->io.genUserClip > 0) { 1158bf215546Sopenharmony_ci info_out->io.clipDistances = info_out->io.genUserClip; 1159bf215546Sopenharmony_ci 1160bf215546Sopenharmony_ci const unsigned int nOut = (info_out->io.genUserClip + 3) / 4; 1161bf215546Sopenharmony_ci 1162bf215546Sopenharmony_ci for (unsigned int n = 0; n < nOut; ++n) { 1163bf215546Sopenharmony_ci unsigned int i = info_out->numOutputs++; 1164bf215546Sopenharmony_ci info_out->out[i].id = i; 1165bf215546Sopenharmony_ci info_out->out[i].sn = TGSI_SEMANTIC_CLIPDIST; 1166bf215546Sopenharmony_ci info_out->out[i].si = n; 1167bf215546Sopenharmony_ci info_out->out[i].mask = ((1 << info_out->io.clipDistances) - 1) >> (n * 4); 1168bf215546Sopenharmony_ci } 1169bf215546Sopenharmony_ci } 1170bf215546Sopenharmony_ci 1171bf215546Sopenharmony_ci return info->assignSlots(info_out) == 0; 1172bf215546Sopenharmony_ci} 1173bf215546Sopenharmony_ci 1174bf215546Sopenharmony_ciuint32_t 1175bf215546Sopenharmony_ciConverter::getSlotAddress(nir_intrinsic_instr *insn, uint8_t idx, uint8_t slot) 1176bf215546Sopenharmony_ci{ 1177bf215546Sopenharmony_ci DataType ty; 1178bf215546Sopenharmony_ci int offset = nir_intrinsic_component(insn); 1179bf215546Sopenharmony_ci bool input; 1180bf215546Sopenharmony_ci 1181bf215546Sopenharmony_ci if (nir_intrinsic_infos[insn->intrinsic].has_dest) 1182bf215546Sopenharmony_ci ty = getDType(insn); 1183bf215546Sopenharmony_ci else 1184bf215546Sopenharmony_ci ty = getSType(insn->src[0], false, false); 1185bf215546Sopenharmony_ci 1186bf215546Sopenharmony_ci switch (insn->intrinsic) { 1187bf215546Sopenharmony_ci case nir_intrinsic_load_input: 1188bf215546Sopenharmony_ci case nir_intrinsic_load_interpolated_input: 1189bf215546Sopenharmony_ci case nir_intrinsic_load_per_vertex_input: 1190bf215546Sopenharmony_ci input = true; 1191bf215546Sopenharmony_ci break; 1192bf215546Sopenharmony_ci case nir_intrinsic_load_output: 1193bf215546Sopenharmony_ci case nir_intrinsic_load_per_vertex_output: 1194bf215546Sopenharmony_ci case nir_intrinsic_store_output: 1195bf215546Sopenharmony_ci case nir_intrinsic_store_per_vertex_output: 1196bf215546Sopenharmony_ci input = false; 1197bf215546Sopenharmony_ci break; 1198bf215546Sopenharmony_ci default: 1199bf215546Sopenharmony_ci ERROR("unknown intrinsic in getSlotAddress %s", 1200bf215546Sopenharmony_ci nir_intrinsic_infos[insn->intrinsic].name); 1201bf215546Sopenharmony_ci input = false; 1202bf215546Sopenharmony_ci assert(false); 1203bf215546Sopenharmony_ci break; 1204bf215546Sopenharmony_ci } 1205bf215546Sopenharmony_ci 1206bf215546Sopenharmony_ci if (typeSizeof(ty) == 8) { 1207bf215546Sopenharmony_ci slot *= 2; 1208bf215546Sopenharmony_ci slot += offset; 1209bf215546Sopenharmony_ci if (slot >= 4) { 1210bf215546Sopenharmony_ci idx += 1; 1211bf215546Sopenharmony_ci slot -= 4; 1212bf215546Sopenharmony_ci } 1213bf215546Sopenharmony_ci } else { 1214bf215546Sopenharmony_ci slot += offset; 1215bf215546Sopenharmony_ci } 1216bf215546Sopenharmony_ci 1217bf215546Sopenharmony_ci assert(slot < 4); 1218bf215546Sopenharmony_ci assert(!input || idx < NV50_CODEGEN_MAX_VARYINGS); 1219bf215546Sopenharmony_ci assert(input || idx < NV50_CODEGEN_MAX_VARYINGS); 1220bf215546Sopenharmony_ci 1221bf215546Sopenharmony_ci const nv50_ir_varying *vary = input ? info_out->in : info_out->out; 1222bf215546Sopenharmony_ci return vary[idx].slot[slot] * 4; 1223bf215546Sopenharmony_ci} 1224bf215546Sopenharmony_ci 1225bf215546Sopenharmony_ciInstruction * 1226bf215546Sopenharmony_ciConverter::loadFrom(DataFile file, uint8_t i, DataType ty, Value *def, 1227bf215546Sopenharmony_ci uint32_t base, uint8_t c, Value *indirect0, 1228bf215546Sopenharmony_ci Value *indirect1, bool patch) 1229bf215546Sopenharmony_ci{ 1230bf215546Sopenharmony_ci unsigned int tySize = typeSizeof(ty); 1231bf215546Sopenharmony_ci 1232bf215546Sopenharmony_ci if (tySize == 8 && 1233bf215546Sopenharmony_ci (indirect0 || !prog->getTarget()->isAccessSupported(file, TYPE_U64))) { 1234bf215546Sopenharmony_ci Value *lo = getSSA(); 1235bf215546Sopenharmony_ci Value *hi = getSSA(); 1236bf215546Sopenharmony_ci 1237bf215546Sopenharmony_ci Instruction *loi = 1238bf215546Sopenharmony_ci mkLoad(TYPE_U32, lo, 1239bf215546Sopenharmony_ci mkSymbol(file, i, TYPE_U32, base + c * tySize), 1240bf215546Sopenharmony_ci indirect0); 1241bf215546Sopenharmony_ci loi->setIndirect(0, 1, indirect1); 1242bf215546Sopenharmony_ci loi->perPatch = patch; 1243bf215546Sopenharmony_ci 1244bf215546Sopenharmony_ci Instruction *hii = 1245bf215546Sopenharmony_ci mkLoad(TYPE_U32, hi, 1246bf215546Sopenharmony_ci mkSymbol(file, i, TYPE_U32, base + c * tySize + 4), 1247bf215546Sopenharmony_ci indirect0); 1248bf215546Sopenharmony_ci hii->setIndirect(0, 1, indirect1); 1249bf215546Sopenharmony_ci hii->perPatch = patch; 1250bf215546Sopenharmony_ci 1251bf215546Sopenharmony_ci return mkOp2(OP_MERGE, ty, def, lo, hi); 1252bf215546Sopenharmony_ci } else { 1253bf215546Sopenharmony_ci Instruction *ld = 1254bf215546Sopenharmony_ci mkLoad(ty, def, mkSymbol(file, i, ty, base + c * tySize), indirect0); 1255bf215546Sopenharmony_ci ld->setIndirect(0, 1, indirect1); 1256bf215546Sopenharmony_ci ld->perPatch = patch; 1257bf215546Sopenharmony_ci return ld; 1258bf215546Sopenharmony_ci } 1259bf215546Sopenharmony_ci} 1260bf215546Sopenharmony_ci 1261bf215546Sopenharmony_civoid 1262bf215546Sopenharmony_ciConverter::storeTo(nir_intrinsic_instr *insn, DataFile file, operation op, 1263bf215546Sopenharmony_ci DataType ty, Value *src, uint8_t idx, uint8_t c, 1264bf215546Sopenharmony_ci Value *indirect0, Value *indirect1) 1265bf215546Sopenharmony_ci{ 1266bf215546Sopenharmony_ci uint8_t size = typeSizeof(ty); 1267bf215546Sopenharmony_ci uint32_t address = getSlotAddress(insn, idx, c); 1268bf215546Sopenharmony_ci 1269bf215546Sopenharmony_ci if (size == 8 && indirect0) { 1270bf215546Sopenharmony_ci Value *split[2]; 1271bf215546Sopenharmony_ci mkSplit(split, 4, src); 1272bf215546Sopenharmony_ci 1273bf215546Sopenharmony_ci if (op == OP_EXPORT) { 1274bf215546Sopenharmony_ci split[0] = mkMov(getSSA(), split[0], ty)->getDef(0); 1275bf215546Sopenharmony_ci split[1] = mkMov(getSSA(), split[1], ty)->getDef(0); 1276bf215546Sopenharmony_ci } 1277bf215546Sopenharmony_ci 1278bf215546Sopenharmony_ci mkStore(op, TYPE_U32, mkSymbol(file, 0, TYPE_U32, address), indirect0, 1279bf215546Sopenharmony_ci split[0])->perPatch = info_out->out[idx].patch; 1280bf215546Sopenharmony_ci mkStore(op, TYPE_U32, mkSymbol(file, 0, TYPE_U32, address + 4), indirect0, 1281bf215546Sopenharmony_ci split[1])->perPatch = info_out->out[idx].patch; 1282bf215546Sopenharmony_ci } else { 1283bf215546Sopenharmony_ci if (op == OP_EXPORT) 1284bf215546Sopenharmony_ci src = mkMov(getSSA(size), src, ty)->getDef(0); 1285bf215546Sopenharmony_ci mkStore(op, ty, mkSymbol(file, 0, ty, address), indirect0, 1286bf215546Sopenharmony_ci src)->perPatch = info_out->out[idx].patch; 1287bf215546Sopenharmony_ci } 1288bf215546Sopenharmony_ci} 1289bf215546Sopenharmony_ci 1290bf215546Sopenharmony_cibool 1291bf215546Sopenharmony_ciConverter::parseNIR() 1292bf215546Sopenharmony_ci{ 1293bf215546Sopenharmony_ci info_out->bin.tlsSpace = nir->scratch_size; 1294bf215546Sopenharmony_ci info_out->io.clipDistances = nir->info.clip_distance_array_size; 1295bf215546Sopenharmony_ci info_out->io.cullDistances = nir->info.cull_distance_array_size; 1296bf215546Sopenharmony_ci info_out->io.layer_viewport_relative = nir->info.layer_viewport_relative; 1297bf215546Sopenharmony_ci 1298bf215546Sopenharmony_ci switch(prog->getType()) { 1299bf215546Sopenharmony_ci case Program::TYPE_COMPUTE: 1300bf215546Sopenharmony_ci info->prop.cp.numThreads[0] = nir->info.workgroup_size[0]; 1301bf215546Sopenharmony_ci info->prop.cp.numThreads[1] = nir->info.workgroup_size[1]; 1302bf215546Sopenharmony_ci info->prop.cp.numThreads[2] = nir->info.workgroup_size[2]; 1303bf215546Sopenharmony_ci info_out->bin.smemSize = std::max(info_out->bin.smemSize, nir->info.shared_size); 1304bf215546Sopenharmony_ci 1305bf215546Sopenharmony_ci if (info->target < NVISA_GF100_CHIPSET) { 1306bf215546Sopenharmony_ci int gmemSlot = 0; 1307bf215546Sopenharmony_ci 1308bf215546Sopenharmony_ci for (unsigned i = 0; i < nir->info.num_ssbos; i++) { 1309bf215546Sopenharmony_ci info_out->prop.cp.gmem[gmemSlot++] = {.valid = 1, .image = 0, .slot = i}; 1310bf215546Sopenharmony_ci assert(gmemSlot < 16); 1311bf215546Sopenharmony_ci } 1312bf215546Sopenharmony_ci nir_foreach_image_variable(var, nir) { 1313bf215546Sopenharmony_ci int image_count = glsl_type_get_image_count(var->type); 1314bf215546Sopenharmony_ci for (int i = 0; i < image_count; i++) { 1315bf215546Sopenharmony_ci info_out->prop.cp.gmem[gmemSlot++] = {.valid = 1, .image = 1, .slot = var->data.binding + i}; 1316bf215546Sopenharmony_ci assert(gmemSlot < 16); 1317bf215546Sopenharmony_ci } 1318bf215546Sopenharmony_ci } 1319bf215546Sopenharmony_ci } 1320bf215546Sopenharmony_ci 1321bf215546Sopenharmony_ci break; 1322bf215546Sopenharmony_ci case Program::TYPE_FRAGMENT: 1323bf215546Sopenharmony_ci info_out->prop.fp.earlyFragTests = nir->info.fs.early_fragment_tests; 1324bf215546Sopenharmony_ci prog->persampleInvocation = 1325bf215546Sopenharmony_ci BITSET_TEST(nir->info.system_values_read, SYSTEM_VALUE_SAMPLE_ID) || 1326bf215546Sopenharmony_ci BITSET_TEST(nir->info.system_values_read, SYSTEM_VALUE_SAMPLE_POS); 1327bf215546Sopenharmony_ci info_out->prop.fp.postDepthCoverage = nir->info.fs.post_depth_coverage; 1328bf215546Sopenharmony_ci info_out->prop.fp.readsSampleLocations = 1329bf215546Sopenharmony_ci BITSET_TEST(nir->info.system_values_read, SYSTEM_VALUE_SAMPLE_POS); 1330bf215546Sopenharmony_ci info_out->prop.fp.usesDiscard = nir->info.fs.uses_discard || nir->info.fs.uses_demote; 1331bf215546Sopenharmony_ci info_out->prop.fp.usesSampleMaskIn = 1332bf215546Sopenharmony_ci BITSET_TEST(nir->info.system_values_read, SYSTEM_VALUE_SAMPLE_MASK_IN); 1333bf215546Sopenharmony_ci break; 1334bf215546Sopenharmony_ci case Program::TYPE_GEOMETRY: 1335bf215546Sopenharmony_ci info_out->prop.gp.instanceCount = nir->info.gs.invocations; 1336bf215546Sopenharmony_ci info_out->prop.gp.maxVertices = nir->info.gs.vertices_out; 1337bf215546Sopenharmony_ci info_out->prop.gp.outputPrim = nir->info.gs.output_primitive; 1338bf215546Sopenharmony_ci break; 1339bf215546Sopenharmony_ci case Program::TYPE_TESSELLATION_CONTROL: 1340bf215546Sopenharmony_ci case Program::TYPE_TESSELLATION_EVAL: 1341bf215546Sopenharmony_ci info_out->prop.tp.domain = u_tess_prim_from_shader(nir->info.tess._primitive_mode); 1342bf215546Sopenharmony_ci info_out->prop.tp.outputPatchSize = nir->info.tess.tcs_vertices_out; 1343bf215546Sopenharmony_ci info_out->prop.tp.outputPrim = 1344bf215546Sopenharmony_ci nir->info.tess.point_mode ? PIPE_PRIM_POINTS : PIPE_PRIM_TRIANGLES; 1345bf215546Sopenharmony_ci info_out->prop.tp.partitioning = (nir->info.tess.spacing + 1) % 3; 1346bf215546Sopenharmony_ci info_out->prop.tp.winding = !nir->info.tess.ccw; 1347bf215546Sopenharmony_ci break; 1348bf215546Sopenharmony_ci case Program::TYPE_VERTEX: 1349bf215546Sopenharmony_ci info_out->prop.vp.usesDrawParameters = 1350bf215546Sopenharmony_ci BITSET_TEST(nir->info.system_values_read, SYSTEM_VALUE_BASE_VERTEX) || 1351bf215546Sopenharmony_ci BITSET_TEST(nir->info.system_values_read, SYSTEM_VALUE_BASE_INSTANCE) || 1352bf215546Sopenharmony_ci BITSET_TEST(nir->info.system_values_read, SYSTEM_VALUE_DRAW_ID); 1353bf215546Sopenharmony_ci break; 1354bf215546Sopenharmony_ci default: 1355bf215546Sopenharmony_ci break; 1356bf215546Sopenharmony_ci } 1357bf215546Sopenharmony_ci 1358bf215546Sopenharmony_ci return true; 1359bf215546Sopenharmony_ci} 1360bf215546Sopenharmony_ci 1361bf215546Sopenharmony_cibool 1362bf215546Sopenharmony_ciConverter::visit(nir_function *function) 1363bf215546Sopenharmony_ci{ 1364bf215546Sopenharmony_ci assert(function->impl); 1365bf215546Sopenharmony_ci 1366bf215546Sopenharmony_ci // usually the blocks will set everything up, but main is special 1367bf215546Sopenharmony_ci BasicBlock *entry = new BasicBlock(prog->main); 1368bf215546Sopenharmony_ci exit = new BasicBlock(prog->main); 1369bf215546Sopenharmony_ci blocks[nir_start_block(function->impl)->index] = entry; 1370bf215546Sopenharmony_ci prog->main->setEntry(entry); 1371bf215546Sopenharmony_ci prog->main->setExit(exit); 1372bf215546Sopenharmony_ci 1373bf215546Sopenharmony_ci setPosition(entry, true); 1374bf215546Sopenharmony_ci 1375bf215546Sopenharmony_ci if (info_out->io.genUserClip > 0) { 1376bf215546Sopenharmony_ci for (int c = 0; c < 4; ++c) 1377bf215546Sopenharmony_ci clipVtx[c] = getScratch(); 1378bf215546Sopenharmony_ci } 1379bf215546Sopenharmony_ci 1380bf215546Sopenharmony_ci switch (prog->getType()) { 1381bf215546Sopenharmony_ci case Program::TYPE_TESSELLATION_CONTROL: 1382bf215546Sopenharmony_ci outBase = mkOp2v( 1383bf215546Sopenharmony_ci OP_SUB, TYPE_U32, getSSA(), 1384bf215546Sopenharmony_ci mkOp1v(OP_RDSV, TYPE_U32, getSSA(), mkSysVal(SV_LANEID, 0)), 1385bf215546Sopenharmony_ci mkOp1v(OP_RDSV, TYPE_U32, getSSA(), mkSysVal(SV_INVOCATION_ID, 0))); 1386bf215546Sopenharmony_ci break; 1387bf215546Sopenharmony_ci case Program::TYPE_FRAGMENT: { 1388bf215546Sopenharmony_ci Symbol *sv = mkSysVal(SV_POSITION, 3); 1389bf215546Sopenharmony_ci fragCoord[3] = mkOp1v(OP_RDSV, TYPE_F32, getSSA(), sv); 1390bf215546Sopenharmony_ci fp.position = mkOp1v(OP_RCP, TYPE_F32, fragCoord[3], fragCoord[3]); 1391bf215546Sopenharmony_ci break; 1392bf215546Sopenharmony_ci } 1393bf215546Sopenharmony_ci default: 1394bf215546Sopenharmony_ci break; 1395bf215546Sopenharmony_ci } 1396bf215546Sopenharmony_ci 1397bf215546Sopenharmony_ci nir_index_ssa_defs(function->impl); 1398bf215546Sopenharmony_ci foreach_list_typed(nir_cf_node, node, node, &function->impl->body) { 1399bf215546Sopenharmony_ci if (!visit(node)) 1400bf215546Sopenharmony_ci return false; 1401bf215546Sopenharmony_ci } 1402bf215546Sopenharmony_ci 1403bf215546Sopenharmony_ci bb->cfg.attach(&exit->cfg, Graph::Edge::TREE); 1404bf215546Sopenharmony_ci setPosition(exit, true); 1405bf215546Sopenharmony_ci 1406bf215546Sopenharmony_ci if ((prog->getType() == Program::TYPE_VERTEX || 1407bf215546Sopenharmony_ci prog->getType() == Program::TYPE_TESSELLATION_EVAL) 1408bf215546Sopenharmony_ci && info_out->io.genUserClip > 0) 1409bf215546Sopenharmony_ci handleUserClipPlanes(); 1410bf215546Sopenharmony_ci 1411bf215546Sopenharmony_ci // TODO: for non main function this needs to be a OP_RETURN 1412bf215546Sopenharmony_ci mkOp(OP_EXIT, TYPE_NONE, NULL)->terminator = 1; 1413bf215546Sopenharmony_ci return true; 1414bf215546Sopenharmony_ci} 1415bf215546Sopenharmony_ci 1416bf215546Sopenharmony_cibool 1417bf215546Sopenharmony_ciConverter::visit(nir_cf_node *node) 1418bf215546Sopenharmony_ci{ 1419bf215546Sopenharmony_ci switch (node->type) { 1420bf215546Sopenharmony_ci case nir_cf_node_block: 1421bf215546Sopenharmony_ci return visit(nir_cf_node_as_block(node)); 1422bf215546Sopenharmony_ci case nir_cf_node_if: 1423bf215546Sopenharmony_ci return visit(nir_cf_node_as_if(node)); 1424bf215546Sopenharmony_ci case nir_cf_node_loop: 1425bf215546Sopenharmony_ci return visit(nir_cf_node_as_loop(node)); 1426bf215546Sopenharmony_ci default: 1427bf215546Sopenharmony_ci ERROR("unknown nir_cf_node type %u\n", node->type); 1428bf215546Sopenharmony_ci return false; 1429bf215546Sopenharmony_ci } 1430bf215546Sopenharmony_ci} 1431bf215546Sopenharmony_ci 1432bf215546Sopenharmony_cibool 1433bf215546Sopenharmony_ciConverter::visit(nir_block *block) 1434bf215546Sopenharmony_ci{ 1435bf215546Sopenharmony_ci if (!block->predecessors->entries && block->instr_list.is_empty()) 1436bf215546Sopenharmony_ci return true; 1437bf215546Sopenharmony_ci 1438bf215546Sopenharmony_ci BasicBlock *bb = convert(block); 1439bf215546Sopenharmony_ci 1440bf215546Sopenharmony_ci setPosition(bb, true); 1441bf215546Sopenharmony_ci nir_foreach_instr(insn, block) { 1442bf215546Sopenharmony_ci if (!visit(insn)) 1443bf215546Sopenharmony_ci return false; 1444bf215546Sopenharmony_ci } 1445bf215546Sopenharmony_ci return true; 1446bf215546Sopenharmony_ci} 1447bf215546Sopenharmony_ci 1448bf215546Sopenharmony_cibool 1449bf215546Sopenharmony_ciConverter::visit(nir_if *nif) 1450bf215546Sopenharmony_ci{ 1451bf215546Sopenharmony_ci curIfDepth++; 1452bf215546Sopenharmony_ci 1453bf215546Sopenharmony_ci DataType sType = getSType(nif->condition, false, false); 1454bf215546Sopenharmony_ci Value *src = getSrc(&nif->condition, 0); 1455bf215546Sopenharmony_ci 1456bf215546Sopenharmony_ci nir_block *lastThen = nir_if_last_then_block(nif); 1457bf215546Sopenharmony_ci nir_block *lastElse = nir_if_last_else_block(nif); 1458bf215546Sopenharmony_ci 1459bf215546Sopenharmony_ci BasicBlock *headBB = bb; 1460bf215546Sopenharmony_ci BasicBlock *ifBB = convert(nir_if_first_then_block(nif)); 1461bf215546Sopenharmony_ci BasicBlock *elseBB = convert(nir_if_first_else_block(nif)); 1462bf215546Sopenharmony_ci 1463bf215546Sopenharmony_ci bb->cfg.attach(&ifBB->cfg, Graph::Edge::TREE); 1464bf215546Sopenharmony_ci bb->cfg.attach(&elseBB->cfg, Graph::Edge::TREE); 1465bf215546Sopenharmony_ci 1466bf215546Sopenharmony_ci bool insertJoins = lastThen->successors[0] == lastElse->successors[0]; 1467bf215546Sopenharmony_ci mkFlow(OP_BRA, elseBB, CC_EQ, src)->setType(sType); 1468bf215546Sopenharmony_ci 1469bf215546Sopenharmony_ci foreach_list_typed(nir_cf_node, node, node, &nif->then_list) { 1470bf215546Sopenharmony_ci if (!visit(node)) 1471bf215546Sopenharmony_ci return false; 1472bf215546Sopenharmony_ci } 1473bf215546Sopenharmony_ci 1474bf215546Sopenharmony_ci setPosition(convert(lastThen), true); 1475bf215546Sopenharmony_ci if (!bb->isTerminated()) { 1476bf215546Sopenharmony_ci BasicBlock *tailBB = convert(lastThen->successors[0]); 1477bf215546Sopenharmony_ci mkFlow(OP_BRA, tailBB, CC_ALWAYS, NULL); 1478bf215546Sopenharmony_ci bb->cfg.attach(&tailBB->cfg, Graph::Edge::FORWARD); 1479bf215546Sopenharmony_ci } else { 1480bf215546Sopenharmony_ci insertJoins = insertJoins && bb->getExit()->op == OP_BRA; 1481bf215546Sopenharmony_ci } 1482bf215546Sopenharmony_ci 1483bf215546Sopenharmony_ci foreach_list_typed(nir_cf_node, node, node, &nif->else_list) { 1484bf215546Sopenharmony_ci if (!visit(node)) 1485bf215546Sopenharmony_ci return false; 1486bf215546Sopenharmony_ci } 1487bf215546Sopenharmony_ci 1488bf215546Sopenharmony_ci setPosition(convert(lastElse), true); 1489bf215546Sopenharmony_ci if (!bb->isTerminated()) { 1490bf215546Sopenharmony_ci BasicBlock *tailBB = convert(lastElse->successors[0]); 1491bf215546Sopenharmony_ci mkFlow(OP_BRA, tailBB, CC_ALWAYS, NULL); 1492bf215546Sopenharmony_ci bb->cfg.attach(&tailBB->cfg, Graph::Edge::FORWARD); 1493bf215546Sopenharmony_ci } else { 1494bf215546Sopenharmony_ci insertJoins = insertJoins && bb->getExit()->op == OP_BRA; 1495bf215546Sopenharmony_ci } 1496bf215546Sopenharmony_ci 1497bf215546Sopenharmony_ci if (curIfDepth > 6) { 1498bf215546Sopenharmony_ci insertJoins = false; 1499bf215546Sopenharmony_ci } 1500bf215546Sopenharmony_ci 1501bf215546Sopenharmony_ci /* we made sure that all threads would converge at the same block */ 1502bf215546Sopenharmony_ci if (insertJoins) { 1503bf215546Sopenharmony_ci BasicBlock *conv = convert(lastThen->successors[0]); 1504bf215546Sopenharmony_ci setPosition(headBB->getExit(), false); 1505bf215546Sopenharmony_ci headBB->joinAt = mkFlow(OP_JOINAT, conv, CC_ALWAYS, NULL); 1506bf215546Sopenharmony_ci setPosition(conv, false); 1507bf215546Sopenharmony_ci mkFlow(OP_JOIN, NULL, CC_ALWAYS, NULL)->fixed = 1; 1508bf215546Sopenharmony_ci } 1509bf215546Sopenharmony_ci 1510bf215546Sopenharmony_ci curIfDepth--; 1511bf215546Sopenharmony_ci 1512bf215546Sopenharmony_ci return true; 1513bf215546Sopenharmony_ci} 1514bf215546Sopenharmony_ci 1515bf215546Sopenharmony_ci// TODO: add convergency 1516bf215546Sopenharmony_cibool 1517bf215546Sopenharmony_ciConverter::visit(nir_loop *loop) 1518bf215546Sopenharmony_ci{ 1519bf215546Sopenharmony_ci curLoopDepth += 1; 1520bf215546Sopenharmony_ci func->loopNestingBound = std::max(func->loopNestingBound, curLoopDepth); 1521bf215546Sopenharmony_ci 1522bf215546Sopenharmony_ci BasicBlock *loopBB = convert(nir_loop_first_block(loop)); 1523bf215546Sopenharmony_ci BasicBlock *tailBB = convert(nir_cf_node_as_block(nir_cf_node_next(&loop->cf_node))); 1524bf215546Sopenharmony_ci 1525bf215546Sopenharmony_ci bb->cfg.attach(&loopBB->cfg, Graph::Edge::TREE); 1526bf215546Sopenharmony_ci 1527bf215546Sopenharmony_ci mkFlow(OP_PREBREAK, tailBB, CC_ALWAYS, NULL); 1528bf215546Sopenharmony_ci setPosition(loopBB, false); 1529bf215546Sopenharmony_ci mkFlow(OP_PRECONT, loopBB, CC_ALWAYS, NULL); 1530bf215546Sopenharmony_ci 1531bf215546Sopenharmony_ci foreach_list_typed(nir_cf_node, node, node, &loop->body) { 1532bf215546Sopenharmony_ci if (!visit(node)) 1533bf215546Sopenharmony_ci return false; 1534bf215546Sopenharmony_ci } 1535bf215546Sopenharmony_ci 1536bf215546Sopenharmony_ci if (!bb->isTerminated()) { 1537bf215546Sopenharmony_ci mkFlow(OP_CONT, loopBB, CC_ALWAYS, NULL); 1538bf215546Sopenharmony_ci bb->cfg.attach(&loopBB->cfg, Graph::Edge::BACK); 1539bf215546Sopenharmony_ci } 1540bf215546Sopenharmony_ci 1541bf215546Sopenharmony_ci if (tailBB->cfg.incidentCount() == 0) 1542bf215546Sopenharmony_ci loopBB->cfg.attach(&tailBB->cfg, Graph::Edge::TREE); 1543bf215546Sopenharmony_ci 1544bf215546Sopenharmony_ci curLoopDepth -= 1; 1545bf215546Sopenharmony_ci 1546bf215546Sopenharmony_ci info_out->loops++; 1547bf215546Sopenharmony_ci 1548bf215546Sopenharmony_ci return true; 1549bf215546Sopenharmony_ci} 1550bf215546Sopenharmony_ci 1551bf215546Sopenharmony_cibool 1552bf215546Sopenharmony_ciConverter::visit(nir_instr *insn) 1553bf215546Sopenharmony_ci{ 1554bf215546Sopenharmony_ci // we need an insertion point for on the fly generated immediate loads 1555bf215546Sopenharmony_ci immInsertPos = bb->getExit(); 1556bf215546Sopenharmony_ci switch (insn->type) { 1557bf215546Sopenharmony_ci case nir_instr_type_alu: 1558bf215546Sopenharmony_ci return visit(nir_instr_as_alu(insn)); 1559bf215546Sopenharmony_ci case nir_instr_type_intrinsic: 1560bf215546Sopenharmony_ci return visit(nir_instr_as_intrinsic(insn)); 1561bf215546Sopenharmony_ci case nir_instr_type_jump: 1562bf215546Sopenharmony_ci return visit(nir_instr_as_jump(insn)); 1563bf215546Sopenharmony_ci case nir_instr_type_load_const: 1564bf215546Sopenharmony_ci return visit(nir_instr_as_load_const(insn)); 1565bf215546Sopenharmony_ci case nir_instr_type_ssa_undef: 1566bf215546Sopenharmony_ci return visit(nir_instr_as_ssa_undef(insn)); 1567bf215546Sopenharmony_ci case nir_instr_type_tex: 1568bf215546Sopenharmony_ci return visit(nir_instr_as_tex(insn)); 1569bf215546Sopenharmony_ci default: 1570bf215546Sopenharmony_ci ERROR("unknown nir_instr type %u\n", insn->type); 1571bf215546Sopenharmony_ci return false; 1572bf215546Sopenharmony_ci } 1573bf215546Sopenharmony_ci return true; 1574bf215546Sopenharmony_ci} 1575bf215546Sopenharmony_ci 1576bf215546Sopenharmony_ciSVSemantic 1577bf215546Sopenharmony_ciConverter::convert(nir_intrinsic_op intr) 1578bf215546Sopenharmony_ci{ 1579bf215546Sopenharmony_ci switch (intr) { 1580bf215546Sopenharmony_ci case nir_intrinsic_load_base_vertex: 1581bf215546Sopenharmony_ci return SV_BASEVERTEX; 1582bf215546Sopenharmony_ci case nir_intrinsic_load_base_instance: 1583bf215546Sopenharmony_ci return SV_BASEINSTANCE; 1584bf215546Sopenharmony_ci case nir_intrinsic_load_draw_id: 1585bf215546Sopenharmony_ci return SV_DRAWID; 1586bf215546Sopenharmony_ci case nir_intrinsic_load_front_face: 1587bf215546Sopenharmony_ci return SV_FACE; 1588bf215546Sopenharmony_ci case nir_intrinsic_is_helper_invocation: 1589bf215546Sopenharmony_ci case nir_intrinsic_load_helper_invocation: 1590bf215546Sopenharmony_ci return SV_THREAD_KILL; 1591bf215546Sopenharmony_ci case nir_intrinsic_load_instance_id: 1592bf215546Sopenharmony_ci return SV_INSTANCE_ID; 1593bf215546Sopenharmony_ci case nir_intrinsic_load_invocation_id: 1594bf215546Sopenharmony_ci return SV_INVOCATION_ID; 1595bf215546Sopenharmony_ci case nir_intrinsic_load_workgroup_size: 1596bf215546Sopenharmony_ci return SV_NTID; 1597bf215546Sopenharmony_ci case nir_intrinsic_load_local_invocation_id: 1598bf215546Sopenharmony_ci return SV_TID; 1599bf215546Sopenharmony_ci case nir_intrinsic_load_num_workgroups: 1600bf215546Sopenharmony_ci return SV_NCTAID; 1601bf215546Sopenharmony_ci case nir_intrinsic_load_patch_vertices_in: 1602bf215546Sopenharmony_ci return SV_VERTEX_COUNT; 1603bf215546Sopenharmony_ci case nir_intrinsic_load_primitive_id: 1604bf215546Sopenharmony_ci return SV_PRIMITIVE_ID; 1605bf215546Sopenharmony_ci case nir_intrinsic_load_sample_id: 1606bf215546Sopenharmony_ci return SV_SAMPLE_INDEX; 1607bf215546Sopenharmony_ci case nir_intrinsic_load_sample_mask_in: 1608bf215546Sopenharmony_ci return SV_SAMPLE_MASK; 1609bf215546Sopenharmony_ci case nir_intrinsic_load_sample_pos: 1610bf215546Sopenharmony_ci return SV_SAMPLE_POS; 1611bf215546Sopenharmony_ci case nir_intrinsic_load_subgroup_eq_mask: 1612bf215546Sopenharmony_ci return SV_LANEMASK_EQ; 1613bf215546Sopenharmony_ci case nir_intrinsic_load_subgroup_ge_mask: 1614bf215546Sopenharmony_ci return SV_LANEMASK_GE; 1615bf215546Sopenharmony_ci case nir_intrinsic_load_subgroup_gt_mask: 1616bf215546Sopenharmony_ci return SV_LANEMASK_GT; 1617bf215546Sopenharmony_ci case nir_intrinsic_load_subgroup_le_mask: 1618bf215546Sopenharmony_ci return SV_LANEMASK_LE; 1619bf215546Sopenharmony_ci case nir_intrinsic_load_subgroup_lt_mask: 1620bf215546Sopenharmony_ci return SV_LANEMASK_LT; 1621bf215546Sopenharmony_ci case nir_intrinsic_load_subgroup_invocation: 1622bf215546Sopenharmony_ci return SV_LANEID; 1623bf215546Sopenharmony_ci case nir_intrinsic_load_tess_coord: 1624bf215546Sopenharmony_ci return SV_TESS_COORD; 1625bf215546Sopenharmony_ci case nir_intrinsic_load_tess_level_inner: 1626bf215546Sopenharmony_ci return SV_TESS_INNER; 1627bf215546Sopenharmony_ci case nir_intrinsic_load_tess_level_outer: 1628bf215546Sopenharmony_ci return SV_TESS_OUTER; 1629bf215546Sopenharmony_ci case nir_intrinsic_load_vertex_id: 1630bf215546Sopenharmony_ci return SV_VERTEX_ID; 1631bf215546Sopenharmony_ci case nir_intrinsic_load_workgroup_id: 1632bf215546Sopenharmony_ci return SV_CTAID; 1633bf215546Sopenharmony_ci case nir_intrinsic_load_work_dim: 1634bf215546Sopenharmony_ci return SV_WORK_DIM; 1635bf215546Sopenharmony_ci default: 1636bf215546Sopenharmony_ci ERROR("unknown SVSemantic for nir_intrinsic_op %s\n", 1637bf215546Sopenharmony_ci nir_intrinsic_infos[intr].name); 1638bf215546Sopenharmony_ci assert(false); 1639bf215546Sopenharmony_ci return SV_LAST; 1640bf215546Sopenharmony_ci } 1641bf215546Sopenharmony_ci} 1642bf215546Sopenharmony_ci 1643bf215546Sopenharmony_cibool 1644bf215546Sopenharmony_ciConverter::visit(nir_intrinsic_instr *insn) 1645bf215546Sopenharmony_ci{ 1646bf215546Sopenharmony_ci nir_intrinsic_op op = insn->intrinsic; 1647bf215546Sopenharmony_ci const nir_intrinsic_info &opInfo = nir_intrinsic_infos[op]; 1648bf215546Sopenharmony_ci unsigned dest_components = nir_intrinsic_dest_components(insn); 1649bf215546Sopenharmony_ci 1650bf215546Sopenharmony_ci switch (op) { 1651bf215546Sopenharmony_ci case nir_intrinsic_load_uniform: { 1652bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 1653bf215546Sopenharmony_ci const DataType dType = getDType(insn); 1654bf215546Sopenharmony_ci Value *indirect; 1655bf215546Sopenharmony_ci uint32_t coffset = getIndirect(insn, 0, 0, indirect); 1656bf215546Sopenharmony_ci for (uint8_t i = 0; i < dest_components; ++i) { 1657bf215546Sopenharmony_ci loadFrom(FILE_MEMORY_CONST, 0, dType, newDefs[i], 16 * coffset, i, indirect); 1658bf215546Sopenharmony_ci } 1659bf215546Sopenharmony_ci break; 1660bf215546Sopenharmony_ci } 1661bf215546Sopenharmony_ci case nir_intrinsic_store_output: 1662bf215546Sopenharmony_ci case nir_intrinsic_store_per_vertex_output: { 1663bf215546Sopenharmony_ci Value *indirect; 1664bf215546Sopenharmony_ci DataType dType = getSType(insn->src[0], false, false); 1665bf215546Sopenharmony_ci uint32_t idx = getIndirect(insn, op == nir_intrinsic_store_output ? 1 : 2, 0, indirect); 1666bf215546Sopenharmony_ci 1667bf215546Sopenharmony_ci for (uint8_t i = 0u; i < nir_intrinsic_src_components(insn, 0); ++i) { 1668bf215546Sopenharmony_ci if (!((1u << i) & nir_intrinsic_write_mask(insn))) 1669bf215546Sopenharmony_ci continue; 1670bf215546Sopenharmony_ci 1671bf215546Sopenharmony_ci uint8_t offset = 0; 1672bf215546Sopenharmony_ci Value *src = getSrc(&insn->src[0], i); 1673bf215546Sopenharmony_ci switch (prog->getType()) { 1674bf215546Sopenharmony_ci case Program::TYPE_FRAGMENT: { 1675bf215546Sopenharmony_ci if (info_out->out[idx].sn == TGSI_SEMANTIC_POSITION) { 1676bf215546Sopenharmony_ci // TGSI uses a different interface than NIR, TGSI stores that 1677bf215546Sopenharmony_ci // value in the z component, NIR in X 1678bf215546Sopenharmony_ci offset += 2; 1679bf215546Sopenharmony_ci src = mkOp1v(OP_SAT, TYPE_F32, getScratch(), src); 1680bf215546Sopenharmony_ci } 1681bf215546Sopenharmony_ci break; 1682bf215546Sopenharmony_ci } 1683bf215546Sopenharmony_ci case Program::TYPE_GEOMETRY: 1684bf215546Sopenharmony_ci case Program::TYPE_TESSELLATION_EVAL: 1685bf215546Sopenharmony_ci case Program::TYPE_VERTEX: { 1686bf215546Sopenharmony_ci if (info_out->io.genUserClip > 0 && idx == (uint32_t)clipVertexOutput) { 1687bf215546Sopenharmony_ci mkMov(clipVtx[i], src); 1688bf215546Sopenharmony_ci src = clipVtx[i]; 1689bf215546Sopenharmony_ci } 1690bf215546Sopenharmony_ci break; 1691bf215546Sopenharmony_ci } 1692bf215546Sopenharmony_ci default: 1693bf215546Sopenharmony_ci break; 1694bf215546Sopenharmony_ci } 1695bf215546Sopenharmony_ci 1696bf215546Sopenharmony_ci storeTo(insn, FILE_SHADER_OUTPUT, OP_EXPORT, dType, src, idx, i + offset, indirect); 1697bf215546Sopenharmony_ci } 1698bf215546Sopenharmony_ci break; 1699bf215546Sopenharmony_ci } 1700bf215546Sopenharmony_ci case nir_intrinsic_load_input: 1701bf215546Sopenharmony_ci case nir_intrinsic_load_interpolated_input: 1702bf215546Sopenharmony_ci case nir_intrinsic_load_output: { 1703bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 1704bf215546Sopenharmony_ci 1705bf215546Sopenharmony_ci // FBFetch 1706bf215546Sopenharmony_ci if (prog->getType() == Program::TYPE_FRAGMENT && 1707bf215546Sopenharmony_ci op == nir_intrinsic_load_output) { 1708bf215546Sopenharmony_ci std::vector<Value*> defs, srcs; 1709bf215546Sopenharmony_ci uint8_t mask = 0; 1710bf215546Sopenharmony_ci 1711bf215546Sopenharmony_ci srcs.push_back(getSSA()); 1712bf215546Sopenharmony_ci srcs.push_back(getSSA()); 1713bf215546Sopenharmony_ci Value *x = mkOp1v(OP_RDSV, TYPE_F32, getSSA(), mkSysVal(SV_POSITION, 0)); 1714bf215546Sopenharmony_ci Value *y = mkOp1v(OP_RDSV, TYPE_F32, getSSA(), mkSysVal(SV_POSITION, 1)); 1715bf215546Sopenharmony_ci mkCvt(OP_CVT, TYPE_U32, srcs[0], TYPE_F32, x)->rnd = ROUND_Z; 1716bf215546Sopenharmony_ci mkCvt(OP_CVT, TYPE_U32, srcs[1], TYPE_F32, y)->rnd = ROUND_Z; 1717bf215546Sopenharmony_ci 1718bf215546Sopenharmony_ci srcs.push_back(mkOp1v(OP_RDSV, TYPE_U32, getSSA(), mkSysVal(SV_LAYER, 0))); 1719bf215546Sopenharmony_ci srcs.push_back(mkOp1v(OP_RDSV, TYPE_U32, getSSA(), mkSysVal(SV_SAMPLE_INDEX, 0))); 1720bf215546Sopenharmony_ci 1721bf215546Sopenharmony_ci for (uint8_t i = 0u; i < dest_components; ++i) { 1722bf215546Sopenharmony_ci defs.push_back(newDefs[i]); 1723bf215546Sopenharmony_ci mask |= 1 << i; 1724bf215546Sopenharmony_ci } 1725bf215546Sopenharmony_ci 1726bf215546Sopenharmony_ci TexInstruction *texi = mkTex(OP_TXF, TEX_TARGET_2D_MS_ARRAY, 0, 0, defs, srcs); 1727bf215546Sopenharmony_ci texi->tex.levelZero = true; 1728bf215546Sopenharmony_ci texi->tex.mask = mask; 1729bf215546Sopenharmony_ci texi->tex.useOffsets = 0; 1730bf215546Sopenharmony_ci texi->tex.r = 0xffff; 1731bf215546Sopenharmony_ci texi->tex.s = 0xffff; 1732bf215546Sopenharmony_ci 1733bf215546Sopenharmony_ci info_out->prop.fp.readsFramebuffer = true; 1734bf215546Sopenharmony_ci break; 1735bf215546Sopenharmony_ci } 1736bf215546Sopenharmony_ci 1737bf215546Sopenharmony_ci const DataType dType = getDType(insn); 1738bf215546Sopenharmony_ci Value *indirect; 1739bf215546Sopenharmony_ci bool input = op != nir_intrinsic_load_output; 1740bf215546Sopenharmony_ci operation nvirOp; 1741bf215546Sopenharmony_ci uint32_t mode = 0; 1742bf215546Sopenharmony_ci 1743bf215546Sopenharmony_ci uint32_t idx = getIndirect(insn, op == nir_intrinsic_load_interpolated_input ? 1 : 0, 0, indirect); 1744bf215546Sopenharmony_ci nv50_ir_varying& vary = input ? info_out->in[idx] : info_out->out[idx]; 1745bf215546Sopenharmony_ci 1746bf215546Sopenharmony_ci // see load_barycentric_* handling 1747bf215546Sopenharmony_ci if (prog->getType() == Program::TYPE_FRAGMENT) { 1748bf215546Sopenharmony_ci if (op == nir_intrinsic_load_interpolated_input) { 1749bf215546Sopenharmony_ci ImmediateValue immMode; 1750bf215546Sopenharmony_ci if (getSrc(&insn->src[0], 1)->getUniqueInsn()->src(0).getImmediate(immMode)) 1751bf215546Sopenharmony_ci mode = immMode.reg.data.u32; 1752bf215546Sopenharmony_ci } 1753bf215546Sopenharmony_ci if (mode == NV50_IR_INTERP_DEFAULT) 1754bf215546Sopenharmony_ci mode |= translateInterpMode(&vary, nvirOp); 1755bf215546Sopenharmony_ci else { 1756bf215546Sopenharmony_ci if (vary.linear) { 1757bf215546Sopenharmony_ci nvirOp = OP_LINTERP; 1758bf215546Sopenharmony_ci mode |= NV50_IR_INTERP_LINEAR; 1759bf215546Sopenharmony_ci } else { 1760bf215546Sopenharmony_ci nvirOp = OP_PINTERP; 1761bf215546Sopenharmony_ci mode |= NV50_IR_INTERP_PERSPECTIVE; 1762bf215546Sopenharmony_ci } 1763bf215546Sopenharmony_ci } 1764bf215546Sopenharmony_ci } 1765bf215546Sopenharmony_ci 1766bf215546Sopenharmony_ci for (uint8_t i = 0u; i < dest_components; ++i) { 1767bf215546Sopenharmony_ci uint32_t address = getSlotAddress(insn, idx, i); 1768bf215546Sopenharmony_ci Symbol *sym = mkSymbol(input ? FILE_SHADER_INPUT : FILE_SHADER_OUTPUT, 0, dType, address); 1769bf215546Sopenharmony_ci if (prog->getType() == Program::TYPE_FRAGMENT) { 1770bf215546Sopenharmony_ci int s = 1; 1771bf215546Sopenharmony_ci if (typeSizeof(dType) == 8) { 1772bf215546Sopenharmony_ci Value *lo = getSSA(); 1773bf215546Sopenharmony_ci Value *hi = getSSA(); 1774bf215546Sopenharmony_ci Instruction *interp; 1775bf215546Sopenharmony_ci 1776bf215546Sopenharmony_ci interp = mkOp1(nvirOp, TYPE_U32, lo, sym); 1777bf215546Sopenharmony_ci if (nvirOp == OP_PINTERP) 1778bf215546Sopenharmony_ci interp->setSrc(s++, fp.position); 1779bf215546Sopenharmony_ci if (mode & NV50_IR_INTERP_OFFSET) 1780bf215546Sopenharmony_ci interp->setSrc(s++, getSrc(&insn->src[0], 0)); 1781bf215546Sopenharmony_ci interp->setInterpolate(mode); 1782bf215546Sopenharmony_ci interp->setIndirect(0, 0, indirect); 1783bf215546Sopenharmony_ci 1784bf215546Sopenharmony_ci Symbol *sym1 = mkSymbol(input ? FILE_SHADER_INPUT : FILE_SHADER_OUTPUT, 0, dType, address + 4); 1785bf215546Sopenharmony_ci interp = mkOp1(nvirOp, TYPE_U32, hi, sym1); 1786bf215546Sopenharmony_ci if (nvirOp == OP_PINTERP) 1787bf215546Sopenharmony_ci interp->setSrc(s++, fp.position); 1788bf215546Sopenharmony_ci if (mode & NV50_IR_INTERP_OFFSET) 1789bf215546Sopenharmony_ci interp->setSrc(s++, getSrc(&insn->src[0], 0)); 1790bf215546Sopenharmony_ci interp->setInterpolate(mode); 1791bf215546Sopenharmony_ci interp->setIndirect(0, 0, indirect); 1792bf215546Sopenharmony_ci 1793bf215546Sopenharmony_ci mkOp2(OP_MERGE, dType, newDefs[i], lo, hi); 1794bf215546Sopenharmony_ci } else { 1795bf215546Sopenharmony_ci Instruction *interp = mkOp1(nvirOp, dType, newDefs[i], sym); 1796bf215546Sopenharmony_ci if (nvirOp == OP_PINTERP) 1797bf215546Sopenharmony_ci interp->setSrc(s++, fp.position); 1798bf215546Sopenharmony_ci if (mode & NV50_IR_INTERP_OFFSET) 1799bf215546Sopenharmony_ci interp->setSrc(s++, getSrc(&insn->src[0], 0)); 1800bf215546Sopenharmony_ci interp->setInterpolate(mode); 1801bf215546Sopenharmony_ci interp->setIndirect(0, 0, indirect); 1802bf215546Sopenharmony_ci } 1803bf215546Sopenharmony_ci } else { 1804bf215546Sopenharmony_ci mkLoad(dType, newDefs[i], sym, indirect)->perPatch = vary.patch; 1805bf215546Sopenharmony_ci } 1806bf215546Sopenharmony_ci } 1807bf215546Sopenharmony_ci break; 1808bf215546Sopenharmony_ci } 1809bf215546Sopenharmony_ci case nir_intrinsic_load_barycentric_at_offset: 1810bf215546Sopenharmony_ci case nir_intrinsic_load_barycentric_at_sample: 1811bf215546Sopenharmony_ci case nir_intrinsic_load_barycentric_centroid: 1812bf215546Sopenharmony_ci case nir_intrinsic_load_barycentric_pixel: 1813bf215546Sopenharmony_ci case nir_intrinsic_load_barycentric_sample: { 1814bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 1815bf215546Sopenharmony_ci uint32_t mode; 1816bf215546Sopenharmony_ci 1817bf215546Sopenharmony_ci if (op == nir_intrinsic_load_barycentric_centroid || 1818bf215546Sopenharmony_ci op == nir_intrinsic_load_barycentric_sample) { 1819bf215546Sopenharmony_ci mode = NV50_IR_INTERP_CENTROID; 1820bf215546Sopenharmony_ci } else if (op == nir_intrinsic_load_barycentric_at_offset) { 1821bf215546Sopenharmony_ci Value *offs[2]; 1822bf215546Sopenharmony_ci for (uint8_t c = 0; c < 2; c++) { 1823bf215546Sopenharmony_ci offs[c] = getScratch(); 1824bf215546Sopenharmony_ci mkOp2(OP_MIN, TYPE_F32, offs[c], getSrc(&insn->src[0], c), loadImm(NULL, 0.4375f)); 1825bf215546Sopenharmony_ci mkOp2(OP_MAX, TYPE_F32, offs[c], offs[c], loadImm(NULL, -0.5f)); 1826bf215546Sopenharmony_ci mkOp2(OP_MUL, TYPE_F32, offs[c], offs[c], loadImm(NULL, 4096.0f)); 1827bf215546Sopenharmony_ci mkCvt(OP_CVT, TYPE_S32, offs[c], TYPE_F32, offs[c]); 1828bf215546Sopenharmony_ci } 1829bf215546Sopenharmony_ci mkOp3v(OP_INSBF, TYPE_U32, newDefs[0], offs[1], mkImm(0x1010), offs[0]); 1830bf215546Sopenharmony_ci 1831bf215546Sopenharmony_ci mode = NV50_IR_INTERP_OFFSET; 1832bf215546Sopenharmony_ci } else if (op == nir_intrinsic_load_barycentric_pixel) { 1833bf215546Sopenharmony_ci mode = NV50_IR_INTERP_DEFAULT; 1834bf215546Sopenharmony_ci } else if (op == nir_intrinsic_load_barycentric_at_sample) { 1835bf215546Sopenharmony_ci info_out->prop.fp.readsSampleLocations = true; 1836bf215546Sopenharmony_ci Value *sample = getSSA(); 1837bf215546Sopenharmony_ci mkOp3(OP_SELP, TYPE_U32, sample, mkImm(0), getSrc(&insn->src[0], 0), mkImm(0)) 1838bf215546Sopenharmony_ci ->subOp = 2; 1839bf215546Sopenharmony_ci mkOp1(OP_PIXLD, TYPE_U32, newDefs[0], sample)->subOp = NV50_IR_SUBOP_PIXLD_OFFSET; 1840bf215546Sopenharmony_ci mode = NV50_IR_INTERP_OFFSET; 1841bf215546Sopenharmony_ci } else { 1842bf215546Sopenharmony_ci unreachable("all intrinsics already handled above"); 1843bf215546Sopenharmony_ci } 1844bf215546Sopenharmony_ci 1845bf215546Sopenharmony_ci loadImm(newDefs[1], mode); 1846bf215546Sopenharmony_ci break; 1847bf215546Sopenharmony_ci } 1848bf215546Sopenharmony_ci case nir_intrinsic_demote: 1849bf215546Sopenharmony_ci case nir_intrinsic_discard: 1850bf215546Sopenharmony_ci mkOp(OP_DISCARD, TYPE_NONE, NULL); 1851bf215546Sopenharmony_ci break; 1852bf215546Sopenharmony_ci case nir_intrinsic_demote_if: 1853bf215546Sopenharmony_ci case nir_intrinsic_discard_if: { 1854bf215546Sopenharmony_ci Value *pred = getSSA(1, FILE_PREDICATE); 1855bf215546Sopenharmony_ci if (insn->num_components > 1) { 1856bf215546Sopenharmony_ci ERROR("nir_intrinsic_discard_if only with 1 component supported!\n"); 1857bf215546Sopenharmony_ci assert(false); 1858bf215546Sopenharmony_ci return false; 1859bf215546Sopenharmony_ci } 1860bf215546Sopenharmony_ci mkCmp(OP_SET, CC_NE, TYPE_U8, pred, TYPE_U32, getSrc(&insn->src[0], 0), zero); 1861bf215546Sopenharmony_ci mkOp(OP_DISCARD, TYPE_NONE, NULL)->setPredicate(CC_P, pred); 1862bf215546Sopenharmony_ci break; 1863bf215546Sopenharmony_ci } 1864bf215546Sopenharmony_ci case nir_intrinsic_load_base_vertex: 1865bf215546Sopenharmony_ci case nir_intrinsic_load_base_instance: 1866bf215546Sopenharmony_ci case nir_intrinsic_load_draw_id: 1867bf215546Sopenharmony_ci case nir_intrinsic_load_front_face: 1868bf215546Sopenharmony_ci case nir_intrinsic_is_helper_invocation: 1869bf215546Sopenharmony_ci case nir_intrinsic_load_helper_invocation: 1870bf215546Sopenharmony_ci case nir_intrinsic_load_instance_id: 1871bf215546Sopenharmony_ci case nir_intrinsic_load_invocation_id: 1872bf215546Sopenharmony_ci case nir_intrinsic_load_workgroup_size: 1873bf215546Sopenharmony_ci case nir_intrinsic_load_local_invocation_id: 1874bf215546Sopenharmony_ci case nir_intrinsic_load_num_workgroups: 1875bf215546Sopenharmony_ci case nir_intrinsic_load_patch_vertices_in: 1876bf215546Sopenharmony_ci case nir_intrinsic_load_primitive_id: 1877bf215546Sopenharmony_ci case nir_intrinsic_load_sample_id: 1878bf215546Sopenharmony_ci case nir_intrinsic_load_sample_mask_in: 1879bf215546Sopenharmony_ci case nir_intrinsic_load_sample_pos: 1880bf215546Sopenharmony_ci case nir_intrinsic_load_subgroup_eq_mask: 1881bf215546Sopenharmony_ci case nir_intrinsic_load_subgroup_ge_mask: 1882bf215546Sopenharmony_ci case nir_intrinsic_load_subgroup_gt_mask: 1883bf215546Sopenharmony_ci case nir_intrinsic_load_subgroup_le_mask: 1884bf215546Sopenharmony_ci case nir_intrinsic_load_subgroup_lt_mask: 1885bf215546Sopenharmony_ci case nir_intrinsic_load_subgroup_invocation: 1886bf215546Sopenharmony_ci case nir_intrinsic_load_tess_coord: 1887bf215546Sopenharmony_ci case nir_intrinsic_load_tess_level_inner: 1888bf215546Sopenharmony_ci case nir_intrinsic_load_tess_level_outer: 1889bf215546Sopenharmony_ci case nir_intrinsic_load_vertex_id: 1890bf215546Sopenharmony_ci case nir_intrinsic_load_workgroup_id: 1891bf215546Sopenharmony_ci case nir_intrinsic_load_work_dim: { 1892bf215546Sopenharmony_ci const DataType dType = getDType(insn); 1893bf215546Sopenharmony_ci SVSemantic sv = convert(op); 1894bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 1895bf215546Sopenharmony_ci 1896bf215546Sopenharmony_ci for (uint8_t i = 0u; i < nir_intrinsic_dest_components(insn); ++i) { 1897bf215546Sopenharmony_ci Value *def; 1898bf215546Sopenharmony_ci if (typeSizeof(dType) == 8) 1899bf215546Sopenharmony_ci def = getSSA(); 1900bf215546Sopenharmony_ci else 1901bf215546Sopenharmony_ci def = newDefs[i]; 1902bf215546Sopenharmony_ci 1903bf215546Sopenharmony_ci if (sv == SV_TID && info->prop.cp.numThreads[i] == 1) { 1904bf215546Sopenharmony_ci loadImm(def, 0u); 1905bf215546Sopenharmony_ci } else { 1906bf215546Sopenharmony_ci Symbol *sym = mkSysVal(sv, i); 1907bf215546Sopenharmony_ci Instruction *rdsv = mkOp1(OP_RDSV, TYPE_U32, def, sym); 1908bf215546Sopenharmony_ci if (sv == SV_TESS_OUTER || sv == SV_TESS_INNER) 1909bf215546Sopenharmony_ci rdsv->perPatch = 1; 1910bf215546Sopenharmony_ci } 1911bf215546Sopenharmony_ci 1912bf215546Sopenharmony_ci if (typeSizeof(dType) == 8) 1913bf215546Sopenharmony_ci mkOp2(OP_MERGE, dType, newDefs[i], def, loadImm(getSSA(), 0u)); 1914bf215546Sopenharmony_ci } 1915bf215546Sopenharmony_ci break; 1916bf215546Sopenharmony_ci } 1917bf215546Sopenharmony_ci // constants 1918bf215546Sopenharmony_ci case nir_intrinsic_load_subgroup_size: { 1919bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 1920bf215546Sopenharmony_ci loadImm(newDefs[0], 32u); 1921bf215546Sopenharmony_ci break; 1922bf215546Sopenharmony_ci } 1923bf215546Sopenharmony_ci case nir_intrinsic_vote_all: 1924bf215546Sopenharmony_ci case nir_intrinsic_vote_any: 1925bf215546Sopenharmony_ci case nir_intrinsic_vote_ieq: { 1926bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 1927bf215546Sopenharmony_ci Value *pred = getScratch(1, FILE_PREDICATE); 1928bf215546Sopenharmony_ci mkCmp(OP_SET, CC_NE, TYPE_U32, pred, TYPE_U32, getSrc(&insn->src[0], 0), zero); 1929bf215546Sopenharmony_ci mkOp1(OP_VOTE, TYPE_U32, pred, pred)->subOp = getSubOp(op); 1930bf215546Sopenharmony_ci mkCvt(OP_CVT, TYPE_U32, newDefs[0], TYPE_U8, pred); 1931bf215546Sopenharmony_ci break; 1932bf215546Sopenharmony_ci } 1933bf215546Sopenharmony_ci case nir_intrinsic_ballot: { 1934bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 1935bf215546Sopenharmony_ci Value *pred = getSSA(1, FILE_PREDICATE); 1936bf215546Sopenharmony_ci mkCmp(OP_SET, CC_NE, TYPE_U32, pred, TYPE_U32, getSrc(&insn->src[0], 0), zero); 1937bf215546Sopenharmony_ci mkOp1(OP_VOTE, TYPE_U32, newDefs[0], pred)->subOp = NV50_IR_SUBOP_VOTE_ANY; 1938bf215546Sopenharmony_ci break; 1939bf215546Sopenharmony_ci } 1940bf215546Sopenharmony_ci case nir_intrinsic_read_first_invocation: 1941bf215546Sopenharmony_ci case nir_intrinsic_read_invocation: { 1942bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 1943bf215546Sopenharmony_ci const DataType dType = getDType(insn); 1944bf215546Sopenharmony_ci Value *tmp = getScratch(); 1945bf215546Sopenharmony_ci 1946bf215546Sopenharmony_ci if (op == nir_intrinsic_read_first_invocation) { 1947bf215546Sopenharmony_ci mkOp1(OP_VOTE, TYPE_U32, tmp, mkImm(1))->subOp = NV50_IR_SUBOP_VOTE_ANY; 1948bf215546Sopenharmony_ci mkOp1(OP_BREV, TYPE_U32, tmp, tmp); 1949bf215546Sopenharmony_ci mkOp1(OP_BFIND, TYPE_U32, tmp, tmp)->subOp = NV50_IR_SUBOP_BFIND_SAMT; 1950bf215546Sopenharmony_ci } else 1951bf215546Sopenharmony_ci tmp = getSrc(&insn->src[1], 0); 1952bf215546Sopenharmony_ci 1953bf215546Sopenharmony_ci for (uint8_t i = 0; i < dest_components; ++i) { 1954bf215546Sopenharmony_ci mkOp3(OP_SHFL, dType, newDefs[i], getSrc(&insn->src[0], i), tmp, mkImm(0x1f)) 1955bf215546Sopenharmony_ci ->subOp = NV50_IR_SUBOP_SHFL_IDX; 1956bf215546Sopenharmony_ci } 1957bf215546Sopenharmony_ci break; 1958bf215546Sopenharmony_ci } 1959bf215546Sopenharmony_ci case nir_intrinsic_load_per_vertex_input: { 1960bf215546Sopenharmony_ci const DataType dType = getDType(insn); 1961bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 1962bf215546Sopenharmony_ci Value *indirectVertex; 1963bf215546Sopenharmony_ci Value *indirectOffset; 1964bf215546Sopenharmony_ci uint32_t baseVertex = getIndirect(&insn->src[0], 0, indirectVertex); 1965bf215546Sopenharmony_ci uint32_t idx = getIndirect(insn, 1, 0, indirectOffset); 1966bf215546Sopenharmony_ci 1967bf215546Sopenharmony_ci Value *vtxBase = mkOp2v(OP_PFETCH, TYPE_U32, getSSA(4, FILE_ADDRESS), 1968bf215546Sopenharmony_ci mkImm(baseVertex), indirectVertex); 1969bf215546Sopenharmony_ci for (uint8_t i = 0u; i < dest_components; ++i) { 1970bf215546Sopenharmony_ci uint32_t address = getSlotAddress(insn, idx, i); 1971bf215546Sopenharmony_ci loadFrom(FILE_SHADER_INPUT, 0, dType, newDefs[i], address, 0, 1972bf215546Sopenharmony_ci indirectOffset, vtxBase, info_out->in[idx].patch); 1973bf215546Sopenharmony_ci } 1974bf215546Sopenharmony_ci break; 1975bf215546Sopenharmony_ci } 1976bf215546Sopenharmony_ci case nir_intrinsic_load_per_vertex_output: { 1977bf215546Sopenharmony_ci const DataType dType = getDType(insn); 1978bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 1979bf215546Sopenharmony_ci Value *indirectVertex; 1980bf215546Sopenharmony_ci Value *indirectOffset; 1981bf215546Sopenharmony_ci uint32_t baseVertex = getIndirect(&insn->src[0], 0, indirectVertex); 1982bf215546Sopenharmony_ci uint32_t idx = getIndirect(insn, 1, 0, indirectOffset); 1983bf215546Sopenharmony_ci Value *vtxBase = NULL; 1984bf215546Sopenharmony_ci 1985bf215546Sopenharmony_ci if (indirectVertex) 1986bf215546Sopenharmony_ci vtxBase = indirectVertex; 1987bf215546Sopenharmony_ci else 1988bf215546Sopenharmony_ci vtxBase = loadImm(NULL, baseVertex); 1989bf215546Sopenharmony_ci 1990bf215546Sopenharmony_ci vtxBase = mkOp2v(OP_ADD, TYPE_U32, getSSA(4, FILE_ADDRESS), outBase, vtxBase); 1991bf215546Sopenharmony_ci 1992bf215546Sopenharmony_ci for (uint8_t i = 0u; i < dest_components; ++i) { 1993bf215546Sopenharmony_ci uint32_t address = getSlotAddress(insn, idx, i); 1994bf215546Sopenharmony_ci loadFrom(FILE_SHADER_OUTPUT, 0, dType, newDefs[i], address, 0, 1995bf215546Sopenharmony_ci indirectOffset, vtxBase, info_out->in[idx].patch); 1996bf215546Sopenharmony_ci } 1997bf215546Sopenharmony_ci break; 1998bf215546Sopenharmony_ci } 1999bf215546Sopenharmony_ci case nir_intrinsic_emit_vertex: { 2000bf215546Sopenharmony_ci if (info_out->io.genUserClip > 0) 2001bf215546Sopenharmony_ci handleUserClipPlanes(); 2002bf215546Sopenharmony_ci uint32_t idx = nir_intrinsic_stream_id(insn); 2003bf215546Sopenharmony_ci mkOp1(getOperation(op), TYPE_U32, NULL, mkImm(idx))->fixed = 1; 2004bf215546Sopenharmony_ci break; 2005bf215546Sopenharmony_ci } 2006bf215546Sopenharmony_ci case nir_intrinsic_end_primitive: { 2007bf215546Sopenharmony_ci uint32_t idx = nir_intrinsic_stream_id(insn); 2008bf215546Sopenharmony_ci if (idx) 2009bf215546Sopenharmony_ci break; 2010bf215546Sopenharmony_ci mkOp1(getOperation(op), TYPE_U32, NULL, mkImm(idx))->fixed = 1; 2011bf215546Sopenharmony_ci break; 2012bf215546Sopenharmony_ci } 2013bf215546Sopenharmony_ci case nir_intrinsic_load_ubo: { 2014bf215546Sopenharmony_ci const DataType dType = getDType(insn); 2015bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2016bf215546Sopenharmony_ci Value *indirectIndex; 2017bf215546Sopenharmony_ci Value *indirectOffset; 2018bf215546Sopenharmony_ci uint32_t index = getIndirect(&insn->src[0], 0, indirectIndex) + 1; 2019bf215546Sopenharmony_ci uint32_t offset = getIndirect(&insn->src[1], 0, indirectOffset); 2020bf215546Sopenharmony_ci if (indirectOffset) 2021bf215546Sopenharmony_ci indirectOffset = mkOp1v(OP_MOV, TYPE_U32, getSSA(4, FILE_ADDRESS), indirectOffset); 2022bf215546Sopenharmony_ci 2023bf215546Sopenharmony_ci for (uint8_t i = 0u; i < dest_components; ++i) { 2024bf215546Sopenharmony_ci loadFrom(FILE_MEMORY_CONST, index, dType, newDefs[i], offset, i, 2025bf215546Sopenharmony_ci indirectOffset, indirectIndex); 2026bf215546Sopenharmony_ci } 2027bf215546Sopenharmony_ci break; 2028bf215546Sopenharmony_ci } 2029bf215546Sopenharmony_ci case nir_intrinsic_get_ssbo_size: { 2030bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2031bf215546Sopenharmony_ci const DataType dType = getDType(insn); 2032bf215546Sopenharmony_ci Value *indirectBuffer; 2033bf215546Sopenharmony_ci uint32_t buffer = getIndirect(&insn->src[0], 0, indirectBuffer); 2034bf215546Sopenharmony_ci 2035bf215546Sopenharmony_ci Symbol *sym = mkSymbol(FILE_MEMORY_BUFFER, buffer, dType, 0); 2036bf215546Sopenharmony_ci mkOp1(OP_BUFQ, dType, newDefs[0], sym)->setIndirect(0, 0, indirectBuffer); 2037bf215546Sopenharmony_ci break; 2038bf215546Sopenharmony_ci } 2039bf215546Sopenharmony_ci case nir_intrinsic_store_ssbo: { 2040bf215546Sopenharmony_ci DataType sType = getSType(insn->src[0], false, false); 2041bf215546Sopenharmony_ci Value *indirectBuffer; 2042bf215546Sopenharmony_ci Value *indirectOffset; 2043bf215546Sopenharmony_ci uint32_t buffer = getIndirect(&insn->src[1], 0, indirectBuffer); 2044bf215546Sopenharmony_ci uint32_t offset = getIndirect(&insn->src[2], 0, indirectOffset); 2045bf215546Sopenharmony_ci 2046bf215546Sopenharmony_ci for (uint8_t i = 0u; i < nir_intrinsic_src_components(insn, 0); ++i) { 2047bf215546Sopenharmony_ci if (!((1u << i) & nir_intrinsic_write_mask(insn))) 2048bf215546Sopenharmony_ci continue; 2049bf215546Sopenharmony_ci Symbol *sym = mkSymbol(FILE_MEMORY_BUFFER, buffer, sType, 2050bf215546Sopenharmony_ci offset + i * typeSizeof(sType)); 2051bf215546Sopenharmony_ci mkStore(OP_STORE, sType, sym, indirectOffset, getSrc(&insn->src[0], i)) 2052bf215546Sopenharmony_ci ->setIndirect(0, 1, indirectBuffer); 2053bf215546Sopenharmony_ci } 2054bf215546Sopenharmony_ci info_out->io.globalAccess |= 0x2; 2055bf215546Sopenharmony_ci break; 2056bf215546Sopenharmony_ci } 2057bf215546Sopenharmony_ci case nir_intrinsic_load_ssbo: { 2058bf215546Sopenharmony_ci const DataType dType = getDType(insn); 2059bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2060bf215546Sopenharmony_ci Value *indirectBuffer; 2061bf215546Sopenharmony_ci Value *indirectOffset; 2062bf215546Sopenharmony_ci uint32_t buffer = getIndirect(&insn->src[0], 0, indirectBuffer); 2063bf215546Sopenharmony_ci uint32_t offset = getIndirect(&insn->src[1], 0, indirectOffset); 2064bf215546Sopenharmony_ci 2065bf215546Sopenharmony_ci for (uint8_t i = 0u; i < dest_components; ++i) 2066bf215546Sopenharmony_ci loadFrom(FILE_MEMORY_BUFFER, buffer, dType, newDefs[i], offset, i, 2067bf215546Sopenharmony_ci indirectOffset, indirectBuffer); 2068bf215546Sopenharmony_ci 2069bf215546Sopenharmony_ci info_out->io.globalAccess |= 0x1; 2070bf215546Sopenharmony_ci break; 2071bf215546Sopenharmony_ci } 2072bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_add: 2073bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_fadd: 2074bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_and: 2075bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_comp_swap: 2076bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_exchange: 2077bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_or: 2078bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_imax: 2079bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_imin: 2080bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_umax: 2081bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_umin: 2082bf215546Sopenharmony_ci case nir_intrinsic_shared_atomic_xor: { 2083bf215546Sopenharmony_ci const DataType dType = getDType(insn); 2084bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2085bf215546Sopenharmony_ci Value *indirectOffset; 2086bf215546Sopenharmony_ci uint32_t offset = getIndirect(&insn->src[0], 0, indirectOffset); 2087bf215546Sopenharmony_ci Symbol *sym = mkSymbol(FILE_MEMORY_SHARED, 0, dType, offset); 2088bf215546Sopenharmony_ci Instruction *atom = mkOp2(OP_ATOM, dType, newDefs[0], sym, getSrc(&insn->src[1], 0)); 2089bf215546Sopenharmony_ci if (op == nir_intrinsic_shared_atomic_comp_swap) 2090bf215546Sopenharmony_ci atom->setSrc(2, getSrc(&insn->src[2], 0)); 2091bf215546Sopenharmony_ci atom->setIndirect(0, 0, indirectOffset); 2092bf215546Sopenharmony_ci atom->subOp = getSubOp(op); 2093bf215546Sopenharmony_ci break; 2094bf215546Sopenharmony_ci } 2095bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_add: 2096bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_fadd: 2097bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_and: 2098bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_comp_swap: 2099bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_exchange: 2100bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_or: 2101bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_imax: 2102bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_imin: 2103bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_umax: 2104bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_umin: 2105bf215546Sopenharmony_ci case nir_intrinsic_ssbo_atomic_xor: { 2106bf215546Sopenharmony_ci const DataType dType = getDType(insn); 2107bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2108bf215546Sopenharmony_ci Value *indirectBuffer; 2109bf215546Sopenharmony_ci Value *indirectOffset; 2110bf215546Sopenharmony_ci uint32_t buffer = getIndirect(&insn->src[0], 0, indirectBuffer); 2111bf215546Sopenharmony_ci uint32_t offset = getIndirect(&insn->src[1], 0, indirectOffset); 2112bf215546Sopenharmony_ci 2113bf215546Sopenharmony_ci Symbol *sym = mkSymbol(FILE_MEMORY_BUFFER, buffer, dType, offset); 2114bf215546Sopenharmony_ci Instruction *atom = mkOp2(OP_ATOM, dType, newDefs[0], sym, 2115bf215546Sopenharmony_ci getSrc(&insn->src[2], 0)); 2116bf215546Sopenharmony_ci if (op == nir_intrinsic_ssbo_atomic_comp_swap) 2117bf215546Sopenharmony_ci atom->setSrc(2, getSrc(&insn->src[3], 0)); 2118bf215546Sopenharmony_ci atom->setIndirect(0, 0, indirectOffset); 2119bf215546Sopenharmony_ci atom->setIndirect(0, 1, indirectBuffer); 2120bf215546Sopenharmony_ci atom->subOp = getSubOp(op); 2121bf215546Sopenharmony_ci 2122bf215546Sopenharmony_ci info_out->io.globalAccess |= 0x2; 2123bf215546Sopenharmony_ci break; 2124bf215546Sopenharmony_ci } 2125bf215546Sopenharmony_ci case nir_intrinsic_global_atomic_add: 2126bf215546Sopenharmony_ci case nir_intrinsic_global_atomic_fadd: 2127bf215546Sopenharmony_ci case nir_intrinsic_global_atomic_and: 2128bf215546Sopenharmony_ci case nir_intrinsic_global_atomic_comp_swap: 2129bf215546Sopenharmony_ci case nir_intrinsic_global_atomic_exchange: 2130bf215546Sopenharmony_ci case nir_intrinsic_global_atomic_or: 2131bf215546Sopenharmony_ci case nir_intrinsic_global_atomic_imax: 2132bf215546Sopenharmony_ci case nir_intrinsic_global_atomic_imin: 2133bf215546Sopenharmony_ci case nir_intrinsic_global_atomic_umax: 2134bf215546Sopenharmony_ci case nir_intrinsic_global_atomic_umin: 2135bf215546Sopenharmony_ci case nir_intrinsic_global_atomic_xor: { 2136bf215546Sopenharmony_ci const DataType dType = getDType(insn); 2137bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2138bf215546Sopenharmony_ci Value *address; 2139bf215546Sopenharmony_ci uint32_t offset = getIndirect(&insn->src[0], 0, address); 2140bf215546Sopenharmony_ci 2141bf215546Sopenharmony_ci Symbol *sym = mkSymbol(FILE_MEMORY_GLOBAL, 0, dType, offset); 2142bf215546Sopenharmony_ci Instruction *atom = 2143bf215546Sopenharmony_ci mkOp2(OP_ATOM, dType, newDefs[0], sym, getSrc(&insn->src[1], 0)); 2144bf215546Sopenharmony_ci if (op == nir_intrinsic_global_atomic_comp_swap) 2145bf215546Sopenharmony_ci atom->setSrc(2, getSrc(&insn->src[2], 0)); 2146bf215546Sopenharmony_ci atom->setIndirect(0, 0, address); 2147bf215546Sopenharmony_ci atom->subOp = getSubOp(op); 2148bf215546Sopenharmony_ci 2149bf215546Sopenharmony_ci info_out->io.globalAccess |= 0x2; 2150bf215546Sopenharmony_ci break; 2151bf215546Sopenharmony_ci } 2152bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_add: 2153bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_fadd: 2154bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_and: 2155bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_comp_swap: 2156bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_exchange: 2157bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_imax: 2158bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_umax: 2159bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_imin: 2160bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_umin: 2161bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_or: 2162bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_xor: 2163bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_inc_wrap: 2164bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_dec_wrap: 2165bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_load: 2166bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_samples: 2167bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_size: 2168bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_store: 2169bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_add: 2170bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_fadd: 2171bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_and: 2172bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_comp_swap: 2173bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_exchange: 2174bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_imax: 2175bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_umax: 2176bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_imin: 2177bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_umin: 2178bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_or: 2179bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_xor: 2180bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_inc_wrap: 2181bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_dec_wrap: 2182bf215546Sopenharmony_ci case nir_intrinsic_image_load: 2183bf215546Sopenharmony_ci case nir_intrinsic_image_samples: 2184bf215546Sopenharmony_ci case nir_intrinsic_image_size: 2185bf215546Sopenharmony_ci case nir_intrinsic_image_store: { 2186bf215546Sopenharmony_ci std::vector<Value*> srcs, defs; 2187bf215546Sopenharmony_ci Value *indirect; 2188bf215546Sopenharmony_ci DataType ty; 2189bf215546Sopenharmony_ci 2190bf215546Sopenharmony_ci uint32_t mask = 0; 2191bf215546Sopenharmony_ci TexInstruction::Target target = 2192bf215546Sopenharmony_ci convert(nir_intrinsic_image_dim(insn), !!nir_intrinsic_image_array(insn), false); 2193bf215546Sopenharmony_ci unsigned int argCount = getNIRArgCount(target); 2194bf215546Sopenharmony_ci uint16_t location = 0; 2195bf215546Sopenharmony_ci 2196bf215546Sopenharmony_ci if (opInfo.has_dest) { 2197bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2198bf215546Sopenharmony_ci for (uint8_t i = 0u; i < newDefs.size(); ++i) { 2199bf215546Sopenharmony_ci defs.push_back(newDefs[i]); 2200bf215546Sopenharmony_ci mask |= 1 << i; 2201bf215546Sopenharmony_ci } 2202bf215546Sopenharmony_ci } 2203bf215546Sopenharmony_ci 2204bf215546Sopenharmony_ci int lod_src = -1; 2205bf215546Sopenharmony_ci bool bindless = false; 2206bf215546Sopenharmony_ci switch (op) { 2207bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_add: 2208bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_fadd: 2209bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_and: 2210bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_comp_swap: 2211bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_exchange: 2212bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_imax: 2213bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_umax: 2214bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_imin: 2215bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_umin: 2216bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_or: 2217bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_xor: 2218bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_inc_wrap: 2219bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_atomic_dec_wrap: 2220bf215546Sopenharmony_ci ty = getDType(insn); 2221bf215546Sopenharmony_ci bindless = true; 2222bf215546Sopenharmony_ci info_out->io.globalAccess |= 0x2; 2223bf215546Sopenharmony_ci mask = 0x1; 2224bf215546Sopenharmony_ci break; 2225bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_add: 2226bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_fadd: 2227bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_and: 2228bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_comp_swap: 2229bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_exchange: 2230bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_imax: 2231bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_umax: 2232bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_imin: 2233bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_umin: 2234bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_or: 2235bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_xor: 2236bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_inc_wrap: 2237bf215546Sopenharmony_ci case nir_intrinsic_image_atomic_dec_wrap: 2238bf215546Sopenharmony_ci ty = getDType(insn); 2239bf215546Sopenharmony_ci bindless = false; 2240bf215546Sopenharmony_ci info_out->io.globalAccess |= 0x2; 2241bf215546Sopenharmony_ci mask = 0x1; 2242bf215546Sopenharmony_ci break; 2243bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_load: 2244bf215546Sopenharmony_ci case nir_intrinsic_image_load: 2245bf215546Sopenharmony_ci ty = TYPE_U32; 2246bf215546Sopenharmony_ci bindless = op == nir_intrinsic_bindless_image_load; 2247bf215546Sopenharmony_ci info_out->io.globalAccess |= 0x1; 2248bf215546Sopenharmony_ci lod_src = 4; 2249bf215546Sopenharmony_ci break; 2250bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_store: 2251bf215546Sopenharmony_ci case nir_intrinsic_image_store: 2252bf215546Sopenharmony_ci ty = TYPE_U32; 2253bf215546Sopenharmony_ci bindless = op == nir_intrinsic_bindless_image_store; 2254bf215546Sopenharmony_ci info_out->io.globalAccess |= 0x2; 2255bf215546Sopenharmony_ci lod_src = 5; 2256bf215546Sopenharmony_ci mask = 0xf; 2257bf215546Sopenharmony_ci break; 2258bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_samples: 2259bf215546Sopenharmony_ci mask = 0x8; 2260bf215546Sopenharmony_ci FALLTHROUGH; 2261bf215546Sopenharmony_ci case nir_intrinsic_image_samples: 2262bf215546Sopenharmony_ci ty = TYPE_U32; 2263bf215546Sopenharmony_ci bindless = op == nir_intrinsic_bindless_image_samples; 2264bf215546Sopenharmony_ci mask = 0x8; 2265bf215546Sopenharmony_ci break; 2266bf215546Sopenharmony_ci case nir_intrinsic_bindless_image_size: 2267bf215546Sopenharmony_ci case nir_intrinsic_image_size: 2268bf215546Sopenharmony_ci assert(nir_src_as_uint(insn->src[1]) == 0); 2269bf215546Sopenharmony_ci ty = TYPE_U32; 2270bf215546Sopenharmony_ci bindless = op == nir_intrinsic_bindless_image_size; 2271bf215546Sopenharmony_ci break; 2272bf215546Sopenharmony_ci default: 2273bf215546Sopenharmony_ci unreachable("unhandled image opcode"); 2274bf215546Sopenharmony_ci break; 2275bf215546Sopenharmony_ci } 2276bf215546Sopenharmony_ci 2277bf215546Sopenharmony_ci if (bindless) 2278bf215546Sopenharmony_ci indirect = getSrc(&insn->src[0], 0); 2279bf215546Sopenharmony_ci else 2280bf215546Sopenharmony_ci location = getIndirect(&insn->src[0], 0, indirect); 2281bf215546Sopenharmony_ci 2282bf215546Sopenharmony_ci /* Pre-GF100, SSBOs and images are in the same HW file, managed by 2283bf215546Sopenharmony_ci * prop.cp.gmem. images are located after SSBOs. 2284bf215546Sopenharmony_ci */ 2285bf215546Sopenharmony_ci if (info->target < NVISA_GF100_CHIPSET) 2286bf215546Sopenharmony_ci location += nir->info.num_ssbos; 2287bf215546Sopenharmony_ci 2288bf215546Sopenharmony_ci // coords 2289bf215546Sopenharmony_ci if (opInfo.num_srcs >= 2) 2290bf215546Sopenharmony_ci for (unsigned int i = 0u; i < argCount; ++i) 2291bf215546Sopenharmony_ci srcs.push_back(getSrc(&insn->src[1], i)); 2292bf215546Sopenharmony_ci 2293bf215546Sopenharmony_ci // the sampler is just another src added after coords 2294bf215546Sopenharmony_ci if (opInfo.num_srcs >= 3 && target.isMS()) 2295bf215546Sopenharmony_ci srcs.push_back(getSrc(&insn->src[2], 0)); 2296bf215546Sopenharmony_ci 2297bf215546Sopenharmony_ci if (opInfo.num_srcs >= 4 && lod_src != 4) { 2298bf215546Sopenharmony_ci unsigned components = opInfo.src_components[3] ? opInfo.src_components[3] : insn->num_components; 2299bf215546Sopenharmony_ci for (uint8_t i = 0u; i < components; ++i) 2300bf215546Sopenharmony_ci srcs.push_back(getSrc(&insn->src[3], i)); 2301bf215546Sopenharmony_ci } 2302bf215546Sopenharmony_ci 2303bf215546Sopenharmony_ci if (opInfo.num_srcs >= 5 && lod_src != 5) 2304bf215546Sopenharmony_ci // 1 for aotmic swap 2305bf215546Sopenharmony_ci for (uint8_t i = 0u; i < opInfo.src_components[4]; ++i) 2306bf215546Sopenharmony_ci srcs.push_back(getSrc(&insn->src[4], i)); 2307bf215546Sopenharmony_ci 2308bf215546Sopenharmony_ci TexInstruction *texi = mkTex(getOperation(op), target.getEnum(), location, 0, defs, srcs); 2309bf215546Sopenharmony_ci texi->tex.bindless = bindless; 2310bf215546Sopenharmony_ci texi->tex.format = nv50_ir::TexInstruction::translateImgFormat(nir_intrinsic_format(insn)); 2311bf215546Sopenharmony_ci texi->tex.mask = mask; 2312bf215546Sopenharmony_ci texi->cache = convert(nir_intrinsic_access(insn)); 2313bf215546Sopenharmony_ci texi->setType(ty); 2314bf215546Sopenharmony_ci texi->subOp = getSubOp(op); 2315bf215546Sopenharmony_ci 2316bf215546Sopenharmony_ci if (indirect) 2317bf215546Sopenharmony_ci texi->setIndirectR(indirect); 2318bf215546Sopenharmony_ci 2319bf215546Sopenharmony_ci break; 2320bf215546Sopenharmony_ci } 2321bf215546Sopenharmony_ci case nir_intrinsic_store_scratch: 2322bf215546Sopenharmony_ci case nir_intrinsic_store_shared: { 2323bf215546Sopenharmony_ci DataType sType = getSType(insn->src[0], false, false); 2324bf215546Sopenharmony_ci Value *indirectOffset; 2325bf215546Sopenharmony_ci uint32_t offset = getIndirect(&insn->src[1], 0, indirectOffset); 2326bf215546Sopenharmony_ci if (indirectOffset) 2327bf215546Sopenharmony_ci indirectOffset = mkOp1v(OP_MOV, TYPE_U32, getSSA(4, FILE_ADDRESS), indirectOffset); 2328bf215546Sopenharmony_ci 2329bf215546Sopenharmony_ci for (uint8_t i = 0u; i < nir_intrinsic_src_components(insn, 0); ++i) { 2330bf215546Sopenharmony_ci if (!((1u << i) & nir_intrinsic_write_mask(insn))) 2331bf215546Sopenharmony_ci continue; 2332bf215546Sopenharmony_ci Symbol *sym = mkSymbol(getFile(op), 0, sType, offset + i * typeSizeof(sType)); 2333bf215546Sopenharmony_ci mkStore(OP_STORE, sType, sym, indirectOffset, getSrc(&insn->src[0], i)); 2334bf215546Sopenharmony_ci } 2335bf215546Sopenharmony_ci break; 2336bf215546Sopenharmony_ci } 2337bf215546Sopenharmony_ci case nir_intrinsic_load_kernel_input: 2338bf215546Sopenharmony_ci case nir_intrinsic_load_scratch: 2339bf215546Sopenharmony_ci case nir_intrinsic_load_shared: { 2340bf215546Sopenharmony_ci const DataType dType = getDType(insn); 2341bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2342bf215546Sopenharmony_ci Value *indirectOffset; 2343bf215546Sopenharmony_ci uint32_t offset = getIndirect(&insn->src[0], 0, indirectOffset); 2344bf215546Sopenharmony_ci if (indirectOffset) 2345bf215546Sopenharmony_ci indirectOffset = mkOp1v(OP_MOV, TYPE_U32, getSSA(4, FILE_ADDRESS), indirectOffset); 2346bf215546Sopenharmony_ci 2347bf215546Sopenharmony_ci for (uint8_t i = 0u; i < dest_components; ++i) 2348bf215546Sopenharmony_ci loadFrom(getFile(op), 0, dType, newDefs[i], offset, i, indirectOffset); 2349bf215546Sopenharmony_ci 2350bf215546Sopenharmony_ci break; 2351bf215546Sopenharmony_ci } 2352bf215546Sopenharmony_ci case nir_intrinsic_control_barrier: { 2353bf215546Sopenharmony_ci // TODO: add flag to shader_info 2354bf215546Sopenharmony_ci info_out->numBarriers = 1; 2355bf215546Sopenharmony_ci Instruction *bar = mkOp2(OP_BAR, TYPE_U32, NULL, mkImm(0), mkImm(0)); 2356bf215546Sopenharmony_ci bar->fixed = 1; 2357bf215546Sopenharmony_ci bar->subOp = NV50_IR_SUBOP_BAR_SYNC; 2358bf215546Sopenharmony_ci break; 2359bf215546Sopenharmony_ci } 2360bf215546Sopenharmony_ci case nir_intrinsic_group_memory_barrier: 2361bf215546Sopenharmony_ci case nir_intrinsic_memory_barrier: 2362bf215546Sopenharmony_ci case nir_intrinsic_memory_barrier_buffer: 2363bf215546Sopenharmony_ci case nir_intrinsic_memory_barrier_image: 2364bf215546Sopenharmony_ci case nir_intrinsic_memory_barrier_shared: { 2365bf215546Sopenharmony_ci Instruction *bar = mkOp(OP_MEMBAR, TYPE_NONE, NULL); 2366bf215546Sopenharmony_ci bar->fixed = 1; 2367bf215546Sopenharmony_ci bar->subOp = getSubOp(op); 2368bf215546Sopenharmony_ci break; 2369bf215546Sopenharmony_ci } 2370bf215546Sopenharmony_ci case nir_intrinsic_memory_barrier_tcs_patch: 2371bf215546Sopenharmony_ci break; 2372bf215546Sopenharmony_ci case nir_intrinsic_shader_clock: { 2373bf215546Sopenharmony_ci const DataType dType = getDType(insn); 2374bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2375bf215546Sopenharmony_ci 2376bf215546Sopenharmony_ci loadImm(newDefs[0], 0u); 2377bf215546Sopenharmony_ci mkOp1(OP_RDSV, dType, newDefs[1], mkSysVal(SV_CLOCK, 0))->fixed = 1; 2378bf215546Sopenharmony_ci break; 2379bf215546Sopenharmony_ci } 2380bf215546Sopenharmony_ci case nir_intrinsic_load_global: 2381bf215546Sopenharmony_ci case nir_intrinsic_load_global_constant: { 2382bf215546Sopenharmony_ci const DataType dType = getDType(insn); 2383bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2384bf215546Sopenharmony_ci Value *indirectOffset; 2385bf215546Sopenharmony_ci uint32_t offset = getIndirect(&insn->src[0], 0, indirectOffset); 2386bf215546Sopenharmony_ci 2387bf215546Sopenharmony_ci for (auto i = 0u; i < dest_components; ++i) 2388bf215546Sopenharmony_ci loadFrom(FILE_MEMORY_GLOBAL, 0, dType, newDefs[i], offset, i, indirectOffset); 2389bf215546Sopenharmony_ci 2390bf215546Sopenharmony_ci info_out->io.globalAccess |= 0x1; 2391bf215546Sopenharmony_ci break; 2392bf215546Sopenharmony_ci } 2393bf215546Sopenharmony_ci case nir_intrinsic_store_global: { 2394bf215546Sopenharmony_ci DataType sType = getSType(insn->src[0], false, false); 2395bf215546Sopenharmony_ci 2396bf215546Sopenharmony_ci for (auto i = 0u; i < nir_intrinsic_src_components(insn, 0); ++i) { 2397bf215546Sopenharmony_ci if (!((1u << i) & nir_intrinsic_write_mask(insn))) 2398bf215546Sopenharmony_ci continue; 2399bf215546Sopenharmony_ci if (typeSizeof(sType) == 8) { 2400bf215546Sopenharmony_ci Value *split[2]; 2401bf215546Sopenharmony_ci mkSplit(split, 4, getSrc(&insn->src[0], i)); 2402bf215546Sopenharmony_ci 2403bf215546Sopenharmony_ci Symbol *sym = mkSymbol(FILE_MEMORY_GLOBAL, 0, TYPE_U32, i * typeSizeof(sType)); 2404bf215546Sopenharmony_ci mkStore(OP_STORE, TYPE_U32, sym, getSrc(&insn->src[1], 0), split[0]); 2405bf215546Sopenharmony_ci 2406bf215546Sopenharmony_ci sym = mkSymbol(FILE_MEMORY_GLOBAL, 0, TYPE_U32, i * typeSizeof(sType) + 4); 2407bf215546Sopenharmony_ci mkStore(OP_STORE, TYPE_U32, sym, getSrc(&insn->src[1], 0), split[1]); 2408bf215546Sopenharmony_ci } else { 2409bf215546Sopenharmony_ci Symbol *sym = mkSymbol(FILE_MEMORY_GLOBAL, 0, sType, i * typeSizeof(sType)); 2410bf215546Sopenharmony_ci mkStore(OP_STORE, sType, sym, getSrc(&insn->src[1], 0), getSrc(&insn->src[0], i)); 2411bf215546Sopenharmony_ci } 2412bf215546Sopenharmony_ci } 2413bf215546Sopenharmony_ci 2414bf215546Sopenharmony_ci info_out->io.globalAccess |= 0x2; 2415bf215546Sopenharmony_ci break; 2416bf215546Sopenharmony_ci } 2417bf215546Sopenharmony_ci default: 2418bf215546Sopenharmony_ci ERROR("unknown nir_intrinsic_op %s\n", nir_intrinsic_infos[op].name); 2419bf215546Sopenharmony_ci return false; 2420bf215546Sopenharmony_ci } 2421bf215546Sopenharmony_ci 2422bf215546Sopenharmony_ci return true; 2423bf215546Sopenharmony_ci} 2424bf215546Sopenharmony_ci 2425bf215546Sopenharmony_cibool 2426bf215546Sopenharmony_ciConverter::visit(nir_jump_instr *insn) 2427bf215546Sopenharmony_ci{ 2428bf215546Sopenharmony_ci switch (insn->type) { 2429bf215546Sopenharmony_ci case nir_jump_return: 2430bf215546Sopenharmony_ci // TODO: this only works in the main function 2431bf215546Sopenharmony_ci mkFlow(OP_BRA, exit, CC_ALWAYS, NULL); 2432bf215546Sopenharmony_ci bb->cfg.attach(&exit->cfg, Graph::Edge::CROSS); 2433bf215546Sopenharmony_ci break; 2434bf215546Sopenharmony_ci case nir_jump_break: 2435bf215546Sopenharmony_ci case nir_jump_continue: { 2436bf215546Sopenharmony_ci bool isBreak = insn->type == nir_jump_break; 2437bf215546Sopenharmony_ci nir_block *block = insn->instr.block; 2438bf215546Sopenharmony_ci BasicBlock *target = convert(block->successors[0]); 2439bf215546Sopenharmony_ci mkFlow(isBreak ? OP_BREAK : OP_CONT, target, CC_ALWAYS, NULL); 2440bf215546Sopenharmony_ci bb->cfg.attach(&target->cfg, isBreak ? Graph::Edge::CROSS : Graph::Edge::BACK); 2441bf215546Sopenharmony_ci break; 2442bf215546Sopenharmony_ci } 2443bf215546Sopenharmony_ci default: 2444bf215546Sopenharmony_ci ERROR("unknown nir_jump_type %u\n", insn->type); 2445bf215546Sopenharmony_ci return false; 2446bf215546Sopenharmony_ci } 2447bf215546Sopenharmony_ci 2448bf215546Sopenharmony_ci return true; 2449bf215546Sopenharmony_ci} 2450bf215546Sopenharmony_ci 2451bf215546Sopenharmony_ciValue* 2452bf215546Sopenharmony_ciConverter::convert(nir_load_const_instr *insn, uint8_t idx) 2453bf215546Sopenharmony_ci{ 2454bf215546Sopenharmony_ci Value *val; 2455bf215546Sopenharmony_ci 2456bf215546Sopenharmony_ci if (immInsertPos) 2457bf215546Sopenharmony_ci setPosition(immInsertPos, true); 2458bf215546Sopenharmony_ci else 2459bf215546Sopenharmony_ci setPosition(bb, false); 2460bf215546Sopenharmony_ci 2461bf215546Sopenharmony_ci switch (insn->def.bit_size) { 2462bf215546Sopenharmony_ci case 64: 2463bf215546Sopenharmony_ci val = loadImm(getSSA(8), insn->value[idx].u64); 2464bf215546Sopenharmony_ci break; 2465bf215546Sopenharmony_ci case 32: 2466bf215546Sopenharmony_ci val = loadImm(getSSA(4), insn->value[idx].u32); 2467bf215546Sopenharmony_ci break; 2468bf215546Sopenharmony_ci case 16: 2469bf215546Sopenharmony_ci val = loadImm(getSSA(2), insn->value[idx].u16); 2470bf215546Sopenharmony_ci break; 2471bf215546Sopenharmony_ci case 8: 2472bf215546Sopenharmony_ci val = loadImm(getSSA(1), insn->value[idx].u8); 2473bf215546Sopenharmony_ci break; 2474bf215546Sopenharmony_ci default: 2475bf215546Sopenharmony_ci unreachable("unhandled bit size!\n"); 2476bf215546Sopenharmony_ci } 2477bf215546Sopenharmony_ci setPosition(bb, true); 2478bf215546Sopenharmony_ci return val; 2479bf215546Sopenharmony_ci} 2480bf215546Sopenharmony_ci 2481bf215546Sopenharmony_cibool 2482bf215546Sopenharmony_ciConverter::visit(nir_load_const_instr *insn) 2483bf215546Sopenharmony_ci{ 2484bf215546Sopenharmony_ci assert(insn->def.bit_size <= 64); 2485bf215546Sopenharmony_ci immediates[insn->def.index] = insn; 2486bf215546Sopenharmony_ci return true; 2487bf215546Sopenharmony_ci} 2488bf215546Sopenharmony_ci 2489bf215546Sopenharmony_ci#define DEFAULT_CHECKS \ 2490bf215546Sopenharmony_ci if (insn->dest.dest.ssa.num_components > 1) { \ 2491bf215546Sopenharmony_ci ERROR("nir_alu_instr only supported with 1 component!\n"); \ 2492bf215546Sopenharmony_ci return false; \ 2493bf215546Sopenharmony_ci } \ 2494bf215546Sopenharmony_ci if (insn->dest.write_mask != 1) { \ 2495bf215546Sopenharmony_ci ERROR("nir_alu_instr only with write_mask of 1 supported!\n"); \ 2496bf215546Sopenharmony_ci return false; \ 2497bf215546Sopenharmony_ci } 2498bf215546Sopenharmony_cibool 2499bf215546Sopenharmony_ciConverter::visit(nir_alu_instr *insn) 2500bf215546Sopenharmony_ci{ 2501bf215546Sopenharmony_ci const nir_op op = insn->op; 2502bf215546Sopenharmony_ci const nir_op_info &info = nir_op_infos[op]; 2503bf215546Sopenharmony_ci DataType dType = getDType(insn); 2504bf215546Sopenharmony_ci const std::vector<DataType> sTypes = getSTypes(insn); 2505bf215546Sopenharmony_ci 2506bf215546Sopenharmony_ci Instruction *oldPos = this->bb->getExit(); 2507bf215546Sopenharmony_ci 2508bf215546Sopenharmony_ci switch (op) { 2509bf215546Sopenharmony_ci case nir_op_fabs: 2510bf215546Sopenharmony_ci case nir_op_iabs: 2511bf215546Sopenharmony_ci case nir_op_fadd: 2512bf215546Sopenharmony_ci case nir_op_iadd: 2513bf215546Sopenharmony_ci case nir_op_iand: 2514bf215546Sopenharmony_ci case nir_op_fceil: 2515bf215546Sopenharmony_ci case nir_op_fcos: 2516bf215546Sopenharmony_ci case nir_op_fddx: 2517bf215546Sopenharmony_ci case nir_op_fddx_coarse: 2518bf215546Sopenharmony_ci case nir_op_fddx_fine: 2519bf215546Sopenharmony_ci case nir_op_fddy: 2520bf215546Sopenharmony_ci case nir_op_fddy_coarse: 2521bf215546Sopenharmony_ci case nir_op_fddy_fine: 2522bf215546Sopenharmony_ci case nir_op_fdiv: 2523bf215546Sopenharmony_ci case nir_op_idiv: 2524bf215546Sopenharmony_ci case nir_op_udiv: 2525bf215546Sopenharmony_ci case nir_op_fexp2: 2526bf215546Sopenharmony_ci case nir_op_ffloor: 2527bf215546Sopenharmony_ci case nir_op_ffma: 2528bf215546Sopenharmony_ci case nir_op_flog2: 2529bf215546Sopenharmony_ci case nir_op_fmax: 2530bf215546Sopenharmony_ci case nir_op_imax: 2531bf215546Sopenharmony_ci case nir_op_umax: 2532bf215546Sopenharmony_ci case nir_op_fmin: 2533bf215546Sopenharmony_ci case nir_op_imin: 2534bf215546Sopenharmony_ci case nir_op_umin: 2535bf215546Sopenharmony_ci case nir_op_fmod: 2536bf215546Sopenharmony_ci case nir_op_imod: 2537bf215546Sopenharmony_ci case nir_op_umod: 2538bf215546Sopenharmony_ci case nir_op_fmul: 2539bf215546Sopenharmony_ci case nir_op_imul: 2540bf215546Sopenharmony_ci case nir_op_imul_high: 2541bf215546Sopenharmony_ci case nir_op_umul_high: 2542bf215546Sopenharmony_ci case nir_op_fneg: 2543bf215546Sopenharmony_ci case nir_op_ineg: 2544bf215546Sopenharmony_ci case nir_op_inot: 2545bf215546Sopenharmony_ci case nir_op_ior: 2546bf215546Sopenharmony_ci case nir_op_pack_64_2x32_split: 2547bf215546Sopenharmony_ci case nir_op_fpow: 2548bf215546Sopenharmony_ci case nir_op_frcp: 2549bf215546Sopenharmony_ci case nir_op_frem: 2550bf215546Sopenharmony_ci case nir_op_irem: 2551bf215546Sopenharmony_ci case nir_op_frsq: 2552bf215546Sopenharmony_ci case nir_op_fsat: 2553bf215546Sopenharmony_ci case nir_op_ishr: 2554bf215546Sopenharmony_ci case nir_op_ushr: 2555bf215546Sopenharmony_ci case nir_op_fsin: 2556bf215546Sopenharmony_ci case nir_op_fsqrt: 2557bf215546Sopenharmony_ci case nir_op_ftrunc: 2558bf215546Sopenharmony_ci case nir_op_ishl: 2559bf215546Sopenharmony_ci case nir_op_ixor: { 2560bf215546Sopenharmony_ci DEFAULT_CHECKS; 2561bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2562bf215546Sopenharmony_ci operation preOp = preOperationNeeded(op); 2563bf215546Sopenharmony_ci if (preOp != OP_NOP) { 2564bf215546Sopenharmony_ci assert(info.num_inputs < 2); 2565bf215546Sopenharmony_ci Value *tmp = getSSA(typeSizeof(dType)); 2566bf215546Sopenharmony_ci Instruction *i0 = mkOp(preOp, dType, tmp); 2567bf215546Sopenharmony_ci Instruction *i1 = mkOp(getOperation(op), dType, newDefs[0]); 2568bf215546Sopenharmony_ci if (info.num_inputs) { 2569bf215546Sopenharmony_ci i0->setSrc(0, getSrc(&insn->src[0])); 2570bf215546Sopenharmony_ci i1->setSrc(0, tmp); 2571bf215546Sopenharmony_ci } 2572bf215546Sopenharmony_ci i1->subOp = getSubOp(op); 2573bf215546Sopenharmony_ci } else { 2574bf215546Sopenharmony_ci Instruction *i = mkOp(getOperation(op), dType, newDefs[0]); 2575bf215546Sopenharmony_ci for (unsigned s = 0u; s < info.num_inputs; ++s) { 2576bf215546Sopenharmony_ci i->setSrc(s, getSrc(&insn->src[s])); 2577bf215546Sopenharmony_ci 2578bf215546Sopenharmony_ci if (this->info->io.mul_zero_wins) { 2579bf215546Sopenharmony_ci switch (op) { 2580bf215546Sopenharmony_ci case nir_op_fmul: 2581bf215546Sopenharmony_ci case nir_op_ffma: 2582bf215546Sopenharmony_ci i->dnz = true; 2583bf215546Sopenharmony_ci break; 2584bf215546Sopenharmony_ci default: 2585bf215546Sopenharmony_ci break; 2586bf215546Sopenharmony_ci } 2587bf215546Sopenharmony_ci } 2588bf215546Sopenharmony_ci } 2589bf215546Sopenharmony_ci i->subOp = getSubOp(op); 2590bf215546Sopenharmony_ci } 2591bf215546Sopenharmony_ci break; 2592bf215546Sopenharmony_ci } 2593bf215546Sopenharmony_ci case nir_op_ifind_msb: 2594bf215546Sopenharmony_ci case nir_op_ufind_msb: { 2595bf215546Sopenharmony_ci DEFAULT_CHECKS; 2596bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2597bf215546Sopenharmony_ci dType = sTypes[0]; 2598bf215546Sopenharmony_ci mkOp1(getOperation(op), dType, newDefs[0], getSrc(&insn->src[0])); 2599bf215546Sopenharmony_ci break; 2600bf215546Sopenharmony_ci } 2601bf215546Sopenharmony_ci case nir_op_fround_even: { 2602bf215546Sopenharmony_ci DEFAULT_CHECKS; 2603bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2604bf215546Sopenharmony_ci mkCvt(OP_CVT, dType, newDefs[0], dType, getSrc(&insn->src[0]))->rnd = ROUND_NI; 2605bf215546Sopenharmony_ci break; 2606bf215546Sopenharmony_ci } 2607bf215546Sopenharmony_ci // convert instructions 2608bf215546Sopenharmony_ci case nir_op_f2f32: 2609bf215546Sopenharmony_ci case nir_op_f2i32: 2610bf215546Sopenharmony_ci case nir_op_f2u32: 2611bf215546Sopenharmony_ci case nir_op_i2f32: 2612bf215546Sopenharmony_ci case nir_op_i2i32: 2613bf215546Sopenharmony_ci case nir_op_u2f32: 2614bf215546Sopenharmony_ci case nir_op_u2u32: 2615bf215546Sopenharmony_ci case nir_op_f2f64: 2616bf215546Sopenharmony_ci case nir_op_f2i64: 2617bf215546Sopenharmony_ci case nir_op_f2u64: 2618bf215546Sopenharmony_ci case nir_op_i2f64: 2619bf215546Sopenharmony_ci case nir_op_i2i64: 2620bf215546Sopenharmony_ci case nir_op_u2f64: 2621bf215546Sopenharmony_ci case nir_op_u2u64: { 2622bf215546Sopenharmony_ci DEFAULT_CHECKS; 2623bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2624bf215546Sopenharmony_ci Instruction *i = mkOp1(getOperation(op), dType, newDefs[0], getSrc(&insn->src[0])); 2625bf215546Sopenharmony_ci if (op == nir_op_f2i32 || op == nir_op_f2i64 || op == nir_op_f2u32 || op == nir_op_f2u64) 2626bf215546Sopenharmony_ci i->rnd = ROUND_Z; 2627bf215546Sopenharmony_ci i->sType = sTypes[0]; 2628bf215546Sopenharmony_ci break; 2629bf215546Sopenharmony_ci } 2630bf215546Sopenharmony_ci // compare instructions 2631bf215546Sopenharmony_ci case nir_op_feq32: 2632bf215546Sopenharmony_ci case nir_op_ieq32: 2633bf215546Sopenharmony_ci case nir_op_fge32: 2634bf215546Sopenharmony_ci case nir_op_ige32: 2635bf215546Sopenharmony_ci case nir_op_uge32: 2636bf215546Sopenharmony_ci case nir_op_flt32: 2637bf215546Sopenharmony_ci case nir_op_ilt32: 2638bf215546Sopenharmony_ci case nir_op_ult32: 2639bf215546Sopenharmony_ci case nir_op_fneu32: 2640bf215546Sopenharmony_ci case nir_op_ine32: { 2641bf215546Sopenharmony_ci DEFAULT_CHECKS; 2642bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2643bf215546Sopenharmony_ci Instruction *i = mkCmp(getOperation(op), 2644bf215546Sopenharmony_ci getCondCode(op), 2645bf215546Sopenharmony_ci dType, 2646bf215546Sopenharmony_ci newDefs[0], 2647bf215546Sopenharmony_ci dType, 2648bf215546Sopenharmony_ci getSrc(&insn->src[0]), 2649bf215546Sopenharmony_ci getSrc(&insn->src[1])); 2650bf215546Sopenharmony_ci if (info.num_inputs == 3) 2651bf215546Sopenharmony_ci i->setSrc(2, getSrc(&insn->src[2])); 2652bf215546Sopenharmony_ci i->sType = sTypes[0]; 2653bf215546Sopenharmony_ci break; 2654bf215546Sopenharmony_ci } 2655bf215546Sopenharmony_ci case nir_op_mov: 2656bf215546Sopenharmony_ci case nir_op_vec2: 2657bf215546Sopenharmony_ci case nir_op_vec3: 2658bf215546Sopenharmony_ci case nir_op_vec4: 2659bf215546Sopenharmony_ci case nir_op_vec8: 2660bf215546Sopenharmony_ci case nir_op_vec16: { 2661bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2662bf215546Sopenharmony_ci for (LValues::size_type c = 0u; c < newDefs.size(); ++c) { 2663bf215546Sopenharmony_ci mkMov(newDefs[c], getSrc(&insn->src[c]), dType); 2664bf215546Sopenharmony_ci } 2665bf215546Sopenharmony_ci break; 2666bf215546Sopenharmony_ci } 2667bf215546Sopenharmony_ci // (un)pack 2668bf215546Sopenharmony_ci case nir_op_pack_64_2x32: { 2669bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2670bf215546Sopenharmony_ci Instruction *merge = mkOp(OP_MERGE, dType, newDefs[0]); 2671bf215546Sopenharmony_ci merge->setSrc(0, getSrc(&insn->src[0], 0)); 2672bf215546Sopenharmony_ci merge->setSrc(1, getSrc(&insn->src[0], 1)); 2673bf215546Sopenharmony_ci break; 2674bf215546Sopenharmony_ci } 2675bf215546Sopenharmony_ci case nir_op_pack_half_2x16_split: { 2676bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2677bf215546Sopenharmony_ci Value *tmpH = getSSA(); 2678bf215546Sopenharmony_ci Value *tmpL = getSSA(); 2679bf215546Sopenharmony_ci 2680bf215546Sopenharmony_ci mkCvt(OP_CVT, TYPE_F16, tmpL, TYPE_F32, getSrc(&insn->src[0])); 2681bf215546Sopenharmony_ci mkCvt(OP_CVT, TYPE_F16, tmpH, TYPE_F32, getSrc(&insn->src[1])); 2682bf215546Sopenharmony_ci mkOp3(OP_INSBF, TYPE_U32, newDefs[0], tmpH, mkImm(0x1010), tmpL); 2683bf215546Sopenharmony_ci break; 2684bf215546Sopenharmony_ci } 2685bf215546Sopenharmony_ci case nir_op_unpack_half_2x16_split_x: 2686bf215546Sopenharmony_ci case nir_op_unpack_half_2x16_split_y: { 2687bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2688bf215546Sopenharmony_ci Instruction *cvt = mkCvt(OP_CVT, TYPE_F32, newDefs[0], TYPE_F16, getSrc(&insn->src[0])); 2689bf215546Sopenharmony_ci if (op == nir_op_unpack_half_2x16_split_y) 2690bf215546Sopenharmony_ci cvt->subOp = 1; 2691bf215546Sopenharmony_ci break; 2692bf215546Sopenharmony_ci } 2693bf215546Sopenharmony_ci case nir_op_unpack_64_2x32: { 2694bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2695bf215546Sopenharmony_ci mkOp1(OP_SPLIT, dType, newDefs[0], getSrc(&insn->src[0]))->setDef(1, newDefs[1]); 2696bf215546Sopenharmony_ci break; 2697bf215546Sopenharmony_ci } 2698bf215546Sopenharmony_ci case nir_op_unpack_64_2x32_split_x: { 2699bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2700bf215546Sopenharmony_ci mkOp1(OP_SPLIT, dType, newDefs[0], getSrc(&insn->src[0]))->setDef(1, getSSA()); 2701bf215546Sopenharmony_ci break; 2702bf215546Sopenharmony_ci } 2703bf215546Sopenharmony_ci case nir_op_unpack_64_2x32_split_y: { 2704bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2705bf215546Sopenharmony_ci mkOp1(OP_SPLIT, dType, getSSA(), getSrc(&insn->src[0]))->setDef(1, newDefs[0]); 2706bf215546Sopenharmony_ci break; 2707bf215546Sopenharmony_ci } 2708bf215546Sopenharmony_ci // special instructions 2709bf215546Sopenharmony_ci case nir_op_fsign: 2710bf215546Sopenharmony_ci case nir_op_isign: { 2711bf215546Sopenharmony_ci DEFAULT_CHECKS; 2712bf215546Sopenharmony_ci DataType iType; 2713bf215546Sopenharmony_ci if (::isFloatType(dType)) 2714bf215546Sopenharmony_ci iType = TYPE_F32; 2715bf215546Sopenharmony_ci else 2716bf215546Sopenharmony_ci iType = TYPE_S32; 2717bf215546Sopenharmony_ci 2718bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2719bf215546Sopenharmony_ci LValue *val0 = getScratch(); 2720bf215546Sopenharmony_ci LValue *val1 = getScratch(); 2721bf215546Sopenharmony_ci mkCmp(OP_SET, CC_GT, iType, val0, dType, getSrc(&insn->src[0]), zero); 2722bf215546Sopenharmony_ci mkCmp(OP_SET, CC_LT, iType, val1, dType, getSrc(&insn->src[0]), zero); 2723bf215546Sopenharmony_ci 2724bf215546Sopenharmony_ci if (dType == TYPE_F64) { 2725bf215546Sopenharmony_ci mkOp2(OP_SUB, iType, val0, val0, val1); 2726bf215546Sopenharmony_ci mkCvt(OP_CVT, TYPE_F64, newDefs[0], iType, val0); 2727bf215546Sopenharmony_ci } else if (dType == TYPE_S64 || dType == TYPE_U64) { 2728bf215546Sopenharmony_ci mkOp2(OP_SUB, iType, val0, val1, val0); 2729bf215546Sopenharmony_ci mkOp2(OP_SHR, iType, val1, val0, loadImm(NULL, 31)); 2730bf215546Sopenharmony_ci mkOp2(OP_MERGE, dType, newDefs[0], val0, val1); 2731bf215546Sopenharmony_ci } else if (::isFloatType(dType)) 2732bf215546Sopenharmony_ci mkOp2(OP_SUB, iType, newDefs[0], val0, val1); 2733bf215546Sopenharmony_ci else 2734bf215546Sopenharmony_ci mkOp2(OP_SUB, iType, newDefs[0], val1, val0); 2735bf215546Sopenharmony_ci break; 2736bf215546Sopenharmony_ci } 2737bf215546Sopenharmony_ci case nir_op_fcsel: 2738bf215546Sopenharmony_ci case nir_op_b32csel: { 2739bf215546Sopenharmony_ci DEFAULT_CHECKS; 2740bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2741bf215546Sopenharmony_ci mkCmp(OP_SLCT, CC_NE, dType, newDefs[0], sTypes[0], getSrc(&insn->src[1]), getSrc(&insn->src[2]), getSrc(&insn->src[0])); 2742bf215546Sopenharmony_ci break; 2743bf215546Sopenharmony_ci } 2744bf215546Sopenharmony_ci case nir_op_ibitfield_extract: 2745bf215546Sopenharmony_ci case nir_op_ubitfield_extract: { 2746bf215546Sopenharmony_ci DEFAULT_CHECKS; 2747bf215546Sopenharmony_ci Value *tmp = getSSA(); 2748bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2749bf215546Sopenharmony_ci mkOp3(OP_INSBF, dType, tmp, getSrc(&insn->src[2]), loadImm(NULL, 0x808), getSrc(&insn->src[1])); 2750bf215546Sopenharmony_ci mkOp2(OP_EXTBF, dType, newDefs[0], getSrc(&insn->src[0]), tmp); 2751bf215546Sopenharmony_ci break; 2752bf215546Sopenharmony_ci } 2753bf215546Sopenharmony_ci case nir_op_bfm: { 2754bf215546Sopenharmony_ci DEFAULT_CHECKS; 2755bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2756bf215546Sopenharmony_ci mkOp2(OP_BMSK, dType, newDefs[0], getSrc(&insn->src[1]), getSrc(&insn->src[0]))->subOp = NV50_IR_SUBOP_BMSK_W; 2757bf215546Sopenharmony_ci break; 2758bf215546Sopenharmony_ci } 2759bf215546Sopenharmony_ci case nir_op_bitfield_insert: { 2760bf215546Sopenharmony_ci DEFAULT_CHECKS; 2761bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2762bf215546Sopenharmony_ci LValue *temp = getSSA(); 2763bf215546Sopenharmony_ci mkOp3(OP_INSBF, TYPE_U32, temp, getSrc(&insn->src[3]), mkImm(0x808), getSrc(&insn->src[2])); 2764bf215546Sopenharmony_ci mkOp3(OP_INSBF, dType, newDefs[0], getSrc(&insn->src[1]), temp, getSrc(&insn->src[0])); 2765bf215546Sopenharmony_ci break; 2766bf215546Sopenharmony_ci } 2767bf215546Sopenharmony_ci case nir_op_bit_count: { 2768bf215546Sopenharmony_ci DEFAULT_CHECKS; 2769bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2770bf215546Sopenharmony_ci mkOp2(OP_POPCNT, dType, newDefs[0], getSrc(&insn->src[0]), getSrc(&insn->src[0])); 2771bf215546Sopenharmony_ci break; 2772bf215546Sopenharmony_ci } 2773bf215546Sopenharmony_ci case nir_op_bitfield_reverse: { 2774bf215546Sopenharmony_ci DEFAULT_CHECKS; 2775bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2776bf215546Sopenharmony_ci mkOp1(OP_BREV, TYPE_U32, newDefs[0], getSrc(&insn->src[0])); 2777bf215546Sopenharmony_ci break; 2778bf215546Sopenharmony_ci } 2779bf215546Sopenharmony_ci case nir_op_find_lsb: { 2780bf215546Sopenharmony_ci DEFAULT_CHECKS; 2781bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2782bf215546Sopenharmony_ci Value *tmp = getSSA(); 2783bf215546Sopenharmony_ci mkOp1(OP_BREV, TYPE_U32, tmp, getSrc(&insn->src[0])); 2784bf215546Sopenharmony_ci mkOp1(OP_BFIND, TYPE_U32, newDefs[0], tmp)->subOp = NV50_IR_SUBOP_BFIND_SAMT; 2785bf215546Sopenharmony_ci break; 2786bf215546Sopenharmony_ci } 2787bf215546Sopenharmony_ci case nir_op_extract_u8: { 2788bf215546Sopenharmony_ci DEFAULT_CHECKS; 2789bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2790bf215546Sopenharmony_ci Value *prmt = getSSA(); 2791bf215546Sopenharmony_ci mkOp2(OP_OR, TYPE_U32, prmt, getSrc(&insn->src[1]), loadImm(NULL, 0x4440)); 2792bf215546Sopenharmony_ci mkOp3(OP_PERMT, TYPE_U32, newDefs[0], getSrc(&insn->src[0]), prmt, loadImm(NULL, 0)); 2793bf215546Sopenharmony_ci break; 2794bf215546Sopenharmony_ci } 2795bf215546Sopenharmony_ci case nir_op_extract_i8: { 2796bf215546Sopenharmony_ci DEFAULT_CHECKS; 2797bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2798bf215546Sopenharmony_ci Value *prmt = getSSA(); 2799bf215546Sopenharmony_ci mkOp3(OP_MAD, TYPE_U32, prmt, getSrc(&insn->src[1]), loadImm(NULL, 0x1111), loadImm(NULL, 0x8880)); 2800bf215546Sopenharmony_ci mkOp3(OP_PERMT, TYPE_U32, newDefs[0], getSrc(&insn->src[0]), prmt, loadImm(NULL, 0)); 2801bf215546Sopenharmony_ci break; 2802bf215546Sopenharmony_ci } 2803bf215546Sopenharmony_ci case nir_op_extract_u16: { 2804bf215546Sopenharmony_ci DEFAULT_CHECKS; 2805bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2806bf215546Sopenharmony_ci Value *prmt = getSSA(); 2807bf215546Sopenharmony_ci mkOp3(OP_MAD, TYPE_U32, prmt, getSrc(&insn->src[1]), loadImm(NULL, 0x22), loadImm(NULL, 0x4410)); 2808bf215546Sopenharmony_ci mkOp3(OP_PERMT, TYPE_U32, newDefs[0], getSrc(&insn->src[0]), prmt, loadImm(NULL, 0)); 2809bf215546Sopenharmony_ci break; 2810bf215546Sopenharmony_ci } 2811bf215546Sopenharmony_ci case nir_op_extract_i16: { 2812bf215546Sopenharmony_ci DEFAULT_CHECKS; 2813bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2814bf215546Sopenharmony_ci Value *prmt = getSSA(); 2815bf215546Sopenharmony_ci mkOp3(OP_MAD, TYPE_U32, prmt, getSrc(&insn->src[1]), loadImm(NULL, 0x2222), loadImm(NULL, 0x9910)); 2816bf215546Sopenharmony_ci mkOp3(OP_PERMT, TYPE_U32, newDefs[0], getSrc(&insn->src[0]), prmt, loadImm(NULL, 0)); 2817bf215546Sopenharmony_ci break; 2818bf215546Sopenharmony_ci } 2819bf215546Sopenharmony_ci case nir_op_urol: { 2820bf215546Sopenharmony_ci DEFAULT_CHECKS; 2821bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2822bf215546Sopenharmony_ci mkOp3(OP_SHF, TYPE_U32, newDefs[0], getSrc(&insn->src[0]), 2823bf215546Sopenharmony_ci getSrc(&insn->src[1]), getSrc(&insn->src[0])) 2824bf215546Sopenharmony_ci ->subOp = NV50_IR_SUBOP_SHF_L | 2825bf215546Sopenharmony_ci NV50_IR_SUBOP_SHF_W | 2826bf215546Sopenharmony_ci NV50_IR_SUBOP_SHF_HI; 2827bf215546Sopenharmony_ci break; 2828bf215546Sopenharmony_ci } 2829bf215546Sopenharmony_ci case nir_op_uror: { 2830bf215546Sopenharmony_ci DEFAULT_CHECKS; 2831bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2832bf215546Sopenharmony_ci mkOp3(OP_SHF, TYPE_U32, newDefs[0], getSrc(&insn->src[0]), 2833bf215546Sopenharmony_ci getSrc(&insn->src[1]), getSrc(&insn->src[0])) 2834bf215546Sopenharmony_ci ->subOp = NV50_IR_SUBOP_SHF_R | 2835bf215546Sopenharmony_ci NV50_IR_SUBOP_SHF_W | 2836bf215546Sopenharmony_ci NV50_IR_SUBOP_SHF_LO; 2837bf215546Sopenharmony_ci break; 2838bf215546Sopenharmony_ci } 2839bf215546Sopenharmony_ci // boolean conversions 2840bf215546Sopenharmony_ci case nir_op_b2f32: { 2841bf215546Sopenharmony_ci DEFAULT_CHECKS; 2842bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2843bf215546Sopenharmony_ci mkOp2(OP_AND, TYPE_U32, newDefs[0], getSrc(&insn->src[0]), loadImm(NULL, 1.0f)); 2844bf215546Sopenharmony_ci break; 2845bf215546Sopenharmony_ci } 2846bf215546Sopenharmony_ci case nir_op_b2f64: { 2847bf215546Sopenharmony_ci DEFAULT_CHECKS; 2848bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2849bf215546Sopenharmony_ci Value *tmp = getSSA(4); 2850bf215546Sopenharmony_ci mkOp2(OP_AND, TYPE_U32, tmp, getSrc(&insn->src[0]), loadImm(NULL, 0x3ff00000)); 2851bf215546Sopenharmony_ci mkOp2(OP_MERGE, TYPE_U64, newDefs[0], loadImm(NULL, 0), tmp); 2852bf215546Sopenharmony_ci break; 2853bf215546Sopenharmony_ci } 2854bf215546Sopenharmony_ci case nir_op_f2b32: 2855bf215546Sopenharmony_ci case nir_op_i2b32: { 2856bf215546Sopenharmony_ci DEFAULT_CHECKS; 2857bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2858bf215546Sopenharmony_ci Value *src1; 2859bf215546Sopenharmony_ci if (typeSizeof(sTypes[0]) == 8) { 2860bf215546Sopenharmony_ci src1 = loadImm(getSSA(8), 0.0); 2861bf215546Sopenharmony_ci } else { 2862bf215546Sopenharmony_ci src1 = zero; 2863bf215546Sopenharmony_ci } 2864bf215546Sopenharmony_ci CondCode cc = op == nir_op_f2b32 ? CC_NEU : CC_NE; 2865bf215546Sopenharmony_ci mkCmp(OP_SET, cc, TYPE_U32, newDefs[0], sTypes[0], getSrc(&insn->src[0]), src1); 2866bf215546Sopenharmony_ci break; 2867bf215546Sopenharmony_ci } 2868bf215546Sopenharmony_ci case nir_op_b2i32: { 2869bf215546Sopenharmony_ci DEFAULT_CHECKS; 2870bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2871bf215546Sopenharmony_ci mkOp2(OP_AND, TYPE_U32, newDefs[0], getSrc(&insn->src[0]), loadImm(NULL, 1)); 2872bf215546Sopenharmony_ci break; 2873bf215546Sopenharmony_ci } 2874bf215546Sopenharmony_ci case nir_op_b2i64: { 2875bf215546Sopenharmony_ci DEFAULT_CHECKS; 2876bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2877bf215546Sopenharmony_ci LValue *def = getScratch(); 2878bf215546Sopenharmony_ci mkOp2(OP_AND, TYPE_U32, def, getSrc(&insn->src[0]), loadImm(NULL, 1)); 2879bf215546Sopenharmony_ci mkOp2(OP_MERGE, TYPE_S64, newDefs[0], def, loadImm(NULL, 0)); 2880bf215546Sopenharmony_ci break; 2881bf215546Sopenharmony_ci } 2882bf215546Sopenharmony_ci default: 2883bf215546Sopenharmony_ci ERROR("unknown nir_op %s\n", info.name); 2884bf215546Sopenharmony_ci assert(false); 2885bf215546Sopenharmony_ci return false; 2886bf215546Sopenharmony_ci } 2887bf215546Sopenharmony_ci 2888bf215546Sopenharmony_ci if (!oldPos) { 2889bf215546Sopenharmony_ci oldPos = this->bb->getEntry(); 2890bf215546Sopenharmony_ci oldPos->precise = insn->exact; 2891bf215546Sopenharmony_ci } 2892bf215546Sopenharmony_ci 2893bf215546Sopenharmony_ci if (unlikely(!oldPos)) 2894bf215546Sopenharmony_ci return true; 2895bf215546Sopenharmony_ci 2896bf215546Sopenharmony_ci while (oldPos->next) { 2897bf215546Sopenharmony_ci oldPos = oldPos->next; 2898bf215546Sopenharmony_ci oldPos->precise = insn->exact; 2899bf215546Sopenharmony_ci } 2900bf215546Sopenharmony_ci oldPos->saturate = insn->dest.saturate; 2901bf215546Sopenharmony_ci 2902bf215546Sopenharmony_ci return true; 2903bf215546Sopenharmony_ci} 2904bf215546Sopenharmony_ci#undef DEFAULT_CHECKS 2905bf215546Sopenharmony_ci 2906bf215546Sopenharmony_cibool 2907bf215546Sopenharmony_ciConverter::visit(nir_ssa_undef_instr *insn) 2908bf215546Sopenharmony_ci{ 2909bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->def); 2910bf215546Sopenharmony_ci for (uint8_t i = 0u; i < insn->def.num_components; ++i) { 2911bf215546Sopenharmony_ci mkOp(OP_NOP, TYPE_NONE, newDefs[i]); 2912bf215546Sopenharmony_ci } 2913bf215546Sopenharmony_ci return true; 2914bf215546Sopenharmony_ci} 2915bf215546Sopenharmony_ci 2916bf215546Sopenharmony_ci#define CASE_SAMPLER(ty) \ 2917bf215546Sopenharmony_ci case GLSL_SAMPLER_DIM_ ## ty : \ 2918bf215546Sopenharmony_ci if (isArray && !isShadow) \ 2919bf215546Sopenharmony_ci return TEX_TARGET_ ## ty ## _ARRAY; \ 2920bf215546Sopenharmony_ci else if (!isArray && isShadow) \ 2921bf215546Sopenharmony_ci return TEX_TARGET_## ty ## _SHADOW; \ 2922bf215546Sopenharmony_ci else if (isArray && isShadow) \ 2923bf215546Sopenharmony_ci return TEX_TARGET_## ty ## _ARRAY_SHADOW; \ 2924bf215546Sopenharmony_ci else \ 2925bf215546Sopenharmony_ci return TEX_TARGET_ ## ty 2926bf215546Sopenharmony_ci 2927bf215546Sopenharmony_ciTexTarget 2928bf215546Sopenharmony_ciConverter::convert(glsl_sampler_dim dim, bool isArray, bool isShadow) 2929bf215546Sopenharmony_ci{ 2930bf215546Sopenharmony_ci switch (dim) { 2931bf215546Sopenharmony_ci CASE_SAMPLER(1D); 2932bf215546Sopenharmony_ci CASE_SAMPLER(2D); 2933bf215546Sopenharmony_ci CASE_SAMPLER(CUBE); 2934bf215546Sopenharmony_ci case GLSL_SAMPLER_DIM_3D: 2935bf215546Sopenharmony_ci return TEX_TARGET_3D; 2936bf215546Sopenharmony_ci case GLSL_SAMPLER_DIM_MS: 2937bf215546Sopenharmony_ci if (isArray) 2938bf215546Sopenharmony_ci return TEX_TARGET_2D_MS_ARRAY; 2939bf215546Sopenharmony_ci return TEX_TARGET_2D_MS; 2940bf215546Sopenharmony_ci case GLSL_SAMPLER_DIM_RECT: 2941bf215546Sopenharmony_ci if (isShadow) 2942bf215546Sopenharmony_ci return TEX_TARGET_RECT_SHADOW; 2943bf215546Sopenharmony_ci return TEX_TARGET_RECT; 2944bf215546Sopenharmony_ci case GLSL_SAMPLER_DIM_BUF: 2945bf215546Sopenharmony_ci return TEX_TARGET_BUFFER; 2946bf215546Sopenharmony_ci case GLSL_SAMPLER_DIM_EXTERNAL: 2947bf215546Sopenharmony_ci return TEX_TARGET_2D; 2948bf215546Sopenharmony_ci default: 2949bf215546Sopenharmony_ci ERROR("unknown glsl_sampler_dim %u\n", dim); 2950bf215546Sopenharmony_ci assert(false); 2951bf215546Sopenharmony_ci return TEX_TARGET_COUNT; 2952bf215546Sopenharmony_ci } 2953bf215546Sopenharmony_ci} 2954bf215546Sopenharmony_ci#undef CASE_SAMPLER 2955bf215546Sopenharmony_ci 2956bf215546Sopenharmony_ciunsigned int 2957bf215546Sopenharmony_ciConverter::getNIRArgCount(TexInstruction::Target& target) 2958bf215546Sopenharmony_ci{ 2959bf215546Sopenharmony_ci unsigned int result = target.getArgCount(); 2960bf215546Sopenharmony_ci if (target.isCube() && target.isArray()) 2961bf215546Sopenharmony_ci result--; 2962bf215546Sopenharmony_ci if (target.isMS()) 2963bf215546Sopenharmony_ci result--; 2964bf215546Sopenharmony_ci return result; 2965bf215546Sopenharmony_ci} 2966bf215546Sopenharmony_ci 2967bf215546Sopenharmony_ciCacheMode 2968bf215546Sopenharmony_ciConverter::convert(enum gl_access_qualifier access) 2969bf215546Sopenharmony_ci{ 2970bf215546Sopenharmony_ci if (access & ACCESS_VOLATILE) 2971bf215546Sopenharmony_ci return CACHE_CV; 2972bf215546Sopenharmony_ci if (access & ACCESS_COHERENT) 2973bf215546Sopenharmony_ci return CACHE_CG; 2974bf215546Sopenharmony_ci return CACHE_CA; 2975bf215546Sopenharmony_ci} 2976bf215546Sopenharmony_ci 2977bf215546Sopenharmony_cibool 2978bf215546Sopenharmony_ciConverter::visit(nir_tex_instr *insn) 2979bf215546Sopenharmony_ci{ 2980bf215546Sopenharmony_ci switch (insn->op) { 2981bf215546Sopenharmony_ci case nir_texop_lod: 2982bf215546Sopenharmony_ci case nir_texop_query_levels: 2983bf215546Sopenharmony_ci case nir_texop_tex: 2984bf215546Sopenharmony_ci case nir_texop_texture_samples: 2985bf215546Sopenharmony_ci case nir_texop_tg4: 2986bf215546Sopenharmony_ci case nir_texop_txb: 2987bf215546Sopenharmony_ci case nir_texop_txd: 2988bf215546Sopenharmony_ci case nir_texop_txf: 2989bf215546Sopenharmony_ci case nir_texop_txf_ms: 2990bf215546Sopenharmony_ci case nir_texop_txl: 2991bf215546Sopenharmony_ci case nir_texop_txs: { 2992bf215546Sopenharmony_ci LValues &newDefs = convert(&insn->dest); 2993bf215546Sopenharmony_ci std::vector<Value*> srcs; 2994bf215546Sopenharmony_ci std::vector<Value*> defs; 2995bf215546Sopenharmony_ci std::vector<nir_src*> offsets; 2996bf215546Sopenharmony_ci uint8_t mask = 0; 2997bf215546Sopenharmony_ci bool lz = false; 2998bf215546Sopenharmony_ci TexInstruction::Target target = convert(insn->sampler_dim, insn->is_array, insn->is_shadow); 2999bf215546Sopenharmony_ci operation op = getOperation(insn->op); 3000bf215546Sopenharmony_ci 3001bf215546Sopenharmony_ci int r, s; 3002bf215546Sopenharmony_ci int biasIdx = nir_tex_instr_src_index(insn, nir_tex_src_bias); 3003bf215546Sopenharmony_ci int compIdx = nir_tex_instr_src_index(insn, nir_tex_src_comparator); 3004bf215546Sopenharmony_ci int coordsIdx = nir_tex_instr_src_index(insn, nir_tex_src_coord); 3005bf215546Sopenharmony_ci int ddxIdx = nir_tex_instr_src_index(insn, nir_tex_src_ddx); 3006bf215546Sopenharmony_ci int ddyIdx = nir_tex_instr_src_index(insn, nir_tex_src_ddy); 3007bf215546Sopenharmony_ci int msIdx = nir_tex_instr_src_index(insn, nir_tex_src_ms_index); 3008bf215546Sopenharmony_ci int lodIdx = nir_tex_instr_src_index(insn, nir_tex_src_lod); 3009bf215546Sopenharmony_ci int offsetIdx = nir_tex_instr_src_index(insn, nir_tex_src_offset); 3010bf215546Sopenharmony_ci int sampOffIdx = nir_tex_instr_src_index(insn, nir_tex_src_sampler_offset); 3011bf215546Sopenharmony_ci int texOffIdx = nir_tex_instr_src_index(insn, nir_tex_src_texture_offset); 3012bf215546Sopenharmony_ci int sampHandleIdx = nir_tex_instr_src_index(insn, nir_tex_src_sampler_handle); 3013bf215546Sopenharmony_ci int texHandleIdx = nir_tex_instr_src_index(insn, nir_tex_src_texture_handle); 3014bf215546Sopenharmony_ci 3015bf215546Sopenharmony_ci bool bindless = sampHandleIdx != -1 || texHandleIdx != -1; 3016bf215546Sopenharmony_ci assert((sampHandleIdx != -1) == (texHandleIdx != -1)); 3017bf215546Sopenharmony_ci 3018bf215546Sopenharmony_ci srcs.resize(insn->coord_components); 3019bf215546Sopenharmony_ci for (uint8_t i = 0u; i < insn->coord_components; ++i) 3020bf215546Sopenharmony_ci srcs[i] = getSrc(&insn->src[coordsIdx].src, i); 3021bf215546Sopenharmony_ci 3022bf215546Sopenharmony_ci // sometimes we get less args than target.getArgCount, but codegen expects the latter 3023bf215546Sopenharmony_ci if (insn->coord_components) { 3024bf215546Sopenharmony_ci uint32_t argCount = target.getArgCount(); 3025bf215546Sopenharmony_ci 3026bf215546Sopenharmony_ci if (target.isMS()) 3027bf215546Sopenharmony_ci argCount -= 1; 3028bf215546Sopenharmony_ci 3029bf215546Sopenharmony_ci for (uint32_t i = 0u; i < (argCount - insn->coord_components); ++i) 3030bf215546Sopenharmony_ci srcs.push_back(getSSA()); 3031bf215546Sopenharmony_ci } 3032bf215546Sopenharmony_ci 3033bf215546Sopenharmony_ci if (insn->op == nir_texop_texture_samples) 3034bf215546Sopenharmony_ci srcs.push_back(zero); 3035bf215546Sopenharmony_ci else if (!insn->num_srcs) 3036bf215546Sopenharmony_ci srcs.push_back(loadImm(NULL, 0)); 3037bf215546Sopenharmony_ci if (biasIdx != -1) 3038bf215546Sopenharmony_ci srcs.push_back(getSrc(&insn->src[biasIdx].src, 0)); 3039bf215546Sopenharmony_ci if (lodIdx != -1) 3040bf215546Sopenharmony_ci srcs.push_back(getSrc(&insn->src[lodIdx].src, 0)); 3041bf215546Sopenharmony_ci else if (op == OP_TXF) 3042bf215546Sopenharmony_ci lz = true; 3043bf215546Sopenharmony_ci if (msIdx != -1) 3044bf215546Sopenharmony_ci srcs.push_back(getSrc(&insn->src[msIdx].src, 0)); 3045bf215546Sopenharmony_ci if (offsetIdx != -1) 3046bf215546Sopenharmony_ci offsets.push_back(&insn->src[offsetIdx].src); 3047bf215546Sopenharmony_ci if (compIdx != -1) 3048bf215546Sopenharmony_ci srcs.push_back(getSrc(&insn->src[compIdx].src, 0)); 3049bf215546Sopenharmony_ci if (texOffIdx != -1) { 3050bf215546Sopenharmony_ci srcs.push_back(getSrc(&insn->src[texOffIdx].src, 0)); 3051bf215546Sopenharmony_ci texOffIdx = srcs.size() - 1; 3052bf215546Sopenharmony_ci } 3053bf215546Sopenharmony_ci if (sampOffIdx != -1) { 3054bf215546Sopenharmony_ci srcs.push_back(getSrc(&insn->src[sampOffIdx].src, 0)); 3055bf215546Sopenharmony_ci sampOffIdx = srcs.size() - 1; 3056bf215546Sopenharmony_ci } 3057bf215546Sopenharmony_ci if (bindless) { 3058bf215546Sopenharmony_ci // currently we use the lower bits 3059bf215546Sopenharmony_ci Value *split[2]; 3060bf215546Sopenharmony_ci Value *handle = getSrc(&insn->src[sampHandleIdx].src, 0); 3061bf215546Sopenharmony_ci 3062bf215546Sopenharmony_ci mkSplit(split, 4, handle); 3063bf215546Sopenharmony_ci 3064bf215546Sopenharmony_ci srcs.push_back(split[0]); 3065bf215546Sopenharmony_ci texOffIdx = srcs.size() - 1; 3066bf215546Sopenharmony_ci } 3067bf215546Sopenharmony_ci 3068bf215546Sopenharmony_ci r = bindless ? 0xff : insn->texture_index; 3069bf215546Sopenharmony_ci s = bindless ? 0x1f : insn->sampler_index; 3070bf215546Sopenharmony_ci if (op == OP_TXF || op == OP_TXQ) 3071bf215546Sopenharmony_ci s = 0; 3072bf215546Sopenharmony_ci 3073bf215546Sopenharmony_ci defs.resize(newDefs.size()); 3074bf215546Sopenharmony_ci for (uint8_t d = 0u; d < newDefs.size(); ++d) { 3075bf215546Sopenharmony_ci defs[d] = newDefs[d]; 3076bf215546Sopenharmony_ci mask |= 1 << d; 3077bf215546Sopenharmony_ci } 3078bf215546Sopenharmony_ci if (target.isMS() || (op == OP_TEX && prog->getType() != Program::TYPE_FRAGMENT)) 3079bf215546Sopenharmony_ci lz = true; 3080bf215546Sopenharmony_ci 3081bf215546Sopenharmony_ci TexInstruction *texi = mkTex(op, target.getEnum(), r, s, defs, srcs); 3082bf215546Sopenharmony_ci texi->tex.levelZero = lz; 3083bf215546Sopenharmony_ci texi->tex.mask = mask; 3084bf215546Sopenharmony_ci texi->tex.bindless = bindless; 3085bf215546Sopenharmony_ci 3086bf215546Sopenharmony_ci if (texOffIdx != -1) 3087bf215546Sopenharmony_ci texi->tex.rIndirectSrc = texOffIdx; 3088bf215546Sopenharmony_ci if (sampOffIdx != -1) 3089bf215546Sopenharmony_ci texi->tex.sIndirectSrc = sampOffIdx; 3090bf215546Sopenharmony_ci 3091bf215546Sopenharmony_ci switch (insn->op) { 3092bf215546Sopenharmony_ci case nir_texop_tg4: 3093bf215546Sopenharmony_ci if (!target.isShadow()) 3094bf215546Sopenharmony_ci texi->tex.gatherComp = insn->component; 3095bf215546Sopenharmony_ci break; 3096bf215546Sopenharmony_ci case nir_texop_txs: 3097bf215546Sopenharmony_ci texi->tex.query = TXQ_DIMS; 3098bf215546Sopenharmony_ci break; 3099bf215546Sopenharmony_ci case nir_texop_texture_samples: 3100bf215546Sopenharmony_ci texi->tex.mask = 0x4; 3101bf215546Sopenharmony_ci texi->tex.query = TXQ_TYPE; 3102bf215546Sopenharmony_ci break; 3103bf215546Sopenharmony_ci case nir_texop_query_levels: 3104bf215546Sopenharmony_ci texi->tex.mask = 0x8; 3105bf215546Sopenharmony_ci texi->tex.query = TXQ_DIMS; 3106bf215546Sopenharmony_ci break; 3107bf215546Sopenharmony_ci default: 3108bf215546Sopenharmony_ci break; 3109bf215546Sopenharmony_ci } 3110bf215546Sopenharmony_ci 3111bf215546Sopenharmony_ci texi->tex.useOffsets = offsets.size(); 3112bf215546Sopenharmony_ci if (texi->tex.useOffsets) { 3113bf215546Sopenharmony_ci for (uint8_t s = 0; s < texi->tex.useOffsets; ++s) { 3114bf215546Sopenharmony_ci for (uint32_t c = 0u; c < 3; ++c) { 3115bf215546Sopenharmony_ci uint8_t s2 = std::min(c, target.getDim() - 1); 3116bf215546Sopenharmony_ci texi->offset[s][c].set(getSrc(offsets[s], s2)); 3117bf215546Sopenharmony_ci texi->offset[s][c].setInsn(texi); 3118bf215546Sopenharmony_ci } 3119bf215546Sopenharmony_ci } 3120bf215546Sopenharmony_ci } 3121bf215546Sopenharmony_ci 3122bf215546Sopenharmony_ci if (op == OP_TXG && offsetIdx == -1) { 3123bf215546Sopenharmony_ci if (nir_tex_instr_has_explicit_tg4_offsets(insn)) { 3124bf215546Sopenharmony_ci texi->tex.useOffsets = 4; 3125bf215546Sopenharmony_ci setPosition(texi, false); 3126bf215546Sopenharmony_ci for (uint8_t i = 0; i < 4; ++i) { 3127bf215546Sopenharmony_ci for (uint8_t j = 0; j < 2; ++j) { 3128bf215546Sopenharmony_ci texi->offset[i][j].set(loadImm(NULL, insn->tg4_offsets[i][j])); 3129bf215546Sopenharmony_ci texi->offset[i][j].setInsn(texi); 3130bf215546Sopenharmony_ci } 3131bf215546Sopenharmony_ci } 3132bf215546Sopenharmony_ci setPosition(texi, true); 3133bf215546Sopenharmony_ci } 3134bf215546Sopenharmony_ci } 3135bf215546Sopenharmony_ci 3136bf215546Sopenharmony_ci if (ddxIdx != -1 && ddyIdx != -1) { 3137bf215546Sopenharmony_ci for (uint8_t c = 0u; c < target.getDim() + target.isCube(); ++c) { 3138bf215546Sopenharmony_ci texi->dPdx[c].set(getSrc(&insn->src[ddxIdx].src, c)); 3139bf215546Sopenharmony_ci texi->dPdy[c].set(getSrc(&insn->src[ddyIdx].src, c)); 3140bf215546Sopenharmony_ci } 3141bf215546Sopenharmony_ci } 3142bf215546Sopenharmony_ci 3143bf215546Sopenharmony_ci break; 3144bf215546Sopenharmony_ci } 3145bf215546Sopenharmony_ci default: 3146bf215546Sopenharmony_ci ERROR("unknown nir_texop %u\n", insn->op); 3147bf215546Sopenharmony_ci return false; 3148bf215546Sopenharmony_ci } 3149bf215546Sopenharmony_ci return true; 3150bf215546Sopenharmony_ci} 3151bf215546Sopenharmony_ci 3152bf215546Sopenharmony_ci/* nouveau's RA doesn't track the liveness of exported registers in the fragment 3153bf215546Sopenharmony_ci * shader, so we need all the store_outputs to appear at the end of the shader 3154bf215546Sopenharmony_ci * with no other instructions that might generate a temp value in between them. 3155bf215546Sopenharmony_ci */ 3156bf215546Sopenharmony_cistatic void 3157bf215546Sopenharmony_cinv_nir_move_stores_to_end(nir_shader *s) 3158bf215546Sopenharmony_ci{ 3159bf215546Sopenharmony_ci nir_function_impl *impl = nir_shader_get_entrypoint(s); 3160bf215546Sopenharmony_ci nir_block *block = nir_impl_last_block(impl); 3161bf215546Sopenharmony_ci nir_instr *first_store = NULL; 3162bf215546Sopenharmony_ci 3163bf215546Sopenharmony_ci nir_foreach_instr_safe(instr, block) { 3164bf215546Sopenharmony_ci if (instr == first_store) 3165bf215546Sopenharmony_ci break; 3166bf215546Sopenharmony_ci if (instr->type != nir_instr_type_intrinsic) 3167bf215546Sopenharmony_ci continue; 3168bf215546Sopenharmony_ci nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr); 3169bf215546Sopenharmony_ci if (intrin->intrinsic == nir_intrinsic_store_output) { 3170bf215546Sopenharmony_ci nir_instr_remove(instr); 3171bf215546Sopenharmony_ci nir_instr_insert(nir_after_block(block), instr); 3172bf215546Sopenharmony_ci 3173bf215546Sopenharmony_ci if (!first_store) 3174bf215546Sopenharmony_ci first_store = instr; 3175bf215546Sopenharmony_ci } 3176bf215546Sopenharmony_ci } 3177bf215546Sopenharmony_ci nir_metadata_preserve(impl, 3178bf215546Sopenharmony_ci nir_metadata_block_index | 3179bf215546Sopenharmony_ci nir_metadata_dominance); 3180bf215546Sopenharmony_ci} 3181bf215546Sopenharmony_ci 3182bf215546Sopenharmony_cibool 3183bf215546Sopenharmony_ciConverter::run() 3184bf215546Sopenharmony_ci{ 3185bf215546Sopenharmony_ci bool progress; 3186bf215546Sopenharmony_ci 3187bf215546Sopenharmony_ci if (prog->dbgFlags & NV50_IR_DEBUG_VERBOSE) 3188bf215546Sopenharmony_ci nir_print_shader(nir, stderr); 3189bf215546Sopenharmony_ci 3190bf215546Sopenharmony_ci struct nir_lower_subgroups_options subgroup_options = {}; 3191bf215546Sopenharmony_ci subgroup_options.subgroup_size = 32; 3192bf215546Sopenharmony_ci subgroup_options.ballot_bit_size = 32; 3193bf215546Sopenharmony_ci subgroup_options.ballot_components = 1; 3194bf215546Sopenharmony_ci subgroup_options.lower_elect = true; 3195bf215546Sopenharmony_ci 3196bf215546Sopenharmony_ci /* prepare for IO lowering */ 3197bf215546Sopenharmony_ci NIR_PASS_V(nir, nir_opt_deref); 3198bf215546Sopenharmony_ci NIR_PASS_V(nir, nir_lower_regs_to_ssa); 3199bf215546Sopenharmony_ci NIR_PASS_V(nir, nir_lower_vars_to_ssa); 3200bf215546Sopenharmony_ci 3201bf215546Sopenharmony_ci /* codegen assumes vec4 alignment for memory */ 3202bf215546Sopenharmony_ci NIR_PASS_V(nir, nir_lower_vars_to_explicit_types, nir_var_function_temp, function_temp_type_info); 3203bf215546Sopenharmony_ci NIR_PASS_V(nir, nir_lower_explicit_io, nir_var_function_temp, nir_address_format_32bit_offset); 3204bf215546Sopenharmony_ci NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_function_temp, NULL); 3205bf215546Sopenharmony_ci 3206bf215546Sopenharmony_ci NIR_PASS_V(nir, nir_lower_io, nir_var_shader_in | nir_var_shader_out, 3207bf215546Sopenharmony_ci type_size, (nir_lower_io_options)0); 3208bf215546Sopenharmony_ci 3209bf215546Sopenharmony_ci NIR_PASS_V(nir, nir_lower_subgroups, &subgroup_options); 3210bf215546Sopenharmony_ci 3211bf215546Sopenharmony_ci struct nir_lower_tex_options tex_options = {}; 3212bf215546Sopenharmony_ci tex_options.lower_txp = ~0; 3213bf215546Sopenharmony_ci 3214bf215546Sopenharmony_ci NIR_PASS_V(nir, nir_lower_tex, &tex_options); 3215bf215546Sopenharmony_ci 3216bf215546Sopenharmony_ci NIR_PASS_V(nir, nir_lower_load_const_to_scalar); 3217bf215546Sopenharmony_ci NIR_PASS_V(nir, nir_lower_alu_to_scalar, NULL, NULL); 3218bf215546Sopenharmony_ci NIR_PASS_V(nir, nir_lower_phis_to_scalar, false); 3219bf215546Sopenharmony_ci 3220bf215546Sopenharmony_ci /*TODO: improve this lowering/optimisation loop so that we can use 3221bf215546Sopenharmony_ci * nir_opt_idiv_const effectively before this. 3222bf215546Sopenharmony_ci */ 3223bf215546Sopenharmony_ci nir_lower_idiv_options idiv_options = { 3224bf215546Sopenharmony_ci .imprecise_32bit_lowering = false, 3225bf215546Sopenharmony_ci .allow_fp16 = true, 3226bf215546Sopenharmony_ci }; 3227bf215546Sopenharmony_ci NIR_PASS(progress, nir, nir_lower_idiv, &idiv_options); 3228bf215546Sopenharmony_ci 3229bf215546Sopenharmony_ci do { 3230bf215546Sopenharmony_ci progress = false; 3231bf215546Sopenharmony_ci NIR_PASS(progress, nir, nir_copy_prop); 3232bf215546Sopenharmony_ci NIR_PASS(progress, nir, nir_opt_remove_phis); 3233bf215546Sopenharmony_ci NIR_PASS(progress, nir, nir_opt_trivial_continues); 3234bf215546Sopenharmony_ci NIR_PASS(progress, nir, nir_opt_cse); 3235bf215546Sopenharmony_ci NIR_PASS(progress, nir, nir_opt_algebraic); 3236bf215546Sopenharmony_ci NIR_PASS(progress, nir, nir_opt_constant_folding); 3237bf215546Sopenharmony_ci NIR_PASS(progress, nir, nir_copy_prop); 3238bf215546Sopenharmony_ci NIR_PASS(progress, nir, nir_opt_dce); 3239bf215546Sopenharmony_ci NIR_PASS(progress, nir, nir_opt_dead_cf); 3240bf215546Sopenharmony_ci NIR_PASS(progress, nir, nir_lower_64bit_phis); 3241bf215546Sopenharmony_ci } while (progress); 3242bf215546Sopenharmony_ci 3243bf215546Sopenharmony_ci nir_move_options move_options = 3244bf215546Sopenharmony_ci (nir_move_options)(nir_move_const_undef | 3245bf215546Sopenharmony_ci nir_move_load_ubo | 3246bf215546Sopenharmony_ci nir_move_load_uniform | 3247bf215546Sopenharmony_ci nir_move_load_input); 3248bf215546Sopenharmony_ci NIR_PASS_V(nir, nir_opt_sink, move_options); 3249bf215546Sopenharmony_ci NIR_PASS_V(nir, nir_opt_move, move_options); 3250bf215546Sopenharmony_ci 3251bf215546Sopenharmony_ci if (nir->info.stage == MESA_SHADER_FRAGMENT) 3252bf215546Sopenharmony_ci NIR_PASS_V(nir, nv_nir_move_stores_to_end); 3253bf215546Sopenharmony_ci 3254bf215546Sopenharmony_ci NIR_PASS_V(nir, nir_lower_bool_to_int32); 3255bf215546Sopenharmony_ci NIR_PASS_V(nir, nir_convert_from_ssa, true); 3256bf215546Sopenharmony_ci 3257bf215546Sopenharmony_ci // Garbage collect dead instructions 3258bf215546Sopenharmony_ci nir_sweep(nir); 3259bf215546Sopenharmony_ci 3260bf215546Sopenharmony_ci if (!parseNIR()) { 3261bf215546Sopenharmony_ci ERROR("Couldn't prase NIR!\n"); 3262bf215546Sopenharmony_ci return false; 3263bf215546Sopenharmony_ci } 3264bf215546Sopenharmony_ci 3265bf215546Sopenharmony_ci if (!assignSlots()) { 3266bf215546Sopenharmony_ci ERROR("Couldn't assign slots!\n"); 3267bf215546Sopenharmony_ci return false; 3268bf215546Sopenharmony_ci } 3269bf215546Sopenharmony_ci 3270bf215546Sopenharmony_ci if (prog->dbgFlags & NV50_IR_DEBUG_BASIC) 3271bf215546Sopenharmony_ci nir_print_shader(nir, stderr); 3272bf215546Sopenharmony_ci 3273bf215546Sopenharmony_ci nir_foreach_function(function, nir) { 3274bf215546Sopenharmony_ci if (!visit(function)) 3275bf215546Sopenharmony_ci return false; 3276bf215546Sopenharmony_ci } 3277bf215546Sopenharmony_ci 3278bf215546Sopenharmony_ci return true; 3279bf215546Sopenharmony_ci} 3280bf215546Sopenharmony_ci 3281bf215546Sopenharmony_ci} // unnamed namespace 3282bf215546Sopenharmony_ci 3283bf215546Sopenharmony_cinamespace nv50_ir { 3284bf215546Sopenharmony_ci 3285bf215546Sopenharmony_cibool 3286bf215546Sopenharmony_ciProgram::makeFromNIR(struct nv50_ir_prog_info *info, 3287bf215546Sopenharmony_ci struct nv50_ir_prog_info_out *info_out) 3288bf215546Sopenharmony_ci{ 3289bf215546Sopenharmony_ci nir_shader *nir = (nir_shader*)info->bin.source; 3290bf215546Sopenharmony_ci Converter converter(this, nir, info, info_out); 3291bf215546Sopenharmony_ci bool result = converter.run(); 3292bf215546Sopenharmony_ci if (!result) 3293bf215546Sopenharmony_ci return result; 3294bf215546Sopenharmony_ci LoweringHelper lowering; 3295bf215546Sopenharmony_ci lowering.run(this); 3296bf215546Sopenharmony_ci tlsSize = info_out->bin.tlsSpace; 3297bf215546Sopenharmony_ci return result; 3298bf215546Sopenharmony_ci} 3299bf215546Sopenharmony_ci 3300bf215546Sopenharmony_ci} // namespace nv50_ir 3301bf215546Sopenharmony_ci 3302bf215546Sopenharmony_cistatic nir_shader_compiler_options 3303bf215546Sopenharmony_cinvir_nir_shader_compiler_options(int chipset, uint8_t shader_type) 3304bf215546Sopenharmony_ci{ 3305bf215546Sopenharmony_ci nir_shader_compiler_options op = {}; 3306bf215546Sopenharmony_ci op.lower_fdiv = (chipset >= NVISA_GV100_CHIPSET); 3307bf215546Sopenharmony_ci op.lower_ffma16 = false; 3308bf215546Sopenharmony_ci op.lower_ffma32 = false; 3309bf215546Sopenharmony_ci op.lower_ffma64 = false; 3310bf215546Sopenharmony_ci op.fuse_ffma16 = false; /* nir doesn't track mad vs fma */ 3311bf215546Sopenharmony_ci op.fuse_ffma32 = false; /* nir doesn't track mad vs fma */ 3312bf215546Sopenharmony_ci op.fuse_ffma64 = false; /* nir doesn't track mad vs fma */ 3313bf215546Sopenharmony_ci op.lower_flrp16 = (chipset >= NVISA_GV100_CHIPSET); 3314bf215546Sopenharmony_ci op.lower_flrp32 = true; 3315bf215546Sopenharmony_ci op.lower_flrp64 = true; 3316bf215546Sopenharmony_ci op.lower_fpow = false; // TODO: nir's lowering is broken, or we could use it 3317bf215546Sopenharmony_ci op.lower_fsat = false; 3318bf215546Sopenharmony_ci op.lower_fsqrt = false; // TODO: only before gm200 3319bf215546Sopenharmony_ci op.lower_sincos = false; 3320bf215546Sopenharmony_ci op.lower_fmod = true; 3321bf215546Sopenharmony_ci op.lower_bitfield_extract = false; 3322bf215546Sopenharmony_ci op.lower_bitfield_extract_to_shifts = (chipset >= NVISA_GV100_CHIPSET || chipset < NVISA_GF100_CHIPSET); 3323bf215546Sopenharmony_ci op.lower_bitfield_insert = false; 3324bf215546Sopenharmony_ci op.lower_bitfield_insert_to_shifts = (chipset >= NVISA_GV100_CHIPSET || chipset < NVISA_GF100_CHIPSET); 3325bf215546Sopenharmony_ci op.lower_bitfield_insert_to_bitfield_select = false; 3326bf215546Sopenharmony_ci op.lower_bitfield_reverse = (chipset < NVISA_GF100_CHIPSET); 3327bf215546Sopenharmony_ci op.lower_bit_count = (chipset < NVISA_GF100_CHIPSET); 3328bf215546Sopenharmony_ci op.lower_ifind_msb = (chipset < NVISA_GF100_CHIPSET); 3329bf215546Sopenharmony_ci op.lower_find_lsb = (chipset < NVISA_GF100_CHIPSET); 3330bf215546Sopenharmony_ci op.lower_uadd_carry = true; // TODO 3331bf215546Sopenharmony_ci op.lower_usub_borrow = true; // TODO 3332bf215546Sopenharmony_ci op.lower_mul_high = false; 3333bf215546Sopenharmony_ci op.lower_fneg = false; 3334bf215546Sopenharmony_ci op.lower_ineg = false; 3335bf215546Sopenharmony_ci op.lower_scmp = true; // TODO: not implemented yet 3336bf215546Sopenharmony_ci op.lower_vector_cmp = false; 3337bf215546Sopenharmony_ci op.lower_bitops = false; 3338bf215546Sopenharmony_ci op.lower_isign = (chipset >= NVISA_GV100_CHIPSET); 3339bf215546Sopenharmony_ci op.lower_fsign = (chipset >= NVISA_GV100_CHIPSET); 3340bf215546Sopenharmony_ci op.lower_fdph = false; 3341bf215546Sopenharmony_ci op.lower_fdot = false; 3342bf215546Sopenharmony_ci op.fdot_replicates = false; // TODO 3343bf215546Sopenharmony_ci op.lower_ffloor = false; // TODO 3344bf215546Sopenharmony_ci op.lower_ffract = true; 3345bf215546Sopenharmony_ci op.lower_fceil = false; // TODO 3346bf215546Sopenharmony_ci op.lower_ftrunc = false; 3347bf215546Sopenharmony_ci op.lower_ldexp = true; 3348bf215546Sopenharmony_ci op.lower_pack_half_2x16 = true; 3349bf215546Sopenharmony_ci op.lower_pack_unorm_2x16 = true; 3350bf215546Sopenharmony_ci op.lower_pack_snorm_2x16 = true; 3351bf215546Sopenharmony_ci op.lower_pack_unorm_4x8 = true; 3352bf215546Sopenharmony_ci op.lower_pack_snorm_4x8 = true; 3353bf215546Sopenharmony_ci op.lower_unpack_half_2x16 = true; 3354bf215546Sopenharmony_ci op.lower_unpack_unorm_2x16 = true; 3355bf215546Sopenharmony_ci op.lower_unpack_snorm_2x16 = true; 3356bf215546Sopenharmony_ci op.lower_unpack_unorm_4x8 = true; 3357bf215546Sopenharmony_ci op.lower_unpack_snorm_4x8 = true; 3358bf215546Sopenharmony_ci op.lower_pack_split = false; 3359bf215546Sopenharmony_ci op.lower_extract_byte = (chipset < NVISA_GM107_CHIPSET); 3360bf215546Sopenharmony_ci op.lower_extract_word = (chipset < NVISA_GM107_CHIPSET); 3361bf215546Sopenharmony_ci op.lower_insert_byte = true; 3362bf215546Sopenharmony_ci op.lower_insert_word = true; 3363bf215546Sopenharmony_ci op.lower_all_io_to_temps = false; 3364bf215546Sopenharmony_ci op.lower_all_io_to_elements = false; 3365bf215546Sopenharmony_ci op.vertex_id_zero_based = false; 3366bf215546Sopenharmony_ci op.lower_base_vertex = false; 3367bf215546Sopenharmony_ci op.lower_helper_invocation = false; 3368bf215546Sopenharmony_ci op.optimize_sample_mask_in = false; 3369bf215546Sopenharmony_ci op.lower_cs_local_index_to_id = true; 3370bf215546Sopenharmony_ci op.lower_cs_local_id_to_index = false; 3371bf215546Sopenharmony_ci op.lower_device_index_to_zero = false; // TODO 3372bf215546Sopenharmony_ci op.lower_wpos_pntc = false; // TODO 3373bf215546Sopenharmony_ci op.lower_hadd = true; // TODO 3374bf215546Sopenharmony_ci op.lower_uadd_sat = true; // TODO 3375bf215546Sopenharmony_ci op.lower_usub_sat = true; // TODO 3376bf215546Sopenharmony_ci op.lower_iadd_sat = true; // TODO 3377bf215546Sopenharmony_ci op.vectorize_io = false; 3378bf215546Sopenharmony_ci op.lower_to_scalar = false; 3379bf215546Sopenharmony_ci op.unify_interfaces = false; 3380bf215546Sopenharmony_ci op.use_interpolated_input_intrinsics = true; 3381bf215546Sopenharmony_ci op.lower_mul_2x32_64 = true; // TODO 3382bf215546Sopenharmony_ci op.lower_rotate = (chipset < NVISA_GV100_CHIPSET); 3383bf215546Sopenharmony_ci op.has_imul24 = false; 3384bf215546Sopenharmony_ci op.intel_vec4 = false; 3385bf215546Sopenharmony_ci op.force_indirect_unrolling = (nir_variable_mode) ( 3386bf215546Sopenharmony_ci ((shader_type == PIPE_SHADER_FRAGMENT) ? nir_var_shader_out : 0) | 3387bf215546Sopenharmony_ci /* HW doesn't support indirect addressing of fragment program inputs 3388bf215546Sopenharmony_ci * on Volta. The binary driver generates a function to handle every 3389bf215546Sopenharmony_ci * possible indirection, and indirectly calls the function to handle 3390bf215546Sopenharmony_ci * this instead. 3391bf215546Sopenharmony_ci */ 3392bf215546Sopenharmony_ci ((chipset >= NVISA_GV100_CHIPSET && shader_type == PIPE_SHADER_FRAGMENT) ? nir_var_shader_in : 0) 3393bf215546Sopenharmony_ci ); 3394bf215546Sopenharmony_ci op.force_indirect_unrolling_sampler = (chipset < NVISA_GF100_CHIPSET), 3395bf215546Sopenharmony_ci op.max_unroll_iterations = 32; 3396bf215546Sopenharmony_ci op.lower_int64_options = (nir_lower_int64_options) ( 3397bf215546Sopenharmony_ci ((chipset >= NVISA_GV100_CHIPSET) ? nir_lower_imul64 : 0) | 3398bf215546Sopenharmony_ci ((chipset >= NVISA_GV100_CHIPSET) ? nir_lower_isign64 : 0) | 3399bf215546Sopenharmony_ci nir_lower_divmod64 | 3400bf215546Sopenharmony_ci ((chipset >= NVISA_GV100_CHIPSET) ? nir_lower_imul_high64 : 0) | 3401bf215546Sopenharmony_ci ((chipset >= NVISA_GV100_CHIPSET) ? nir_lower_mov64 : 0) | 3402bf215546Sopenharmony_ci ((chipset >= NVISA_GV100_CHIPSET) ? nir_lower_icmp64 : 0) | 3403bf215546Sopenharmony_ci ((chipset >= NVISA_GV100_CHIPSET) ? nir_lower_iabs64 : 0) | 3404bf215546Sopenharmony_ci ((chipset >= NVISA_GV100_CHIPSET) ? nir_lower_ineg64 : 0) | 3405bf215546Sopenharmony_ci ((chipset >= NVISA_GV100_CHIPSET) ? nir_lower_logic64 : 0) | 3406bf215546Sopenharmony_ci ((chipset >= NVISA_GV100_CHIPSET) ? nir_lower_minmax64 : 0) | 3407bf215546Sopenharmony_ci ((chipset >= NVISA_GV100_CHIPSET) ? nir_lower_shift64 : 0) | 3408bf215546Sopenharmony_ci nir_lower_imul_2x32_64 | 3409bf215546Sopenharmony_ci ((chipset >= NVISA_GM107_CHIPSET) ? nir_lower_extract64 : 0) | 3410bf215546Sopenharmony_ci nir_lower_ufind_msb64 3411bf215546Sopenharmony_ci ); 3412bf215546Sopenharmony_ci op.lower_doubles_options = (nir_lower_doubles_options) ( 3413bf215546Sopenharmony_ci ((chipset >= NVISA_GV100_CHIPSET) ? nir_lower_drcp : 0) | 3414bf215546Sopenharmony_ci ((chipset >= NVISA_GV100_CHIPSET) ? nir_lower_dsqrt : 0) | 3415bf215546Sopenharmony_ci ((chipset >= NVISA_GV100_CHIPSET) ? nir_lower_drsq : 0) | 3416bf215546Sopenharmony_ci ((chipset >= NVISA_GV100_CHIPSET) ? nir_lower_dfract : 0) | 3417bf215546Sopenharmony_ci nir_lower_dmod | 3418bf215546Sopenharmony_ci ((chipset >= NVISA_GV100_CHIPSET) ? nir_lower_dsub : 0) | 3419bf215546Sopenharmony_ci ((chipset >= NVISA_GV100_CHIPSET) ? nir_lower_ddiv : 0) 3420bf215546Sopenharmony_ci ); 3421bf215546Sopenharmony_ci return op; 3422bf215546Sopenharmony_ci} 3423bf215546Sopenharmony_ci 3424bf215546Sopenharmony_cistatic const nir_shader_compiler_options g80_nir_shader_compiler_options = 3425bf215546Sopenharmony_cinvir_nir_shader_compiler_options(NVISA_G80_CHIPSET, PIPE_SHADER_TYPES); 3426bf215546Sopenharmony_cistatic const nir_shader_compiler_options g80_fs_nir_shader_compiler_options = 3427bf215546Sopenharmony_cinvir_nir_shader_compiler_options(NVISA_G80_CHIPSET, PIPE_SHADER_FRAGMENT); 3428bf215546Sopenharmony_cistatic const nir_shader_compiler_options gf100_nir_shader_compiler_options = 3429bf215546Sopenharmony_cinvir_nir_shader_compiler_options(NVISA_GF100_CHIPSET, PIPE_SHADER_TYPES); 3430bf215546Sopenharmony_cistatic const nir_shader_compiler_options gf100_fs_nir_shader_compiler_options = 3431bf215546Sopenharmony_cinvir_nir_shader_compiler_options(NVISA_GF100_CHIPSET, PIPE_SHADER_FRAGMENT); 3432bf215546Sopenharmony_cistatic const nir_shader_compiler_options gm107_nir_shader_compiler_options = 3433bf215546Sopenharmony_cinvir_nir_shader_compiler_options(NVISA_GM107_CHIPSET, PIPE_SHADER_TYPES); 3434bf215546Sopenharmony_cistatic const nir_shader_compiler_options gm107_fs_nir_shader_compiler_options = 3435bf215546Sopenharmony_cinvir_nir_shader_compiler_options(NVISA_GM107_CHIPSET, PIPE_SHADER_FRAGMENT); 3436bf215546Sopenharmony_cistatic const nir_shader_compiler_options gv100_nir_shader_compiler_options = 3437bf215546Sopenharmony_cinvir_nir_shader_compiler_options(NVISA_GV100_CHIPSET, PIPE_SHADER_TYPES); 3438bf215546Sopenharmony_cistatic const nir_shader_compiler_options gv100_fs_nir_shader_compiler_options = 3439bf215546Sopenharmony_cinvir_nir_shader_compiler_options(NVISA_GV100_CHIPSET, PIPE_SHADER_FRAGMENT); 3440bf215546Sopenharmony_ci 3441bf215546Sopenharmony_ciconst nir_shader_compiler_options * 3442bf215546Sopenharmony_cinv50_ir_nir_shader_compiler_options(int chipset, uint8_t shader_type) 3443bf215546Sopenharmony_ci{ 3444bf215546Sopenharmony_ci if (chipset >= NVISA_GV100_CHIPSET) { 3445bf215546Sopenharmony_ci if (shader_type == PIPE_SHADER_FRAGMENT) 3446bf215546Sopenharmony_ci return &gv100_fs_nir_shader_compiler_options; 3447bf215546Sopenharmony_ci else 3448bf215546Sopenharmony_ci return &gv100_nir_shader_compiler_options; 3449bf215546Sopenharmony_ci } 3450bf215546Sopenharmony_ci 3451bf215546Sopenharmony_ci if (chipset >= NVISA_GM107_CHIPSET) { 3452bf215546Sopenharmony_ci if (shader_type == PIPE_SHADER_FRAGMENT) 3453bf215546Sopenharmony_ci return &gm107_fs_nir_shader_compiler_options; 3454bf215546Sopenharmony_ci else 3455bf215546Sopenharmony_ci return &gm107_nir_shader_compiler_options; 3456bf215546Sopenharmony_ci } 3457bf215546Sopenharmony_ci 3458bf215546Sopenharmony_ci if (chipset >= NVISA_GF100_CHIPSET) { 3459bf215546Sopenharmony_ci if (shader_type == PIPE_SHADER_FRAGMENT) 3460bf215546Sopenharmony_ci return &gf100_fs_nir_shader_compiler_options; 3461bf215546Sopenharmony_ci else 3462bf215546Sopenharmony_ci return &gf100_nir_shader_compiler_options; 3463bf215546Sopenharmony_ci } 3464bf215546Sopenharmony_ci 3465bf215546Sopenharmony_ci if (shader_type == PIPE_SHADER_FRAGMENT) 3466bf215546Sopenharmony_ci return &g80_fs_nir_shader_compiler_options; 3467bf215546Sopenharmony_ci else 3468bf215546Sopenharmony_ci return &g80_nir_shader_compiler_options; 3469bf215546Sopenharmony_ci} 3470