From cbe742cbbb51c2140a0852d717732afe71709cb9 Mon Sep 17 00:00:00 2001 From: Radu Grecu Date: Wed, 9 Oct 2024 21:04:02 +0200 Subject: [PATCH] AMD Display Capture documentation and fixes * Remove AMD Trace and debug statements * Add code comments --- src/platform/windows/display.h | 11 +++++++--- src/platform/windows/display_amd.cpp | 30 +++------------------------ src/platform/windows/display_base.cpp | 18 ++++++++-------- src/platform/windows/display_vram.cpp | 2 +- src/video.cpp | 1 - 5 files changed, 21 insertions(+), 41 deletions(-) diff --git a/src/platform/windows/display.h b/src/platform/windows/display.h index 331832c5b74..4e8e8aae76d 100644 --- a/src/platform/windows/display.h +++ b/src/platform/windows/display.h @@ -4,6 +4,8 @@ */ #pragma once +#include +#include #include #include #include @@ -13,8 +15,6 @@ #include #include -#include -#include #include "src/platform/common.h" #include "src/utility.h" @@ -33,6 +33,10 @@ namespace platf::dxgi { dxgi->Release(); } + /** + * Windows DLL loader function helper for AMD Display Capture + * @param item library dll + */ inline void FreeLibraryHelper(void *item) { @@ -467,7 +471,8 @@ namespace platf::dxgi { /** - * Display backend that uses Windows.Graphics.Capture with a hardware encoder. + * Display backend that uses AMD Display Capture with a hardware encoder. + * Main purpose is to capture AMD Fluid Motion Frames (AFMF) */ class display_amd_vram_t: public display_vram_t { amd_capture_t dup; diff --git a/src/platform/windows/display_amd.cpp b/src/platform/windows/display_amd.cpp index 6b58eeaec35..c497b7b3f85 100644 --- a/src/platform/windows/display_amd.cpp +++ b/src/platform/windows/display_amd.cpp @@ -55,24 +55,21 @@ namespace platf::dxgi { return capture_e::ok; } - /** + /** * @brief Get the next frame from the producer thread. * If not available, the capture thread blocks until one is, or the wait times out. * @param timeout how long to wait for the next frame - * @param out a texture containing the frame just captured - * @param out_time the timestamp of the frame just captured + * @param out pointer to AMFSurfacePtr */ capture_e amd_capture_t::next_frame(std::chrono::milliseconds timeout, amf::AMFData** out) { release_frame(); - // this CONSUMER runs in the capture thread - // Poll for the next frame + AMF_RESULT result; auto capture_start = std::chrono::steady_clock::now(); do { result = captureComp->QueryOutput(out); if (result == AMF_REPEAT) { - // Check for capture timeout expiration if (std::chrono::steady_clock::now() - capture_start >= timeout) { return platf::capture_e::timeout; } @@ -81,7 +78,6 @@ namespace platf::dxgi { } while (result == AMF_REPEAT); if (result != AMF_OK) { - BOOST_LOG(error) << "DisplayCapture::QueryOutput() failed: "sv << result; return capture_e::timeout; } return capture_e::ok; @@ -133,31 +129,11 @@ namespace platf::dxgi { DXGI_ADAPTER_DESC adapter_desc; display->adapter->GetDesc(&adapter_desc); - amf::AMFTrace* traceAMF; - amf_factory->GetTrace(&traceAMF); - traceAMF->SetGlobalLevel(AMF_TRACE_DEBUG); - traceAMF->EnableWriter(AMF_TRACE_WRITER_FILE, true); - traceAMF->SetWriterLevel(AMF_TRACE_WRITER_FILE, AMF_TRACE_DEBUG); - traceAMF->SetPath(L"D:/amflog.txt"); - - amf::AMFDebug* debugAMF; - amf_factory->GetDebug(&debugAMF); - debugAMF->AssertsEnable(false); - // Bail if this is not an AMD GPU if (adapter_desc.VendorId != 0x1002) { return -1; } - // BOOST_LOG(info) << "### framerate " << config.framerate << " dynamicRange " << config.dynamicRange; - - // // FIXME: Don't use Direct Capture for a SDR P010 stream. The output is very dim. - // // This seems like a possible bug in VideoConverter when upconverting 8-bit to 10-bit. - // if (config.dynamicRange && !display->is_hdr()) { - // BOOST_LOG(info) << "AMD Direct Capture is disabled while 10-bit stream is in SDR mode"sv; - // return -1; - // } - // Create the capture context result = amf_factory->CreateContext(&context); diff --git a/src/platform/windows/display_base.cpp b/src/platform/windows/display_base.cpp index 36a2141fa06..1adb49093c5 100644 --- a/src/platform/windows/display_base.cpp +++ b/src/platform/windows/display_base.cpp @@ -1036,26 +1036,26 @@ namespace platf { */ std::shared_ptr display(mem_type_e hwdevice_type, const std::string &display_name, const video::config_t &config) { - if (config::video.capture == "ddx" || config::video.capture.empty()) { + if (config::video.capture == "amd" || config::video.capture.empty()) { if (hwdevice_type == mem_type_e::dxgi) { - auto disp = std::make_shared(); + auto disp = std::make_shared(); if (!disp->init(config, display_name)) { return disp; } } - else if (hwdevice_type == mem_type_e::system) { - auto disp = std::make_shared(); + } + + if (config::video.capture == "ddx" || config::video.capture.empty()) { + if (hwdevice_type == mem_type_e::dxgi) { + auto disp = std::make_shared(); if (!disp->init(config, display_name)) { return disp; } } - } - - if (config::video.capture == "amd") { - if (hwdevice_type == mem_type_e::dxgi) { - auto disp = std::make_shared(); + else if (hwdevice_type == mem_type_e::system) { + auto disp = std::make_shared(); if (!disp->init(config, display_name)) { return disp; diff --git a/src/platform/windows/display_vram.cpp b/src/platform/windows/display_vram.cpp index 585ac0d9e1e..b42c60e349e 100644 --- a/src/platform/windows/display_vram.cpp +++ b/src/platform/windows/display_vram.cpp @@ -1428,7 +1428,7 @@ namespace platf::dxgi { } -/** + /** * @brief Get the next frame from the Windows.Graphics.Capture API and copy it into a new snapshot texture. * @param pull_free_image_cb call this to get a new free image from the video subsystem. * @param img_out the captured frame is returned here diff --git a/src/video.cpp b/src/video.cpp index d6213c332c2..ac66cf6e8b7 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -1190,7 +1190,6 @@ namespace video { auto status = disp->capture(push_captured_image_callback, pull_free_image_callback, &display_cursor); - if (artificial_reinit && status != platf::capture_e::error) { status = platf::capture_e::reinit;