diff options
author | Apple SWE <[email protected]> | 2018-03-13 18:24:26 -0700 |
---|---|---|
committer | Jeremy Huddleston Sequoia <[email protected]> | 2018-03-13 22:50:27 -0700 |
commit | de0d10db93d85de79c7b4451c4851ace2976f8f4 (patch) | |
tree | 448bd7d9ca17a79cc13b9782384a3b6c010c3db7 /src/gallium/drivers/swr | |
parent | 274f8bf05ef526d65f01614313dda65bc7ec7a87 (diff) |
Add processor topology calculation implementation for Darwin/OSX targets.
The implementation for bootstrapping SWR on Darwin targets is based on the Linux version.
Instead of reading the output of /proc/cpuinfo, sysctlbyname is used to determine the
physical identifiers, processor identifiers, core counts and thread-processor affinities.
With this patch, it is possible to use SWR as an alternate renderer on OSX to softpipe and
llvmpipe.
Reviewed-by: Jeremy Huddleston Sequoia <[email protected]>
Signed-off-by: Jeremy Huddleston Sequoia <[email protected]>
Diffstat (limited to 'src/gallium/drivers/swr')
-rw-r--r-- | src/gallium/drivers/swr/rasterizer/core/threads.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/gallium/drivers/swr/rasterizer/core/threads.cpp b/src/gallium/drivers/swr/rasterizer/core/threads.cpp index 4d79168d2dc..fd7a42e4720 100644 --- a/src/gallium/drivers/swr/rasterizer/core/threads.cpp +++ b/src/gallium/drivers/swr/rasterizer/core/threads.cpp @@ -36,6 +36,11 @@ #include <unistd.h> #endif +#ifdef __APPLE__ +#include <sys/types.h> +#include <sys/sysctl.h> +#endif + #include "common/os.h" #include "context.h" #include "frontend.h" @@ -253,6 +258,56 @@ void CalculateProcessorTopology(CPUNumaNodes& out_nodes, uint32_t& out_numThread } } + auto numProcessors = 0; + auto numCores = 0; + auto numPhysicalIds = 0; + + int value; + size_t size = sizeof(value); + + int result = sysctlbyname("hw.packages", &value, &size, NULL, 0); + SWR_ASSERT(result == 0); + numPhysicalIds = value; + + result = sysctlbyname("hw.logicalcpu", &value, &size, NULL, 0); + SWR_ASSERT(result == 0); + numProcessors = value; + + result = sysctlbyname("hw.physicalcpu", &value, &size, NULL, 0); + SWR_ASSERT(result == 0); + numCores = value; + + out_nodes.resize(numPhysicalIds); + + for (auto physId = 0; physId < numPhysicalIds; ++physId) + { + auto &numaNode = out_nodes[physId]; + auto procId = 0; + + numaNode.cores.resize(numCores); + + while (procId < numProcessors) + { + for (auto coreId = 0; coreId < numaNode.cores.size(); ++coreId, ++procId) + { + auto &core = numaNode.cores[coreId]; + + core.procGroup = coreId; + core.threadIds.push_back(procId); + } + } + } + + out_numThreadsPerProcGroup = 0; + + for (auto &node : out_nodes) + { + for (auto &core : node.cores) + { + out_numThreadsPerProcGroup += core.threadIds.size(); + } + } + void bindThread(SWR_CONTEXT* pContext, uint32_t threadId, uint32_t procGroupId = 0, bool bindProcGroup=false) { |