clover: Fix up NULL constant pointer arguments.
[mesa.git] / src / gallium / state_trackers / clover / core / event.hpp
1 //
2 // Copyright 2012 Francisco Jerez
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 // OTHER DEALINGS IN THE SOFTWARE.
21 //
22
23 #ifndef CLOVER_CORE_EVENT_HPP
24 #define CLOVER_CORE_EVENT_HPP
25
26 #include <functional>
27
28 #include "core/object.hpp"
29 #include "core/queue.hpp"
30 #include "core/timestamp.hpp"
31 #include "util/lazy.hpp"
32
33 namespace clover {
34 ///
35 /// Class that represents a task that might be executed
36 /// asynchronously at some point in the future.
37 ///
38 /// An event consists of a list of dependencies, a boolean
39 /// signalled() flag, and an associated task. An event is
40 /// considered signalled as soon as all its dependencies (if any)
41 /// are signalled as well, and the trigger() method is called; at
42 /// that point the associated task will be started through the
43 /// specified \a action_ok. If the abort() method is called
44 /// instead, the specified \a action_fail is executed and the
45 /// associated task will never be started. Dependent events will
46 /// be aborted recursively.
47 ///
48 /// The execution status of the associated task can be queried
49 /// using the status() method, and it can be waited for completion
50 /// using the wait() method.
51 ///
52 class event : public ref_counter, public _cl_event {
53 public:
54 typedef std::function<void (event &)> action;
55
56 event(context &ctx, const ref_vector<event> &deps,
57 action action_ok, action action_fail);
58 virtual ~event();
59
60 event(const event &ev) = delete;
61 event &
62 operator=(const event &ev) = delete;
63
64 void trigger();
65 void abort(cl_int status);
66 bool signalled() const;
67
68 virtual cl_int status() const = 0;
69 virtual command_queue *queue() const = 0;
70 virtual cl_command_type command() const = 0;
71 virtual void wait() const = 0;
72
73 context &ctx;
74
75 protected:
76 void chain(event *ev);
77
78 cl_int _status;
79 std::vector<ref_ptr<event>> deps;
80
81 private:
82 unsigned wait_count;
83 action action_ok;
84 action action_fail;
85 std::vector<ref_ptr<event>> _chain;
86 };
87
88 ///
89 /// Class that represents a task executed by a command queue.
90 ///
91 /// Similar to a normal clover::event. In addition it's associated
92 /// with a given command queue \a q and a given OpenCL \a command.
93 /// hard_event instances created for the same queue are implicitly
94 /// ordered with respect to each other, and they are implicitly
95 /// triggered on construction.
96 ///
97 /// A hard_event is considered complete when the associated
98 /// hardware task finishes execution.
99 ///
100 class hard_event : public event {
101 public:
102 hard_event(command_queue &q, cl_command_type command,
103 const ref_vector<event> &deps,
104 action action = [](event &){});
105 ~hard_event();
106
107 virtual cl_int status() const;
108 virtual command_queue *queue() const;
109 virtual cl_command_type command() const;
110 virtual void wait() const;
111
112 const lazy<cl_ulong> &time_queued() const;
113 const lazy<cl_ulong> &time_submit() const;
114 const lazy<cl_ulong> &time_start() const;
115 const lazy<cl_ulong> &time_end() const;
116
117 friend class command_queue;
118
119 private:
120 virtual void fence(pipe_fence_handle *fence);
121 action profile(command_queue &q, const action &action) const;
122
123 command_queue &_queue;
124 cl_command_type _command;
125 pipe_fence_handle *_fence;
126 lazy<cl_ulong> _time_queued, _time_submit, _time_start, _time_end;
127 };
128
129 ///
130 /// Class that represents a software event.
131 ///
132 /// A soft_event is not associated with any specific hardware task
133 /// or command queue. It's considered complete as soon as all its
134 /// dependencies finish execution.
135 ///
136 class soft_event : public event {
137 public:
138 soft_event(context &ctx, const ref_vector<event> &deps,
139 bool trigger, action action = [](event &){});
140
141 virtual cl_int status() const;
142 virtual command_queue *queue() const;
143 virtual cl_command_type command() const;
144 virtual void wait() const;
145 };
146 }
147
148 #endif