| 1 |
/* |
| 2 |
* Copyright (c) 2013 Connor Abbott ([email protected]) |
| 3 |
* Copyright (c) 2018 Alyssa Rosenzweig |
| 4 |
* Copyright (C) 2019-2020 Collabora, Ltd. |
| 5 |
* SPDX-License-Identifier: MIT |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifndef __midgard_h__ |
| 9 |
#define __midgard_h__ |
| 10 |
|
| 11 |
#include <stdbool.h> |
| 12 |
#include <stdint.h> |
| 13 |
|
| 14 |
#define MIDGARD_DBG_SHADERS 0x0002 |
| 15 |
#define MIDGARD_DBG_SHADERDB 0x0004 |
| 16 |
#define MIDGARD_DBG_INORDER 0x0008 |
| 17 |
#define MIDGARD_DBG_VERBOSE 0x0010 |
| 18 |
#define MIDGARD_DBG_INTERNAL 0x0020 |
| 19 |
|
| 20 |
extern int midgard_debug; |
| 21 |
|
| 22 |
typedef enum { |
| 23 |
midgard_word_type_alu, |
| 24 |
midgard_word_type_load_store, |
| 25 |
midgard_word_type_texture |
| 26 |
} midgard_word_type; |
| 27 |
|
| 28 |
typedef enum { |
| 29 |
midgard_alu_vmul, |
| 30 |
midgard_alu_sadd, |
| 31 |
midgard_alu_smul, |
| 32 |
midgard_alu_vadd, |
| 33 |
midgard_alu_lut |
| 34 |
} midgard_alu; |
| 35 |
|
| 36 |
enum { |
| 37 |
TAG_INVALID = 0x0, |
| 38 |
TAG_BREAK = 0x1, |
| 39 |
TAG_TEXTURE_4_VTX = 0x2, |
| 40 |
TAG_TEXTURE_4 = 0x3, |
| 41 |
TAG_TEXTURE_4_BARRIER = 0x4, |
| 42 |
TAG_LOAD_STORE_4 = 0x5, |
| 43 |
TAG_UNKNOWN_1 = 0x6, |
| 44 |
TAG_UNKNOWN_2 = 0x7, |
| 45 |
TAG_ALU_4 = 0x8, |
| 46 |
TAG_ALU_8 = 0x9, |
| 47 |
TAG_ALU_12 = 0xA, |
| 48 |
TAG_ALU_16 = 0xB, |
| 49 |
TAG_ALU_4_WRITEOUT = 0xC, |
| 50 |
TAG_ALU_8_WRITEOUT = 0xD, |
| 51 |
TAG_ALU_12_WRITEOUT = 0xE, |
| 52 |
TAG_ALU_16_WRITEOUT = 0xF |
| 53 |
}; |
| 54 |
|
| 55 |
/* |
| 56 |
* ALU words |
| 57 |
*/ |
| 58 |
|
| 59 |
typedef enum { |
| 60 |
midgard_alu_op_fadd = 0x10, /* round to even */ |
| 61 |
midgard_alu_op_fadd_rtz = 0x11, |
| 62 |
midgard_alu_op_fadd_rtn = 0x12, |
| 63 |
midgard_alu_op_fadd_rtp = 0x13, |
| 64 |
midgard_alu_op_fmul = 0x14, /* round to even */ |
| 65 |
midgard_alu_op_fmul_rtz = 0x15, |
| 66 |
midgard_alu_op_fmul_rtn = 0x16, |
| 67 |
midgard_alu_op_fmul_rtp = 0x17, |
| 68 |
|
| 69 |
midgard_alu_op_fmin = 0x28, /* if an operand is NaN, propagate the other */ |
| 70 |
midgard_alu_op_fmin_nan = 0x29, /* if an operand is NaN, propagate it */ |
| 71 |
midgard_alu_op_fabsmin = 0x2A, /* min(abs(a,b)) */ |
| 72 |
midgard_alu_op_fabsmin_nan = 0x2B, /* min_nan(abs(a,b)) */ |
| 73 |
midgard_alu_op_fmax = 0x2C, /* if an operand is NaN, propagate the other */ |
| 74 |
midgard_alu_op_fmax_nan = 0x2D, /* if an operand is NaN, propagate it */ |
| 75 |
midgard_alu_op_fabsmax = 0x2E, /* max(abs(a,b)) */ |
| 76 |
midgard_alu_op_fabsmax_nan = 0x2F, /* max_nan(abs(a,b)) */ |
| 77 |
|
| 78 |
midgard_alu_op_fmov = 0x30, /* fmov_rte */ |
| 79 |
midgard_alu_op_fmov_rtz = 0x31, |
| 80 |
midgard_alu_op_fmov_rtn = 0x32, |
| 81 |
midgard_alu_op_fmov_rtp = 0x33, |
| 82 |
midgard_alu_op_froundeven = 0x34, |
| 83 |
midgard_alu_op_ftrunc = 0x35, |
| 84 |
midgard_alu_op_ffloor = 0x36, |
| 85 |
midgard_alu_op_fceil = 0x37, |
| 86 |
midgard_alu_op_ffma = 0x38, /* rte */ |
| 87 |
midgard_alu_op_ffma_rtz = 0x39, |
| 88 |
midgard_alu_op_ffma_rtn = 0x3A, |
| 89 |
midgard_alu_op_ffma_rtp = 0x3B, |
| 90 |
midgard_alu_op_fdot3 = 0x3C, |
| 91 |
midgard_alu_op_fdot3r = 0x3D, |
| 92 |
midgard_alu_op_fdot4 = 0x3E, |
| 93 |
midgard_alu_op_freduce = 0x3F, |
| 94 |
|
| 95 |
midgard_alu_op_iadd = 0x40, |
| 96 |
midgard_alu_op_ishladd = 0x41, /* (a<<1) + b */ |
| 97 |
midgard_alu_op_isub = 0x46, |
| 98 |
midgard_alu_op_ishlsub = 0x47, /* (a<<1) - b */ |
| 99 |
midgard_alu_op_iaddsat = 0x48, |
| 100 |
midgard_alu_op_uaddsat = 0x49, |
| 101 |
midgard_alu_op_isubsat = 0x4E, |
| 102 |
midgard_alu_op_usubsat = 0x4F, |
| 103 |
|
| 104 |
midgard_alu_op_imul = 0x58, |
| 105 |
/* Multiplies two ints and stores the result in the next larger datasize. */ |
| 106 |
midgard_alu_op_iwmul = 0x59, /* sint * sint = sint */ |
| 107 |
midgard_alu_op_uwmul = 0x5A, /* uint * uint = uint */ |
| 108 |
midgard_alu_op_iuwmul = 0x5B, /* sint * uint = sint */ |
| 109 |
|
| 110 |
midgard_alu_op_imin = 0x60, |
| 111 |
midgard_alu_op_umin = 0x61, |
| 112 |
midgard_alu_op_imax = 0x62, |
| 113 |
midgard_alu_op_umax = 0x63, |
| 114 |
midgard_alu_op_iavg = 0x64, |
| 115 |
midgard_alu_op_uavg = 0x65, |
| 116 |
midgard_alu_op_iravg = 0x66, |
| 117 |
midgard_alu_op_uravg = 0x67, |
| 118 |
midgard_alu_op_iasr = 0x68, |
| 119 |
midgard_alu_op_ilsr = 0x69, |
| 120 |
midgard_alu_op_ishlsat = 0x6C, |
| 121 |
midgard_alu_op_ushlsat = 0x6D, |
| 122 |
midgard_alu_op_ishl = 0x6E, |
| 123 |
|
| 124 |
midgard_alu_op_iand = 0x70, |
| 125 |
midgard_alu_op_ior = 0x71, |
| 126 |
midgard_alu_op_inand = 0x72, /* ~(a & b), for inot let a = b */ |
| 127 |
midgard_alu_op_inor = 0x73, /* ~(a | b) */ |
| 128 |
midgard_alu_op_iandnot = 0x74, /* (a & ~b), used for not/b2f */ |
| 129 |
midgard_alu_op_iornot = 0x75, /* (a | ~b) */ |
| 130 |
midgard_alu_op_ixor = 0x76, |
| 131 |
midgard_alu_op_inxor = 0x77, /* ~(a ^ b) */ |
| 132 |
midgard_alu_op_iclz = 0x78, /* Number of zeroes on left */ |
| 133 |
midgard_alu_op_ipopcnt = 0x7A, /* Population count */ |
| 134 |
midgard_alu_op_imov = 0x7B, |
| 135 |
midgard_alu_op_iabsdiff = 0x7C, |
| 136 |
midgard_alu_op_uabsdiff = 0x7D, |
| 137 |
midgard_alu_op_ichoose = |
| 138 |
0x7E, /* vector, component number - dupe for shuffle() */ |
| 139 |
|
| 140 |
midgard_alu_op_feq = 0x80, |
| 141 |
midgard_alu_op_fne = 0x81, |
| 142 |
midgard_alu_op_flt = 0x82, |
| 143 |
midgard_alu_op_fle = 0x83, |
| 144 |
midgard_alu_op_fball_eq = 0x88, |
| 145 |
midgard_alu_op_fball_neq = 0x89, |
| 146 |
midgard_alu_op_fball_lt = 0x8A, /* all(lessThan(.., ..)) */ |
| 147 |
midgard_alu_op_fball_lte = 0x8B, /* all(lessThanEqual(.., ..)) */ |
| 148 |
|
| 149 |
midgard_alu_op_fbany_eq = 0x90, |
| 150 |
midgard_alu_op_fbany_neq = 0x91, |
| 151 |
midgard_alu_op_fbany_lt = 0x92, /* any(lessThan(.., ..)) */ |
| 152 |
midgard_alu_op_fbany_lte = 0x93, /* any(lessThanEqual(.., ..)) */ |
| 153 |
|
| 154 |
midgard_alu_op_f2i_rte = 0x98, |
| 155 |
midgard_alu_op_f2i_rtz = 0x99, |
| 156 |
midgard_alu_op_f2i_rtn = 0x9A, |
| 157 |
midgard_alu_op_f2i_rtp = 0x9B, |
| 158 |
midgard_alu_op_f2u_rte = 0x9C, |
| 159 |
midgard_alu_op_f2u_rtz = 0x9D, |
| 160 |
midgard_alu_op_f2u_rtn = 0x9E, |
| 161 |
midgard_alu_op_f2u_rtp = 0x9F, |
| 162 |
|
| 163 |
midgard_alu_op_ieq = 0xA0, |
| 164 |
midgard_alu_op_ine = 0xA1, |
| 165 |
midgard_alu_op_ult = 0xA2, |
| 166 |
midgard_alu_op_ule = 0xA3, |
| 167 |
midgard_alu_op_ilt = 0xA4, |
| 168 |
midgard_alu_op_ile = 0xA5, |
| 169 |
midgard_alu_op_iball_eq = 0xA8, |
| 170 |
midgard_alu_op_iball_neq = 0xA9, |
| 171 |
midgard_alu_op_uball_lt = 0xAA, |
| 172 |
midgard_alu_op_uball_lte = 0xAB, |
| 173 |
midgard_alu_op_iball_lt = 0xAC, |
| 174 |
midgard_alu_op_iball_lte = 0xAD, |
| 175 |
|
| 176 |
midgard_alu_op_ibany_eq = 0xB0, |
| 177 |
midgard_alu_op_ibany_neq = 0xB1, |
| 178 |
midgard_alu_op_ubany_lt = 0xB2, |
| 179 |
midgard_alu_op_ubany_lte = 0xB3, |
| 180 |
midgard_alu_op_ibany_lt = 0xB4, /* any(lessThan(.., ..)) */ |
| 181 |
midgard_alu_op_ibany_lte = 0xB5, /* any(lessThanEqual(.., ..)) */ |
| 182 |
midgard_alu_op_i2f_rte = 0xB8, |
| 183 |
midgard_alu_op_i2f_rtz = 0xB9, |
| 184 |
midgard_alu_op_i2f_rtn = 0xBA, |
| 185 |
midgard_alu_op_i2f_rtp = 0xBB, |
| 186 |
midgard_alu_op_u2f_rte = 0xBC, |
| 187 |
midgard_alu_op_u2f_rtz = 0xBD, |
| 188 |
midgard_alu_op_u2f_rtn = 0xBE, |
| 189 |
midgard_alu_op_u2f_rtp = 0xBF, |
| 190 |
|
| 191 |
/* All csel* instructions use as a condition the output of the previous |
| 192 |
* vector or scalar unit, thus it must run on the second pipeline stage |
| 193 |
* and be scheduled to the same bundle as the opcode that it uses as a |
| 194 |
* condition. */ |
| 195 |
midgard_alu_op_icsel_v = 0xC0, |
| 196 |
midgard_alu_op_icsel = 0xC1, |
| 197 |
midgard_alu_op_fcsel_v = 0xC4, |
| 198 |
midgard_alu_op_fcsel = 0xC5, |
| 199 |
midgard_alu_op_froundaway = 0xC6, /* round to nearest away */ |
| 200 |
|
| 201 |
midgard_alu_op_fatan2_pt2 = 0xE8, |
| 202 |
midgard_alu_op_fpow_pt1 = 0xEC, |
| 203 |
midgard_alu_op_fpown_pt1 = 0xED, |
| 204 |
midgard_alu_op_fpowr_pt1 = 0xEE, |
| 205 |
|
| 206 |
midgard_alu_op_frcp = 0xF0, |
| 207 |
midgard_alu_op_frsqrt = 0xF2, |
| 208 |
midgard_alu_op_fsqrt = 0xF3, |
| 209 |
midgard_alu_op_fexp2 = 0xF4, |
| 210 |
midgard_alu_op_flog2 = 0xF5, |
| 211 |
midgard_alu_op_fsinpi = 0xF6, /* sin(pi * x) */ |
| 212 |
midgard_alu_op_fcospi = 0xF7, /* cos(pi * x) */ |
| 213 |
midgard_alu_op_fatan2_pt1 = 0xF9, |
| 214 |
} midgard_alu_op; |
| 215 |
|
| 216 |
typedef enum { |
| 217 |
midgard_outmod_none = 0, |
| 218 |
midgard_outmod_clamp_0_inf = 1, /* max(x, 0.0), NaNs become +0.0 */ |
| 219 |
midgard_outmod_clamp_m1_1 = 2, /* clamp(x, -1.0, 1.0), NaNs become -1.0 */ |
| 220 |
midgard_outmod_clamp_0_1 = 3 /* clamp(x, 0.0, 1.0), NaNs become +0.0 */ |
| 221 |
} midgard_outmod_float; |
| 222 |
|
| 223 |
/* These are applied to the resulting value that's going to be stored in the |
| 224 |
* dest reg. This should be set to midgard_outmod_keeplo when shrink_mode is |
| 225 |
* midgard_shrink_mode_none. */ |
| 226 |
typedef enum { |
| 227 |
midgard_outmod_ssat = 0, |
| 228 |
midgard_outmod_usat = 1, |
| 229 |
midgard_outmod_keeplo = 2, /* Keep low half */ |
| 230 |
midgard_outmod_keephi = 3, /* Keep high half */ |
| 231 |
} midgard_outmod_int; |
| 232 |
|
| 233 |
typedef enum { |
| 234 |
midgard_reg_mode_8 = 0, |
| 235 |
midgard_reg_mode_16 = 1, |
| 236 |
midgard_reg_mode_32 = 2, |
| 237 |
midgard_reg_mode_64 = 3 |
| 238 |
} midgard_reg_mode; |
| 239 |
|
| 240 |
typedef enum { |
| 241 |
midgard_shrink_mode_lower = 0, |
| 242 |
midgard_shrink_mode_upper = 1, |
| 243 |
midgard_shrink_mode_none = 2 |
| 244 |
} midgard_shrink_mode; |
| 245 |
|
| 246 |
/* Only used if midgard_src_expand_mode is set to one of midgard_src_expand_*. */ |
| 247 |
typedef enum { |
| 248 |
midgard_int_sign_extend = 0, |
| 249 |
midgard_int_zero_extend = 1, |
| 250 |
midgard_int_replicate = 2, |
| 251 |
midgard_int_left_shift = 3 |
| 252 |
} midgard_int_mod; |
| 253 |
|
| 254 |
/* Unlike midgard_int_mod, fload modifiers are applied after the expansion |
| 255 |
* happens, so they don't depend on midgard_src_expand_mode. */ |
| 256 |
#define MIDGARD_FLOAT_MOD_ABS (1 << 0) |
| 257 |
#define MIDGARD_FLOAT_MOD_NEG (1 << 1) |
| 258 |
|
| 259 |
/* The expand options depend on both midgard_int_mod and midgard_reg_mode. For |
| 260 |
* example, a vec4 with midgard_int_sign_extend and midgard_src_expand_low is |
| 261 |
* treated as a vec8 and each 16-bit element from the low 64-bits is then sign |
| 262 |
* extended, resulting in a vec4 where each 32-bit element corresponds to a |
| 263 |
* 16-bit element from the low 64-bits of the input vector. */ |
| 264 |
typedef enum { |
| 265 |
midgard_src_passthrough = 0, |
| 266 |
midgard_src_rep_low = 1, /* replicate lower 64 bits to higher 64 bits */ |
| 267 |
midgard_src_rep_high = 2, /* replicate higher 64 bits to lower 64 bits */ |
| 268 |
midgard_src_swap = 3, /* swap lower 64 bits with higher 64 bits */ |
| 269 |
midgard_src_expand_low = 4, /* expand low 64 bits */ |
| 270 |
midgard_src_expand_high = 5, /* expand high 64 bits */ |
| 271 |
midgard_src_expand_low_swap = 6, /* expand low 64 bits, then swap */ |
| 272 |
midgard_src_expand_high_swap = 7, /* expand high 64 bits, then swap */ |
| 273 |
} midgard_src_expand_mode; |
| 274 |
|
| 275 |
#define INPUT_EXPANDS(a) \ |
| 276 |
(a >= midgard_src_expand_low && a <= midgard_src_expand_high_swap) |
| 277 |
|
| 278 |
#define INPUT_SWAPS(a) \ |
| 279 |
(a == midgard_src_swap || a >= midgard_src_expand_low_swap) |
| 280 |
|
| 281 |
typedef struct __attribute__((__packed__)) { |
| 282 |
/* Either midgard_int_mod or from midgard_float_mod_*, depending on the |
| 283 |
* type of op */ |
| 284 |
unsigned mod : 2; |
| 285 |
midgard_src_expand_mode expand_mode : 3; |
| 286 |
unsigned swizzle : 8; |
| 287 |
} midgard_vector_alu_src; |
| 288 |
|
| 289 |
typedef struct __attribute__((__packed__)) { |
| 290 |
midgard_alu_op op : 8; |
| 291 |
midgard_reg_mode reg_mode : 2; |
| 292 |
unsigned src1 : 13; |
| 293 |
unsigned src2 : 13; |
| 294 |
midgard_shrink_mode shrink_mode : 2; |
| 295 |
unsigned outmod : 2; |
| 296 |
unsigned mask : 8; |
| 297 |
} midgard_vector_alu; |
| 298 |
|
| 299 |
typedef struct __attribute__((__packed__)) { |
| 300 |
unsigned mod : 2; |
| 301 |
bool full : 1; /* 0 = 16-bit, 1 = 32-bit */ |
| 302 |
unsigned component : 3; |
| 303 |
} midgard_scalar_alu_src; |
| 304 |
|
| 305 |
typedef struct __attribute__((__packed__)) { |
| 306 |
midgard_alu_op op : 8; |
| 307 |
unsigned src1 : 6; |
| 308 |
/* last 5 bits are used when src2 is an immediate */ |
| 309 |
unsigned src2 : 11; |
| 310 |
unsigned reserved : 1; |
| 311 |
unsigned outmod : 2; |
| 312 |
bool output_full : 1; |
| 313 |
unsigned output_component : 3; |
| 314 |
} midgard_scalar_alu; |
| 315 |
|
| 316 |
typedef struct __attribute__((__packed__)) { |
| 317 |
unsigned src1_reg : 5; |
| 318 |
unsigned src2_reg : 5; |
| 319 |
unsigned out_reg : 5; |
| 320 |
bool src2_imm : 1; |
| 321 |
} midgard_reg_info; |
| 322 |
|
| 323 |
/* In addition to conditional branches and jumps (unconditional branches), |
| 324 |
* Midgard implements a bit of fixed function functionality used in fragment |
| 325 |
* shaders via specially crafted branches. These have special branch opcodes, |
| 326 |
* which perform a fixed-function operation and/or use the results of a |
| 327 |
* fixed-function operation as the branch condition. */ |
| 328 |
|
| 329 |
typedef enum { |
| 330 |
/* Regular branches */ |
| 331 |
midgard_jmp_writeout_op_branch_uncond = 1, |
| 332 |
midgard_jmp_writeout_op_branch_cond = 2, |
| 333 |
|
| 334 |
/* In a fragment shader, execute a discard_if instruction, with the |
| 335 |
* corresponding condition code. Terminates the shader, so generally |
| 336 |
* set the branch target to out of the shader */ |
| 337 |
midgard_jmp_writeout_op_discard = 4, |
| 338 |
|
| 339 |
/* Branch if the tilebuffer is not yet ready. At the beginning of a |
| 340 |
* fragment shader that reads from the tile buffer, for instance via |
| 341 |
* ARM_shader_framebuffer_fetch or EXT_pixel_local_storage, this branch |
| 342 |
* operation should be used as a loop. An instruction like |
| 343 |
* "br.tilebuffer.always -1" does the trick, corresponding to |
| 344 |
* "while(!is_tilebuffer_ready) */ |
| 345 |
midgard_jmp_writeout_op_tilebuffer_pending = 6, |
| 346 |
|
| 347 |
/* In a fragment shader, try to write out the value pushed to r0 to the |
| 348 |
* tilebuffer, subject to state in r1.z and r1.w. If this |
| 349 |
* succeeds, the shader terminates. If it fails, it branches to the |
| 350 |
* specified branch target. Generally, this should be used in a loop to |
| 351 |
* itself, acting as "do { write(r0); } while(!write_successful);" */ |
| 352 |
midgard_jmp_writeout_op_writeout = 7, |
| 353 |
} midgard_jmp_writeout_op; |
| 354 |
|
| 355 |
typedef enum { |
| 356 |
midgard_condition_write0 = 0, |
| 357 |
|
| 358 |
/* These condition codes denote a conditional branch on FALSE and on |
| 359 |
* TRUE respectively */ |
| 360 |
midgard_condition_false = 1, |
| 361 |
midgard_condition_true = 2, |
| 362 |
|
| 363 |
/* This condition code always branches. For a pure branch, the |
| 364 |
* unconditional branch coding should be used instead, but for |
| 365 |
* fixed-function branch opcodes, this is still useful */ |
| 366 |
midgard_condition_always = 3, |
| 367 |
} midgard_condition; |
| 368 |
|
| 369 |
enum midgard_call_mode { |
| 370 |
midgard_call_mode_default = 1, |
| 371 |
midgard_call_mode_call = 2, |
| 372 |
midgard_call_mode_return = 3 |
| 373 |
}; |
| 374 |
|
| 375 |
typedef struct __attribute__((__packed__)) { |
| 376 |
midgard_jmp_writeout_op op : 3; /* == branch_uncond */ |
| 377 |
unsigned dest_tag : 4; /* tag of branch destination */ |
| 378 |
enum midgard_call_mode call_mode : 2; |
| 379 |
int offset : 7; |
| 380 |
} midgard_branch_uncond; |
| 381 |
|
| 382 |
typedef struct __attribute__((__packed__)) { |
| 383 |
midgard_jmp_writeout_op op : 3; /* == branch_cond */ |
| 384 |
unsigned dest_tag : 4; /* tag of branch destination */ |
| 385 |
int offset : 7; |
| 386 |
midgard_condition cond : 2; |
| 387 |
} midgard_branch_cond; |
| 388 |
|
| 389 |
typedef struct __attribute__((__packed__)) { |
| 390 |
midgard_jmp_writeout_op op : 3; /* == branch_cond */ |
| 391 |
unsigned dest_tag : 4; /* tag of branch destination */ |
| 392 |
enum midgard_call_mode call_mode : 2; |
| 393 |
signed offset : 23; |
| 394 |
|
| 395 |
/* Extended branches permit inputting up to 4 conditions loaded into |
| 396 |
* r31 (two in r31.w and two in r31.x). In the most general case, we |
| 397 |
* specify a function f(A, B, C, D) mapping 4 1-bit conditions to a |
| 398 |
* single 1-bit branch criteria. Note that the domain of f has 2^(2^4) |
| 399 |
* elements, each mapping to 1-bit of output, so we can trivially |
| 400 |
* construct a Godel numbering of f as a (2^4)=16-bit integer. This |
| 401 |
* 16-bit integer serves as a lookup table to compute f, subject to |
| 402 |
* some swaps for ordering. |
| 403 |
* |
| 404 |
* Interesting, the standard 2-bit condition codes are also a LUT with |
| 405 |
* the same format (2^1-bit), but it's usually easier to use enums. */ |
| 406 |
|
| 407 |
unsigned cond : 16; |
| 408 |
} midgard_branch_extended; |
| 409 |
|
| 410 |
typedef struct __attribute__((__packed__)) { |
| 411 |
midgard_jmp_writeout_op op : 3; /* == writeout */ |
| 412 |
unsigned unknown : 13; |
| 413 |
} midgard_writeout; |
| 414 |
|
| 415 |
/* |
| 416 |
* Load/store words |
| 417 |
*/ |
| 418 |
|
| 419 |
typedef enum { |
| 420 |
midgard_op_ld_st_noop = 0x03, |
| 421 |
|
| 422 |
/* Unpacks a colour from a native format to <format> */ |
| 423 |
midgard_op_unpack_colour_f32 = 0x04, |
| 424 |
midgard_op_unpack_colour_f16 = 0x05, |
| 425 |
midgard_op_unpack_colour_u32 = 0x06, |
| 426 |
midgard_op_unpack_colour_s32 = 0x07, |
| 427 |
|
| 428 |
/* Packs a colour from <format> to a native format */ |
| 429 |
midgard_op_pack_colour_f32 = 0x08, |
| 430 |
midgard_op_pack_colour_f16 = 0x09, |
| 431 |
midgard_op_pack_colour_u32 = 0x0A, |
| 432 |
midgard_op_pack_colour_s32 = 0x0B, |
| 433 |
|
| 434 |
/* Computes the effective address of a mem address expression */ |
| 435 |
midgard_op_lea = 0x0C, |
| 436 |
|
| 437 |
/* Converts image coordinates into mem address */ |
| 438 |
midgard_op_lea_image = 0x0D, |
| 439 |
|
| 440 |
/* Unclear why this is on the L/S unit, but moves fp32 cube map |
| 441 |
* coordinates in r27 to its cube map texture coordinate destination |
| 442 |
* (e.g r29). */ |
| 443 |
|
| 444 |
midgard_op_ld_cubemap_coords = 0x0E, |
| 445 |
|
| 446 |
/* A mov between registers that the ldst pipeline can access */ |
| 447 |
midgard_op_ldst_mov = 0x10, |
| 448 |
|
| 449 |
/* The L/S unit can do perspective division a clock faster than the ALU |
| 450 |
* if you're lucky. Put the vec4 in r27, and call with 0x24 as the |
| 451 |
* unknown state; the output will be <x/w, y/w, z/w, 1>. Replace w with |
| 452 |
* z for the z version */ |
| 453 |
midgard_op_ldst_perspective_div_y = 0x11, |
| 454 |
midgard_op_ldst_perspective_div_z = 0x12, |
| 455 |
midgard_op_ldst_perspective_div_w = 0x13, |
| 456 |
|
| 457 |
/* val in r27.y, address embedded, outputs result to argument. Invert val for |
| 458 |
sub. Let val = +-1 for inc/dec. */ |
| 459 |
midgard_op_atomic_add = 0x40, |
| 460 |
midgard_op_atomic_add64 = 0x41, |
| 461 |
midgard_op_atomic_add_be = 0x42, |
| 462 |
midgard_op_atomic_add64_be = 0x43, |
| 463 |
|
| 464 |
midgard_op_atomic_and = 0x44, |
| 465 |
midgard_op_atomic_and64 = 0x45, |
| 466 |
midgard_op_atomic_and_be = 0x46, |
| 467 |
midgard_op_atomic_and64_be = 0x47, |
| 468 |
midgard_op_atomic_or = 0x48, |
| 469 |
midgard_op_atomic_or64 = 0x49, |
| 470 |
midgard_op_atomic_or_be = 0x4A, |
| 471 |
midgard_op_atomic_or64_be = 0x4B, |
| 472 |
midgard_op_atomic_xor = 0x4C, |
| 473 |
midgard_op_atomic_xor64 = 0x4D, |
| 474 |
midgard_op_atomic_xor_be = 0x4E, |
| 475 |
midgard_op_atomic_xor64_be = 0x4F, |
| 476 |
|
| 477 |
midgard_op_atomic_imin = 0x50, |
| 478 |
midgard_op_atomic_imin64 = 0x51, |
| 479 |
midgard_op_atomic_imin_be = 0x52, |
| 480 |
midgard_op_atomic_imin64_be = 0x53, |
| 481 |
midgard_op_atomic_umin = 0x54, |
| 482 |
midgard_op_atomic_umin64 = 0x55, |
| 483 |
midgard_op_atomic_umin_be = 0x56, |
| 484 |
midgard_op_atomic_umin64_be = 0x57, |
| 485 |
midgard_op_atomic_imax = 0x58, |
| 486 |
midgard_op_atomic_imax64 = 0x59, |
| 487 |
midgard_op_atomic_imax_be = 0x5A, |
| 488 |
midgard_op_atomic_imax64_be = 0x5B, |
| 489 |
midgard_op_atomic_umax = 0x5C, |
| 490 |
midgard_op_atomic_umax64 = 0x5D, |
| 491 |
midgard_op_atomic_umax_be = 0x5E, |
| 492 |
midgard_op_atomic_umax64_be = 0x5F, |
| 493 |
|
| 494 |
midgard_op_atomic_xchg = 0x60, |
| 495 |
midgard_op_atomic_xchg64 = 0x61, |
| 496 |
midgard_op_atomic_xchg_be = 0x62, |
| 497 |
midgard_op_atomic_xchg64_be = 0x63, |
| 498 |
|
| 499 |
midgard_op_atomic_cmpxchg = 0x64, |
| 500 |
midgard_op_atomic_cmpxchg64 = 0x65, |
| 501 |
midgard_op_atomic_cmpxchg_be = 0x66, |
| 502 |
midgard_op_atomic_cmpxchg64_be = 0x67, |
| 503 |
|
| 504 |
/* Used for compute shader's __global arguments, __local |
| 505 |
* variables (or for register spilling) */ |
| 506 |
|
| 507 |
midgard_op_ld_u8 = 0x80, /* zero extends */ |
| 508 |
midgard_op_ld_i8 = 0x81, /* sign extends */ |
| 509 |
midgard_op_ld_u16 = 0x84, /* zero extends */ |
| 510 |
midgard_op_ld_i16 = 0x85, /* sign extends */ |
| 511 |
midgard_op_ld_u16_be = 0x86, /* zero extends, big endian */ |
| 512 |
midgard_op_ld_i16_be = 0x87, /* sign extends, big endian */ |
| 513 |
midgard_op_ld_32 = 0x88, /* short2, int, float */ |
| 514 |
midgard_op_ld_32_bswap2 = 0x89, /* 16-bit big endian vector */ |
| 515 |
midgard_op_ld_32_bswap4 = 0x8A, /* 32-bit big endian scalar */ |
| 516 |
midgard_op_ld_64 = 0x8C, /* int2, float2, long */ |
| 517 |
midgard_op_ld_64_bswap2 = 0x8D, /* 16-bit big endian vector */ |
| 518 |
midgard_op_ld_64_bswap4 = 0x8E, /* 32-bit big endian vector */ |
| 519 |
midgard_op_ld_64_bswap8 = 0x8F, /* 64-bit big endian scalar */ |
| 520 |
midgard_op_ld_128 = 0x90, /* float4, long2 */ |
| 521 |
midgard_op_ld_128_bswap2 = 0x91, /* 16-bit big endian vector */ |
| 522 |
midgard_op_ld_128_bswap4 = 0x92, /* 32-bit big endian vector */ |
| 523 |
midgard_op_ld_128_bswap8 = 0x93, /* 64-bit big endian vector */ |
| 524 |
|
| 525 |
midgard_op_ld_attr_32 = 0x94, |
| 526 |
midgard_op_ld_attr_16 = 0x95, |
| 527 |
midgard_op_ld_attr_32u = 0x96, |
| 528 |
midgard_op_ld_attr_32i = 0x97, |
| 529 |
midgard_op_ld_vary_32 = 0x98, |
| 530 |
midgard_op_ld_vary_16 = 0x99, |
| 531 |
midgard_op_ld_vary_32u = 0x9A, |
| 532 |
midgard_op_ld_vary_32i = 0x9B, |
| 533 |
|
| 534 |
/* This instruction behaves differently depending if the gpu is a v4 |
| 535 |
* or a newer gpu. The main difference hinges on which values of the |
| 536 |
* second argument are valid for each gpu. |
| 537 |
* TODO: properly document and decode each possible value for the |
| 538 |
* second argument. */ |
| 539 |
midgard_op_ld_special_32f = 0x9C, |
| 540 |
midgard_op_ld_special_16f = 0x9D, |
| 541 |
midgard_op_ld_special_32u = 0x9E, |
| 542 |
midgard_op_ld_special_32i = 0x9F, |
| 543 |
|
| 544 |
/* The distinction between these ops is the alignment |
| 545 |
* requirement / accompanying shift. Thus, the offset to |
| 546 |
* ld_ubo_128 is in 16-byte units and can load 128-bit. The |
| 547 |
* offset to ld_ubo_64 is in 8-byte units; ld_ubo_32 in 4-byte |
| 548 |
* units. */ |
| 549 |
midgard_op_ld_ubo_u8 = 0xA0, /* theoretical */ |
| 550 |
midgard_op_ld_ubo_i8 = 0xA1, /* theoretical */ |
| 551 |
midgard_op_ld_ubo_u16 = 0xA4, /* theoretical */ |
| 552 |
midgard_op_ld_ubo_i16 = 0xA5, /* theoretical */ |
| 553 |
midgard_op_ld_ubo_u16_be = 0xA6, /* theoretical */ |
| 554 |
midgard_op_ld_ubo_i16_be = 0xA7, /* theoretical */ |
| 555 |
midgard_op_ld_ubo_32 = 0xA8, |
| 556 |
midgard_op_ld_ubo_32_bswap2 = 0xA9, |
| 557 |
midgard_op_ld_ubo_32_bswap4 = 0xAA, |
| 558 |
midgard_op_ld_ubo_64 = 0xAC, |
| 559 |
midgard_op_ld_ubo_64_bswap2 = 0xAD, |
| 560 |
midgard_op_ld_ubo_64_bswap4 = 0xAE, |
| 561 |
midgard_op_ld_ubo_64_bswap8 = 0xAF, |
| 562 |
midgard_op_ld_ubo_128 = 0xB0, |
| 563 |
midgard_op_ld_ubo_128_bswap2 = 0xB1, |
| 564 |
midgard_op_ld_ubo_128_bswap4 = 0xB2, |
| 565 |
midgard_op_ld_ubo_128_bswap8 = 0xB3, |
| 566 |
|
| 567 |
midgard_op_ld_image_32f = 0xB4, |
| 568 |
midgard_op_ld_image_16f = 0xB5, |
| 569 |
midgard_op_ld_image_32u = 0xB6, |
| 570 |
midgard_op_ld_image_32i = 0xB7, |
| 571 |
|
| 572 |
/* Only works on v5 or newer. |
| 573 |
* Older cards must use ld_special with tilebuffer selectors. */ |
| 574 |
midgard_op_ld_tilebuffer_32f = 0xB8, |
| 575 |
midgard_op_ld_tilebuffer_16f = 0xB9, |
| 576 |
midgard_op_ld_tilebuffer_raw = 0xBA, |
| 577 |
|
| 578 |
midgard_op_st_u8 = 0xC0, /* zero extends */ |
| 579 |
midgard_op_st_i8 = 0xC1, /* sign extends */ |
| 580 |
midgard_op_st_u16 = 0xC4, /* zero extends */ |
| 581 |
midgard_op_st_i16 = 0xC5, /* sign extends */ |
| 582 |
midgard_op_st_u16_be = 0xC6, /* zero extends, big endian */ |
| 583 |
midgard_op_st_i16_be = 0xC7, /* sign extends, big endian */ |
| 584 |
midgard_op_st_32 = 0xC8, /* short2, int, float */ |
| 585 |
midgard_op_st_32_bswap2 = 0xC9, /* 16-bit big endian vector */ |
| 586 |
midgard_op_st_32_bswap4 = 0xCA, /* 32-bit big endian scalar */ |
| 587 |
midgard_op_st_64 = 0xCC, /* int2, float2, long */ |
| 588 |
midgard_op_st_64_bswap2 = 0xCD, /* 16-bit big endian vector */ |
| 589 |
midgard_op_st_64_bswap4 = 0xCE, /* 32-bit big endian vector */ |
| 590 |
midgard_op_st_64_bswap8 = 0xCF, /* 64-bit big endian scalar */ |
| 591 |
midgard_op_st_128 = 0xD0, /* float4, long2 */ |
| 592 |
midgard_op_st_128_bswap2 = 0xD1, /* 16-bit big endian vector */ |
| 593 |
midgard_op_st_128_bswap4 = 0xD2, /* 32-bit big endian vector */ |
| 594 |
midgard_op_st_128_bswap8 = 0xD3, /* 64-bit big endian vector */ |
| 595 |
|
| 596 |
midgard_op_st_vary_32 = 0xD4, |
| 597 |
midgard_op_st_vary_16 = 0xD5, |
| 598 |
midgard_op_st_vary_32u = 0xD6, |
| 599 |
midgard_op_st_vary_32i = 0xD7, |
| 600 |
|
| 601 |
/* Value to st in r27, location r26.w as short2 */ |
| 602 |
midgard_op_st_image_32f = 0xD8, |
| 603 |
midgard_op_st_image_16f = 0xD9, |
| 604 |
midgard_op_st_image_32u = 0xDA, |
| 605 |
midgard_op_st_image_32i = 0xDB, |
| 606 |
|
| 607 |
midgard_op_st_special_32f = 0xDC, |
| 608 |
midgard_op_st_special_16f = 0xDD, |
| 609 |
midgard_op_st_special_32u = 0xDE, |
| 610 |
midgard_op_st_special_32i = 0xDF, |
| 611 |
|
| 612 |
/* Only works on v5 or newer. |
| 613 |
* Older cards must use ld_special with tilebuffer selectors. */ |
| 614 |
midgard_op_st_tilebuffer_32f = 0xE8, |
| 615 |
midgard_op_st_tilebuffer_16f = 0xE9, |
| 616 |
midgard_op_st_tilebuffer_raw = 0xEA, |
| 617 |
midgard_op_trap = 0xFC, |
| 618 |
} midgard_load_store_op; |
| 619 |
|
| 620 |
typedef enum { |
| 621 |
midgard_interp_sample = 0, |
| 622 |
midgard_interp_centroid = 1, |
| 623 |
midgard_interp_default = 2 |
| 624 |
} midgard_interpolation; |
| 625 |
|
| 626 |
typedef enum { |
| 627 |
midgard_varying_mod_none = 0, |
| 628 |
|
| 629 |
/* Take the would-be result and divide all components by its y/z/w |
| 630 |
* (perspective division baked in with the load) */ |
| 631 |
midgard_varying_mod_perspective_y = 1, |
| 632 |
midgard_varying_mod_perspective_z = 2, |
| 633 |
midgard_varying_mod_perspective_w = 3, |
| 634 |
|
| 635 |
/* The result is a 64-bit cubemap descriptor to use with |
| 636 |
* midgard_tex_op_normal or midgard_tex_op_gradient */ |
| 637 |
midgard_varying_mod_cubemap = 4, |
| 638 |
} midgard_varying_modifier; |
| 639 |
|
| 640 |
typedef struct __attribute__((__packed__)) { |
| 641 |
midgard_varying_modifier modifier : 3; |
| 642 |
|
| 643 |
bool flat_shading : 1; |
| 644 |
|
| 645 |
/* These are ignored if flat_shading is enabled. */ |
| 646 |
bool perspective_correction : 1; |
| 647 |
bool centroid_mapping : 1; |
| 648 |
|
| 649 |
/* This is ignored if the shader only runs once per pixel. */ |
| 650 |
bool interpolate_sample : 1; |
| 651 |
|
| 652 |
bool zero0 : 1; /* Always zero */ |
| 653 |
|
| 654 |
unsigned direct_sample_pos_x : 4; |
| 655 |
unsigned direct_sample_pos_y : 4; |
| 656 |
} midgard_varying_params; |
| 657 |
|
| 658 |
/* 8-bit register/etc selector for load/store ops */ |
| 659 |
typedef struct __attribute__((__packed__)) { |
| 660 |
/* Indexes into the register */ |
| 661 |
unsigned component : 2; |
| 662 |
|
| 663 |
/* Register select between r26/r27 */ |
| 664 |
unsigned select : 1; |
| 665 |
|
| 666 |
unsigned unknown : 2; |
| 667 |
|
| 668 |
/* Like any good Arm instruction set, load/store arguments can be |
| 669 |
* implicitly left-shifted... but only the second argument. Zero for no |
| 670 |
* shifting, up to <<7 possible though. This is useful for indexing. |
| 671 |
* |
| 672 |
* For the first argument, it's unknown what these bits mean */ |
| 673 |
unsigned shift : 3; |
| 674 |
} midgard_ldst_register_select; |
| 675 |
|
| 676 |
typedef enum { |
| 677 |
/* 0 is reserved */ |
| 678 |
midgard_index_address_u64 = 1, |
| 679 |
midgard_index_address_u32 = 2, |
| 680 |
midgard_index_address_s32 = 3, |
| 681 |
} midgard_index_address_format; |
| 682 |
|
| 683 |
typedef struct __attribute__((__packed__)) { |
| 684 |
midgard_load_store_op op : 8; |
| 685 |
|
| 686 |
/* Source/dest reg */ |
| 687 |
unsigned reg : 5; |
| 688 |
|
| 689 |
/* Generally is a writemask. |
| 690 |
* For ST_ATTR and ST_TEX, unused. |
| 691 |
* For other stores, each bit masks 1/4th of the output. */ |
| 692 |
unsigned mask : 4; |
| 693 |
|
| 694 |
/* Swizzle for stores, but for atomics it encodes also the source |
| 695 |
* register. This fits because atomics dont need a swizzle since they |
| 696 |
* are not vectorized instructions. */ |
| 697 |
unsigned swizzle : 8; |
| 698 |
|
| 699 |
/* Arg reg, meaning changes according to each opcode */ |
| 700 |
unsigned arg_comp : 2; |
| 701 |
unsigned arg_reg : 3; |
| 702 |
|
| 703 |
/* 64-bit address enable |
| 704 |
* 32-bit data type enable for CUBEMAP and perspective div. |
| 705 |
* Explicit indexing enable for LD_ATTR. |
| 706 |
* 64-bit coordinate enable for LD_IMAGE. */ |
| 707 |
bool bitsize_toggle : 1; |
| 708 |
|
| 709 |
/* These are mainly used for opcodes that have addresses. |
| 710 |
* For cmpxchg, index_reg is used for the comparison value. |
| 711 |
* For ops that access the attrib table, bit 1 encodes which table. |
| 712 |
* For LD_VAR and LD/ST_ATTR, bit 0 enables dest/src type inferral. */ |
| 713 |
midgard_index_address_format index_format : 2; |
| 714 |
unsigned index_comp : 2; |
| 715 |
unsigned index_reg : 3; |
| 716 |
unsigned index_shift : 4; |
| 717 |
|
| 718 |
/* Generaly is a signed offset, but has different bitsize and starts at |
| 719 |
* different bits depending on the opcode, LDST_*_DISPLACEMENT helpers |
| 720 |
* are recommended when packing/unpacking this attribute. |
| 721 |
* For LD_UBO, bit 0 enables ubo index immediate. |
| 722 |
* For LD_TILEBUFFER_RAW, bit 0 disables sample index immediate. */ |
| 723 |
int signed_offset : 18; |
| 724 |
} midgard_load_store_word; |
| 725 |
|
| 726 |
typedef struct __attribute__((__packed__)) { |
| 727 |
unsigned type : 4; |
| 728 |
unsigned next_type : 4; |
| 729 |
uint64_t word1 : 60; |
| 730 |
uint64_t word2 : 60; |
| 731 |
} midgard_load_store; |
| 732 |
|
| 733 |
/* 8-bit register selector used in texture ops to select a bias/LOD/gradient |
| 734 |
* register, shoved into the `bias` field */ |
| 735 |
|
| 736 |
typedef struct __attribute__((__packed__)) { |
| 737 |
/* 32-bit register, clear for half-register */ |
| 738 |
unsigned full : 1; |
| 739 |
|
| 740 |
/* Register select between r28/r29 */ |
| 741 |
unsigned select : 1; |
| 742 |
|
| 743 |
/* For a half-register, selects the upper half */ |
| 744 |
unsigned upper : 1; |
| 745 |
|
| 746 |
/* Indexes into the register */ |
| 747 |
unsigned component : 2; |
| 748 |
|
| 749 |
/* Padding to make this 8-bit */ |
| 750 |
unsigned zero : 3; |
| 751 |
} midgard_tex_register_select; |
| 752 |
|
| 753 |
/* Texture pipeline results are in r28-r29 */ |
| 754 |
#define REG_TEX_BASE 28 |
| 755 |
|
| 756 |
enum mali_texture_op { |
| 757 |
/* [texture + LOD bias] |
| 758 |
* If the texture is mipmapped, barriers must be enabled in the |
| 759 |
* instruction word in order for this opcode to compute the output |
| 760 |
* correctly. */ |
| 761 |
midgard_tex_op_normal = 1, |
| 762 |
|
| 763 |
/* [texture + gradient for LOD and anisotropy] |
| 764 |
* Unlike midgard_tex_op_normal, this opcode does not require barriers |
| 765 |
* to compute the output correctly. */ |
| 766 |
midgard_tex_op_gradient = 2, |
| 767 |
|
| 768 |
/* [unfiltered texturing] |
| 769 |
* Unlike midgard_tex_op_normal, this opcode does not require barriers |
| 770 |
* to compute the output correctly. */ |
| 771 |
midgard_tex_op_fetch = 4, |
| 772 |
|
| 773 |
/* [gradient from derivative] */ |
| 774 |
midgard_tex_op_grad_from_derivative = 9, |
| 775 |
|
| 776 |
/* [mov] */ |
| 777 |
midgard_tex_op_mov = 10, |
| 778 |
|
| 779 |
/* [noop] |
| 780 |
* Mostly used for barriers. */ |
| 781 |
midgard_tex_op_barrier = 11, |
| 782 |
|
| 783 |
/* [gradient from coords] */ |
| 784 |
midgard_tex_op_grad_from_coords = 12, |
| 785 |
|
| 786 |
/* [derivative] |
| 787 |
* Computes derivatives in 2x2 fragment blocks. */ |
| 788 |
midgard_tex_op_derivative = 13 |
| 789 |
}; |
| 790 |
|
| 791 |
enum mali_sampler_type { |
| 792 |
/* 0 is reserved */ |
| 793 |
MALI_SAMPLER_FLOAT = 0x1, /* sampler */ |
| 794 |
MALI_SAMPLER_UNSIGNED = 0x2, /* usampler */ |
| 795 |
MALI_SAMPLER_SIGNED = 0x3, /* isampler */ |
| 796 |
}; |
| 797 |
|
| 798 |
/* Texture modes */ |
| 799 |
enum mali_texture_mode { |
| 800 |
TEXTURE_NORMAL = 1, |
| 801 |
TEXTURE_SHADOW = 5, |
| 802 |
TEXTURE_GATHER_SHADOW = 6, |
| 803 |
TEXTURE_GATHER_X = 8, |
| 804 |
TEXTURE_GATHER_Y = 9, |
| 805 |
TEXTURE_GATHER_Z = 10, |
| 806 |
TEXTURE_GATHER_W = 11, |
| 807 |
}; |
| 808 |
|
| 809 |
enum mali_derivative_mode { |
| 810 |
TEXTURE_DFDX = 0, |
| 811 |
TEXTURE_DFDY = 1, |
| 812 |
}; |
| 813 |
|
| 814 |
enum midgard_partial_execution { |
| 815 |
MIDGARD_PARTIAL_EXECUTION_SKIP = 1, |
| 816 |
MIDGARD_PARTIAL_EXECUTION_KILL = 2, |
| 817 |
MIDGARD_PARTIAL_EXECUTION_NONE = 3 |
| 818 |
}; |
| 819 |
|
| 820 |
typedef struct __attribute__((__packed__)) { |
| 821 |
unsigned type : 4; |
| 822 |
unsigned next_type : 4; |
| 823 |
|
| 824 |
enum mali_texture_op op : 4; |
| 825 |
unsigned mode : 4; |
| 826 |
enum midgard_partial_execution exec : 2; |
| 827 |
|
| 828 |
unsigned format : 2; |
| 829 |
|
| 830 |
/* Are sampler_handle/texture_handler respectively set by registers? If |
| 831 |
* true, the lower 8-bits of the respective field is a register word. |
| 832 |
* If false, they are an immediate */ |
| 833 |
|
| 834 |
unsigned sampler_register : 1; |
| 835 |
unsigned texture_register : 1; |
| 836 |
|
| 837 |
/* Is a register used to specify the |
| 838 |
* LOD/bias/offset? If set, use the `bias` field as |
| 839 |
* a register index. If clear, use the `bias` field |
| 840 |
* as an immediate. */ |
| 841 |
unsigned lod_register : 1; |
| 842 |
|
| 843 |
/* Is a register used to specify an offset? If set, use the |
| 844 |
* offset_reg_* fields to encode this, duplicated for each of the |
| 845 |
* components. If clear, there is implcitly always an immediate offst |
| 846 |
* specificed in offset_imm_* */ |
| 847 |
unsigned offset_register : 1; |
| 848 |
|
| 849 |
unsigned in_reg_full : 1; |
| 850 |
unsigned in_reg_select : 1; |
| 851 |
unsigned in_reg_upper : 1; |
| 852 |
unsigned in_reg_swizzle : 8; |
| 853 |
|
| 854 |
unsigned unknown8 : 2; |
| 855 |
|
| 856 |
unsigned out_full : 1; |
| 857 |
|
| 858 |
enum mali_sampler_type sampler_type : 2; |
| 859 |
|
| 860 |
unsigned out_reg_select : 1; |
| 861 |
unsigned out_upper : 1; |
| 862 |
|
| 863 |
unsigned mask : 4; |
| 864 |
|
| 865 |
/* Intriguingly, textures can take an outmod just like alu ops. Int |
| 866 |
* outmods are not supported as far as I can tell, so this is only |
| 867 |
* meaningful for float samplers */ |
| 868 |
midgard_outmod_float outmod : 2; |
| 869 |
|
| 870 |
unsigned swizzle : 8; |
| 871 |
|
| 872 |
/* These indicate how many bundles after this texture op may be |
| 873 |
* executed in parallel with this op. We may execute only ALU and |
| 874 |
* ld/st in parallel (not other textures), and obviously there cannot |
| 875 |
* be any dependency (the blob appears to forbid even accessing other |
| 876 |
* channels of a given texture register). */ |
| 877 |
|
| 878 |
unsigned out_of_order : 4; |
| 879 |
unsigned unknown4 : 8; |
| 880 |
|
| 881 |
/* In immediate mode, each offset field is an immediate range [0, 7]. |
| 882 |
* |
| 883 |
* In register mode, offset_x becomes a register (full, select, upper) |
| 884 |
* triplet followed by a vec3 swizzle is splattered across |
| 885 |
* offset_y/offset_z in a genuinely bizarre way. |
| 886 |
* |
| 887 |
* For texel fetches in immediate mode, the range is the full [-8, 7], |
| 888 |
* but for normal texturing the top bit must be zero and a register |
| 889 |
* used instead. It's not clear where this limitation is from. |
| 890 |
* |
| 891 |
* union { |
| 892 |
* struct { |
| 893 |
* signed offset_x : 4; |
| 894 |
* signed offset_y : 4; |
| 895 |
* signed offset_z : 4; |
| 896 |
* } immediate; |
| 897 |
* struct { |
| 898 |
* bool full : 1; |
| 899 |
* bool select : 1; |
| 900 |
* bool upper : 1; |
| 901 |
* unsigned swizzle : 8; |
| 902 |
* unsigned zero : 1; |
| 903 |
* } register; |
| 904 |
* } |
| 905 |
*/ |
| 906 |
|
| 907 |
unsigned offset : 12; |
| 908 |
|
| 909 |
/* In immediate bias mode, for a normal texture op, this is |
| 910 |
* texture bias, computed as int(2^8 * frac(biasf)), with |
| 911 |
* bias_int = floor(bias). For a textureLod, it's that, but |
| 912 |
* s/bias/lod. For a texel fetch, this is the LOD as-is. |
| 913 |
* |
| 914 |
* In register mode, this is a midgard_tex_register_select |
| 915 |
* structure and bias_int is zero */ |
| 916 |
|
| 917 |
unsigned bias : 8; |
| 918 |
signed bias_int : 8; |
| 919 |
|
| 920 |
/* If sampler/texture_register is set, the bottom 8-bits are |
| 921 |
* midgard_tex_register_select and the top 8-bits are zero. If they are |
| 922 |
* clear, they are immediate texture indices */ |
| 923 |
|
| 924 |
unsigned sampler_handle : 16; |
| 925 |
unsigned texture_handle : 16; |
| 926 |
} midgard_texture_word; |
| 927 |
|
| 928 |
/* Technically barriers are texture instructions but it's less work to add them |
| 929 |
* as an explicitly zeroed special case, since most fields are forced to go to |
| 930 |
* zero */ |
| 931 |
|
| 932 |
typedef struct __attribute__((__packed__)) { |
| 933 |
unsigned type : 4; |
| 934 |
unsigned next_type : 4; |
| 935 |
|
| 936 |
/* op = TEXTURE_OP_BARRIER */ |
| 937 |
unsigned op : 6; |
| 938 |
unsigned zero1 : 2; |
| 939 |
|
| 940 |
/* Since helper invocations don't make any sense, these are forced to one */ |
| 941 |
unsigned cont : 1; |
| 942 |
unsigned last : 1; |
| 943 |
unsigned zero2 : 14; |
| 944 |
|
| 945 |
unsigned zero3 : 24; |
| 946 |
unsigned out_of_order : 4; |
| 947 |
unsigned zero4 : 4; |
| 948 |
|
| 949 |
uint64_t zero5; |
| 950 |
} midgard_texture_barrier_word; |
| 951 |
|
| 952 |
typedef union midgard_constants { |
| 953 |
double f64[2]; |
| 954 |
uint64_t u64[2]; |
| 955 |
int64_t i64[2]; |
| 956 |
float f32[4]; |
| 957 |
uint32_t u32[4]; |
| 958 |
int32_t i32[4]; |
| 959 |
uint16_t f16[8]; |
| 960 |
uint16_t u16[8]; |
| 961 |
int16_t i16[8]; |
| 962 |
uint8_t u8[16]; |
| 963 |
int8_t i8[16]; |
| 964 |
} midgard_constants; |
| 965 |
|
| 966 |
enum midgard_roundmode { |
| 967 |
MIDGARD_RTE = 0x0, /* round to even */ |
| 968 |
MIDGARD_RTZ = 0x1, /* round to zero */ |
| 969 |
MIDGARD_RTN = 0x2, /* round to negative */ |
| 970 |
MIDGARD_RTP = 0x3, /* round to positive */ |
| 971 |
}; |
| 972 |
|
| 973 |
#endif |