diff options
| author | riperiperi <rhy3756547@hotmail.com> | 2021-03-29 21:52:25 +0100 |
|---|---|---|
| committer | riperiperi <rhy3756547@hotmail.com> | 2021-04-18 17:33:58 +0100 |
| commit | ddf4b92a9cfbe98f798dd86a7c123b065a832d51 (patch) | |
| tree | aead39221f1975579d00446f181750a299960bca /Ryujinx.Graphics.Gpu/Shader/ShaderCompileTask.cs | |
| parent | bb43219f1dfc2fc35e21bcccab4d96fba5e01f34 (diff) | |
Implement parallel host shader cache compilation.
Diffstat (limited to 'Ryujinx.Graphics.Gpu/Shader/ShaderCompileTask.cs')
| -rw-r--r-- | Ryujinx.Graphics.Gpu/Shader/ShaderCompileTask.cs | 81 |
1 files changed, 81 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..cc1b322b --- /dev/null +++ b/Ryujinx.Graphics.Gpu/Shader/ShaderCompileTask.cs @@ -0,0 +1,81 @@ +using Ryujinx.Graphics.GAL; +using System; +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; + + /// <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; + } + + /// <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); + } + } + } +} |
