Skip to content

Commit

Permalink
nvapi-adapter: Improve DXVK NVAPI hack detection
Browse files Browse the repository at this point in the history
When DXVK_ENABLE_NVAPI is set, we can be sure that the
NVAPI hack is disabled.
  • Loading branch information
jp7677 committed Jun 11, 2023
1 parent cb61c3f commit a2235c8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/sysinfo/nvapi_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ namespace dxvk {
if (!HasNvProprietaryDriver() && allowOtherDrivers.empty())
return false;

if (HasNvProprietaryDriver() && m_dxgiDesc.VendorId != NvidiaPciVendorId)
auto dxvkEnableNvapi = env::getEnvVariable("DXVK_ENABLE_NVAPI");
if (HasNvProprietaryDriver() && m_dxgiDesc.VendorId != NvidiaPciVendorId && dxvkEnableNvapi.empty())

This comment has been minimized.

Copy link
@adamdmoss

adamdmoss Jun 15, 2023

A minor hole, but I think this is not strictly correct; DXVK compares DXVK_ENABLE_NVAPI against "1", not just a non-empty string. So DXVK_ENABLE_NVAPI=0 will still generate a disagreement.

This comment has been minimized.

Copy link
@jp7677

jp7677 Jun 16, 2023

Author Owner

Thanks for pointing this out! Addressed in f50c29b

return false; // DXVK NVAPI-hack is enabled, skip this adapter

if (HasNvProprietaryDriver())
Expand Down
17 changes: 17 additions & 0 deletions tests/nvapi_sysinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ TEST_CASE("Initialize succeeds", "[.sysinfo]") {
}

SECTION("Initialize returns device-not-found when DXVK NVAPI hack is enabled") {
::SetEnvironmentVariableA("DXVK_ENABLE_NVAPI", "");

ALLOW_CALL(adapter, GetDesc1(_))
.SIDE_EFFECT(_1->VendorId = 0x1002)
.RETURN(S_OK);
Expand All @@ -52,6 +54,21 @@ TEST_CASE("Initialize succeeds", "[.sysinfo]") {
REQUIRE(NvAPI_Unload() == NVAPI_API_NOT_INITIALIZED);
}

SECTION("Initialize returns OK when DXVK reports other vendor but DXVK_ENABLE_NVAPI is set") {
::SetEnvironmentVariableA("DXVK_ENABLE_NVAPI", "1");

ALLOW_CALL(adapter, GetDesc1(_))
.SIDE_EFFECT(_1->VendorId = 0x1002)
.RETURN(S_OK);

SetupResourceFactory(std::move(dxgiFactory), std::move(vulkan), std::move(nvml), std::move(lfx));

REQUIRE(NvAPI_Initialize() == NVAPI_OK);
REQUIRE(NvAPI_Unload() == NVAPI_OK);

::SetEnvironmentVariableA("DXVK_ENABLE_NVAPI", "");
}

SECTION("Initialize returns device-not-found when adapter with non NVIDIA driver ID has been found") {
ALLOW_CALL(*vulkan, GetPhysicalDeviceProperties2(_, _, _)) // NOLINT(bugprone-use-after-move)
.SIDE_EFFECT(
Expand Down

0 comments on commit a2235c8

Please sign in to comment.