maxwell_3d.h 51 KB

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