33 #include "configEvent.h"
36 # define snprintf _snprintf
39 namespace eqPixelBench
43 #pragma warning(disable: 411) // class defines no constructor to initialize ...
46 const char* internalFormatString;
47 const uint32_t internalFormat;
48 const size_t pixelSize;
51 #pragma warning(default: 411)
53 #define ENUM_MAP_ITEM( internalFormat, pixelSize ) \
54 { #internalFormat, EQ_COMPRESSOR_DATATYPE_ ## internalFormat, pixelSize }
56 static EnumMap _enums[] = {
57 ENUM_MAP_ITEM( RGBA32F, 16 ),
58 ENUM_MAP_ITEM( RGBA, 4 ),
59 ENUM_MAP_ITEM( RGB10_A2, 4 ),
60 ENUM_MAP_ITEM( RGBA16F, 8 ),
61 ENUM_MAP_ITEM( RGBA32F, 16 ),
62 ENUM_MAP_ITEM( DEPTH, 4 ),
71 _frame.setFrameData( frameData );
73 for(
unsigned i = 0; i < NUM_IMAGES; ++i )
84 const uint32_t frameNumber )
87 const lunchbox::Clock* clock = config->
getClock();
91 const std::string formatType =
"app->pipe thread latency";
92 _sendEvent( START_LATENCY, clock->getTimef(), eq::Vector2i( 0, 0 ),
105 glMatrixMode( GL_PROJECTION );
110 glMatrixMode( GL_MODELVIEW );
116 _testFormats( 1.0f );
117 _testFormats( 0.5f );
118 _testFormats( 2.0f );
119 _testTiledOperations();
120 _testDepthAssemble();
125 void Channel::_testFormats(
float applyZoom )
135 const eq::Vector2i offset( pvp.x, pvp.y );
136 const eq::Zoom zoom( applyZoom, applyZoom );
138 lunchbox::Clock clock;
142 for( uint32_t i=0; _enums[i].internalFormatString; ++i )
144 const uint32_t internalFormat = _enums[i].internalFormat;
151 const std::vector< uint32_t >& names =
154 for( std::vector< uint32_t >::const_iterator j = names.begin();
155 j != names.end(); ++j )
157 _draw( co::uint128_t( ));
162 const uint32_t outputToken =
164 std::stringstream formatType;
165 formatType << std::hex << *j <<
':'
166 << _enums[i].internalFormatString <<
'/' << outputToken
174 while( clock.getTime64() < 100 )
178 image->finishReadback( glObjects.glewGetContext( ));
182 const float msec = clock.getTimef() / float( nLoops );
183 const GLenum error = glGetError();
184 if( error != GL_NO_ERROR )
189 const eq::Vector2i area( pixels.
pvp.w, pixels.
pvp.h );
190 const uint64_t dataSizeGPU = area.x() * area.y() *
192 const uint64_t dataSizeCPU =
195 _sendEvent( READBACK, msec, area, formatType.str(), dataSizeGPU,
200 _sendEvent( READBACK, -static_cast<float>( e.glError ),
201 eq::Vector2i(), formatType.str(), 0, 0 );
212 const uint64_t dataSizeCPU =
219 const float msec = clock.getTimef() / float( nLoops );
220 const GLenum error = glGetError();
221 if( error != GL_NO_ERROR )
226 const eq::Vector2i area( pixels.
pvp.w, pixels.
pvp.h );
227 const uint64_t dataSizeGPU =
229 _sendEvent( ASSEMBLE, msec, area, formatType.str(), dataSizeGPU,
234 _sendEvent( ASSEMBLE, -static_cast<float>( e.glError ),
235 eq::Vector2i(), formatType.str(), 0, 0 );
241 void Channel::_testTiledOperations()
247 LBASSERT( images[0] );
250 const eq::Vector2i offset( pvp.x, pvp.y );
255 lunchbox::Clock clock;
260 eq::PixelViewport subPVP = pvp;
261 subPVP.h /= NUM_IMAGES;
263 for(
unsigned i = 0; i < NUM_IMAGES; ++i )
265 LBASSERT( images[ i ] );
266 images[ i ]->setPixelViewport( subPVP );
269 for(
unsigned tiles = 0; tiles < NUM_IMAGES; ++tiles )
271 EQ_GL_CALL( _draw( co::uint128_t( )));
272 area.y() = subPVP.h * (tiles+1);
275 std::stringstream formatType;
276 formatType << tiles+1 <<
" depth tiles";
279 for(
unsigned j = 0; j <= tiles; ++j )
281 subPVP.y = pvp.y + j * subPVP.h;
284 EQ_COMPRESSOR_TRANSFER_DEPTH_TO_DEPTH_UNSIGNED_INT,
290 eq::Zoom::NONE, glObjects );
291 image->finishReadback( glObjects.glewGetContext( ));
292 msec += clock.getTimef();
295 _sendEvent( READBACK, msec, area, formatType.str(), 0, 0 );
297 if( tiles == NUM_IMAGES-1 )
298 for(
unsigned j = 0; j <= tiles; ++j )
299 _saveImage( images[j],
300 "EQ_COMPRESSOR_DATATYPE_DEPTH_UNSIGNED_INT",
305 formatType << tiles+1 <<
" color tiles";
308 for(
unsigned j = 0; j <= tiles; ++j )
310 subPVP.y = pvp.y + j * subPVP.h;
314 EQ_COMPRESSOR_TRANSFER_RGBA_TO_BGRA,
320 eq::Zoom::NONE, glObjects );
321 image->finishReadback( glObjects.glewGetContext( ));
322 msec += clock.getTimef();
324 _sendEvent( READBACK, msec, area, formatType.str(), 0, 0 );
326 if( tiles == NUM_IMAGES-1 )
327 for(
unsigned j = 0; j <= tiles; ++j )
328 _saveImage( images[j],
"EQ_COMPRESSOR_DATATYPE_BGRA",
"tiles" );
331 subPVP.y = pvp.y + tiles * subPVP.h;
340 formatType <<
"tiles, GL1.1, " << tiles+1 <<
" images";
343 for(
unsigned j = 0; j <= tiles; ++j )
346 msec = clock.getTimef();
347 _sendEvent( ASSEMBLE, msec, area, formatType.str(), 0, 0 );
351 formatType <<
"tiles, CPU, " << tiles+1 <<
" images";
353 std::vector< eq::Frame* > frames;
354 frames.push_back( &_frame );
358 msec = clock.getTimef();
359 _sendEvent( ASSEMBLE, msec, area, formatType.str(), 0, 0 );
363 void Channel::_testDepthAssemble()
373 const eq::Vector2i offset( pvp.x, pvp.y );
378 lunchbox::Clock clock;
383 for(
unsigned i = 0; i < NUM_IMAGES; ++i )
392 for( uint64_t i = 0; i < NUM_IMAGES; ++i )
394 _draw( co::uint128_t( i ) );
400 EQ_COMPRESSOR_TRANSFER_RGBA_TO_BGRA,
404 EQ_COMPRESSOR_TRANSFER_DEPTH_TO_DEPTH_UNSIGNED_INT,
411 pvp, eq::Zoom::NONE, glObjects );
412 image->finishReadback( glObjects.glewGetContext( ));
416 if( i == NUM_IMAGES-1 )
417 _saveImage( image,
"EQ_COMPRESSOR_DATATYPE_DEPTH_UNSIGNED_INT",
427 std::stringstream formatType;
428 formatType <<
"depth, GL1.1, " << i+1 <<
" images";
431 for(
unsigned j = 0; j <= i; ++j )
434 float msec = clock.getTimef();
435 _sendEvent( ASSEMBLE, msec, area, formatType.str(), 0, 0 );
438 if( GLEW_VERSION_2_0 )
441 formatType <<
"depth, GLSL, " << i+1 <<
" images";
444 for(
unsigned j = 0; j <= i; ++j )
446 msec = clock.getTimef();
447 _sendEvent( ASSEMBLE, msec, area, formatType.str(), 0, 0 );
452 formatType <<
"depth, CPU, " << i+1 <<
" images";
454 std::vector< eq::Frame* > frames;
455 frames.push_back( &_frame );
459 msec = clock.getTimef();
460 _sendEvent( ASSEMBLE, msec, area, formatType.str(), 0, 0 );
464 void Channel::_sendEvent( ConfigEventType type,
const float msec,
465 const eq::Vector2i& area,
466 const std::string& formatType,
467 const uint64_t dataSizeGPU,
468 const uint64_t dataSizeCPU )
473 std::stringstream strName;
475 name = strName.str();
479 << msec << name << area << formatType << dataSizeGPU << dataSizeCPU;
482 void Channel::_saveImage(
const eq::Image* image,
483 const char* externalformat,
488 static uint32_t counter = 0;
489 std::ostringstream stringstream;
490 stringstream <<
"Image_" << ++counter <<
"_" << externalformat <<
"_"
495 void Channel::_draw(
const eq::uint128_t& spin )
498 EQ_GL_CALL( glPushAttrib( GL_ALL_ATTRIB_BITS ));
501 EQ_GL_CALL( glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ));
502 EQ_GL_CALL( glEnable( GL_DEPTH_TEST ));
504 const float lightPos[] = { 0.0f, 0.0f, 1.0f, 0.0f };
505 glLightfv( GL_LIGHT0, GL_POSITION, lightPos );
507 const float lightAmbient[] = { 0.2f, 0.2f, 0.2f, 1.0f };
508 glLightfv( GL_LIGHT0, GL_AMBIENT, lightAmbient );
511 glRotatef( static_cast< float >( spin.low() + 3 ) * 10, 1.0f, 0.5f, 0.25f );
515 glColor3f( 1.0f, 0.5f, 0.5f );
516 glNormal3f( 0.0f, 0.0f, 1.0f );
517 glBegin( GL_TRIANGLE_STRIP );
518 glVertex3f( .7f, .7f, -1.0f );
519 glVertex3f( -.7f, .7f, -1.0f );
520 glVertex3f( .7f, -.7f, -1.0f );
521 glVertex3f( -.7f, -.7f, -1.0f );
525 glColor3f( 0.5f, 1.0f, 0.5f );
526 glNormal3f( 0.0f, 1.0f, 0.0f );
527 glBegin( GL_TRIANGLE_STRIP );
528 glVertex3f( .7f, -1.0f, .7f );
529 glVertex3f( -.7f, -1.0f, .7f );
530 glVertex3f( .7f, -1.0f, -.7f );
531 glVertex3f( -.7f, -1.0f, -.7f );
535 glColor3f( 0.5f, 0.5f, 1.0f );
536 glNormal3f( 0.0f, 0.0f, -1.0f );
537 glBegin( GL_TRIANGLE_STRIP );
538 glVertex3f( .7f, .7f, 1.0f );
539 glVertex3f( -.7f, .7f, 1.0f );
540 glVertex3f( .7f, -.7f, 1.0f );
541 glVertex3f( -.7f, -.7f, 1.0f );
545 glColor3f( 1.0f, 1.0f, 0.5f );
546 glNormal3f( 0.f, -1.f, 0.f );
547 glBegin( GL_TRIANGLE_STRIP );
548 glVertex3f( .7f, 1.0f, .7f );
549 glVertex3f( -.7f, 1.0f, .7f );
550 glVertex3f( .7f, 1.0f, -.7f );
551 glVertex3f( -.7f, 1.0f, -.7f );
555 glColor3f( 1.0f, 0.5f, 1.0f );
556 glNormal3f( -1.f, 0.f, 0.f );
557 glBegin( GL_TRIANGLE_STRIP );
558 glVertex3f( 1.0f, .7f, .7f );
559 glVertex3f( 1.0f, -.7f, .7f );
560 glVertex3f( 1.0f, .7f, -.7f );
561 glVertex3f( 1.0f, -.7f, -.7f );
565 glColor3f( 0.5f, 1.0f, 1.0f );
566 glNormal3f( 1.f, 0.f, 0.f );
567 glBegin( GL_TRIANGLE_STRIP );
568 glVertex3f( -1.0f, .7f, .7f );
569 glVertex3f( -1.0f, -.7f, .7f );
570 glVertex3f( -1.0f, .7f, -.7f );
571 glVertex3f( -1.0f, -.7f, -.7f );
574 EQ_GL_CALL( glPopAttrib( ));
EQ_API bool writeImages(const std::string &filenameTemplate) const
Write all valid pixel data as separate images.
uint32_t buffers
The Frame buffer attachments to use.
const PixelViewport & getPixelViewport() const
Zoom zoom
The zoom factor.
A channel represents a two-dimensional viewport within a Window.
Vector2i offset
The offset wrt destination window.
virtual void frameDraw(const eq::uint128_t &frameID)
Draw the scene.
static uint32_t assembleFramesCPU(const Frames &frames, Channel *channel, const bool blendAlpha=false)
Assemble all frames in the given order in a memory buffer using the CPU before assembling the result ...
virtual EQ_API void frameStart(const uint128_t &frameID, const uint32_t frameNumber)
Start rendering a frame.
EQ_API bool startReadback(const uint32_t buffers, const PixelViewport &pvp, const Zoom &zoom, util::ObjectManager &glObjects)
Start reading back an image from the frame buffer.
virtual EQ_API void frameDraw(const uint128_t &frameID)
Draw the scene.
static void assembleImageDB_FF(const Image *image, const ImageOp &op)
Start a Z-based assembly of the image color and depth attachment, based on OpenGL 1...
EQ_API void flush()
Free all cached data of this image.
The pixel data structure manages the pixel information for images.
EQ_API void bindFrameBuffer()
Rebind the current alternate FBO of the channel or window.
virtual EQ_API void applyViewport() const
Apply the OpenGL viewport for the current rendering task.
virtual EQ_API void applyFrustum() const
Apply the frustum matrix for the current rendering task.
static void assembleImage(const Image *image, const ImageOp &operation)
Assemble an image into the frame buffer.
EQ_API uint32_t getExternalFormat(const Frame::Buffer buffer) const
Get the external format of the given buffer.
virtual void frameStart(const eq::uint128_t &frameID, const uint32_t frameNumber)
Start rendering a frame.
EQ_API void sendEvent(ConfigEvent &event)
Send an (old) event to the application node.
virtual bool configExit()
Exit this channel.
A structure describing an image assembly task.
std::vector< Image * > Images
A vector of pointers to eq::Image.
EQ_API util::ObjectManager & getObjectManager()
EQFABRIC_API const std::string & getName() const
A Window represents an on-screen or off-screen drawable.
EQ_API Config * getConfig()
EQ_API const GLEWContext * glewGetContext() const
Get the GLEW context for this channel.
EQ_API bool hasPixelData(const Frame::Buffer buffer) const
virtual EQ_API void applyHeadTransform() const
Apply the transformation to position the view frustum.
EQ_API void setInternalFormat(const Frame::Buffer buffer, const uint32_t internalFormat)
Set the internal format for the given buffer.
A holder for multiple images.
static void assembleImageDB_GLSL(const Image *image, const ImageOp &op)
Start a Z-based assembly of the image color and depth attachment, using GLSL.
virtual EQ_API bool configExit()
Exit this channel.
const lunchbox::Clock * getClock() const
use main memory to store pixel data
EQ_API const Images & getImages() const
EQ_API uint32_t getPixelDataSize(const Frame::Buffer buffer) const
A facility class to manage OpenGL objects across shared contexts.
EQ_API void clearPixelData(const Frame::Buffer buffer)
Clear and validate an image buffer.
virtual EQ_API void setupAssemblyState()
Setup the OpenGL state for a readback or assemble operation.
EQ_API Image * newImage(const Frame::Type type, const DrawableConfig &config)
Allocate and add a new image.
EQ_API void setQuality(const Frame::Buffer buffer, const float quality)
Set the minimum quality after a full download-compression path.
virtual EQ_API void applyBuffer()
Apply the current rendering buffer, including the color mask.
lunchbox::RefPtr< FrameData > FrameDataPtr
A reference-counted pointer to an eq::FrameData.
virtual EQ_API void resetAssemblyState()
Reset the OpenGL state after an assembly operation.
EQ_API void setPixelViewport(const PixelViewport &pvp)
Set the internal pixel viewport of the image.
Channel * channel
The destination channel.
PixelViewport pvp
The dimensions of the pixel data in pixels.
EQ_API const PixelData & getPixelData(const Frame::Buffer) const
EQ_API FrameDataPtr getFrameData()
Exception class for Equalizer operations.
EQ_API void setAlphaUsage(const bool enabled)
Set alpha data preservation during download and compression.