1bf215546Sopenharmony_ci#ifndef __NVFX_SHADER_H__ 2bf215546Sopenharmony_ci#define __NVFX_SHADER_H__ 3bf215546Sopenharmony_ci 4bf215546Sopenharmony_ci#include <stdint.h> 5bf215546Sopenharmony_ci 6bf215546Sopenharmony_ci#include "pipe/p_compiler.h" 7bf215546Sopenharmony_ci 8bf215546Sopenharmony_ci#define NVFX_SWZ_IDENTITY ((3 << 6) | (2 << 4) | (1 << 2) | (0 << 0)) 9bf215546Sopenharmony_ci 10bf215546Sopenharmony_ci/* this will resolve to either the NV30 or the NV40 version 11bf215546Sopenharmony_ci * depending on the current hardware */ 12bf215546Sopenharmony_ci/* unusual, but very fast and compact method */ 13bf215546Sopenharmony_ci#define NVFX_VP(c) ((NV30_VP_##c) + (vpc->is_nv4x & ((NV40_VP_##c) - (NV30_VP_##c)))) 14bf215546Sopenharmony_ci 15bf215546Sopenharmony_ci#define NVFX_VP_INST_SLOT_VEC 0 16bf215546Sopenharmony_ci#define NVFX_VP_INST_SLOT_SCA 1 17bf215546Sopenharmony_ci 18bf215546Sopenharmony_ci#define NVFX_VP_INST_IN_POS 0 /* These seem to match the bindings specified in */ 19bf215546Sopenharmony_ci#define NVFX_VP_INST_IN_WEIGHT 1 /* the ARB_v_p spec (2.14.3.1) */ 20bf215546Sopenharmony_ci#define NVFX_VP_INST_IN_NORMAL 2 21bf215546Sopenharmony_ci#define NVFX_VP_INST_IN_COL0 3 /* Should probably confirm them all though */ 22bf215546Sopenharmony_ci#define NVFX_VP_INST_IN_COL1 4 23bf215546Sopenharmony_ci#define NVFX_VP_INST_IN_FOGC 5 24bf215546Sopenharmony_ci#define NVFX_VP_INST_IN_TC0 8 25bf215546Sopenharmony_ci#define NVFX_VP_INST_IN_TC(n) (8+n) 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci#define NVFX_VP_INST_SCA_OP_NOP 0x00 28bf215546Sopenharmony_ci#define NVFX_VP_INST_SCA_OP_MOV 0x01 29bf215546Sopenharmony_ci#define NVFX_VP_INST_SCA_OP_RCP 0x02 30bf215546Sopenharmony_ci#define NVFX_VP_INST_SCA_OP_RCC 0x03 31bf215546Sopenharmony_ci#define NVFX_VP_INST_SCA_OP_RSQ 0x04 32bf215546Sopenharmony_ci#define NVFX_VP_INST_SCA_OP_EXP 0x05 33bf215546Sopenharmony_ci#define NVFX_VP_INST_SCA_OP_LOG 0x06 34bf215546Sopenharmony_ci#define NVFX_VP_INST_SCA_OP_LIT 0x07 35bf215546Sopenharmony_ci#define NVFX_VP_INST_SCA_OP_BRA 0x09 36bf215546Sopenharmony_ci#define NVFX_VP_INST_SCA_OP_CAL 0x0B 37bf215546Sopenharmony_ci#define NVFX_VP_INST_SCA_OP_RET 0x0C 38bf215546Sopenharmony_ci#define NVFX_VP_INST_SCA_OP_LG2 0x0D 39bf215546Sopenharmony_ci#define NVFX_VP_INST_SCA_OP_EX2 0x0E 40bf215546Sopenharmony_ci#define NVFX_VP_INST_SCA_OP_SIN 0x0F 41bf215546Sopenharmony_ci#define NVFX_VP_INST_SCA_OP_COS 0x10 42bf215546Sopenharmony_ci 43bf215546Sopenharmony_ci#define NV40_VP_INST_SCA_OP_PUSHA 0x13 44bf215546Sopenharmony_ci#define NV40_VP_INST_SCA_OP_POPA 0x14 45bf215546Sopenharmony_ci 46bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_NOP 0x00 47bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_MOV 0x01 48bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_MUL 0x02 49bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_ADD 0x03 50bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_MAD 0x04 51bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_DP3 0x05 52bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_DPH 0x06 53bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_DP4 0x07 54bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_DST 0x08 55bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_MIN 0x09 56bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_MAX 0x0A 57bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_SLT 0x0B 58bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_SGE 0x0C 59bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_ARL 0x0D 60bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_FRC 0x0E 61bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_FLR 0x0F 62bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_SEQ 0x10 63bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_SFL 0x11 64bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_SGT 0x12 65bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_SLE 0x13 66bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_SNE 0x14 67bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_STR 0x15 68bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_SSG 0x16 69bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_ARR 0x17 70bf215546Sopenharmony_ci#define NVFX_VP_INST_VEC_OP_ARA 0x18 71bf215546Sopenharmony_ci 72bf215546Sopenharmony_ci#define NV40_VP_INST_VEC_OP_TXL 0x19 73bf215546Sopenharmony_ci 74bf215546Sopenharmony_ci/* DWORD 3 */ 75bf215546Sopenharmony_ci#define NVFX_VP_INST_LAST (1 << 0) 76bf215546Sopenharmony_ci 77bf215546Sopenharmony_ci/* 78bf215546Sopenharmony_ci * Each fragment program opcode appears to be comprised of 4 32-bit values. 79bf215546Sopenharmony_ci * 80bf215546Sopenharmony_ci * 0: OPDEST 81bf215546Sopenharmony_ci * 0: program end 82bf215546Sopenharmony_ci * 1-6: destination register 83bf215546Sopenharmony_ci * 7: destination register is fp16?? (use for outputs) 84bf215546Sopenharmony_ci * 8: set condition code 85bf215546Sopenharmony_ci * 9: writemask x 86bf215546Sopenharmony_ci * 10: writemask y 87bf215546Sopenharmony_ci * 11: writemask z 88bf215546Sopenharmony_ci * 12: writemask w 89bf215546Sopenharmony_ci * 13-16: source attribute register number (e.g. COL0) 90bf215546Sopenharmony_ci * 17-20: texture unit number 91bf215546Sopenharmony_ci * 21: expand value on texture operation (x -> 2x - 1) 92bf215546Sopenharmony_ci * 22-23: precision 0 = fp32, 1 = fp16, 2 = s1.10 fixed, 3 = s0.8 fixed (nv40-only)) 93bf215546Sopenharmony_ci * 24-29: opcode 94bf215546Sopenharmony_ci * 30: no destination 95bf215546Sopenharmony_ci * 31: saturate 96bf215546Sopenharmony_ci * 1 - SRC0 97bf215546Sopenharmony_ci * 0-17: see common source fields 98bf215546Sopenharmony_ci * 18: execute if condition code less 99bf215546Sopenharmony_ci * 19: execute if condition code equal 100bf215546Sopenharmony_ci * 20: execute if condition code greater 101bf215546Sopenharmony_ci * 21-22: condition code swizzle x source component 102bf215546Sopenharmony_ci * 23-24: condition code swizzle y source component 103bf215546Sopenharmony_ci * 25-26: condition code swizzle z source component 104bf215546Sopenharmony_ci * 27-28: condition code swizzle w source component 105bf215546Sopenharmony_ci * 29: source 0 absolute 106bf215546Sopenharmony_ci * 30: always 0 in renouveau tests 107bf215546Sopenharmony_ci * 31: always 0 in renouveau tests 108bf215546Sopenharmony_ci * 2 - SRC1 109bf215546Sopenharmony_ci * 0-17: see common source fields 110bf215546Sopenharmony_ci * 18: source 1 absolute 111bf215546Sopenharmony_ci * 19-20: input precision 0 = fp32, 1 = fp16, 2 = s1.10 fixed, 3 = ??? 112bf215546Sopenharmony_ci * 21-27: always 0 in renouveau tests 113bf215546Sopenharmony_ci * 28-30: scale (0 = 1x, 1 = 2x, 2 = 4x, 3 = 8x, 4 = ???, 5, = 1/2, 6 = 1/4, 7 = 1/8) 114bf215546Sopenharmony_ci * 31: opcode is branch 115bf215546Sopenharmony_ci * 3 - SRC2 116bf215546Sopenharmony_ci * 0-17: see common source fields 117bf215546Sopenharmony_ci * 18: source 2 absolute 118bf215546Sopenharmony_ci * 19-29: address register displacement 119bf215546Sopenharmony_ci * 30: use index register 120bf215546Sopenharmony_ci * 31: disable perspective-correct interpolation? 121bf215546Sopenharmony_ci * 122bf215546Sopenharmony_ci* Common fields of 0, 1, 2 - SRC 123bf215546Sopenharmony_ci * 0-1: source register type (0 = temp, 1 = input, 2 = immediate, 3 = ???) 124bf215546Sopenharmony_ci * 2-7: source temp register index 125bf215546Sopenharmony_ci * 8: source register is fp16?? 126bf215546Sopenharmony_ci * 9-10: source swizzle x source component 127bf215546Sopenharmony_ci * 11-12: source swizzle y source component 128bf215546Sopenharmony_ci * 13-14: source swizzle z source component 129bf215546Sopenharmony_ci * 15-16: source swizzle w source component 130bf215546Sopenharmony_ci * 17: negate 131bf215546Sopenharmony_ci 132bf215546Sopenharmony_ci * There appears to be no special difference between result regs and temp regs. 133bf215546Sopenharmony_ci * result.color == R0.xyzw 134bf215546Sopenharmony_ci * result.depth == R1.z 135bf215546Sopenharmony_ci * When the fragprog contains instructions to write depth, NV30_TCL_PRIMITIVE_3D_UNK1D78=0 136bf215546Sopenharmony_ci * otherwise it is set to 1. 137bf215546Sopenharmony_ci * 138bf215546Sopenharmony_ci * Constants are inserted directly after the instruction that uses them. 139bf215546Sopenharmony_ci * 140bf215546Sopenharmony_ci * It appears that it's not possible to use two input registers in one 141bf215546Sopenharmony_ci * instruction as the input sourcing is done in the instruction dword 142bf215546Sopenharmony_ci * and not the source selection dwords. As such instructions such as: 143bf215546Sopenharmony_ci * 144bf215546Sopenharmony_ci * ADD result.color, fragment.color, fragment.texcoord[0]; 145bf215546Sopenharmony_ci * 146bf215546Sopenharmony_ci * must be split into two MOV's and then an ADD (nvidia does this) but 147bf215546Sopenharmony_ci * I'm not sure why it's not just one MOV and then source the second input 148bf215546Sopenharmony_ci * in the ADD instruction.. 149bf215546Sopenharmony_ci * 150bf215546Sopenharmony_ci * Negation of the full source is done with NV30_FP_REG_NEGATE, arbitrary 151bf215546Sopenharmony_ci * negation requires multiplication with a const. 152bf215546Sopenharmony_ci * 153bf215546Sopenharmony_ci * Arbitrary swizzling is supported with the exception of SWIZZLE_ZERO/SWIZZLE_ONE 154bf215546Sopenharmony_ci * The temp/result regs appear to be initialised to (0.0, 0.0, 0.0, 0.0) as SWIZZLE_ZERO 155bf215546Sopenharmony_ci * is implemented simply by not writing to the relevant components of the destination. 156bf215546Sopenharmony_ci * 157bf215546Sopenharmony_ci * Conditional execution 158bf215546Sopenharmony_ci * TODO 159bf215546Sopenharmony_ci * 160bf215546Sopenharmony_ci * Non-native instructions: 161bf215546Sopenharmony_ci * LIT 162bf215546Sopenharmony_ci * LRP - MAD+MAD 163bf215546Sopenharmony_ci * SUB - ADD, negate second source 164bf215546Sopenharmony_ci * RSQ - LG2 + EX2 165bf215546Sopenharmony_ci * POW - LG2 + MUL + EX2 166bf215546Sopenharmony_ci * 167bf215546Sopenharmony_ci * NV40 Looping 168bf215546Sopenharmony_ci * Loops appear to be fairly expensive on NV40 at least, the proprietary 169bf215546Sopenharmony_ci * driver goes to a lot of effort to avoid using the native looping 170bf215546Sopenharmony_ci * instructions. If the total number of *executed* instructions between 171bf215546Sopenharmony_ci * REP/ENDREP or LOOP/ENDLOOP is <=500, the driver will unroll the loop. 172bf215546Sopenharmony_ci * The maximum loop count is 255. 173bf215546Sopenharmony_ci * 174bf215546Sopenharmony_ci */ 175bf215546Sopenharmony_ci 176bf215546Sopenharmony_ci//== Opcode / Destination selection == 177bf215546Sopenharmony_ci#define NVFX_FP_OP_PROGRAM_END (1 << 0) 178bf215546Sopenharmony_ci#define NVFX_FP_OP_OUT_REG_SHIFT 1 179bf215546Sopenharmony_ci#define NV30_FP_OP_OUT_REG_MASK (31 << 1) /* uncertain */ 180bf215546Sopenharmony_ci#define NV40_FP_OP_OUT_REG_MASK (63 << 1) 181bf215546Sopenharmony_ci/* Needs to be set when writing outputs to get expected result.. */ 182bf215546Sopenharmony_ci#define NVFX_FP_OP_OUT_REG_HALF (1 << 7) 183bf215546Sopenharmony_ci#define NVFX_FP_OP_COND_WRITE_ENABLE (1 << 8) 184bf215546Sopenharmony_ci#define NVFX_FP_OP_OUTMASK_SHIFT 9 185bf215546Sopenharmony_ci#define NVFX_FP_OP_OUTMASK_MASK (0xF << 9) 186bf215546Sopenharmony_ci# define NVFX_FP_OP_OUT_X (1<<9) 187bf215546Sopenharmony_ci# define NVFX_FP_OP_OUT_Y (1<<10) 188bf215546Sopenharmony_ci# define NVFX_FP_OP_OUT_Z (1<<11) 189bf215546Sopenharmony_ci# define NVFX_FP_OP_OUT_W (1<<12) 190bf215546Sopenharmony_ci/* Uncertain about these, especially the input_src values.. it's possible that 191bf215546Sopenharmony_ci * they can be dynamically changed. 192bf215546Sopenharmony_ci */ 193bf215546Sopenharmony_ci#define NVFX_FP_OP_INPUT_SRC_SHIFT 13 194bf215546Sopenharmony_ci#define NVFX_FP_OP_INPUT_SRC_MASK (15 << 13) 195bf215546Sopenharmony_ci# define NVFX_FP_OP_INPUT_SRC_POSITION 0x0 196bf215546Sopenharmony_ci# define NVFX_FP_OP_INPUT_SRC_COL0 0x1 197bf215546Sopenharmony_ci# define NVFX_FP_OP_INPUT_SRC_COL1 0x2 198bf215546Sopenharmony_ci# define NVFX_FP_OP_INPUT_SRC_FOGC 0x3 199bf215546Sopenharmony_ci# define NVFX_FP_OP_INPUT_SRC_TC0 0x4 200bf215546Sopenharmony_ci# define NVFX_FP_OP_INPUT_SRC_TC(n) (0x4 + n) 201bf215546Sopenharmony_ci# define NV40_FP_OP_INPUT_SRC_FACING 0xE 202bf215546Sopenharmony_ci#define NVFX_FP_OP_TEX_UNIT_SHIFT 17 203bf215546Sopenharmony_ci#define NVFX_FP_OP_TEX_UNIT_MASK (0xF << 17) /* guess */ 204bf215546Sopenharmony_ci#define NVFX_FP_OP_PRECISION_SHIFT 22 205bf215546Sopenharmony_ci#define NVFX_FP_OP_PRECISION_MASK (3 << 22) 206bf215546Sopenharmony_ci# define NVFX_FP_PRECISION_FP32 0 207bf215546Sopenharmony_ci# define NVFX_FP_PRECISION_FP16 1 208bf215546Sopenharmony_ci# define NVFX_FP_PRECISION_FX12 2 209bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_SHIFT 24 210bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_MASK (0x3F << 24) 211bf215546Sopenharmony_ci/* NV30/NV40 fragment program opcodes */ 212bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_NOP 0x00 213bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_MOV 0x01 214bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_MUL 0x02 215bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_ADD 0x03 216bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_MAD 0x04 217bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_DP3 0x05 218bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_DP4 0x06 219bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_DST 0x07 220bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_MIN 0x08 221bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_MAX 0x09 222bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_SLT 0x0A 223bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_SGE 0x0B 224bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_SLE 0x0C 225bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_SGT 0x0D 226bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_SNE 0x0E 227bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_SEQ 0x0F 228bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_FRC 0x10 229bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_FLR 0x11 230bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_KIL 0x12 231bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_PK4B 0x13 232bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_UP4B 0x14 233bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_DDX 0x15 /* can only write XY */ 234bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_DDY 0x16 /* can only write XY */ 235bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_TEX 0x17 236bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_TXP 0x18 237bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_TXD 0x19 238bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_RCP 0x1A 239bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_EX2 0x1C 240bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_LG2 0x1D 241bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_STR 0x20 242bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_SFL 0x21 243bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_COS 0x22 244bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_SIN 0x23 245bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_PK2H 0x24 246bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_UP2H 0x25 247bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_PK4UB 0x27 248bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_UP4UB 0x28 249bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_PK2US 0x29 250bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_UP2US 0x2A 251bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_DP2A 0x2E 252bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_TXB 0x31 253bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_DIV 0x3A 254bf215546Sopenharmony_ci 255bf215546Sopenharmony_ci/* NV30 only fragment program opcodes */ 256bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_RSQ_NV30 0x1B 257bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_LIT_NV30 0x1E 258bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_LRP_NV30 0x1F 259bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_POW_NV30 0x26 260bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_RFL_NV30 0x36 261bf215546Sopenharmony_ci 262bf215546Sopenharmony_ci/* NV40 only fragment program opcodes */ 263bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_TXL_NV40 0x2F 264bf215546Sopenharmony_ci#define NVFX_FP_OP_OPCODE_LITEX2_NV40 0x3C 265bf215546Sopenharmony_ci 266bf215546Sopenharmony_ci/* The use of these instructions appears to be indicated by bit 31 of DWORD 2.*/ 267bf215546Sopenharmony_ci#define NV40_FP_OP_BRA_OPCODE_BRK 0x0 268bf215546Sopenharmony_ci#define NV40_FP_OP_BRA_OPCODE_CAL 0x1 269bf215546Sopenharmony_ci#define NV40_FP_OP_BRA_OPCODE_IF 0x2 270bf215546Sopenharmony_ci#define NV40_FP_OP_BRA_OPCODE_LOOP 0x3 271bf215546Sopenharmony_ci#define NV40_FP_OP_BRA_OPCODE_REP 0x4 272bf215546Sopenharmony_ci#define NV40_FP_OP_BRA_OPCODE_RET 0x5 273bf215546Sopenharmony_ci 274bf215546Sopenharmony_ci#define NV40_FP_OP_OUT_NONE (1 << 30) 275bf215546Sopenharmony_ci#define NVFX_FP_OP_OUT_SAT (1 << 31) 276bf215546Sopenharmony_ci 277bf215546Sopenharmony_ci/* high order bits of SRC0 */ 278bf215546Sopenharmony_ci#define NVFX_FP_OP_SRC0_ABS (1 << 29) 279bf215546Sopenharmony_ci#define NVFX_FP_OP_COND_SWZ_W_SHIFT 27 280bf215546Sopenharmony_ci#define NVFX_FP_OP_COND_SWZ_W_MASK (3 << 27) 281bf215546Sopenharmony_ci#define NVFX_FP_OP_COND_SWZ_Z_SHIFT 25 282bf215546Sopenharmony_ci#define NVFX_FP_OP_COND_SWZ_Z_MASK (3 << 25) 283bf215546Sopenharmony_ci#define NVFX_FP_OP_COND_SWZ_Y_SHIFT 23 284bf215546Sopenharmony_ci#define NVFX_FP_OP_COND_SWZ_Y_MASK (3 << 23) 285bf215546Sopenharmony_ci#define NVFX_FP_OP_COND_SWZ_X_SHIFT 21 286bf215546Sopenharmony_ci#define NVFX_FP_OP_COND_SWZ_X_MASK (3 << 21) 287bf215546Sopenharmony_ci#define NVFX_FP_OP_COND_SWZ_ALL_SHIFT 21 288bf215546Sopenharmony_ci#define NVFX_FP_OP_COND_SWZ_ALL_MASK (0xFF << 21) 289bf215546Sopenharmony_ci#define NVFX_FP_OP_COND_SHIFT 18 290bf215546Sopenharmony_ci#define NVFX_FP_OP_COND_MASK (0x07 << 18) 291bf215546Sopenharmony_ci# define NVFX_FP_OP_COND_FL 0 292bf215546Sopenharmony_ci# define NVFX_FP_OP_COND_LT 1 293bf215546Sopenharmony_ci# define NVFX_FP_OP_COND_EQ 2 294bf215546Sopenharmony_ci# define NVFX_FP_OP_COND_LE 3 295bf215546Sopenharmony_ci# define NVFX_FP_OP_COND_GT 4 296bf215546Sopenharmony_ci# define NVFX_FP_OP_COND_NE 5 297bf215546Sopenharmony_ci# define NVFX_FP_OP_COND_GE 6 298bf215546Sopenharmony_ci# define NVFX_FP_OP_COND_TR 7 299bf215546Sopenharmony_ci 300bf215546Sopenharmony_ci/* high order bits of SRC1 */ 301bf215546Sopenharmony_ci#define NV40_FP_OP_OPCODE_IS_BRANCH (1<<31) 302bf215546Sopenharmony_ci#define NVFX_FP_OP_DST_SCALE_SHIFT 28 303bf215546Sopenharmony_ci#define NVFX_FP_OP_DST_SCALE_MASK (3 << 28) 304bf215546Sopenharmony_ci#define NVFX_FP_OP_DST_SCALE_1X 0 305bf215546Sopenharmony_ci#define NVFX_FP_OP_DST_SCALE_2X 1 306bf215546Sopenharmony_ci#define NVFX_FP_OP_DST_SCALE_4X 2 307bf215546Sopenharmony_ci#define NVFX_FP_OP_DST_SCALE_8X 3 308bf215546Sopenharmony_ci#define NVFX_FP_OP_DST_SCALE_INV_2X 5 309bf215546Sopenharmony_ci#define NVFX_FP_OP_DST_SCALE_INV_4X 6 310bf215546Sopenharmony_ci#define NVFX_FP_OP_DST_SCALE_INV_8X 7 311bf215546Sopenharmony_ci#define NVFX_FP_OP_SRC1_ABS (1 << 18) 312bf215546Sopenharmony_ci 313bf215546Sopenharmony_ci/* SRC1 LOOP */ 314bf215546Sopenharmony_ci#define NV40_FP_OP_LOOP_INCR_SHIFT 19 315bf215546Sopenharmony_ci#define NV40_FP_OP_LOOP_INCR_MASK (0xFF << 19) 316bf215546Sopenharmony_ci#define NV40_FP_OP_LOOP_INDEX_SHIFT 10 317bf215546Sopenharmony_ci#define NV40_FP_OP_LOOP_INDEX_MASK (0xFF << 10) 318bf215546Sopenharmony_ci#define NV40_FP_OP_LOOP_COUNT_SHIFT 2 319bf215546Sopenharmony_ci#define NV40_FP_OP_LOOP_COUNT_MASK (0xFF << 2) 320bf215546Sopenharmony_ci 321bf215546Sopenharmony_ci/* SRC1 IF: absolute offset in dwords */ 322bf215546Sopenharmony_ci#define NV40_FP_OP_ELSE_OFFSET_SHIFT 0 323bf215546Sopenharmony_ci#define NV40_FP_OP_ELSE_OFFSET_MASK (0x7FFFFFFF << 0) 324bf215546Sopenharmony_ci 325bf215546Sopenharmony_ci/* SRC1 CAL */ 326bf215546Sopenharmony_ci#define NV40_FP_OP_SUB_OFFSET_SHIFT 0 327bf215546Sopenharmony_ci#define NV40_FP_OP_SUB_OFFSET_MASK (0x7FFFFFFF << 0) 328bf215546Sopenharmony_ci 329bf215546Sopenharmony_ci/* SRC1 REP 330bf215546Sopenharmony_ci * I have no idea why there are 3 count values here.. but they 331bf215546Sopenharmony_ci * have always been filled with the same value in my tests so 332bf215546Sopenharmony_ci * far.. 333bf215546Sopenharmony_ci */ 334bf215546Sopenharmony_ci#define NV40_FP_OP_REP_COUNT1_SHIFT 2 335bf215546Sopenharmony_ci#define NV40_FP_OP_REP_COUNT1_MASK (0xFF << 2) 336bf215546Sopenharmony_ci#define NV40_FP_OP_REP_COUNT2_SHIFT 10 337bf215546Sopenharmony_ci#define NV40_FP_OP_REP_COUNT2_MASK (0xFF << 10) 338bf215546Sopenharmony_ci#define NV40_FP_OP_REP_COUNT3_SHIFT 19 339bf215546Sopenharmony_ci#define NV40_FP_OP_REP_COUNT3_MASK (0xFF << 19) 340bf215546Sopenharmony_ci 341bf215546Sopenharmony_ci/* SRC2 REP/IF: absolute offset in dwords */ 342bf215546Sopenharmony_ci#define NV40_FP_OP_END_OFFSET_SHIFT 0 343bf215546Sopenharmony_ci#define NV40_FP_OP_END_OFFSET_MASK (0x7FFFFFFF << 0) 344bf215546Sopenharmony_ci 345bf215546Sopenharmony_ci/* high order bits of SRC2 */ 346bf215546Sopenharmony_ci#define NVFX_FP_OP_INDEX_INPUT (1 << 30) 347bf215546Sopenharmony_ci#define NV40_FP_OP_ADDR_INDEX_SHIFT 19 348bf215546Sopenharmony_ci#define NV40_FP_OP_ADDR_INDEX_MASK (0xF << 19) 349bf215546Sopenharmony_ci 350bf215546Sopenharmony_ci//== Register selection == 351bf215546Sopenharmony_ci#define NVFX_FP_REG_TYPE_SHIFT 0 352bf215546Sopenharmony_ci#define NVFX_FP_REG_TYPE_MASK (3 << 0) 353bf215546Sopenharmony_ci# define NVFX_FP_REG_TYPE_TEMP 0 354bf215546Sopenharmony_ci# define NVFX_FP_REG_TYPE_INPUT 1 355bf215546Sopenharmony_ci# define NVFX_FP_REG_TYPE_CONST 2 356bf215546Sopenharmony_ci#define NVFX_FP_REG_SRC_SHIFT 2 357bf215546Sopenharmony_ci#define NV30_FP_REG_SRC_MASK (31 << 2) 358bf215546Sopenharmony_ci#define NV40_FP_REG_SRC_MASK (63 << 2) 359bf215546Sopenharmony_ci#define NVFX_FP_REG_SRC_HALF (1 << 8) 360bf215546Sopenharmony_ci#define NVFX_FP_REG_SWZ_ALL_SHIFT 9 361bf215546Sopenharmony_ci#define NVFX_FP_REG_SWZ_ALL_MASK (255 << 9) 362bf215546Sopenharmony_ci#define NVFX_FP_REG_SWZ_X_SHIFT 9 363bf215546Sopenharmony_ci#define NVFX_FP_REG_SWZ_X_MASK (3 << 9) 364bf215546Sopenharmony_ci#define NVFX_FP_REG_SWZ_Y_SHIFT 11 365bf215546Sopenharmony_ci#define NVFX_FP_REG_SWZ_Y_MASK (3 << 11) 366bf215546Sopenharmony_ci#define NVFX_FP_REG_SWZ_Z_SHIFT 13 367bf215546Sopenharmony_ci#define NVFX_FP_REG_SWZ_Z_MASK (3 << 13) 368bf215546Sopenharmony_ci#define NVFX_FP_REG_SWZ_W_SHIFT 15 369bf215546Sopenharmony_ci#define NVFX_FP_REG_SWZ_W_MASK (3 << 15) 370bf215546Sopenharmony_ci# define NVFX_FP_SWIZZLE_X 0 371bf215546Sopenharmony_ci# define NVFX_FP_SWIZZLE_Y 1 372bf215546Sopenharmony_ci# define NVFX_FP_SWIZZLE_Z 2 373bf215546Sopenharmony_ci# define NVFX_FP_SWIZZLE_W 3 374bf215546Sopenharmony_ci#define NVFX_FP_REG_NEGATE (1 << 17) 375bf215546Sopenharmony_ci 376bf215546Sopenharmony_ci#define NVFXSR_NONE 0 377bf215546Sopenharmony_ci#define NVFXSR_OUTPUT 1 378bf215546Sopenharmony_ci#define NVFXSR_INPUT 2 379bf215546Sopenharmony_ci#define NVFXSR_TEMP 3 380bf215546Sopenharmony_ci#define NVFXSR_CONST 5 381bf215546Sopenharmony_ci#define NVFXSR_IMM 6 382bf215546Sopenharmony_ci 383bf215546Sopenharmony_ci#define NVFX_COND_FL 0 384bf215546Sopenharmony_ci#define NVFX_COND_LT 1 385bf215546Sopenharmony_ci#define NVFX_COND_EQ 2 386bf215546Sopenharmony_ci#define NVFX_COND_LE 3 387bf215546Sopenharmony_ci#define NVFX_COND_GT 4 388bf215546Sopenharmony_ci#define NVFX_COND_NE 5 389bf215546Sopenharmony_ci#define NVFX_COND_GE 6 390bf215546Sopenharmony_ci#define NVFX_COND_TR 7 391bf215546Sopenharmony_ci 392bf215546Sopenharmony_ci/* Yes, this are ordered differently... */ 393bf215546Sopenharmony_ci 394bf215546Sopenharmony_ci#define NVFX_VP_MASK_X 8 395bf215546Sopenharmony_ci#define NVFX_VP_MASK_Y 4 396bf215546Sopenharmony_ci#define NVFX_VP_MASK_Z 2 397bf215546Sopenharmony_ci#define NVFX_VP_MASK_W 1 398bf215546Sopenharmony_ci#define NVFX_VP_MASK_ALL 0xf 399bf215546Sopenharmony_ci 400bf215546Sopenharmony_ci#define NVFX_FP_MASK_X 1 401bf215546Sopenharmony_ci#define NVFX_FP_MASK_Y 2 402bf215546Sopenharmony_ci#define NVFX_FP_MASK_Z 4 403bf215546Sopenharmony_ci#define NVFX_FP_MASK_W 8 404bf215546Sopenharmony_ci#define NVFX_FP_MASK_ALL 0xf 405bf215546Sopenharmony_ci 406bf215546Sopenharmony_ci#define NVFX_SWZ_X 0 407bf215546Sopenharmony_ci#define NVFX_SWZ_Y 1 408bf215546Sopenharmony_ci#define NVFX_SWZ_Z 2 409bf215546Sopenharmony_ci#define NVFX_SWZ_W 3 410bf215546Sopenharmony_ci 411bf215546Sopenharmony_ci#define swz(s,x,y,z,w) nvfx_src_swz((s), NVFX_SWZ_##x, NVFX_SWZ_##y, NVFX_SWZ_##z, NVFX_SWZ_##w) 412bf215546Sopenharmony_ci#define neg(s) nvfx_src_neg((s)) 413bf215546Sopenharmony_ci#define abs(s) nvfx_src_abs((s)) 414bf215546Sopenharmony_ci 415bf215546Sopenharmony_cistruct nvfx_reg { 416bf215546Sopenharmony_ci int8_t type; 417bf215546Sopenharmony_ci int32_t index; 418bf215546Sopenharmony_ci}; 419bf215546Sopenharmony_ci 420bf215546Sopenharmony_cistruct nvfx_src { 421bf215546Sopenharmony_ci struct nvfx_reg reg; 422bf215546Sopenharmony_ci 423bf215546Sopenharmony_ci uint8_t indirect : 1; 424bf215546Sopenharmony_ci uint8_t indirect_reg : 1; 425bf215546Sopenharmony_ci uint8_t indirect_swz : 2; 426bf215546Sopenharmony_ci uint8_t negate : 1; 427bf215546Sopenharmony_ci uint8_t abs : 1; 428bf215546Sopenharmony_ci uint8_t swz[4]; 429bf215546Sopenharmony_ci}; 430bf215546Sopenharmony_ci 431bf215546Sopenharmony_cistruct nvfx_insn 432bf215546Sopenharmony_ci{ 433bf215546Sopenharmony_ci uint8_t op; 434bf215546Sopenharmony_ci char scale; 435bf215546Sopenharmony_ci int8_t unit; 436bf215546Sopenharmony_ci uint8_t mask; 437bf215546Sopenharmony_ci uint8_t cc_swz[4]; 438bf215546Sopenharmony_ci 439bf215546Sopenharmony_ci uint8_t sat : 1; 440bf215546Sopenharmony_ci uint8_t cc_update : 1; 441bf215546Sopenharmony_ci uint8_t cc_update_reg : 1; 442bf215546Sopenharmony_ci uint8_t cc_test : 3; 443bf215546Sopenharmony_ci uint8_t cc_test_reg : 1; 444bf215546Sopenharmony_ci 445bf215546Sopenharmony_ci struct nvfx_reg dst; 446bf215546Sopenharmony_ci struct nvfx_src src[3]; 447bf215546Sopenharmony_ci}; 448bf215546Sopenharmony_ci 449bf215546Sopenharmony_cistatic inline struct nvfx_insn 450bf215546Sopenharmony_cinvfx_insn(bool sat, unsigned op, int unit, struct nvfx_reg dst, unsigned mask, struct nvfx_src s0, struct nvfx_src s1, struct nvfx_src s2) 451bf215546Sopenharmony_ci{ 452bf215546Sopenharmony_ci struct nvfx_insn insn = { 453bf215546Sopenharmony_ci .op = op, 454bf215546Sopenharmony_ci .scale = 0, 455bf215546Sopenharmony_ci .unit = unit, 456bf215546Sopenharmony_ci .sat = sat, 457bf215546Sopenharmony_ci .mask = mask, 458bf215546Sopenharmony_ci .cc_update = 0, 459bf215546Sopenharmony_ci .cc_update_reg = 0, 460bf215546Sopenharmony_ci .cc_test = NVFX_COND_TR, 461bf215546Sopenharmony_ci .cc_test_reg = 0, 462bf215546Sopenharmony_ci .cc_swz = { 0, 1, 2, 3 }, 463bf215546Sopenharmony_ci .dst = dst, 464bf215546Sopenharmony_ci .src = {s0, s1, s2} 465bf215546Sopenharmony_ci }; 466bf215546Sopenharmony_ci return insn; 467bf215546Sopenharmony_ci} 468bf215546Sopenharmony_ci 469bf215546Sopenharmony_cistatic inline struct nvfx_reg 470bf215546Sopenharmony_cinvfx_reg(int type, int index) 471bf215546Sopenharmony_ci{ 472bf215546Sopenharmony_ci struct nvfx_reg temp = { 473bf215546Sopenharmony_ci .type = type, 474bf215546Sopenharmony_ci .index = index, 475bf215546Sopenharmony_ci }; 476bf215546Sopenharmony_ci return temp; 477bf215546Sopenharmony_ci} 478bf215546Sopenharmony_ci 479bf215546Sopenharmony_cistatic inline struct nvfx_src 480bf215546Sopenharmony_cinvfx_src(struct nvfx_reg reg) 481bf215546Sopenharmony_ci{ 482bf215546Sopenharmony_ci struct nvfx_src temp = { 483bf215546Sopenharmony_ci .reg = reg, 484bf215546Sopenharmony_ci .abs = 0, 485bf215546Sopenharmony_ci .negate = 0, 486bf215546Sopenharmony_ci .swz = { 0, 1, 2, 3 }, 487bf215546Sopenharmony_ci .indirect = 0, 488bf215546Sopenharmony_ci }; 489bf215546Sopenharmony_ci return temp; 490bf215546Sopenharmony_ci} 491bf215546Sopenharmony_ci 492bf215546Sopenharmony_cistatic inline struct nvfx_src 493bf215546Sopenharmony_cinvfx_src_swz(struct nvfx_src src, int x, int y, int z, int w) 494bf215546Sopenharmony_ci{ 495bf215546Sopenharmony_ci struct nvfx_src dst = src; 496bf215546Sopenharmony_ci 497bf215546Sopenharmony_ci dst.swz[NVFX_SWZ_X] = src.swz[x]; 498bf215546Sopenharmony_ci dst.swz[NVFX_SWZ_Y] = src.swz[y]; 499bf215546Sopenharmony_ci dst.swz[NVFX_SWZ_Z] = src.swz[z]; 500bf215546Sopenharmony_ci dst.swz[NVFX_SWZ_W] = src.swz[w]; 501bf215546Sopenharmony_ci return dst; 502bf215546Sopenharmony_ci} 503bf215546Sopenharmony_ci 504bf215546Sopenharmony_cistatic inline struct nvfx_src 505bf215546Sopenharmony_cinvfx_src_neg(struct nvfx_src src) 506bf215546Sopenharmony_ci{ 507bf215546Sopenharmony_ci src.negate = !src.negate; 508bf215546Sopenharmony_ci return src; 509bf215546Sopenharmony_ci} 510bf215546Sopenharmony_ci 511bf215546Sopenharmony_cistatic inline struct nvfx_src 512bf215546Sopenharmony_cinvfx_src_abs(struct nvfx_src src) 513bf215546Sopenharmony_ci{ 514bf215546Sopenharmony_ci src.abs = 1; 515bf215546Sopenharmony_ci return src; 516bf215546Sopenharmony_ci} 517bf215546Sopenharmony_ci 518bf215546Sopenharmony_cistruct nvfx_relocation { 519bf215546Sopenharmony_ci unsigned location; 520bf215546Sopenharmony_ci unsigned target; 521bf215546Sopenharmony_ci}; 522bf215546Sopenharmony_ci 523bf215546Sopenharmony_cistruct nv30_fragprog; 524bf215546Sopenharmony_cistruct nv30_vertprog; 525bf215546Sopenharmony_ci 526bf215546Sopenharmony_ci//XXX: needed to make it build, clean this up! 527bf215546Sopenharmony_civoid 528bf215546Sopenharmony_ci_nvfx_fragprog_translate(uint16_t oclass, struct nv30_fragprog *fp); 529bf215546Sopenharmony_ci 530bf215546Sopenharmony_cibool 531bf215546Sopenharmony_ci_nvfx_vertprog_translate(uint16_t oclass, struct nv30_vertprog *vp); 532bf215546Sopenharmony_ci 533bf215546Sopenharmony_ci#endif 534