GSXRDebugThermalEvents.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. public class GSXRDebugThermalEvents : MonoBehaviour, GSXRManager.SlamEventListener
  5. {
  6. enum slamThermalLevel
  7. {
  8. kSafe,
  9. kLevel1,
  10. kLevel2,
  11. kLevel3,
  12. kCritical,
  13. kNumThermalLevels
  14. };
  15. public class BaseFsa
  16. {
  17. public List<string>[] actions = {
  18. null, //new List<string>(), // State0
  19. null, //new List<string>(), // State1
  20. null, //new List<string>(), // State2
  21. null, //new List<string>(), // State3
  22. null, //new List<string>(), // State4
  23. };
  24. private int _state = 0;
  25. public int state
  26. {
  27. get { return _state; }
  28. set { OnExit(_state); OnEnter(value); _state = value; }
  29. }
  30. public void OnEnter(int state) { Apply(actions[state]); }
  31. public void OnExit(int state) { }
  32. public void Apply(List<string> actions)
  33. {
  34. if (actions == null || actions.Count == 0) return;
  35. Debug.LogFormat("Actions: {0} {1} {2}", (actions.Count > 0 ? actions[0] : null), (actions.Count > 1 ? actions[1] : null), (actions.Count > 2 ? actions[2] : null));
  36. for(int i=0; i<actions.Count; i++)
  37. {
  38. string[] tokens = actions[i].Split(':');
  39. switch (tokens[0])
  40. {
  41. case "FullFPS":
  42. case "Vsync0":
  43. GSXROverrideSettings.VSyncCount = GSXROverrideSettings.eVSyncCount.k1;
  44. break;
  45. case "HalfFPS":
  46. case "Vsync1":
  47. GSXROverrideSettings.VSyncCount = GSXROverrideSettings.eVSyncCount.k2;
  48. break;
  49. case "MSAA4":
  50. GSXROverrideSettings.EyeAntiAliasing = GSXROverrideSettings.eAntiAliasing.k4;
  51. break;
  52. case "MSAA2":
  53. GSXROverrideSettings.EyeAntiAliasing = GSXROverrideSettings.eAntiAliasing.k2;
  54. break;
  55. case "MSAA1":
  56. GSXROverrideSettings.EyeAntiAliasing = GSXROverrideSettings.eAntiAliasing.k1;
  57. break;
  58. case "Render":
  59. GSXROverrideSettings.EyeResolutionScaleFactor = tokens.Length > 1 ? float.Parse(tokens[1]) / 100f : 1.0f;
  60. break;
  61. case "Render100":
  62. GSXROverrideSettings.EyeResolutionScaleFactor = 1.0f;
  63. break;
  64. case "Render90":
  65. GSXROverrideSettings.EyeResolutionScaleFactor = 0.90f;
  66. break;
  67. case "Render80":
  68. GSXROverrideSettings.EyeResolutionScaleFactor = 0.80f;
  69. break;
  70. case "Render70":
  71. GSXROverrideSettings.EyeResolutionScaleFactor = 0.70f;
  72. break;
  73. case "Render60":
  74. GSXROverrideSettings.EyeResolutionScaleFactor = 0.60f;
  75. break;
  76. case "Render50":
  77. GSXROverrideSettings.EyeResolutionScaleFactor = 0.50f;
  78. break;
  79. case "Render40":
  80. GSXROverrideSettings.EyeResolutionScaleFactor = 0.40f;
  81. break;
  82. case "Render30":
  83. GSXROverrideSettings.EyeResolutionScaleFactor = 0.30f;
  84. break;
  85. case "Render20":
  86. GSXROverrideSettings.EyeResolutionScaleFactor = 0.20f;
  87. break;
  88. case "Render10":
  89. GSXROverrideSettings.EyeResolutionScaleFactor = 0.10f;
  90. break;
  91. case "TextureFull":
  92. GSXROverrideSettings.MasterTextureLimit = GSXROverrideSettings.eMasterTextureLimit.k0;
  93. break;
  94. case "TextureHalf":
  95. GSXROverrideSettings.MasterTextureLimit = GSXROverrideSettings.eMasterTextureLimit.k1;
  96. break;
  97. case "TextureForth":
  98. GSXROverrideSettings.MasterTextureLimit = GSXROverrideSettings.eMasterTextureLimit.k2;
  99. break;
  100. case "TextureEighth":
  101. GSXROverrideSettings.MasterTextureLimit = GSXROverrideSettings.eMasterTextureLimit.k3;
  102. break;
  103. case "Fovea0":
  104. GSXROverrideSettings.FoveateArea = 0;
  105. GSXROverrideSettings.FoveateGain = Vector2.one;
  106. break;
  107. case "Fovea1":
  108. GSXROverrideSettings.FoveateArea = 2;
  109. GSXROverrideSettings.FoveateGain = 2*Vector2.one;
  110. break;
  111. case "Fovea2":
  112. GSXROverrideSettings.FoveateArea = 2;
  113. GSXROverrideSettings.FoveateGain = 4 * Vector2.one;
  114. break;
  115. case "Fovea3":
  116. GSXROverrideSettings.FoveateArea = 1;
  117. GSXROverrideSettings.FoveateGain = 4 * Vector2.one;
  118. break;
  119. case "Fovea4":
  120. GSXROverrideSettings.FoveateArea = 0;
  121. GSXROverrideSettings.FoveateGain = 4 * Vector2.one;
  122. break;
  123. case "Fovea5":
  124. GSXROverrideSettings.FoveateArea = 0;
  125. GSXROverrideSettings.FoveateGain = 6 * Vector2.one;
  126. break;
  127. case "CpuPerfMax":
  128. GSXROverrideSettings.CpuPerfLevel = GSXROverrideSettings.ePerfLevel.Maximum;
  129. break;
  130. case "CpuPerfMed":
  131. GSXROverrideSettings.CpuPerfLevel = GSXROverrideSettings.ePerfLevel.Medium;
  132. break;
  133. case "CpuPerfMin":
  134. GSXROverrideSettings.CpuPerfLevel = GSXROverrideSettings.ePerfLevel.Minimum;
  135. break;
  136. case "GpuPerfMax":
  137. GSXROverrideSettings.GpuPerfLevel = GSXROverrideSettings.ePerfLevel.Maximum;
  138. break;
  139. case "GpuPerfMed":
  140. GSXROverrideSettings.GpuPerfLevel = GSXROverrideSettings.ePerfLevel.Medium;
  141. break;
  142. case "GpuPerfMin":
  143. GSXROverrideSettings.GpuPerfLevel = GSXROverrideSettings.ePerfLevel.Minimum;
  144. break;
  145. case "ChromaticOn":
  146. GSXROverrideSettings.ChromaticAberrationCorrection = GSXROverrideSettings.eChromaticAberrationCorrection.kEnable;
  147. break;
  148. case "ChromaticOff":
  149. GSXROverrideSettings.ChromaticAberrationCorrection = GSXROverrideSettings.eChromaticAberrationCorrection.kDisable;
  150. break;
  151. default:
  152. Debug.LogFormat("SlamThermalEvent: Action {0} not supported", actions[i]);
  153. break;
  154. }
  155. }
  156. }
  157. }
  158. public class CpuFsa : BaseFsa { }
  159. public class GpuFsa : BaseFsa { }
  160. public class SkinFsa : BaseFsa { }
  161. private CpuFsa cpu = new CpuFsa();
  162. private GpuFsa gpu = new GpuFsa();
  163. private SkinFsa skin = new SkinFsa();
  164. void Start()
  165. {
  166. enabled = GSXRConfigOptions.Instance.ThermalEnabled;
  167. if (!GSXRConfigOptions.Instance.ThermalEnabled) return;
  168. //Register for SlamEvents
  169. GSXRManager.Instance.AddEventListener(this);
  170. // Configure state machines
  171. cpu.actions[0] = GSXRConfigOptions.Instance.CpuState0;
  172. cpu.actions[1] = GSXRConfigOptions.Instance.CpuState1;
  173. cpu.actions[2] = GSXRConfigOptions.Instance.CpuState2;
  174. cpu.actions[3] = GSXRConfigOptions.Instance.CpuState3;
  175. cpu.actions[4] = GSXRConfigOptions.Instance.CpuState4;
  176. gpu.actions[0] = GSXRConfigOptions.Instance.GpuState0;
  177. gpu.actions[1] = GSXRConfigOptions.Instance.GpuState1;
  178. gpu.actions[2] = GSXRConfigOptions.Instance.GpuState2;
  179. gpu.actions[3] = GSXRConfigOptions.Instance.GpuState3;
  180. gpu.actions[4] = GSXRConfigOptions.Instance.GpuState4;
  181. skin.actions[0] = GSXRConfigOptions.Instance.SkinState0;
  182. skin.actions[1] = GSXRConfigOptions.Instance.SkinState1;
  183. skin.actions[2] = GSXRConfigOptions.Instance.SkinState2;
  184. skin.actions[3] = GSXRConfigOptions.Instance.SkinState3;
  185. skin.actions[4] = GSXRConfigOptions.Instance.SkinState4;
  186. }
  187. public void OnSlamEvent(GSXRManager.SlamEvent ev)
  188. {
  189. switch (ev.eventType)
  190. {
  191. case GSXRManager.slamEventType.kEventThermal:
  192. //Debug.LogFormat("OnSlamEvent: data {0} {1}", ev.eventData.thermal.zone, ev.eventData.thermal.level);
  193. UpdateThermalEvent((int)ev.eventData.thermal.zone, (int)ev.eventData.thermal.level);
  194. break;
  195. case GSXRManager.slamEventType.kEventVrModeStarted:
  196. SetThermalEvent(GSXRConfigOptions.Instance.ThermalStatesDefault);
  197. break;
  198. }
  199. }
  200. public void Update()
  201. {
  202. if (GSXRConfigOptions.Instance.ThermalTouchTest && Input.GetMouseButtonDown(0))
  203. {
  204. UpdateThermalEvent((int)Random.Range(0, 3), (int)Random.Range(0, 5));
  205. }
  206. }
  207. private void UpdateThermalEvent(int zone, int level)
  208. {
  209. Debug.LogFormat("SlamThermalEvent: zone {0} level {1}", zone, level);
  210. switch(zone)
  211. {
  212. case 0: // cpu
  213. cpu.state = level;
  214. break;
  215. case 1: // gpu
  216. gpu.state = level;
  217. break;
  218. case 2: // skin
  219. skin.state = level;
  220. break;
  221. }
  222. }
  223. private void SetThermalEvent(List<string> states)
  224. {
  225. for (int i = 0; i < states.Count; i++)
  226. {
  227. switch(states[i])
  228. {
  229. case "CpuState0":
  230. UpdateThermalEvent(0, 0);
  231. break;
  232. case "CpuState1":
  233. UpdateThermalEvent(0, 1);
  234. break;
  235. case "CpuState2":
  236. UpdateThermalEvent(0, 2);
  237. break;
  238. case "CpuState3":
  239. UpdateThermalEvent(0, 3);
  240. break;
  241. case "CpuState4":
  242. UpdateThermalEvent(0, 4);
  243. break;
  244. case "GpuState0":
  245. UpdateThermalEvent(1, 0);
  246. break;
  247. case "GpuState1":
  248. UpdateThermalEvent(1, 1);
  249. break;
  250. case "GpuState2":
  251. UpdateThermalEvent(1, 2);
  252. break;
  253. case "GpuState3":
  254. UpdateThermalEvent(1, 3);
  255. break;
  256. case "GpuState4":
  257. UpdateThermalEvent(1, 4);
  258. break;
  259. case "SkinState0":
  260. UpdateThermalEvent(2, 0);
  261. break;
  262. case "SkinState1":
  263. UpdateThermalEvent(2, 1);
  264. break;
  265. case "SkinState2":
  266. UpdateThermalEvent(2, 2);
  267. break;
  268. case "SkinState3":
  269. UpdateThermalEvent(2, 3);
  270. break;
  271. case "SkinState4":
  272. UpdateThermalEvent(2, 4);
  273. break;
  274. }
  275. }
  276. }
  277. }