VertexLoader_Normal.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // Copyright 2008 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include "Common/CommonTypes.h"
  5. #include "Common/EnumMap.h"
  6. #include "Common/Inline.h"
  7. #include "VideoCommon/CPMemory.h"
  8. #include "VideoCommon/VertexLoader.h"
  9. class VertexLoader_Normal
  10. {
  11. public:
  12. static DOLPHIN_FORCE_INLINE u32 GetSize(VertexComponentFormat type, ComponentFormat format,
  13. NormalComponentCount elements, bool index3)
  14. {
  15. return s_table_size[type][index3][elements][format];
  16. }
  17. static TPipelineFunction GetFunction(VertexComponentFormat type, ComponentFormat format,
  18. NormalComponentCount elements, bool index3);
  19. private:
  20. template <typename T, auto last_member>
  21. using EnumMap = typename Common::EnumMap<T, last_member>;
  22. using SizeTable = EnumMap<
  23. std::array<EnumMap<EnumMap<u32, ComponentFormat::InvalidFloat7>, NormalComponentCount::NTB>,
  24. 2>,
  25. VertexComponentFormat::Index16>;
  26. static constexpr SizeTable s_table_size = []() consteval
  27. {
  28. SizeTable table{};
  29. using VCF = VertexComponentFormat;
  30. using NCC = NormalComponentCount;
  31. using FMT = ComponentFormat;
  32. table[VCF::Direct][false][NCC::N][FMT::UByte] = 3;
  33. table[VCF::Direct][false][NCC::N][FMT::Byte] = 3;
  34. table[VCF::Direct][false][NCC::N][FMT::UShort] = 6;
  35. table[VCF::Direct][false][NCC::N][FMT::Short] = 6;
  36. table[VCF::Direct][false][NCC::N][FMT::Float] = 12;
  37. table[VCF::Direct][false][NCC::N][FMT::InvalidFloat5] = 12;
  38. table[VCF::Direct][false][NCC::N][FMT::InvalidFloat6] = 12;
  39. table[VCF::Direct][false][NCC::N][FMT::InvalidFloat7] = 12;
  40. table[VCF::Direct][false][NCC::NTB][FMT::UByte] = 9;
  41. table[VCF::Direct][false][NCC::NTB][FMT::Byte] = 9;
  42. table[VCF::Direct][false][NCC::NTB][FMT::UShort] = 18;
  43. table[VCF::Direct][false][NCC::NTB][FMT::Short] = 18;
  44. table[VCF::Direct][false][NCC::NTB][FMT::Float] = 36;
  45. table[VCF::Direct][false][NCC::NTB][FMT::InvalidFloat5] = 36;
  46. table[VCF::Direct][false][NCC::NTB][FMT::InvalidFloat6] = 36;
  47. table[VCF::Direct][false][NCC::NTB][FMT::InvalidFloat7] = 36;
  48. // Same as above, since there are no indices
  49. table[VCF::Direct][true][NCC::N][FMT::UByte] = 3;
  50. table[VCF::Direct][true][NCC::N][FMT::Byte] = 3;
  51. table[VCF::Direct][true][NCC::N][FMT::UShort] = 6;
  52. table[VCF::Direct][true][NCC::N][FMT::Short] = 6;
  53. table[VCF::Direct][true][NCC::N][FMT::Float] = 12;
  54. table[VCF::Direct][true][NCC::N][FMT::InvalidFloat5] = 12;
  55. table[VCF::Direct][true][NCC::N][FMT::InvalidFloat6] = 12;
  56. table[VCF::Direct][true][NCC::N][FMT::InvalidFloat7] = 12;
  57. table[VCF::Direct][true][NCC::NTB][FMT::UByte] = 9;
  58. table[VCF::Direct][true][NCC::NTB][FMT::Byte] = 9;
  59. table[VCF::Direct][true][NCC::NTB][FMT::UShort] = 18;
  60. table[VCF::Direct][true][NCC::NTB][FMT::Short] = 18;
  61. table[VCF::Direct][true][NCC::NTB][FMT::Float] = 36;
  62. table[VCF::Direct][true][NCC::NTB][FMT::InvalidFloat5] = 36;
  63. table[VCF::Direct][true][NCC::NTB][FMT::InvalidFloat6] = 36;
  64. table[VCF::Direct][true][NCC::NTB][FMT::InvalidFloat7] = 36;
  65. table[VCF::Index8][false][NCC::N][FMT::UByte] = 1;
  66. table[VCF::Index8][false][NCC::N][FMT::Byte] = 1;
  67. table[VCF::Index8][false][NCC::N][FMT::UShort] = 1;
  68. table[VCF::Index8][false][NCC::N][FMT::Short] = 1;
  69. table[VCF::Index8][false][NCC::N][FMT::Float] = 1;
  70. table[VCF::Index8][false][NCC::N][FMT::InvalidFloat5] = 1;
  71. table[VCF::Index8][false][NCC::N][FMT::InvalidFloat6] = 1;
  72. table[VCF::Index8][false][NCC::N][FMT::InvalidFloat7] = 1;
  73. table[VCF::Index8][false][NCC::NTB][FMT::UByte] = 1;
  74. table[VCF::Index8][false][NCC::NTB][FMT::Byte] = 1;
  75. table[VCF::Index8][false][NCC::NTB][FMT::UShort] = 1;
  76. table[VCF::Index8][false][NCC::NTB][FMT::Short] = 1;
  77. table[VCF::Index8][false][NCC::NTB][FMT::Float] = 1;
  78. table[VCF::Index8][false][NCC::NTB][FMT::InvalidFloat5] = 1;
  79. table[VCF::Index8][false][NCC::NTB][FMT::InvalidFloat6] = 1;
  80. table[VCF::Index8][false][NCC::NTB][FMT::InvalidFloat7] = 1;
  81. // Same for NormalComponentCount::N; differs for NTB
  82. table[VCF::Index8][true][NCC::N][FMT::UByte] = 1;
  83. table[VCF::Index8][true][NCC::N][FMT::Byte] = 1;
  84. table[VCF::Index8][true][NCC::N][FMT::UShort] = 1;
  85. table[VCF::Index8][true][NCC::N][FMT::Short] = 1;
  86. table[VCF::Index8][true][NCC::N][FMT::Float] = 1;
  87. table[VCF::Index8][true][NCC::N][FMT::InvalidFloat5] = 1;
  88. table[VCF::Index8][true][NCC::N][FMT::InvalidFloat6] = 1;
  89. table[VCF::Index8][true][NCC::N][FMT::InvalidFloat7] = 1;
  90. table[VCF::Index8][true][NCC::NTB][FMT::UByte] = 3;
  91. table[VCF::Index8][true][NCC::NTB][FMT::Byte] = 3;
  92. table[VCF::Index8][true][NCC::NTB][FMT::UShort] = 3;
  93. table[VCF::Index8][true][NCC::NTB][FMT::Short] = 3;
  94. table[VCF::Index8][true][NCC::NTB][FMT::Float] = 3;
  95. table[VCF::Index8][true][NCC::NTB][FMT::InvalidFloat5] = 3;
  96. table[VCF::Index8][true][NCC::NTB][FMT::InvalidFloat6] = 3;
  97. table[VCF::Index8][true][NCC::NTB][FMT::InvalidFloat7] = 3;
  98. table[VCF::Index16][false][NCC::N][FMT::UByte] = 2;
  99. table[VCF::Index16][false][NCC::N][FMT::Byte] = 2;
  100. table[VCF::Index16][false][NCC::N][FMT::UShort] = 2;
  101. table[VCF::Index16][false][NCC::N][FMT::Short] = 2;
  102. table[VCF::Index16][false][NCC::N][FMT::Float] = 2;
  103. table[VCF::Index16][false][NCC::N][FMT::InvalidFloat5] = 2;
  104. table[VCF::Index16][false][NCC::N][FMT::InvalidFloat6] = 2;
  105. table[VCF::Index16][false][NCC::N][FMT::InvalidFloat7] = 2;
  106. table[VCF::Index16][false][NCC::NTB][FMT::UByte] = 2;
  107. table[VCF::Index16][false][NCC::NTB][FMT::Byte] = 2;
  108. table[VCF::Index16][false][NCC::NTB][FMT::UShort] = 2;
  109. table[VCF::Index16][false][NCC::NTB][FMT::Short] = 2;
  110. table[VCF::Index16][false][NCC::NTB][FMT::Float] = 2;
  111. table[VCF::Index16][false][NCC::NTB][FMT::InvalidFloat5] = 2;
  112. table[VCF::Index16][false][NCC::NTB][FMT::InvalidFloat6] = 2;
  113. table[VCF::Index16][false][NCC::NTB][FMT::InvalidFloat7] = 2;
  114. // Same for NormalComponentCount::N; differs for NTB
  115. table[VCF::Index16][true][NCC::N][FMT::UByte] = 2;
  116. table[VCF::Index16][true][NCC::N][FMT::Byte] = 2;
  117. table[VCF::Index16][true][NCC::N][FMT::UShort] = 2;
  118. table[VCF::Index16][true][NCC::N][FMT::Short] = 2;
  119. table[VCF::Index16][true][NCC::N][FMT::Float] = 2;
  120. table[VCF::Index16][true][NCC::N][FMT::InvalidFloat5] = 2;
  121. table[VCF::Index16][true][NCC::N][FMT::InvalidFloat6] = 2;
  122. table[VCF::Index16][true][NCC::N][FMT::InvalidFloat7] = 2;
  123. table[VCF::Index16][true][NCC::NTB][FMT::UByte] = 6;
  124. table[VCF::Index16][true][NCC::NTB][FMT::Byte] = 6;
  125. table[VCF::Index16][true][NCC::NTB][FMT::UShort] = 6;
  126. table[VCF::Index16][true][NCC::NTB][FMT::Short] = 6;
  127. table[VCF::Index16][true][NCC::NTB][FMT::Float] = 6;
  128. table[VCF::Index16][true][NCC::NTB][FMT::InvalidFloat5] = 6;
  129. table[VCF::Index16][true][NCC::NTB][FMT::InvalidFloat6] = 6;
  130. table[VCF::Index16][true][NCC::NTB][FMT::InvalidFloat7] = 6;
  131. return table;
  132. }
  133. ();
  134. };