Skip to content

Commit

Permalink
AMD Display Capture documentation and fixes
Browse files Browse the repository at this point in the history
* Remove AMD Trace and debug statements
* Add code comments
  • Loading branch information
radugrecu97 committed Oct 9, 2024
1 parent b65e56d commit cbe742c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 41 deletions.
11 changes: 8 additions & 3 deletions src/platform/windows/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
#pragma once

#include <AMF/core/CurrentTime.h>
#include <AMF/core/Factory.h>
#include <d3d11.h>
#include <d3d11_4.h>
#include <d3dcommon.h>
Expand All @@ -13,8 +15,6 @@

#include <Unknwn.h>
#include <winrt/Windows.Graphics.Capture.h>
#include <AMF/core/Factory.h>
#include <AMF/core/CurrentTime.h>

#include "src/platform/common.h"
#include "src/utility.h"
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
30 changes: 3 additions & 27 deletions src/platform/windows/display_amd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
18 changes: 9 additions & 9 deletions src/platform/windows/display_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1036,26 +1036,26 @@ namespace platf {
*/
std::shared_ptr<display_t>
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<dxgi::display_ddup_vram_t>();
auto disp = std::make_shared<dxgi::display_amd_vram_t>();

if (!disp->init(config, display_name)) {
return disp;
}
}
else if (hwdevice_type == mem_type_e::system) {
auto disp = std::make_shared<dxgi::display_ddup_ram_t>();
}

if (config::video.capture == "ddx" || config::video.capture.empty()) {
if (hwdevice_type == mem_type_e::dxgi) {
auto disp = std::make_shared<dxgi::display_ddup_vram_t>();

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<dxgi::display_amd_vram_t>();
else if (hwdevice_type == mem_type_e::system) {
auto disp = std::make_shared<dxgi::display_ddup_ram_t>();

if (!disp->init(config, display_name)) {
return disp;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/windows/display_vram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit cbe742c

Please sign in to comment.