Path: blob/21.2-virgl/src/gallium/drivers/llvmpipe/lp_cs_tpool.h
4570 views
/**************************************************************************1*2* Copyright 2019 Red Hat.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the "Software"),7* to deal in the Software without restriction, including without limitation8* the rights to use, copy, modify, merge, publish, distribute, sublicense,9* and/or sell copies of the Software, and to permit persons to whom the10* Software is furnished to do so, subject to the following conditions:11*12* The above copyright notice and this permission notice shall be included13* in all copies or substantial portions of the Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS16* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*23**************************************************************************/2425/* This is a compute shader specific thread pool.26* It allows the queuing of a number of tasks per work item.27* The item is added to the work queue once, but it must execute28* number of iterations times. This saves storing a bunch of queue29* structs with just unique indexes in them.30* It also supports a local memory support struct to be passed from31* outside the thread exec function.32*/33#ifndef LP_CS_QUEUE34#define LP_CS_QUEUE3536#include "pipe/p_compiler.h"3738#include "util/u_thread.h"39#include "util/list.h"4041#include "lp_limits.h"4243struct lp_cs_tpool {44mtx_t m;45cnd_t new_work;4647thrd_t threads[LP_MAX_THREADS];48unsigned num_threads;49struct list_head workqueue;50bool shutdown;51};5253struct lp_cs_local_mem {54unsigned local_size;55void *local_mem_ptr;56};5758typedef void (*lp_cs_tpool_task_func)(void *data, int iter_idx, struct lp_cs_local_mem *lmem);5960struct lp_cs_tpool_task {61lp_cs_tpool_task_func work;62void *data;63struct list_head list;64cnd_t finish;65unsigned iter_total;66unsigned iter_start;67unsigned iter_finished;68};6970struct lp_cs_tpool *lp_cs_tpool_create(unsigned num_threads);71void lp_cs_tpool_destroy(struct lp_cs_tpool *);7273struct lp_cs_tpool_task *lp_cs_tpool_queue_task(struct lp_cs_tpool *,74lp_cs_tpool_task_func func,75void *data, int num_iters);7677void lp_cs_tpool_wait_for_task(struct lp_cs_tpool *pool,78struct lp_cs_tpool_task **task);7980#endif /* LP_BIN_QUEUE */818283