VertexShaderGen.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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/EnumFormatter.h"
  6. #include "VideoCommon/LightingShaderGen.h"
  7. #include "VideoCommon/ShaderGenCommon.h"
  8. enum class APIType;
  9. enum class TexInputForm : u32;
  10. enum class TexGenType : u32;
  11. enum class SourceRow : u32;
  12. enum class VSExpand : u32;
  13. // TODO should be reordered
  14. enum class ShaderAttrib : u32
  15. {
  16. Position = 0,
  17. PositionMatrix = 1,
  18. Normal = 2,
  19. Tangent = 3,
  20. Binormal = 4,
  21. Color0 = 5,
  22. Color1 = 6,
  23. TexCoord0 = 8,
  24. TexCoord1 = 9,
  25. TexCoord2 = 10,
  26. TexCoord3 = 11,
  27. TexCoord4 = 12,
  28. TexCoord5 = 13,
  29. TexCoord6 = 14,
  30. TexCoord7 = 15
  31. };
  32. template <>
  33. struct fmt::formatter<ShaderAttrib> : EnumFormatter<ShaderAttrib::TexCoord7>
  34. {
  35. static constexpr array_type names = {
  36. "Position", "Position Matrix", "Normal", "Tangent", "Binormal", "Color 0",
  37. "Color 1", nullptr, "Tex Coord 0", "Tex Coord 1", "Tex Coord 2", "Tex Coord 3",
  38. "Tex Coord 4", "Tex Coord 5", "Tex Coord 6", "Tex Coord 7"};
  39. constexpr formatter() : EnumFormatter(names) {}
  40. };
  41. // Intended for offsetting from Color0/TexCoord0
  42. constexpr ShaderAttrib operator+(ShaderAttrib attrib, int offset)
  43. {
  44. return static_cast<ShaderAttrib>(static_cast<u8>(attrib) + offset);
  45. }
  46. #pragma pack(1)
  47. struct vertex_shader_uid_data
  48. {
  49. u32 NumValues() const { return sizeof(vertex_shader_uid_data); }
  50. u32 components : 23;
  51. u32 numTexGens : 4;
  52. u32 numColorChans : 2;
  53. u32 dualTexTrans_enabled : 1;
  54. VSExpand vs_expand : 2;
  55. u32 position_has_3_elems : 1;
  56. u16 texcoord_elem_count; // 2 bits per texcoord input
  57. u16 texMtxInfo_n_projection; // Stored separately to guarantee that the texMtxInfo struct is
  58. // 8 bits wide
  59. struct
  60. {
  61. TexInputForm inputform : 2;
  62. TexGenType texgentype : 3;
  63. SourceRow sourcerow : 5;
  64. u32 embosssourceshift : 3;
  65. u32 embosslightshift : 3;
  66. } texMtxInfo[8];
  67. struct
  68. {
  69. u32 index : 6;
  70. u32 normalize : 1;
  71. u32 pad : 1;
  72. } postMtxInfo[8];
  73. LightingUidData lighting;
  74. };
  75. #pragma pack()
  76. using VertexShaderUid = ShaderUid<vertex_shader_uid_data>;
  77. VertexShaderUid GetVertexShaderUid();
  78. ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& host_config,
  79. const vertex_shader_uid_data* uid_data);