GPU-SD
1.4.0
|
00001 00002 /* Copyright (c) 2011-2012, Stefan Eilemann <eile@eyescale.ch> 00003 * 00004 * This library is free software; you can redistribute it and/or modify it under 00005 * the terms of the GNU Lesser General Public License version 2.1 as published 00006 * by the Free Software Foundation. 00007 * 00008 * This library is distributed in the hope that it will be useful, but WITHOUT 00009 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00010 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00011 * details. 00012 * 00013 * You should have received a copy of the GNU Lesser General Public License 00014 * along with this library; if not, write to the Free Software Foundation, Inc., 00015 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00016 */ 00017 00018 #ifndef GPUSD_GPUINFO_H 00019 #define GPUSD_GPUINFO_H 00020 00021 #include <climits> 00022 #include <cstring> 00023 #include <iostream> 00024 #include <string> 00025 00026 namespace gpusd 00027 { 00029 struct GPUInfo 00030 { 00032 static const unsigned defaultValue = UINT_MAX; 00033 00035 static const unsigned FLAG_VIRTUALGL = 0x1; 00036 00038 static const unsigned FLAG_VIRTUALGL_DISPLAY = 0x2; 00039 00041 GPUInfo() 00042 : type( 0 ), port( defaultValue ), device( defaultValue ) 00043 , session( "local" ), flags( 0 ) 00044 { invalidatePVP(); } 00045 00055 GPUInfo( const std::string& name ) 00056 : type( 0 ), port( defaultValue ), device( defaultValue ) 00057 , session( "local" ), flags( 0 ) 00058 { 00059 invalidatePVP(); 00060 strncpy( reinterpret_cast< char* >( &type ), name.c_str(), 4 ); 00061 } 00062 00064 void invalidatePVP() 00065 { 00066 pvp[0] = 0; 00067 pvp[1] = 0; 00068 pvp[2] = -1; 00069 pvp[3] = -1; 00070 } 00071 00073 bool operator == ( const GPUInfo& rhs ) const 00074 { 00075 return ( type == rhs.type && hostname == rhs.hostname && 00076 session == rhs.session && port == rhs.port && 00077 device == rhs.device && 00078 pvp[0] == rhs.pvp[0] && pvp[1] == rhs.pvp[1] && 00079 pvp[2] == rhs.pvp[2] && pvp[3] == rhs.pvp[3] ); 00080 } 00081 00083 bool operator != ( const GPUInfo& rhs ) const 00084 { 00085 return !(*this == rhs ); 00086 } 00087 00089 std::string getName() const 00090 { return std::string( reinterpret_cast<const char*>( &type ), 4 ); } 00091 00093 unsigned type; 00094 00096 unsigned port; 00097 00102 unsigned device; 00103 00105 int pvp[4]; 00106 00107 std::string hostname; 00108 std::string session; 00109 00110 unsigned flags; 00111 unsigned unused; 00112 char dummy[24]; 00113 }; 00114 00115 inline std::ostream& operator << ( std::ostream& os, const GPUInfo& info ) 00116 { 00117 if( !info.getName().empty( )) 00118 os << "type " << info.getName() << std::endl; 00119 if( !info.hostname.empty( )) 00120 os << "hostname " << info.hostname << std::endl; 00121 if( !info.session.empty() && info.session != "local" ) 00122 os << "session " << info.session << std::endl; 00123 if( info.port != GPUInfo::defaultValue ) 00124 os << "port " << info.port << std::endl; 00125 if( info.device != GPUInfo::defaultValue ) 00126 os << "device " << info.device << std::endl; 00127 if( info.pvp[2] >0 && info.pvp[3] > 0 ) 00128 os << "viewport [" << info.pvp[0] << ' ' << info.pvp[1] << ' ' 00129 << info.pvp[2] << ' ' << info.pvp[3] << ']' << std::endl; 00130 if( info.flags != 0 ) 00131 os << "flags " 00132 << (info.flags&GPUInfo::FLAG_VIRTUALGL ? "VirtualGL" : "") 00133 << (info.flags&GPUInfo::FLAG_VIRTUALGL_DISPLAY ? "Display" : "") 00134 << std::endl; 00135 return os; 00136 } 00137 } 00138 #endif // GPUSD_GPUINFO_H 00139