From 288e0239c211e73ee218db60309b682b5a4e8e3c Mon Sep 17 00:00:00 2001 From: Amit Prakash Date: Wed, 23 May 2018 18:01:04 -0400 Subject: [PATCH] Fix Baldur review Change-Id: I4430d0ec658ec9859226086a879c3e134a20b5e4 --- renderdoc/core/core.cpp | 2 ++ renderdoc/core/core.h | 7 +++++ renderdoc/driver/d3d12/d3d12_hooks.cpp | 2 +- renderdoc/driver/ihv/amd/amd_counters.cpp | 31 +++++++++-------------- renderdoc/driver/ihv/amd/amd_counters.h | 10 ++++---- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/renderdoc/core/core.cpp b/renderdoc/core/core.cpp index 1526a2617..6cae03585 100644 --- a/renderdoc/core/core.cpp +++ b/renderdoc/core/core.cpp @@ -227,6 +227,8 @@ RenderDoc::RenderDoc() m_TargetControlThreadShutdown = false; m_ControlClientThreadShutdown = false; + + m_DX12DebugLayerEnabled = false; } void RenderDoc::Initialise() diff --git a/renderdoc/core/core.h b/renderdoc/core/core.h index 7b18d9572..df367d51f 100644 --- a/renderdoc/core/core.h +++ b/renderdoc/core/core.h @@ -538,6 +538,11 @@ public: string GetOverlayText(RDCDriver driver, uint32_t frameNumber, int flags); + void SetDX12DebugLayerEnabled(const bool &enableDX12DebugLayer) + { + m_DX12DebugLayerEnabled = enableDX12DebugLayer; + } + bool IsDX12DebugLayerEnabled() const { return m_DX12DebugLayerEnabled; } private: RenderDoc(); ~RenderDoc(); @@ -653,6 +658,8 @@ private: static void TargetControlClientThread(uint32_t version, Network::Socket *client); ICrashHandler *m_ExHandler; + + bool m_DX12DebugLayerEnabled; }; struct DriverRegistration diff --git a/renderdoc/driver/d3d12/d3d12_hooks.cpp b/renderdoc/driver/d3d12/d3d12_hooks.cpp index be983f8a0..de80d4b12 100644 --- a/renderdoc/driver/d3d12/d3d12_hooks.cpp +++ b/renderdoc/driver/d3d12/d3d12_hooks.cpp @@ -211,7 +211,7 @@ private: if(SUCCEEDED(hr) && debug) { debug->EnableDebugLayer(); - + RenderDoc::Inst().SetDX12DebugLayerEnabled(true); RDCDEBUG("Enabling debug layer"); // enable this to get GPU-based validation, where available, whenever we enable API validation diff --git a/renderdoc/driver/ihv/amd/amd_counters.cpp b/renderdoc/driver/ihv/amd/amd_counters.cpp index 850c82e59..87672aad7 100644 --- a/renderdoc/driver/ihv/amd/amd_counters.cpp +++ b/renderdoc/driver/ihv/amd/amd_counters.cpp @@ -25,6 +25,7 @@ #include "amd_counters.h" #include "common/common.h" #include "common/timing.h" +#include "core/core.h" #include "core/plugins.h" #include "official/GPUPerfAPI/Include/GPUPerfAPIFunctionTypes.h" #include "strings/string_utils.h" @@ -111,9 +112,7 @@ bool AMDCounters::Init(ApiType apiType, void *pContext) bool disableCounters = false; -#ifndef RELEASE - - if(apiType == ApiType::Dx12) + if(apiType == ApiType::Dx12 && RenderDoc::Inst().IsDX12DebugLayerEnabled()) { // Disable counters in DX12 Debug configuration void *versionFunc = Process::GetFunctionAddress(module, "GPA_GetVersion"); @@ -123,7 +122,6 @@ bool AMDCounters::Init(ApiType apiType, void *pContext) disableCounters = true; } } -#endif if(disableCounters) { @@ -147,7 +145,7 @@ bool AMDCounters::Init(ApiType apiType, void *pContext) } else { - delete m_pGPUPerfAPI; + SAFE_DELETE(m_pGPUPerfAPI); RDCERR("Failed to get GPA function table. Invalid dynamic library?"); return false; } @@ -167,8 +165,7 @@ bool AMDCounters::Init(ApiType apiType, void *pContext) if(AMD_FAILED(status)) { GPA_ERROR("Initialization failed", status); - delete m_pGPUPerfAPI; - m_pGPUPerfAPI = NULL; + SAFE_DELETE(m_pGPUPerfAPI); return false; } @@ -179,8 +176,7 @@ bool AMDCounters::Init(ApiType apiType, void *pContext) { GPA_WARNING("Open context for counters failed", status); m_pGPUPerfAPI->GPA_Destroy(); - delete m_pGPUPerfAPI; - m_pGPUPerfAPI = NULL; + SAFE_DELETE(m_pGPUPerfAPI); return false; } @@ -218,7 +214,7 @@ AMDCounters::~AMDCounters() GPA_ERROR("Destroy failed", status); } - delete m_pGPUPerfAPI; + SAFE_DELETE(m_pGPUPerfAPI); } } @@ -448,7 +444,7 @@ uint32_t AMDCounters::GetPassCount() uint32_t AMDCounters::CreateSession() { uint32_t sessionID = m_gpaSessionCounter; - GPA_SessionId gpaSessionId = nullptr; + GPA_SessionId gpaSessionId = NULL; GPA_Status status = m_pGPUPerfAPI->GPA_CreateSession( m_gpaContextId, GPA_SESSION_SAMPLE_TYPE_DISCRETE_COUNTER, &gpaSessionId); @@ -498,7 +494,7 @@ void AMDCounters::InitializeCmdInfo() case ApiType::Ogl: break; case ApiType::Vk: case ApiType::Dx12: - if(nullptr == m_gpaCmdListInfo.m_pCommandListMap) + if(NULL == m_gpaCmdListInfo.m_pCommandListMap) { m_gpaCmdListInfo.m_pCommandListMap = new std::map(); } @@ -513,10 +509,7 @@ void AMDCounters::DeInitializeCmdInfo() case ApiType::Dx11: case ApiType::Ogl: break; case ApiType::Vk: - case ApiType::Dx12: - delete m_gpaCmdListInfo.m_pCommandListMap; - m_gpaCmdListInfo.m_pCommandListMap = nullptr; - break; + case ApiType::Dx12: SAFE_DELETE(m_gpaCmdListInfo.m_pCommandListMap); break; } } @@ -656,7 +649,7 @@ void AMDCounters::BeginPass() if(m_apiType == ApiType::Dx12 || m_apiType == ApiType::Vk) { - if(nullptr != m_gpaCmdListInfo.m_pCommandListMap) + if(NULL != m_gpaCmdListInfo.m_pCommandListMap) { m_gpaCmdListInfo.m_pCommandListMap->clear(); } @@ -735,7 +728,7 @@ void AMDCounters::EndSample(void *pCommandList) void AMDCounters::BeginCommandList(void *pCommandList) { - void *cmdList = nullptr; + void *cmdList = NULL; GPA_Command_List_Type cmdType = GPA_COMMAND_LIST_NONE; switch(m_apiType) { @@ -748,7 +741,7 @@ void AMDCounters::BeginCommandList(void *pCommandList) break; } - GPA_CommandListId gpaCmdId = nullptr; + GPA_CommandListId gpaCmdId = NULL; GPA_Status status = m_pGPUPerfAPI->GPA_BeginCommandList(m_gpaSessionInfo.back(), m_passCounter, cmdList, cmdType, &gpaCmdId); diff --git a/renderdoc/driver/ihv/amd/amd_counters.h b/renderdoc/driver/ihv/amd/amd_counters.h index 46d3ec5c1..5d4631016 100644 --- a/renderdoc/driver/ihv/amd/amd_counters.h +++ b/renderdoc/driver/ihv/amd/amd_counters.h @@ -70,11 +70,11 @@ public: void BeginPass(); void EndPass(); - void BeginCommandList(void *pCommandList = nullptr); - void EndCommandList(void *pCommandList = nullptr); + void BeginCommandList(void *pCommandList = NULL); + void EndCommandList(void *pCommandList = NULL); - void BeginSample(uint32_t sampleID, void *pCommandList = nullptr); - void EndSample(void *pCommandList = nullptr); + void BeginSample(uint32_t sampleID, void *pCommandList = NULL); + void EndSample(void *pCommandList = NULL); // Session data retrieval std::vector GetCounterData(uint32_t sessionID, uint32_t maxSampleIndex, @@ -92,7 +92,7 @@ private: GPA_CommandListId m_gpaCommandListId; std::map *m_pCommandListMap; - GPACmdListInfo() : m_pCommandListMap(nullptr) {} + GPACmdListInfo() : m_pCommandListMap(NULL) {} ~GPACmdListInfo() {} };