GXReadGP1Metric

C Specification

#include <revolution/gx.h>
u32 GXReadGP1Metric( void );

Arguments

None.

Return Values

The current unsigned 32-bit value (u32) for the GP counter 1.

Description

The Graphics Processor (GP) can count many internal events that give detailed information on performance. This convenient function returns the current value of performance counter 1, perf1. After the current value of the counter is read, the counter is reset. The metric to be measured is set using GXSetGP1Metric. The initial metric measured is GX_PERF1_NONE which returns zero for the first call to GXReadGP1Metric. If you want to monitor GP counter 0 and 1 at the same time, use GXSetGPMetric/GXReadGPMetric.

This function reads results from CPU-accessible registers in the GP; this command must not be used in a display list. Furthermore, in some cases the performance counters are triggered by sending tokens through the graphics FIFO to the GP. This implies that the function should only be used in immediate mode (when the graphics FIFO is connected simultaneously to the CPU and the GP). It may also be necessary to send a draw sync token using GXSetDrawSync or call GXSetDrawDone after GXReadGP1Metric to ensure that the state has actually been processed by the GP.

GXSetGP0Metric( GX_PERF0_NONE );
GXSetGP1Metric( GX_PERF1_TEXELS );
drawSphere();
GXSetDrawSync(0xbabe);
while (0xbabe != GXReadDrawSync())
    ;
count = GXReadGP1Metric();
OSReport("Number of texels in sphere: %d\n", count);

The GXReadGP1Metric function can be used in the callback associated with the draw sync interrupt. Refer to GXSetDrawSyncCallback. Because it inserts random tokens in the GP command stream, the GXSetGPMetric function should not be used in the draw sync callback.

#define OBJECTS 3
u32 count[OBJECTS]

void myDrawSyncCallback( u16 token )
{
    count[token - 1] = GXReadGP1Metric();
}

void myDraw( void )
{
    GXSetDrawSyncCallback( myDrawSyncCallback );
    GXSetGP1Metric( GX_PERF1_TEXELS );
    drawSphere();
    GXSetDrawSync(0x1);
    drawCube();
    GXSetDrawSync(0x2);
    drawCylinder();
    GXSetDrawSync(0x3);
    GXDrawDone();
    for (i = 0; i < OBJECTS; i++)
        OSReport("texels object %d: %d\n", i, count[i]);
}

Each performance counter has a unique set of events or ratios that it can count. In some cases the same metric can be counted using both counters. For example, there are GX_PERF0_VERTICES and GX_PERF1_VERTICES. Ratios (metric names ending in _RATIO) are multiplied by 1000 (1000 = all misses/clips, etc., 0 = no misses/clips, etc.).

Counter 1 Details

For details on the metrics that GP counter 1 can measure, see the GXSetGP1Metric function.

See Also

GXReadMemMetric
GXClearMemMetric
GXReadPixMetric
GXClearPixMetric
GXReadVCacheMetric
GXSetVCacheMetric
GXClearVCacheMetric

Revision History

03/01/2006 Initial version.