bool Plugin::init( const std::string& libraryName ) { if( !_dso.open( libraryName )) return false; getNumCompressors = ( GetNumCompressors_t ) ( _dso.getFunctionPointer( "EqCompressorGetNumCompressors" )); GetInfo_t getInfo = ( GetInfo_t ) ( _dso.getFunctionPointer( "EqCompressorGetInfo" )); compress = ( Compress_t ) ( _dso.getFunctionPointer( "EqCompressorCompress" )); decompress = ( Decompress_t ) ( _dso.getFunctionPointer( "EqCompressorDecompress" )); getNumResults = ( GetNumResults_t ) ( _dso.getFunctionPointer( "EqCompressorGetNumResults" )); getResult = ( GetResult_t ) ( _dso.getFunctionPointer( "EqCompressorGetResult" )); deleteDecompressor = ( DeleteDecompressor_t ) ( _dso.getFunctionPointer( "EqCompressorDeleteDecompressor" )); deleteCompressor = ( DeleteCompressor_t ) ( _dso.getFunctionPointer( "EqCompressorDeleteCompressor" )); newCompressor = ( NewCompressor_t ) ( _dso.getFunctionPointer( "EqCompressorNewCompressor" )); newDecompressor = ( NewDecompressor_t ) ( _dso.getFunctionPointer( "EqCompressorNewDecompressor" )); isCompatible = ( IsCompatible_t ) ( _dso.getFunctionPointer( "EqCompressorIsCompatible" )); download = ( Download_t ) ( _dso.getFunctionPointer( "EqCompressorDownload" )); startDownload = ( StartDownload_t ) ( _dso.getFunctionPointer( "EqCompressorStartDownload" )); finishDownload = ( FinishDownload_t ) ( _dso.getFunctionPointer( "EqCompressorFinishDownload" )); upload = ( Upload_t ) ( _dso.getFunctionPointer( "EqCompressorUpload" )); const bool foundBase = newDecompressor && newCompressor && deleteCompressor && deleteDecompressor && getInfo && getNumCompressors; const bool foundCPU = getResult && getNumResults && decompress && compress; const bool foundGPU = isCompatible && download && upload; if( !foundBase || ( !foundCPU && !foundGPU )) { LBWARN << "Initializing compression DSO " << libraryName << " failed, at least one entry point missing" << std::endl; return false; } const size_t nCompressors = getNumCompressors(); if( nCompressors == 0 ) { LBWARN << "Initializing compression DSO " << libraryName << " failed, 0 compression engines reported" << std::endl; return false; } _infos.resize( nCompressors ); for( size_t i = 0; i < nCompressors; ++i ) { CompressorInfo& info = _infos[ i ]; info.version = EQ_COMPRESSOR_VERSION; info.outputTokenType = EQ_COMPRESSOR_DATATYPE_NONE; info.outputTokenSize = 0; getInfo( i, &info ); if(( info.capabilities & EQ_COMPRESSOR_USE_ASYNC_DOWNLOAD ) && ( !startDownload || !finishDownload )) { LBWARN << "Download plugin claims to support async readback " << "but corresponding functions are missing" << std::endl; _infos.clear(); return false; } if( !( info.capabilities & EQ_COMPRESSOR_TRANSFER )) { if( info.outputTokenType == EQ_COMPRESSOR_DATATYPE_NONE ) { // Set up CPU compressor output to be input type info.outputTokenType = info.tokenType; LBASSERT( info.outputTokenSize == 0 ); } else { LBASSERT( info.outputTokenSize != 0 ); } } #ifndef NDEBUG // Check that each compressor exist once for( size_t j = 0; j < i; ++j ) { LBASSERTINFO( info.name != _infos[j].name, "Compressors " << i << " and " << j << " in '" << libraryName << "' use the same name" ); } #endif } return true; }
Plugin::Plugin( const std::string& libraryName ) : DSO( libraryName ) , getNumCompressors( getFunctionPointer< GetNumCompressors_t >( "EqCompressorGetNumCompressors" )) , newCompressor( getFunctionPointer< NewCompressor_t >( "EqCompressorNewCompressor" )) , newDecompressor( getFunctionPointer< NewDecompressor_t >( "EqCompressorNewDecompressor" )) , deleteCompressor( getFunctionPointer< DeleteCompressor_t >( "EqCompressorDeleteCompressor" )) , deleteDecompressor( getFunctionPointer< DeleteDecompressor_t >( "EqCompressorDeleteDecompressor" )) , compress( getFunctionPointer< Compress_t >( "EqCompressorCompress" )) , decompress( getFunctionPointer< Decompress_t >( "EqCompressorDecompress")) , getNumResults( getFunctionPointer< GetNumResults_t >( "EqCompressorGetNumResults" )) , getResult( getFunctionPointer< GetResult_t >( "EqCompressorGetResult" )) , isCompatible( getFunctionPointer< IsCompatible_t >( "EqCompressorIsCompatible" )) , download( getFunctionPointer< Download_t >( "EqCompressorDownload" )) , upload( getFunctionPointer< Upload_t >( "EqCompressorUpload" )) , startDownload( getFunctionPointer< StartDownload_t >( "EqCompressorStartDownload" )) , finishDownload( getFunctionPointer< FinishDownload_t >( "EqCompressorFinishDownload" )) , impl_( new detail::Plugin ) { if( !isOpen( )) return; const GetInfo_t getInfo = getFunctionPointer< GetInfo_t >( "EqCompressorGetInfo" ); const bool hasBase = newDecompressor && newCompressor && deleteCompressor && deleteDecompressor && getInfo && getNumCompressors; const bool hasCPU = getResult && getNumResults && decompress && compress; const bool hasGPU = isCompatible && download && upload; if( !hasBase || ( !hasCPU && !hasGPU )) { LBWARN << "Initializing compression DSO " << libraryName << " failed, at least one entry point missing" << std::endl; return; } const size_t nCompressors = getNumCompressors(); if( nCompressors == 0 ) { LBWARN << "Initializing compression DSO " << libraryName << " failed, 0 compression engines reported" << std::endl; return; } impl_->infos.resize( nCompressors ); for( size_t i = 0; i < nCompressors; ++i ) { CompressorInfo& info = impl_->infos[ i ]; info.version = EQ_COMPRESSOR_VERSION; info.outputTokenType = EQ_COMPRESSOR_DATATYPE_NONE; info.outputTokenSize = 0; getInfo( i, &info ); if(( info.capabilities & EQ_COMPRESSOR_USE_ASYNC_DOWNLOAD ) && ( !startDownload || !finishDownload )) { LBWARN << "Download plugin claims to support async readback " << "but corresponding functions are missing" << std::endl; impl_->infos.clear(); return; } info.ratingAlpha = powf( info.speed, .3f ) / info.ratio; info.ratingNoAlpha = info.ratingAlpha; if( info.capabilities & EQ_COMPRESSOR_IGNORE_ALPHA ) { switch( info.tokenType ) { case EQ_COMPRESSOR_DATATYPE_4_BYTE: case EQ_COMPRESSOR_DATATYPE_4_HALF_FLOAT: case EQ_COMPRESSOR_DATATYPE_4_FLOAT: info.ratingNoAlpha /= .75f; break; case EQ_COMPRESSOR_DATATYPE_RGB10_A2: info.ratingNoAlpha /= .9375f; // 30/32 break; default: break; } } if( !( info.capabilities & EQ_COMPRESSOR_TRANSFER )) { if( info.outputTokenType == EQ_COMPRESSOR_DATATYPE_NONE ) { // Set up CPU compressor output to be input type info.outputTokenType = info.tokenType; LBASSERT( info.outputTokenSize == 0 ); } else { LBASSERT( info.outputTokenSize != 0 ); } } #ifndef NDEBUG // Check that each compressor exist once for( size_t j = 0; j < i; ++j ) { LBASSERTINFO( info.name != impl_->infos[j].name, "Compressors " << i << " and " << j << " in '" << libraryName << "' use the same name" ); } #endif } if( nCompressors == 0 ) LBERROR << "No plugins found in " << libraryName << std::endl; else LBDEBUG << "Loaded " << nCompressors << " plugins from " << libraryName << std::endl; }