diff options
| author | EmulationFanatic <62343878+EmulationFanatic@users.noreply.github.com> | 2021-05-19 11:39:19 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-19 11:39:19 -0700 |
| commit | b5c72b44dee2fd977d7cca5aa3c29ef1e2286aa7 (patch) | |
| tree | ae064aca256cb6193f6908cc9698660043754008 /Ryujinx.Graphics.Gpu/Shader/ShaderCompileTask.cs | |
| parent | 0129250c2e169c7386f7e2868cc055f8ec55c005 (diff) | |
| parent | 778011c12ae7905173e02665f397a96686863b89 (diff) | |
Merge pull request #2177 from riperiperi/feature/parallel-shader-cache
Allow parallel shader compilation when loading a shader cache
Diffstat (limited to 'Ryujinx.Graphics.Gpu/Shader/ShaderCompileTask.cs')
| -rw-r--r-- | Ryujinx.Graphics.Gpu/Shader/ShaderCompileTask.cs | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/Ryujinx.Graphics.Gpu/Shader/ShaderCompileTask.cs b/Ryujinx.Graphics.Gpu/Shader/ShaderCompileTask.cs new file mode 100644 index 00000000..ff48fab0 --- /dev/null +++ b/Ryujinx.Graphics.Gpu/Shader/ShaderCompileTask.cs @@ -0,0 +1,94 @@ +using Ryujinx.Graphics.GAL; +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Ryujinx.Graphics.Gpu.Shader +{ + delegate bool ShaderCompileTaskCallback(bool success, ShaderCompileTask task); + + /// <summary> + /// A class that represents a shader compilation. + /// </summary> + class ShaderCompileTask + { + private bool _compiling; + + private Task _programsTask; + private IProgram _program; + + private ShaderCompileTaskCallback _action; + private AutoResetEvent _taskDoneEvent; + + /// <summary> + /// Create a new shader compile task, with an event to signal whenever a subtask completes. + /// </summary> + /// <param name="taskDoneEvent">Event to signal when a subtask completes</param> + public ShaderCompileTask(AutoResetEvent taskDoneEvent) + { + _taskDoneEvent = taskDoneEvent; + } + + /// <summary> + /// Check the completion status of the shader compile task, and run callbacks on step completion. + /// Calling this periodically is required to progress through steps of the compilation. + /// </summary> + /// <returns>True if the task is complete, false if it is in progress</returns> + public bool IsDone() + { + if (_compiling) + { + ProgramLinkStatus status = _program.CheckProgramLink(false); + + if (status != ProgramLinkStatus.Incomplete) + { + return _action(status == ProgramLinkStatus.Success, this); + } + } + else + { + // Waiting on the task. + + if (_programsTask.IsCompleted) + { + return _action(true, this); + } + } + + return false; + } + + /// <summary> + /// Run a callback when the specified task has completed. + /// </summary> + /// <param name="task">The task object that needs to complete</param> + /// <param name="action">The action to perform when it is complete</param> + public void OnTask(Task task, ShaderCompileTaskCallback action) + { + _compiling = false; + + _programsTask = task; + _action = action; + + task.ContinueWith(task => _taskDoneEvent.Set()); + } + + /// <summary> + /// Run a callback when the specified program has been linked. + /// </summary> + /// <param name="task">The program that needs to be linked</param> + /// <param name="action">The action to perform when linking is complete</param> + public void OnCompiled(IProgram program, ShaderCompileTaskCallback action) + { + _compiling = true; + + _program = program; + _action = action; + + if (program == null) + { + action(false, this); + } + } + } +} |
