jobsystem updates:

- separate workloads possible with context;
- jobs can spawn other jobs;
- threads don't yield when waiting;
- loading screen uses job system now;
- compiling psos with jobsystem;
This commit is contained in:
turanszkij
2019-06-29 17:18:12 +01:00
13 changed files with 447 additions and 455 deletions
+4 -2
View File
@@ -488,6 +488,8 @@ ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor)
}
wiJobSystem::context ctx;
for (auto& it : gen_meshes)
{
MeshComponent& mesh = *it.first;
@@ -503,12 +505,12 @@ ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor)
}
else if (gen_type == UV_GEN_GENERATE_ATLAS)
{
wiJobSystem::Execute([&] {
wiJobSystem::Execute(ctx, [&] {
it.second = GenerateMeshAtlas(mesh, (uint32_t)lightmapResolutionSlider->GetValue());
});
}
}
wiJobSystem::Wait();
wiJobSystem::Wait(ctx);
for (auto& x : gen_objects)
{
+10 -7
View File
@@ -198,6 +198,9 @@ void TestsRenderer::RunJobSystemTest()
{
wiTimer timer;
// This is created to be able to wait on the workload independently from other workload:
wiJobSystem::context ctx;
// This will simulate going over a big dataset first in a simple loop, then with the Job System and compare timings
uint32_t itemCount = 1000000;
std::stringstream ss("");
@@ -221,11 +224,11 @@ void TestsRenderer::RunJobSystemTest()
// Execute test
{
timer.record();
wiJobSystem::Execute([]{ wiHelper::Spin(100); });
wiJobSystem::Execute([]{ wiHelper::Spin(100); });
wiJobSystem::Execute([]{ wiHelper::Spin(100); });
wiJobSystem::Execute([]{ wiHelper::Spin(100); });
wiJobSystem::Wait();
wiJobSystem::Execute(ctx, []{ wiHelper::Spin(100); });
wiJobSystem::Execute(ctx, []{ wiHelper::Spin(100); });
wiJobSystem::Execute(ctx, []{ wiHelper::Spin(100); });
wiJobSystem::Execute(ctx, []{ wiHelper::Spin(100); });
wiJobSystem::Wait(ctx);
double time = timer.elapsed();
ss << "wiJobSystem::Execute() took " << time << " milliseconds" << std::endl;
}
@@ -249,10 +252,10 @@ void TestsRenderer::RunJobSystemTest()
{
std::vector<wiSceneSystem::CameraComponent> dataSet(itemCount);
timer.record();
wiJobSystem::Dispatch(itemCount, 1000, [&](wiJobDispatchArgs args) {
wiJobSystem::Dispatch(ctx, itemCount, 1000, [&](wiJobDispatchArgs args) {
dataSet[args.jobIndex].UpdateCamera();
});
wiJobSystem::Wait();
wiJobSystem::Wait(ctx);
double time = timer.elapsed();
ss << "wiJobSystem::Dispatch() took " << time << " milliseconds" << std::endl;
}
+11 -65
View File
@@ -3,34 +3,16 @@
using namespace std;
LoadingScreen::LoadingScreen() : RenderPath2D()
{
loaders.clear();
finish = nullptr;
}
LoadingScreen::~LoadingScreen()
{
}
bool LoadingScreen::isActive()
{
for (LoaderTask& x : loaders)
{
if (x.active.load())
{
return true;
}
}
return false;
return wiJobSystem::IsBusy(ctx_main) || wiJobSystem::IsBusy(ctx_finish);
}
void LoadingScreen::addLoadingFunction(function<void()> loadingFunction)
{
if (loadingFunction != nullptr)
{
loaders.push_back(LoaderTask(loadingFunction));
tasks.push_back(loadingFunction);
}
}
@@ -50,48 +32,6 @@ void LoadingScreen::onFinished(function<void()> finishFunction)
finish = finishFunction;
}
void LoadingScreen::waitForFinish()
{
worker.join();
if (finish != nullptr)
finish();
}
void LoadingScreen::doLoadingTasks()
{
std::vector<thread> loaderThreads(0);
for (LoaderTask& x : loaders)
{
x.active.store(true);
loaderThreads.push_back(thread(x.functionBody));
}
int i = 0;
for (thread& x : loaderThreads)
{
x.join();
loaders[i].active.store(false);
i++;
}
}
int LoadingScreen::getPercentageComplete()
{
const int numberOfLoaders = (int)loaders.size();
int completed = 0;
for (LoaderTask& x : loaders)
{
if (!x.active.load())
{
completed++;
}
}
return (int)(((float)completed / (float)numberOfLoaders)*100.f);
}
void LoadingScreen::Unload()
{
RenderPath2D::Unload();
@@ -99,15 +39,21 @@ void LoadingScreen::Unload()
void LoadingScreen::Start()
{
worker = thread(&LoadingScreen::doLoadingTasks, this);
thread(&LoadingScreen::waitForFinish, this).detach();
for (auto& x : tasks)
{
wiJobSystem::Execute(ctx_main, x);
}
wiJobSystem::Execute(ctx_finish, [this] {
wiJobSystem::Wait(ctx_main);
finish();
});
RenderPath2D::Start();
}
void LoadingScreen::Stop()
{
loaders.clear();
tasks.clear();
finish = nullptr;
RenderPath2D::Stop();
+4 -24
View File
@@ -1,10 +1,9 @@
#pragma once
#include "RenderPath2D.h"
#include "wiColor.h"
#include "wiJobSystem.h"
#include <thread>
#include <functional>
#include <atomic>
class MainComponent;
@@ -12,30 +11,11 @@ class LoadingScreen :
public RenderPath2D
{
private:
struct LoaderTask
{
std::function<void()> functionBody;
std::atomic_bool active;
LoaderTask(std::function<void()> functionBody) :functionBody(functionBody)
{
active.store(false);
}
LoaderTask(const LoaderTask& l)
{
functionBody = l.functionBody;
active.store(l.active.load());
}
};
std::vector<LoaderTask> loaders;
void doLoadingTasks();
void waitForFinish();
wiJobSystem::context ctx_main;
wiJobSystem::context ctx_finish;
std::vector<std::function<void()>> tasks;
std::function<void()> finish;
std::thread worker;
public:
LoadingScreen();
virtual ~LoadingScreen();
//Add a loading task which should be executed
//use std::bind( YourFunctionPointer )
+16 -15
View File
@@ -9,11 +9,12 @@ using namespace std;
namespace wiInitializer
{
bool initializationStarted = false;
wiJobSystem::context ctx;
void InitializeComponentsImmediate()
{
InitializeComponentsAsync();
wiJobSystem::Wait();
wiJobSystem::Wait(ctx);
}
void InitializeComponentsAsync()
{
@@ -23,24 +24,24 @@ namespace wiInitializer
wiJobSystem::Initialize();
wiJobSystem::Execute([] { wiFont::Initialize(); });
wiJobSystem::Execute([] { wiImage::Initialize(); });
wiJobSystem::Execute([] { wiInputManager::Initialize(); });
wiJobSystem::Execute([] { wiRenderer::Initialize(); wiWidget::LoadShaders(); });
wiJobSystem::Execute([] { wiSoundEffect::Initialize(); wiMusic::Initialize(); });
wiJobSystem::Execute([] { wiTextureHelper::Initialize(); });
wiJobSystem::Execute([] { wiSceneSystem::wiHairParticle::Initialize(); });
wiJobSystem::Execute([] { wiSceneSystem::wiEmittedParticle::Initialize(); });
wiJobSystem::Execute([] { wiLensFlare::Initialize(); });
wiJobSystem::Execute([] { wiOcean::Initialize(); });
wiJobSystem::Execute([] { wiGPUSortLib::LoadShaders(); });
wiJobSystem::Execute([] { wiGPUBVH::LoadShaders(); });
wiJobSystem::Execute([] { wiPhysicsEngine::Initialize(); });
wiJobSystem::Execute(ctx, [] { wiFont::Initialize(); });
wiJobSystem::Execute(ctx, [] { wiImage::Initialize(); });
wiJobSystem::Execute(ctx, [] { wiInputManager::Initialize(); });
wiJobSystem::Execute(ctx, [] { wiRenderer::Initialize(); wiWidget::LoadShaders(); });
wiJobSystem::Execute(ctx, [] { wiSoundEffect::Initialize(); wiMusic::Initialize(); });
wiJobSystem::Execute(ctx, [] { wiTextureHelper::Initialize(); });
wiJobSystem::Execute(ctx, [] { wiSceneSystem::wiHairParticle::Initialize(); });
wiJobSystem::Execute(ctx, [] { wiSceneSystem::wiEmittedParticle::Initialize(); });
wiJobSystem::Execute(ctx, [] { wiLensFlare::Initialize(); });
wiJobSystem::Execute(ctx, [] { wiOcean::Initialize(); });
wiJobSystem::Execute(ctx, [] { wiGPUSortLib::LoadShaders(); });
wiJobSystem::Execute(ctx, [] { wiGPUBVH::LoadShaders(); });
wiJobSystem::Execute(ctx, [] { wiPhysicsEngine::Initialize(); });
}
bool IsInitializeFinished()
{
return initializationStarted && !wiJobSystem::IsBusy();
return initializationStarted && !wiJobSystem::IsBusy(ctx);
}
}
+44 -39
View File
@@ -3,31 +3,44 @@
#include "wiBackLog.h"
#include "wiContainers.h"
#include <atomic>
#include <thread>
#include <condition_variable>
#include <deque>
#include <sstream>
#include <algorithm>
namespace wiJobSystem
{
struct Job
{
std::function<void()> task;
context* ctx;
};
uint32_t numThreads = 0;
wiContainers::ThreadSafeRingBuffer<std::function<void()>, 256> jobPool;
wiContainers::ThreadSafeRingBuffer<Job, 256> jobPool;
std::condition_variable wakeCondition;
std::mutex wakeMutex;
uint64_t currentLabel = 0;
std::atomic<uint64_t> finishedLabel;
// This function executes the next item from the job queue. Returns true if successful, false if there was no job available
inline bool work()
{
Job job;
if (jobPool.pop_front(job))
{
job.task(); // execute job
job.ctx->counter.fetch_sub(1);
return true;
}
return false;
}
void Initialize()
{
finishedLabel.store(0);
// Retrieve the number of hardware threads in this system:
auto numCores = std::thread::hardware_concurrency();
// Calculate the actual number of worker threads we want:
numThreads = std::max(1u, numCores);
// Calculate the actual number of worker threads we want (-1 main thread):
numThreads = std::max(1u, numCores - 1);
for (uint32_t threadID = 0; threadID < numThreads; ++threadID)
{
@@ -37,12 +50,7 @@ namespace wiJobSystem
while (true)
{
if (jobPool.pop_front(job))
{
job(); // execute job
finishedLabel.fetch_add(1); // update worker label state
}
else
if (!work())
{
// no job, put thread to sleep
std::unique_lock<std::mutex> lock(wakeMutex);
@@ -80,30 +88,24 @@ namespace wiJobSystem
wiBackLog::post(ss.str().c_str());
}
// This little function will not let the system to be deadlocked while the main thread is waiting for something
inline void poll()
{
wakeCondition.notify_one(); // wake one worker thread
std::this_thread::yield(); // allow this thread to be rescheduled
}
uint32_t GetThreadCount()
{
return numThreads;
}
void Execute(const std::function<void()>& job)
void Execute(context& ctx, const std::function<void()>& job)
{
// The main thread label state is updated:
currentLabel += 1;
// Context state is updated:
ctx.counter.fetch_add(1);
// Try to push a new job until it is pushed successfully:
while (!jobPool.push_back(job)) { poll(); }
while (!jobPool.push_back({ job, &ctx })) { wakeCondition.notify_all(); }
wakeCondition.notify_one(); // wake one thread
// Wake any one thread that might be sleeping:
wakeCondition.notify_one();
}
void Dispatch(uint32_t jobCount, uint32_t groupSize, const std::function<void(wiJobDispatchArgs)>& job)
void Dispatch(context& ctx, uint32_t jobCount, uint32_t groupSize, const std::function<void(wiJobDispatchArgs)>& job)
{
if (jobCount == 0 || groupSize == 0)
{
@@ -113,8 +115,8 @@ namespace wiJobSystem
// Calculate the amount of job groups to dispatch (overestimate, or "ceil"):
const uint32_t groupCount = (jobCount + groupSize - 1) / groupSize;
// The main thread label state is updated:
currentLabel += groupCount;
// Context state is updated:
ctx.counter.fetch_add(groupCount);
for (uint32_t groupIndex = 0; groupIndex < groupCount; ++groupIndex)
{
@@ -137,22 +139,25 @@ namespace wiJobSystem
};
// Try to push a new job until it is pushed successfully:
while (!jobPool.push_back(jobGroup)) { poll(); }
wakeCondition.notify_one(); // wake one thread
while (!jobPool.push_back({ jobGroup, &ctx })) { wakeCondition.notify_all(); }
}
// Wake any threads that might be sleeping:
wakeCondition.notify_all();
}
bool IsBusy()
bool IsBusy(const context& ctx)
{
// Whenever the main thread label is not reached by the workers, it indicates that some worker is still alive
return finishedLabel.load() < currentLabel;
// Whenever the context label is greater than zero, it means that there is still work that needs to be done
return ctx.counter.load() > 0;
}
void Wait()
void Wait(const context& ctx)
{
while (IsBusy()) { poll(); }
// Wake any threads that might be sleeping:
wakeCondition.notify_all();
// Waiting will also put the current thread to good use by working on an other job if it can:
while (IsBusy(ctx)) { work(); }
}
}
+11 -4
View File
@@ -1,6 +1,7 @@
#pragma once
#include <functional>
#include <atomic>
struct wiJobDispatchArgs
{
@@ -14,18 +15,24 @@ namespace wiJobSystem
uint32_t GetThreadCount();
// Defines a state of execution, can be waited on
struct context
{
std::atomic<uint32_t> counter = 0;
};
// Add a job to execute asynchronously. Any idle thread will execute this job.
void Execute(const std::function<void()>& job);
void Execute(context& ctx, const std::function<void()>& job);
// Divide a job 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(uint32_t jobCount, uint32_t groupSize, const std::function<void(wiJobDispatchArgs)>& job);
void Dispatch(context& ctx, uint32_t jobCount, uint32_t groupSize, const std::function<void(wiJobDispatchArgs)>& job);
// Check if any threads are working currently or not
bool IsBusy();
bool IsBusy(const context& ctx);
// Wait until all threads become idle
void Wait();
void Wait(const context& ctx);
}
+2
View File
@@ -1,6 +1,7 @@
#pragma once
#include "wiECS.h"
#include "wiSceneSystem_Decl.h"
#include "wiJobSystem.h"
namespace wiPhysicsEngine
{
@@ -11,6 +12,7 @@ namespace wiPhysicsEngine
void SetEnabled(bool value);
void RunPhysicsUpdateSystem(
wiJobSystem::context& ctx,
const wiSceneSystem::WeatherComponent& weather,
const wiECS::ComponentManager<wiSceneSystem::ArmatureComponent>& armatures,
wiECS::ComponentManager<wiSceneSystem::TransformComponent>& transforms,
+4 -3
View File
@@ -298,6 +298,7 @@ namespace wiPhysicsEngine
}
void RunPhysicsUpdateSystem(
wiJobSystem::context& ctx,
const WeatherComponent& weather,
const ComponentManager<ArmatureComponent>& armatures,
ComponentManager<TransformComponent>& transforms,
@@ -318,7 +319,7 @@ namespace wiPhysicsEngine
btVector3 wind = btVector3(weather.windDirection.x, weather.windDirection.y, weather.windDirection.z);
// System will register rigidbodies to objects, and update physics engine state for kinematics:
wiJobSystem::Dispatch((uint32_t)rigidbodies.GetCount(), 256, [&](wiJobDispatchArgs args) {
wiJobSystem::Dispatch(ctx, (uint32_t)rigidbodies.GetCount(), 256, [&](wiJobDispatchArgs args) {
RigidBodyPhysicsComponent& physicscomponent = rigidbodies[args.jobIndex];
Entity entity = rigidbodies.GetEntity(args.jobIndex);
@@ -368,7 +369,7 @@ namespace wiPhysicsEngine
});
// System will register softbodies to meshes and update physics engine state:
wiJobSystem::Dispatch((uint32_t)softbodies.GetCount(), 1, [&](wiJobDispatchArgs args) {
wiJobSystem::Dispatch(ctx, (uint32_t)softbodies.GetCount(), 1, [&](wiJobDispatchArgs args) {
SoftBodyPhysicsComponent& physicscomponent = softbodies[args.jobIndex];
Entity entity = softbodies.GetEntity(args.jobIndex);
@@ -411,7 +412,7 @@ namespace wiPhysicsEngine
}
});
wiJobSystem::Wait();
wiJobSystem::Wait(ctx);
// Perform internal simulation step:
dynamicsWorld->stepSimulation(dt, 10);
File diff suppressed because it is too large Load Diff
+55 -36
View File
@@ -996,46 +996,47 @@ namespace wiSceneSystem
UpdateCamera();
}
void Scene::Update(float dt)
{
RunPreviousFrameTransformUpdateSystem(transforms, prev_transforms);
wiJobSystem::context ctx;
RunAnimationUpdateSystem(animations, transforms, dt);
RunPreviousFrameTransformUpdateSystem(ctx, transforms, prev_transforms);
wiPhysicsEngine::RunPhysicsUpdateSystem(weather, armatures, transforms, meshes, objects, rigidbodies, softbodies, dt);
RunAnimationUpdateSystem(ctx, animations, transforms, dt);
RunTransformUpdateSystem(transforms);
wiPhysicsEngine::RunPhysicsUpdateSystem(ctx, weather, armatures, transforms, meshes, objects, rigidbodies, softbodies, dt);
wiJobSystem::Wait(); // dependecies
RunTransformUpdateSystem(ctx, transforms);
RunHierarchyUpdateSystem(hierarchy, transforms, layers);
wiJobSystem::Wait(ctx); // dependecies
RunArmatureUpdateSystem(transforms, armatures);
RunHierarchyUpdateSystem(ctx, hierarchy, transforms, layers);
RunMaterialUpdateSystem(materials, dt);
RunArmatureUpdateSystem(ctx, transforms, armatures);
RunImpostorUpdateSystem(impostors);
RunMaterialUpdateSystem(ctx, materials, dt);
wiJobSystem::Wait(); // dependecies
RunImpostorUpdateSystem(ctx, impostors);
RunObjectUpdateSystem(prev_transforms, transforms, meshes, materials, objects, aabb_objects, impostors, softbodies, bounds, waterPlane);
wiJobSystem::Wait(ctx); // dependecies
RunCameraUpdateSystem(transforms, cameras);
RunObjectUpdateSystem(ctx, prev_transforms, transforms, meshes, materials, objects, aabb_objects, impostors, softbodies, bounds, waterPlane);
RunDecalUpdateSystem(transforms, materials, aabb_decals, decals);
RunCameraUpdateSystem(ctx, transforms, cameras);
RunProbeUpdateSystem(transforms, aabb_probes, probes);
RunDecalUpdateSystem(ctx, transforms, materials, aabb_decals, decals);
RunForceUpdateSystem(transforms, forces);
RunProbeUpdateSystem(ctx, transforms, aabb_probes, probes);
RunLightUpdateSystem(transforms, aabb_lights, lights);
RunForceUpdateSystem(ctx, transforms, forces);
RunParticleUpdateSystem(transforms, meshes, emitters, hairs, dt);
RunLightUpdateSystem(ctx, transforms, aabb_lights, lights);
wiJobSystem::Wait(); // dependecies
RunParticleUpdateSystem(ctx, transforms, meshes, emitters, hairs, dt);
RunWeatherUpdateSystem(weathers, lights, weather);
wiJobSystem::Wait(ctx); // dependecies
RunWeatherUpdateSystem(ctx, weathers, lights, weather);
}
void Scene::Clear()
{
@@ -1481,11 +1482,12 @@ namespace wiSceneSystem
const uint32_t small_subtask_groupsize = 1024;
void RunPreviousFrameTransformUpdateSystem(
wiJobSystem::context& ctx,
const ComponentManager<TransformComponent>& transforms,
ComponentManager<PreviousFrameTransformComponent>& prev_transforms
)
{
wiJobSystem::Dispatch((uint32_t)prev_transforms.GetCount(), small_subtask_groupsize, [&](wiJobDispatchArgs args) {
wiJobSystem::Dispatch(ctx, (uint32_t)prev_transforms.GetCount(), small_subtask_groupsize, [&](wiJobDispatchArgs args) {
PreviousFrameTransformComponent& prev_transform = prev_transforms[args.jobIndex];
Entity entity = prev_transforms.GetEntity(args.jobIndex);
@@ -1495,6 +1497,7 @@ namespace wiSceneSystem
});
}
void RunAnimationUpdateSystem(
wiJobSystem::context& ctx,
ComponentManager<AnimationComponent>& animations,
ComponentManager<TransformComponent>& transforms,
float dt
@@ -1617,15 +1620,18 @@ namespace wiSceneSystem
}
}
}
void RunTransformUpdateSystem(ComponentManager<TransformComponent>& transforms)
void RunTransformUpdateSystem(
wiJobSystem::context& ctx,
ComponentManager<TransformComponent>& transforms)
{
wiJobSystem::Dispatch((uint32_t)transforms.GetCount(), small_subtask_groupsize, [&](wiJobDispatchArgs args) {
wiJobSystem::Dispatch(ctx, (uint32_t)transforms.GetCount(), small_subtask_groupsize, [&](wiJobDispatchArgs args) {
TransformComponent& transform = transforms[args.jobIndex];
transform.UpdateTransform();
});
}
void RunHierarchyUpdateSystem(
wiJobSystem::context& ctx,
const ComponentManager<HierarchyComponent>& hierarchy,
ComponentManager<TransformComponent>& transforms,
ComponentManager<LayerComponent>& layers
@@ -1656,11 +1662,12 @@ namespace wiSceneSystem
}
}
void RunArmatureUpdateSystem(
wiJobSystem::context& ctx,
const ComponentManager<TransformComponent>& transforms,
ComponentManager<ArmatureComponent>& armatures
)
{
wiJobSystem::Dispatch((uint32_t)armatures.GetCount(), 1, [&](wiJobDispatchArgs args) {
wiJobSystem::Dispatch(ctx, (uint32_t)armatures.GetCount(), 1, [&](wiJobDispatchArgs args) {
ArmatureComponent& armature = armatures[args.jobIndex];
Entity entity = armatures.GetEntity(args.jobIndex);
@@ -1697,9 +1704,11 @@ namespace wiSceneSystem
});
}
void RunMaterialUpdateSystem(ComponentManager<MaterialComponent>& materials, float dt)
void RunMaterialUpdateSystem(
wiJobSystem::context& ctx,
ComponentManager<MaterialComponent>& materials, float dt)
{
wiJobSystem::Dispatch((uint32_t)materials.GetCount(), small_subtask_groupsize, [&](wiJobDispatchArgs args) {
wiJobSystem::Dispatch(ctx, (uint32_t)materials.GetCount(), small_subtask_groupsize, [&](wiJobDispatchArgs args) {
MaterialComponent& material = materials[args.jobIndex];
@@ -1720,9 +1729,11 @@ namespace wiSceneSystem
}
});
}
void RunImpostorUpdateSystem(ComponentManager<ImpostorComponent>& impostors)
void RunImpostorUpdateSystem(
wiJobSystem::context& ctx,
ComponentManager<ImpostorComponent>& impostors)
{
wiJobSystem::Dispatch((uint32_t)impostors.GetCount(), 1, [&](wiJobDispatchArgs args) {
wiJobSystem::Dispatch(ctx, (uint32_t)impostors.GetCount(), 1, [&](wiJobDispatchArgs args) {
ImpostorComponent& impostor = impostors[args.jobIndex];
impostor.aabb = AABB();
@@ -1730,6 +1741,7 @@ namespace wiSceneSystem
});
}
void RunObjectUpdateSystem(
wiJobSystem::context& ctx,
const ComponentManager<PreviousFrameTransformComponent>& prev_transforms,
const ComponentManager<TransformComponent>& transforms,
const ComponentManager<MeshComponent>& meshes,
@@ -1747,7 +1759,7 @@ namespace wiSceneSystem
sceneBounds = AABB();
// Instead of Dispatching, this will be one big job, because there is contention for several resources (sceneBounds, waterPlane, impostors)
wiJobSystem::Execute([&] {
wiJobSystem::Execute(ctx, [&] {
for (size_t i = 0; i < objects.GetCount(); ++i)
{
@@ -1868,11 +1880,12 @@ namespace wiSceneSystem
});
}
void RunCameraUpdateSystem(
wiJobSystem::context& ctx,
const ComponentManager<TransformComponent>& transforms,
ComponentManager<CameraComponent>& cameras
)
{
wiJobSystem::Dispatch((uint32_t)cameras.GetCount(), small_subtask_groupsize, [&](wiJobDispatchArgs args) {
wiJobSystem::Dispatch(ctx, (uint32_t)cameras.GetCount(), small_subtask_groupsize, [&](wiJobDispatchArgs args) {
CameraComponent& camera = cameras[args.jobIndex];
Entity entity = cameras.GetEntity(args.jobIndex);
@@ -1885,6 +1898,7 @@ namespace wiSceneSystem
});
}
void RunDecalUpdateSystem(
wiJobSystem::context& ctx,
const ComponentManager<TransformComponent>& transforms,
const ComponentManager<MaterialComponent>& materials,
ComponentManager<AABB>& aabb_decals,
@@ -1893,7 +1907,7 @@ namespace wiSceneSystem
{
assert(decals.GetCount() == aabb_decals.GetCount());
wiJobSystem::Dispatch((uint32_t)decals.GetCount(), small_subtask_groupsize, [&](wiJobDispatchArgs args) {
wiJobSystem::Dispatch(ctx, (uint32_t)decals.GetCount(), small_subtask_groupsize, [&](wiJobDispatchArgs args) {
DecalComponent& decal = decals[args.jobIndex];
Entity entity = decals.GetEntity(args.jobIndex);
@@ -1924,6 +1938,7 @@ namespace wiSceneSystem
});
}
void RunProbeUpdateSystem(
wiJobSystem::context& ctx,
const ComponentManager<TransformComponent>& transforms,
ComponentManager<AABB>& aabb_probes,
ComponentManager<EnvironmentProbeComponent>& probes
@@ -1931,7 +1946,7 @@ namespace wiSceneSystem
{
assert(probes.GetCount() == aabb_probes.GetCount());
wiJobSystem::Dispatch((uint32_t)probes.GetCount(), small_subtask_groupsize, [&](wiJobDispatchArgs args) {
wiJobSystem::Dispatch(ctx, (uint32_t)probes.GetCount(), small_subtask_groupsize, [&](wiJobDispatchArgs args) {
EnvironmentProbeComponent& probe = probes[args.jobIndex];
Entity entity = probes.GetEntity(args.jobIndex);
@@ -1954,11 +1969,12 @@ namespace wiSceneSystem
});
}
void RunForceUpdateSystem(
wiJobSystem::context& ctx,
const ComponentManager<TransformComponent>& transforms,
ComponentManager<ForceFieldComponent>& forces
)
{
wiJobSystem::Dispatch((uint32_t)forces.GetCount(), small_subtask_groupsize, [&](wiJobDispatchArgs args) {
wiJobSystem::Dispatch(ctx, (uint32_t)forces.GetCount(), small_subtask_groupsize, [&](wiJobDispatchArgs args) {
ForceFieldComponent& force = forces[args.jobIndex];
Entity entity = forces.GetEntity(args.jobIndex);
@@ -1975,6 +1991,7 @@ namespace wiSceneSystem
});
}
void RunLightUpdateSystem(
wiJobSystem::context& ctx,
const ComponentManager<TransformComponent>& transforms,
ComponentManager<AABB>& aabb_lights,
ComponentManager<LightComponent>& lights
@@ -1982,7 +1999,7 @@ namespace wiSceneSystem
{
assert(lights.GetCount() == aabb_lights.GetCount());
wiJobSystem::Dispatch((uint32_t)lights.GetCount(), small_subtask_groupsize, [&](wiJobDispatchArgs args) {
wiJobSystem::Dispatch(ctx, (uint32_t)lights.GetCount(), small_subtask_groupsize, [&](wiJobDispatchArgs args) {
LightComponent& light = lights[args.jobIndex];
Entity entity = lights.GetEntity(args.jobIndex);
@@ -2025,6 +2042,7 @@ namespace wiSceneSystem
});
}
void RunParticleUpdateSystem(
wiJobSystem::context& ctx,
const ComponentManager<TransformComponent>& transforms,
const ComponentManager<MeshComponent>& meshes,
ComponentManager<wiEmittedParticle>& emitters,
@@ -2032,7 +2050,7 @@ namespace wiSceneSystem
float dt
)
{
wiJobSystem::Dispatch((uint32_t)emitters.GetCount(), small_subtask_groupsize, [&](wiJobDispatchArgs args) {
wiJobSystem::Dispatch(ctx, (uint32_t)emitters.GetCount(), small_subtask_groupsize, [&](wiJobDispatchArgs args) {
wiEmittedParticle& emitter = emitters[args.jobIndex];
Entity entity = emitters.GetEntity(args.jobIndex);
@@ -2040,7 +2058,7 @@ namespace wiSceneSystem
emitter.UpdateCPU(transform, dt);
});
wiJobSystem::Dispatch((uint32_t)hairs.GetCount(), small_subtask_groupsize, [&](wiJobDispatchArgs args) {
wiJobSystem::Dispatch(ctx, (uint32_t)hairs.GetCount(), small_subtask_groupsize, [&](wiJobDispatchArgs args) {
wiHairParticle& hair = hairs[args.jobIndex];
Entity entity = hairs.GetEntity(args.jobIndex);
@@ -2059,6 +2077,7 @@ namespace wiSceneSystem
});
}
void RunWeatherUpdateSystem(
wiJobSystem::context& ctx,
const ComponentManager<WeatherComponent>& weathers,
const ComponentManager<LightComponent>& lights,
WeatherComponent& weather)
+25 -3
View File
@@ -5,6 +5,7 @@
#include "wiEmittedParticle.h"
#include "wiHairParticle.h"
#include "ShaderInterop_Renderer.h"
#include "wiJobSystem.h"
#include "wiECS.h"
#include "wiSceneSystem_Decl.h"
@@ -1058,27 +1059,41 @@ namespace wiSceneSystem
};
void RunPreviousFrameTransformUpdateSystem(
wiJobSystem::context& ctx,
const wiECS::ComponentManager<TransformComponent>& transforms,
wiECS::ComponentManager<PreviousFrameTransformComponent>& prev_transforms
);
void RunAnimationUpdateSystem(
wiJobSystem::context& ctx,
wiECS::ComponentManager<AnimationComponent>& animations,
wiECS::ComponentManager<TransformComponent>& transforms,
float dt
);
void RunTransformUpdateSystem(wiECS::ComponentManager<TransformComponent>& transforms);
void RunTransformUpdateSystem(
wiJobSystem::context& ctx,
wiECS::ComponentManager<TransformComponent>& transforms
);
void RunHierarchyUpdateSystem(
wiJobSystem::context& ctx,
const wiECS::ComponentManager<HierarchyComponent>& hierarchy,
wiECS::ComponentManager<TransformComponent>& transforms,
wiECS::ComponentManager<LayerComponent>& layers
);
void RunArmatureUpdateSystem(
wiJobSystem::context& ctx,
const wiECS::ComponentManager<TransformComponent>& transforms,
wiECS::ComponentManager<ArmatureComponent>& armatures
);
void RunMaterialUpdateSystem(wiECS::ComponentManager<MaterialComponent>& materials, float dt);
void RunImpostorUpdateSystem(wiECS::ComponentManager<ImpostorComponent>& impostors);
void RunMaterialUpdateSystem(
wiJobSystem::context& ctx,
wiECS::ComponentManager<MaterialComponent>& materials, float dt
);
void RunImpostorUpdateSystem(
wiJobSystem::context& ctx,
wiECS::ComponentManager<ImpostorComponent>& impostors
);
void RunObjectUpdateSystem(
wiJobSystem::context& ctx,
const wiECS::ComponentManager<PreviousFrameTransformComponent>& prev_transforms,
const wiECS::ComponentManager<TransformComponent>& transforms,
const wiECS::ComponentManager<MeshComponent>& meshes,
@@ -1091,30 +1106,36 @@ namespace wiSceneSystem
XMFLOAT4& waterPlane
);
void RunCameraUpdateSystem(
wiJobSystem::context& ctx,
const wiECS::ComponentManager<TransformComponent>& transforms,
wiECS::ComponentManager<CameraComponent>& cameras
);
void RunDecalUpdateSystem(
wiJobSystem::context& ctx,
const wiECS::ComponentManager<TransformComponent>& transforms,
const wiECS::ComponentManager<MaterialComponent>& materials,
wiECS::ComponentManager<AABB>& aabb_decals,
wiECS::ComponentManager<DecalComponent>& decals
);
void RunProbeUpdateSystem(
wiJobSystem::context& ctx,
const wiECS::ComponentManager<TransformComponent>& transforms,
wiECS::ComponentManager<AABB>& aabb_probes,
wiECS::ComponentManager<EnvironmentProbeComponent>& probes
);
void RunForceUpdateSystem(
wiJobSystem::context& ctx,
const wiECS::ComponentManager<TransformComponent>& transforms,
wiECS::ComponentManager<ForceFieldComponent>& forces
);
void RunLightUpdateSystem(
wiJobSystem::context& ctx,
const wiECS::ComponentManager<TransformComponent>& transforms,
wiECS::ComponentManager<AABB>& aabb_lights,
wiECS::ComponentManager<LightComponent>& lights
);
void RunParticleUpdateSystem(
wiJobSystem::context& ctx,
const wiECS::ComponentManager<TransformComponent>& transforms,
const wiECS::ComponentManager<MeshComponent>& meshes,
wiECS::ComponentManager<wiEmittedParticle>& emitters,
@@ -1122,6 +1143,7 @@ namespace wiSceneSystem
float dt
);
void RunWeatherUpdateSystem(
wiJobSystem::context& ctx,
const wiECS::ComponentManager<WeatherComponent>& weathers,
const wiECS::ComponentManager<LightComponent>& lights,
WeatherComponent& weather
+1 -1
View File
@@ -9,7 +9,7 @@ namespace wiVersion
// minor features, major updates
const int minor = 26;
// minor bug fixes, alterations, refactors, updates
const int revision = 40;
const int revision = 41;
long GetVersion()