diff --git a/renderdoc/driver/ihv/amd/AMD.vcxproj b/renderdoc/driver/ihv/amd/AMD.vcxproj index 7d896674b..1e817174d 100644 --- a/renderdoc/driver/ihv/amd/AMD.vcxproj +++ b/renderdoc/driver/ihv/amd/AMD.vcxproj @@ -100,11 +100,13 @@ true + + diff --git a/renderdoc/driver/ihv/amd/AMD.vcxproj.filters b/renderdoc/driver/ihv/amd/AMD.vcxproj.filters index d35ce320f..0730a15b2 100644 --- a/renderdoc/driver/ihv/amd/AMD.vcxproj.filters +++ b/renderdoc/driver/ihv/amd/AMD.vcxproj.filters @@ -25,6 +25,9 @@ {47a6fd91-f76e-4faa-9e5c-4bb899be9796} + + {9977fd12-32d0-49d3-b20d-c38b0df2dc95} + @@ -42,6 +45,9 @@ ISA + + RGP + @@ -107,5 +113,6 @@ official\GPUPerfAPI + \ No newline at end of file diff --git a/renderdoc/driver/ihv/amd/CMakeLists.txt b/renderdoc/driver/ihv/amd/CMakeLists.txt index ff8b16b97..f851af96e 100644 --- a/renderdoc/driver/ihv/amd/CMakeLists.txt +++ b/renderdoc/driver/ihv/amd/CMakeLists.txt @@ -5,8 +5,82 @@ set(sources amd_isa.h amd_isa_devices.cpp amd_isa_devices.h - amd_isa_posix.cpp) + amd_isa_posix.cpp + amd_rgp.cpp + amd_rgp.h) + +set(rgp_sources + official/RGP/DevDriverAPI/RGPClientInProcessModel.cpp + official/RGP/DevDriverAPI/RGPClientInProcessModel.h + official/RGP/DevDriverAPI/DevDriverAPI.cpp + official/RGP/DevDriverAPI/DevDriverAPI.h) + +set(dev_driver_sources + official/RGP/DevDriverComponents/listener/ddListenerURIService.cpp + official/RGP/DevDriverComponents/listener/ddListenerURIService.h + official/RGP/DevDriverComponents/listener/hostMsgTransport.h + official/RGP/DevDriverComponents/listener/hostMsgTransport.cpp + official/RGP/DevDriverComponents/listener/listenerServer.h + official/RGP/DevDriverComponents/listener/listenerServer.cpp + official/RGP/DevDriverComponents/listener/transports/hostTransport.h + official/RGP/DevDriverComponents/listener/transports/hostTransport.cpp + official/RGP/DevDriverComponents/listener/routerCore.h + official/RGP/DevDriverComponents/listener/routerCore.cpp + official/RGP/DevDriverComponents/listener/listenerCore.h + official/RGP/DevDriverComponents/listener/listenerCore.cpp + official/RGP/DevDriverComponents/listener/transportThread.h + official/RGP/DevDriverComponents/listener/transportThread.cpp + official/RGP/DevDriverComponents/listener/transports/abstractListenerTransport.h + official/RGP/DevDriverComponents/listener/transports/socketTransport.h + official/RGP/DevDriverComponents/listener/transports/socketTransport.cpp + official/RGP/DevDriverComponents/listener/clientmanagers/abstractClientManager.h + official/RGP/DevDriverComponents/listener/clientmanagers/listenerClientManager.h + official/RGP/DevDriverComponents/listener/clientmanagers/listenerClientManager.cpp + official/RGP/DevDriverComponents/src/baseProtocolClient.cpp + official/RGP/DevDriverComponents/src/baseProtocolServer.cpp + official/RGP/DevDriverComponents/src/ddClientURIService.cpp + official/RGP/DevDriverComponents/src/ddClientURIService.h + official/RGP/DevDriverComponents/src/ddSocket.h + official/RGP/DevDriverComponents/src/ddTransferManager.cpp + official/RGP/DevDriverComponents/src/devDriverClient.cpp + official/RGP/DevDriverComponents/src/devDriverServer.cpp + official/RGP/DevDriverComponents/src/messageChannel.h + official/RGP/DevDriverComponents/src/messageChannel.inl + official/RGP/DevDriverComponents/src/session.h + official/RGP/DevDriverComponents/src/session.cpp + official/RGP/DevDriverComponents/src/sessionManager.h + official/RGP/DevDriverComponents/src/sessionManager.cpp + official/RGP/DevDriverComponents/src/socketMsgTransport.h + official/RGP/DevDriverComponents/src/socketMsgTransport.cpp + official/RGP/DevDriverComponents/src/protocols/ddGpuCrashDumpClient.cpp + official/RGP/DevDriverComponents/src/protocols/ddGpuCrashDumpServer.cpp + official/RGP/DevDriverComponents/src/protocols/ddTransferClient.cpp + official/RGP/DevDriverComponents/src/protocols/ddTransferServer.cpp + official/RGP/DevDriverComponents/src/protocols/ddURIClient.cpp + official/RGP/DevDriverComponents/src/protocols/ddURIServer.cpp + official/RGP/DevDriverComponents/src/protocols/ddURIServer.h + official/RGP/DevDriverComponents/src/protocols/driverControlClient.cpp + official/RGP/DevDriverComponents/src/protocols/driverControlServer.cpp + official/RGP/DevDriverComponents/src/protocols/loggingClient.cpp + official/RGP/DevDriverComponents/src/protocols/loggingServer.cpp + official/RGP/DevDriverComponents/src/protocols/rgpClient.cpp + official/RGP/DevDriverComponents/src/protocols/rgpServer.cpp + official/RGP/DevDriverComponents/src/protocols/settingsClient.cpp + official/RGP/DevDriverComponents/src/protocols/settingsServer.cpp + + official/RGP//DevDriverComponents/src/posix/ddPosixPlatform.cpp + official/RGP//DevDriverComponents/src/posix/ddPosixSocket.cpp +) + +set(include_dirs ${RDOC_INCLUDES}) + +if(UNIX AND NOT ANDROID AND NOT APPLE) + add_compile_options(-D_LINUX -DGPUOPEN_CLIENT_INTERFACE_MAJOR_VERSION=30) + + list(APPEND sources ${dev_driver_sources} ${rgp_sources}) + list(APPEND include_dirs official/RGP/DevDriverComponents/inc) +endif() add_library(rdoc_amd OBJECT ${sources}) target_compile_definitions(rdoc_amd ${RDOC_DEFINITIONS}) -target_include_directories(rdoc_amd ${RDOC_INCLUDES}) +target_include_directories(rdoc_amd ${include_dirs}) diff --git a/renderdoc/driver/ihv/amd/amd_rgp.cpp b/renderdoc/driver/ihv/amd/amd_rgp.cpp new file mode 100644 index 000000000..905f994ee --- /dev/null +++ b/renderdoc/driver/ihv/amd/amd_rgp.cpp @@ -0,0 +1,190 @@ +/****************************************************************************** + * 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 "amd_rgp.h" +#include "common/common.h" +#include "official/RGP/DevDriverAPI/DevDriverAPI.h" + +uint64_t MakeTagFromMarker(const char *marker) +{ + if(!marker) + return 0; + + uint64_t ret = 0; + + for(int i = 0; i < 7 && marker && marker[i]; i++) + ret |= uint64_t(marker[i]) << (i * 8); + + return ret; +} + +const char *AMDRGPControl::GetBeginMarker() +{ + return "BeginRenderDocRGPCapture======"; +} + +const char *AMDRGPControl::GetEndMarker() +{ + return "EndRenderDocRGPCapture======"; +} + +uint64_t AMDRGPControl::GetBeginTag() +{ + return MakeTagFromMarker(GetBeginMarker()); +} + +uint64_t AMDRGPControl::GetEndTag() +{ + return MakeTagFromMarker(GetEndMarker()); +} + +AMDRGPControl::AMDRGPControl() +{ + m_RGPDispatchTable = new DevDriverAPI; + m_RGPDispatchTable->majorVersion = DEV_DRIVER_API_MAJOR_VERSION; + m_RGPDispatchTable->minorVersion = DEV_DRIVER_API_MINOR_VERSION; + m_RGPContext = NULL; + +#if ENABLED(RDOC_WIN32) || ENABLED(RDOC_LINUX) + DevDriverStatus rgpStatus = DevDriverGetFuncTable(m_RGPDispatchTable); + if(rgpStatus == DEV_DRIVER_STATUS_SUCCESS) + { + DevDriverFeatures initOptions[] = { + {DEV_DRIVER_FEATURE_ENABLE_RGP, sizeof(DevDriverFeatureRGP)}, + }; + + int numFeatures = sizeof(initOptions) / sizeof(initOptions[0]); + rgpStatus = m_RGPDispatchTable->DevDriverInit(initOptions, numFeatures, &m_RGPContext); + + // check the driver version if initialization succeeded. + bool supportsInterop = false; + if(rgpStatus == DEV_DRIVER_STATUS_SUCCESS) + { + supportsInterop = DriverSupportsInterop(); + } + + // if initialization failed or driver doesn't support interop + if(supportsInterop == false) + { + if(m_RGPContext != NULL) + m_RGPDispatchTable->DevDriverFinish(m_RGPContext); + m_RGPContext = NULL; + } + } + else +#endif + { + m_RGPContext = NULL; + } +} + +AMDRGPControl::~AMDRGPControl() +{ + if(m_RGPContext != NULL) + m_RGPDispatchTable->DevDriverFinish(m_RGPContext); + + delete m_RGPDispatchTable; + m_RGPContext = NULL; + m_RGPDispatchTable = NULL; +} + +bool AMDRGPControl::Initialised() +{ + return m_RGPContext != NULL; +} + +bool AMDRGPControl::TriggerCapture(const std::string &path) +{ + if(m_RGPContext == NULL) + return false; + + // set up for capturing + RGPProfileOptions profileOptions = {}; + + profileOptions.m_pProfileFilePath = path.c_str(); + + profileOptions.m_beginFrameTerminatorTag = GetBeginTag(); + profileOptions.m_endFrameTerminatorTag = GetEndTag(); + profileOptions.m_pBeginFrameTerminatorString = GetBeginMarker(); + profileOptions.m_pEndFrameTerminatorString = GetEndMarker(); + + DevDriverStatus result = m_RGPDispatchTable->TriggerRgpProfile(m_RGPContext, &profileOptions); + if(result == DEV_DRIVER_STATUS_SUCCESS) + return true; + else + return false; +} + +bool AMDRGPControl::HasCapture() +{ + if(m_RGPContext == NULL) + return false; + + return m_RGPDispatchTable->IsRgpProfileCaptured(m_RGPContext) == DEV_DRIVER_STATUS_SUCCESS; +} + +bool AMDRGPControl::DriverSupportsInterop() +{ + // interop is supported on AMD driver version 18.10 or newer + if(m_RGPContext == NULL) + return false; + + unsigned int majorVersion = 0; + unsigned int minorVersion = 0; + + if(m_RGPDispatchTable->GetDriverVersion(m_RGPContext, majorVersion, minorVersion) == + DEV_DRIVER_STATUS_SUCCESS) + { + if(majorVersion > 18 || (majorVersion == 18 && minorVersion >= 10)) + { + return true; + } + } + return false; +} + +#if ENABLED(ENABLE_UNIT_TESTS) + +#undef None + +#include "3rdparty/catch/catch.hpp" + +TEST_CASE("Check that markers are distinct for begin and end", "[amd]") +{ + std::string beginMark = AMDRGPControl::GetBeginMarker(); + std::string endMark = AMDRGPControl::GetEndMarker(); + + CHECK(beginMark != endMark); + CHECK(beginMark != ""); + CHECK(endMark != ""); + + uint64_t beginTag = AMDRGPControl::GetBeginTag(); + uint64_t endTag = AMDRGPControl::GetEndTag(); + + CHECK(beginTag != endTag); + CHECK(beginTag != 0); + CHECK(endTag != 0); +} + +#endif \ No newline at end of file diff --git a/renderdoc/driver/ihv/amd/amd_rgp.h b/renderdoc/driver/ihv/amd/amd_rgp.h new file mode 100644 index 000000000..ae005cb23 --- /dev/null +++ b/renderdoc/driver/ihv/amd/amd_rgp.h @@ -0,0 +1,54 @@ +/****************************************************************************** + * 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 + +typedef void *DevDriverAPIContext; + +struct DevDriverAPI; + +class AMDRGPControl +{ +public: + AMDRGPControl(); + ~AMDRGPControl(); + + bool Initialised(); + + bool TriggerCapture(const std::string &path); + bool HasCapture(); + bool DriverSupportsInterop(); + + static const char *GetBeginMarker(); + static const char *GetEndMarker(); + + static uint64_t GetBeginTag(); + static uint64_t GetEndTag(); + +private: + DevDriverAPIContext m_RGPContext = NULL; + DevDriverAPI *m_RGPDispatchTable = NULL; +}; \ No newline at end of file