pica_state.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // Copyright 2016 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 "common/bit_field.h"
  7. #include "common/common_types.h"
  8. #include "common/vector_math.h"
  9. #include "video_core/primitive_assembly.h"
  10. #include "video_core/regs.h"
  11. #include "video_core/shader/shader.h"
  12. namespace Pica {
  13. /// Struct used to describe current Pica state
  14. struct State {
  15. void Reset();
  16. /// Pica registers
  17. Regs regs;
  18. Shader::ShaderSetup vs;
  19. Shader::ShaderSetup gs;
  20. Shader::AttributeBuffer input_default_attributes;
  21. struct ProcTex {
  22. union ValueEntry {
  23. u32 raw;
  24. // LUT value, encoded as 12-bit fixed point, with 12 fraction bits
  25. BitField<0, 12, u32> value; // 0.0.12 fixed point
  26. // Difference between two entry values. Used for efficient interpolation.
  27. // 0.0.12 fixed point with two's complement. The range is [-0.5, 0.5).
  28. // Note: the type of this is different from the one of lighting LUT
  29. BitField<12, 12, s32> difference;
  30. float ToFloat() const {
  31. return static_cast<float>(value) / 4095.f;
  32. }
  33. float DiffToFloat() const {
  34. return static_cast<float>(difference) / 4095.f;
  35. }
  36. };
  37. union ColorEntry {
  38. u32 raw;
  39. BitField<0, 8, u32> r;
  40. BitField<8, 8, u32> g;
  41. BitField<16, 8, u32> b;
  42. BitField<24, 8, u32> a;
  43. Math::Vec4<u8> ToVector() const {
  44. return {static_cast<u8>(r), static_cast<u8>(g), static_cast<u8>(b),
  45. static_cast<u8>(a)};
  46. }
  47. };
  48. union ColorDifferenceEntry {
  49. u32 raw;
  50. BitField<0, 8, s32> r; // half of the difference between two ColorEntry
  51. BitField<8, 8, s32> g;
  52. BitField<16, 8, s32> b;
  53. BitField<24, 8, s32> a;
  54. Math::Vec4<s32> ToVector() const {
  55. return Math::Vec4<s32>{r, g, b, a} * 2;
  56. }
  57. };
  58. std::array<ValueEntry, 128> noise_table;
  59. std::array<ValueEntry, 128> color_map_table;
  60. std::array<ValueEntry, 128> alpha_map_table;
  61. std::array<ColorEntry, 256> color_table;
  62. std::array<ColorDifferenceEntry, 256> color_diff_table;
  63. } proctex;
  64. struct {
  65. union LutEntry {
  66. // Used for raw access
  67. u32 raw;
  68. // LUT value, encoded as 12-bit fixed point, with 12 fraction bits
  69. BitField<0, 12, u32> value; // 0.0.12 fixed point
  70. // Used for efficient interpolation.
  71. BitField<12, 11, u32> difference; // 0.0.11 fixed point
  72. BitField<23, 1, u32> neg_difference;
  73. float ToFloat() const {
  74. return static_cast<float>(value) / 4095.f;
  75. }
  76. float DiffToFloat() const {
  77. float diff = static_cast<float>(difference) / 2047.f;
  78. return neg_difference ? -diff : diff;
  79. }
  80. };
  81. std::array<std::array<LutEntry, 256>, 24> luts;
  82. } lighting;
  83. struct {
  84. union LutEntry {
  85. // Used for raw access
  86. u32 raw;
  87. BitField<0, 13, s32> difference; // 1.1.11 fixed point
  88. BitField<13, 11, u32> value; // 0.0.11 fixed point
  89. float ToFloat() const {
  90. return static_cast<float>(value) / 2047.0f;
  91. }
  92. float DiffToFloat() const {
  93. return static_cast<float>(difference) / 2047.0f;
  94. }
  95. };
  96. std::array<LutEntry, 128> lut;
  97. } fog;
  98. /// Current Pica command list
  99. struct {
  100. const u32* head_ptr;
  101. const u32* current_ptr;
  102. u32 length;
  103. } cmd_list;
  104. /// Struct used to describe immediate mode rendering state
  105. struct ImmediateModeState {
  106. // Used to buffer partial vertices for immediate-mode rendering.
  107. Shader::AttributeBuffer input_vertex;
  108. // Index of the next attribute to be loaded into `input_vertex`.
  109. u32 current_attribute = 0;
  110. } immediate;
  111. // This is constructed with a dummy triangle topology
  112. PrimitiveAssembler<Shader::OutputVertex> primitive_assembler;
  113. };
  114. extern State g_state; ///< Current Pica state
  115. } // namespace