Skip to content

Commit

Permalink
Optimize D3D11 HDR processing to avoid creating timer queries unless …
Browse files Browse the repository at this point in the history
…the widget is visible
  • Loading branch information
Kaldaien committed Dec 27, 2024
1 parent ea98b7e commit 61c1926
Showing 1 changed file with 46 additions and 33 deletions.
79 changes: 46 additions & 33 deletions src/render/d3d11/hdr/d3d11_hdr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,40 +791,47 @@ SK_HDR_SnapshotSwapchain (void)
return;
}

if ( nullptr == SK_D3D11_HDRDisjointQuery.async )
{
D3D11_QUERY_DESC query_desc {
D3D11_QUERY_TIMESTAMP_DISJOINT, 0x00
};

SK_ComPtr <ID3D11Query> pQuery;
if (SUCCEEDED (pDev->CreateQuery (&query_desc, &pQuery.p)))
//
// Optimization: Only create timer queries when the HDR widget is open
//
if (SK_ImGui_Widgets->hdr_control->isVisible ())
{
if ( nullptr == SK_D3D11_HDRDisjointQuery.async )
{
SK_D3D11_HDRDisjointQuery.async = pQuery;
pDevCtx->Begin (pQuery);
D3D11_QUERY_DESC query_desc {
D3D11_QUERY_TIMESTAMP_DISJOINT, 0x00
};

SK_D3D11_HDRDisjointQuery.active = true;
SK_ComPtr <ID3D11Query> pQuery;
if (SUCCEEDED (pDev->CreateQuery (&query_desc, &pQuery.p)))
{
SK_D3D11_HDRDisjointQuery.async = pQuery;
pDevCtx->Begin (pQuery);

SK_D3D11_HDRDisjointQuery.active = true;
}
}
}

if (SK_D3D11_HDRDisjointQuery.active)
{
// Start a new query
D3D11_QUERY_DESC query_desc {
D3D11_QUERY_TIMESTAMP, 0x00
};
if (SK_D3D11_HDRDisjointQuery.active)
{
// Start a new query
D3D11_QUERY_DESC query_desc {
D3D11_QUERY_TIMESTAMP, 0x00
};

d3d11_shader_tracking_s::duration_s duration;
d3d11_shader_tracking_s::duration_s duration;

SK_ComPtr <ID3D11Query> pQuery;
if (SUCCEEDED (pDev->CreateQuery (&query_desc, &pQuery)))
SK_ComPtr <ID3D11Query> pQuery;
if (SUCCEEDED (pDev->CreateQuery (&query_desc, &pQuery)))
{
duration.start.dev_ctx = pDevCtx;
duration.start.async = pQuery;
pDevCtx->End ( pQuery);

SK_D3D11_HDRTimers.emplace_back (duration);
}
}
}

SK_ComPtr <ID3D11RenderTargetView> pRtv = nullptr;
Expand Down Expand Up @@ -1168,22 +1175,28 @@ SK_HDR_SnapshotSwapchain (void)
#endif
}

if ( pDev != nullptr &&
pDevCtx != nullptr && SK_D3D11_HDRDisjointQuery.active )
//
// Optimization: Only create timer queries when the HDR widget is open
//
if (SK_ImGui_Widgets->hdr_control->isVisible ())
{
D3D11_QUERY_DESC query_desc {
D3D11_QUERY_TIMESTAMP, 0x00
};
if ( pDev != nullptr &&
pDevCtx != nullptr && SK_D3D11_HDRDisjointQuery.active )
{
D3D11_QUERY_DESC query_desc {
D3D11_QUERY_TIMESTAMP, 0x00
};

d3d11_shader_tracking_s::duration_s& duration =
SK_D3D11_HDRTimers.back ();
d3d11_shader_tracking_s::duration_s& duration =
SK_D3D11_HDRTimers.back ();

SK_ComPtr <ID3D11Query> pQuery;
if ( SUCCEEDED ( pDev->CreateQuery (&query_desc, &pQuery.p ) ) )
{
duration.end.dev_ctx = pDevCtx;
duration.end.async = pQuery;
pDevCtx->End ( pQuery);
SK_ComPtr <ID3D11Query> pQuery;
if ( SUCCEEDED ( pDev->CreateQuery (&query_desc, &pQuery.p ) ) )
{
duration.end.dev_ctx = pDevCtx;
duration.end.async = pQuery;
pDevCtx->End ( pQuery);
}
}
}
}
Expand Down

0 comments on commit 61c1926

Please sign in to comment.