Profiler::Result Profiler::getResult(ID3D11Device* graphicsDevice, Game* game)
{
	ID3D11DeviceContext* immediateContext;

	graphicsDevice->GetImmediateContext(&immediateContext);

	GPA_BeginSession(&sessionID);

	for (unsigned i = 0; i < numPasses; ++i)
	{
		GPA_BeginPass();
		GPA_BeginSample(0);

		game->drawTerrain(graphicsDevice);

		GPA_EndSample();
		GPA_EndPass();
	}

	GPA_EndSession();

	immediateContext->Release();

	bool readyResult;

	do GPA_IsSessionReady(&readyResult, sessionID); 
	while (!readyResult);

	do GPA_IsSampleReady(&readyResult, sessionID, 0);
	while (!readyResult);

	double primitivesIn;
	double pixelsPerTriangle;

	GPA_GetSampleFloat64(sessionID, 0, primitivesInCounterID, &primitivesIn);
	GPA_GetSampleFloat64(sessionID, 0, pixelsPerTriangleCounterID, &pixelsPerTriangle);

	Result result;

	result.primitiveCount = (unsigned)primitivesIn;
	result.pixelsPerTriangle = (float)pixelsPerTriangle;

	return result;
}
Exemple #2
0
int
dxt_encoder_compress_texture(struct dxt_encoder* encoder, int texture, unsigned char* image_compressed)
{
#ifdef USE_PBO_DXT_ENCODER
    GLubyte *ptr;
#endif

    glBindTexture(GL_TEXTURE_2D, texture);

    glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); 
    assert(GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER));

    glClearColor(1,0,0,1);
    glClear(GL_COLOR_BUFFER_BIT);

    if(encoder->legacy) {
        glBegin(GL_QUADS);
        glTexCoord2f(0.0, 0.0); glVertex2f(-1.0, -1.0);
        glTexCoord2f(1.0, 0.0); glVertex2f(1.0, -1.0);
        glTexCoord2f(1.0, 1.0); glVertex2f(1.0, 1.0);
        glTexCoord2f(0.0, 1.0); glVertex2f(-1.0, 1.0);
        glEnd();
    } else {
#if ! defined HAVE_MACOSX || OS_VERSION_MAJOR >= 11
        // Compress
        glBindVertexArray(encoder->g_vao);
        //glDrawElements(GL_TRIANGLE_STRIP, sizeof(m_quad.indices) / sizeof(m_quad.indices[0]), GL_UNSIGNED_SHORT, BUFFER_OFFSET(0));
        glDrawArrays(GL_TRIANGLES, 0, 6);
        glBindVertexArray(0);
#endif
    }
#ifdef HAVE_GPUPERFAPI
    GPA_EndSample();
    GPA_BeginSample(3);
#endif
#ifdef RTDXT_DEBUG
    glEndQuery(GL_TIME_ELAPSED_EXT);
    glBeginQuery(GL_TIME_ELAPSED_EXT, encoder->queries[3]);
#endif
#ifdef RTDXT_DEBUG_HOST
    glFinish();
    TIMER_STOP_PRINT("Texture Compress:  ");
    TIMER_START();
#endif


    glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);

#ifdef USE_PBO_DXT_ENCODER
    // Read back
    // read pixels from framebuffer to PBO
    // glReadPixels() should return immediately.
    glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, encoder->pbo_out);
    if ( encoder->type == DXT_TYPE_DXT5_YCOCG )
        glReadPixels(0, 0, (encoder->width + 3) / 4, (encoder->height + 3) / 4, GL_RGBA_INTEGER_EXT, GL_UNSIGNED_INT, 0);
    else
        glReadPixels(0, 0, (encoder->width + 3) / 4, (encoder->height + 3) / 4 , GL_RGBA_INTEGER_EXT, GL_UNSIGNED_SHORT, 0);

    // map the PBO to process its data by CPU
    glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, encoder->pbo_out);
    ptr = (GLubyte*)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB,
                                            GL_READ_ONLY_ARB);
    if(ptr)
    {
        memcpy(image_compressed, ptr, ((encoder->width + 3) / 4 * 4) * ((encoder->height + 3) / 4 * 4) / (encoder->type == DXT_TYPE_DXT5_YCOCG ? 1 : 2));
        glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB);
    }

    // back to conventional pixel operation
    glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
#else
        glReadPixels(0, 0, (encoder->width + 3) / 4, (encoder->height + 3) / 4, GL_RGBA_INTEGER_EXT,
                        encoder->type == DXT_TYPE_DXT5_YCOCG ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, image_compressed);
#endif

        
#ifdef RTDXT_DEBUG_HOST
    glFinish();
    TIMER_STOP_PRINT("Texture Save:      ");
#endif
#ifdef RTDXT_DEBUG
    glEndQuery(GL_TIME_ELAPSED_EXT);
    {
        GLint available = 0;
        GLuint64 load = 0,
                 convert = 0,
                 compress = 0,
                 store = 0;
        while (!available) {
            glGetQueryObjectiv(encoder->queries[3], GL_QUERY_RESULT_AVAILABLE, &available);
        }
        glGetQueryObjectui64vEXT(encoder->queries[0], GL_QUERY_RESULT, &load);
        glGetQueryObjectui64vEXT(encoder->queries[1], GL_QUERY_RESULT, &convert);
        glGetQueryObjectui64vEXT(encoder->queries[2], GL_QUERY_RESULT, &compress);
        glGetQueryObjectui64vEXT(encoder->queries[3], GL_QUERY_RESULT, &store);
        printf("Load: %8lu; YUV444->YUV422: %8lu; compress: %8lu; store: %8lu\n",
                load, convert, compress, store);
    }
#endif
#ifdef HAVE_GPUPERFAPI
    GPA_EndSample();
    GPA_EndPass();
#endif
    
    return 0;
}
Exemple #3
0
/** Documented at declaration */
int
dxt_encoder_compress(struct dxt_encoder* encoder, DXT_IMAGE_TYPE* image, unsigned char* image_compressed)
{        
#ifdef RTDXT_DEBUG
    glBeginQuery(GL_TIME_ELAPSED_EXT, encoder->queries[0]);
#endif
#ifdef RTDXT_DEBUG_HOST
    TIMER_INIT();

    TIMER_START();
#endif
#ifdef HAVE_GPUPERFAPI
    GPA_BeginPass();
    GPA_BeginSample(0);
#endif
#ifdef USE_PBO_DXT_ENCODER
    GLubyte *ptr;
#endif

    int data_size = encoder->width * encoder->height;
    switch(encoder->format) {
            case DXT_FORMAT_YUV422:
                data_size *= 2;
                break;
            case DXT_FORMAT_RGB:
                data_size *= 3;
                break;
            case DXT_FORMAT_RGBA:
            case DXT_FORMAT_YUV:
                data_size *= 4;
                break;
    }

    switch(encoder->format) {
            case DXT_FORMAT_YUV422:
                        glBindFramebuffer(GL_FRAMEBUFFER, encoder->fbo444_id);
                        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, encoder->texture_id, 0);
                        glBindTexture(GL_TEXTURE_2D, encoder->texture_yuv422);
                        
                        glPushAttrib(GL_VIEWPORT_BIT);
                        glViewport( 0, 0, encoder->width, encoder->height);
                
#ifdef USE_PBO_DXT_ENCODER
                        glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, encoder->pbo_in); // current pbo
                        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, encoder->width / 2, encoder->height,  GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
                        glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, data_size, 0, GL_STREAM_DRAW_ARB);
                        ptr = (GLubyte*)glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY_ARB);
                        if(ptr)
                        {
                            // update data directly on the mapped buffer
                            memcpy(ptr, image, data_size); 
                            glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB); // release pointer to mapping buffer
                        }
#else
                        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, encoder->width / 2, encoder->height,  GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, image);
#endif
                        glUseProgram(encoder->yuv422_to_444_program);
#ifdef RTDXT_DEBUG
    glEndQuery(GL_TIME_ELAPSED_EXT);
    glBeginQuery(GL_TIME_ELAPSED_EXT, encoder->queries[1]);
#endif
#ifdef HAVE_GPUPERFAPI
    GPA_EndSample();
    GPA_BeginSample(1);
#endif
                        
                        if(encoder->legacy) {
                            glBegin(GL_QUADS);
                            glTexCoord2f(0.0, 0.0); glVertex2f(-1.0, -1.0);
                            glTexCoord2f(1.0, 0.0); glVertex2f(1.0, -1.0);
                            glTexCoord2f(1.0, 1.0); glVertex2f(1.0, 1.0);
                            glTexCoord2f(0.0, 1.0); glVertex2f(-1.0, 1.0);
                            glEnd();
                        } else {
#if ! defined HAVE_MACOSX || OS_VERSION_MAJOR >= 11
                            // Compress
                            glBindVertexArray(encoder->g_vao_422);
                            //glDrawElements(GL_TRIANGLE_STRIP, sizeof(m_quad.indices) / sizeof(m_quad.indices[0]), GL_UNSIGNED_SHORT, BUFFER_OFFSET(0));
                            glDrawArrays(GL_TRIANGLES, 0, 6);
                            glBindVertexArray(0);
#endif
                        }
                        
                        glPopAttrib();
                        /* there is some problem with restoring viewport state (Mac OS Lion, OpenGL 3.2) */
                        glViewport( 0, 0, (encoder->width + 3) / 4, encoder->height / 4);
                        
                        //glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
                        
                        glUseProgram(encoder->program_compress);
                        glBindFramebuffer(GL_FRAMEBUFFER, encoder->fbo_id);
                        glBindTexture(GL_TEXTURE_2D, encoder->texture_id);
                
                        //gl_check_error();
                        break;
                case DXT_FORMAT_YUV:
                case DXT_FORMAT_RGBA:
                        glBindTexture(GL_TEXTURE_2D, encoder->texture_id);
#ifdef USE_PBO_DXT_ENCODER
                        glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, encoder->pbo_in); // current pbo
                        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, encoder->width, encoder->height, GL_RGBA, DXT_IMAGE_GL_TYPE, 0);
                        glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, data_size, 0, GL_STREAM_DRAW_ARB);
                        ptr = (GLubyte*)glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY_ARB);
                        if(ptr)
                        {
                            // update data directly on the mapped buffer
                            memcpy(ptr, image, data_size); 
                            glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB); // release pointer to mapping buffer
                        }
#else
                        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, encoder->width, encoder->height, GL_RGBA, DXT_IMAGE_GL_TYPE, image);
#endif

                        break;
                case DXT_FORMAT_RGB:
                        glBindTexture(GL_TEXTURE_2D, encoder->texture_id);
#ifdef USE_PBO_DXT_ENCODER
                        glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, encoder->pbo_in); // current pbo
                        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, encoder->width, encoder->height, GL_RGB, GL_UNSIGNED_BYTE, 0);
                        glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, data_size, 0, GL_STREAM_DRAW_ARB);
                        ptr = (GLubyte*)glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY_ARB);
                        if(ptr)
                        {
                            // update data directly on the mapped buffer
                            memcpy(ptr, image, data_size); 
                            glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB); // release pointer to mapping buffer
                        }
#else
                        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, encoder->width, encoder->height, GL_RGB, GL_UNSIGNED_BYTE, image);
#endif
                        break;
    }
#ifdef RTDXT_DEBUG
    glEndQuery(GL_TIME_ELAPSED_EXT);
    glBeginQuery(GL_TIME_ELAPSED_EXT, encoder->queries[2]);
#endif
#ifdef RTDXT_DEBUG_HOST
    glFinish();
    TIMER_STOP_PRINT("Tex Load (+->444): ");
    TIMER_START();
#endif

#ifdef HAVE_GPUPERFAPI
    GPA_EndSample();
    GPA_BeginSample(2);
#endif

    return dxt_encoder_compress_texture(encoder, encoder->texture_id, image_compressed);
}