1 /**************************************************************************
3 * Copyright 2019 Red Hat.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 **************************************************************************/
26 /* This is a compute shader specific thread pool.
27 * It allows the queuing of a number of tasks per work item.
28 * The item is added to the work queue once, but it must execute
29 * number of iterations times. This saves storing a bunch of queue
30 * structs with just unique indexes in them.
31 * It also supports a local memory support struct to be passed from
32 * outside the thread exec function.
37 #include "pipe/p_compiler.h"
39 #include "util/u_thread.h"
40 #include "util/list.h"
42 #include "lp_limits.h"
48 thrd_t threads
[LP_MAX_THREADS
];
50 struct list_head workqueue
;
54 struct lp_cs_local_mem
{
59 typedef void (*lp_cs_tpool_task_func
)(void *data
, int iter_idx
, struct lp_cs_local_mem
*lmem
);
61 struct lp_cs_tpool_task
{
62 lp_cs_tpool_task_func work
;
64 struct list_head list
;
68 unsigned iter_finished
;
71 struct lp_cs_tpool
*lp_cs_tpool_create(unsigned num_threads
);
72 void lp_cs_tpool_destroy(struct lp_cs_tpool
*);
74 struct lp_cs_tpool_task
*lp_cs_tpool_queue_task(struct lp_cs_tpool
*,
75 lp_cs_tpool_task_func func
,
76 void *data
, int num_iters
);
78 void lp_cs_tpool_wait_for_task(struct lp_cs_tpool
*pool
,
79 struct lp_cs_tpool_task
**task
);
81 #endif /* LP_BIN_QUEUE */