ConstantManager.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Copyright 2013 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <array>
  5. #include "Common/CommonTypes.h"
  6. // all constant buffer attributes must be 16 bytes aligned, so this are the only allowed components:
  7. using float4 = std::array<float, 4>;
  8. using uint4 = std::array<u32, 4>;
  9. using int4 = std::array<s32, 4>;
  10. enum class DstBlendFactor : u32;
  11. enum class SrcBlendFactor : u32;
  12. enum class ZTexOp : u32;
  13. enum class LogicOp : u32;
  14. struct alignas(16) PixelShaderConstants
  15. {
  16. std::array<int4, 4> colors;
  17. std::array<int4, 4> kcolors;
  18. int4 alpha;
  19. std::array<uint4, 8> texdims;
  20. std::array<int4, 2> zbias;
  21. std::array<int4, 2> indtexscale;
  22. std::array<int4, 6> indtexmtx;
  23. int4 fogcolor;
  24. int4 fogi;
  25. float4 fogf;
  26. std::array<float4, 3> fogrange;
  27. float4 zslope;
  28. std::array<float, 2> efbscale; // .xy
  29. // Constants from here onwards are only used in ubershaders, other than pack2.
  30. u32 genmode; // .z
  31. u32 alphaTest; // .w
  32. u32 fogParam3; // .x
  33. u32 fogRangeBase; // .y
  34. u32 dstalpha; // .z
  35. ZTexOp ztex_op; // .w
  36. u32 late_ztest; // .x (bool)
  37. u32 rgba6_format; // .y (bool)
  38. u32 dither; // .z (bool)
  39. u32 bounding_box; // .w (bool)
  40. std::array<uint4, 16> pack1; // .xy - combiners, .z - tevind, .w - iref
  41. std::array<uint4, 8> pack2; // .x - tevorder, .y - tevksel, .z/.w - SamplerState tm0/tm1
  42. std::array<int4, 32> konst; // .rgba
  43. // The following are used in ubershaders when using shader_framebuffer_fetch blending
  44. u32 blend_enable;
  45. SrcBlendFactor blend_src_factor;
  46. SrcBlendFactor blend_src_factor_alpha;
  47. DstBlendFactor blend_dst_factor;
  48. DstBlendFactor blend_dst_factor_alpha;
  49. u32 blend_subtract;
  50. u32 blend_subtract_alpha;
  51. // For shader_framebuffer_fetch logic ops:
  52. u32 logic_op_enable; // bool
  53. LogicOp logic_op_mode;
  54. // For custom shaders...
  55. u32 time_ms;
  56. };
  57. struct alignas(16) VertexShaderConstants
  58. {
  59. u32 components; // .x
  60. u32 xfmem_dualTexInfo; // .y
  61. u32 xfmem_numColorChans; // .z
  62. u32 missing_color_hex; // .w, used for change detection but not directly by shaders
  63. float4 missing_color_value;
  64. std::array<float4, 6> posnormalmatrix;
  65. std::array<float4, 4> projection;
  66. std::array<int4, 4> materials;
  67. struct Light
  68. {
  69. int4 color;
  70. float4 cosatt;
  71. float4 distatt;
  72. float4 pos;
  73. float4 dir;
  74. };
  75. std::array<Light, 8> lights;
  76. std::array<float4, 24> texmatrices;
  77. std::array<float4, 64> transformmatrices;
  78. std::array<float4, 32> normalmatrices;
  79. std::array<float4, 64> posttransformmatrices;
  80. float4 pixelcentercorrection;
  81. std::array<float, 2> viewport; // .xy
  82. std::array<float, 2> pad2; // .zw
  83. // .x - texMtxInfo, .y - postMtxInfo, [0..1].z = color, [0..1].w = alpha
  84. std::array<uint4, 8> xfmem_pack1;
  85. float4 cached_normal;
  86. float4 cached_tangent;
  87. float4 cached_binormal;
  88. // For UberShader vertex loader
  89. u32 vertex_stride;
  90. std::array<u32, 3> vertex_offset_normals;
  91. u32 vertex_offset_position;
  92. u32 vertex_offset_posmtx;
  93. std::array<u32, 2> vertex_offset_colors;
  94. std::array<u32, 8> vertex_offset_texcoords;
  95. };
  96. enum class VSExpand : u32
  97. {
  98. None = 0,
  99. Point,
  100. Line,
  101. };
  102. struct alignas(16) GeometryShaderConstants
  103. {
  104. float4 stereoparams;
  105. float4 lineptparams;
  106. int4 texoffset;
  107. VSExpand vs_expand; // Used by VS point/line expansion in ubershaders
  108. u32 pad[3];
  109. };