shader_bytecode.h 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158
  1. // Copyright 2018 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include <bitset>
  7. #include <optional>
  8. #include <tuple>
  9. #include <vector>
  10. #include "common/assert.h"
  11. #include "common/bit_field.h"
  12. #include "common/common_types.h"
  13. namespace Tegra::Shader {
  14. struct Register {
  15. /// Number of registers
  16. static constexpr std::size_t NumRegisters = 256;
  17. /// Register 255 is special cased to always be 0
  18. static constexpr std::size_t ZeroIndex = 255;
  19. enum class Size : u64 {
  20. Byte = 0,
  21. Short = 1,
  22. Word = 2,
  23. Long = 3,
  24. };
  25. constexpr Register() = default;
  26. constexpr Register(u64 value) : value(value) {}
  27. constexpr operator u64() const {
  28. return value;
  29. }
  30. template <typename T>
  31. constexpr u64 operator-(const T& oth) const {
  32. return value - oth;
  33. }
  34. template <typename T>
  35. constexpr u64 operator&(const T& oth) const {
  36. return value & oth;
  37. }
  38. constexpr u64 operator&(const Register& oth) const {
  39. return value & oth.value;
  40. }
  41. constexpr u64 operator~() const {
  42. return ~value;
  43. }
  44. u64 GetSwizzledIndex(u64 elem) const {
  45. elem = (value + elem) & 3;
  46. return (value & ~3) + elem;
  47. }
  48. private:
  49. u64 value{};
  50. };
  51. enum class AttributeSize : u64 {
  52. Word = 0,
  53. DoubleWord = 1,
  54. TripleWord = 2,
  55. QuadWord = 3,
  56. };
  57. union Attribute {
  58. Attribute() = default;
  59. constexpr explicit Attribute(u64 value) : value(value) {}
  60. enum class Index : u64 {
  61. LayerViewportPointSize = 6,
  62. Position = 7,
  63. Attribute_0 = 8,
  64. Attribute_31 = 39,
  65. ClipDistances0123 = 44,
  66. ClipDistances4567 = 45,
  67. PointCoord = 46,
  68. // This attribute contains a tuple of (~, ~, InstanceId, VertexId) when inside a vertex
  69. // shader, and a tuple of (TessCoord.x, TessCoord.y, TessCoord.z, ~) when inside a Tess Eval
  70. // shader.
  71. TessCoordInstanceIDVertexID = 47,
  72. // This attribute contains a tuple of (Unk, Unk, Unk, gl_FrontFacing) when inside a fragment
  73. // shader. It is unknown what the other values contain.
  74. FrontFacing = 63,
  75. };
  76. union {
  77. BitField<20, 10, u64> immediate;
  78. BitField<22, 2, u64> element;
  79. BitField<24, 6, Index> index;
  80. BitField<31, 1, u64> patch;
  81. BitField<47, 3, AttributeSize> size;
  82. bool IsPhysical() const {
  83. return patch == 0 && element == 0 && static_cast<u64>(index.Value()) == 0;
  84. }
  85. } fmt20;
  86. union {
  87. BitField<30, 2, u64> element;
  88. BitField<32, 6, Index> index;
  89. } fmt28;
  90. BitField<39, 8, u64> reg;
  91. u64 value{};
  92. };
  93. union Sampler {
  94. Sampler() = default;
  95. constexpr explicit Sampler(u64 value) : value(value) {}
  96. enum class Index : u64 {
  97. Sampler_0 = 8,
  98. };
  99. BitField<36, 13, Index> index;
  100. u64 value{};
  101. };
  102. union Image {
  103. Image() = default;
  104. constexpr explicit Image(u64 value) : value{value} {}
  105. BitField<36, 13, u64> index;
  106. u64 value;
  107. };
  108. } // namespace Tegra::Shader
  109. namespace std {
  110. // TODO(bunnei): The below is forbidden by the C++ standard, but works fine. See #330.
  111. template <>
  112. struct make_unsigned<Tegra::Shader::Attribute> {
  113. using type = Tegra::Shader::Attribute;
  114. };
  115. template <>
  116. struct make_unsigned<Tegra::Shader::Register> {
  117. using type = Tegra::Shader::Register;
  118. };
  119. } // namespace std
  120. namespace Tegra::Shader {
  121. enum class Pred : u64 {
  122. UnusedIndex = 0x7,
  123. NeverExecute = 0xF,
  124. };
  125. enum class PredCondition : u64 {
  126. LessThan = 1,
  127. Equal = 2,
  128. LessEqual = 3,
  129. GreaterThan = 4,
  130. NotEqual = 5,
  131. GreaterEqual = 6,
  132. LessThanWithNan = 9,
  133. LessEqualWithNan = 11,
  134. GreaterThanWithNan = 12,
  135. NotEqualWithNan = 13,
  136. GreaterEqualWithNan = 14,
  137. // TODO(Subv): Other condition types
  138. };
  139. enum class PredOperation : u64 {
  140. And = 0,
  141. Or = 1,
  142. Xor = 2,
  143. };
  144. enum class LogicOperation : u64 {
  145. And = 0,
  146. Or = 1,
  147. Xor = 2,
  148. PassB = 3,
  149. };
  150. enum class SubOp : u64 {
  151. Cos = 0x0,
  152. Sin = 0x1,
  153. Ex2 = 0x2,
  154. Lg2 = 0x3,
  155. Rcp = 0x4,
  156. Rsq = 0x5,
  157. Sqrt = 0x8,
  158. };
  159. enum class F2iRoundingOp : u64 {
  160. RoundEven = 0,
  161. Floor = 1,
  162. Ceil = 2,
  163. Trunc = 3,
  164. };
  165. enum class F2fRoundingOp : u64 {
  166. None = 0,
  167. Pass = 3,
  168. Round = 8,
  169. Floor = 9,
  170. Ceil = 10,
  171. Trunc = 11,
  172. };
  173. enum class AtomicOp : u64 {
  174. Add = 0,
  175. Min = 1,
  176. Max = 2,
  177. Inc = 3,
  178. Dec = 4,
  179. And = 5,
  180. Or = 6,
  181. Xor = 7,
  182. Exch = 8,
  183. };
  184. enum class UniformType : u64 {
  185. UnsignedByte = 0,
  186. SignedByte = 1,
  187. UnsignedShort = 2,
  188. SignedShort = 3,
  189. Single = 4,
  190. Double = 5,
  191. Quad = 6,
  192. UnsignedQuad = 7,
  193. };
  194. enum class StoreType : u64 {
  195. Unsigned8 = 0,
  196. Signed8 = 1,
  197. Unsigned16 = 2,
  198. Signed16 = 3,
  199. Bits32 = 4,
  200. Bits64 = 5,
  201. Bits128 = 6,
  202. };
  203. enum class AtomicType : u64 {
  204. U32 = 0,
  205. S32 = 1,
  206. U64 = 2,
  207. S64 = 3,
  208. };
  209. enum class IMinMaxExchange : u64 {
  210. None = 0,
  211. XLo = 1,
  212. XMed = 2,
  213. XHi = 3,
  214. };
  215. enum class VideoType : u64 {
  216. Size16_Low = 0,
  217. Size16_High = 1,
  218. Size32 = 2,
  219. Invalid = 3,
  220. };
  221. enum class VmadShr : u64 {
  222. Shr7 = 1,
  223. Shr15 = 2,
  224. };
  225. enum class XmadMode : u64 {
  226. None = 0,
  227. CLo = 1,
  228. CHi = 2,
  229. CSfu = 3,
  230. CBcc = 4,
  231. };
  232. enum class IAdd3Mode : u64 {
  233. None = 0,
  234. RightShift = 1,
  235. LeftShift = 2,
  236. };
  237. enum class IAdd3Height : u64 {
  238. None = 0,
  239. LowerHalfWord = 1,
  240. UpperHalfWord = 2,
  241. };
  242. enum class FlowCondition : u64 {
  243. Always = 0xF,
  244. Fcsm_Tr = 0x1C, // TODO(bunnei): What is this used for?
  245. };
  246. enum class ConditionCode : u64 {
  247. F = 0,
  248. LT = 1,
  249. EQ = 2,
  250. LE = 3,
  251. GT = 4,
  252. NE = 5,
  253. GE = 6,
  254. Num = 7,
  255. Nan = 8,
  256. LTU = 9,
  257. EQU = 10,
  258. LEU = 11,
  259. GTU = 12,
  260. NEU = 13,
  261. GEU = 14,
  262. T = 15,
  263. OFF = 16,
  264. LO = 17,
  265. SFF = 18,
  266. LS = 19,
  267. HI = 20,
  268. SFT = 21,
  269. HS = 22,
  270. OFT = 23,
  271. CSM_TA = 24,
  272. CSM_TR = 25,
  273. CSM_MX = 26,
  274. FCSM_TA = 27,
  275. FCSM_TR = 28,
  276. FCSM_MX = 29,
  277. RLE = 30,
  278. RGT = 31,
  279. };
  280. enum class PredicateResultMode : u64 {
  281. None = 0x0,
  282. NotZero = 0x3,
  283. };
  284. enum class TextureType : u64 {
  285. Texture1D = 0,
  286. Texture2D = 1,
  287. Texture3D = 2,
  288. TextureCube = 3,
  289. };
  290. enum class TextureQueryType : u64 {
  291. Dimension = 1,
  292. TextureType = 2,
  293. SamplePosition = 5,
  294. Filter = 16,
  295. LevelOfDetail = 18,
  296. Wrap = 20,
  297. BorderColor = 22,
  298. };
  299. enum class TextureProcessMode : u64 {
  300. None = 0,
  301. LZ = 1, // Load LOD of zero.
  302. LB = 2, // Load Bias.
  303. LL = 3, // Load LOD.
  304. LBA = 6, // Load Bias. The A is unknown, does not appear to differ with LB.
  305. LLA = 7 // Load LOD. The A is unknown, does not appear to differ with LL.
  306. };
  307. enum class TextureMiscMode : u64 {
  308. DC,
  309. AOFFI, // Uses Offset
  310. NDV,
  311. NODEP,
  312. MZ,
  313. PTP,
  314. };
  315. enum class SurfaceDataMode : u64 {
  316. P = 0,
  317. D_BA = 1,
  318. };
  319. enum class OutOfBoundsStore : u64 {
  320. Ignore = 0,
  321. Clamp = 1,
  322. Trap = 2,
  323. };
  324. enum class ImageType : u64 {
  325. Texture1D = 0,
  326. TextureBuffer = 1,
  327. Texture1DArray = 2,
  328. Texture2D = 3,
  329. Texture2DArray = 4,
  330. Texture3D = 5,
  331. };
  332. enum class IsberdMode : u64 {
  333. None = 0,
  334. Patch = 1,
  335. Prim = 2,
  336. Attr = 3,
  337. };
  338. enum class IsberdShift : u64 { None = 0, U16 = 1, B32 = 2 };
  339. enum class MembarType : u64 {
  340. CTA = 0,
  341. GL = 1,
  342. SYS = 2,
  343. VC = 3,
  344. };
  345. enum class MembarUnknown : u64 { Default = 0, IVALLD = 1, IVALLT = 2, IVALLTD = 3 };
  346. enum class HalfType : u64 {
  347. H0_H1 = 0,
  348. F32 = 1,
  349. H0_H0 = 2,
  350. H1_H1 = 3,
  351. };
  352. enum class HalfMerge : u64 {
  353. H0_H1 = 0,
  354. F32 = 1,
  355. Mrg_H0 = 2,
  356. Mrg_H1 = 3,
  357. };
  358. enum class HalfPrecision : u64 {
  359. None = 0,
  360. FTZ = 1,
  361. FMZ = 2,
  362. };
  363. enum class R2pMode : u64 {
  364. Pr = 0,
  365. Cc = 1,
  366. };
  367. enum class IpaInterpMode : u64 {
  368. Pass = 0,
  369. Multiply = 1,
  370. Constant = 2,
  371. Sc = 3,
  372. };
  373. enum class IpaSampleMode : u64 {
  374. Default = 0,
  375. Centroid = 1,
  376. Offset = 2,
  377. };
  378. enum class LmemLoadCacheManagement : u64 {
  379. Default = 0,
  380. LU = 1,
  381. CI = 2,
  382. CV = 3,
  383. };
  384. enum class StoreCacheManagement : u64 {
  385. Default = 0,
  386. CG = 1,
  387. CS = 2,
  388. WT = 3,
  389. };
  390. struct IpaMode {
  391. IpaInterpMode interpolation_mode;
  392. IpaSampleMode sampling_mode;
  393. bool operator==(const IpaMode& a) const {
  394. return std::tie(interpolation_mode, sampling_mode) ==
  395. std::tie(a.interpolation_mode, a.sampling_mode);
  396. }
  397. bool operator!=(const IpaMode& a) const {
  398. return !operator==(a);
  399. }
  400. bool operator<(const IpaMode& a) const {
  401. return std::tie(interpolation_mode, sampling_mode) <
  402. std::tie(a.interpolation_mode, a.sampling_mode);
  403. }
  404. };
  405. enum class SystemVariable : u64 {
  406. LaneId = 0x00,
  407. VirtCfg = 0x02,
  408. VirtId = 0x03,
  409. Pm0 = 0x04,
  410. Pm1 = 0x05,
  411. Pm2 = 0x06,
  412. Pm3 = 0x07,
  413. Pm4 = 0x08,
  414. Pm5 = 0x09,
  415. Pm6 = 0x0a,
  416. Pm7 = 0x0b,
  417. OrderingTicket = 0x0f,
  418. PrimType = 0x10,
  419. InvocationId = 0x11,
  420. Ydirection = 0x12,
  421. ThreadKill = 0x13,
  422. ShaderType = 0x14,
  423. DirectBeWriteAddressLow = 0x15,
  424. DirectBeWriteAddressHigh = 0x16,
  425. DirectBeWriteEnabled = 0x17,
  426. MachineId0 = 0x18,
  427. MachineId1 = 0x19,
  428. MachineId2 = 0x1a,
  429. MachineId3 = 0x1b,
  430. Affinity = 0x1c,
  431. InvocationInfo = 0x1d,
  432. WscaleFactorXY = 0x1e,
  433. WscaleFactorZ = 0x1f,
  434. Tid = 0x20,
  435. TidX = 0x21,
  436. TidY = 0x22,
  437. TidZ = 0x23,
  438. CtaParam = 0x24,
  439. CtaIdX = 0x25,
  440. CtaIdY = 0x26,
  441. CtaIdZ = 0x27,
  442. NtId = 0x28,
  443. CirQueueIncrMinusOne = 0x29,
  444. Nlatc = 0x2a,
  445. SmSpaVersion = 0x2c,
  446. MultiPassShaderInfo = 0x2d,
  447. LwinHi = 0x2e,
  448. SwinHi = 0x2f,
  449. SwinLo = 0x30,
  450. SwinSz = 0x31,
  451. SmemSz = 0x32,
  452. SmemBanks = 0x33,
  453. LwinLo = 0x34,
  454. LwinSz = 0x35,
  455. LmemLosz = 0x36,
  456. LmemHioff = 0x37,
  457. EqMask = 0x38,
  458. LtMask = 0x39,
  459. LeMask = 0x3a,
  460. GtMask = 0x3b,
  461. GeMask = 0x3c,
  462. RegAlloc = 0x3d,
  463. CtxAddr = 0x3e, // .fmask = F_SM50
  464. BarrierAlloc = 0x3e, // .fmask = F_SM60
  465. GlobalErrorStatus = 0x40,
  466. WarpErrorStatus = 0x42,
  467. WarpErrorStatusClear = 0x43,
  468. PmHi0 = 0x48,
  469. PmHi1 = 0x49,
  470. PmHi2 = 0x4a,
  471. PmHi3 = 0x4b,
  472. PmHi4 = 0x4c,
  473. PmHi5 = 0x4d,
  474. PmHi6 = 0x4e,
  475. PmHi7 = 0x4f,
  476. ClockLo = 0x50,
  477. ClockHi = 0x51,
  478. GlobalTimerLo = 0x52,
  479. GlobalTimerHi = 0x53,
  480. HwTaskId = 0x60,
  481. CircularQueueEntryIndex = 0x61,
  482. CircularQueueEntryAddressLow = 0x62,
  483. CircularQueueEntryAddressHigh = 0x63,
  484. };
  485. enum class PhysicalAttributeDirection : u64 {
  486. Input = 0,
  487. Output = 1,
  488. };
  489. enum class VoteOperation : u64 {
  490. All = 0, // allThreadsNV
  491. Any = 1, // anyThreadNV
  492. Eq = 2, // allThreadsEqualNV
  493. };
  494. enum class ImageAtomicOperationType : u64 {
  495. U32 = 0,
  496. S32 = 1,
  497. U64 = 2,
  498. F32 = 3,
  499. S64 = 5,
  500. SD32 = 6,
  501. SD64 = 7,
  502. };
  503. enum class ImageAtomicOperation : u64 {
  504. Add = 0,
  505. Min = 1,
  506. Max = 2,
  507. Inc = 3,
  508. Dec = 4,
  509. And = 5,
  510. Or = 6,
  511. Xor = 7,
  512. Exch = 8,
  513. };
  514. enum class ShuffleOperation : u64 {
  515. Idx = 0, // shuffleNV
  516. Up = 1, // shuffleUpNV
  517. Down = 2, // shuffleDownNV
  518. Bfly = 3, // shuffleXorNV
  519. };
  520. union Instruction {
  521. constexpr Instruction& operator=(const Instruction& instr) {
  522. value = instr.value;
  523. return *this;
  524. }
  525. constexpr Instruction(u64 value) : value{value} {}
  526. BitField<0, 8, Register> gpr0;
  527. BitField<8, 8, Register> gpr8;
  528. union {
  529. BitField<16, 4, Pred> full_pred;
  530. BitField<16, 3, u64> pred_index;
  531. } pred;
  532. BitField<19, 1, u64> negate_pred;
  533. BitField<20, 8, Register> gpr20;
  534. BitField<20, 4, SubOp> sub_op;
  535. BitField<28, 8, Register> gpr28;
  536. BitField<39, 8, Register> gpr39;
  537. BitField<48, 16, u64> opcode;
  538. union {
  539. BitField<8, 5, ConditionCode> cc;
  540. BitField<13, 1, u64> trigger;
  541. } nop;
  542. union {
  543. BitField<48, 2, VoteOperation> operation;
  544. BitField<45, 3, u64> dest_pred;
  545. BitField<39, 3, u64> value;
  546. BitField<42, 1, u64> negate_value;
  547. } vote;
  548. union {
  549. BitField<30, 2, ShuffleOperation> operation;
  550. BitField<48, 3, u64> pred48;
  551. BitField<28, 1, u64> is_index_imm;
  552. BitField<29, 1, u64> is_mask_imm;
  553. BitField<20, 5, u64> index_imm;
  554. BitField<34, 13, u64> mask_imm;
  555. } shfl;
  556. union {
  557. BitField<44, 1, u64> ftz;
  558. BitField<39, 2, u64> tab5cb8_2;
  559. BitField<38, 1, u64> ndv;
  560. BitField<47, 1, u64> cc;
  561. BitField<28, 8, u64> swizzle;
  562. } fswzadd;
  563. union {
  564. BitField<8, 8, Register> gpr;
  565. BitField<20, 24, s64> offset;
  566. } gmem;
  567. union {
  568. BitField<20, 16, u64> imm20_16;
  569. BitField<20, 19, u64> imm20_19;
  570. BitField<20, 32, s64> imm20_32;
  571. BitField<45, 1, u64> negate_b;
  572. BitField<46, 1, u64> abs_a;
  573. BitField<48, 1, u64> negate_a;
  574. BitField<49, 1, u64> abs_b;
  575. BitField<50, 1, u64> saturate_d;
  576. BitField<56, 1, u64> negate_imm;
  577. union {
  578. BitField<39, 3, u64> pred;
  579. BitField<42, 1, u64> negate_pred;
  580. } fmnmx;
  581. union {
  582. BitField<39, 1, u64> invert_a;
  583. BitField<40, 1, u64> invert_b;
  584. BitField<41, 2, LogicOperation> operation;
  585. BitField<44, 2, PredicateResultMode> pred_result_mode;
  586. BitField<48, 3, Pred> pred48;
  587. } lop;
  588. union {
  589. BitField<53, 2, LogicOperation> operation;
  590. BitField<55, 1, u64> invert_a;
  591. BitField<56, 1, u64> invert_b;
  592. } lop32i;
  593. union {
  594. BitField<28, 8, u64> imm_lut28;
  595. BitField<48, 8, u64> imm_lut48;
  596. u32 GetImmLut28() const {
  597. return static_cast<u32>(imm_lut28);
  598. }
  599. u32 GetImmLut48() const {
  600. return static_cast<u32>(imm_lut48);
  601. }
  602. } lop3;
  603. u16 GetImm20_16() const {
  604. return static_cast<u16>(imm20_16);
  605. }
  606. u32 GetImm20_19() const {
  607. u32 imm{static_cast<u32>(imm20_19)};
  608. imm <<= 12;
  609. imm |= negate_imm ? 0x80000000 : 0;
  610. return imm;
  611. }
  612. u32 GetImm20_32() const {
  613. return static_cast<u32>(imm20_32);
  614. }
  615. s32 GetSignedImm20_20() const {
  616. u32 immediate = static_cast<u32>(imm20_19 | (negate_imm << 19));
  617. // Sign extend the 20-bit value.
  618. u32 mask = 1U << (20 - 1);
  619. return static_cast<s32>((immediate ^ mask) - mask);
  620. }
  621. } alu;
  622. union {
  623. BitField<38, 1, u64> idx;
  624. BitField<51, 1, u64> saturate;
  625. BitField<52, 2, IpaSampleMode> sample_mode;
  626. BitField<54, 2, IpaInterpMode> interp_mode;
  627. } ipa;
  628. union {
  629. BitField<39, 2, u64> tab5cb8_2;
  630. BitField<41, 3, u64> postfactor;
  631. BitField<44, 2, u64> tab5c68_0;
  632. BitField<48, 1, u64> negate_b;
  633. } fmul;
  634. union {
  635. BitField<55, 1, u64> saturate;
  636. } fmul32;
  637. union {
  638. BitField<52, 1, u64> generates_cc;
  639. } op_32;
  640. union {
  641. BitField<48, 1, u64> is_signed;
  642. } shift;
  643. union {
  644. BitField<39, 1, u64> wrap;
  645. } shr;
  646. union {
  647. BitField<39, 5, u64> shift_amount;
  648. BitField<48, 1, u64> negate_b;
  649. BitField<49, 1, u64> negate_a;
  650. } alu_integer;
  651. union {
  652. BitField<39, 1, u64> ftz;
  653. BitField<32, 1, u64> saturate;
  654. BitField<49, 2, HalfMerge> merge;
  655. BitField<43, 1, u64> negate_a;
  656. BitField<44, 1, u64> abs_a;
  657. BitField<47, 2, HalfType> type_a;
  658. BitField<31, 1, u64> negate_b;
  659. BitField<30, 1, u64> abs_b;
  660. BitField<28, 2, HalfType> type_b;
  661. BitField<35, 2, HalfType> type_c;
  662. } alu_half;
  663. union {
  664. BitField<39, 2, HalfPrecision> precision;
  665. BitField<39, 1, u64> ftz;
  666. BitField<52, 1, u64> saturate;
  667. BitField<49, 2, HalfMerge> merge;
  668. BitField<43, 1, u64> negate_a;
  669. BitField<44, 1, u64> abs_a;
  670. BitField<47, 2, HalfType> type_a;
  671. } alu_half_imm;
  672. union {
  673. BitField<29, 1, u64> first_negate;
  674. BitField<20, 9, u64> first;
  675. BitField<56, 1, u64> second_negate;
  676. BitField<30, 9, u64> second;
  677. u32 PackImmediates() const {
  678. // Immediates are half floats shifted.
  679. constexpr u32 imm_shift = 6;
  680. return static_cast<u32>((first << imm_shift) | (second << (16 + imm_shift)));
  681. }
  682. } half_imm;
  683. union {
  684. union {
  685. BitField<37, 2, HalfPrecision> precision;
  686. BitField<32, 1, u64> saturate;
  687. BitField<31, 1, u64> negate_b;
  688. BitField<30, 1, u64> negate_c;
  689. BitField<35, 2, HalfType> type_c;
  690. } rr;
  691. BitField<57, 2, HalfPrecision> precision;
  692. BitField<52, 1, u64> saturate;
  693. BitField<49, 2, HalfMerge> merge;
  694. BitField<47, 2, HalfType> type_a;
  695. BitField<56, 1, u64> negate_b;
  696. BitField<28, 2, HalfType> type_b;
  697. BitField<51, 1, u64> negate_c;
  698. BitField<53, 2, HalfType> type_reg39;
  699. } hfma2;
  700. union {
  701. BitField<40, 1, u64> invert;
  702. } popc;
  703. union {
  704. BitField<41, 1, u64> sh;
  705. BitField<40, 1, u64> invert;
  706. BitField<48, 1, u64> is_signed;
  707. } flo;
  708. union {
  709. BitField<39, 3, u64> pred;
  710. BitField<42, 1, u64> neg_pred;
  711. } sel;
  712. union {
  713. BitField<39, 3, u64> pred;
  714. BitField<42, 1, u64> negate_pred;
  715. BitField<43, 2, IMinMaxExchange> exchange;
  716. BitField<48, 1, u64> is_signed;
  717. } imnmx;
  718. union {
  719. BitField<31, 2, IAdd3Height> height_c;
  720. BitField<33, 2, IAdd3Height> height_b;
  721. BitField<35, 2, IAdd3Height> height_a;
  722. BitField<37, 2, IAdd3Mode> mode;
  723. BitField<49, 1, u64> neg_c;
  724. BitField<50, 1, u64> neg_b;
  725. BitField<51, 1, u64> neg_a;
  726. } iadd3;
  727. union {
  728. BitField<54, 1, u64> saturate;
  729. BitField<56, 1, u64> negate_a;
  730. } iadd32i;
  731. union {
  732. BitField<53, 1, u64> negate_b;
  733. BitField<54, 1, u64> abs_a;
  734. BitField<56, 1, u64> negate_a;
  735. BitField<57, 1, u64> abs_b;
  736. } fadd32i;
  737. union {
  738. BitField<20, 8, u64> shift_position;
  739. BitField<28, 8, u64> shift_length;
  740. BitField<48, 1, u64> negate_b;
  741. BitField<49, 1, u64> negate_a;
  742. u64 GetLeftShiftValue() const {
  743. return 32 - (shift_position + shift_length);
  744. }
  745. } bfe;
  746. union {
  747. BitField<48, 3, u64> pred48;
  748. union {
  749. BitField<20, 20, u64> entry_a;
  750. BitField<39, 5, u64> entry_b;
  751. BitField<45, 1, u64> neg;
  752. BitField<46, 1, u64> uses_cc;
  753. } imm;
  754. union {
  755. BitField<20, 14, u64> cb_index;
  756. BitField<34, 5, u64> cb_offset;
  757. BitField<56, 1, u64> neg;
  758. BitField<57, 1, u64> uses_cc;
  759. } hi;
  760. union {
  761. BitField<20, 14, u64> cb_index;
  762. BitField<34, 5, u64> cb_offset;
  763. BitField<39, 5, u64> entry_a;
  764. BitField<45, 1, u64> neg;
  765. BitField<46, 1, u64> uses_cc;
  766. } rz;
  767. union {
  768. BitField<39, 5, u64> entry_a;
  769. BitField<45, 1, u64> neg;
  770. BitField<46, 1, u64> uses_cc;
  771. } r1;
  772. union {
  773. BitField<28, 8, u64> entry_a;
  774. BitField<37, 1, u64> neg;
  775. BitField<38, 1, u64> uses_cc;
  776. } r2;
  777. } lea;
  778. union {
  779. BitField<0, 5, FlowCondition> cond;
  780. } flow;
  781. union {
  782. BitField<47, 1, u64> cc;
  783. BitField<48, 1, u64> negate_b;
  784. BitField<49, 1, u64> negate_c;
  785. BitField<51, 2, u64> tab5980_1;
  786. BitField<53, 2, u64> tab5980_0;
  787. } ffma;
  788. union {
  789. BitField<48, 3, UniformType> type;
  790. BitField<44, 2, u64> unknown;
  791. } ld_c;
  792. union {
  793. BitField<48, 3, StoreType> type;
  794. } ldst_sl;
  795. union {
  796. BitField<44, 2, u64> unknown;
  797. } ld_l;
  798. union {
  799. BitField<44, 2, StoreCacheManagement> cache_management;
  800. } st_l;
  801. union {
  802. BitField<48, 3, UniformType> type;
  803. BitField<46, 2, u64> cache_mode;
  804. } ldg;
  805. union {
  806. BitField<48, 3, UniformType> type;
  807. BitField<46, 2, u64> cache_mode;
  808. } stg;
  809. union {
  810. BitField<52, 4, AtomicOp> operation;
  811. BitField<28, 2, AtomicType> type;
  812. BitField<30, 22, s64> offset;
  813. s32 GetImmediateOffset() const {
  814. return static_cast<s32>(offset << 2);
  815. }
  816. } atoms;
  817. union {
  818. BitField<32, 1, PhysicalAttributeDirection> direction;
  819. BitField<47, 3, AttributeSize> size;
  820. BitField<20, 11, u64> address;
  821. } al2p;
  822. union {
  823. BitField<53, 3, UniformType> type;
  824. BitField<52, 1, u64> extended;
  825. } generic;
  826. union {
  827. BitField<0, 3, u64> pred0;
  828. BitField<3, 3, u64> pred3;
  829. BitField<6, 1, u64> neg_b;
  830. BitField<7, 1, u64> abs_a;
  831. BitField<39, 3, u64> pred39;
  832. BitField<42, 1, u64> neg_pred;
  833. BitField<43, 1, u64> neg_a;
  834. BitField<44, 1, u64> abs_b;
  835. BitField<45, 2, PredOperation> op;
  836. BitField<47, 1, u64> ftz;
  837. BitField<48, 4, PredCondition> cond;
  838. } fsetp;
  839. union {
  840. BitField<0, 3, u64> pred0;
  841. BitField<3, 3, u64> pred3;
  842. BitField<39, 3, u64> pred39;
  843. BitField<42, 1, u64> neg_pred;
  844. BitField<45, 2, PredOperation> op;
  845. BitField<48, 1, u64> is_signed;
  846. BitField<49, 3, PredCondition> cond;
  847. } isetp;
  848. union {
  849. BitField<48, 1, u64> is_signed;
  850. BitField<49, 3, PredCondition> cond;
  851. } icmp;
  852. union {
  853. BitField<0, 3, u64> pred0;
  854. BitField<3, 3, u64> pred3;
  855. BitField<12, 3, u64> pred12;
  856. BitField<15, 1, u64> neg_pred12;
  857. BitField<24, 2, PredOperation> cond;
  858. BitField<29, 3, u64> pred29;
  859. BitField<32, 1, u64> neg_pred29;
  860. BitField<39, 3, u64> pred39;
  861. BitField<42, 1, u64> neg_pred39;
  862. BitField<45, 2, PredOperation> op;
  863. } psetp;
  864. union {
  865. BitField<43, 4, PredCondition> cond;
  866. BitField<45, 2, PredOperation> op;
  867. BitField<3, 3, u64> pred3;
  868. BitField<0, 3, u64> pred0;
  869. BitField<39, 3, u64> pred39;
  870. } vsetp;
  871. union {
  872. BitField<12, 3, u64> pred12;
  873. BitField<15, 1, u64> neg_pred12;
  874. BitField<24, 2, PredOperation> cond;
  875. BitField<29, 3, u64> pred29;
  876. BitField<32, 1, u64> neg_pred29;
  877. BitField<39, 3, u64> pred39;
  878. BitField<42, 1, u64> neg_pred39;
  879. BitField<44, 1, u64> bf;
  880. BitField<45, 2, PredOperation> op;
  881. } pset;
  882. union {
  883. BitField<0, 3, u64> pred0;
  884. BitField<3, 3, u64> pred3;
  885. BitField<8, 5, ConditionCode> cc; // flag in cc
  886. BitField<39, 3, u64> pred39;
  887. BitField<42, 1, u64> neg_pred39;
  888. BitField<45, 4, PredOperation> op; // op with pred39
  889. } csetp;
  890. union {
  891. BitField<6, 1, u64> ftz;
  892. BitField<45, 2, PredOperation> op;
  893. BitField<3, 3, u64> pred3;
  894. BitField<0, 3, u64> pred0;
  895. BitField<43, 1, u64> negate_a;
  896. BitField<44, 1, u64> abs_a;
  897. BitField<47, 2, HalfType> type_a;
  898. union {
  899. BitField<35, 4, PredCondition> cond;
  900. BitField<49, 1, u64> h_and;
  901. BitField<31, 1, u64> negate_b;
  902. BitField<30, 1, u64> abs_b;
  903. BitField<28, 2, HalfType> type_b;
  904. } reg;
  905. union {
  906. BitField<56, 1, u64> negate_b;
  907. BitField<54, 1, u64> abs_b;
  908. } cbuf;
  909. union {
  910. BitField<49, 4, PredCondition> cond;
  911. BitField<53, 1, u64> h_and;
  912. } cbuf_and_imm;
  913. BitField<42, 1, u64> neg_pred;
  914. BitField<39, 3, u64> pred39;
  915. } hsetp2;
  916. union {
  917. BitField<40, 1, R2pMode> mode;
  918. BitField<41, 2, u64> byte;
  919. BitField<20, 7, u64> immediate_mask;
  920. } p2r_r2p;
  921. union {
  922. BitField<39, 3, u64> pred39;
  923. BitField<42, 1, u64> neg_pred;
  924. BitField<43, 1, u64> neg_a;
  925. BitField<44, 1, u64> abs_b;
  926. BitField<45, 2, PredOperation> op;
  927. BitField<48, 4, PredCondition> cond;
  928. BitField<52, 1, u64> bf;
  929. BitField<53, 1, u64> neg_b;
  930. BitField<54, 1, u64> abs_a;
  931. BitField<55, 1, u64> ftz;
  932. } fset;
  933. union {
  934. BitField<49, 1, u64> bf;
  935. BitField<35, 3, PredCondition> cond;
  936. BitField<50, 1, u64> ftz;
  937. BitField<45, 2, PredOperation> op;
  938. BitField<43, 1, u64> negate_a;
  939. BitField<44, 1, u64> abs_a;
  940. BitField<47, 2, HalfType> type_a;
  941. BitField<31, 1, u64> negate_b;
  942. BitField<30, 1, u64> abs_b;
  943. BitField<28, 2, HalfType> type_b;
  944. BitField<42, 1, u64> neg_pred;
  945. BitField<39, 3, u64> pred39;
  946. } hset2;
  947. union {
  948. BitField<39, 3, u64> pred39;
  949. BitField<42, 1, u64> neg_pred;
  950. BitField<44, 1, u64> bf;
  951. BitField<45, 2, PredOperation> op;
  952. BitField<48, 1, u64> is_signed;
  953. BitField<49, 3, PredCondition> cond;
  954. } iset;
  955. union {
  956. BitField<45, 1, u64> negate_a;
  957. BitField<49, 1, u64> abs_a;
  958. BitField<10, 2, Register::Size> src_size;
  959. BitField<13, 1, u64> is_input_signed;
  960. BitField<8, 2, Register::Size> dst_size;
  961. BitField<12, 1, u64> is_output_signed;
  962. union {
  963. BitField<39, 2, u64> tab5cb8_2;
  964. } i2f;
  965. union {
  966. BitField<39, 2, F2iRoundingOp> rounding;
  967. } f2i;
  968. union {
  969. BitField<39, 4, u64> rounding;
  970. // H0, H1 extract for F16 missing
  971. BitField<41, 1, u64> selector; // Guessed as some games set it, TODO: reverse this value
  972. F2fRoundingOp GetRoundingMode() const {
  973. constexpr u64 rounding_mask = 0x0B;
  974. return static_cast<F2fRoundingOp>(rounding.Value() & rounding_mask);
  975. }
  976. } f2f;
  977. union {
  978. BitField<41, 2, u64> selector;
  979. } int_src;
  980. union {
  981. BitField<41, 1, u64> selector;
  982. } float_src;
  983. } conversion;
  984. union {
  985. BitField<28, 1, u64> array;
  986. BitField<29, 2, TextureType> texture_type;
  987. BitField<31, 4, u64> component_mask;
  988. BitField<49, 1, u64> nodep_flag;
  989. BitField<50, 1, u64> dc_flag;
  990. BitField<54, 1, u64> aoffi_flag;
  991. BitField<55, 3, TextureProcessMode> process_mode;
  992. bool IsComponentEnabled(std::size_t component) const {
  993. return ((1ull << component) & component_mask) != 0;
  994. }
  995. TextureProcessMode GetTextureProcessMode() const {
  996. return process_mode;
  997. }
  998. bool UsesMiscMode(TextureMiscMode mode) const {
  999. switch (mode) {
  1000. case TextureMiscMode::DC:
  1001. return dc_flag != 0;
  1002. case TextureMiscMode::NODEP:
  1003. return nodep_flag != 0;
  1004. case TextureMiscMode::AOFFI:
  1005. return aoffi_flag != 0;
  1006. default:
  1007. break;
  1008. }
  1009. return false;
  1010. }
  1011. } tex;
  1012. union {
  1013. BitField<28, 1, u64> array;
  1014. BitField<29, 2, TextureType> texture_type;
  1015. BitField<31, 4, u64> component_mask;
  1016. BitField<49, 1, u64> nodep_flag;
  1017. BitField<50, 1, u64> dc_flag;
  1018. BitField<36, 1, u64> aoffi_flag;
  1019. BitField<37, 3, TextureProcessMode> process_mode;
  1020. bool IsComponentEnabled(std::size_t component) const {
  1021. return ((1ULL << component) & component_mask) != 0;
  1022. }
  1023. TextureProcessMode GetTextureProcessMode() const {
  1024. return process_mode;
  1025. }
  1026. bool UsesMiscMode(TextureMiscMode mode) const {
  1027. switch (mode) {
  1028. case TextureMiscMode::DC:
  1029. return dc_flag != 0;
  1030. case TextureMiscMode::NODEP:
  1031. return nodep_flag != 0;
  1032. case TextureMiscMode::AOFFI:
  1033. return aoffi_flag != 0;
  1034. default:
  1035. break;
  1036. }
  1037. return false;
  1038. }
  1039. } tex_b;
  1040. union {
  1041. BitField<22, 6, TextureQueryType> query_type;
  1042. BitField<31, 4, u64> component_mask;
  1043. BitField<49, 1, u64> nodep_flag;
  1044. bool UsesMiscMode(TextureMiscMode mode) const {
  1045. switch (mode) {
  1046. case TextureMiscMode::NODEP:
  1047. return nodep_flag != 0;
  1048. default:
  1049. break;
  1050. }
  1051. return false;
  1052. }
  1053. bool IsComponentEnabled(std::size_t component) const {
  1054. return ((1ULL << component) & component_mask) != 0;
  1055. }
  1056. } txq;
  1057. union {
  1058. BitField<28, 1, u64> array;
  1059. BitField<29, 2, TextureType> texture_type;
  1060. BitField<31, 4, u64> component_mask;
  1061. BitField<35, 1, u64> ndv_flag;
  1062. BitField<49, 1, u64> nodep_flag;
  1063. bool IsComponentEnabled(std::size_t component) const {
  1064. return ((1ull << component) & component_mask) != 0;
  1065. }
  1066. bool UsesMiscMode(TextureMiscMode mode) const {
  1067. switch (mode) {
  1068. case TextureMiscMode::NDV:
  1069. return (ndv_flag != 0);
  1070. case TextureMiscMode::NODEP:
  1071. return (nodep_flag != 0);
  1072. default:
  1073. break;
  1074. }
  1075. return false;
  1076. }
  1077. } tmml;
  1078. union {
  1079. BitField<28, 1, u64> array;
  1080. BitField<29, 2, TextureType> texture_type;
  1081. BitField<35, 1, u64> ndv_flag;
  1082. BitField<49, 1, u64> nodep_flag;
  1083. BitField<50, 1, u64> dc_flag;
  1084. BitField<54, 2, u64> offset_mode;
  1085. BitField<56, 2, u64> component;
  1086. bool UsesMiscMode(TextureMiscMode mode) const {
  1087. switch (mode) {
  1088. case TextureMiscMode::NDV:
  1089. return ndv_flag != 0;
  1090. case TextureMiscMode::NODEP:
  1091. return nodep_flag != 0;
  1092. case TextureMiscMode::DC:
  1093. return dc_flag != 0;
  1094. case TextureMiscMode::AOFFI:
  1095. return offset_mode == 1;
  1096. case TextureMiscMode::PTP:
  1097. return offset_mode == 2;
  1098. default:
  1099. break;
  1100. }
  1101. return false;
  1102. }
  1103. } tld4;
  1104. union {
  1105. BitField<35, 1, u64> ndv_flag;
  1106. BitField<49, 1, u64> nodep_flag;
  1107. BitField<50, 1, u64> dc_flag;
  1108. BitField<33, 2, u64> offset_mode;
  1109. BitField<37, 2, u64> component;
  1110. bool UsesMiscMode(TextureMiscMode mode) const {
  1111. switch (mode) {
  1112. case TextureMiscMode::NDV:
  1113. return ndv_flag != 0;
  1114. case TextureMiscMode::NODEP:
  1115. return nodep_flag != 0;
  1116. case TextureMiscMode::DC:
  1117. return dc_flag != 0;
  1118. case TextureMiscMode::AOFFI:
  1119. return offset_mode == 1;
  1120. case TextureMiscMode::PTP:
  1121. return offset_mode == 2;
  1122. default:
  1123. break;
  1124. }
  1125. return false;
  1126. }
  1127. } tld4_b;
  1128. union {
  1129. BitField<49, 1, u64> nodep_flag;
  1130. BitField<50, 1, u64> dc_flag;
  1131. BitField<51, 1, u64> aoffi_flag;
  1132. BitField<52, 2, u64> component;
  1133. BitField<55, 1, u64> fp16_flag;
  1134. bool UsesMiscMode(TextureMiscMode mode) const {
  1135. switch (mode) {
  1136. case TextureMiscMode::DC:
  1137. return dc_flag != 0;
  1138. case TextureMiscMode::NODEP:
  1139. return nodep_flag != 0;
  1140. case TextureMiscMode::AOFFI:
  1141. return aoffi_flag != 0;
  1142. default:
  1143. break;
  1144. }
  1145. return false;
  1146. }
  1147. } tld4s;
  1148. union {
  1149. BitField<0, 8, Register> gpr0;
  1150. BitField<28, 8, Register> gpr28;
  1151. BitField<49, 1, u64> nodep_flag;
  1152. BitField<50, 3, u64> component_mask_selector;
  1153. BitField<53, 4, u64> texture_info;
  1154. BitField<59, 1, u64> fp32_flag;
  1155. TextureType GetTextureType() const {
  1156. // The TEXS instruction has a weird encoding for the texture type.
  1157. if (texture_info == 0)
  1158. return TextureType::Texture1D;
  1159. if (texture_info >= 1 && texture_info <= 9)
  1160. return TextureType::Texture2D;
  1161. if (texture_info >= 10 && texture_info <= 11)
  1162. return TextureType::Texture3D;
  1163. if (texture_info >= 12 && texture_info <= 13)
  1164. return TextureType::TextureCube;
  1165. LOG_CRITICAL(HW_GPU, "Unhandled texture_info: {}",
  1166. static_cast<u32>(texture_info.Value()));
  1167. UNREACHABLE();
  1168. return TextureType::Texture1D;
  1169. }
  1170. TextureProcessMode GetTextureProcessMode() const {
  1171. switch (texture_info) {
  1172. case 0:
  1173. case 2:
  1174. case 6:
  1175. case 8:
  1176. case 9:
  1177. case 11:
  1178. return TextureProcessMode::LZ;
  1179. case 3:
  1180. case 5:
  1181. case 13:
  1182. return TextureProcessMode::LL;
  1183. default:
  1184. break;
  1185. }
  1186. return TextureProcessMode::None;
  1187. }
  1188. bool UsesMiscMode(TextureMiscMode mode) const {
  1189. switch (mode) {
  1190. case TextureMiscMode::DC:
  1191. return (texture_info >= 4 && texture_info <= 6) || texture_info == 9;
  1192. case TextureMiscMode::NODEP:
  1193. return nodep_flag != 0;
  1194. default:
  1195. break;
  1196. }
  1197. return false;
  1198. }
  1199. bool IsArrayTexture() const {
  1200. // TEXS only supports Texture2D arrays.
  1201. return texture_info >= 7 && texture_info <= 9;
  1202. }
  1203. bool HasTwoDestinations() const {
  1204. return gpr28.Value() != Register::ZeroIndex;
  1205. }
  1206. bool IsComponentEnabled(std::size_t component) const {
  1207. static constexpr std::array<std::array<u32, 8>, 4> mask_lut{{
  1208. {},
  1209. {0x1, 0x2, 0x4, 0x8, 0x3, 0x9, 0xa, 0xc},
  1210. {0x1, 0x2, 0x4, 0x8, 0x3, 0x9, 0xa, 0xc},
  1211. {0x7, 0xb, 0xd, 0xe, 0xf},
  1212. }};
  1213. std::size_t index{gpr0.Value() != Register::ZeroIndex ? 1U : 0U};
  1214. index |= gpr28.Value() != Register::ZeroIndex ? 2 : 0;
  1215. u32 mask = mask_lut[index][component_mask_selector];
  1216. // A mask of 0 means this instruction uses an unimplemented mask.
  1217. ASSERT(mask != 0);
  1218. return ((1ull << component) & mask) != 0;
  1219. }
  1220. } texs;
  1221. union {
  1222. BitField<28, 1, u64> is_array;
  1223. BitField<29, 2, TextureType> texture_type;
  1224. BitField<35, 1, u64> aoffi;
  1225. BitField<49, 1, u64> nodep_flag;
  1226. BitField<50, 1, u64> ms; // Multisample?
  1227. BitField<54, 1, u64> cl;
  1228. BitField<55, 1, u64> process_mode;
  1229. TextureProcessMode GetTextureProcessMode() const {
  1230. return process_mode == 0 ? TextureProcessMode::LZ : TextureProcessMode::LL;
  1231. }
  1232. } tld;
  1233. union {
  1234. BitField<49, 1, u64> nodep_flag;
  1235. BitField<53, 4, u64> texture_info;
  1236. BitField<59, 1, u64> fp32_flag;
  1237. TextureType GetTextureType() const {
  1238. // The TLDS instruction has a weird encoding for the texture type.
  1239. if (texture_info >= 0 && texture_info <= 1) {
  1240. return TextureType::Texture1D;
  1241. }
  1242. if (texture_info == 2 || texture_info == 8 || texture_info == 12 ||
  1243. (texture_info >= 4 && texture_info <= 6)) {
  1244. return TextureType::Texture2D;
  1245. }
  1246. if (texture_info == 7) {
  1247. return TextureType::Texture3D;
  1248. }
  1249. LOG_CRITICAL(HW_GPU, "Unhandled texture_info: {}",
  1250. static_cast<u32>(texture_info.Value()));
  1251. UNREACHABLE();
  1252. return TextureType::Texture1D;
  1253. }
  1254. TextureProcessMode GetTextureProcessMode() const {
  1255. if (texture_info == 1 || texture_info == 5 || texture_info == 12)
  1256. return TextureProcessMode::LL;
  1257. return TextureProcessMode::LZ;
  1258. }
  1259. bool UsesMiscMode(TextureMiscMode mode) const {
  1260. switch (mode) {
  1261. case TextureMiscMode::AOFFI:
  1262. return texture_info == 12 || texture_info == 4;
  1263. case TextureMiscMode::MZ:
  1264. return texture_info == 5;
  1265. case TextureMiscMode::NODEP:
  1266. return nodep_flag != 0;
  1267. default:
  1268. break;
  1269. }
  1270. return false;
  1271. }
  1272. bool IsArrayTexture() const {
  1273. // TEXS only supports Texture2D arrays.
  1274. return texture_info == 8;
  1275. }
  1276. } tlds;
  1277. union {
  1278. BitField<28, 1, u64> is_array;
  1279. BitField<29, 2, TextureType> texture_type;
  1280. BitField<35, 1, u64> aoffi_flag;
  1281. BitField<49, 1, u64> nodep_flag;
  1282. bool UsesMiscMode(TextureMiscMode mode) const {
  1283. switch (mode) {
  1284. case TextureMiscMode::AOFFI:
  1285. return aoffi_flag != 0;
  1286. case TextureMiscMode::NODEP:
  1287. return nodep_flag != 0;
  1288. default:
  1289. break;
  1290. }
  1291. return false;
  1292. }
  1293. } txd;
  1294. union {
  1295. BitField<24, 2, StoreCacheManagement> cache_management;
  1296. BitField<33, 3, ImageType> image_type;
  1297. BitField<49, 2, OutOfBoundsStore> out_of_bounds_store;
  1298. BitField<51, 1, u64> is_immediate;
  1299. BitField<52, 1, SurfaceDataMode> mode;
  1300. BitField<20, 3, StoreType> store_data_layout;
  1301. BitField<20, 4, u64> component_mask_selector;
  1302. bool IsComponentEnabled(std::size_t component) const {
  1303. ASSERT(mode == SurfaceDataMode::P);
  1304. constexpr u8 R = 0b0001;
  1305. constexpr u8 G = 0b0010;
  1306. constexpr u8 B = 0b0100;
  1307. constexpr u8 A = 0b1000;
  1308. constexpr std::array<u8, 16> mask = {
  1309. 0, (R), (G), (R | G), (B), (R | B),
  1310. (G | B), (R | G | B), (A), (R | A), (G | A), (R | G | A),
  1311. (B | A), (R | B | A), (G | B | A), (R | G | B | A)};
  1312. return std::bitset<4>{mask.at(component_mask_selector)}.test(component);
  1313. }
  1314. StoreType GetStoreDataLayout() const {
  1315. ASSERT(mode == SurfaceDataMode::D_BA);
  1316. return store_data_layout;
  1317. }
  1318. } suldst;
  1319. union {
  1320. BitField<28, 1, u64> is_ba;
  1321. BitField<51, 3, ImageAtomicOperationType> operation_type;
  1322. BitField<33, 3, ImageType> image_type;
  1323. BitField<29, 4, ImageAtomicOperation> operation;
  1324. BitField<49, 2, OutOfBoundsStore> out_of_bounds_store;
  1325. } suatom_d;
  1326. union {
  1327. BitField<20, 24, u64> target;
  1328. BitField<5, 1, u64> constant_buffer;
  1329. s32 GetBranchTarget() const {
  1330. // Sign extend the branch target offset
  1331. u32 mask = 1U << (24 - 1);
  1332. u32 value = static_cast<u32>(target);
  1333. // The branch offset is relative to the next instruction and is stored in bytes, so
  1334. // divide it by the size of an instruction and add 1 to it.
  1335. return static_cast<s32>((value ^ mask) - mask) / static_cast<s32>(sizeof(Instruction)) +
  1336. 1;
  1337. }
  1338. } bra;
  1339. union {
  1340. BitField<20, 24, u64> target;
  1341. BitField<5, 1, u64> constant_buffer;
  1342. s32 GetBranchExtend() const {
  1343. // Sign extend the branch target offset
  1344. u32 mask = 1U << (24 - 1);
  1345. u32 value = static_cast<u32>(target);
  1346. // The branch offset is relative to the next instruction and is stored in bytes, so
  1347. // divide it by the size of an instruction and add 1 to it.
  1348. return static_cast<s32>((value ^ mask) - mask) / static_cast<s32>(sizeof(Instruction)) +
  1349. 1;
  1350. }
  1351. } brx;
  1352. union {
  1353. BitField<39, 1, u64> emit; // EmitVertex
  1354. BitField<40, 1, u64> cut; // EndPrimitive
  1355. } out;
  1356. union {
  1357. BitField<31, 1, u64> skew;
  1358. BitField<32, 1, u64> o;
  1359. BitField<33, 2, IsberdMode> mode;
  1360. BitField<47, 2, IsberdShift> shift;
  1361. } isberd;
  1362. union {
  1363. BitField<8, 2, MembarType> type;
  1364. BitField<0, 2, MembarUnknown> unknown;
  1365. } membar;
  1366. union {
  1367. BitField<48, 1, u64> signed_a;
  1368. BitField<38, 1, u64> is_byte_chunk_a;
  1369. BitField<36, 2, VideoType> type_a;
  1370. BitField<36, 2, u64> byte_height_a;
  1371. BitField<49, 1, u64> signed_b;
  1372. BitField<50, 1, u64> use_register_b;
  1373. BitField<30, 1, u64> is_byte_chunk_b;
  1374. BitField<28, 2, VideoType> type_b;
  1375. BitField<28, 2, u64> byte_height_b;
  1376. } video;
  1377. union {
  1378. BitField<51, 2, VmadShr> shr;
  1379. BitField<55, 1, u64> saturate; // Saturates the result (a * b + c)
  1380. BitField<47, 1, u64> cc;
  1381. } vmad;
  1382. union {
  1383. BitField<20, 16, u64> imm20_16;
  1384. BitField<35, 1, u64> high_b_rr; // used on RR
  1385. BitField<36, 1, u64> product_shift_left;
  1386. BitField<37, 1, u64> merge_37;
  1387. BitField<48, 1, u64> sign_a;
  1388. BitField<49, 1, u64> sign_b;
  1389. BitField<50, 2, XmadMode> mode_cbf; // used by CR, RC
  1390. BitField<50, 3, XmadMode> mode;
  1391. BitField<52, 1, u64> high_b;
  1392. BitField<53, 1, u64> high_a;
  1393. BitField<55, 1, u64> product_shift_left_second; // used on CR
  1394. BitField<56, 1, u64> merge_56;
  1395. } xmad;
  1396. union {
  1397. BitField<20, 14, u64> offset;
  1398. BitField<34, 5, u64> index;
  1399. u64 GetOffset() const {
  1400. return offset * 4;
  1401. }
  1402. } cbuf34;
  1403. union {
  1404. BitField<20, 16, s64> offset;
  1405. BitField<36, 5, u64> index;
  1406. s64 GetOffset() const {
  1407. return offset;
  1408. }
  1409. } cbuf36;
  1410. // Unsure about the size of this one.
  1411. // It's always used with a gpr0, so any size should be fine.
  1412. BitField<20, 8, SystemVariable> sys20;
  1413. BitField<47, 1, u64> generates_cc;
  1414. BitField<61, 1, u64> is_b_imm;
  1415. BitField<60, 1, u64> is_b_gpr;
  1416. BitField<59, 1, u64> is_c_gpr;
  1417. BitField<20, 24, s64> smem_imm;
  1418. BitField<0, 5, ConditionCode> flow_condition_code;
  1419. Attribute attribute;
  1420. Sampler sampler;
  1421. Image image;
  1422. u64 value;
  1423. };
  1424. static_assert(sizeof(Instruction) == 0x8, "Incorrect structure size");
  1425. static_assert(std::is_standard_layout_v<Instruction>, "Instruction is not standard layout");
  1426. class OpCode {
  1427. public:
  1428. enum class Id {
  1429. KIL,
  1430. SSY,
  1431. SYNC,
  1432. BRK,
  1433. DEPBAR,
  1434. VOTE,
  1435. SHFL,
  1436. FSWZADD,
  1437. BFE_C,
  1438. BFE_R,
  1439. BFE_IMM,
  1440. BFI_IMM_R,
  1441. BRA,
  1442. BRX,
  1443. PBK,
  1444. LD_A,
  1445. LD_L,
  1446. LD_S,
  1447. LD_C,
  1448. LD, // Load from generic memory
  1449. LDG, // Load from global memory
  1450. ST_A,
  1451. ST_L,
  1452. ST_S,
  1453. ST, // Store in generic memory
  1454. STG, // Store in global memory
  1455. ATOMS, // Atomic operation on shared memory
  1456. AL2P, // Transforms attribute memory into physical memory
  1457. TEX,
  1458. TEX_B, // Texture Load Bindless
  1459. TXQ, // Texture Query
  1460. TXQ_B, // Texture Query Bindless
  1461. TEXS, // Texture Fetch with scalar/non-vec4 source/destinations
  1462. TLD, // Texture Load
  1463. TLDS, // Texture Load with scalar/non-vec4 source/destinations
  1464. TLD4, // Texture Gather 4
  1465. TLD4_B, // Texture Gather 4 Bindless
  1466. TLD4S, // Texture Load 4 with scalar / non - vec4 source / destinations
  1467. TMML_B, // Texture Mip Map Level
  1468. TMML, // Texture Mip Map Level
  1469. TXD, // Texture Gradient/Load with Derivates
  1470. TXD_B, // Texture Gradient/Load with Derivates Bindless
  1471. SUST, // Surface Store
  1472. SULD, // Surface Load
  1473. SUATOM, // Surface Atomic Operation
  1474. EXIT,
  1475. NOP,
  1476. IPA,
  1477. OUT_R, // Emit vertex/primitive
  1478. ISBERD,
  1479. MEMBAR,
  1480. VMAD,
  1481. VSETP,
  1482. FFMA_IMM, // Fused Multiply and Add
  1483. FFMA_CR,
  1484. FFMA_RC,
  1485. FFMA_RR,
  1486. FADD_C,
  1487. FADD_R,
  1488. FADD_IMM,
  1489. FADD32I,
  1490. FMUL_C,
  1491. FMUL_R,
  1492. FMUL_IMM,
  1493. FMUL32_IMM,
  1494. IADD_C,
  1495. IADD_R,
  1496. IADD_IMM,
  1497. IADD3_C, // Add 3 Integers
  1498. IADD3_R,
  1499. IADD3_IMM,
  1500. IADD32I,
  1501. ISCADD_C, // Scale and Add
  1502. ISCADD_R,
  1503. ISCADD_IMM,
  1504. FLO_R,
  1505. FLO_C,
  1506. FLO_IMM,
  1507. LEA_R1,
  1508. LEA_R2,
  1509. LEA_RZ,
  1510. LEA_IMM,
  1511. LEA_HI,
  1512. HADD2_C,
  1513. HADD2_R,
  1514. HADD2_IMM,
  1515. HMUL2_C,
  1516. HMUL2_R,
  1517. HMUL2_IMM,
  1518. HFMA2_CR,
  1519. HFMA2_RC,
  1520. HFMA2_RR,
  1521. HFMA2_IMM_R,
  1522. HSETP2_C,
  1523. HSETP2_R,
  1524. HSETP2_IMM,
  1525. HSET2_R,
  1526. POPC_C,
  1527. POPC_R,
  1528. POPC_IMM,
  1529. SEL_C,
  1530. SEL_R,
  1531. SEL_IMM,
  1532. ICMP_RC,
  1533. ICMP_R,
  1534. ICMP_CR,
  1535. ICMP_IMM,
  1536. MUFU, // Multi-Function Operator
  1537. RRO_C, // Range Reduction Operator
  1538. RRO_R,
  1539. RRO_IMM,
  1540. F2F_C,
  1541. F2F_R,
  1542. F2F_IMM,
  1543. F2I_C,
  1544. F2I_R,
  1545. F2I_IMM,
  1546. I2F_C,
  1547. I2F_R,
  1548. I2F_IMM,
  1549. I2I_C,
  1550. I2I_R,
  1551. I2I_IMM,
  1552. LOP_C,
  1553. LOP_R,
  1554. LOP_IMM,
  1555. LOP32I,
  1556. LOP3_C,
  1557. LOP3_R,
  1558. LOP3_IMM,
  1559. MOV_C,
  1560. MOV_R,
  1561. MOV_IMM,
  1562. MOV_SYS,
  1563. MOV32_IMM,
  1564. SHL_C,
  1565. SHL_R,
  1566. SHL_IMM,
  1567. SHR_C,
  1568. SHR_R,
  1569. SHR_IMM,
  1570. SHF_RIGHT_R,
  1571. SHF_RIGHT_IMM,
  1572. SHF_LEFT_R,
  1573. SHF_LEFT_IMM,
  1574. FMNMX_C,
  1575. FMNMX_R,
  1576. FMNMX_IMM,
  1577. IMNMX_C,
  1578. IMNMX_R,
  1579. IMNMX_IMM,
  1580. FSETP_C, // Set Predicate
  1581. FSETP_R,
  1582. FSETP_IMM,
  1583. FSET_C,
  1584. FSET_R,
  1585. FSET_IMM,
  1586. ISETP_C,
  1587. ISETP_IMM,
  1588. ISETP_R,
  1589. ISET_R,
  1590. ISET_C,
  1591. ISET_IMM,
  1592. PSETP,
  1593. PSET,
  1594. CSETP,
  1595. R2P_IMM,
  1596. P2R_IMM,
  1597. XMAD_IMM,
  1598. XMAD_CR,
  1599. XMAD_RC,
  1600. XMAD_RR,
  1601. };
  1602. enum class Type {
  1603. Trivial,
  1604. Arithmetic,
  1605. ArithmeticImmediate,
  1606. ArithmeticInteger,
  1607. ArithmeticIntegerImmediate,
  1608. ArithmeticHalf,
  1609. ArithmeticHalfImmediate,
  1610. Bfe,
  1611. Bfi,
  1612. Shift,
  1613. Ffma,
  1614. Hfma2,
  1615. Flow,
  1616. Synch,
  1617. Warp,
  1618. Memory,
  1619. Texture,
  1620. Image,
  1621. FloatSet,
  1622. FloatSetPredicate,
  1623. IntegerSet,
  1624. IntegerSetPredicate,
  1625. HalfSet,
  1626. HalfSetPredicate,
  1627. PredicateSetPredicate,
  1628. PredicateSetRegister,
  1629. RegisterSetPredicate,
  1630. Conversion,
  1631. Video,
  1632. Xmad,
  1633. Unknown,
  1634. };
  1635. /// Returns whether an opcode has an execution predicate field or not (ie, whether it can be
  1636. /// conditionally executed).
  1637. static bool IsPredicatedInstruction(Id opcode) {
  1638. // TODO(Subv): Add the rest of unpredicated instructions.
  1639. return opcode != Id::SSY && opcode != Id::PBK;
  1640. }
  1641. class Matcher {
  1642. public:
  1643. constexpr Matcher(const char* const name, u16 mask, u16 expected, Id id, Type type)
  1644. : name{name}, mask{mask}, expected{expected}, id{id}, type{type} {}
  1645. constexpr const char* GetName() const {
  1646. return name;
  1647. }
  1648. constexpr u16 GetMask() const {
  1649. return mask;
  1650. }
  1651. constexpr Id GetId() const {
  1652. return id;
  1653. }
  1654. constexpr Type GetType() const {
  1655. return type;
  1656. }
  1657. /**
  1658. * Tests to see if the given instruction is the instruction this matcher represents.
  1659. * @param instruction The instruction to test
  1660. * @returns true if the given instruction matches.
  1661. */
  1662. constexpr bool Matches(u16 instruction) const {
  1663. return (instruction & mask) == expected;
  1664. }
  1665. private:
  1666. const char* name;
  1667. u16 mask;
  1668. u16 expected;
  1669. Id id;
  1670. Type type;
  1671. };
  1672. static std::optional<std::reference_wrapper<const Matcher>> Decode(Instruction instr) {
  1673. static const auto table{GetDecodeTable()};
  1674. const auto matches_instruction = [instr](const auto& matcher) {
  1675. return matcher.Matches(static_cast<u16>(instr.opcode));
  1676. };
  1677. auto iter = std::find_if(table.begin(), table.end(), matches_instruction);
  1678. return iter != table.end() ? std::optional<std::reference_wrapper<const Matcher>>(*iter)
  1679. : std::nullopt;
  1680. }
  1681. private:
  1682. struct Detail {
  1683. private:
  1684. static constexpr std::size_t opcode_bitsize = 16;
  1685. /**
  1686. * Generates the mask and the expected value after masking from a given bitstring.
  1687. * A '0' in a bitstring indicates that a zero must be present at that bit position.
  1688. * A '1' in a bitstring indicates that a one must be present at that bit position.
  1689. */
  1690. static constexpr auto GetMaskAndExpect(const char* const bitstring) {
  1691. u16 mask = 0, expect = 0;
  1692. for (std::size_t i = 0; i < opcode_bitsize; i++) {
  1693. const std::size_t bit_position = opcode_bitsize - i - 1;
  1694. switch (bitstring[i]) {
  1695. case '0':
  1696. mask |= static_cast<u16>(1U << bit_position);
  1697. break;
  1698. case '1':
  1699. expect |= static_cast<u16>(1U << bit_position);
  1700. mask |= static_cast<u16>(1U << bit_position);
  1701. break;
  1702. default:
  1703. // Ignore
  1704. break;
  1705. }
  1706. }
  1707. return std::make_pair(mask, expect);
  1708. }
  1709. public:
  1710. /// Creates a matcher that can match and parse instructions based on bitstring.
  1711. static constexpr auto GetMatcher(const char* const bitstring, Id op, Type type,
  1712. const char* const name) {
  1713. const auto [mask, expected] = GetMaskAndExpect(bitstring);
  1714. return Matcher(name, mask, expected, op, type);
  1715. }
  1716. };
  1717. static std::vector<Matcher> GetDecodeTable() {
  1718. std::vector<Matcher> table = {
  1719. #define INST(bitstring, op, type, name) Detail::GetMatcher(bitstring, op, type, name)
  1720. INST("111000110011----", Id::KIL, Type::Flow, "KIL"),
  1721. INST("111000101001----", Id::SSY, Type::Flow, "SSY"),
  1722. INST("111000101010----", Id::PBK, Type::Flow, "PBK"),
  1723. INST("111000100100----", Id::BRA, Type::Flow, "BRA"),
  1724. INST("111000100101----", Id::BRX, Type::Flow, "BRX"),
  1725. INST("1111000011111---", Id::SYNC, Type::Flow, "SYNC"),
  1726. INST("111000110100----", Id::BRK, Type::Flow, "BRK"),
  1727. INST("111000110000----", Id::EXIT, Type::Flow, "EXIT"),
  1728. INST("1111000011110---", Id::DEPBAR, Type::Synch, "DEPBAR"),
  1729. INST("0101000011011---", Id::VOTE, Type::Warp, "VOTE"),
  1730. INST("1110111100010---", Id::SHFL, Type::Warp, "SHFL"),
  1731. INST("0101000011111---", Id::FSWZADD, Type::Warp, "FSWZADD"),
  1732. INST("1110111111011---", Id::LD_A, Type::Memory, "LD_A"),
  1733. INST("1110111101001---", Id::LD_S, Type::Memory, "LD_S"),
  1734. INST("1110111101000---", Id::LD_L, Type::Memory, "LD_L"),
  1735. INST("1110111110010---", Id::LD_C, Type::Memory, "LD_C"),
  1736. INST("100-------------", Id::LD, Type::Memory, "LD"),
  1737. INST("1110111011010---", Id::LDG, Type::Memory, "LDG"),
  1738. INST("1110111111110---", Id::ST_A, Type::Memory, "ST_A"),
  1739. INST("1110111101011---", Id::ST_S, Type::Memory, "ST_S"),
  1740. INST("1110111101010---", Id::ST_L, Type::Memory, "ST_L"),
  1741. INST("101-------------", Id::ST, Type::Memory, "ST"),
  1742. INST("1110111011011---", Id::STG, Type::Memory, "STG"),
  1743. INST("11101100--------", Id::ATOMS, Type::Memory, "ATOMS"),
  1744. INST("1110111110100---", Id::AL2P, Type::Memory, "AL2P"),
  1745. INST("110000----111---", Id::TEX, Type::Texture, "TEX"),
  1746. INST("1101111010111---", Id::TEX_B, Type::Texture, "TEX_B"),
  1747. INST("1101111101001---", Id::TXQ, Type::Texture, "TXQ"),
  1748. INST("1101111101010---", Id::TXQ_B, Type::Texture, "TXQ_B"),
  1749. INST("1101-00---------", Id::TEXS, Type::Texture, "TEXS"),
  1750. INST("11011100--11----", Id::TLD, Type::Texture, "TLD"),
  1751. INST("1101-01---------", Id::TLDS, Type::Texture, "TLDS"),
  1752. INST("110010----111---", Id::TLD4, Type::Texture, "TLD4"),
  1753. INST("1101111011111---", Id::TLD4_B, Type::Texture, "TLD4_B"),
  1754. INST("11011111-0------", Id::TLD4S, Type::Texture, "TLD4S"),
  1755. INST("110111110110----", Id::TMML_B, Type::Texture, "TMML_B"),
  1756. INST("1101111101011---", Id::TMML, Type::Texture, "TMML"),
  1757. INST("11011110011110--", Id::TXD_B, Type::Texture, "TXD_B"),
  1758. INST("11011110001110--", Id::TXD, Type::Texture, "TXD"),
  1759. INST("11101011001-----", Id::SUST, Type::Image, "SUST"),
  1760. INST("11101011000-----", Id::SULD, Type::Image, "SULD"),
  1761. INST("1110101000------", Id::SUATOM, Type::Image, "SUATOM_D"),
  1762. INST("0101000010110---", Id::NOP, Type::Trivial, "NOP"),
  1763. INST("11100000--------", Id::IPA, Type::Trivial, "IPA"),
  1764. INST("1111101111100---", Id::OUT_R, Type::Trivial, "OUT_R"),
  1765. INST("1110111111010---", Id::ISBERD, Type::Trivial, "ISBERD"),
  1766. INST("1110111110011---", Id::MEMBAR, Type::Trivial, "MEMBAR"),
  1767. INST("01011111--------", Id::VMAD, Type::Video, "VMAD"),
  1768. INST("0101000011110---", Id::VSETP, Type::Video, "VSETP"),
  1769. INST("0011001-1-------", Id::FFMA_IMM, Type::Ffma, "FFMA_IMM"),
  1770. INST("010010011-------", Id::FFMA_CR, Type::Ffma, "FFMA_CR"),
  1771. INST("010100011-------", Id::FFMA_RC, Type::Ffma, "FFMA_RC"),
  1772. INST("010110011-------", Id::FFMA_RR, Type::Ffma, "FFMA_RR"),
  1773. INST("0100110001011---", Id::FADD_C, Type::Arithmetic, "FADD_C"),
  1774. INST("0101110001011---", Id::FADD_R, Type::Arithmetic, "FADD_R"),
  1775. INST("0011100-01011---", Id::FADD_IMM, Type::Arithmetic, "FADD_IMM"),
  1776. INST("000010----------", Id::FADD32I, Type::ArithmeticImmediate, "FADD32I"),
  1777. INST("0100110001101---", Id::FMUL_C, Type::Arithmetic, "FMUL_C"),
  1778. INST("0101110001101---", Id::FMUL_R, Type::Arithmetic, "FMUL_R"),
  1779. INST("0011100-01101---", Id::FMUL_IMM, Type::Arithmetic, "FMUL_IMM"),
  1780. INST("00011110--------", Id::FMUL32_IMM, Type::ArithmeticImmediate, "FMUL32_IMM"),
  1781. INST("0100110000010---", Id::IADD_C, Type::ArithmeticInteger, "IADD_C"),
  1782. INST("0101110000010---", Id::IADD_R, Type::ArithmeticInteger, "IADD_R"),
  1783. INST("0011100-00010---", Id::IADD_IMM, Type::ArithmeticInteger, "IADD_IMM"),
  1784. INST("010011001100----", Id::IADD3_C, Type::ArithmeticInteger, "IADD3_C"),
  1785. INST("010111001100----", Id::IADD3_R, Type::ArithmeticInteger, "IADD3_R"),
  1786. INST("0011100-1100----", Id::IADD3_IMM, Type::ArithmeticInteger, "IADD3_IMM"),
  1787. INST("0001110---------", Id::IADD32I, Type::ArithmeticIntegerImmediate, "IADD32I"),
  1788. INST("0100110000011---", Id::ISCADD_C, Type::ArithmeticInteger, "ISCADD_C"),
  1789. INST("0101110000011---", Id::ISCADD_R, Type::ArithmeticInteger, "ISCADD_R"),
  1790. INST("0011100-00011---", Id::ISCADD_IMM, Type::ArithmeticInteger, "ISCADD_IMM"),
  1791. INST("0100110000001---", Id::POPC_C, Type::ArithmeticInteger, "POPC_C"),
  1792. INST("0101110000001---", Id::POPC_R, Type::ArithmeticInteger, "POPC_R"),
  1793. INST("0011100-00001---", Id::POPC_IMM, Type::ArithmeticInteger, "POPC_IMM"),
  1794. INST("0100110010100---", Id::SEL_C, Type::ArithmeticInteger, "SEL_C"),
  1795. INST("0101110010100---", Id::SEL_R, Type::ArithmeticInteger, "SEL_R"),
  1796. INST("0011100-10100---", Id::SEL_IMM, Type::ArithmeticInteger, "SEL_IMM"),
  1797. INST("010100110100----", Id::ICMP_RC, Type::ArithmeticInteger, "ICMP_RC"),
  1798. INST("010110110100----", Id::ICMP_R, Type::ArithmeticInteger, "ICMP_R"),
  1799. INST("010010110100----", Id::ICMP_CR, Type::ArithmeticInteger, "ICMP_CR"),
  1800. INST("0011011-0100----", Id::ICMP_IMM, Type::ArithmeticInteger, "ICMP_IMM"),
  1801. INST("0101110000110---", Id::FLO_R, Type::ArithmeticInteger, "FLO_R"),
  1802. INST("0100110000110---", Id::FLO_C, Type::ArithmeticInteger, "FLO_C"),
  1803. INST("0011100-00110---", Id::FLO_IMM, Type::ArithmeticInteger, "FLO_IMM"),
  1804. INST("0101101111011---", Id::LEA_R2, Type::ArithmeticInteger, "LEA_R2"),
  1805. INST("0101101111010---", Id::LEA_R1, Type::ArithmeticInteger, "LEA_R1"),
  1806. INST("001101101101----", Id::LEA_IMM, Type::ArithmeticInteger, "LEA_IMM"),
  1807. INST("010010111101----", Id::LEA_RZ, Type::ArithmeticInteger, "LEA_RZ"),
  1808. INST("00011000--------", Id::LEA_HI, Type::ArithmeticInteger, "LEA_HI"),
  1809. INST("0111101-1-------", Id::HADD2_C, Type::ArithmeticHalf, "HADD2_C"),
  1810. INST("0101110100010---", Id::HADD2_R, Type::ArithmeticHalf, "HADD2_R"),
  1811. INST("0111101-0-------", Id::HADD2_IMM, Type::ArithmeticHalfImmediate, "HADD2_IMM"),
  1812. INST("0111100-1-------", Id::HMUL2_C, Type::ArithmeticHalf, "HMUL2_C"),
  1813. INST("0101110100001---", Id::HMUL2_R, Type::ArithmeticHalf, "HMUL2_R"),
  1814. INST("0111100-0-------", Id::HMUL2_IMM, Type::ArithmeticHalfImmediate, "HMUL2_IMM"),
  1815. INST("01110---1-------", Id::HFMA2_CR, Type::Hfma2, "HFMA2_CR"),
  1816. INST("01100---1-------", Id::HFMA2_RC, Type::Hfma2, "HFMA2_RC"),
  1817. INST("0101110100000---", Id::HFMA2_RR, Type::Hfma2, "HFMA2_RR"),
  1818. INST("01110---0-------", Id::HFMA2_IMM_R, Type::Hfma2, "HFMA2_R_IMM"),
  1819. INST("0111111-1-------", Id::HSETP2_C, Type::HalfSetPredicate, "HSETP2_C"),
  1820. INST("0101110100100---", Id::HSETP2_R, Type::HalfSetPredicate, "HSETP2_R"),
  1821. INST("0111111-0-------", Id::HSETP2_IMM, Type::HalfSetPredicate, "HSETP2_IMM"),
  1822. INST("0101110100011---", Id::HSET2_R, Type::HalfSet, "HSET2_R"),
  1823. INST("0101000010000---", Id::MUFU, Type::Arithmetic, "MUFU"),
  1824. INST("0100110010010---", Id::RRO_C, Type::Arithmetic, "RRO_C"),
  1825. INST("0101110010010---", Id::RRO_R, Type::Arithmetic, "RRO_R"),
  1826. INST("0011100-10010---", Id::RRO_IMM, Type::Arithmetic, "RRO_IMM"),
  1827. INST("0100110010101---", Id::F2F_C, Type::Conversion, "F2F_C"),
  1828. INST("0101110010101---", Id::F2F_R, Type::Conversion, "F2F_R"),
  1829. INST("0011100-10101---", Id::F2F_IMM, Type::Conversion, "F2F_IMM"),
  1830. INST("0100110010110---", Id::F2I_C, Type::Conversion, "F2I_C"),
  1831. INST("0101110010110---", Id::F2I_R, Type::Conversion, "F2I_R"),
  1832. INST("0011100-10110---", Id::F2I_IMM, Type::Conversion, "F2I_IMM"),
  1833. INST("0100110010011---", Id::MOV_C, Type::Arithmetic, "MOV_C"),
  1834. INST("0101110010011---", Id::MOV_R, Type::Arithmetic, "MOV_R"),
  1835. INST("0011100-10011---", Id::MOV_IMM, Type::Arithmetic, "MOV_IMM"),
  1836. INST("1111000011001---", Id::MOV_SYS, Type::Trivial, "MOV_SYS"),
  1837. INST("000000010000----", Id::MOV32_IMM, Type::ArithmeticImmediate, "MOV32_IMM"),
  1838. INST("0100110001100---", Id::FMNMX_C, Type::Arithmetic, "FMNMX_C"),
  1839. INST("0101110001100---", Id::FMNMX_R, Type::Arithmetic, "FMNMX_R"),
  1840. INST("0011100-01100---", Id::FMNMX_IMM, Type::Arithmetic, "FMNMX_IMM"),
  1841. INST("0100110000100---", Id::IMNMX_C, Type::ArithmeticInteger, "IMNMX_C"),
  1842. INST("0101110000100---", Id::IMNMX_R, Type::ArithmeticInteger, "IMNMX_R"),
  1843. INST("0011100-00100---", Id::IMNMX_IMM, Type::ArithmeticInteger, "IMNMX_IMM"),
  1844. INST("0100110000000---", Id::BFE_C, Type::Bfe, "BFE_C"),
  1845. INST("0101110000000---", Id::BFE_R, Type::Bfe, "BFE_R"),
  1846. INST("0011100-00000---", Id::BFE_IMM, Type::Bfe, "BFE_IMM"),
  1847. INST("0011011-11110---", Id::BFI_IMM_R, Type::Bfi, "BFI_IMM_R"),
  1848. INST("0100110001000---", Id::LOP_C, Type::ArithmeticInteger, "LOP_C"),
  1849. INST("0101110001000---", Id::LOP_R, Type::ArithmeticInteger, "LOP_R"),
  1850. INST("0011100-01000---", Id::LOP_IMM, Type::ArithmeticInteger, "LOP_IMM"),
  1851. INST("000001----------", Id::LOP32I, Type::ArithmeticIntegerImmediate, "LOP32I"),
  1852. INST("0000001---------", Id::LOP3_C, Type::ArithmeticInteger, "LOP3_C"),
  1853. INST("0101101111100---", Id::LOP3_R, Type::ArithmeticInteger, "LOP3_R"),
  1854. INST("0011110---------", Id::LOP3_IMM, Type::ArithmeticInteger, "LOP3_IMM"),
  1855. INST("0100110001001---", Id::SHL_C, Type::Shift, "SHL_C"),
  1856. INST("0101110001001---", Id::SHL_R, Type::Shift, "SHL_R"),
  1857. INST("0011100-01001---", Id::SHL_IMM, Type::Shift, "SHL_IMM"),
  1858. INST("0100110000101---", Id::SHR_C, Type::Shift, "SHR_C"),
  1859. INST("0101110000101---", Id::SHR_R, Type::Shift, "SHR_R"),
  1860. INST("0011100-00101---", Id::SHR_IMM, Type::Shift, "SHR_IMM"),
  1861. INST("0101110011111---", Id::SHF_RIGHT_R, Type::Shift, "SHF_RIGHT_R"),
  1862. INST("0011100-11111---", Id::SHF_RIGHT_IMM, Type::Shift, "SHF_RIGHT_IMM"),
  1863. INST("0101101111111---", Id::SHF_LEFT_R, Type::Shift, "SHF_LEFT_R"),
  1864. INST("0011011-11111---", Id::SHF_LEFT_IMM, Type::Shift, "SHF_LEFT_IMM"),
  1865. INST("0100110011100---", Id::I2I_C, Type::Conversion, "I2I_C"),
  1866. INST("0101110011100---", Id::I2I_R, Type::Conversion, "I2I_R"),
  1867. INST("0011101-11100---", Id::I2I_IMM, Type::Conversion, "I2I_IMM"),
  1868. INST("0100110010111---", Id::I2F_C, Type::Conversion, "I2F_C"),
  1869. INST("0101110010111---", Id::I2F_R, Type::Conversion, "I2F_R"),
  1870. INST("0011100-10111---", Id::I2F_IMM, Type::Conversion, "I2F_IMM"),
  1871. INST("01011000--------", Id::FSET_R, Type::FloatSet, "FSET_R"),
  1872. INST("0100100---------", Id::FSET_C, Type::FloatSet, "FSET_C"),
  1873. INST("0011000---------", Id::FSET_IMM, Type::FloatSet, "FSET_IMM"),
  1874. INST("010010111011----", Id::FSETP_C, Type::FloatSetPredicate, "FSETP_C"),
  1875. INST("010110111011----", Id::FSETP_R, Type::FloatSetPredicate, "FSETP_R"),
  1876. INST("0011011-1011----", Id::FSETP_IMM, Type::FloatSetPredicate, "FSETP_IMM"),
  1877. INST("010010110110----", Id::ISETP_C, Type::IntegerSetPredicate, "ISETP_C"),
  1878. INST("010110110110----", Id::ISETP_R, Type::IntegerSetPredicate, "ISETP_R"),
  1879. INST("0011011-0110----", Id::ISETP_IMM, Type::IntegerSetPredicate, "ISETP_IMM"),
  1880. INST("010110110101----", Id::ISET_R, Type::IntegerSet, "ISET_R"),
  1881. INST("010010110101----", Id::ISET_C, Type::IntegerSet, "ISET_C"),
  1882. INST("0011011-0101----", Id::ISET_IMM, Type::IntegerSet, "ISET_IMM"),
  1883. INST("0101000010001---", Id::PSET, Type::PredicateSetRegister, "PSET"),
  1884. INST("0101000010010---", Id::PSETP, Type::PredicateSetPredicate, "PSETP"),
  1885. INST("010100001010----", Id::CSETP, Type::PredicateSetPredicate, "CSETP"),
  1886. INST("0011100-11110---", Id::R2P_IMM, Type::RegisterSetPredicate, "R2P_IMM"),
  1887. INST("0011100-11101---", Id::P2R_IMM, Type::RegisterSetPredicate, "P2R_IMM"),
  1888. INST("0011011-00------", Id::XMAD_IMM, Type::Xmad, "XMAD_IMM"),
  1889. INST("0100111---------", Id::XMAD_CR, Type::Xmad, "XMAD_CR"),
  1890. INST("010100010-------", Id::XMAD_RC, Type::Xmad, "XMAD_RC"),
  1891. INST("0101101100------", Id::XMAD_RR, Type::Xmad, "XMAD_RR"),
  1892. };
  1893. #undef INST
  1894. std::stable_sort(table.begin(), table.end(), [](const auto& a, const auto& b) {
  1895. // If a matcher has more bits in its mask it is more specific, so it
  1896. // should come first.
  1897. return std::bitset<16>(a.GetMask()).count() > std::bitset<16>(b.GetMask()).count();
  1898. });
  1899. return table;
  1900. }
  1901. };
  1902. } // namespace Tegra::Shader