maxwell_3d.h 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512
  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 <type_traits>
  9. #include <unordered_map>
  10. #include <vector>
  11. #include "common/assert.h"
  12. #include "common/bit_field.h"
  13. #include "common/common_funcs.h"
  14. #include "common/common_types.h"
  15. #include "common/math_util.h"
  16. #include "video_core/engines/const_buffer_engine_interface.h"
  17. #include "video_core/engines/const_buffer_info.h"
  18. #include "video_core/engines/engine_upload.h"
  19. #include "video_core/engines/shader_type.h"
  20. #include "video_core/gpu.h"
  21. #include "video_core/macro_interpreter.h"
  22. #include "video_core/textures/texture.h"
  23. namespace Core {
  24. class System;
  25. }
  26. namespace Tegra {
  27. class MemoryManager;
  28. }
  29. namespace VideoCore {
  30. class RasterizerInterface;
  31. }
  32. namespace Tegra::Engines {
  33. /**
  34. * This Engine is known as GF100_3D. Documentation can be found in:
  35. * https://github.com/envytools/envytools/blob/master/rnndb/graph/gf100_3d.xml
  36. * https://cgit.freedesktop.org/mesa/mesa/tree/src/gallium/drivers/nouveau/nvc0/nvc0_3d.xml.h
  37. */
  38. #define MAXWELL3D_REG_INDEX(field_name) \
  39. (offsetof(Tegra::Engines::Maxwell3D::Regs, field_name) / sizeof(u32))
  40. class Maxwell3D final : public ConstBufferEngineInterface {
  41. public:
  42. explicit Maxwell3D(Core::System& system, VideoCore::RasterizerInterface& rasterizer,
  43. MemoryManager& memory_manager);
  44. ~Maxwell3D() = default;
  45. /// Register structure of the Maxwell3D engine.
  46. /// TODO(Subv): This structure will need to be made bigger as more registers are discovered.
  47. struct Regs {
  48. static constexpr std::size_t NUM_REGS = 0xE00;
  49. static constexpr std::size_t NumRenderTargets = 8;
  50. static constexpr std::size_t NumViewports = 16;
  51. static constexpr std::size_t NumCBData = 16;
  52. static constexpr std::size_t NumVertexArrays = 32;
  53. static constexpr std::size_t NumVertexAttributes = 32;
  54. static constexpr std::size_t NumVaryings = 31;
  55. static constexpr std::size_t NumImages = 8; // TODO(Rodrigo): Investigate this number
  56. static constexpr std::size_t NumClipDistances = 8;
  57. static constexpr std::size_t MaxShaderProgram = 6;
  58. static constexpr std::size_t MaxShaderStage = 5;
  59. // Maximum number of const buffers per shader stage.
  60. static constexpr std::size_t MaxConstBuffers = 18;
  61. static constexpr std::size_t MaxConstBufferSize = 0x10000;
  62. enum class QueryOperation : u32 {
  63. Release = 0,
  64. Acquire = 1,
  65. Counter = 2,
  66. Trap = 3,
  67. };
  68. enum class QueryUnit : u32 {
  69. VFetch = 1,
  70. VP = 2,
  71. Rast = 4,
  72. StrmOut = 5,
  73. GP = 6,
  74. ZCull = 7,
  75. Prop = 10,
  76. Crop = 15,
  77. };
  78. enum class QuerySelect : u32 {
  79. Zero = 0,
  80. TimeElapsed = 2,
  81. TransformFeedbackPrimitivesGenerated = 11,
  82. PrimitivesGenerated = 18,
  83. SamplesPassed = 21,
  84. TransformFeedbackUnknown = 26,
  85. };
  86. struct QueryCompare {
  87. u32 initial_sequence;
  88. u32 initial_mode;
  89. u32 unknown1;
  90. u32 unknown2;
  91. u32 current_sequence;
  92. u32 current_mode;
  93. };
  94. enum class QuerySyncCondition : u32 {
  95. NotEqual = 0,
  96. GreaterThan = 1,
  97. };
  98. enum class ConditionMode : u32 {
  99. Never = 0,
  100. Always = 1,
  101. ResNonZero = 2,
  102. Equal = 3,
  103. NotEqual = 4,
  104. };
  105. enum class ShaderProgram : u32 {
  106. VertexA = 0,
  107. VertexB = 1,
  108. TesselationControl = 2,
  109. TesselationEval = 3,
  110. Geometry = 4,
  111. Fragment = 5,
  112. };
  113. struct VertexAttribute {
  114. enum class Size : u32 {
  115. Invalid = 0x0,
  116. Size_32_32_32_32 = 0x01,
  117. Size_32_32_32 = 0x02,
  118. Size_16_16_16_16 = 0x03,
  119. Size_32_32 = 0x04,
  120. Size_16_16_16 = 0x05,
  121. Size_8_8_8_8 = 0x0a,
  122. Size_16_16 = 0x0f,
  123. Size_32 = 0x12,
  124. Size_8_8_8 = 0x13,
  125. Size_8_8 = 0x18,
  126. Size_16 = 0x1b,
  127. Size_8 = 0x1d,
  128. Size_10_10_10_2 = 0x30,
  129. Size_11_11_10 = 0x31,
  130. };
  131. enum class Type : u32 {
  132. SignedNorm = 1,
  133. UnsignedNorm = 2,
  134. SignedInt = 3,
  135. UnsignedInt = 4,
  136. UnsignedScaled = 5,
  137. SignedScaled = 6,
  138. Float = 7,
  139. };
  140. union {
  141. BitField<0, 5, u32> buffer;
  142. BitField<6, 1, u32> constant;
  143. BitField<7, 14, u32> offset;
  144. BitField<21, 6, Size> size;
  145. BitField<27, 3, Type> type;
  146. BitField<31, 1, u32> bgra;
  147. u32 hex;
  148. };
  149. u32 ComponentCount() const {
  150. switch (size) {
  151. case Size::Size_32_32_32_32:
  152. return 4;
  153. case Size::Size_32_32_32:
  154. return 3;
  155. case Size::Size_16_16_16_16:
  156. return 4;
  157. case Size::Size_32_32:
  158. return 2;
  159. case Size::Size_16_16_16:
  160. return 3;
  161. case Size::Size_8_8_8_8:
  162. return 4;
  163. case Size::Size_16_16:
  164. return 2;
  165. case Size::Size_32:
  166. return 1;
  167. case Size::Size_8_8_8:
  168. return 3;
  169. case Size::Size_8_8:
  170. return 2;
  171. case Size::Size_16:
  172. return 1;
  173. case Size::Size_8:
  174. return 1;
  175. case Size::Size_10_10_10_2:
  176. return 4;
  177. case Size::Size_11_11_10:
  178. return 3;
  179. default:
  180. UNREACHABLE();
  181. return 1;
  182. }
  183. }
  184. u32 SizeInBytes() const {
  185. switch (size) {
  186. case Size::Size_32_32_32_32:
  187. return 16;
  188. case Size::Size_32_32_32:
  189. return 12;
  190. case Size::Size_16_16_16_16:
  191. return 8;
  192. case Size::Size_32_32:
  193. return 8;
  194. case Size::Size_16_16_16:
  195. return 6;
  196. case Size::Size_8_8_8_8:
  197. return 4;
  198. case Size::Size_16_16:
  199. return 4;
  200. case Size::Size_32:
  201. return 4;
  202. case Size::Size_8_8_8:
  203. return 3;
  204. case Size::Size_8_8:
  205. return 2;
  206. case Size::Size_16:
  207. return 2;
  208. case Size::Size_8:
  209. return 1;
  210. case Size::Size_10_10_10_2:
  211. return 4;
  212. case Size::Size_11_11_10:
  213. return 4;
  214. default:
  215. UNREACHABLE();
  216. }
  217. }
  218. std::string SizeString() const {
  219. switch (size) {
  220. case Size::Size_32_32_32_32:
  221. return "32_32_32_32";
  222. case Size::Size_32_32_32:
  223. return "32_32_32";
  224. case Size::Size_16_16_16_16:
  225. return "16_16_16_16";
  226. case Size::Size_32_32:
  227. return "32_32";
  228. case Size::Size_16_16_16:
  229. return "16_16_16";
  230. case Size::Size_8_8_8_8:
  231. return "8_8_8_8";
  232. case Size::Size_16_16:
  233. return "16_16";
  234. case Size::Size_32:
  235. return "32";
  236. case Size::Size_8_8_8:
  237. return "8_8_8";
  238. case Size::Size_8_8:
  239. return "8_8";
  240. case Size::Size_16:
  241. return "16";
  242. case Size::Size_8:
  243. return "8";
  244. case Size::Size_10_10_10_2:
  245. return "10_10_10_2";
  246. case Size::Size_11_11_10:
  247. return "11_11_10";
  248. default:
  249. UNREACHABLE();
  250. return {};
  251. }
  252. }
  253. std::string TypeString() const {
  254. switch (type) {
  255. case Type::SignedNorm:
  256. return "SNORM";
  257. case Type::UnsignedNorm:
  258. return "UNORM";
  259. case Type::SignedInt:
  260. return "SINT";
  261. case Type::UnsignedInt:
  262. return "UINT";
  263. case Type::UnsignedScaled:
  264. return "USCALED";
  265. case Type::SignedScaled:
  266. return "SSCALED";
  267. case Type::Float:
  268. return "FLOAT";
  269. }
  270. UNREACHABLE();
  271. return {};
  272. }
  273. bool IsNormalized() const {
  274. return (type == Type::SignedNorm) || (type == Type::UnsignedNorm);
  275. }
  276. bool IsValid() const {
  277. return size != Size::Invalid;
  278. }
  279. bool operator<(const VertexAttribute& other) const {
  280. return hex < other.hex;
  281. }
  282. };
  283. enum class DepthMode : u32 {
  284. MinusOneToOne = 0,
  285. ZeroToOne = 1,
  286. };
  287. enum class PrimitiveTopology : u32 {
  288. Points = 0x0,
  289. Lines = 0x1,
  290. LineLoop = 0x2,
  291. LineStrip = 0x3,
  292. Triangles = 0x4,
  293. TriangleStrip = 0x5,
  294. TriangleFan = 0x6,
  295. Quads = 0x7,
  296. QuadStrip = 0x8,
  297. Polygon = 0x9,
  298. LinesAdjacency = 0xa,
  299. LineStripAdjacency = 0xb,
  300. TrianglesAdjacency = 0xc,
  301. TriangleStripAdjacency = 0xd,
  302. Patches = 0xe,
  303. };
  304. enum class IndexFormat : u32 {
  305. UnsignedByte = 0x0,
  306. UnsignedShort = 0x1,
  307. UnsignedInt = 0x2,
  308. };
  309. enum class ComparisonOp : u32 {
  310. // These values are used by Nouveau and most games, they correspond to the OpenGL token
  311. // values for these operations.
  312. Never = 0x200,
  313. Less = 0x201,
  314. Equal = 0x202,
  315. LessEqual = 0x203,
  316. Greater = 0x204,
  317. NotEqual = 0x205,
  318. GreaterEqual = 0x206,
  319. Always = 0x207,
  320. // These values are used by some games, they seem to be NV04 values.
  321. NeverOld = 1,
  322. LessOld = 2,
  323. EqualOld = 3,
  324. LessEqualOld = 4,
  325. GreaterOld = 5,
  326. NotEqualOld = 6,
  327. GreaterEqualOld = 7,
  328. AlwaysOld = 8,
  329. };
  330. enum class LogicOperation : u32 {
  331. Clear = 0x1500,
  332. And = 0x1501,
  333. AndReverse = 0x1502,
  334. Copy = 0x1503,
  335. AndInverted = 0x1504,
  336. NoOp = 0x1505,
  337. Xor = 0x1506,
  338. Or = 0x1507,
  339. Nor = 0x1508,
  340. Equiv = 0x1509,
  341. Invert = 0x150A,
  342. OrReverse = 0x150B,
  343. CopyInverted = 0x150C,
  344. OrInverted = 0x150D,
  345. Nand = 0x150E,
  346. Set = 0x150F,
  347. };
  348. enum class StencilOp : u32 {
  349. Keep = 1,
  350. Zero = 2,
  351. Replace = 3,
  352. Incr = 4,
  353. Decr = 5,
  354. Invert = 6,
  355. IncrWrap = 7,
  356. DecrWrap = 8,
  357. KeepOGL = 0x1E00,
  358. ZeroOGL = 0,
  359. ReplaceOGL = 0x1E01,
  360. IncrOGL = 0x1E02,
  361. DecrOGL = 0x1E03,
  362. InvertOGL = 0x150A,
  363. IncrWrapOGL = 0x8507,
  364. DecrWrapOGL = 0x8508,
  365. };
  366. enum class MemoryLayout : u32 {
  367. Linear = 0,
  368. BlockLinear = 1,
  369. };
  370. enum class InvMemoryLayout : u32 {
  371. BlockLinear = 0,
  372. Linear = 1,
  373. };
  374. enum class CounterReset : u32 {
  375. SampleCnt = 0x01,
  376. Unk02 = 0x02,
  377. Unk03 = 0x03,
  378. Unk04 = 0x04,
  379. EmittedPrimitives = 0x10, // Not tested
  380. Unk11 = 0x11,
  381. Unk12 = 0x12,
  382. Unk13 = 0x13,
  383. Unk15 = 0x15,
  384. Unk16 = 0x16,
  385. Unk17 = 0x17,
  386. Unk18 = 0x18,
  387. Unk1A = 0x1A,
  388. Unk1B = 0x1B,
  389. Unk1C = 0x1C,
  390. Unk1D = 0x1D,
  391. Unk1E = 0x1E,
  392. GeneratedPrimitives = 0x1F,
  393. };
  394. struct Cull {
  395. enum class FrontFace : u32 {
  396. ClockWise = 0x0900,
  397. CounterClockWise = 0x0901,
  398. };
  399. enum class CullFace : u32 {
  400. Front = 0x0404,
  401. Back = 0x0405,
  402. FrontAndBack = 0x0408,
  403. };
  404. u32 enabled;
  405. FrontFace front_face;
  406. CullFace cull_face;
  407. };
  408. struct Blend {
  409. enum class Equation : u32 {
  410. Add = 1,
  411. Subtract = 2,
  412. ReverseSubtract = 3,
  413. Min = 4,
  414. Max = 5,
  415. // These values are used by Nouveau and some games.
  416. AddGL = 0x8006,
  417. SubtractGL = 0x8007,
  418. ReverseSubtractGL = 0x8008,
  419. MinGL = 0x800a,
  420. MaxGL = 0x800b
  421. };
  422. enum class Factor : u32 {
  423. Zero = 0x1,
  424. One = 0x2,
  425. SourceColor = 0x3,
  426. OneMinusSourceColor = 0x4,
  427. SourceAlpha = 0x5,
  428. OneMinusSourceAlpha = 0x6,
  429. DestAlpha = 0x7,
  430. OneMinusDestAlpha = 0x8,
  431. DestColor = 0x9,
  432. OneMinusDestColor = 0xa,
  433. SourceAlphaSaturate = 0xb,
  434. Source1Color = 0x10,
  435. OneMinusSource1Color = 0x11,
  436. Source1Alpha = 0x12,
  437. OneMinusSource1Alpha = 0x13,
  438. ConstantColor = 0x61,
  439. OneMinusConstantColor = 0x62,
  440. ConstantAlpha = 0x63,
  441. OneMinusConstantAlpha = 0x64,
  442. // These values are used by Nouveau and some games.
  443. ZeroGL = 0x4000,
  444. OneGL = 0x4001,
  445. SourceColorGL = 0x4300,
  446. OneMinusSourceColorGL = 0x4301,
  447. SourceAlphaGL = 0x4302,
  448. OneMinusSourceAlphaGL = 0x4303,
  449. DestAlphaGL = 0x4304,
  450. OneMinusDestAlphaGL = 0x4305,
  451. DestColorGL = 0x4306,
  452. OneMinusDestColorGL = 0x4307,
  453. SourceAlphaSaturateGL = 0x4308,
  454. ConstantColorGL = 0xc001,
  455. OneMinusConstantColorGL = 0xc002,
  456. ConstantAlphaGL = 0xc003,
  457. OneMinusConstantAlphaGL = 0xc004,
  458. Source1ColorGL = 0xc900,
  459. OneMinusSource1ColorGL = 0xc901,
  460. Source1AlphaGL = 0xc902,
  461. OneMinusSource1AlphaGL = 0xc903,
  462. };
  463. u32 separate_alpha;
  464. Equation equation_rgb;
  465. Factor factor_source_rgb;
  466. Factor factor_dest_rgb;
  467. Equation equation_a;
  468. Factor factor_source_a;
  469. Factor factor_dest_a;
  470. INSERT_UNION_PADDING_WORDS(1);
  471. };
  472. enum class TessellationPrimitive : u32 {
  473. Isolines = 0,
  474. Triangles = 1,
  475. Quads = 2,
  476. };
  477. enum class TessellationSpacing : u32 {
  478. Equal = 0,
  479. FractionalOdd = 1,
  480. FractionalEven = 2,
  481. };
  482. struct RenderTargetConfig {
  483. u32 address_high;
  484. u32 address_low;
  485. u32 width;
  486. u32 height;
  487. Tegra::RenderTargetFormat format;
  488. union {
  489. BitField<0, 3, u32> block_width;
  490. BitField<4, 3, u32> block_height;
  491. BitField<8, 3, u32> block_depth;
  492. BitField<12, 1, InvMemoryLayout> type;
  493. } memory_layout;
  494. union {
  495. BitField<0, 16, u32> layers;
  496. BitField<16, 1, u32> volume;
  497. };
  498. u32 layer_stride;
  499. u32 base_layer;
  500. INSERT_UNION_PADDING_WORDS(7);
  501. GPUVAddr Address() const {
  502. return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) |
  503. address_low);
  504. }
  505. };
  506. struct ColorMask {
  507. union {
  508. u32 raw;
  509. BitField<0, 4, u32> R;
  510. BitField<4, 4, u32> G;
  511. BitField<8, 4, u32> B;
  512. BitField<12, 4, u32> A;
  513. };
  514. };
  515. struct ViewportTransform {
  516. f32 scale_x;
  517. f32 scale_y;
  518. f32 scale_z;
  519. f32 translate_x;
  520. f32 translate_y;
  521. f32 translate_z;
  522. INSERT_UNION_PADDING_WORDS(2);
  523. Common::Rectangle<f32> GetRect() const {
  524. return {
  525. GetX(), // left
  526. GetY() + GetHeight(), // top
  527. GetX() + GetWidth(), // right
  528. GetY() // bottom
  529. };
  530. };
  531. f32 GetX() const {
  532. return std::max(0.0f, translate_x - std::fabs(scale_x));
  533. }
  534. f32 GetY() const {
  535. return std::max(0.0f, translate_y - std::fabs(scale_y));
  536. }
  537. f32 GetWidth() const {
  538. return translate_x + std::fabs(scale_x) - GetX();
  539. }
  540. f32 GetHeight() const {
  541. return translate_y + std::fabs(scale_y) - GetY();
  542. }
  543. };
  544. struct ScissorTest {
  545. u32 enable;
  546. union {
  547. BitField<0, 16, u32> min_x;
  548. BitField<16, 16, u32> max_x;
  549. };
  550. union {
  551. BitField<0, 16, u32> min_y;
  552. BitField<16, 16, u32> max_y;
  553. };
  554. u32 fill;
  555. };
  556. struct ViewPort {
  557. union {
  558. BitField<0, 16, u32> x;
  559. BitField<16, 16, u32> width;
  560. };
  561. union {
  562. BitField<0, 16, u32> y;
  563. BitField<16, 16, u32> height;
  564. };
  565. float depth_range_near;
  566. float depth_range_far;
  567. };
  568. bool IsShaderConfigEnabled(std::size_t index) const {
  569. // The VertexB is always enabled.
  570. if (index == static_cast<std::size_t>(Regs::ShaderProgram::VertexB)) {
  571. return true;
  572. }
  573. return shader_config[index].enable != 0;
  574. }
  575. union {
  576. struct {
  577. INSERT_UNION_PADDING_WORDS(0x45);
  578. struct {
  579. u32 upload_address;
  580. u32 data;
  581. u32 entry;
  582. u32 bind;
  583. } macros;
  584. INSERT_UNION_PADDING_WORDS(0x17);
  585. Upload::Registers upload;
  586. struct {
  587. union {
  588. BitField<0, 1, u32> linear;
  589. };
  590. } exec_upload;
  591. u32 data_upload;
  592. INSERT_UNION_PADDING_WORDS(0x44);
  593. struct {
  594. union {
  595. BitField<0, 16, u32> sync_point;
  596. BitField<16, 1, u32> unknown;
  597. BitField<20, 1, u32> increment;
  598. };
  599. } sync_info;
  600. INSERT_UNION_PADDING_WORDS(0x15);
  601. union {
  602. BitField<0, 2, TessellationPrimitive> prim;
  603. BitField<4, 2, TessellationSpacing> spacing;
  604. BitField<8, 1, u32> cw;
  605. BitField<9, 1, u32> connected;
  606. } tess_mode;
  607. std::array<f32, 4> tess_level_outer;
  608. std::array<f32, 2> tess_level_inner;
  609. INSERT_UNION_PADDING_WORDS(0x10);
  610. u32 rasterize_enable;
  611. INSERT_UNION_PADDING_WORDS(0xF1);
  612. u32 tfb_enabled;
  613. INSERT_UNION_PADDING_WORDS(0x2E);
  614. std::array<RenderTargetConfig, NumRenderTargets> rt;
  615. std::array<ViewportTransform, NumViewports> viewport_transform;
  616. std::array<ViewPort, NumViewports> viewports;
  617. INSERT_UNION_PADDING_WORDS(0x1D);
  618. struct {
  619. u32 first;
  620. u32 count;
  621. } vertex_buffer;
  622. DepthMode depth_mode;
  623. float clear_color[4];
  624. float clear_depth;
  625. INSERT_UNION_PADDING_WORDS(0x3);
  626. s32 clear_stencil;
  627. INSERT_UNION_PADDING_WORDS(0x7);
  628. u32 polygon_offset_point_enable;
  629. u32 polygon_offset_line_enable;
  630. u32 polygon_offset_fill_enable;
  631. u32 patch_vertices;
  632. INSERT_UNION_PADDING_WORDS(0xC);
  633. std::array<ScissorTest, NumViewports> scissor_test;
  634. INSERT_UNION_PADDING_WORDS(0x15);
  635. s32 stencil_back_func_ref;
  636. u32 stencil_back_mask;
  637. u32 stencil_back_func_mask;
  638. INSERT_UNION_PADDING_WORDS(0xC);
  639. u32 color_mask_common;
  640. INSERT_UNION_PADDING_WORDS(0x2);
  641. f32 depth_bounds[2];
  642. INSERT_UNION_PADDING_WORDS(0x2);
  643. u32 rt_separate_frag_data;
  644. INSERT_UNION_PADDING_WORDS(0xC);
  645. struct {
  646. u32 address_high;
  647. u32 address_low;
  648. Tegra::DepthFormat format;
  649. union {
  650. BitField<0, 4, u32> block_width;
  651. BitField<4, 4, u32> block_height;
  652. BitField<8, 4, u32> block_depth;
  653. BitField<20, 1, InvMemoryLayout> type;
  654. } memory_layout;
  655. u32 layer_stride;
  656. GPUVAddr Address() const {
  657. return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) |
  658. address_low);
  659. }
  660. } zeta;
  661. INSERT_UNION_PADDING_WORDS(0x41);
  662. union {
  663. BitField<0, 4, u32> stencil;
  664. BitField<4, 4, u32> unknown;
  665. BitField<8, 4, u32> scissor;
  666. BitField<12, 4, u32> viewport;
  667. } clear_flags;
  668. INSERT_UNION_PADDING_WORDS(0x19);
  669. std::array<VertexAttribute, NumVertexAttributes> vertex_attrib_format;
  670. INSERT_UNION_PADDING_WORDS(0xF);
  671. struct {
  672. union {
  673. BitField<0, 4, u32> count;
  674. BitField<4, 3, u32> map_0;
  675. BitField<7, 3, u32> map_1;
  676. BitField<10, 3, u32> map_2;
  677. BitField<13, 3, u32> map_3;
  678. BitField<16, 3, u32> map_4;
  679. BitField<19, 3, u32> map_5;
  680. BitField<22, 3, u32> map_6;
  681. BitField<25, 3, u32> map_7;
  682. };
  683. u32 GetMap(std::size_t index) const {
  684. const std::array<u32, NumRenderTargets> maps{map_0, map_1, map_2, map_3,
  685. map_4, map_5, map_6, map_7};
  686. ASSERT(index < maps.size());
  687. return maps[index];
  688. }
  689. } rt_control;
  690. INSERT_UNION_PADDING_WORDS(0x2);
  691. u32 zeta_width;
  692. u32 zeta_height;
  693. union {
  694. BitField<0, 16, u32> zeta_layers;
  695. BitField<16, 1, u32> zeta_volume;
  696. };
  697. INSERT_UNION_PADDING_WORDS(0x26);
  698. u32 depth_test_enable;
  699. INSERT_UNION_PADDING_WORDS(0x5);
  700. u32 independent_blend_enable;
  701. u32 depth_write_enabled;
  702. u32 alpha_test_enabled;
  703. INSERT_UNION_PADDING_WORDS(0x6);
  704. u32 d3d_cull_mode;
  705. ComparisonOp depth_test_func;
  706. float alpha_test_ref;
  707. ComparisonOp alpha_test_func;
  708. u32 draw_tfb_stride;
  709. struct {
  710. float r;
  711. float g;
  712. float b;
  713. float a;
  714. } blend_color;
  715. INSERT_UNION_PADDING_WORDS(0x4);
  716. struct {
  717. u32 separate_alpha;
  718. Blend::Equation equation_rgb;
  719. Blend::Factor factor_source_rgb;
  720. Blend::Factor factor_dest_rgb;
  721. Blend::Equation equation_a;
  722. Blend::Factor factor_source_a;
  723. INSERT_UNION_PADDING_WORDS(1);
  724. Blend::Factor factor_dest_a;
  725. u32 enable_common;
  726. u32 enable[NumRenderTargets];
  727. } blend;
  728. u32 stencil_enable;
  729. StencilOp stencil_front_op_fail;
  730. StencilOp stencil_front_op_zfail;
  731. StencilOp stencil_front_op_zpass;
  732. ComparisonOp stencil_front_func_func;
  733. s32 stencil_front_func_ref;
  734. u32 stencil_front_func_mask;
  735. u32 stencil_front_mask;
  736. INSERT_UNION_PADDING_WORDS(0x2);
  737. u32 frag_color_clamp;
  738. union {
  739. BitField<0, 1, u32> y_negate;
  740. BitField<4, 1, u32> triangle_rast_flip;
  741. } screen_y_control;
  742. INSERT_UNION_PADDING_WORDS(0x21);
  743. u32 vb_element_base;
  744. u32 vb_base_instance;
  745. INSERT_UNION_PADDING_WORDS(0x35);
  746. union {
  747. BitField<0, 1, u32> c0;
  748. BitField<1, 1, u32> c1;
  749. BitField<2, 1, u32> c2;
  750. BitField<3, 1, u32> c3;
  751. BitField<4, 1, u32> c4;
  752. BitField<5, 1, u32> c5;
  753. BitField<6, 1, u32> c6;
  754. BitField<7, 1, u32> c7;
  755. } clip_distance_enabled;
  756. u32 samplecnt_enable;
  757. float point_size;
  758. INSERT_UNION_PADDING_WORDS(0x1);
  759. u32 point_sprite_enable;
  760. INSERT_UNION_PADDING_WORDS(0x3);
  761. CounterReset counter_reset;
  762. INSERT_UNION_PADDING_WORDS(0x1);
  763. u32 zeta_enable;
  764. union {
  765. BitField<0, 1, u32> alpha_to_coverage;
  766. BitField<4, 1, u32> alpha_to_one;
  767. } multisample_control;
  768. INSERT_UNION_PADDING_WORDS(0x4);
  769. struct {
  770. u32 address_high;
  771. u32 address_low;
  772. ConditionMode mode;
  773. GPUVAddr Address() const {
  774. return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) |
  775. address_low);
  776. }
  777. } condition;
  778. struct {
  779. u32 tsc_address_high;
  780. u32 tsc_address_low;
  781. u32 tsc_limit;
  782. GPUVAddr TSCAddress() const {
  783. return static_cast<GPUVAddr>(
  784. (static_cast<GPUVAddr>(tsc_address_high) << 32) | tsc_address_low);
  785. }
  786. } tsc;
  787. INSERT_UNION_PADDING_WORDS(0x1);
  788. float polygon_offset_factor;
  789. INSERT_UNION_PADDING_WORDS(0x1);
  790. struct {
  791. u32 tic_address_high;
  792. u32 tic_address_low;
  793. u32 tic_limit;
  794. GPUVAddr TICAddress() const {
  795. return static_cast<GPUVAddr>(
  796. (static_cast<GPUVAddr>(tic_address_high) << 32) | tic_address_low);
  797. }
  798. } tic;
  799. INSERT_UNION_PADDING_WORDS(0x5);
  800. u32 stencil_two_side_enable;
  801. StencilOp stencil_back_op_fail;
  802. StencilOp stencil_back_op_zfail;
  803. StencilOp stencil_back_op_zpass;
  804. ComparisonOp stencil_back_func_func;
  805. INSERT_UNION_PADDING_WORDS(0x4);
  806. u32 framebuffer_srgb;
  807. float polygon_offset_units;
  808. INSERT_UNION_PADDING_WORDS(0x11);
  809. union {
  810. BitField<2, 1, u32> coord_origin;
  811. BitField<3, 10, u32> enable;
  812. } point_coord_replace;
  813. struct {
  814. u32 code_address_high;
  815. u32 code_address_low;
  816. GPUVAddr CodeAddress() const {
  817. return static_cast<GPUVAddr>(
  818. (static_cast<GPUVAddr>(code_address_high) << 32) | code_address_low);
  819. }
  820. } code_address;
  821. INSERT_UNION_PADDING_WORDS(1);
  822. struct {
  823. u32 vertex_end_gl;
  824. union {
  825. u32 vertex_begin_gl;
  826. BitField<0, 16, PrimitiveTopology> topology;
  827. BitField<26, 1, u32> instance_next;
  828. BitField<27, 1, u32> instance_cont;
  829. };
  830. } draw;
  831. INSERT_UNION_PADDING_WORDS(0xA);
  832. struct {
  833. u32 enabled;
  834. u32 index;
  835. } primitive_restart;
  836. INSERT_UNION_PADDING_WORDS(0x5F);
  837. struct {
  838. u32 start_addr_high;
  839. u32 start_addr_low;
  840. u32 end_addr_high;
  841. u32 end_addr_low;
  842. IndexFormat format;
  843. u32 first;
  844. u32 count;
  845. unsigned FormatSizeInBytes() const {
  846. switch (format) {
  847. case IndexFormat::UnsignedByte:
  848. return 1;
  849. case IndexFormat::UnsignedShort:
  850. return 2;
  851. case IndexFormat::UnsignedInt:
  852. return 4;
  853. }
  854. UNREACHABLE();
  855. return 1;
  856. }
  857. GPUVAddr StartAddress() const {
  858. return static_cast<GPUVAddr>(
  859. (static_cast<GPUVAddr>(start_addr_high) << 32) | start_addr_low);
  860. }
  861. GPUVAddr EndAddress() const {
  862. return static_cast<GPUVAddr>((static_cast<GPUVAddr>(end_addr_high) << 32) |
  863. end_addr_low);
  864. }
  865. /// Adjust the index buffer offset so it points to the first desired index.
  866. GPUVAddr IndexStart() const {
  867. return StartAddress() + static_cast<size_t>(first) *
  868. static_cast<size_t>(FormatSizeInBytes());
  869. }
  870. } index_array;
  871. INSERT_UNION_PADDING_WORDS(0x7);
  872. INSERT_UNION_PADDING_WORDS(0x1F);
  873. float polygon_offset_clamp;
  874. struct {
  875. u32 is_instanced[NumVertexArrays];
  876. /// Returns whether the vertex array specified by index is supposed to be
  877. /// accessed per instance or not.
  878. bool IsInstancingEnabled(u32 index) const {
  879. return is_instanced[index];
  880. }
  881. } instanced_arrays;
  882. INSERT_UNION_PADDING_WORDS(0x4);
  883. union {
  884. BitField<0, 1, u32> enable;
  885. BitField<4, 8, u32> unk4;
  886. } vp_point_size;
  887. INSERT_UNION_PADDING_WORDS(1);
  888. Cull cull;
  889. u32 pixel_center_integer;
  890. INSERT_UNION_PADDING_WORDS(0x1);
  891. u32 viewport_transform_enabled;
  892. INSERT_UNION_PADDING_WORDS(0x3);
  893. union {
  894. BitField<0, 1, u32> depth_range_0_1;
  895. BitField<3, 1, u32> depth_clamp_near;
  896. BitField<4, 1, u32> depth_clamp_far;
  897. } view_volume_clip_control;
  898. INSERT_UNION_PADDING_WORDS(0x1F);
  899. u32 depth_bounds_enable;
  900. INSERT_UNION_PADDING_WORDS(1);
  901. struct {
  902. u32 enable;
  903. LogicOperation operation;
  904. } logic_op;
  905. INSERT_UNION_PADDING_WORDS(0x1);
  906. union {
  907. u32 raw;
  908. BitField<0, 1, u32> Z;
  909. BitField<1, 1, u32> S;
  910. BitField<2, 1, u32> R;
  911. BitField<3, 1, u32> G;
  912. BitField<4, 1, u32> B;
  913. BitField<5, 1, u32> A;
  914. BitField<6, 4, u32> RT;
  915. BitField<10, 11, u32> layer;
  916. } clear_buffers;
  917. INSERT_UNION_PADDING_WORDS(0xB);
  918. std::array<ColorMask, NumRenderTargets> color_mask;
  919. INSERT_UNION_PADDING_WORDS(0x38);
  920. struct {
  921. u32 query_address_high;
  922. u32 query_address_low;
  923. u32 query_sequence;
  924. union {
  925. u32 raw;
  926. BitField<0, 2, QueryOperation> operation;
  927. BitField<4, 1, u32> fence;
  928. BitField<12, 4, QueryUnit> unit;
  929. BitField<16, 1, QuerySyncCondition> sync_cond;
  930. BitField<23, 5, QuerySelect> select;
  931. BitField<28, 1, u32> short_query;
  932. } query_get;
  933. GPUVAddr QueryAddress() const {
  934. return static_cast<GPUVAddr>(
  935. (static_cast<GPUVAddr>(query_address_high) << 32) | query_address_low);
  936. }
  937. } query;
  938. INSERT_UNION_PADDING_WORDS(0x3C);
  939. struct {
  940. union {
  941. BitField<0, 12, u32> stride;
  942. BitField<12, 1, u32> enable;
  943. };
  944. u32 start_high;
  945. u32 start_low;
  946. u32 divisor;
  947. GPUVAddr StartAddress() const {
  948. return static_cast<GPUVAddr>((static_cast<GPUVAddr>(start_high) << 32) |
  949. start_low);
  950. }
  951. bool IsEnabled() const {
  952. return enable != 0 && StartAddress() != 0;
  953. }
  954. } vertex_array[NumVertexArrays];
  955. Blend independent_blend[NumRenderTargets];
  956. struct {
  957. u32 limit_high;
  958. u32 limit_low;
  959. GPUVAddr LimitAddress() const {
  960. return static_cast<GPUVAddr>((static_cast<GPUVAddr>(limit_high) << 32) |
  961. limit_low);
  962. }
  963. } vertex_array_limit[NumVertexArrays];
  964. struct {
  965. union {
  966. BitField<0, 1, u32> enable;
  967. BitField<4, 4, ShaderProgram> program;
  968. };
  969. u32 offset;
  970. INSERT_UNION_PADDING_WORDS(14);
  971. } shader_config[MaxShaderProgram];
  972. INSERT_UNION_PADDING_WORDS(0x60);
  973. u32 firmware[0x20];
  974. struct {
  975. u32 cb_size;
  976. u32 cb_address_high;
  977. u32 cb_address_low;
  978. u32 cb_pos;
  979. u32 cb_data[NumCBData];
  980. GPUVAddr BufferAddress() const {
  981. return static_cast<GPUVAddr>(
  982. (static_cast<GPUVAddr>(cb_address_high) << 32) | cb_address_low);
  983. }
  984. } const_buffer;
  985. INSERT_UNION_PADDING_WORDS(0x10);
  986. struct {
  987. union {
  988. u32 raw_config;
  989. BitField<0, 1, u32> valid;
  990. BitField<4, 5, u32> index;
  991. };
  992. INSERT_UNION_PADDING_WORDS(7);
  993. } cb_bind[MaxShaderStage];
  994. INSERT_UNION_PADDING_WORDS(0x56);
  995. u32 tex_cb_index;
  996. INSERT_UNION_PADDING_WORDS(0x395);
  997. struct {
  998. /// Compressed address of a buffer that holds information about bound SSBOs.
  999. /// This address is usually bound to c0 in the shaders.
  1000. u32 buffer_address;
  1001. GPUVAddr BufferAddress() const {
  1002. return static_cast<GPUVAddr>(buffer_address) << 8;
  1003. }
  1004. } ssbo_info;
  1005. INSERT_UNION_PADDING_WORDS(0x11);
  1006. struct {
  1007. u32 address[MaxShaderStage];
  1008. u32 size[MaxShaderStage];
  1009. } tex_info_buffers;
  1010. INSERT_UNION_PADDING_WORDS(0xCC);
  1011. };
  1012. std::array<u32, NUM_REGS> reg_array;
  1013. };
  1014. } regs{};
  1015. static_assert(sizeof(Regs) == Regs::NUM_REGS * sizeof(u32), "Maxwell3D Regs has wrong size");
  1016. static_assert(std::is_trivially_copyable_v<Regs>, "Maxwell3D Regs must be trivially copyable");
  1017. struct State {
  1018. struct ShaderStageInfo {
  1019. std::array<ConstBufferInfo, Regs::MaxConstBuffers> const_buffers;
  1020. };
  1021. std::array<ShaderStageInfo, Regs::MaxShaderStage> shader_stages;
  1022. u32 current_instance = 0; ///< Current instance to be used to simulate instanced rendering.
  1023. };
  1024. State state{};
  1025. /// Reads a register value located at the input method address
  1026. u32 GetRegisterValue(u32 method) const;
  1027. /// Write the value to the register identified by method.
  1028. void CallMethod(const GPU::MethodCall& method_call);
  1029. /// Write the value to the register identified by method.
  1030. void CallMethodFromMME(const GPU::MethodCall& method_call);
  1031. void FlushMMEInlineDraw();
  1032. /// Given a texture handle, returns the TSC and TIC entries.
  1033. Texture::FullTextureInfo GetTextureInfo(Texture::TextureHandle tex_handle) const;
  1034. /// Returns the texture information for a specific texture in a specific shader stage.
  1035. Texture::FullTextureInfo GetStageTexture(ShaderType stage, std::size_t offset) const;
  1036. u32 AccessConstBuffer32(ShaderType stage, u64 const_buffer, u64 offset) const override;
  1037. SamplerDescriptor AccessBoundSampler(ShaderType stage, u64 offset) const override;
  1038. SamplerDescriptor AccessBindlessSampler(ShaderType stage, u64 const_buffer,
  1039. u64 offset) const override;
  1040. u32 GetBoundBuffer() const override {
  1041. return regs.tex_cb_index;
  1042. }
  1043. VideoCore::GuestDriverProfile& AccessGuestDriverProfile() override;
  1044. const VideoCore::GuestDriverProfile& AccessGuestDriverProfile() const override;
  1045. /// Memory for macro code - it's undetermined how big this is, however 1MB is much larger than
  1046. /// we've seen used.
  1047. using MacroMemory = std::array<u32, 0x40000>;
  1048. /// Gets a reference to macro memory.
  1049. const MacroMemory& GetMacroMemory() const {
  1050. return macro_memory;
  1051. }
  1052. bool ShouldExecute() const {
  1053. return execute_on;
  1054. }
  1055. enum class MMEDrawMode : u32 {
  1056. Undefined,
  1057. Array,
  1058. Indexed,
  1059. };
  1060. struct MMEDrawState {
  1061. MMEDrawMode current_mode{MMEDrawMode::Undefined};
  1062. u32 current_count{};
  1063. u32 instance_count{};
  1064. bool instance_mode{};
  1065. bool gl_begin_consume{};
  1066. u32 gl_end_count{};
  1067. } mme_draw;
  1068. private:
  1069. void InitializeRegisterDefaults();
  1070. Core::System& system;
  1071. VideoCore::RasterizerInterface& rasterizer;
  1072. MemoryManager& memory_manager;
  1073. /// Start offsets of each macro in macro_memory
  1074. std::array<u32, 0x80> macro_positions = {};
  1075. std::array<bool, Regs::NUM_REGS> mme_inline{};
  1076. /// Memory for macro code
  1077. MacroMemory macro_memory;
  1078. /// Macro method that is currently being executed / being fed parameters.
  1079. u32 executing_macro = 0;
  1080. /// Parameters that have been submitted to the macro call so far.
  1081. std::vector<u32> macro_params;
  1082. /// Interpreter for the macro codes uploaded to the GPU.
  1083. MacroInterpreter macro_interpreter;
  1084. static constexpr u32 null_cb_data = 0xFFFFFFFF;
  1085. struct {
  1086. std::array<std::array<u32, 0x4000>, 16> buffer;
  1087. u32 current{null_cb_data};
  1088. u32 id{null_cb_data};
  1089. u32 start_pos{};
  1090. u32 counter{};
  1091. } cb_data_state;
  1092. Upload::State upload_state;
  1093. bool execute_on{true};
  1094. std::array<u8, Regs::NUM_REGS> dirty_pointers{};
  1095. /// Retrieves information about a specific TIC entry from the TIC buffer.
  1096. Texture::TICEntry GetTICEntry(u32 tic_index) const;
  1097. /// Retrieves information about a specific TSC entry from the TSC buffer.
  1098. Texture::TSCEntry GetTSCEntry(u32 tsc_index) const;
  1099. /**
  1100. * Call a macro on this engine.
  1101. * @param method Method to call
  1102. * @param num_parameters Number of arguments
  1103. * @param parameters Arguments to the method call
  1104. */
  1105. void CallMacroMethod(u32 method, std::size_t num_parameters, const u32* parameters);
  1106. /// Handles writes to the macro uploading register.
  1107. void ProcessMacroUpload(u32 data);
  1108. /// Handles writes to the macro bind register.
  1109. void ProcessMacroBind(u32 data);
  1110. /// Handles firmware blob 4
  1111. void ProcessFirmwareCall4();
  1112. /// Handles a write to the CLEAR_BUFFERS register.
  1113. void ProcessClearBuffers();
  1114. /// Handles a write to the QUERY_GET register.
  1115. void ProcessQueryGet();
  1116. /// Writes the query result accordingly.
  1117. void StampQueryResult(u64 payload, bool long_query);
  1118. /// Handles conditional rendering.
  1119. void ProcessQueryCondition();
  1120. /// Handles counter resets.
  1121. void ProcessCounterReset();
  1122. /// Handles writes to syncing register.
  1123. void ProcessSyncPoint();
  1124. /// Handles a write to the CB_DATA[i] register.
  1125. void StartCBData(u32 method);
  1126. void ProcessCBData(u32 value);
  1127. void FinishCBData();
  1128. /// Handles a write to the CB_BIND register.
  1129. void ProcessCBBind(std::size_t stage_index);
  1130. /// Handles a write to the VERTEX_END_GL register, triggering a draw.
  1131. void DrawArrays();
  1132. // Handles a instance drawcall from MME
  1133. void StepInstance(MMEDrawMode expected_mode, u32 count);
  1134. /// Returns a query's value or an empty object if the value will be deferred through a cache.
  1135. std::optional<u64> GetQueryResult();
  1136. };
  1137. #define ASSERT_REG_POSITION(field_name, position) \
  1138. static_assert(offsetof(Maxwell3D::Regs, field_name) == position * 4, \
  1139. "Field " #field_name " has invalid position")
  1140. ASSERT_REG_POSITION(macros, 0x45);
  1141. ASSERT_REG_POSITION(upload, 0x60);
  1142. ASSERT_REG_POSITION(exec_upload, 0x6C);
  1143. ASSERT_REG_POSITION(data_upload, 0x6D);
  1144. ASSERT_REG_POSITION(sync_info, 0xB2);
  1145. ASSERT_REG_POSITION(tess_mode, 0xC8);
  1146. ASSERT_REG_POSITION(tess_level_outer, 0xC9);
  1147. ASSERT_REG_POSITION(tess_level_inner, 0xCD);
  1148. ASSERT_REG_POSITION(rasterize_enable, 0xDF);
  1149. ASSERT_REG_POSITION(tfb_enabled, 0x1D1);
  1150. ASSERT_REG_POSITION(rt, 0x200);
  1151. ASSERT_REG_POSITION(viewport_transform, 0x280);
  1152. ASSERT_REG_POSITION(viewports, 0x300);
  1153. ASSERT_REG_POSITION(vertex_buffer, 0x35D);
  1154. ASSERT_REG_POSITION(depth_mode, 0x35F);
  1155. ASSERT_REG_POSITION(clear_color[0], 0x360);
  1156. ASSERT_REG_POSITION(clear_depth, 0x364);
  1157. ASSERT_REG_POSITION(clear_stencil, 0x368);
  1158. ASSERT_REG_POSITION(polygon_offset_point_enable, 0x370);
  1159. ASSERT_REG_POSITION(polygon_offset_line_enable, 0x371);
  1160. ASSERT_REG_POSITION(polygon_offset_fill_enable, 0x372);
  1161. ASSERT_REG_POSITION(patch_vertices, 0x373);
  1162. ASSERT_REG_POSITION(scissor_test, 0x380);
  1163. ASSERT_REG_POSITION(stencil_back_func_ref, 0x3D5);
  1164. ASSERT_REG_POSITION(stencil_back_mask, 0x3D6);
  1165. ASSERT_REG_POSITION(stencil_back_func_mask, 0x3D7);
  1166. ASSERT_REG_POSITION(color_mask_common, 0x3E4);
  1167. ASSERT_REG_POSITION(rt_separate_frag_data, 0x3EB);
  1168. ASSERT_REG_POSITION(depth_bounds, 0x3E7);
  1169. ASSERT_REG_POSITION(zeta, 0x3F8);
  1170. ASSERT_REG_POSITION(clear_flags, 0x43E);
  1171. ASSERT_REG_POSITION(vertex_attrib_format, 0x458);
  1172. ASSERT_REG_POSITION(rt_control, 0x487);
  1173. ASSERT_REG_POSITION(zeta_width, 0x48a);
  1174. ASSERT_REG_POSITION(zeta_height, 0x48b);
  1175. ASSERT_REG_POSITION(zeta_layers, 0x48c);
  1176. ASSERT_REG_POSITION(depth_test_enable, 0x4B3);
  1177. ASSERT_REG_POSITION(independent_blend_enable, 0x4B9);
  1178. ASSERT_REG_POSITION(depth_write_enabled, 0x4BA);
  1179. ASSERT_REG_POSITION(alpha_test_enabled, 0x4BB);
  1180. ASSERT_REG_POSITION(d3d_cull_mode, 0x4C2);
  1181. ASSERT_REG_POSITION(depth_test_func, 0x4C3);
  1182. ASSERT_REG_POSITION(alpha_test_ref, 0x4C4);
  1183. ASSERT_REG_POSITION(alpha_test_func, 0x4C5);
  1184. ASSERT_REG_POSITION(draw_tfb_stride, 0x4C6);
  1185. ASSERT_REG_POSITION(blend_color, 0x4C7);
  1186. ASSERT_REG_POSITION(blend, 0x4CF);
  1187. ASSERT_REG_POSITION(stencil_enable, 0x4E0);
  1188. ASSERT_REG_POSITION(stencil_front_op_fail, 0x4E1);
  1189. ASSERT_REG_POSITION(stencil_front_op_zfail, 0x4E2);
  1190. ASSERT_REG_POSITION(stencil_front_op_zpass, 0x4E3);
  1191. ASSERT_REG_POSITION(stencil_front_func_func, 0x4E4);
  1192. ASSERT_REG_POSITION(stencil_front_func_ref, 0x4E5);
  1193. ASSERT_REG_POSITION(stencil_front_func_mask, 0x4E6);
  1194. ASSERT_REG_POSITION(stencil_front_mask, 0x4E7);
  1195. ASSERT_REG_POSITION(frag_color_clamp, 0x4EA);
  1196. ASSERT_REG_POSITION(screen_y_control, 0x4EB);
  1197. ASSERT_REG_POSITION(vb_element_base, 0x50D);
  1198. ASSERT_REG_POSITION(vb_base_instance, 0x50E);
  1199. ASSERT_REG_POSITION(clip_distance_enabled, 0x544);
  1200. ASSERT_REG_POSITION(samplecnt_enable, 0x545);
  1201. ASSERT_REG_POSITION(point_size, 0x546);
  1202. ASSERT_REG_POSITION(point_sprite_enable, 0x548);
  1203. ASSERT_REG_POSITION(counter_reset, 0x54C);
  1204. ASSERT_REG_POSITION(zeta_enable, 0x54E);
  1205. ASSERT_REG_POSITION(multisample_control, 0x54F);
  1206. ASSERT_REG_POSITION(condition, 0x554);
  1207. ASSERT_REG_POSITION(tsc, 0x557);
  1208. ASSERT_REG_POSITION(polygon_offset_factor, 0x55b);
  1209. ASSERT_REG_POSITION(tic, 0x55D);
  1210. ASSERT_REG_POSITION(stencil_two_side_enable, 0x565);
  1211. ASSERT_REG_POSITION(stencil_back_op_fail, 0x566);
  1212. ASSERT_REG_POSITION(stencil_back_op_zfail, 0x567);
  1213. ASSERT_REG_POSITION(stencil_back_op_zpass, 0x568);
  1214. ASSERT_REG_POSITION(stencil_back_func_func, 0x569);
  1215. ASSERT_REG_POSITION(framebuffer_srgb, 0x56E);
  1216. ASSERT_REG_POSITION(polygon_offset_units, 0x56F);
  1217. ASSERT_REG_POSITION(point_coord_replace, 0x581);
  1218. ASSERT_REG_POSITION(code_address, 0x582);
  1219. ASSERT_REG_POSITION(draw, 0x585);
  1220. ASSERT_REG_POSITION(primitive_restart, 0x591);
  1221. ASSERT_REG_POSITION(index_array, 0x5F2);
  1222. ASSERT_REG_POSITION(polygon_offset_clamp, 0x61F);
  1223. ASSERT_REG_POSITION(instanced_arrays, 0x620);
  1224. ASSERT_REG_POSITION(vp_point_size, 0x644);
  1225. ASSERT_REG_POSITION(cull, 0x646);
  1226. ASSERT_REG_POSITION(pixel_center_integer, 0x649);
  1227. ASSERT_REG_POSITION(viewport_transform_enabled, 0x64B);
  1228. ASSERT_REG_POSITION(view_volume_clip_control, 0x64F);
  1229. ASSERT_REG_POSITION(depth_bounds_enable, 0x66F);
  1230. ASSERT_REG_POSITION(logic_op, 0x671);
  1231. ASSERT_REG_POSITION(clear_buffers, 0x674);
  1232. ASSERT_REG_POSITION(color_mask, 0x680);
  1233. ASSERT_REG_POSITION(query, 0x6C0);
  1234. ASSERT_REG_POSITION(vertex_array[0], 0x700);
  1235. ASSERT_REG_POSITION(independent_blend, 0x780);
  1236. ASSERT_REG_POSITION(vertex_array_limit[0], 0x7C0);
  1237. ASSERT_REG_POSITION(shader_config[0], 0x800);
  1238. ASSERT_REG_POSITION(firmware, 0x8C0);
  1239. ASSERT_REG_POSITION(const_buffer, 0x8E0);
  1240. ASSERT_REG_POSITION(cb_bind[0], 0x904);
  1241. ASSERT_REG_POSITION(tex_cb_index, 0x982);
  1242. ASSERT_REG_POSITION(ssbo_info, 0xD18);
  1243. ASSERT_REG_POSITION(tex_info_buffers.address[0], 0xD2A);
  1244. ASSERT_REG_POSITION(tex_info_buffers.size[0], 0xD2F);
  1245. #undef ASSERT_REG_POSITION
  1246. } // namespace Tegra::Engines