Skip to content

Commit

Permalink
bugfix: verifying frames should test up to 10 frames
Browse files Browse the repository at this point in the history
Fixed a bug that caused the verify frame code to exit the loop early if it failed to aquire a frame (due to timeouts or other reasons).

It should now properly try up to 10 times.
  • Loading branch information
Nonary committed Nov 22, 2024
1 parent d5854ae commit 4260b52
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions tools/ddprobe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ is_valid_frame(const D3D11_MAPPED_SUBRESOURCE &mappedResource, const D3D11_TEXTU
*/
HRESULT
test_frame_capture(dxgi::dup_t &dup, ComPtr<ID3D11Device> device) {
HRESULT failStatus;
for (int i = 0; i < 10; ++i) {
std::cout << "Attempting to acquire frame " << (i + 1) << " of 10..." << std::endl;
ComPtr<IDXGIResource> frameResource;
Expand All @@ -137,7 +138,8 @@ test_frame_capture(dxgi::dup_t &dup, ComPtr<ID3D11Device> device) {

if (FAILED(status)) {
std::cout << "Error: Failed to acquire next frame [0x"sv << util::hex(status).to_string_view() << ']' << std::endl;
return status;
failStatus = status;
continue;
}

auto cleanup = util::fail_guard([&dup]() {
Expand All @@ -150,7 +152,8 @@ test_frame_capture(dxgi::dup_t &dup, ComPtr<ID3D11Device> device) {
status = frameResource->QueryInterface(IID_PPV_ARGS(&frameTexture));
if (FAILED(status)) {
std::cout << "Error: Failed to query texture interface from frame resource [0x"sv << util::hex(status).to_string_view() << ']' << std::endl;
return status;
failStatus = status;
continue;
}

D3D11_TEXTURE2D_DESC frameDesc;
Expand All @@ -163,7 +166,8 @@ test_frame_capture(dxgi::dup_t &dup, ComPtr<ID3D11Device> device) {
status = device->CreateTexture2D(&frameDesc, nullptr, &stagingTexture);
if (FAILED(status)) {
std::cout << "Error: Failed to create staging texture [0x"sv << util::hex(status).to_string_view() << ']' << std::endl;
return status;
failStatus = status;
continue;
}

context->CopyResource(stagingTexture.Get(), frameTexture.Get());
Expand All @@ -172,7 +176,8 @@ test_frame_capture(dxgi::dup_t &dup, ComPtr<ID3D11Device> device) {
status = context->Map(stagingTexture.Get(), 0, D3D11_MAP_READ, 0, &mappedResource);
if (FAILED(status)) {
std::cout << "Error: Failed to map the staging texture for inspection [0x"sv << util::hex(status).to_string_view() << ']' << std::endl;
return status;
failStatus = status;
continue;
}

auto contextCleanup = util::fail_guard([&context, &stagingTexture]() {
Expand All @@ -181,14 +186,14 @@ test_frame_capture(dxgi::dup_t &dup, ComPtr<ID3D11Device> device) {

if (is_valid_frame(mappedResource, frameDesc)) {
std::cout << "Frame " << (i + 1) << " is non-empty (contains visible content)." << std::endl;
return S_OK;
return S_OK; // We don't need to test anymore frames at this point.
}

std::cout << "Frame " << (i + 1) << " is empty (no visible content)." << std::endl;
}

// All frames were empty, indicating potential capture issues.
return E_FAIL;
return failStatus;
}

HRESULT
Expand Down

0 comments on commit 4260b52

Please sign in to comment.