22 #include <sys/sysinfo.h> 26 #if defined(IS_OSX) || defined(IS_FREEBSD) 27 #include <sys/sysctl.h> 32 #ifndef WIN32_LEAN_AND_MEAN 33 #define WIN32_LEAN_AND_MEAN 1 39 #if defined(__i386) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64) 41 #if defined(__GNUC__) && !defined(__APPLE__) 54 uint32_t eax, ebx, ecx, edx;
61 static inline uint32_t get_cpuid_max(uint32_t leaf) {
62 #if defined(__GNUC__) && !defined(__APPLE__) 63 return __get_cpuid_max(leaf,
nullptr);
64 #elif defined(_MSC_VER) 66 __cpuid((
int *)p, leaf);
80 static inline void get_cpuid(uint32_t leaf, cpuid_info &info) {
81 #if defined(__GNUC__) && !defined(__APPLE__) 82 __cpuid(leaf, info.eax, info.ebx, info.ecx, info.edx);
83 #elif defined(_MSC_VER) 84 __cpuid((
int *)info.str, leaf);
87 :
"=a" (info.eax),
"=b" (info.ebx),
"=c" (info.ecx),
"=d" (info.edx)
98 struct sysinfo meminfo;
99 if (sysinfo(&meminfo) == 0) {
100 info->_physical_memory = meminfo.totalram;
101 info->_available_physical_memory = meminfo.freeram;
102 info->_page_file_size = meminfo.totalswap;
103 info->_available_page_file_size = meminfo.freeswap;
115 _lock(
"GraphicsPipe")
123 _supported_types = 0;
130 #if defined(__i386) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64) 132 const uint32_t max_cpuid = get_cpuid_max(0);
133 const uint32_t max_extended = get_cpuid_max(0x80000000);
135 if (max_cpuid >= 1) {
137 std::swap(info.ecx, info.edx);
138 _display_information->_cpu_vendor_string = std::string(info.str + 4, 12);
141 _display_information->_cpu_version_information = info.eax;
142 _display_information->_cpu_brand_index = info.ebx & 0xff;
145 if (max_extended >= 0x80000004) {
147 get_cpuid(0x80000002, info);
148 memcpy(brand, info.str, 16);
149 get_cpuid(0x80000003, info);
150 memcpy(brand + 16, info.str, 16);
151 get_cpuid(0x80000004, info);
152 memcpy(brand + 32, info.str, 16);
154 _display_information->_cpu_brand_string = brand;
160 size_t len =
sizeof(uint64_t);
161 sysctlbyname(
"hw.memsize", &_display_information->_physical_memory, &len,
nullptr, 0);
162 len =
sizeof(uint64_t);
163 sysctlbyname(
"hw.cpufrequency", &_display_information->_cpu_frequency, &len,
nullptr, 0);
164 len =
sizeof(uint64_t);
165 sysctlbyname(
"hw.cpufrequency", &_display_information->_current_cpu_frequency, &len,
nullptr, 0);
166 len =
sizeof(uint64_t);
167 sysctlbyname(
"hw.cpufrequency_max", &_display_information->_maximum_cpu_frequency, &len,
nullptr, 0);
169 sysctlbyname(
"hw.physicalcpu", &_display_information->_num_cpu_cores, &len,
nullptr, 0);
171 sysctlbyname(
"hw.logicalcpu", &_display_information->_num_logical_cpus, &len,
nullptr, 0);
173 #elif defined(IS_LINUX) 174 _display_information->_get_memory_information_function = &update_memory_info;
175 update_memory_info(_display_information);
177 #elif defined(IS_FREEBSD) 178 size_t len =
sizeof(uint64_t);
179 sysctlbyname(
"hw.physmem", &_display_information->_physical_memory, &len,
nullptr, 0);
180 len =
sizeof(uint64_t);
181 sysctlbyname(
"vm.swap_total", &_display_information->_page_file_size, &len,
nullptr, 0);
183 #elif defined(_WIN32) 184 MEMORYSTATUSEX status;
185 status.dwLength =
sizeof(MEMORYSTATUSEX);
186 if (GlobalMemoryStatusEx(&status)) {
187 _display_information->_physical_memory = status.ullTotalPhys;
188 _display_information->_available_physical_memory = status.ullAvailPhys;
189 _display_information->_page_file_size = status.ullTotalPageFile;
190 _display_information->_available_page_file_size = status.ullAvailPageFile;
191 _display_information->_process_virtual_memory = status.ullTotalVirtual;
192 _display_information->_available_process_virtual_memory = status.ullAvailVirtual;
193 _display_information->_memory_load = status.dwMemoryLoad;
197 #if defined(IS_LINUX) || defined(IS_FREEBSD) 198 long nproc = sysconf(_SC_NPROCESSORS_CONF);
200 _display_information->_num_logical_cpus = nproc;
210 delete _display_information;
218 GraphicsPipe::PreferredWindowThread
239 make_device(
void *scrn) {
241 <<
"make_device() unimplemented by " << get_type() <<
"\n";
254 if (gsg !=
nullptr) {
263 make_output(
const std::string &name,
273 << get_type() <<
" cannot create buffers or windows.\n";
281 get_display_information() {
282 return _display_information;
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual PreferredWindowThread get_preferred_window_thread() const
Returns an indication of the thread in which this GraphicsPipe requires its window processing to be p...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A container for the various kinds of properties we might ask to have on a graphics window before we o...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a base class for the various different classes that represent the result of a frame of render...
An abstract device object that is part of Graphics Pipe.
virtual void lookup_cpu_data()
Looks up the detailed CPU information and stores it in _display_information, if supported by the OS.
Encapsulates all the communication with a particular instance of a given rendering backend.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class is the main interface to controlling the render process.
TypeHandle is the identifier used to differentiate C++ class types.
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
PT(GraphicsStateGuardian) GraphicsPipe
This is called when make_output() is used to create a CallbackGraphicsWindow.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.