@@ -36,6 +36,20 @@ size_t GetNextPipelineTraceID();
36
36
37
37
// / A thread-safe queue of resources for a single consumer and a single
38
38
// / producer.
39
+ // /
40
+ // / Pipelines support two key operations: produce and consume.
41
+ // /
42
+ // / The consumer calls `Consume` to wait for a resource to be produced and
43
+ // / consume it when ready.
44
+ // /
45
+ // / The producer calls `Produce` to generate a `ProducerContinuation` which
46
+ // / provides a means to enqueue a resource in the pipeline. When the resource
47
+ // / has been prepared, the producer calls `Complete` on the continuation, which
48
+ // / enqueues the resource and signals the waiting consumer.
49
+ // /
50
+ // / Pipelines generate the following tracing information:
51
+ // / * PipelineProduce: async flow tracking time taken to produce a resource.
52
+ // / * Pipeline Depth: counter of inflight resource producers.
39
53
template <class R >
40
54
class Pipeline {
41
55
public:
@@ -70,6 +84,7 @@ class Pipeline {
70
84
}
71
85
}
72
86
87
+ // / Completes the continuation with the specified resource.
73
88
[[nodiscard]] PipelineProduceResult Complete (ResourcePtr resource) {
74
89
PipelineProduceResult result;
75
90
if (continuation_) {
@@ -108,6 +123,8 @@ class Pipeline {
108
123
109
124
bool IsValid () const { return empty_.IsValid () && available_.IsValid (); }
110
125
126
+ // Creates a `ProducerContinuation` that a producer can use to add a resource
127
+ // to the queue.
111
128
ProducerContinuation Produce () {
112
129
if (!empty_.TryWait ()) {
113
130
return {};
@@ -124,8 +141,9 @@ class Pipeline {
124
141
GetNextPipelineTraceID ()}; // trace id
125
142
}
126
143
127
- // Create a `ProducerContinuation` that will only push the task if the queue
144
+ // Creates a `ProducerContinuation` that will only push the task if the queue
128
145
// is empty.
146
+ //
129
147
// Prefer using |Produce|. ProducerContinuation returned by this method
130
148
// doesn't guarantee that the frame will be rendered.
131
149
ProducerContinuation ProduceIfEmpty () {
@@ -186,6 +204,8 @@ class Pipeline {
186
204
std::mutex queue_mutex_;
187
205
std::deque<std::pair<ResourcePtr, size_t >> queue_;
188
206
207
+ // / Commits a produced resource to the queue and signals the consumer that a
208
+ // / resource is available.
189
209
PipelineProduceResult ProducerCommit (ResourcePtr resource, size_t trace_id) {
190
210
bool is_first_item = false ;
191
211
{
0 commit comments