From 22f450477de0a139979d6bbfbd557b40fd4621d3 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 9 Aug 2023 20:40:36 -0500 Subject: [PATCH] Disable HDR encoding for AMF versions below 1.4.23 --- src/platform/windows/display_base.cpp | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/platform/windows/display_base.cpp b/src/platform/windows/display_base.cpp index 4fdf61b2d99..66a687d488d 100644 --- a/src/platform/windows/display_base.cpp +++ b/src/platform/windows/display_base.cpp @@ -19,6 +19,8 @@ typedef long NTSTATUS; #include "src/platform/common.h" #include "src/video.h" +#include + namespace platf { using namespace std::literals; } @@ -485,6 +487,45 @@ namespace platf::dxgi { dup.use_dwmflush = config::video.dwmflush && !(config.framerate > refresh_rate) ? true : false; + // Older versions of the AMD AMF runtime can crash when fed P010 surfaces, so we'll + // check the AMF version if we are using HDR on an AMD GPU to avoid possibly crashing. + if (config.dynamicRange && adapter_desc.VendorId == 0x1002) { + HMODULE amfrt = LoadLibraryW(AMF_DLL_NAME); + if (amfrt) { + auto unload_amfrt = util::fail_guard([amfrt]() { + FreeLibrary(amfrt); + }); + + auto fnAMFQueryVersion = (AMFQueryVersion_Fn) GetProcAddress(amfrt, AMF_QUERY_VERSION_FUNCTION_NAME); + if (fnAMFQueryVersion) { + amf_uint64 version; + auto result = fnAMFQueryVersion(&version); + if (result == AMF_OK) { + // Fail if AMF version is below 1.4.23 where HEVC Main10 encoding was introduced. + // AMF 1.4.23 corresponds to driver version 21.12.1 (21.40.11.03) or newer. + if (version < AMF_MAKE_FULL_VERSION(1, 4, 23, 0)) { + BOOST_LOG(warning) << "HDR encoding is disabled on AMF version "sv + << AMF_GET_MAJOR_VERSION(version) << '.' + << AMF_GET_MINOR_VERSION(version) << '.' + << AMF_GET_SUBMINOR_VERSION(version) << '.' + << AMF_GET_BUILD_VERSION(version); + BOOST_LOG(warning) << "If your AMD GPU supports HEVC Main10 encoding, update your graphics drivers!"sv; + return -1; + } + } + else { + BOOST_LOG(warning) << "AMFQueryVersion() failed: "sv << result; + } + } + else { + BOOST_LOG(warning) << "AMF DLL missing export: "sv << AMF_QUERY_VERSION_FUNCTION_NAME; + } + } + else { + BOOST_LOG(warning) << "Detected AMD GPU but AMF failed to load"sv; + } + } + // Bump up thread priority { const DWORD flags = TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY;