aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/llvmpipe/lp_cs_tpool.h
blob: d32a5e09099457273b882fb2546d1a8ab714cff6 (plain)
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
/**************************************************************************
 *
 * Copyright 2019 Red Hat.
 * All Rights Reserved.
 *
 * 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.
 *
 **************************************************************************/

/* This is a compute shader specific thread pool.
 * It allows the queuing of a number of tasks per work item.
 * The item is added to the work queue once, but it must execute
 * number of iterations times. This saves storing a bunch of queue
 * structs with just unique indexes in them.
 * It also supports a local memory support struct to be passed from
 * outside the thread exec function.
 */
#ifndef LP_CS_QUEUE
#define LP_CS_QUEUE

#include "pipe/p_compiler.h"

#include "util/u_thread.h"
#include "util/list.h"

#include "lp_limits.h"

struct lp_cs_tpool {
   mtx_t m;
   cnd_t new_work;

   thrd_t threads[LP_MAX_THREADS];
   unsigned num_threads;
   struct list_head workqueue;
   bool shutdown;
};

struct lp_cs_local_mem {
   unsigned local_size;
   void *local_mem_ptr;
};

typedef void (*lp_cs_tpool_task_func)(void *data, int iter_idx, struct lp_cs_local_mem *lmem);

struct lp_cs_tpool_task {
   lp_cs_tpool_task_func work;
   void *data;
   struct list_head list;
   cnd_t finish;
   unsigned iter_total;
   unsigned iter_start;
   unsigned iter_finished;
};

struct lp_cs_tpool *lp_cs_tpool_create(unsigned num_threads);
void lp_cs_tpool_destroy(struct lp_cs_tpool *);

struct lp_cs_tpool_task *lp_cs_tpool_queue_task(struct lp_cs_tpool *,
                                                lp_cs_tpool_task_func func,
                                                void *data, int num_iters);

void lp_cs_tpool_wait_for_task(struct lp_cs_tpool *pool,
                            struct lp_cs_tpool_task **task);

#endif /* LP_BIN_QUEUE */