Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
/// Given a sessionID, query the counter values and save them to a file
static void WriteSession( gpa_uint32 currentWaitSessionID,
        const char* filename )
{
    static bool doneHeadings = FALSE;
    gpa_uint32 count;
    GPA_GetEnabledCount( &count );
    FILE* f;
    if ( !doneHeadings )
    {
        const char* name;
        f = fopen( filename, "w" );
        assert( f );
        fprintf( f, "Identifier, " );
        for (gpa_uint32 counter = 0 ; counter < count ; counter++ )
        {
            gpa_uint32 enabledCounterIndex;
            GPA_GetEnabledIndex( counter, &enabledCounterIndex );
            GPA_GetCounterName( enabledCounterIndex, &name );
            fprintf( f, "%s, ", name );
        }
        fprintf( f, "\n" );
        fclose( f );
        doneHeadings = TRUE;
    }
    f = fopen( filename, "a+" );
    assert( f );
    gpa_uint32 sampleCount;
    GPA_GetSampleCount( currentWaitSessionID, &sampleCount );
    for (gpa_uint32 sample = 0 ; sample < sampleCount ; sample++ )
    {
        fprintf( f, "session: %d; sample: %d, ", currentWaitSessionID,
                sample );
        for (gpa_uint32 counter = 0 ; counter < count ; counter++ )
        {
            gpa_uint32 enabledCounterIndex;
            GPA_GetEnabledIndex( counter, &enabledCounterIndex );
            GPA_Type type;
            GPA_GetCounterDataType( enabledCounterIndex, &type );
            if ( type == GPA_TYPE_UINT32 )
            {
                gpa_uint32 value;
                GPA_GetSampleUInt32( currentWaitSessionID,
                        sample, enabledCounterIndex, &value );
                fprintf( f, "%u,", value );
            }
            else if ( type == GPA_TYPE_UINT64 )
            {
                gpa_uint64 value;
                GPA_GetSampleUInt64( currentWaitSessionID,
                        sample, enabledCounterIndex, &value );
                fprintf( f, "%lu,", value );
            }
            else if ( type == GPA_TYPE_FLOAT32 )
            {
                gpa_float32 value;
                GPA_GetSampleFloat32( currentWaitSessionID,
                        sample, enabledCounterIndex, &value );
                fprintf( f, "%f,", (double) value );
            }
            else if ( type == GPA_TYPE_FLOAT64 )
            {
                gpa_float64 value;
                GPA_GetSampleFloat64( currentWaitSessionID,
                        sample, enabledCounterIndex, &value );
                fprintf( f, "%f,", value );
            }
            else
            {
                assert(FALSE);
            }
        }
        fprintf( f, "\n" );
    }
    fclose( f );
}