Src/GPUPerfAPICounterGenerator/GPACounterGeneratorDX11.cpp
/// Generates internal counters
/// \param pHardwareCounters the hardware counters to generate
/// \param generation the generation for which counters need to be generated
/// \return true on success
Generates internal counters
\param pHardwareCounters the hardware counters to generate
\param generation the generation for which counters need to be generated
\return true on success
Generates internal counters \ param pHardwareCounters the hardware counters to generate \ param generation the generation for which counters need to be generated \ return true on success
static bool generateInternalCounters(GPA_HardwareCounters* pHardwareCounters, GDT_HW_GENERATION generation)
{
    pHardwareCounters->m_counters.clear();
    GPA_HardwareCounterDescExt counter;
#if defined(_DEBUG) && defined(AMDT_INTERNAL)
    FILE* pFile = nullptr;
    fopen_s(&pFile, "HardwareCounterNamesDX11.txt", "w");
#endif
    unsigned int globalCounterIndex = 0;
    for (unsigned int g = 0; g < (int)pHardwareCounters->m_groupCount; g++)
    {
        GPA_HardwareCounterDesc* pGroupCounters = pHardwareCounters->m_ppCounterGroupArray[g];
        GPA_CounterGroupDesc group = pHardwareCounters->m_pGroups[g];
        if (g == pHardwareCounters->m_gpuTimestampIndex)
        {
            pHardwareCounters->m_gpuTimestampTopCounterIndex = (gpa_uint32)pHardwareCounters->m_counters.size();
        }
        else if (g == pHardwareCounters->m_gpuTimeIndex)
        {
            pHardwareCounters->m_gpuTimeBottomToBottomCounterIndex = (gpa_uint32)pHardwareCounters->m_counters.size();
            pHardwareCounters->m_gpuTimeTopToBottomCounterIndex = (gpa_uint32)pHardwareCounters->m_counters.size() + 1;
        }
        UINT blockId = CalculateBlockIdDX11(generation, &group);
        const gpa_uint64 numCountersInGroup = pHardwareCounters->m_pGroups[g].m_numCounters;
        for (int c = 0; c < numCountersInGroup; c++)
        {
            counter.m_groupIndex = g;
            counter.m_pHardwareCounter = &(pGroupCounters[c]);
            counter.m_groupIdDriver = blockId;
            if (counter.m_groupIndex >= pHardwareCounters->m_gpuTimestampIndex)
            {
                counter.m_counterIdDriver = EncodeGPUTimeCounter(generation, globalCounterIndex);
            }
            else
            {
                counter.m_counterIdDriver = 0;
            }
#if defined(_DEBUG) && defined(AMDT_INTERNAL)
            if (nullptr != pFile)
            {
                fwrite("    \"", 1, 5, pFile);
                std::string tmpName(counter.m_pHardwareCounter->m_pName);
                size_t size = tmpName.size();
                fwrite(counter.m_pHardwareCounter->m_pName, 1, size, pFile);
                fwrite("\",", 1, 2, pFile);
#ifdef EXTRA_COUNTER_INFO
                std::stringstream ss;
                ss << " " << counter.m_groupIndex << ", " << counter.m_groupIdDriver << ", " << counter.m_pHardwareCounter->m_counterIndexInGroup << ", " << counter.m_counterIdDriver;
                std::string tmpCounterInfo(ss.str());
                size = tmpCounterInfo.size();
                fwrite(tmpCounterInfo.c_str(), 1, size, pFile);
#endif
                fwrite("\n", 1, 1, pFile);
            }
#endif
            pHardwareCounters->m_counters.push_back(counter);
            ++globalCounterIndex;
        }
    }
#if defined(_DEBUG) && defined(AMDT_INTERNAL)
    if (nullptr != pFile)
    {
        fclose(pFile);
    }
#endif;
    pHardwareCounters->m_countersGenerated = true;
    return true;
}
static bool generateInternalCounters ( GPA_HardwareCounters * pHardwareCounters , GDT_HW_GENERATION generation ) { pHardwareCounters -> m_counters . clear ( ) ; GPA_HardwareCounterDescExt counter ; #if defined ( _DEBUG ) && defined ( AMDT_INTERNAL ) FILE * pFile = nullptr ; fopen_s ( & pFile , " " , " " ) ; #endif unsigned int globalCounterIndex = 0 ; for ( unsigned int g = 0 ; g < ( int ) pHardwareCounters -> m_groupCount ; g ++ ) { GPA_HardwareCounterDesc * pGroupCounters = pHardwareCounters -> m_ppCounterGroupArray [ g ] ; GPA_CounterGroupDesc group = pHardwareCounters -> m_pGroups [ g ] ; if ( g == pHardwareCounters -> m_gpuTimestampIndex ) { pHardwareCounters -> m_gpuTimestampTopCounterIndex = ( gpa_uint32 ) pHardwareCounters -> m_counters . size ( ) ; } else if ( g == pHardwareCounters -> m_gpuTimeIndex ) { pHardwareCounters -> m_gpuTimeBottomToBottomCounterIndex = ( gpa_uint32 ) pHardwareCounters -> m_counters . size ( ) ; pHardwareCounters -> m_gpuTimeTopToBottomCounterIndex = ( gpa_uint32 ) pHardwareCounters -> m_counters . size ( ) + 1 ; } UINT blockId = CalculateBlockIdDX11 ( generation , & group ) ; const gpa_uint64 numCountersInGroup = pHardwareCounters -> m_pGroups [ g ] . m_numCounters ; for ( int c = 0 ; c < numCountersInGroup ; c ++ ) { counter . m_groupIndex = g ; counter . m_pHardwareCounter = & ( pGroupCounters [ c ] ) ; counter . m_groupIdDriver = blockId ; if ( counter . m_groupIndex >= pHardwareCounters -> m_gpuTimestampIndex ) { counter . m_counterIdDriver = EncodeGPUTimeCounter ( generation , globalCounterIndex ) ; } else { counter . m_counterIdDriver = 0 ; } #if defined ( _DEBUG ) && defined ( AMDT_INTERNAL ) if ( nullptr != pFile ) { fwrite ( " \" " , 1 , 5 , pFile ) ; std :: string tmpName ( counter . m_pHardwareCounter -> m_pName ) ; size_t size = tmpName . size ( ) ; fwrite ( counter . m_pHardwareCounter -> m_pName , 1 , size , pFile ) ; fwrite ( " \" " , 1 , 2 , pFile ) ; #ifdef EXTRA_COUNTER_INFO std :: stringstream ss ; ss << " " << counter . m_groupIndex << " " << counter . m_groupIdDriver << " " << counter . m_pHardwareCounter -> m_counterIndexInGroup << " " << counter . m_counterIdDriver ; std :: string tmpCounterInfo ( ss . str ( ) ) ; size = tmpCounterInfo . size ( ) ; fwrite ( tmpCounterInfo . c_str ( ) , 1 , size , pFile ) ; #endif fwrite ( " \n " , 1 , 1 , pFile ) ; } #endif pHardwareCounters -> m_counters . push_back ( counter ) ; ++ globalCounterIndex ; } } #if defined ( _DEBUG ) && defined ( AMDT_INTERNAL ) if ( nullptr != pFile ) { fclose ( pFile ) ; } #endif ; pHardwareCounters -> m_countersGenerated = true ; return true ; }
Generates internal counters
\param pHardwareCounters the hardware counters to generate
\param generation the generation for which counters need to be generated
\return true on success
Generates internal counters \ param pHardwareCounters the hardware counters to generate \ param generation the generation for which counters need to be generated \ return true on success
// Debug builds will generate a file that lists the counter names in a format that can be // easily copy/pasted into the GPUPerfAPIUnitTests project // for each group, get the group name, number of counters, and max counters (and maybe validate them) // calculate per-block values outside the for loop // only add the number of counters that are supported; but no more than the number that we expect // counterIdDriver is used primarily for pre-SI.  In SI and later, it is used for GPUTimeStamp and GPUTime counters only. // this can be useful for debugging counter definitions