PixelShaderGen.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // Copyright 2008 Dolphin Emulator Project
  2. // Licensed under GPLv2+
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include "VideoCommon/BPMemory.h"
  6. #include "VideoCommon/LightingShaderGen.h"
  7. #include "VideoCommon/ShaderGenCommon.h"
  8. #include "VideoCommon/VideoCommon.h"
  9. // TODO: get rid of them as they aren't used
  10. #define C_COLORMATRIX 0 // 0
  11. #define C_COLORS 0 // 0
  12. #define C_KCOLORS (C_COLORS + 4) // 4
  13. #define C_ALPHA (C_KCOLORS + 4) // 8
  14. #define C_TEXDIMS (C_ALPHA + 1) // 9
  15. #define C_ZBIAS (C_TEXDIMS + 8) //17
  16. #define C_INDTEXSCALE (C_ZBIAS + 2) //19
  17. #define C_INDTEXMTX (C_INDTEXSCALE + 2) //21
  18. #define C_FOGCOLOR (C_INDTEXMTX + 6) //27
  19. #define C_FOGI (C_FOGCOLOR + 1) //28
  20. #define C_FOGF (C_FOGI + 1) //29
  21. #define C_ZSLOPE (C_FOGF + 2) //31
  22. #define C_EFBSCALE (C_ZSLOPE + 1) //32
  23. #define C_PENVCONST_END (C_EFBSCALE + 1)
  24. // Different ways to achieve rendering with destination alpha
  25. enum DSTALPHA_MODE
  26. {
  27. DSTALPHA_NONE, // Render normally, without destination alpha
  28. DSTALPHA_ALPHA_PASS, // Render normally first, then render again for alpha
  29. DSTALPHA_DUAL_SOURCE_BLEND // Use dual-source blending
  30. };
  31. #pragma pack(1)
  32. struct pixel_shader_uid_data
  33. {
  34. // TODO: Optimize field order for easy access!
  35. u32 num_values; // TODO: Shouldn't be a u32
  36. u32 NumValues() const { return num_values; }
  37. u32 components : 23;
  38. u32 dstAlphaMode : 2;
  39. u32 Pretest : 2;
  40. u32 nIndirectStagesUsed : 4;
  41. u32 stereo : 1;
  42. u32 genMode_numtexgens : 4;
  43. u32 genMode_numtevstages : 4;
  44. u32 genMode_numindstages : 3;
  45. u32 alpha_test_comp0 : 3;
  46. u32 alpha_test_comp1 : 3;
  47. u32 alpha_test_logic : 2;
  48. u32 alpha_test_use_zcomploc_hack : 1;
  49. u32 fog_proj : 1;
  50. u32 fog_fsel : 3;
  51. u32 fog_RangeBaseEnabled : 1;
  52. u32 ztex_op : 2;
  53. u32 fast_depth_calc : 1;
  54. u32 per_pixel_depth : 1;
  55. u32 forced_early_z : 1;
  56. u32 early_ztest : 1;
  57. u32 bounding_box : 1;
  58. // TODO: 31 bits of padding is a waste. Can we free up some bits elseware?
  59. u32 zfreeze : 1;
  60. u32 pad : 31;
  61. u32 texMtxInfo_n_projection : 8; // 8x1 bit
  62. u32 tevindref_bi0 : 3;
  63. u32 tevindref_bc0 : 3;
  64. u32 tevindref_bi1 : 3;
  65. u32 tevindref_bc1 : 3;
  66. u32 tevindref_bi2 : 3;
  67. u32 tevindref_bc3 : 3;
  68. u32 tevindref_bi4 : 3;
  69. u32 tevindref_bc4 : 3;
  70. inline void SetTevindrefValues(int index, u32 texcoord, u32 texmap)
  71. {
  72. if (index == 0) { tevindref_bc0 = texcoord; tevindref_bi0 = texmap; }
  73. else if (index == 1) { tevindref_bc1 = texcoord; tevindref_bi1 = texmap; }
  74. else if (index == 2) { tevindref_bc3 = texcoord; tevindref_bi2 = texmap; }
  75. else if (index == 3) { tevindref_bc4 = texcoord; tevindref_bi4 = texmap; }
  76. }
  77. inline void SetTevindrefTexmap(int index, u32 texmap)
  78. {
  79. if (index == 0) { tevindref_bi0 = texmap; }
  80. else if (index == 1) { tevindref_bi1 = texmap; }
  81. else if (index == 2) { tevindref_bi2 = texmap; }
  82. else if (index == 3) { tevindref_bi4 = texmap; }
  83. }
  84. struct {
  85. // TODO: Can save a lot space by removing the padding bits
  86. u32 cc : 24;
  87. u32 ac : 24;
  88. u32 tevorders_texmap : 3;
  89. u32 tevorders_texcoord : 3;
  90. u32 tevorders_enable : 1;
  91. u32 tevorders_colorchan : 3;
  92. u32 pad1 : 6;
  93. // TODO: Clean up the swapXY mess
  94. u32 hasindstage : 1;
  95. u32 tevind : 21;
  96. u32 tevksel_swap1a : 2;
  97. u32 tevksel_swap2a : 2;
  98. u32 tevksel_swap1b : 2;
  99. u32 tevksel_swap2b : 2;
  100. u32 pad2 : 2;
  101. u32 tevksel_swap1c : 2;
  102. u32 tevksel_swap2c : 2;
  103. u32 tevksel_swap1d : 2;
  104. u32 tevksel_swap2d : 2;
  105. u32 tevksel_kc : 5;
  106. u32 tevksel_ka : 5;
  107. u32 pad3 : 14;
  108. } stagehash[16];
  109. // TODO: I think we're fine without an enablePixelLighting field, should probably double check, though..
  110. LightingUidData lighting;
  111. };
  112. #pragma pack()
  113. typedef ShaderUid<pixel_shader_uid_data> PixelShaderUid;
  114. typedef ShaderCode PixelShaderCode; // TODO: Obsolete
  115. typedef ShaderConstantProfile PixelShaderConstantProfile; // TODO: Obsolete
  116. void GeneratePixelShaderCode(PixelShaderCode& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components);
  117. void GetPixelShaderUid(PixelShaderUid& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components);
  118. void GetPixelShaderConstantProfile(PixelShaderConstantProfile& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components);