Skip to content

Commit 708db84

Browse files
committed
AMD Display Capture documentation and fixes
* Remove AMD Trace and debug statements * Add code comments
1 parent 7c0fb37 commit 708db84

File tree

5 files changed

+21
-41
lines changed

5 files changed

+21
-41
lines changed

src/platform/windows/display.h

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
#pragma once
66

7+
#include <AMF/core/CurrentTime.h>
8+
#include <AMF/core/Factory.h>
79
#include <d3d11.h>
810
#include <d3d11_4.h>
911
#include <d3dcommon.h>
@@ -13,8 +15,6 @@
1315

1416
#include <Unknwn.h>
1517
#include <winrt/Windows.Graphics.Capture.h>
16-
#include <AMF/core/Factory.h>
17-
#include <AMF/core/CurrentTime.h>
1818

1919
#include "src/platform/common.h"
2020
#include "src/utility.h"
@@ -33,6 +33,10 @@ namespace platf::dxgi {
3333
dxgi->Release();
3434
}
3535

36+
/**
37+
* Windows DLL loader function helper for AMD Display Capture
38+
* @param item library dll
39+
*/
3640
inline
3741
void
3842
FreeLibraryHelper(void *item) {
@@ -467,7 +471,8 @@ namespace platf::dxgi {
467471

468472

469473
/**
470-
* Display backend that uses Windows.Graphics.Capture with a hardware encoder.
474+
* Display backend that uses AMD Display Capture with a hardware encoder.
475+
* Main purpose is to capture AMD Fluid Motion Frames (AFMF)
471476
*/
472477
class display_amd_vram_t: public display_vram_t {
473478
amd_capture_t dup;

src/platform/windows/display_amd.cpp

+3-27
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,21 @@ namespace platf::dxgi {
5555
return capture_e::ok;
5656
}
5757

58-
/**
58+
/**
5959
* @brief Get the next frame from the producer thread.
6060
* If not available, the capture thread blocks until one is, or the wait times out.
6161
* @param timeout how long to wait for the next frame
62-
* @param out a texture containing the frame just captured
63-
* @param out_time the timestamp of the frame just captured
62+
* @param out pointer to AMFSurfacePtr
6463
*/
6564
capture_e
6665
amd_capture_t::next_frame(std::chrono::milliseconds timeout, amf::AMFData** out) {
6766
release_frame();
68-
// this CONSUMER runs in the capture thread
69-
// Poll for the next frame
67+
7068
AMF_RESULT result;
7169
auto capture_start = std::chrono::steady_clock::now();
7270
do {
7371
result = captureComp->QueryOutput(out);
7472
if (result == AMF_REPEAT) {
75-
// Check for capture timeout expiration
7673
if (std::chrono::steady_clock::now() - capture_start >= timeout) {
7774
return platf::capture_e::timeout;
7875
}
@@ -81,7 +78,6 @@ namespace platf::dxgi {
8178
} while (result == AMF_REPEAT);
8279

8380
if (result != AMF_OK) {
84-
BOOST_LOG(error) << "DisplayCapture::QueryOutput() failed: "sv << result;
8581
return capture_e::timeout;
8682
}
8783
return capture_e::ok;
@@ -133,31 +129,11 @@ namespace platf::dxgi {
133129
DXGI_ADAPTER_DESC adapter_desc;
134130
display->adapter->GetDesc(&adapter_desc);
135131

136-
amf::AMFTrace* traceAMF;
137-
amf_factory->GetTrace(&traceAMF);
138-
traceAMF->SetGlobalLevel(AMF_TRACE_DEBUG);
139-
traceAMF->EnableWriter(AMF_TRACE_WRITER_FILE, true);
140-
traceAMF->SetWriterLevel(AMF_TRACE_WRITER_FILE, AMF_TRACE_DEBUG);
141-
traceAMF->SetPath(L"D:/amflog.txt");
142-
143-
amf::AMFDebug* debugAMF;
144-
amf_factory->GetDebug(&debugAMF);
145-
debugAMF->AssertsEnable(false);
146-
147132
// Bail if this is not an AMD GPU
148133
if (adapter_desc.VendorId != 0x1002) {
149134
return -1;
150135
}
151136

152-
// BOOST_LOG(info) << "### framerate " << config.framerate << " dynamicRange " << config.dynamicRange;
153-
154-
// // FIXME: Don't use Direct Capture for a SDR P010 stream. The output is very dim.
155-
// // This seems like a possible bug in VideoConverter when upconverting 8-bit to 10-bit.
156-
// if (config.dynamicRange && !display->is_hdr()) {
157-
// BOOST_LOG(info) << "AMD Direct Capture is disabled while 10-bit stream is in SDR mode"sv;
158-
// return -1;
159-
// }
160-
161137
// Create the capture context
162138
result = amf_factory->CreateContext(&context);
163139

src/platform/windows/display_base.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -1036,26 +1036,26 @@ namespace platf {
10361036
*/
10371037
std::shared_ptr<display_t>
10381038
display(mem_type_e hwdevice_type, const std::string &display_name, const video::config_t &config) {
1039-
if (config::video.capture == "ddx" || config::video.capture.empty()) {
1039+
if (config::video.capture == "amd" || config::video.capture.empty()) {
10401040
if (hwdevice_type == mem_type_e::dxgi) {
1041-
auto disp = std::make_shared<dxgi::display_ddup_vram_t>();
1041+
auto disp = std::make_shared<dxgi::display_amd_vram_t>();
10421042

10431043
if (!disp->init(config, display_name)) {
10441044
return disp;
10451045
}
10461046
}
1047-
else if (hwdevice_type == mem_type_e::system) {
1048-
auto disp = std::make_shared<dxgi::display_ddup_ram_t>();
1047+
}
1048+
1049+
if (config::video.capture == "ddx" || config::video.capture.empty()) {
1050+
if (hwdevice_type == mem_type_e::dxgi) {
1051+
auto disp = std::make_shared<dxgi::display_ddup_vram_t>();
10491052

10501053
if (!disp->init(config, display_name)) {
10511054
return disp;
10521055
}
10531056
}
1054-
}
1055-
1056-
if (config::video.capture == "amd") {
1057-
if (hwdevice_type == mem_type_e::dxgi) {
1058-
auto disp = std::make_shared<dxgi::display_amd_vram_t>();
1057+
else if (hwdevice_type == mem_type_e::system) {
1058+
auto disp = std::make_shared<dxgi::display_ddup_ram_t>();
10591059

10601060
if (!disp->init(config, display_name)) {
10611061
return disp;

src/platform/windows/display_vram.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,7 @@ namespace platf::dxgi {
14281428
}
14291429

14301430

1431-
/**
1431+
/**
14321432
* @brief Get the next frame from the Windows.Graphics.Capture API and copy it into a new snapshot texture.
14331433
* @param pull_free_image_cb call this to get a new free image from the video subsystem.
14341434
* @param img_out the captured frame is returned here

src/video.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,6 @@ namespace video {
11901190

11911191
auto status = disp->capture(push_captured_image_callback, pull_free_image_callback, &display_cursor);
11921192

1193-
11941193
if (artificial_reinit && status != platf::capture_e::error) {
11951194
status = platf::capture_e::reinit;
11961195

0 commit comments

Comments
 (0)