From 714b37ded5c0632c040905f5db1f4376143264ca Mon Sep 17 00:00:00 2001 From: reinsteam Date: Thu, 29 Mar 2018 00:59:57 +0900 Subject: [PATCH] Various fixes for PR - Various style-related fixes - Loading NvPmApi.dll from plugins directories - Added copyright notice to newly added files - Replaced local fixed size array of `char` with std::vector - Removed `FlushGPU` --- renderdoc/driver/d3d11/d3d11_counters.cpp | 38 +--- renderdoc/driver/d3d11/d3d11_replay.cpp | 16 +- renderdoc/driver/ihv/nv/nv_counters.cpp | 247 ++++++++++++---------- renderdoc/driver/ihv/nv/nv_counters.h | 52 +++-- 4 files changed, 189 insertions(+), 164 deletions(-) diff --git a/renderdoc/driver/d3d11/d3d11_counters.cpp b/renderdoc/driver/d3d11/d3d11_counters.cpp index 382012820..0ff200ff9 100644 --- a/renderdoc/driver/d3d11/d3d11_counters.cpp +++ b/renderdoc/driver/d3d11/d3d11_counters.cpp @@ -348,38 +348,6 @@ void D3D11Replay::FillTimersAMD(uint32_t &eventStartID, uint32_t &sampleIndex, } } -static void FlushGPU(WrappedID3D11Device *pDevice, WrappedID3D11DeviceContext *pImmediateContext) -{ - ID3D11Query *pAPIQuery = NULL; - D3D11_QUERY_DESC queryDesc; - queryDesc.Query = D3D11_QUERY_EVENT; - queryDesc.MiscFlags = 0; - if(FAILED(pDevice->CreateQuery(&queryDesc, &pAPIQuery))) - { - return; - } - - HRESULT hr; - pImmediateContext->Flush(); - pImmediateContext->End(pAPIQuery); - pImmediateContext->Flush(); - if(S_OK != (hr = pImmediateContext->GetData(pAPIQuery, NULL, 0, D3D11_ASYNC_GETDATA_DONOTFLUSH))) - { - do - { - if(FAILED(hr)) - { - return; - } - ::Sleep(0); // Give up time slice - } while(S_OK != - (hr = pImmediateContext->GetData(pAPIQuery, NULL, 0, D3D11_ASYNC_GETDATA_DONOTFLUSH))); - } - - if(pAPIQuery) - pAPIQuery->Release(); -} - void D3D11Replay::FillTimersNV(uint32_t &eventStartID, uint32_t &sampleIndex, vector &eventIDs, const DrawcallDescription &drawnode) { @@ -400,13 +368,13 @@ void D3D11Replay::FillTimersNV(uint32_t &eventStartID, uint32_t &sampleIndex, m_pDevice->ReplayLog(eventStartID, d.eventId, eReplay_WithoutDraw); - FlushGPU(m_pDevice, m_pImmediateContext); + SerializeImmediateContext(); m_pNVCounters->BeginSample(sampleIndex); m_pDevice->ReplayLog(eventStartID, d.eventId, eReplay_OnlyDraw); - FlushGPU(m_pDevice, m_pImmediateContext); + SerializeImmediateContext(); m_pNVCounters->EndSample(sampleIndex); @@ -469,7 +437,7 @@ vector D3D11Replay::FetchCountersNV(const vector &cou if(m_pNVCounters->PrepareExperiment(counters, objectsCount)) { - FlushGPU(m_pDevice, m_pImmediateContext); + SerializeImmediateContext(); uint32_t passCount = m_pNVCounters->BeginExperiment(); uint32_t sampleIndex = 0; diff --git a/renderdoc/driver/d3d11/d3d11_replay.cpp b/renderdoc/driver/d3d11/d3d11_replay.cpp index 8eaa8a644..4e7e8fbed 100644 --- a/renderdoc/driver/d3d11/d3d11_replay.cpp +++ b/renderdoc/driver/d3d11/d3d11_replay.cpp @@ -157,28 +157,28 @@ void D3D11Replay::CreateResources() RenderDoc::Inst().SetProgress(LoadProgress::DebugManagerInit, 0.9f); - AMDCounters *pAMDCounters = new AMDCounters(); - NVCounters *pNVCounters = new NVCounters(); + AMDCounters *countersAMD = new AMDCounters(); + NVCounters *countersNV = new NVCounters(); ID3D11Device *d3dDevice = m_pDevice->GetReal(); - if(pAMDCounters->Init(AMDCounters::ApiType::Dx11, (void *)d3dDevice)) + if(countersAMD->Init(AMDCounters::ApiType::Dx11, (void *)d3dDevice)) { - m_pAMDCounters = pAMDCounters; + m_pAMDCounters = countersAMD; } else { - delete pAMDCounters; + delete countersAMD; m_pAMDCounters = NULL; } - if(pNVCounters->Init(d3dDevice)) + if(countersNV->Init(d3dDevice)) { - m_pNVCounters = pNVCounters; + m_pNVCounters = countersNV; } else { - delete pNVCounters; + delete countersNV; m_pNVCounters = NULL; } RenderDoc::Inst().SetProgress(LoadProgress::DebugManagerInit, 1.0f); diff --git a/renderdoc/driver/ihv/nv/nv_counters.cpp b/renderdoc/driver/ihv/nv/nv_counters.cpp index ee8c45fdc..90b27e0ca 100644 --- a/renderdoc/driver/ihv/nv/nv_counters.cpp +++ b/renderdoc/driver/ihv/nv/nv_counters.cpp @@ -1,20 +1,44 @@ +/****************************************************************************** +* The MIT License (MIT) +* +* Copyright (c) 2018 Baldur Karlsson +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +******************************************************************************/ + #include "nv_counters.h" #include "common/common.h" +#include "core/plugins.h" #define NVPM_INITGUID #include "official/PerfKit/include/NvPmApi.h" #include "strings/string_utils.h" -#include - struct EnumCountersCtx { - std::vector mExternalIds; - std::vector mInternalIds; - std::vector mExternalDescriptors; - std::vector mInternalDescriptors; + std::vector m_ExternalIds; + std::vector m_InternalIds; + std::vector m_ExternalDescriptors; + std::vector m_InternalDescriptors; + std::vector m_TmpStr; - NvPmApi *mNvPmApi; + NvPmApi *m_NvPmApi; uint32_t mCurrentCounterId; }; @@ -31,27 +55,27 @@ static bool NvPmResultFails(NVPMRESULT actual, char const *failMsg) int NvPmCountCounters(NVPMCounterID unCounterID, const char *pcCounterName, void *pUserData) { - uint32_t *pNumCounters = static_cast(pUserData); + uint32_t *pNumCounters = (uint32_t *)pUserData; *pNumCounters += 1; return NVPM_OK; } int NvPmGatherCounters(NVPMCounterID unCounterID, const char *pcCounterName, void *pUserData) { - EnumCountersCtx *pEnumCtx = static_cast(pUserData); + EnumCountersCtx *pEnumCtx = (EnumCountersCtx *)pUserData; const uint32_t i = pEnumCtx->mCurrentCounterId; - GPUCounter globalId = static_cast(static_cast(GPUCounter::FirstNvidia) + i); - pEnumCtx->mExternalIds[i] = globalId; - pEnumCtx->mInternalIds[i] = unCounterID; + GPUCounter globalId = (GPUCounter)((uint32_t)GPUCounter::FirstNvidia + i); + pEnumCtx->m_ExternalIds[i] = globalId; + pEnumCtx->m_InternalIds[i] = unCounterID; - CounterDescription &desc = pEnumCtx->mExternalDescriptors[i]; + CounterDescription &desc = pEnumCtx->m_ExternalDescriptors[i]; NVPMUINT64 Attribute = 0; - pEnumCtx->mNvPmApi->GetCounterAttribute(unCounterID, NVPMA_COUNTER_TYPE, &Attribute); - NVPMCOUNTERTYPE Type = static_cast(Attribute); + pEnumCtx->m_NvPmApi->GetCounterAttribute(unCounterID, NVPMA_COUNTER_TYPE, &Attribute); + NVPMCOUNTERTYPE Type = (NVPMCOUNTERTYPE)Attribute; switch(Type) { @@ -68,20 +92,23 @@ int NvPmGatherCounters(NVPMCounterID unCounterID, const char *pcCounterName, voi case NVPM_CT_USER: desc.category = "USER"; break; }; - pEnumCtx->mNvPmApi->GetCounterAttribute(unCounterID, NVPMA_COUNTER_DISPLAY, &Attribute); - NVPMCOUNTERDISPLAY DisplayType = static_cast(Attribute); + pEnumCtx->m_NvPmApi->GetCounterAttribute(unCounterID, NVPMA_COUNTER_DISPLAY, &Attribute); + NVPMCOUNTERDISPLAY DisplayType = (NVPMCOUNTERDISPLAY)Attribute; - pEnumCtx->mNvPmApi->GetCounterAttribute(unCounterID, NVPMA_COUNTER_DOMAIN, &Attribute); + pEnumCtx->m_NvPmApi->GetCounterAttribute(unCounterID, NVPMA_COUNTER_DOMAIN, &Attribute); - pEnumCtx->mNvPmApi->GetCounterAttribute(unCounterID, NVPMA_COUNTER_VALUE_TYPE, &Attribute); - NVPMCOUNTERVALUETYPE ValueType = static_cast(Attribute); + pEnumCtx->m_NvPmApi->GetCounterAttribute(unCounterID, NVPMA_COUNTER_VALUE_TYPE, &Attribute); + NVPMCOUNTERVALUETYPE ValueType = (NVPMCOUNTERVALUETYPE)Attribute; - pEnumCtx->mInternalDescriptors[i] = (DisplayType << 1) | ValueType; + pEnumCtx->m_InternalDescriptors[i] = (DisplayType << 1) | ValueType; if(ValueType == NVPM_VALUE_TYPE_UINT64) { if(DisplayType == NVPM_CD_RATIO) { + // Unfortunately, we can't classify exactly NV counters with display type `Ratio` + // because sometimes they could be `percents` and sometimes 'ratios' (avg. instructions per + // shader invocation, for example) desc.unit = CounterUnit::Ratio; desc.resultType = CompType::Double; desc.resultByteWidth = sizeof(double); @@ -101,17 +128,22 @@ int NvPmGatherCounters(NVPMCounterID unCounterID, const char *pcCounterName, voi " normalization for counters with DisplayType == NVPM_CD_RATIO and ValueType == " "NVPM_VALUE_TYPE_FLOAT64 is unhandled"); } + // Same problem as for counters with 'ratio' display type but: + // don't know for sure if a counter should be displayed as is or annotated with `%` symbol desc.unit = CounterUnit::Ratio; desc.resultType = CompType::Double; desc.resultByteWidth = sizeof(double); } - char Description[512]; - NVPMUINT DescriptionSize = sizeof(Description); - pEnumCtx->mNvPmApi->GetCounterDescription(unCounterID, Description, &DescriptionSize); + char DummyChar = '\0'; + NVPMUINT DescriptionSize = 0; + pEnumCtx->m_NvPmApi->GetCounterDescription(unCounterID, &DummyChar, &DescriptionSize); + pEnumCtx->m_TmpStr.resize(DescriptionSize); + pEnumCtx->m_NvPmApi->GetCounterDescription(unCounterID, pEnumCtx->m_TmpStr.data(), + &DescriptionSize); desc.counter = globalId; - desc.description = Description; + desc.description = pEnumCtx->m_TmpStr.data(); desc.name = pcCounterName; desc.uuid.words[0] = 0xC8958C90; @@ -125,59 +157,68 @@ int NvPmGatherCounters(NVPMCounterID unCounterID, const char *pcCounterName, voi } NVCounters::NVCounters() - : mNvPmLib(NULL), mNvPmApi(NULL), mNvPmCtx(static_cast(-1)), mObjectsCount(0) + : m_NvPmLib(NULL), m_NvPmApi(NULL), m_NvPmCtx((uint64_t)-1), m_ObjectsCount(0) { } NVCounters::~NVCounters() { - if(mObjectsCount != 0) + if(m_ObjectsCount != 0) { - NvPmResultFails(mNvPmApi->DeleteObjects(mNvPmCtx), "call to 'NvPmApi::DeleteObjects'"); - mObjectsCount = 0; + NvPmResultFails(m_NvPmApi->DeleteObjects(m_NvPmCtx), "call to 'NvPmApi::DeleteObjects'"); + m_ObjectsCount = 0; } - if(mNvPmCtx != static_cast(-1)) + if(m_NvPmCtx != (uint64_t)-1) { - NvPmResultFails(mNvPmApi->DestroyContext(mNvPmCtx), "call to 'NvPmApi::DestroyContext'"); - mNvPmCtx = static_cast(-1); + NvPmResultFails(m_NvPmApi->DestroyContext(m_NvPmCtx), "call to 'NvPmApi::DestroyContext'"); + m_NvPmCtx = (uint64_t)-1; } - if(mNvPmApi != 0) + if(m_NvPmApi != NULL) { - NvPmResultFails(mNvPmApi->Shutdown(), "call to 'NvPmApi::Shutdown'"); - mNvPmApi = NULL; + NvPmResultFails(m_NvPmApi->Shutdown(), "call to 'NvPmApi::Shutdown'"); + m_NvPmApi = NULL; } - mNvPmLib = NULL; + m_NvPmLib = NULL; } bool NVCounters::Init() { - if(mNvPmLib != NULL) + if(m_NvPmLib != NULL) { return false; } +#if ENABLED(RDOC_WIN32) - mNvPmLib = Process::LoadModule("NvPmApi.Core.dll"); - if(mNvPmLib == NULL) +#if ENABLED(RDOC_X64) + std::string dllPath = LocatePluginFile("nv/counters/x64", "NvPmApi.Core.dll"); +#else + std::string dllPath = LocatePluginFile("nv/counters/x86", "NvPmApi.Core.dll"); +#endif + +#endif + + m_NvPmLib = Process::LoadModule(dllPath.c_str()); + if(m_NvPmLib == NULL) { RDCWARN("NV GPU performance counters could not locate 'NvPmApi.Core.dll'"); return false; } NVPMGetExportTable_Pfn pfnGetExportTable = - (NVPMGetExportTable_Pfn)Process::GetFunctionAddress(mNvPmLib, "NVPMGetExportTable"); + (NVPMGetExportTable_Pfn)Process::GetFunctionAddress(m_NvPmLib, "NVPMGetExportTable"); if(pfnGetExportTable == NULL) { return false; } - if(NvPmResultFails(pfnGetExportTable(&ETID_NvPmApi, (void **)&mNvPmApi), "get 'NvPmApi' table")) + if(NvPmResultFails(pfnGetExportTable(&ETID_NvPmApi, (void **)&m_NvPmApi), "get 'NvPmApi' table")) { return false; } - if(NvPmResultFails(mNvPmApi->Init(), "init 'NvPmApi'")) + if(NvPmResultFails(m_NvPmApi->Init(), "init 'NvPmApi'")) { return false; } @@ -191,77 +232,77 @@ bool NVCounters::Init(ID3D11Device *pDevice) return false; } - if(NvPmResultFails(mNvPmApi->CreateContextFromD3D11Device(pDevice, &mNvPmCtx), + if(NvPmResultFails(m_NvPmApi->CreateContextFromD3D11Device(pDevice, &m_NvPmCtx), "init 'NVPMContext' from ID3D11Device")) { return false; } uint32_t NumCounters = 0; - mNvPmApi->EnumCountersByContextUserData(mNvPmCtx, NvPmCountCounters, &NumCounters); + m_NvPmApi->EnumCountersByContextUserData(m_NvPmCtx, NvPmCountCounters, &NumCounters); EnumCountersCtx ctx; - ctx.mExternalIds.resize(NumCounters); - ctx.mInternalIds.resize(NumCounters); - ctx.mExternalDescriptors.resize(NumCounters); - ctx.mInternalDescriptors.resize(NumCounters); - ctx.mNvPmApi = mNvPmApi; + ctx.m_ExternalIds.resize(NumCounters); + ctx.m_InternalIds.resize(NumCounters); + ctx.m_ExternalDescriptors.resize(NumCounters); + ctx.m_InternalDescriptors.resize(NumCounters); + ctx.m_NvPmApi = m_NvPmApi; ctx.mCurrentCounterId = 0; - mNvPmApi->EnumCountersByContextUserData(mNvPmCtx, NvPmGatherCounters, &ctx); + m_NvPmApi->EnumCountersByContextUserData(m_NvPmCtx, NvPmGatherCounters, &ctx); - ctx.mExternalIds.swap(mExternalIds); - ctx.mInternalIds.swap(mInternalIds); - ctx.mExternalDescriptors.swap(mExternalDescriptors); - ctx.mInternalDescriptors.swap(mInternalDescriptors); + ctx.m_ExternalIds.swap(m_ExternalIds); + ctx.m_InternalIds.swap(m_InternalIds); + ctx.m_ExternalDescriptors.swap(m_ExternalDescriptors); + ctx.m_InternalDescriptors.swap(m_InternalDescriptors); - mSelectedExternalIds.reserve(NumCounters); - mSelectedInternalIds.reserve(NumCounters); + m_SelectedExternalIds.reserve(NumCounters); + m_SelectedInternalIds.reserve(NumCounters); return true; } bool NVCounters::PrepareExperiment(const std::vector &counters, uint32_t objectsCount) { - if(NvPmResultFails(mNvPmApi->RemoveAllCounters(mNvPmCtx), "call to 'NvPmApi::RemoveAllCounters'")) + if(NvPmResultFails(m_NvPmApi->RemoveAllCounters(m_NvPmCtx), + "call to 'NvPmApi::RemoveAllCounters'")) { return false; } - mSelectedExternalIds.clear(); - mSelectedInternalIds.clear(); + m_SelectedExternalIds.clear(); + m_SelectedInternalIds.clear(); - std::for_each(counters.begin(), counters.end(), - [&selExternalIds = mSelectedExternalIds, &selInternalIds = mSelectedInternalIds, - &internalIds = mInternalIds](GPUCounter counter) { - const uint32_t externalId = static_cast(counter) - - static_cast(GPUCounter::FirstNvidia); - selExternalIds.push_back(counter); - selInternalIds.push_back(internalIds[externalId]); - }); + const size_t numCounters = counters.size(); - if(NvPmResultFails( - mNvPmApi->AddCounters(mNvPmCtx, static_cast(mSelectedInternalIds.size()), - mSelectedInternalIds.data()), - "call to 'NvPmApi::AddCounters'")) + for(size_t i = 0; i < numCounters; ++i) + { + const uint32_t externalId = (uint64_t)counters[i] - (uint64_t)GPUCounter::FirstNvidia; + m_SelectedExternalIds.push_back(counters[i]); + m_SelectedInternalIds.push_back(m_InternalIds[externalId]); + } + + if(NvPmResultFails(m_NvPmApi->AddCounters(m_NvPmCtx, (NVPMUINT)m_SelectedInternalIds.size(), + m_SelectedInternalIds.data()), + "call to 'NvPmApi::AddCounters'")) { return false; } - if(mObjectsCount != objectsCount) + if(m_ObjectsCount != objectsCount) { - if(mObjectsCount != 0) + if(m_ObjectsCount != 0) { - NvPmResultFails(mNvPmApi->DeleteObjects(mNvPmCtx), "call to 'NvPmApi::DeleteObjects'"); - mObjectsCount = 0; + NvPmResultFails(m_NvPmApi->DeleteObjects(m_NvPmCtx), "call to 'NvPmApi::DeleteObjects'"); + m_ObjectsCount = 0; } - if(NvPmResultFails(mNvPmApi->ReserveObjects(mNvPmCtx, objectsCount), + if(NvPmResultFails(m_NvPmApi->ReserveObjects(m_NvPmCtx, objectsCount), "call to 'NvPmApi::ReserveObjects'")) { return false; } - mObjectsCount = objectsCount; + m_ObjectsCount = objectsCount; } return true; } @@ -269,7 +310,7 @@ bool NVCounters::PrepareExperiment(const std::vector &counters, uint uint32_t NVCounters::BeginExperiment() const { NVPMUINT NumPasses = 0; - if(NvPmResultFails(mNvPmApi->BeginExperiment(mNvPmCtx, &NumPasses), + if(NvPmResultFails(m_NvPmApi->BeginExperiment(m_NvPmCtx, &NumPasses), "call to 'NvPmApi::BeginExperiment'")) { return 0; @@ -280,42 +321,36 @@ uint32_t NVCounters::BeginExperiment() const void NVCounters::EndExperiment(const std::vector &eventIds, std::vector &Result) const { - NvPmResultFails(mNvPmApi->EndExperiment(mNvPmCtx), "call to 'NvPmApi::EndExperiment'"); + NvPmResultFails(m_NvPmApi->EndExperiment(m_NvPmCtx), "call to 'NvPmApi::EndExperiment'"); - // NVPMUINT NumCounters = mObjectsCount; - // NVPMRESULT result = mNvPmApi->SampleEx(mNvPmCtx, Samples.data(), &NumCounters); - // NvPmResultFails(result, "call to 'NvPmApi::SampleEx'"); - // mNvPmApi->GetCounterValue(); + Result.reserve(m_SelectedExternalIds.size() * m_ObjectsCount); - Result.reserve(mSelectedExternalIds.size() * mObjectsCount); - - for(uint32_t counterIdx = 0; counterIdx < mSelectedExternalIds.size(); ++counterIdx) + for(uint32_t counterIdx = 0; counterIdx < m_SelectedExternalIds.size(); ++counterIdx) { - const GPUCounter counter = mSelectedExternalIds[counterIdx]; + const GPUCounter counter = m_SelectedExternalIds[counterIdx]; - const uint32_t externalId = - static_cast(counter) - static_cast(GPUCounter::FirstNvidia); + const uint32_t externalId = (uint32_t)counter - (uint32_t)GPUCounter::FirstNvidia; - const NVPMCounterID internalId = mInternalIds[externalId]; + const NVPMCounterID internalId = m_InternalIds[externalId]; - const uint32_t internalDesc = mInternalDescriptors[externalId]; + const uint32_t internalDesc = m_InternalDescriptors[externalId]; - const NVPMCOUNTERDISPLAY displayType = static_cast(internalDesc >> 1); - const NVPMCOUNTERTYPE counterType = static_cast(internalDesc & 1); + const NVPMCOUNTERDISPLAY displayType = (NVPMCOUNTERDISPLAY)(internalDesc >> 1); + const NVPMCOUNTERVALUETYPE counterType = (NVPMCOUNTERVALUETYPE)(internalDesc & 1); if(counterType == NVPM_VALUE_TYPE_UINT64) { if(displayType == NVPM_CD_RATIO) { - for(uint32_t i = 0; i < mObjectsCount; ++i) + for(uint32_t i = 0; i < m_ObjectsCount; ++i) { NVPMUINT64 Value; NVPMUINT64 Cycles; NVPMUINT8 Overflow; NVPMRESULT result = - mNvPmApi->GetCounterValueUint64(mNvPmCtx, internalId, i, &Value, &Cycles, &Overflow); + m_NvPmApi->GetCounterValueUint64(m_NvPmCtx, internalId, i, &Value, &Cycles, &Overflow); - double Ratio = static_cast(Value) / static_cast(Cycles); + double Ratio = (double)Value / (double)Cycles; Result.push_back(CounterResult(eventIds[i], counter, Ratio)); (void)result; @@ -323,13 +358,13 @@ void NVCounters::EndExperiment(const std::vector &eventIds, } else { - for(uint32_t i = 0; i < mObjectsCount; ++i) + for(uint32_t i = 0; i < m_ObjectsCount; ++i) { NVPMUINT64 Value; NVPMUINT64 Cycles; NVPMUINT8 Overflow; NVPMRESULT result = - mNvPmApi->GetCounterValueUint64(mNvPmCtx, internalId, i, &Value, &Cycles, &Overflow); + m_NvPmApi->GetCounterValueUint64(m_NvPmCtx, internalId, i, &Value, &Cycles, &Overflow); Result.push_back(CounterResult(eventIds[i], counter, Value)); @@ -339,13 +374,13 @@ void NVCounters::EndExperiment(const std::vector &eventIds, } else { - for(uint32_t i = 0; i < mObjectsCount; ++i) + for(uint32_t i = 0; i < m_ObjectsCount; ++i) { NVPMFLOAT64 Value; NVPMUINT64 Cycles; NVPMUINT8 Overflow; NVPMRESULT result = - mNvPmApi->GetCounterValueFloat64(mNvPmCtx, internalId, i, &Value, &Cycles, &Overflow); + m_NvPmApi->GetCounterValueFloat64(m_NvPmCtx, internalId, i, &Value, &Cycles, &Overflow); Result.push_back(CounterResult(eventIds[i], counter, Value)); @@ -357,22 +392,22 @@ void NVCounters::EndExperiment(const std::vector &eventIds, void NVCounters::BeginPass(uint32_t passIdx) const { - NvPmResultFails(mNvPmApi->BeginPass(mNvPmCtx, passIdx), "call to 'NvPmApi::BeginPass'"); + NvPmResultFails(m_NvPmApi->BeginPass(m_NvPmCtx, passIdx), "call to 'NvPmApi::BeginPass'"); } void NVCounters::EndPass(uint32_t passIdx) const { - NvPmResultFails(mNvPmApi->EndPass(mNvPmCtx, passIdx), "call to 'NvPmApi::EndPass'"); + NvPmResultFails(m_NvPmApi->EndPass(m_NvPmCtx, passIdx), "call to 'NvPmApi::EndPass'"); } void NVCounters::BeginSample(uint32_t sampleIdx) const { - RDCASSERT(sampleIdx < mObjectsCount); - NvPmResultFails(mNvPmApi->BeginObject(mNvPmCtx, sampleIdx), "call to 'NvPmApi::BeginObject'"); + RDCASSERT(sampleIdx < m_ObjectsCount); + NvPmResultFails(m_NvPmApi->BeginObject(m_NvPmCtx, sampleIdx), "call to 'NvPmApi::BeginObject'"); } void NVCounters::EndSample(uint32_t sampleIdx) const { - RDCASSERT(sampleIdx < mObjectsCount); - NvPmResultFails(mNvPmApi->EndObject(mNvPmCtx, sampleIdx), "call to 'NvPmApi::EndObject'"); + RDCASSERT(sampleIdx < m_ObjectsCount); + NvPmResultFails(m_NvPmApi->EndObject(m_NvPmCtx, sampleIdx), "call to 'NvPmApi::EndObject'"); } diff --git a/renderdoc/driver/ihv/nv/nv_counters.h b/renderdoc/driver/ihv/nv/nv_counters.h index c2e8b182d..022b8e734 100644 --- a/renderdoc/driver/ihv/nv/nv_counters.h +++ b/renderdoc/driver/ihv/nv/nv_counters.h @@ -1,3 +1,27 @@ +/****************************************************************************** +* The MIT License (MIT) +* +* Copyright (c) 2018 Baldur Karlsson +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +******************************************************************************/ + #pragma once #include @@ -14,13 +38,11 @@ public: bool Init(ID3D11Device *pDevice); - std::vector GetPublicCounterIds() const { return mExternalIds; } - + std::vector GetPublicCounterIds() const { return m_ExternalIds; } CounterDescription GetCounterDescription(GPUCounter counterID) const { - const uint32_t LocalId = - static_cast(counterID) - static_cast(GPUCounter::FirstNvidia); - return mExternalDescriptors[LocalId]; + const uint32_t LocalId = (uint32_t)counterID - (uint32_t)GPUCounter::FirstNvidia; + return m_ExternalDescriptors[LocalId]; } bool PrepareExperiment(const std::vector &counters, uint32_t objectsCount); @@ -38,15 +60,15 @@ public: private: bool Init(void); - void *mNvPmLib; - struct _NvPmApi *mNvPmApi; - uint64_t mNvPmCtx; - uint32_t mObjectsCount; + void *m_NvPmLib; + struct _NvPmApi *m_NvPmApi; + uint64_t m_NvPmCtx; + uint32_t m_ObjectsCount; - std::vector mExternalIds; - std::vector mInternalIds; - std::vector mSelectedExternalIds; - std::vector mSelectedInternalIds; - std::vector mExternalDescriptors; - std::vector mInternalDescriptors; + std::vector m_ExternalIds; + std::vector m_InternalIds; + std::vector m_SelectedExternalIds; + std::vector m_SelectedInternalIds; + std::vector m_ExternalDescriptors; + std::vector m_InternalDescriptors; };