job system updates, cpu performance improvements

This commit is contained in:
Turanszki Janos
2020-05-31 00:38:03 +01:00
parent 1831df147c
commit c7f5c1a17e
20 changed files with 815 additions and 845 deletions
+15 -8
View File
@@ -3,10 +3,14 @@
#include <functional>
#include <atomic>
struct wiJobDispatchArgs
struct wiJobArgs
{
uint32_t jobIndex;
uint32_t groupIndex;
uint32_t jobIndex; // job index relative to dispatch (like SV_DispatchThreadID in HLSL)
uint32_t groupID; // group index relative to dispatch (like SV_GroupID in HLSL)
uint32_t groupIndex; // job index relative to group (like SV_GroupIndex in HLSL)
bool isFirstJobInGroup; // is the current job the first one in the group?
bool isLastJobInGroup; // is the current job the last one in the group?
void* sharedmemory; // stack memory shared within the current group (jobs within a group execute serially)
};
namespace wiJobSystem
@@ -21,14 +25,17 @@ namespace wiJobSystem
std::atomic<uint32_t> counter{ 0 };
};
// Add a job to execute asynchronously. Any idle thread will execute this job.
void Execute(context& ctx, const std::function<void()>& job);
// Add a task to execute asynchronously. Any idle thread will execute this.
void Execute(context& ctx, const std::function<void(wiJobArgs)>& task);
// Divide a job onto multiple jobs and execute in parallel.
// Divide a task onto multiple jobs and execute in parallel.
// jobCount : how many jobs to generate for this task.
// groupSize : how many jobs to execute per thread. Jobs inside a group execute serially. It might be worth to increase for small jobs
// func : receives a wiJobDispatchArgs as parameter
void Dispatch(context& ctx, uint32_t jobCount, uint32_t groupSize, const std::function<void(wiJobDispatchArgs)>& job);
// task : receives a wiJobArgs as parameter
void Dispatch(context& ctx, uint32_t jobCount, uint32_t groupSize, const std::function<void(wiJobArgs)>& task, size_t sharedmemory_size = 0);
// Returns the amount of job groups that will be created for a set number of jobs and group size
uint32_t DispatchGroupCount(uint32_t jobCount, uint32_t groupSize);
// Check if any threads are working currently or not
bool IsBusy(const context& ctx);