Cycles: Make all #include statements relative to cycles source directory
[blender.git] / intern / cycles / util / util_windows.cpp
1 /*
2  * Copyright 2011-2016 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "util/util_windows.h"
18
19 #ifdef _WIN32
20
21 CCL_NAMESPACE_BEGIN
22
23 #ifdef _M_X64
24 #  include <VersionHelpers.h>
25 #endif
26
27 #if _WIN32_WINNT < 0x0601
28 tGetActiveProcessorGroupCount *GetActiveProcessorGroupCount;
29 tGetActiveProcessorCount *GetActiveProcessorCount;
30 tSetThreadGroupAffinity *SetThreadGroupAffinity;
31 tGetProcessGroupAffinity *GetProcessGroupAffinity;
32 #endif
33
34 static WORD GetActiveProcessorGroupCount_stub()
35 {
36         return 1;
37 }
38
39 static DWORD GetActiveProcessorCount_stub(WORD /*GroupNumber*/)
40 {
41         SYSTEM_INFO info;
42         GetSystemInfo(&info);
43         return info.dwNumberOfProcessors;
44 }
45
46 static BOOL SetThreadGroupAffinity_stub(
47         HANDLE /*hThread*/,
48         const GROUP_AFFINITY  * /*GroupAffinity*/,
49         PGROUP_AFFINITY /*PreviousGroupAffinity*/)
50 {
51         return TRUE;
52 }
53
54 static BOOL GetProcessGroupAffinity_stub(HANDLE hProcess,
55                                          PUSHORT GroupCount,
56                                          PUSHORT GroupArray)
57 {
58         if(*GroupCount < 1) {
59                 return FALSE;
60         }
61         *GroupCount = 1;
62         GroupArray[0] = 0;
63         return TRUE;
64 }
65
66 static bool supports_numa()
67 {
68 #ifndef _M_X64
69         return false;
70 #else
71         return IsWindows7OrGreater();
72 #endif
73 }
74
75 void util_windows_init_numa_groups()
76 {
77         static bool initialized = false;
78         if(initialized) {
79                 return;
80         }
81         initialized = true;
82 #if _WIN32_WINNT < 0x0601
83         if(!supports_numa()) {
84                 /* Use stubs on platforms which doesn't have rean NUMA/Groups. */
85                 GetActiveProcessorGroupCount = GetActiveProcessorGroupCount_stub;
86                 GetActiveProcessorCount = GetActiveProcessorCount_stub;
87                 SetThreadGroupAffinity = SetThreadGroupAffinity_stub;
88                 GetProcessGroupAffinity = GetProcessGroupAffinity_stub;
89                 return;
90         }
91         HMODULE kernel = GetModuleHandleA("kernel32.dll");
92 #  define READ_SYMBOL(sym) sym = (t##sym*)GetProcAddress(kernel, #sym)
93         READ_SYMBOL(GetActiveProcessorGroupCount);
94         READ_SYMBOL(GetActiveProcessorCount);
95         READ_SYMBOL(SetThreadGroupAffinity);
96         READ_SYMBOL(GetProcessGroupAffinity);
97 #  undef READ_SUMBOL
98 #endif
99 }
100
101 CCL_NAMESPACE_END
102
103 #endif  /* _WIN32 */