Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
   Copyright (c) 2016 DIVIDE-Studio
   Copyright (c) 2009 Ionut Cava

   This file is part of DIVIDE Framework.

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software
   and associated documentation files (the "Software"), to deal in the Software
   without restriction,
   including without limitation the rights to use, copy, modify, merge, publish,
   distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so,
   subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED,
   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
   PARTICULAR PURPOSE AND NONINFRINGEMENT.
   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
   DAMAGES OR OTHER LIABILITY,
   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
   IN CONNECTION WITH THE SOFTWARE
   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 */

#ifndef _TASKS_H_
#define _TASKS_H_

#include "Platform/Threading/Headers/Thread.h"
#include "Platform/Headers/PlatformDefines.h"

namespace Divide {

class Application;
class TaskPool;
/**
 *@brief Using std::atomic for thread-shared data to avoid locking
 */
class Task : public GUIDWrapper, private NonCopyable {
   public:
       static constexpr U16 MAX_CHILD_TASKS = to_const_ushort(std::numeric_limits<I8>::max());

       enum class TaskPriority : U32 {
           DONT_CARE = 0,
           LOW = 1,
           MEDIUM = 2,
           HIGH = 3,
           MAX = 4,
           REALTIME = 5, //<= not threaded
           REALTIME_WITH_CALLBACK = 6, //<= not threaded
           COUNT
       };

      enum class TaskFlags : U32 {
        SYNC_WITH_GPU = toBit(1),
        PRINT_DEBUG_INFO = toBit(2),
        COUNT = 2,
      };

    /**
     * @brief Creates a new Task that runs in a separate thread
     * @param f The callback function (bool param will be true if the task receives a stop request)
     */
    explicit Task();
    ~Task();

    void startTask(TaskPriority priority = TaskPriority::DONT_CARE,
                   U32 taskFlags = 0);

    void stopTask();

    void reset();

    inline void setOwningPool(TaskPool& pool, U32 poolIndex) {
        _tp = &pool;
        _poolIndex = poolIndex;
    }

    inline TaskPool& getOwningPool() {
        assert(_tp != nullptr);
        return *_tp;
    }

    inline bool isRunning() const {
        return !_done;
    }

    inline I64 jobIdentifier() const {
        return _jobIdentifier;
    }

    inline U32 poolIndex() const {
        return _poolIndex;
    }

    inline bool stopRequested() const {
        return _stopRequested;
    }

    inline void threadedCallback(const DELEGATE_CBK_PARAM<const Task&>& cbk, I64 jobIdentifier) {
        _callback = cbk;
        _jobIdentifier = jobIdentifier;
    }

    void addChildTask(Task* task);

    void wait();

   protected:
    void run();
    void runTaskWithGPUSync();
    void runTaskWithDebugInfo();
    void runTaskWithGPUSyncAndDebugInfo();

    PoolTask getRunTask(TaskPriority priority, U32 taskFlags);

    void beginSyncGPU();
    void endSyncGPU();

   private:
    const Application& _application;

    mutable std::mutex _taskDoneMutex;
    std::condition_variable _taskDoneCV;
    std::atomic_bool _done;

    I64 _jobIdentifier;

    std::atomic_bool _stopRequested;

    DELEGATE_CBK_PARAM<const Task&> _callback;
    
    TaskPriority _priority;
    TaskPool* _tp;
    U32 _poolIndex;

    Task* _parentTask;
    std::array<Task*, MAX_CHILD_TASKS> _childTasks;
    std::atomic_short _childTaskCount;
};

// A task object may be used for multiple jobs
struct TaskHandle {
    explicit TaskHandle(Task* task, I64 id) 
        : _task(task),
          _jobIdentifier(id)
    {
    }

    inline void startTask(Task::TaskPriority prio = Task::TaskPriority::DONT_CARE,
                          U32 taskFlags = 0) {
        assert(_task != nullptr);
        _task->startTask(prio, taskFlags);
    }

    inline Task* addChildTask(Task* task) {
        assert(_task != nullptr);
        _task->addChildTask(task);
        return task;
    }

    inline void wait() {
        if (_task != nullptr) {
            _task->wait();
        }
    }

    Task* _task;
    I64 _jobIdentifier;
};


};  // namespace Divide

#endif

Commits for Divide-Framework/trunk/Source Code/Platform/Threading/Headers/Task.h

Diff revisions: vs.
Revision Author Commited Message
827 Diff Diff IonutCava picture IonutCava Sun 22 Jan, 2017 21:59:36 +0000

[IonutCava]
- ShaderBuffers now decide heuristically if they get persistently mapped or not (depends on size. Current limit is 512Kb for subData calls.
- Separate visible node command generation into 2 steps: onRender and getDrawPackage. onRender allows the creation of parallel tasks that should finish by the time the second call, getDrawPackage reaches the same node
- Update ParticleEmitter to take into account multiple players and increase parallelism at the cost of memory consumption and complexity.
- Add a default bounding box for Players (add extents to SceneTransform nodes)
- All buffers (ShaderBuffer, d3dConstantBuffer, glUniformBuffer, glBufferImpl, glGenericBuffer, etc) use BufferParams for creation.
— Constructor and create calls have been merged together

819 Diff Diff IonutCava picture IonutCava Mon 16 Jan, 2017 21:30:53 +0000

[IonutCava]
- More threading updates to the LightPool class

811 Diff Diff IonutCava picture IonutCava Wed 11 Jan, 2017 17:26:49 +0000

[IonutCava]
- Fix some threadpool cleanup bugs
- Fix terrain rendering (except underwater caustics)
- Fix terrain loading
- Fix terrain unloading

806 Diff Diff IonutCava picture IonutCava Sun 08 Jan, 2017 22:00:48 +0000

[IonutCava]
- Finish implementing per-fragment velocity computation using a compute shader
— Further tuning still needed
- Add VS2017 build targets

801 Diff Diff IonutCava picture IonutCava Sun 27 Nov, 2016 21:28:01 +0000

[IonutCava]
- More performance analysis guided optimizations.
- Some refactoring to allow later removal of Singletons status for: GFXDevice, SFXDevice, PXDevice, GUI and Input.
— Pass a PlatformContext around objects to access these classes.

799 Diff Diff IonutCava picture IonutCava Thu 24 Nov, 2016 22:55:23 +0000

[IonutCava]
- Performance analysis guided optimizations.

740 Diff Diff IonutCava picture IonutCava Sat 25 Jun, 2016 17:09:50 +0000

[IonutCava]
- More scene changing related fixes
- GUIDWrapper is now a core feature instead of a utility

719 Diff Diff IonutCava picture IonutCava Fri 03 Jun, 2016 16:20:08 +0000

[IonutCava]
- More SceneManager – ScenePool splitting of responsibilities
- DefaultScene will be the first scene loaded by the application. If nothing is specified in XML, it will default to "DefaultScene"

716 Diff Diff IonutCava picture IonutCava Tue 31 May, 2016 16:08:29 +0000

[IonutCava]
- Multithreaded scene load/unload fixes:
— Added postLoadMainThread call for scenes for thread sensitive loading steps
— GUI element adding is a thread sensitive loading step (a fast one) because CEGUI doesn’t handle threading
- Added REALTIME_WITH_CALLBACK task priority for tasks that need an immediate callback when they complete instead of using the flushCallbackQueue system.
- Some work on shadow mapping for getting it to work again
- ShaderPrograms that fail to load can cause a LockManager infinite wait. Delete the lockManager if the shader didn’t load to avoid waiting on commands that never get called.

714 IonutCava picture IonutCava Thu 26 May, 2016 16:26:23 +0000

[IonutCava]
- Initial code for multithreaded scene load:
— Tasks can have a “sync with gpu” flag that will cause them to use a shared context (so they can call GL functions)
- Added per scene GUI lists that get passed to the main GUI class (still need a base class to hold the map and accessors to avoid code duplication)
- Re-enabled threading unit tests