Skip to content

Commit 4c203f5

Browse files
committed
nvapi-d3d: Fix NV_LATENCY_MARKER_TYPE forwarding
Unfortunately NV_LATENCY_MARKER_TYPE doesn't match VkLatencyMarkerNV, so we need to convert manually. Silently acknowledge, but ignore, calls with unsupported values.
1 parent e3a6ab2 commit 4c203f5

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

src/nvapi/nvapi_d3d_low_latency_device.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include "nvapi_d3d_low_latency_device.h"
2+
#include "../util/util_string.h"
3+
#include "../util/util_log.h"
24

35
namespace dxvk {
46
LowLatencyFrameIdGenerator::LowLatencyFrameIdGenerator()
@@ -110,6 +112,32 @@ namespace dxvk {
110112
GetFrameIdGenerator(d3dLowLatencyDevice.ptr())->GetLowLatencyDeviceFrameId(frameID), markerType));
111113
}
112114

115+
std::optional<uint32_t> NvapiD3dLowLatencyDevice::ToMarkerType(NV_LATENCY_MARKER_TYPE markerType) {
116+
switch (markerType) {
117+
case (SIMULATION_START):
118+
case (SIMULATION_END):
119+
case (RENDERSUBMIT_START):
120+
case (RENDERSUBMIT_END):
121+
case (PRESENT_START):
122+
case (PRESENT_END):
123+
case (INPUT_SAMPLE):
124+
case (TRIGGER_FLASH):
125+
return markerType;
126+
// VkLatencyMarkerNV misses PC_LATENCY_PING and all following enum values are offset
127+
// See https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkSetLatencyMarkerInfoNV-marker-parameter
128+
case (PC_LATENCY_PING):
129+
return {};
130+
case (OUT_OF_BAND_RENDERSUBMIT_START):
131+
case (OUT_OF_BAND_RENDERSUBMIT_END):
132+
case (OUT_OF_BAND_PRESENT_START):
133+
case (OUT_OF_BAND_PRESENT_END):
134+
return markerType - 1;
135+
}
136+
137+
log::info(str::format("Unknown NV_LATENCY_MARKER_TYPE: ", markerType));
138+
return {};
139+
}
140+
113141
void NvapiD3dLowLatencyDevice::ClearCacheMaps() {
114142
std::scoped_lock lock(m_lowLatencyDeviceMutex, m_lowLatencyFrameIdGeneratorMutex);
115143

src/nvapi/nvapi_d3d_low_latency_device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ namespace dxvk {
3333
static bool SetLatencyMarker(IUnknown* device, uint64_t frameID, uint32_t markerType);
3434
static bool SetLatencyMarker(ID3D12CommandQueue* commandQueue, uint64_t frameID, uint32_t markerType);
3535

36+
[[nodiscard]] static std::optional<uint32_t> ToMarkerType(NV_LATENCY_MARKER_TYPE markerType);
37+
3638
static void ClearCacheMaps();
3739

3840
private:

src/nvapi_d3d.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ extern "C" {
256256
thread_local bool alreadyLoggedNoImpl = false;
257257
thread_local bool alreadyLoggedError = false;
258258
thread_local bool alreadyLoggedOk = false;
259+
thread_local bool alreadyLoggedMarkerTypeNotSupported = false;
259260

260261
if (log::tracing())
261262
log::trace(n, log::fmt::ptr(pDev), log::fmt::nv_latency_marker_params(pSetLatencyMarkerParams));
@@ -272,7 +273,16 @@ extern "C" {
272273
if (nvapiD3dInstance->IsUsingLfx() || !NvapiD3dLowLatencyDevice::SupportsLowLatency(pDev))
273274
return NoImplementation(n, alreadyLoggedNoImpl);
274275

275-
if (!NvapiD3dLowLatencyDevice::SetLatencyMarker(pDev, pSetLatencyMarkerParams->frameID, pSetLatencyMarkerParams->markerType))
276+
auto markerType = NvapiD3dLowLatencyDevice::ToMarkerType(pSetLatencyMarkerParams->markerType);
277+
if (!markerType.has_value()) {
278+
// Silently drop unsupported marker types
279+
if (!std::exchange(alreadyLoggedMarkerTypeNotSupported, true))
280+
log::info(str::format("Not supported NV_LATENCY_MARKER_TYPE: ", pSetLatencyMarkerParams->markerType));
281+
282+
return Ok(n, alreadyLoggedOk);
283+
}
284+
285+
if (!NvapiD3dLowLatencyDevice::SetLatencyMarker(pDev, pSetLatencyMarkerParams->frameID, markerType.value()))
276286
return Error(n, alreadyLoggedError);
277287

278288
return Ok(n, alreadyLoggedOk);

tests/nvapi_d3d.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ TEST_CASE("D3D Reflex/LatencyFleX depending methods succeed", "[.d3d]") {
383383
.RETURN(S_OK);
384384
REQUIRE_CALL(lowLatencyDevice, LatencySleep())
385385
.RETURN(S_OK);
386-
REQUIRE_CALL(lowLatencyDevice, SetLatencyMarker(1ULL, SIMULATION_START))
386+
REQUIRE_CALL(lowLatencyDevice, SetLatencyMarker(1ULL, VK_LATENCY_MARKER_SIMULATION_START_NV))
387387
.RETURN(S_OK);
388388

389389
SetupResourceFactory(std::move(dxgiFactory), std::move(vulkan), std::move(nvml), std::move(lfx));
@@ -402,6 +402,19 @@ TEST_CASE("D3D Reflex/LatencyFleX depending methods succeed", "[.d3d]") {
402402
REQUIRE(NvAPI_D3D_SetLatencyMarker(&unknown, &latencyMarkerParams) == NVAPI_OK);
403403
}
404404

405+
SECTION("SetLatencyMarker drops PC_LATENCY_PING and returns OK") {
406+
FORBID_CALL(lowLatencyDevice, SetLatencyMarker(_, _));
407+
408+
SetupResourceFactory(std::move(dxgiFactory), std::move(vulkan), std::move(nvml), std::move(lfx));
409+
REQUIRE(NvAPI_Initialize() == NVAPI_OK);
410+
411+
NV_LATENCY_MARKER_PARAMS latencyMarkerParams{};
412+
latencyMarkerParams.version = NV_LATENCY_MARKER_PARAMS_VER1;
413+
latencyMarkerParams.frameID = 123ULL;
414+
latencyMarkerParams.markerType = PC_LATENCY_PING;
415+
REQUIRE(NvAPI_D3D_SetLatencyMarker(&unknown, &latencyMarkerParams) == NVAPI_OK);
416+
}
417+
405418
SECTION("SetLatencyMarker correctly produces monotonic frame ids for a sequence of unique application frame ids") {
406419
REQUIRE_CALL(lowLatencyDevice, SetLatencySleepMode(true, false, 750U))
407420
.RETURN(S_OK);

0 commit comments

Comments
 (0)