Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

codegen.h 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /*
  2. * Copyright (c) 2017 Lima Project
  3. * Copyright (c) 2013 Ben Brewer (ben.brewer@codethink.co.uk)
  4. * Copyright (c) 2013 Connor Abbott (connor@abbott.cx)
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sub license,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the
  14. * next paragraph) shall be included in all copies or substantial portions
  15. * of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  20. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. *
  25. */
  26. #ifndef LIMA_IR_PP_CODEGEN_H
  27. #define LIMA_IR_PP_CODEGEN_H
  28. #include <stdint.h>
  29. #include <stdbool.h>
  30. /* Control */
  31. typedef union __attribute__((__packed__)) {
  32. struct __attribute__((__packed__)) {
  33. unsigned count : 5;
  34. bool stop : 1;
  35. bool sync : 1;
  36. unsigned fields : 12;
  37. unsigned next_count : 6;
  38. bool prefetch : 1;
  39. unsigned unknown : 6;
  40. };
  41. uint32_t mask;
  42. } ppir_codegen_ctrl;
  43. typedef enum {
  44. ppir_codegen_field_shift_varying = 0,
  45. ppir_codegen_field_shift_sampler = 1,
  46. ppir_codegen_field_shift_uniform = 2,
  47. ppir_codegen_field_shift_vec4_mul = 3,
  48. ppir_codegen_field_shift_float_mul = 4,
  49. ppir_codegen_field_shift_vec4_acc = 5,
  50. ppir_codegen_field_shift_float_acc = 6,
  51. ppir_codegen_field_shift_combine = 7,
  52. ppir_codegen_field_shift_temp_write = 8,
  53. ppir_codegen_field_shift_branch = 9,
  54. ppir_codegen_field_shift_vec4_const_0 = 10,
  55. ppir_codegen_field_shift_vec4_const_1 = 11,
  56. ppir_codegen_field_shift_count = 12,
  57. } ppir_codegen_field_shift;
  58. /* Data Inputs */
  59. typedef enum {
  60. ppir_codegen_vec4_reg_frag_color = 0,
  61. ppir_codegen_vec4_reg_constant0 = 12,
  62. ppir_codegen_vec4_reg_constant1 = 13,
  63. ppir_codegen_vec4_reg_texture = 14,
  64. ppir_codegen_vec4_reg_uniform = 15,
  65. ppir_codegen_vec4_reg_discard = 15,
  66. } ppir_codegen_vec4_reg;
  67. typedef union __attribute__((__packed__)) {
  68. struct __attribute__((__packed__)) {
  69. unsigned perspective : 2;
  70. unsigned source_type : 2;
  71. unsigned unknown_0 : 1; /* = 0 */
  72. unsigned alignment : 2;
  73. unsigned unknown_1 : 3; /* = 00 0 */
  74. unsigned offset_vector : 4;
  75. unsigned unknown_2 : 2; /* = 00 */
  76. unsigned offset_scalar : 2;
  77. unsigned index : 6;
  78. ppir_codegen_vec4_reg dest : 4;
  79. unsigned mask : 4;
  80. unsigned unknown_3 : 2; /* = 00 */
  81. } imm;
  82. struct __attribute__((__packed__)) {
  83. unsigned perspective : 2;
  84. unsigned source_type : 2; /* = 01 */
  85. unsigned unknown_0 : 2; /* = 00 */
  86. bool normalize : 1;
  87. unsigned unknown_1 : 3;
  88. ppir_codegen_vec4_reg source : 4;
  89. bool negate : 1;
  90. bool absolute : 1;
  91. unsigned swizzle : 8;
  92. ppir_codegen_vec4_reg dest : 4;
  93. unsigned mask : 4;
  94. unsigned unknown_2 : 2; /* = 00 */
  95. } reg;
  96. } ppir_codegen_field_varying;
  97. typedef enum {
  98. ppir_codegen_sampler_type_2d = 0x00,
  99. ppir_codegen_sampler_type_cube = 0x1F,
  100. } ppir_codegen_sampler_type;
  101. typedef struct __attribute__((__packed__)) {
  102. unsigned lod_bias : 6;
  103. unsigned index_offset : 6;
  104. unsigned unknown_0 : 5; /* = 00000 */
  105. bool explicit_lod : 1;
  106. bool lod_bias_en : 1;
  107. unsigned unknown_1 : 5; /* = 00000 */
  108. ppir_codegen_sampler_type type : 5;
  109. bool offset_en : 1;
  110. unsigned index : 12;
  111. unsigned unknown_2 : 20; /* = 0011 1001 0000 0000 0001 */
  112. } ppir_codegen_field_sampler;
  113. typedef enum {
  114. ppir_codegen_uniform_src_uniform = 0,
  115. ppir_codegen_uniform_src_temporary = 3,
  116. } ppir_codegen_uniform_src;
  117. typedef struct __attribute__((__packed__)) {
  118. ppir_codegen_uniform_src source : 2;
  119. unsigned unknown_0 : 8; /* = 00 0000 00 */
  120. unsigned alignment : 2; /* 00: float, 01: vec2, 10: vec4 */
  121. unsigned unknown_1 : 6; /* = 00 0000 */
  122. unsigned offset_reg : 6;
  123. bool offset_en : 1;
  124. unsigned index : 16;
  125. } ppir_codegen_field_uniform;
  126. /* Vector Pipe */
  127. typedef enum {
  128. ppir_codegen_vec4_mul_op_not = 0x08, /* Logical Not */
  129. ppir_codegen_vec4_mul_op_and = 0x09, /* Logical AND */
  130. ppir_codegen_vec4_mul_op_or = 0x0A, /* Logical OR */
  131. ppir_codegen_vec4_mul_op_xor = 0x0B, /* Logical XOR */
  132. ppir_codegen_vec4_mul_op_ne = 0x0C, /* Not Equal */
  133. ppir_codegen_vec4_mul_op_gt = 0x0D, /* Great Than */
  134. ppir_codegen_vec4_mul_op_ge = 0x0E, /* Great than or Equal */
  135. ppir_codegen_vec4_mul_op_eq = 0x0F, /* Equal */
  136. ppir_codegen_vec4_mul_op_min = 0x10, /* Minimum */
  137. ppir_codegen_vec4_mul_op_max = 0x11, /* Maximum */
  138. ppir_codegen_vec4_mul_op_mov = 0x1F, /* Passthrough, result = arg1 */
  139. } ppir_codegen_vec4_mul_op;
  140. typedef enum {
  141. ppir_codegen_outmod_none = 0,
  142. ppir_codegen_outmod_clamp_fraction = 1,
  143. ppir_codegen_outmod_clamp_positive = 2,
  144. ppir_codegen_outmod_round = 3,
  145. } ppir_codegen_outmod;
  146. typedef struct __attribute__((__packed__)) {
  147. ppir_codegen_vec4_reg arg0_source : 4;
  148. unsigned arg0_swizzle : 8;
  149. bool arg0_absolute : 1;
  150. bool arg0_negate : 1;
  151. ppir_codegen_vec4_reg arg1_source : 4;
  152. unsigned arg1_swizzle : 8;
  153. bool arg1_absolute : 1;
  154. bool arg1_negate : 1;
  155. unsigned dest : 4;
  156. unsigned mask : 4;
  157. ppir_codegen_outmod dest_modifier : 2;
  158. ppir_codegen_vec4_mul_op op : 5;
  159. } ppir_codegen_field_vec4_mul;
  160. typedef enum {
  161. ppir_codegen_vec4_acc_op_add = 0x00,
  162. ppir_codegen_vec4_acc_op_fract = 0x04, /* Fract? */
  163. ppir_codegen_vec4_acc_op_ne = 0x08, /* Not Equal */
  164. ppir_codegen_vec4_acc_op_gt = 0x09, /* Great-Than */
  165. ppir_codegen_vec4_acc_op_ge = 0x0A, /* Great-than or Equal */
  166. ppir_codegen_vec4_acc_op_eq = 0x0B, /* Equal */
  167. ppir_codegen_vec4_acc_op_floor = 0x0C,
  168. ppir_codegen_vec4_acc_op_ceil = 0x0D,
  169. ppir_codegen_vec4_acc_op_min = 0x0E,
  170. ppir_codegen_vec4_acc_op_max = 0x0F,
  171. ppir_codegen_vec4_acc_op_sum3 = 0x10, /* dest.xyzw = (arg0.x + arg0.y + arg0.z) */
  172. ppir_codegen_vec4_acc_op_sum4 = 0x11, /* dest.xyzw = (arg0.x + arg0.y + arg0.z + arg0.w) */
  173. ppir_codegen_vec4_acc_op_dFdx = 0x14,
  174. ppir_codegen_vec4_acc_op_dFdy = 0x15,
  175. ppir_codegen_vec4_acc_op_sel = 0x17, /* result = (^fmul ? arg0 : arg1) */
  176. ppir_codegen_vec4_acc_op_mov = 0x1F, /* Passthrough, result = arg0 */
  177. } ppir_codegen_vec4_acc_op;
  178. typedef struct __attribute__((__packed__)) {
  179. ppir_codegen_vec4_reg arg0_source : 4;
  180. unsigned arg0_swizzle : 8;
  181. bool arg0_absolute : 1;
  182. bool arg0_negate : 1;
  183. ppir_codegen_vec4_reg arg1_source : 4;
  184. unsigned arg1_swizzle : 8;
  185. bool arg1_absolute : 1;
  186. bool arg1_negate : 1;
  187. unsigned dest : 4;
  188. unsigned mask : 4;
  189. ppir_codegen_outmod dest_modifier : 2;
  190. ppir_codegen_vec4_acc_op op : 5;
  191. bool mul_in : 1; /* whether to get arg0 from multiply unit below */
  192. } ppir_codegen_field_vec4_acc;
  193. /* Float (Scalar) Pipe */
  194. typedef enum {
  195. ppir_codegen_float_mul_op_not = 0x08, /* Logical Not */
  196. ppir_codegen_float_mul_op_and = 0x09, /* Logical AND */
  197. ppir_codegen_float_mul_op_or = 0x0A, /* Logical OR */
  198. ppir_codegen_float_mul_op_xor = 0x0B, /* Logical XOR */
  199. ppir_codegen_float_mul_op_ne = 0x0C, /* Not Equal */
  200. ppir_codegen_float_mul_op_gt = 0x0D, /* Great Than */
  201. ppir_codegen_float_mul_op_ge = 0x0E, /* great than or Equal */
  202. ppir_codegen_float_mul_op_eq = 0x0F, /* Equal */
  203. ppir_codegen_float_mul_op_min = 0x10, /* Minimum */
  204. ppir_codegen_float_mul_op_max = 0x11, /* Maximum */
  205. ppir_codegen_float_mul_op_mov = 0x1F, /* Passthrough, result = arg1 */
  206. } ppir_codegen_float_mul_op;
  207. typedef struct __attribute__((__packed__)) {
  208. unsigned arg0_source : 6;
  209. bool arg0_absolute : 1;
  210. bool arg0_negate : 1;
  211. unsigned arg1_source : 6;
  212. bool arg1_absolute : 1;
  213. bool arg1_negate : 1;
  214. unsigned dest : 6;
  215. bool output_en : 1; /* Set to 0 when outputting directly to float_acc below. */
  216. ppir_codegen_outmod dest_modifier : 2;
  217. ppir_codegen_float_mul_op op : 5;
  218. } ppir_codegen_field_float_mul;
  219. typedef enum {
  220. ppir_codegen_float_acc_op_add = 0x00,
  221. ppir_codegen_float_acc_op_fract = 0x04,
  222. ppir_codegen_float_acc_op_ne = 0x08, /* Not Equal */
  223. ppir_codegen_float_acc_op_gt = 0x09, /* Great-Than */
  224. ppir_codegen_float_acc_op_ge = 0x0A, /* Great-than or Equal */
  225. ppir_codegen_float_acc_op_eq = 0x0B, /* Equal */
  226. ppir_codegen_float_acc_op_floor = 0x0C,
  227. ppir_codegen_float_acc_op_ceil = 0x0D,
  228. ppir_codegen_float_acc_op_min = 0x0E,
  229. ppir_codegen_float_acc_op_max = 0x0F,
  230. ppir_codegen_float_acc_op_dFdx = 0x14,
  231. ppir_codegen_float_acc_op_dFdy = 0x15,
  232. ppir_codegen_float_acc_op_sel = 0x17, /* result = (^fmul ? arg0 : arg1) */
  233. ppir_codegen_float_acc_op_mov = 0x1F, /* Passthrough, result = arg1 */
  234. } ppir_codegen_float_acc_op;
  235. typedef struct __attribute__((__packed__)) {
  236. unsigned arg0_source : 6;
  237. bool arg0_absolute : 1;
  238. bool arg0_negate : 1;
  239. unsigned arg1_source : 6;
  240. bool arg1_absolute : 1;
  241. bool arg1_negate : 1;
  242. unsigned dest : 6;
  243. bool output_en : 1; /* Always true */
  244. ppir_codegen_outmod dest_modifier : 2;
  245. ppir_codegen_float_acc_op op : 5;
  246. bool mul_in : 1; /* Get arg1 from float_mul above. */
  247. } ppir_codegen_field_float_acc;
  248. /* Temporary Write / Framebuffer Read */
  249. typedef union __attribute__((__packed__)) {
  250. struct __attribute__((__packed__)) {
  251. unsigned dest : 2; /* = 11 */
  252. unsigned unknown_0 : 2; /* = 00 */
  253. unsigned source : 6;
  254. unsigned alignment : 2; /* 0: float, 1:vec2, 2: vec4 */
  255. unsigned unknown_1 : 6; /* = 00 0000 */
  256. unsigned offset_reg : 6;
  257. bool offset_en : 1;
  258. unsigned index : 16;
  259. } temp_write;
  260. struct __attribute__((__packed__)) {
  261. bool source : 1; /* 0 = fb_depth, 1 = fb_color */
  262. unsigned unknown_0 : 5; /* = 00 111 */
  263. unsigned dest : 4;
  264. unsigned unknown_1 : 31; /* = 0 0000 ... 10 */
  265. } fb_read;
  266. } ppir_codegen_field_temp_write;
  267. /* Result combiner */
  268. typedef enum {
  269. ppir_codegen_combine_scalar_op_rcp = 0, /* Reciprocal */
  270. ppir_codegen_combine_scalar_op_mov = 1, /* No Operation */
  271. ppir_codegen_combine_scalar_op_sqrt = 2, /* Square-Root */
  272. ppir_codegen_combine_scalar_op_rsqrt = 3, /* Inverse Square-Root */
  273. ppir_codegen_combine_scalar_op_exp2 = 4, /* Binary Exponent */
  274. ppir_codegen_combine_scalar_op_log2 = 5, /* Binary Logarithm */
  275. ppir_codegen_combine_scalar_op_sin = 6, /* Sine (Scaled LUT) */
  276. ppir_codegen_combine_scalar_op_cos = 7, /* Cosine (Scaled LUT) */
  277. ppir_codegen_combine_scalar_op_atan = 8, /* Arc Tangent Part 1 */
  278. ppir_codegen_combine_scalar_op_atan2 = 9, /* Arc Tangent 2 Part 1 */
  279. } ppir_codegen_combine_scalar_op;
  280. typedef union __attribute__((__packed__)) {
  281. struct __attribute__((__packed__)) {
  282. bool dest_vec : 1;
  283. bool arg1_en : 1;
  284. ppir_codegen_combine_scalar_op op : 4;
  285. bool arg1_absolute : 1;
  286. bool arg1_negate : 1;
  287. unsigned arg1_src : 6;
  288. bool arg0_absolute : 1;
  289. bool arg0_negate : 1;
  290. unsigned arg0_src : 6;
  291. ppir_codegen_outmod dest_modifier : 2;
  292. unsigned dest : 6;
  293. } scalar;
  294. struct __attribute__((__packed__)) {
  295. bool dest_vec : 1;
  296. bool arg1_en : 1;
  297. unsigned arg1_swizzle : 8;
  298. unsigned arg1_source : 4;
  299. unsigned padding_0 : 8;
  300. unsigned mask : 4;
  301. unsigned dest : 4;
  302. } vector;
  303. } ppir_codegen_field_combine;
  304. /* Branch/Control Flow */
  305. #define PPIR_CODEGEN_DISCARD_WORD0 0x007F0003
  306. #define PPIR_CODEGEN_DISCARD_WORD1 0x00000000
  307. #define PPIR_CODEGEN_DISCARD_WORD2 0x000
  308. typedef union __attribute__((__packed__)) {
  309. struct __attribute__((__packed__)) {
  310. unsigned unknown_0 : 4; /* = 0000 */
  311. unsigned arg1_source : 6;
  312. unsigned arg0_source : 6;
  313. bool cond_gt : 1;
  314. bool cond_eq : 1;
  315. bool cond_lt : 1;
  316. unsigned unknown_1 : 22; /* = 0 0000 0000 0000 0000 0000 0 */
  317. signed target : 27;
  318. unsigned next_count : 5;
  319. } branch;
  320. struct __attribute__((__packed__)) {
  321. unsigned word0 : 32;
  322. unsigned word1 : 32;
  323. unsigned word2 : 9;
  324. } discard;
  325. } ppir_codegen_field_branch;
  326. void ppir_disassemble_instr(uint32_t *instr, unsigned offset);
  327. #endif