• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /****************************************************************************
2  * Copyright (C) 2014-2018 Intel Corporation.   All Rights Reserved.
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 (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  *
23  * @file threads.h
24  *
25  * @brief Definitions for SWR threading model.
26  *
27  ******************************************************************************/
28 #pragma once
29 
30 #include "knobs.h"
31 
32 #include <unordered_set>
33 #include <thread>
34 typedef std::thread* THREAD_PTR;
35 
36 struct SWR_CONTEXT;
37 struct DRAW_CONTEXT;
38 struct SWR_WORKER_PRIVATE_STATE;
39 
40 struct THREAD_DATA
41 {
42     void*        pWorkerPrivateData; // Pointer to per-worker private data
43     uint32_t     procGroupId;        // Will always be 0 for non-Windows OS
44     uint32_t     threadId;           // within the procGroup for Windows
45     uint32_t     numaId;             // NUMA node id
46     uint32_t     coreId;             // Core id
47     uint32_t     htId;               // Hyperthread id
48     uint32_t     workerId;           // index of worker in total thread data
49     void*        clipperData;        // pointer to hang clipper-private data on
50     SWR_CONTEXT* pContext;
51     bool         forceBindProcGroup; // Only useful when MAX_WORKER_THREADS is set.
52 };
53 
54 struct THREAD_POOL
55 {
56     THREAD_PTR*  pThreads;
57     uint32_t     numThreads;
58     uint32_t     numaMask;
59     THREAD_DATA* pThreadData;
60     void*        pWorkerPrivateDataArray; // All memory for worker private data
61     uint32_t     numReservedThreads;      // Number of threads reserved for API use
62     THREAD_DATA* pApiThreadData;
63 };
64 
65 struct TileSet;
66 
67 void CreateThreadPool(SWR_CONTEXT* pContext, THREAD_POOL* pPool);
68 void StartThreadPool(SWR_CONTEXT* pContext, THREAD_POOL* pPool);
69 void DestroyThreadPool(SWR_CONTEXT* pContext, THREAD_POOL* pPool);
70 
71 // Expose FE and BE worker functions to the API thread if single threaded
72 void    WorkOnFifoFE(SWR_CONTEXT* pContext, uint32_t workerId, uint32_t& curDrawFE);
73 bool    WorkOnFifoBE(SWR_CONTEXT* pContext,
74                      uint32_t     workerId,
75                      uint32_t&    curDrawBE,
76                      TileSet&     usedTiles,
77                      uint32_t     numaNode,
78                      uint32_t     numaMask);
79 void    WorkOnCompute(SWR_CONTEXT* pContext, uint32_t workerId, uint32_t& curDrawBE);
80 int32_t CompleteDrawContext(SWR_CONTEXT* pContext, DRAW_CONTEXT* pDC);
81 
82 void BindApiThread(SWR_CONTEXT* pContext, uint32_t apiThreadId);
83