daily update on 20240325 by nitload youmu
This commit is contained in:
@@ -295,40 +295,44 @@ namespace StgSharp.Graphics
|
||||
SwapBuffers();
|
||||
PollEvents();
|
||||
frameTimeProvider.WaitNextSpan();
|
||||
Console.WriteLine(frameTimeProvider.CurrentSpan);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GLonUpdate update = new GLonUpdate((GLcontext*)graphicContextID); //更换GL库至双线程模式
|
||||
FrameAsyncThread updateT = new AsyncUpdateDataTask(this); //建立两个异步线程
|
||||
FrameAsyncThread renderT = new AsyncRenderFrameTask(this);
|
||||
AsyncUpdateDataTask updateT = new AsyncUpdateDataTask(this); //建立两个异步线程
|
||||
AsyncRenderFrameTask renderT = new AsyncRenderFrameTask(this);
|
||||
|
||||
frameAsyncTaskList.Add(renderT);
|
||||
frameAsyncTaskList.Add(updateT);
|
||||
gl = update;
|
||||
|
||||
update.ActivatedOperationBuffer = updateT.opBuffer;
|
||||
SemaphoreSlim frameBeginSemaphore = FrameAsyncThread.CombineAsync(renderT, updateT);
|
||||
SemaphoreSlim renderCompleteSemaphor = renderT.AsyncStart();
|
||||
SemaphoreSlim updateCompleteSemaphor = updateT.AsyncStart();
|
||||
Barrier frameBarrier = FrameAsyncThread.CombineBeginningAsync(true, renderT, updateT);
|
||||
Barrier swapBufferBarrier = renderT.TodoCompleteBarrier;
|
||||
Barrier exchangeBufferBarrier = updateT.TodoCompleteBarrier;
|
||||
renderT.AsyncStart();
|
||||
updateT.AsyncStart();
|
||||
|
||||
while (!ShouldClose)
|
||||
{
|
||||
Console.WriteLine(1);
|
||||
frameBeginSemaphore.Release(2); //启动下一个渲染循环
|
||||
Console.WriteLine(2);
|
||||
renderCompleteSemaphor.Wait(); //等待两个线程完成
|
||||
updateCompleteSemaphor.Wait();
|
||||
Console.WriteLine(3);
|
||||
SwapBuffers(); //GLFW必要操作
|
||||
|
||||
swapBufferBarrier.SignalAndWait();
|
||||
SwapBuffers(); //绘制帧必要操作
|
||||
PollEvents();
|
||||
Console.WriteLine(4);
|
||||
|
||||
exchangeBufferBarrier.SignalAndWait();
|
||||
FrameAsyncThread.ExchangeBuffer(updateT, renderT); //交换两个线程的缓冲区
|
||||
update.ActivatedOperationBuffer = updateT.opBuffer;
|
||||
Console.WriteLine(5);
|
||||
|
||||
frameTimeProvider.WaitNextSpan(); //等待下一帧开始
|
||||
Console.WriteLine(6);
|
||||
frameBarrier.SignalAndWait();
|
||||
Console.WriteLine(frameTimeProvider.CurrentSpan);
|
||||
}
|
||||
|
||||
updateT.Terminate();
|
||||
renderT.Terminate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -397,5 +401,6 @@ namespace StgSharp.Graphics
|
||||
|
||||
#endregion form main
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -494,24 +494,26 @@ namespace StgSharp.Graphics
|
||||
|
||||
}
|
||||
|
||||
//TODO 目前还不能加载任何任务
|
||||
//TODO 任务的启动逻辑需要重构
|
||||
|
||||
public class FrameAsyncThread
|
||||
{
|
||||
|
||||
private Thread _task;
|
||||
|
||||
protected SemaphoreSlim _frameCompleteSemaphore = new SemaphoreSlim(0, 1);
|
||||
protected SemaphoreSlim _refreshSemaphore;
|
||||
protected Barrier _drawCompleteBarrier;
|
||||
|
||||
private Thread _task;
|
||||
private int _terminateToken;
|
||||
|
||||
protected Barrier _frameSpeedSyncBarrier;
|
||||
protected Action _taskTODO;
|
||||
protected Func<bool> _terminateSignature;
|
||||
internal FrameOperationBuffer opBuffer;
|
||||
|
||||
internal FrameAsyncThread(Action action, IglFunc gl)
|
||||
{
|
||||
_taskTODO = action;
|
||||
opBuffer = new FrameOperationBuffer(gl);
|
||||
_terminateToken = 1;
|
||||
_drawCompleteBarrier = new Barrier(2);
|
||||
}
|
||||
|
||||
public Action TaskTODO
|
||||
@@ -520,48 +522,53 @@ namespace StgSharp.Graphics
|
||||
set => _taskTODO = value;
|
||||
}
|
||||
|
||||
public virtual SemaphoreSlim AsyncStart()
|
||||
|
||||
public Barrier TodoCompleteBarrier
|
||||
{
|
||||
get => _drawCompleteBarrier;
|
||||
}
|
||||
|
||||
public virtual void AsyncStart()
|
||||
{
|
||||
_task = new Thread(
|
||||
() =>
|
||||
{
|
||||
while (true)
|
||||
while (_terminateToken != 0)
|
||||
{
|
||||
_refreshSemaphore.Wait();
|
||||
_taskTODO();
|
||||
_frameCompleteSemaphore.Release();
|
||||
_drawCompleteBarrier.SignalAndWait();
|
||||
_frameSpeedSyncBarrier.SignalAndWait();
|
||||
}
|
||||
});
|
||||
_task.Start();
|
||||
return _frameCompleteSemaphore;
|
||||
}
|
||||
|
||||
public static SemaphoreSlim CombineAsync(params FrameAsyncThread[] taskList)
|
||||
{
|
||||
if (taskList.Length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
SemaphoreSlim refresh = new SemaphoreSlim(0, taskList.Length);
|
||||
foreach (FrameAsyncThread item in taskList)
|
||||
{
|
||||
item._refreshSemaphore = refresh;
|
||||
}
|
||||
return refresh;
|
||||
}
|
||||
|
||||
public static SemaphoreSlim CombineAsync(List<FrameAsyncThread> taskList)
|
||||
public static Barrier CombineAsync(bool needOuterMonitor, List<FrameAsyncThread> taskList)
|
||||
{
|
||||
if (taskList.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
SemaphoreSlim refresh = new SemaphoreSlim(taskList.Count);
|
||||
Barrier b = new Barrier(taskList.Count + (needOuterMonitor ? 1 : 0));
|
||||
foreach (FrameAsyncThread item in taskList)
|
||||
{
|
||||
item._refreshSemaphore = refresh;
|
||||
item._frameSpeedSyncBarrier = b;
|
||||
}
|
||||
return refresh;
|
||||
return b;
|
||||
}
|
||||
|
||||
public static Barrier CombineBeginningAsync(bool needOuterMonitor, params FrameAsyncThread[] taskList)
|
||||
{
|
||||
if (taskList.Length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Barrier b = new Barrier(taskList.Length + (needOuterMonitor ? 1 : 0));
|
||||
foreach (FrameAsyncThread item in taskList)
|
||||
{
|
||||
item._frameSpeedSyncBarrier = b;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
public static void ExchangeBuffer(FrameAsyncThread task0, FrameAsyncThread task1)
|
||||
@@ -571,6 +578,10 @@ namespace StgSharp.Graphics
|
||||
task1.opBuffer = cache;
|
||||
}
|
||||
|
||||
public void Terminate()
|
||||
{
|
||||
Interlocked.Exchange(ref _terminateToken, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -587,14 +598,17 @@ namespace StgSharp.Graphics
|
||||
internal sealed class AsyncRenderFrameTask : FrameAsyncThread
|
||||
{
|
||||
|
||||
|
||||
public AsyncRenderFrameTask(Form f) : base(null, f.gl)
|
||||
{
|
||||
TaskTODO = FrameOperation;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void FrameOperation()
|
||||
{
|
||||
while (opBuffer.CallNext()) {}
|
||||
while (opBuffer.CallNext()) { }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -100,9 +100,7 @@ namespace StgSharp
|
||||
}
|
||||
|
||||
public int CurrentSpan
|
||||
{
|
||||
get => timeSpanCount.Value;
|
||||
}
|
||||
=> timeSpanCount.Value;
|
||||
/// <summary>
|
||||
/// Time source provider provided in <see cref="StgSharp"/> internal framework.
|
||||
/// </summary>
|
||||
|
||||
Binary file not shown.
@@ -44,7 +44,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9a10ec201c1e78c441727446c2649fae962d9b7a")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+02be081eeec25a0e028a94751b7120f22bb80e3c")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -1 +1 @@
|
||||
a9c71d94f84382b1844591857b1e9ad3af27d0a646db63fd84315bdd8da51c77
|
||||
e975e1f3a179d311b4aad771af458c0cc2539109253a4aa2a194bbfa1c451ab7
|
||||
|
||||
Binary file not shown.
@@ -1 +1 @@
|
||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/9a10ec201c1e78c441727446c2649fae962d9b7a/*"}}
|
||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/02be081eeec25a0e028a94751b7120f22bb80e3c/*"}}
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user