Skip to content

v1.8 Dependencies

Compare
Choose a tag to compare
@dougbinks dougbinks released this 02 Mar 16:07
· 132 commits to master since this release

NOTE: Breaking changes to C API

This release of enkiTS adds a major feature - Dependencies, and a minor feature - Completion Actions.

Dependencies introduce an alternative approach to waiting on tasks to create a sequence of tasks, or task graph. See example below along with links.

Completion Actions are dependencies which execute immediatly after a task has completed, and do not add themselves to the task scheduler. They involve less overhead than a normal task, and can be used to delete the completed task as well as themselves as they are not referenced after their completion function is called. See example/CompletionAction.cpp and example/CompletionAction_c.c .

The following breaking changes to the C API were required:

  1. enkiDelete* functions now require the task scheduler as a parameter.
  2. enkiAddTaskSet replaced with enkiAddTaskSetArgs so that enkiAddTaskSet can be used for a new function which does not set task arguments, intended for use along with the new enkiSetParams* functions.

Dependency usage in C++:

#include "TaskScheduler.h"

enki::TaskScheduler g_TS;

// define a task set, can ignore range if we only do one thing
struct TaskA : enki::ITaskSet {
    void ExecuteRange(  enki::TaskSetPartition range_, uint32_t threadnum_ ) override {
        // do something here, can issue tasks with g_TS
    }
};

struct TaskB : enki::ITaskSet {
    enki::Dependency m_Dependency;
    void ExecuteRange(  enki::TaskSetPartition range_, uint32_t threadnum_ ) override {
        // do something here, can issue tasks with g_TS
    }
};

int main(int argc, const char * argv[]) {
    g_TS.Initialize();
    
    // set dependencies once (can set more than one if needed).
    TaskA taskA;
    TaskB taskB;
    taskB.SetDependency( taskB.m_Dependency, &taskA );

    g_TS.AddTaskSetToPipe( &taskA ); // add first task, when complete TaskB will run
    g_TS.WaitforTask( &taskB );      // wait for last
    return 0;
}