ShaderCompileTask.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using Ryujinx.Graphics.GAL;
  2. using System;
  3. using System.Threading.Tasks;
  4. namespace Ryujinx.Graphics.Gpu.Shader
  5. {
  6. delegate bool ShaderCompileTaskCallback(bool success, ShaderCompileTask task);
  7. /// <summary>
  8. /// A class that represents a shader compilation.
  9. /// </summary>
  10. class ShaderCompileTask
  11. {
  12. private bool _compiling;
  13. private Task _programsTask;
  14. private IProgram _program;
  15. private ShaderCompileTaskCallback _action;
  16. /// <summary>
  17. /// Check the completion status of the shader compile task, and run callbacks on step completion.
  18. /// Calling this periodically is required to progress through steps of the compilation.
  19. /// </summary>
  20. /// <returns>True if the task is complete, false if it is in progress</returns>
  21. public bool IsDone()
  22. {
  23. if (_compiling)
  24. {
  25. ProgramLinkStatus status = _program.CheckProgramLink(false);
  26. if (status != ProgramLinkStatus.Incomplete)
  27. {
  28. return _action(status == ProgramLinkStatus.Success, this);
  29. }
  30. }
  31. else
  32. {
  33. // Waiting on the task.
  34. if (_programsTask.IsCompleted)
  35. {
  36. return _action(true, this);
  37. }
  38. }
  39. return false;
  40. }
  41. /// <summary>
  42. /// Run a callback when the specified task has completed.
  43. /// </summary>
  44. /// <param name="task">The task object that needs to complete</param>
  45. /// <param name="action">The action to perform when it is complete</param>
  46. public void OnTask(Task task, ShaderCompileTaskCallback action)
  47. {
  48. _compiling = false;
  49. _programsTask = task;
  50. _action = action;
  51. }
  52. /// <summary>
  53. /// Run a callback when the specified program has been linked.
  54. /// </summary>
  55. /// <param name="task">The program that needs to be linked</param>
  56. /// <param name="action">The action to perform when linking is complete</param>
  57. public void OnCompiled(IProgram program, ShaderCompileTaskCallback action)
  58. {
  59. _compiling = true;
  60. _program = program;
  61. _action = action;
  62. if (program == null)
  63. {
  64. action(false, this);
  65. }
  66. }
  67. }
  68. }