Last active
April 10, 2020 14:14
-
-
Save jeffvella/d8e0ded2873d0c85780a9bed43e422f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Test, TestCategory(TestCategory.Integrity)] | |
| public void EnqueuesToCorrectThread([Values(1, 10, 100)] int jobCount, [Values(1, 2, 10)] int numPerThread) | |
| { | |
| var threadIds = new NativeArray<int>(jobCount, Allocator.TempJob); | |
| var threadUsages = new NativeArray<int>(JobsUtility.MaxJobThreadCount, Allocator.TempJob); | |
| var (baseQueue, componentQueue, bufferQueue) = new QueueRig<EcsTestData, EcsIntElement>(Allocator.TempJob); | |
| try | |
| { | |
| var handle = IJobParallelForExtensions.Schedule(new EnqueuesToCorrectThreadJob | |
| { | |
| Events = componentQueue, | |
| ThreadIds = threadIds, | |
| ThreadUsages = threadUsages | |
| }, jobCount, numPerThread); | |
| handle.Complete(); | |
| for (int i = 0; i < jobCount; i++) | |
| { | |
| var threadId = threadIds[i]; | |
| var usageCount = threadUsages[threadId]; | |
| if (usageCount == 0) | |
| continue; | |
| var size = baseQueue.GetComponentsForThread(threadId).Length; | |
| var componentCountForThread = size / sizeof(EcsTestData); | |
| if (usageCount != componentCountForThread) | |
| Debugger.Break(); | |
| Assert.AreEqual(usageCount, componentCountForThread); | |
| } | |
| } | |
| finally | |
| { | |
| threadIds.Dispose(); | |
| threadUsages.Dispose(); | |
| baseQueue.Dispose(); | |
| } | |
| } | |
| [BurstCompile] | |
| public struct EnqueuesToCorrectThreadJob : IJobParallelFor | |
| { | |
| public EventQueue<EcsTestData> Events; | |
| [NativeDisableContainerSafetyRestriction] | |
| public NativeArray<int> ThreadIds; | |
| [NativeDisableContainerSafetyRestriction] | |
| public NativeArray<int> ThreadUsages; | |
| #pragma warning disable IDE0044, CS0649 | |
| [NativeSetThreadIndex] | |
| private int _threadIndex; | |
| #pragma warning restore IDE0044, CS0649 | |
| public void Execute(int index) | |
| { | |
| Events.Enqueue(new EcsTestData | |
| { | |
| value = _threadIndex | |
| }); | |
| ThreadIds[index] = _threadIndex; | |
| ThreadUsages[_threadIndex]++; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment