1/**************************************************************************** 2* Copyright (C) 2014-2016 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> 34typedef std::thread* THREAD_PTR; 35 36struct SWR_CONTEXT; 37struct DRAW_CONTEXT; 38 39struct THREAD_DATA 40{ 41 uint32_t procGroupId; // Will always be 0 for non-Windows OS 42 uint32_t threadId; // within the procGroup for Windows 43 uint32_t numaId; // NUMA node id 44 uint32_t coreId; // Core id 45 uint32_t htId; // Hyperthread id 46 uint32_t workerId; 47 SWR_CONTEXT *pContext; 48 bool forceBindProcGroup; // Only useful when MAX_WORKER_THREADS is set. 49}; 50 51 52struct THREAD_POOL 53{ 54 THREAD_PTR* pThreads; 55 uint32_t numThreads; 56 uint32_t numaMask; 57 THREAD_DATA *pThreadData; 58}; 59 60typedef std::unordered_set<uint32_t> TileSet; 61 62void CreateThreadPool(SWR_CONTEXT *pContext, THREAD_POOL *pPool); 63void StartThreadPool(SWR_CONTEXT* pContext, THREAD_POOL* pPool); 64void DestroyThreadPool(SWR_CONTEXT *pContext, THREAD_POOL *pPool); 65 66// Expose FE and BE worker functions to the API thread if single threaded 67void WorkOnFifoFE(SWR_CONTEXT *pContext, uint32_t workerId, uint32_t &curDrawFE); 68bool WorkOnFifoBE(SWR_CONTEXT *pContext, uint32_t workerId, uint32_t &curDrawBE, TileSet &usedTiles, uint32_t numaNode, uint32_t numaMask); 69void WorkOnCompute(SWR_CONTEXT *pContext, uint32_t workerId, uint32_t &curDrawBE); 70int32_t CompleteDrawContext(SWR_CONTEXT* pContext, DRAW_CONTEXT* pDC); 71