pica.h 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311
  1. // Copyright 2014 Citra 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 <cmath>
  7. #include <cstddef>
  8. #include <string>
  9. #include "common/assert.h"
  10. #include "common/bit_field.h"
  11. #include "common/common_funcs.h"
  12. #include "common/common_types.h"
  13. #include "common/vector_math.h"
  14. #include "common/logging/log.h"
  15. #include "pica_types.h"
  16. namespace Pica {
  17. // Returns index corresponding to the Regs member labeled by field_name
  18. // TODO: Due to Visual studio bug 209229, offsetof does not return constant expressions
  19. // when used with array elements (e.g. PICA_REG_INDEX(vs_uniform_setup.set_value[1])).
  20. // For details cf. https://connect.microsoft.com/VisualStudio/feedback/details/209229/offsetof-does-not-produce-a-constant-expression-for-array-members
  21. // Hopefully, this will be fixed sometime in the future.
  22. // For lack of better alternatives, we currently hardcode the offsets when constant
  23. // expressions are needed via PICA_REG_INDEX_WORKAROUND (on sane compilers, static_asserts
  24. // will then make sure the offsets indeed match the automatically calculated ones).
  25. #define PICA_REG_INDEX(field_name) (offsetof(Pica::Regs, field_name) / sizeof(u32))
  26. #if defined(_MSC_VER)
  27. #define PICA_REG_INDEX_WORKAROUND(field_name, backup_workaround_index) (backup_workaround_index)
  28. #else
  29. // NOTE: Yeah, hacking in a static_assert here just to workaround the lacking MSVC compiler
  30. // really is this annoying. This macro just forwards its first argument to PICA_REG_INDEX
  31. // and then performs a (no-op) cast to size_t iff the second argument matches the expected
  32. // field offset. Otherwise, the compiler will fail to compile this code.
  33. #define PICA_REG_INDEX_WORKAROUND(field_name, backup_workaround_index) \
  34. ((typename std::enable_if<backup_workaround_index == PICA_REG_INDEX(field_name), size_t>::type)PICA_REG_INDEX(field_name))
  35. #endif // _MSC_VER
  36. struct Regs {
  37. INSERT_PADDING_WORDS(0x10);
  38. u32 trigger_irq;
  39. INSERT_PADDING_WORDS(0x2f);
  40. enum class CullMode : u32 {
  41. // Select which polygons are considered to be "frontfacing".
  42. KeepAll = 0,
  43. KeepClockWise = 1,
  44. KeepCounterClockWise = 2,
  45. // TODO: What does the third value imply?
  46. };
  47. union {
  48. BitField<0, 2, CullMode> cull_mode;
  49. };
  50. BitField<0, 24, u32> viewport_size_x;
  51. INSERT_PADDING_WORDS(0x1);
  52. BitField<0, 24, u32> viewport_size_y;
  53. INSERT_PADDING_WORDS(0x9);
  54. BitField<0, 24, u32> viewport_depth_range; // float24
  55. BitField<0, 24, u32> viewport_depth_far_plane; // float24
  56. INSERT_PADDING_WORDS(0x1);
  57. union VSOutputAttributes {
  58. // Maps components of output vertex attributes to semantics
  59. enum Semantic : u32
  60. {
  61. POSITION_X = 0,
  62. POSITION_Y = 1,
  63. POSITION_Z = 2,
  64. POSITION_W = 3,
  65. QUATERNION_X = 4,
  66. QUATERNION_Y = 5,
  67. QUATERNION_Z = 6,
  68. QUATERNION_W = 7,
  69. COLOR_R = 8,
  70. COLOR_G = 9,
  71. COLOR_B = 10,
  72. COLOR_A = 11,
  73. TEXCOORD0_U = 12,
  74. TEXCOORD0_V = 13,
  75. TEXCOORD1_U = 14,
  76. TEXCOORD1_V = 15,
  77. // TODO: Not verified
  78. VIEW_X = 18,
  79. VIEW_Y = 19,
  80. VIEW_Z = 20,
  81. TEXCOORD2_U = 22,
  82. TEXCOORD2_V = 23,
  83. INVALID = 31,
  84. };
  85. BitField< 0, 5, Semantic> map_x;
  86. BitField< 8, 5, Semantic> map_y;
  87. BitField<16, 5, Semantic> map_z;
  88. BitField<24, 5, Semantic> map_w;
  89. } vs_output_attributes[7];
  90. INSERT_PADDING_WORDS(0x11);
  91. union {
  92. BitField< 0, 10, s32> x;
  93. BitField<16, 10, s32> y;
  94. } viewport_corner;
  95. INSERT_PADDING_WORDS(0x17);
  96. struct TextureConfig {
  97. enum WrapMode : u32 {
  98. ClampToEdge = 0,
  99. ClampToBorder = 1,
  100. Repeat = 2,
  101. MirroredRepeat = 3,
  102. };
  103. enum TextureFilter : u32 {
  104. Nearest = 0,
  105. Linear = 1
  106. };
  107. union {
  108. u32 raw;
  109. BitField< 0, 8, u32> r;
  110. BitField< 8, 8, u32> g;
  111. BitField<16, 8, u32> b;
  112. BitField<24, 8, u32> a;
  113. } border_color;
  114. union {
  115. BitField< 0, 16, u32> height;
  116. BitField<16, 16, u32> width;
  117. };
  118. union {
  119. BitField< 1, 1, TextureFilter> mag_filter;
  120. BitField< 2, 1, TextureFilter> min_filter;
  121. BitField< 8, 2, WrapMode> wrap_t;
  122. BitField<12, 2, WrapMode> wrap_s;
  123. };
  124. INSERT_PADDING_WORDS(0x1);
  125. u32 address;
  126. u32 GetPhysicalAddress() const {
  127. return DecodeAddressRegister(address);
  128. }
  129. // texture1 and texture2 store the texture format directly after the address
  130. // whereas texture0 inserts some additional flags inbetween.
  131. // Hence, we store the format separately so that all other parameters can be described
  132. // in a single structure.
  133. };
  134. enum class TextureFormat : u32 {
  135. RGBA8 = 0,
  136. RGB8 = 1,
  137. RGB5A1 = 2,
  138. RGB565 = 3,
  139. RGBA4 = 4,
  140. IA8 = 5,
  141. RG8 = 6, ///< @note Also called HILO8 in 3DBrew.
  142. I8 = 7,
  143. A8 = 8,
  144. IA4 = 9,
  145. I4 = 10,
  146. A4 = 11,
  147. ETC1 = 12, // compressed
  148. ETC1A4 = 13, // compressed
  149. };
  150. enum class LogicOp : u32 {
  151. Clear = 0,
  152. And = 1,
  153. AndReverse = 2,
  154. Copy = 3,
  155. Set = 4,
  156. CopyInverted = 5,
  157. NoOp = 6,
  158. Invert = 7,
  159. Nand = 8,
  160. Or = 9,
  161. Nor = 10,
  162. Xor = 11,
  163. Equiv = 12,
  164. AndInverted = 13,
  165. OrReverse = 14,
  166. OrInverted = 15,
  167. };
  168. static unsigned NibblesPerPixel(TextureFormat format) {
  169. switch (format) {
  170. case TextureFormat::RGBA8:
  171. return 8;
  172. case TextureFormat::RGB8:
  173. return 6;
  174. case TextureFormat::RGB5A1:
  175. case TextureFormat::RGB565:
  176. case TextureFormat::RGBA4:
  177. case TextureFormat::IA8:
  178. case TextureFormat::RG8:
  179. return 4;
  180. case TextureFormat::I4:
  181. case TextureFormat::A4:
  182. return 1;
  183. case TextureFormat::I8:
  184. case TextureFormat::A8:
  185. case TextureFormat::IA4:
  186. default: // placeholder for yet unknown formats
  187. return 2;
  188. }
  189. }
  190. union {
  191. BitField< 0, 1, u32> texture0_enable;
  192. BitField< 1, 1, u32> texture1_enable;
  193. BitField< 2, 1, u32> texture2_enable;
  194. };
  195. TextureConfig texture0;
  196. INSERT_PADDING_WORDS(0x8);
  197. BitField<0, 4, TextureFormat> texture0_format;
  198. BitField<0, 1, u32> fragment_lighting_enable;
  199. INSERT_PADDING_WORDS(0x1);
  200. TextureConfig texture1;
  201. BitField<0, 4, TextureFormat> texture1_format;
  202. INSERT_PADDING_WORDS(0x2);
  203. TextureConfig texture2;
  204. BitField<0, 4, TextureFormat> texture2_format;
  205. INSERT_PADDING_WORDS(0x21);
  206. struct FullTextureConfig {
  207. const bool enabled;
  208. const TextureConfig config;
  209. const TextureFormat format;
  210. };
  211. const std::array<FullTextureConfig, 3> GetTextures() const {
  212. return {{
  213. { texture0_enable.ToBool(), texture0, texture0_format },
  214. { texture1_enable.ToBool(), texture1, texture1_format },
  215. { texture2_enable.ToBool(), texture2, texture2_format }
  216. }};
  217. }
  218. // 0xc0-0xff: Texture Combiner (akin to glTexEnv)
  219. struct TevStageConfig {
  220. enum class Source : u32 {
  221. PrimaryColor = 0x0,
  222. PrimaryFragmentColor = 0x1,
  223. SecondaryFragmentColor = 0x2,
  224. Texture0 = 0x3,
  225. Texture1 = 0x4,
  226. Texture2 = 0x5,
  227. Texture3 = 0x6,
  228. PreviousBuffer = 0xd,
  229. Constant = 0xe,
  230. Previous = 0xf,
  231. };
  232. enum class ColorModifier : u32 {
  233. SourceColor = 0x0,
  234. OneMinusSourceColor = 0x1,
  235. SourceAlpha = 0x2,
  236. OneMinusSourceAlpha = 0x3,
  237. SourceRed = 0x4,
  238. OneMinusSourceRed = 0x5,
  239. SourceGreen = 0x8,
  240. OneMinusSourceGreen = 0x9,
  241. SourceBlue = 0xc,
  242. OneMinusSourceBlue = 0xd,
  243. };
  244. enum class AlphaModifier : u32 {
  245. SourceAlpha = 0x0,
  246. OneMinusSourceAlpha = 0x1,
  247. SourceRed = 0x2,
  248. OneMinusSourceRed = 0x3,
  249. SourceGreen = 0x4,
  250. OneMinusSourceGreen = 0x5,
  251. SourceBlue = 0x6,
  252. OneMinusSourceBlue = 0x7,
  253. };
  254. enum class Operation : u32 {
  255. Replace = 0,
  256. Modulate = 1,
  257. Add = 2,
  258. AddSigned = 3,
  259. Lerp = 4,
  260. Subtract = 5,
  261. Dot3_RGB = 6,
  262. MultiplyThenAdd = 8,
  263. AddThenMultiply = 9,
  264. };
  265. union {
  266. u32 sources_raw;
  267. BitField< 0, 4, Source> color_source1;
  268. BitField< 4, 4, Source> color_source2;
  269. BitField< 8, 4, Source> color_source3;
  270. BitField<16, 4, Source> alpha_source1;
  271. BitField<20, 4, Source> alpha_source2;
  272. BitField<24, 4, Source> alpha_source3;
  273. };
  274. union {
  275. u32 modifiers_raw;
  276. BitField< 0, 4, ColorModifier> color_modifier1;
  277. BitField< 4, 4, ColorModifier> color_modifier2;
  278. BitField< 8, 4, ColorModifier> color_modifier3;
  279. BitField<12, 3, AlphaModifier> alpha_modifier1;
  280. BitField<16, 3, AlphaModifier> alpha_modifier2;
  281. BitField<20, 3, AlphaModifier> alpha_modifier3;
  282. };
  283. union {
  284. u32 ops_raw;
  285. BitField< 0, 4, Operation> color_op;
  286. BitField<16, 4, Operation> alpha_op;
  287. };
  288. union {
  289. u32 const_color;
  290. BitField< 0, 8, u32> const_r;
  291. BitField< 8, 8, u32> const_g;
  292. BitField<16, 8, u32> const_b;
  293. BitField<24, 8, u32> const_a;
  294. };
  295. union {
  296. u32 scales_raw;
  297. BitField< 0, 2, u32> color_scale;
  298. BitField<16, 2, u32> alpha_scale;
  299. };
  300. inline unsigned GetColorMultiplier() const {
  301. return (color_scale < 3) ? (1 << color_scale) : 1;
  302. }
  303. inline unsigned GetAlphaMultiplier() const {
  304. return (alpha_scale < 3) ? (1 << alpha_scale) : 1;
  305. }
  306. };
  307. TevStageConfig tev_stage0;
  308. INSERT_PADDING_WORDS(0x3);
  309. TevStageConfig tev_stage1;
  310. INSERT_PADDING_WORDS(0x3);
  311. TevStageConfig tev_stage2;
  312. INSERT_PADDING_WORDS(0x3);
  313. TevStageConfig tev_stage3;
  314. INSERT_PADDING_WORDS(0x3);
  315. union {
  316. // Tev stages 0-3 write their output to the combiner buffer if the corresponding bit in
  317. // these masks are set
  318. BitField< 8, 4, u32> update_mask_rgb;
  319. BitField<12, 4, u32> update_mask_a;
  320. bool TevStageUpdatesCombinerBufferColor(unsigned stage_index) const {
  321. return (stage_index < 4) && (update_mask_rgb & (1 << stage_index));
  322. }
  323. bool TevStageUpdatesCombinerBufferAlpha(unsigned stage_index) const {
  324. return (stage_index < 4) && (update_mask_a & (1 << stage_index));
  325. }
  326. } tev_combiner_buffer_input;
  327. INSERT_PADDING_WORDS(0xf);
  328. TevStageConfig tev_stage4;
  329. INSERT_PADDING_WORDS(0x3);
  330. TevStageConfig tev_stage5;
  331. union {
  332. u32 raw;
  333. BitField< 0, 8, u32> r;
  334. BitField< 8, 8, u32> g;
  335. BitField<16, 8, u32> b;
  336. BitField<24, 8, u32> a;
  337. } tev_combiner_buffer_color;
  338. INSERT_PADDING_WORDS(0x2);
  339. const std::array<Regs::TevStageConfig,6> GetTevStages() const {
  340. return {{ tev_stage0, tev_stage1,
  341. tev_stage2, tev_stage3,
  342. tev_stage4, tev_stage5 }};
  343. };
  344. enum class BlendEquation : u32 {
  345. Add = 0,
  346. Subtract = 1,
  347. ReverseSubtract = 2,
  348. Min = 3,
  349. Max = 4,
  350. };
  351. enum class BlendFactor : u32 {
  352. Zero = 0,
  353. One = 1,
  354. SourceColor = 2,
  355. OneMinusSourceColor = 3,
  356. DestColor = 4,
  357. OneMinusDestColor = 5,
  358. SourceAlpha = 6,
  359. OneMinusSourceAlpha = 7,
  360. DestAlpha = 8,
  361. OneMinusDestAlpha = 9,
  362. ConstantColor = 10,
  363. OneMinusConstantColor = 11,
  364. ConstantAlpha = 12,
  365. OneMinusConstantAlpha = 13,
  366. SourceAlphaSaturate = 14,
  367. };
  368. enum class CompareFunc : u32 {
  369. Never = 0,
  370. Always = 1,
  371. Equal = 2,
  372. NotEqual = 3,
  373. LessThan = 4,
  374. LessThanOrEqual = 5,
  375. GreaterThan = 6,
  376. GreaterThanOrEqual = 7,
  377. };
  378. enum class StencilAction : u32 {
  379. Keep = 0,
  380. Zero = 1,
  381. Replace = 2,
  382. Increment = 3,
  383. Decrement = 4,
  384. Invert = 5,
  385. IncrementWrap = 6,
  386. DecrementWrap = 7
  387. };
  388. struct {
  389. union {
  390. // If false, logic blending is used
  391. BitField<8, 1, u32> alphablend_enable;
  392. };
  393. union {
  394. BitField< 0, 8, BlendEquation> blend_equation_rgb;
  395. BitField< 8, 8, BlendEquation> blend_equation_a;
  396. BitField<16, 4, BlendFactor> factor_source_rgb;
  397. BitField<20, 4, BlendFactor> factor_dest_rgb;
  398. BitField<24, 4, BlendFactor> factor_source_a;
  399. BitField<28, 4, BlendFactor> factor_dest_a;
  400. } alpha_blending;
  401. union {
  402. BitField<0, 4, LogicOp> logic_op;
  403. };
  404. union {
  405. u32 raw;
  406. BitField< 0, 8, u32> r;
  407. BitField< 8, 8, u32> g;
  408. BitField<16, 8, u32> b;
  409. BitField<24, 8, u32> a;
  410. } blend_const;
  411. union {
  412. BitField< 0, 1, u32> enable;
  413. BitField< 4, 3, CompareFunc> func;
  414. BitField< 8, 8, u32> ref;
  415. } alpha_test;
  416. struct {
  417. union {
  418. // Raw value of this register
  419. u32 raw_func;
  420. // If true, enable stencil testing
  421. BitField< 0, 1, u32> enable;
  422. // Comparison operation for stencil testing
  423. BitField< 4, 3, CompareFunc> func;
  424. // Mask used to control writing to the stencil buffer
  425. BitField< 8, 8, u32> write_mask;
  426. // Value to compare against for stencil testing
  427. BitField<16, 8, u32> reference_value;
  428. // Mask to apply on stencil test inputs
  429. BitField<24, 8, u32> input_mask;
  430. };
  431. union {
  432. // Raw value of this register
  433. u32 raw_op;
  434. // Action to perform when the stencil test fails
  435. BitField< 0, 3, StencilAction> action_stencil_fail;
  436. // Action to perform when stencil testing passed but depth testing fails
  437. BitField< 4, 3, StencilAction> action_depth_fail;
  438. // Action to perform when both stencil and depth testing pass
  439. BitField< 8, 3, StencilAction> action_depth_pass;
  440. };
  441. } stencil_test;
  442. union {
  443. BitField< 0, 1, u32> depth_test_enable;
  444. BitField< 4, 3, CompareFunc> depth_test_func;
  445. BitField< 8, 1, u32> red_enable;
  446. BitField< 9, 1, u32> green_enable;
  447. BitField<10, 1, u32> blue_enable;
  448. BitField<11, 1, u32> alpha_enable;
  449. BitField<12, 1, u32> depth_write_enable;
  450. };
  451. INSERT_PADDING_WORDS(0x8);
  452. } output_merger;
  453. // Components are laid out in reverse byte order, most significant bits first.
  454. enum class ColorFormat : u32 {
  455. RGBA8 = 0,
  456. RGB8 = 1,
  457. RGB5A1 = 2,
  458. RGB565 = 3,
  459. RGBA4 = 4,
  460. };
  461. enum class DepthFormat : u32 {
  462. D16 = 0,
  463. D24 = 2,
  464. D24S8 = 3,
  465. };
  466. // Returns the number of bytes in the specified color format
  467. static unsigned BytesPerColorPixel(ColorFormat format) {
  468. switch (format) {
  469. case ColorFormat::RGBA8:
  470. return 4;
  471. case ColorFormat::RGB8:
  472. return 3;
  473. case ColorFormat::RGB5A1:
  474. case ColorFormat::RGB565:
  475. case ColorFormat::RGBA4:
  476. return 2;
  477. default:
  478. LOG_CRITICAL(HW_GPU, "Unknown color format %u", format);
  479. UNIMPLEMENTED();
  480. }
  481. }
  482. struct {
  483. INSERT_PADDING_WORDS(0x6);
  484. DepthFormat depth_format; // TODO: Should be a BitField!
  485. BitField<16, 3, ColorFormat> color_format;
  486. INSERT_PADDING_WORDS(0x4);
  487. u32 depth_buffer_address;
  488. u32 color_buffer_address;
  489. union {
  490. // Apparently, the framebuffer width is stored as expected,
  491. // while the height is stored as the actual height minus one.
  492. // Hence, don't access these fields directly but use the accessors
  493. // GetWidth() and GetHeight() instead.
  494. BitField< 0, 11, u32> width;
  495. BitField<12, 10, u32> height;
  496. };
  497. INSERT_PADDING_WORDS(0x1);
  498. inline u32 GetColorBufferPhysicalAddress() const {
  499. return DecodeAddressRegister(color_buffer_address);
  500. }
  501. inline u32 GetDepthBufferPhysicalAddress() const {
  502. return DecodeAddressRegister(depth_buffer_address);
  503. }
  504. inline u32 GetWidth() const {
  505. return width;
  506. }
  507. inline u32 GetHeight() const {
  508. return height + 1;
  509. }
  510. } framebuffer;
  511. // Returns the number of bytes in the specified depth format
  512. static u32 BytesPerDepthPixel(DepthFormat format) {
  513. switch (format) {
  514. case DepthFormat::D16:
  515. return 2;
  516. case DepthFormat::D24:
  517. return 3;
  518. case DepthFormat::D24S8:
  519. return 4;
  520. default:
  521. LOG_CRITICAL(HW_GPU, "Unknown depth format %u", format);
  522. UNIMPLEMENTED();
  523. }
  524. }
  525. // Returns the number of bits per depth component of the specified depth format
  526. static u32 DepthBitsPerPixel(DepthFormat format) {
  527. switch (format) {
  528. case DepthFormat::D16:
  529. return 16;
  530. case DepthFormat::D24:
  531. case DepthFormat::D24S8:
  532. return 24;
  533. default:
  534. LOG_CRITICAL(HW_GPU, "Unknown depth format %u", format);
  535. UNIMPLEMENTED();
  536. }
  537. }
  538. INSERT_PADDING_WORDS(0x20);
  539. enum class LightingSampler {
  540. Distribution0 = 0,
  541. Distribution1 = 1,
  542. Fresnel = 3,
  543. ReflectBlue = 4,
  544. ReflectGreen = 5,
  545. ReflectRed = 6,
  546. SpotlightAttenuation = 8,
  547. DistanceAttenuation = 16,
  548. };
  549. /**
  550. * Pica fragment lighting supports using different LUTs for each lighting component:
  551. * Reflectance R, G, and B channels, distribution function for specular components 0 and 1,
  552. * fresnel factor, and spotlight attenuation. Furthermore, which LUTs are used for each channel
  553. * (or whether a channel is enabled at all) is specified by various pre-defined lighting
  554. * configurations. With configurations that require more LUTs, more cycles are required on HW to
  555. * perform lighting computations.
  556. */
  557. enum class LightingConfig {
  558. Config0 = 0, ///< Reflect Red, Distribution 0, Spotlight
  559. Config1 = 1, ///< Reflect Red, Fresnel, Spotlight
  560. Config2 = 2, ///< Reflect Red, Distribution 0/1
  561. Config3 = 3, ///< Distribution 0/1, Fresnel
  562. Config4 = 4, ///< Reflect Red/Green/Blue, Distribution 0/1, Spotlight
  563. Config5 = 5, ///< Reflect Red/Green/Blue, Distribution 0, Fresnel, Spotlight
  564. Config6 = 6, ///< Reflect Red, Distribution 0/1, Fresnel, Spotlight
  565. Config7 = 8, ///< Reflect Red/Green/Blue, Distribution 0/1, Fresnel, Spotlight
  566. ///< NOTE: '8' is intentional, '7' does not appear to be a valid configuration
  567. };
  568. /// Selects which lighting components are affected by fresnel
  569. enum class LightingFresnelSelector {
  570. None = 0, ///< Fresnel is disabled
  571. PrimaryAlpha = 1, ///< Primary (diffuse) lighting alpha is affected by fresnel
  572. SecondaryAlpha = 2, ///< Secondary (specular) lighting alpha is affected by fresnel
  573. Both = PrimaryAlpha | SecondaryAlpha, ///< Both primary and secondary lighting alphas are affected by fresnel
  574. };
  575. /// Factor used to scale the output of a lighting LUT
  576. enum class LightingScale {
  577. Scale1 = 0, ///< Scale is 1x
  578. Scale2 = 1, ///< Scale is 2x
  579. Scale4 = 2, ///< Scale is 4x
  580. Scale8 = 3, ///< Scale is 8x
  581. Scale1_4 = 6, ///< Scale is 0.25x
  582. Scale1_2 = 7, ///< Scale is 0.5x
  583. };
  584. enum class LightingLutInput {
  585. NH = 0, // Cosine of the angle between the normal and half-angle vectors
  586. VH = 1, // Cosine of the angle between the view and half-angle vectors
  587. NV = 2, // Cosine of the angle between the normal and the view vector
  588. LN = 3, // Cosine of the angle between the light and the normal vectors
  589. };
  590. enum class LightingBumpMode : u32 {
  591. None = 0,
  592. NormalMap = 1,
  593. TangentMap = 2,
  594. };
  595. union LightColor {
  596. BitField< 0, 10, u32> b;
  597. BitField<10, 10, u32> g;
  598. BitField<20, 10, u32> r;
  599. Math::Vec3f ToVec3f() const {
  600. // These fields are 10 bits wide, however 255 corresponds to 1.0f for each color component
  601. return Math::MakeVec((f32)r / 255.f, (f32)g / 255.f, (f32)b / 255.f);
  602. }
  603. };
  604. /// Returns true if the specified lighting sampler is supported by the current Pica lighting configuration
  605. static bool IsLightingSamplerSupported(LightingConfig config, LightingSampler sampler) {
  606. switch (sampler) {
  607. case LightingSampler::Distribution0:
  608. return (config != LightingConfig::Config1);
  609. case LightingSampler::Distribution1:
  610. return (config != LightingConfig::Config0) && (config != LightingConfig::Config1) && (config != LightingConfig::Config5);
  611. case LightingSampler::Fresnel:
  612. return (config != LightingConfig::Config0) && (config != LightingConfig::Config2) && (config != LightingConfig::Config4);
  613. case LightingSampler::ReflectRed:
  614. return (config != LightingConfig::Config3);
  615. case LightingSampler::ReflectGreen:
  616. case LightingSampler::ReflectBlue:
  617. return (config == LightingConfig::Config4) || (config == LightingConfig::Config5) || (config == LightingConfig::Config7);
  618. }
  619. return false;
  620. }
  621. struct {
  622. struct LightSrc {
  623. LightColor specular_0; // material.specular_0 * light.specular_0
  624. LightColor specular_1; // material.specular_1 * light.specular_1
  625. LightColor diffuse; // material.diffuse * light.diffuse
  626. LightColor ambient; // material.ambient * light.ambient
  627. struct {
  628. // Encoded as 16-bit floating point
  629. union {
  630. BitField< 0, 16, u32> x;
  631. BitField<16, 16, u32> y;
  632. };
  633. union {
  634. BitField< 0, 16, u32> z;
  635. };
  636. INSERT_PADDING_WORDS(0x3);
  637. union {
  638. BitField<0, 1, u32> directional;
  639. BitField<1, 1, u32> two_sided_diffuse; // When disabled, clamp dot-product to 0
  640. };
  641. };
  642. BitField<0, 20, u32> dist_atten_bias;
  643. BitField<0, 20, u32> dist_atten_scale;
  644. INSERT_PADDING_WORDS(0x4);
  645. };
  646. static_assert(sizeof(LightSrc) == 0x10 * sizeof(u32), "LightSrc structure must be 0x10 words");
  647. LightSrc light[8];
  648. LightColor global_ambient; // Emission + (material.ambient * lighting.ambient)
  649. INSERT_PADDING_WORDS(0x1);
  650. BitField<0, 3, u32> num_lights; // Number of enabled lights - 1
  651. union {
  652. BitField< 2, 2, LightingFresnelSelector> fresnel_selector;
  653. BitField< 4, 4, LightingConfig> config;
  654. BitField<22, 2, u32> bump_selector; // 0: Texture 0, 1: Texture 1, 2: Texture 2
  655. BitField<27, 1, u32> clamp_highlights;
  656. BitField<28, 2, LightingBumpMode> bump_mode;
  657. BitField<30, 1, u32> disable_bump_renorm;
  658. };
  659. union {
  660. BitField<16, 1, u32> disable_lut_d0;
  661. BitField<17, 1, u32> disable_lut_d1;
  662. BitField<19, 1, u32> disable_lut_fr;
  663. BitField<20, 1, u32> disable_lut_rr;
  664. BitField<21, 1, u32> disable_lut_rg;
  665. BitField<22, 1, u32> disable_lut_rb;
  666. // Each bit specifies whether distance attenuation should be applied for the
  667. // corresponding light
  668. BitField<24, 1, u32> disable_dist_atten_light_0;
  669. BitField<25, 1, u32> disable_dist_atten_light_1;
  670. BitField<26, 1, u32> disable_dist_atten_light_2;
  671. BitField<27, 1, u32> disable_dist_atten_light_3;
  672. BitField<28, 1, u32> disable_dist_atten_light_4;
  673. BitField<29, 1, u32> disable_dist_atten_light_5;
  674. BitField<30, 1, u32> disable_dist_atten_light_6;
  675. BitField<31, 1, u32> disable_dist_atten_light_7;
  676. };
  677. bool IsDistAttenDisabled(unsigned index) const {
  678. const unsigned disable[] = { disable_dist_atten_light_0, disable_dist_atten_light_1,
  679. disable_dist_atten_light_2, disable_dist_atten_light_3,
  680. disable_dist_atten_light_4, disable_dist_atten_light_5,
  681. disable_dist_atten_light_6, disable_dist_atten_light_7 };
  682. return disable[index] != 0;
  683. }
  684. union {
  685. BitField<0, 8, u32> index; ///< Index at which to set data in the LUT
  686. BitField<8, 5, u32> type; ///< Type of LUT for which to set data
  687. } lut_config;
  688. BitField<0, 1, u32> disable;
  689. INSERT_PADDING_WORDS(0x1);
  690. // When data is written to any of these registers, it gets written to the lookup table of
  691. // the selected type at the selected index, specified above in the `lut_config` register.
  692. // With each write, `lut_config.index` is incremented. It does not matter which of these
  693. // registers is written to, the behavior will be the same.
  694. u32 lut_data[8];
  695. // These are used to specify if absolute (abs) value should be used for each LUT index. When
  696. // abs mode is disabled, LUT indexes are in the range of (-1.0, 1.0). Otherwise, they are in
  697. // the range of (0.0, 1.0).
  698. union {
  699. BitField< 1, 1, u32> disable_d0;
  700. BitField< 5, 1, u32> disable_d1;
  701. BitField< 9, 1, u32> disable_sp;
  702. BitField<13, 1, u32> disable_fr;
  703. BitField<17, 1, u32> disable_rb;
  704. BitField<21, 1, u32> disable_rg;
  705. BitField<25, 1, u32> disable_rr;
  706. } abs_lut_input;
  707. union {
  708. BitField< 0, 3, LightingLutInput> d0;
  709. BitField< 4, 3, LightingLutInput> d1;
  710. BitField< 8, 3, LightingLutInput> sp;
  711. BitField<12, 3, LightingLutInput> fr;
  712. BitField<16, 3, LightingLutInput> rb;
  713. BitField<20, 3, LightingLutInput> rg;
  714. BitField<24, 3, LightingLutInput> rr;
  715. } lut_input;
  716. union {
  717. BitField< 0, 3, LightingScale> d0;
  718. BitField< 4, 3, LightingScale> d1;
  719. BitField< 8, 3, LightingScale> sp;
  720. BitField<12, 3, LightingScale> fr;
  721. BitField<16, 3, LightingScale> rb;
  722. BitField<20, 3, LightingScale> rg;
  723. BitField<24, 3, LightingScale> rr;
  724. static float GetScale(LightingScale scale) {
  725. switch (scale) {
  726. case LightingScale::Scale1:
  727. return 1.0f;
  728. case LightingScale::Scale2:
  729. return 2.0f;
  730. case LightingScale::Scale4:
  731. return 4.0f;
  732. case LightingScale::Scale8:
  733. return 8.0f;
  734. case LightingScale::Scale1_4:
  735. return 0.25f;
  736. case LightingScale::Scale1_2:
  737. return 0.5f;
  738. }
  739. return 0.0f;
  740. }
  741. } lut_scale;
  742. INSERT_PADDING_WORDS(0x6);
  743. union {
  744. // There are 8 light enable "slots", corresponding to the total number of lights
  745. // supported by Pica. For N enabled lights (specified by register 0x1c2, or 'src_num'
  746. // above), the first N slots below will be set to integers within the range of 0-7,
  747. // corresponding to the actual light that is enabled for each slot.
  748. BitField< 0, 3, u32> slot_0;
  749. BitField< 4, 3, u32> slot_1;
  750. BitField< 8, 3, u32> slot_2;
  751. BitField<12, 3, u32> slot_3;
  752. BitField<16, 3, u32> slot_4;
  753. BitField<20, 3, u32> slot_5;
  754. BitField<24, 3, u32> slot_6;
  755. BitField<28, 3, u32> slot_7;
  756. unsigned GetNum(unsigned index) const {
  757. const unsigned enable_slots[] = { slot_0, slot_1, slot_2, slot_3, slot_4, slot_5, slot_6, slot_7 };
  758. return enable_slots[index];
  759. }
  760. } light_enable;
  761. } lighting;
  762. INSERT_PADDING_WORDS(0x26);
  763. enum class VertexAttributeFormat : u64 {
  764. BYTE = 0,
  765. UBYTE = 1,
  766. SHORT = 2,
  767. FLOAT = 3,
  768. };
  769. struct {
  770. BitField<0, 29, u32> base_address;
  771. u32 GetPhysicalBaseAddress() const {
  772. return DecodeAddressRegister(base_address);
  773. }
  774. // Descriptor for internal vertex attributes
  775. union {
  776. BitField< 0, 2, VertexAttributeFormat> format0; // size of one element
  777. BitField< 2, 2, u64> size0; // number of elements minus 1
  778. BitField< 4, 2, VertexAttributeFormat> format1;
  779. BitField< 6, 2, u64> size1;
  780. BitField< 8, 2, VertexAttributeFormat> format2;
  781. BitField<10, 2, u64> size2;
  782. BitField<12, 2, VertexAttributeFormat> format3;
  783. BitField<14, 2, u64> size3;
  784. BitField<16, 2, VertexAttributeFormat> format4;
  785. BitField<18, 2, u64> size4;
  786. BitField<20, 2, VertexAttributeFormat> format5;
  787. BitField<22, 2, u64> size5;
  788. BitField<24, 2, VertexAttributeFormat> format6;
  789. BitField<26, 2, u64> size6;
  790. BitField<28, 2, VertexAttributeFormat> format7;
  791. BitField<30, 2, u64> size7;
  792. BitField<32, 2, VertexAttributeFormat> format8;
  793. BitField<34, 2, u64> size8;
  794. BitField<36, 2, VertexAttributeFormat> format9;
  795. BitField<38, 2, u64> size9;
  796. BitField<40, 2, VertexAttributeFormat> format10;
  797. BitField<42, 2, u64> size10;
  798. BitField<44, 2, VertexAttributeFormat> format11;
  799. BitField<46, 2, u64> size11;
  800. BitField<48, 12, u64> attribute_mask;
  801. // number of total attributes minus 1
  802. BitField<60, 4, u64> num_extra_attributes;
  803. };
  804. inline VertexAttributeFormat GetFormat(int n) const {
  805. VertexAttributeFormat formats[] = {
  806. format0, format1, format2, format3,
  807. format4, format5, format6, format7,
  808. format8, format9, format10, format11
  809. };
  810. return formats[n];
  811. }
  812. inline int GetNumElements(int n) const {
  813. u64 sizes[] = {
  814. size0, size1, size2, size3,
  815. size4, size5, size6, size7,
  816. size8, size9, size10, size11
  817. };
  818. return (int)sizes[n]+1;
  819. }
  820. inline int GetElementSizeInBytes(int n) const {
  821. return (GetFormat(n) == VertexAttributeFormat::FLOAT) ? 4 :
  822. (GetFormat(n) == VertexAttributeFormat::SHORT) ? 2 : 1;
  823. }
  824. inline int GetStride(int n) const {
  825. return GetNumElements(n) * GetElementSizeInBytes(n);
  826. }
  827. inline bool IsDefaultAttribute(int id) const {
  828. return (id >= 12) || (attribute_mask & (1ULL << id)) != 0;
  829. }
  830. inline int GetNumTotalAttributes() const {
  831. return (int)num_extra_attributes+1;
  832. }
  833. // Attribute loaders map the source vertex data to input attributes
  834. // This e.g. allows to load different attributes from different memory locations
  835. struct {
  836. // Source attribute data offset from the base address
  837. u32 data_offset;
  838. union {
  839. BitField< 0, 4, u64> comp0;
  840. BitField< 4, 4, u64> comp1;
  841. BitField< 8, 4, u64> comp2;
  842. BitField<12, 4, u64> comp3;
  843. BitField<16, 4, u64> comp4;
  844. BitField<20, 4, u64> comp5;
  845. BitField<24, 4, u64> comp6;
  846. BitField<28, 4, u64> comp7;
  847. BitField<32, 4, u64> comp8;
  848. BitField<36, 4, u64> comp9;
  849. BitField<40, 4, u64> comp10;
  850. BitField<44, 4, u64> comp11;
  851. // bytes for a single vertex in this loader
  852. BitField<48, 8, u64> byte_count;
  853. BitField<60, 4, u64> component_count;
  854. };
  855. inline int GetComponent(int n) const {
  856. u64 components[] = {
  857. comp0, comp1, comp2, comp3,
  858. comp4, comp5, comp6, comp7,
  859. comp8, comp9, comp10, comp11
  860. };
  861. return (int)components[n];
  862. }
  863. } attribute_loaders[12];
  864. } vertex_attributes;
  865. struct {
  866. enum IndexFormat : u32 {
  867. BYTE = 0,
  868. SHORT = 1,
  869. };
  870. union {
  871. BitField<0, 31, u32> offset; // relative to base attribute address
  872. BitField<31, 1, IndexFormat> format;
  873. };
  874. } index_array;
  875. // Number of vertices to render
  876. u32 num_vertices;
  877. INSERT_PADDING_WORDS(0x1);
  878. // The index of the first vertex to render
  879. u32 vertex_offset;
  880. INSERT_PADDING_WORDS(0x3);
  881. // These two trigger rendering of triangles
  882. u32 trigger_draw;
  883. u32 trigger_draw_indexed;
  884. INSERT_PADDING_WORDS(0x2);
  885. // These registers are used to setup the default "fall-back" vertex shader attributes
  886. struct {
  887. // Index of the current default attribute
  888. u32 index;
  889. // Writing to these registers sets the "current" default attribute.
  890. u32 set_value[3];
  891. } vs_default_attributes_setup;
  892. INSERT_PADDING_WORDS(0x2);
  893. struct {
  894. // There are two channels that can be used to configure the next command buffer, which
  895. // can be then executed by writing to the "trigger" registers. There are two reasons why a
  896. // game might use this feature:
  897. // 1) With this, an arbitrary number of additional command buffers may be executed in
  898. // sequence without requiring any intervention of the CPU after the initial one is
  899. // kicked off.
  900. // 2) Games can configure these registers to provide a command list subroutine mechanism.
  901. BitField< 0, 20, u32> size[2]; ///< Size (in bytes / 8) of each channel's command buffer
  902. BitField< 0, 28, u32> addr[2]; ///< Physical address / 8 of each channel's command buffer
  903. u32 trigger[2]; ///< Triggers execution of the channel's command buffer when written to
  904. unsigned GetSize(unsigned index) const {
  905. ASSERT(index < 2);
  906. return 8 * size[index];
  907. }
  908. PAddr GetPhysicalAddress(unsigned index) const {
  909. ASSERT(index < 2);
  910. return (PAddr)(8 * addr[index]);
  911. }
  912. } command_buffer;
  913. INSERT_PADDING_WORDS(0x07);
  914. enum class GPUMode : u32 {
  915. Drawing = 0,
  916. Configuring = 1
  917. };
  918. GPUMode gpu_mode;
  919. INSERT_PADDING_WORDS(0x18);
  920. enum class TriangleTopology : u32 {
  921. List = 0,
  922. Strip = 1,
  923. Fan = 2,
  924. Shader = 3, // Programmable setup unit implemented in a geometry shader
  925. };
  926. BitField<8, 2, TriangleTopology> triangle_topology;
  927. u32 restart_primitive;
  928. INSERT_PADDING_WORDS(0x20);
  929. struct ShaderConfig {
  930. BitField<0, 16, u32> bool_uniforms;
  931. union {
  932. BitField< 0, 8, u32> x;
  933. BitField< 8, 8, u32> y;
  934. BitField<16, 8, u32> z;
  935. BitField<24, 8, u32> w;
  936. } int_uniforms[4];
  937. INSERT_PADDING_WORDS(0x5);
  938. // Offset to shader program entry point (in words)
  939. BitField<0, 16, u32> main_offset;
  940. union {
  941. BitField< 0, 4, u64> attribute0_register;
  942. BitField< 4, 4, u64> attribute1_register;
  943. BitField< 8, 4, u64> attribute2_register;
  944. BitField<12, 4, u64> attribute3_register;
  945. BitField<16, 4, u64> attribute4_register;
  946. BitField<20, 4, u64> attribute5_register;
  947. BitField<24, 4, u64> attribute6_register;
  948. BitField<28, 4, u64> attribute7_register;
  949. BitField<32, 4, u64> attribute8_register;
  950. BitField<36, 4, u64> attribute9_register;
  951. BitField<40, 4, u64> attribute10_register;
  952. BitField<44, 4, u64> attribute11_register;
  953. BitField<48, 4, u64> attribute12_register;
  954. BitField<52, 4, u64> attribute13_register;
  955. BitField<56, 4, u64> attribute14_register;
  956. BitField<60, 4, u64> attribute15_register;
  957. int GetRegisterForAttribute(int attribute_index) const {
  958. u64 fields[] = {
  959. attribute0_register, attribute1_register, attribute2_register, attribute3_register,
  960. attribute4_register, attribute5_register, attribute6_register, attribute7_register,
  961. attribute8_register, attribute9_register, attribute10_register, attribute11_register,
  962. attribute12_register, attribute13_register, attribute14_register, attribute15_register,
  963. };
  964. return (int)fields[attribute_index];
  965. }
  966. } input_register_map;
  967. // OUTMAP_MASK, 0x28E, CODETRANSFER_END
  968. INSERT_PADDING_WORDS(0x3);
  969. struct {
  970. enum Format : u32
  971. {
  972. FLOAT24 = 0,
  973. FLOAT32 = 1
  974. };
  975. bool IsFloat32() const {
  976. return format == FLOAT32;
  977. }
  978. union {
  979. // Index of the next uniform to write to
  980. // TODO: ctrulib uses 8 bits for this, however that seems to yield lots of invalid indices
  981. // TODO: Maybe the uppermost index is for the geometry shader? Investigate!
  982. BitField<0, 7, u32> index;
  983. BitField<31, 1, Format> format;
  984. };
  985. // Writing to these registers sets the current uniform.
  986. u32 set_value[8];
  987. } uniform_setup;
  988. INSERT_PADDING_WORDS(0x2);
  989. struct {
  990. // Offset of the next instruction to write code to.
  991. // Incremented with each instruction write.
  992. u32 offset;
  993. // Writing to these registers sets the "current" word in the shader program.
  994. u32 set_word[8];
  995. } program;
  996. INSERT_PADDING_WORDS(0x1);
  997. // This register group is used to load an internal table of swizzling patterns,
  998. // which are indexed by each shader instruction to specify vector component swizzling.
  999. struct {
  1000. // Offset of the next swizzle pattern to write code to.
  1001. // Incremented with each instruction write.
  1002. u32 offset;
  1003. // Writing to these registers sets the current swizzle pattern in the table.
  1004. u32 set_word[8];
  1005. } swizzle_patterns;
  1006. INSERT_PADDING_WORDS(0x2);
  1007. };
  1008. ShaderConfig gs;
  1009. ShaderConfig vs;
  1010. INSERT_PADDING_WORDS(0x20);
  1011. // Map register indices to names readable by humans
  1012. // Used for debugging purposes, so performance is not an issue here
  1013. static std::string GetCommandName(int index);
  1014. static inline size_t NumIds() {
  1015. return sizeof(Regs) / sizeof(u32);
  1016. }
  1017. const u32& operator [] (int index) const {
  1018. const u32* content = reinterpret_cast<const u32*>(this);
  1019. return content[index];
  1020. }
  1021. u32& operator [] (int index) {
  1022. u32* content = reinterpret_cast<u32*>(this);
  1023. return content[index];
  1024. }
  1025. private:
  1026. /*
  1027. * Most physical addresses which Pica registers refer to are 8-byte aligned.
  1028. * This function should be used to get the address from a raw register value.
  1029. */
  1030. static inline u32 DecodeAddressRegister(u32 register_value) {
  1031. return register_value * 8;
  1032. }
  1033. };
  1034. // TODO: MSVC does not support using offsetof() on non-static data members even though this
  1035. // is technically allowed since C++11. This macro should be enabled once MSVC adds
  1036. // support for that.
  1037. #ifndef _MSC_VER
  1038. #define ASSERT_REG_POSITION(field_name, position) static_assert(offsetof(Regs, field_name) == position * 4, "Field "#field_name" has invalid position")
  1039. ASSERT_REG_POSITION(trigger_irq, 0x10);
  1040. ASSERT_REG_POSITION(cull_mode, 0x40);
  1041. ASSERT_REG_POSITION(viewport_size_x, 0x41);
  1042. ASSERT_REG_POSITION(viewport_size_y, 0x43);
  1043. ASSERT_REG_POSITION(viewport_depth_range, 0x4d);
  1044. ASSERT_REG_POSITION(viewport_depth_far_plane, 0x4e);
  1045. ASSERT_REG_POSITION(vs_output_attributes[0], 0x50);
  1046. ASSERT_REG_POSITION(vs_output_attributes[1], 0x51);
  1047. ASSERT_REG_POSITION(viewport_corner, 0x68);
  1048. ASSERT_REG_POSITION(texture0_enable, 0x80);
  1049. ASSERT_REG_POSITION(texture0, 0x81);
  1050. ASSERT_REG_POSITION(texture0_format, 0x8e);
  1051. ASSERT_REG_POSITION(fragment_lighting_enable, 0x8f);
  1052. ASSERT_REG_POSITION(texture1, 0x91);
  1053. ASSERT_REG_POSITION(texture1_format, 0x96);
  1054. ASSERT_REG_POSITION(texture2, 0x99);
  1055. ASSERT_REG_POSITION(texture2_format, 0x9e);
  1056. ASSERT_REG_POSITION(tev_stage0, 0xc0);
  1057. ASSERT_REG_POSITION(tev_stage1, 0xc8);
  1058. ASSERT_REG_POSITION(tev_stage2, 0xd0);
  1059. ASSERT_REG_POSITION(tev_stage3, 0xd8);
  1060. ASSERT_REG_POSITION(tev_combiner_buffer_input, 0xe0);
  1061. ASSERT_REG_POSITION(tev_stage4, 0xf0);
  1062. ASSERT_REG_POSITION(tev_stage5, 0xf8);
  1063. ASSERT_REG_POSITION(tev_combiner_buffer_color, 0xfd);
  1064. ASSERT_REG_POSITION(output_merger, 0x100);
  1065. ASSERT_REG_POSITION(framebuffer, 0x110);
  1066. ASSERT_REG_POSITION(lighting, 0x140);
  1067. ASSERT_REG_POSITION(vertex_attributes, 0x200);
  1068. ASSERT_REG_POSITION(index_array, 0x227);
  1069. ASSERT_REG_POSITION(num_vertices, 0x228);
  1070. ASSERT_REG_POSITION(vertex_offset, 0x22a);
  1071. ASSERT_REG_POSITION(trigger_draw, 0x22e);
  1072. ASSERT_REG_POSITION(trigger_draw_indexed, 0x22f);
  1073. ASSERT_REG_POSITION(vs_default_attributes_setup, 0x232);
  1074. ASSERT_REG_POSITION(command_buffer, 0x238);
  1075. ASSERT_REG_POSITION(gpu_mode, 0x245);
  1076. ASSERT_REG_POSITION(triangle_topology, 0x25e);
  1077. ASSERT_REG_POSITION(restart_primitive, 0x25f);
  1078. ASSERT_REG_POSITION(gs, 0x280);
  1079. ASSERT_REG_POSITION(vs, 0x2b0);
  1080. #undef ASSERT_REG_POSITION
  1081. #endif // !defined(_MSC_VER)
  1082. static_assert(sizeof(Regs::ShaderConfig) == 0x30 * sizeof(u32), "ShaderConfig structure has incorrect size");
  1083. // The total number of registers is chosen arbitrarily, but let's make sure it's not some odd value anyway.
  1084. static_assert(sizeof(Regs) <= 0x300 * sizeof(u32), "Register set structure larger than it should be");
  1085. static_assert(sizeof(Regs) >= 0x300 * sizeof(u32), "Register set structure smaller than it should be");
  1086. /// Initialize Pica state
  1087. void Init();
  1088. /// Shutdown Pica state
  1089. void Shutdown();
  1090. } // namespace