Skip to content

Commit

Permalink
nvapi: Add NvAPI_GetLogicalGPUFromDisplay
Browse files Browse the repository at this point in the history
  • Loading branch information
jp7677 committed May 26, 2024
1 parent b7e018f commit 138b319
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/nvapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ extern "C" {
return Ok(n);
}

NvAPI_Status __cdecl NvAPI_GetLogicalGPUFromDisplay(NvDisplayHandle hNvDisp, NvLogicalGpuHandle* pLogicalGPU) {
constexpr auto n = __func__;

if (nvapiAdapterRegistry == nullptr)
return ApiNotInitialized(n);

if (hNvDisp == nullptr)
return InvalidArgument(n);

auto output = reinterpret_cast<NvapiOutput*>(hNvDisp);
if (!nvapiAdapterRegistry->IsOutput(output))
return ExpectedDisplayHandle(n);

*pLogicalGPU = reinterpret_cast<NvLogicalGpuHandle>(output->GetParent());

return Ok(n);
}

NvAPI_Status __cdecl NvAPI_GetPhysicalGPUsFromLogicalGPU(NvLogicalGpuHandle hLogicalGPU, NvPhysicalGpuHandle hPhysicalGPU[NVAPI_MAX_PHYSICAL_GPUS], NvU32* pGpuCount) {
constexpr auto n = __func__;

Expand Down
1 change: 1 addition & 0 deletions src/nvapi_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ extern "C" {
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GetDisplayDriverVersion)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GetPhysicalGPUsFromDisplay)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GetLogicalGPUFromPhysicalGPU)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GetLogicalGPUFromDisplay)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GetPhysicalGPUsFromLogicalGPU)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_EnumNvidiaDisplayHandle)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_EnumNvidiaUnAttachedDisplayHandle)
Expand Down
2 changes: 1 addition & 1 deletion tests/mock_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MockFactory : public dxvk::ResourceFactory {
: m_dxgiFactoryMock(std::move(dxgiFactory1Mock)),
m_vulkanMock(std::move(vulkanMock)),
m_nvmlMock(std::move(nvmlMock)),
m_lfxMock(std::move(lfxMock)){};
m_lfxMock(std::move(lfxMock)) {};

dxvk::Com<IDXGIFactory1> CreateDXGIFactory1() override {
return m_dxgiFactoryMock.get();
Expand Down
33 changes: 31 additions & 2 deletions tests/nvapi_sysinfo_topo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,35 @@ TEST_CASE("Topology methods succeed", "[.sysinfo-topo]") {
REQUIRE(logicalhandle == reinterpret_cast<NvLogicalGpuHandle>(handles[1]));
}

SECTION("GetLogicalGPUFromDisplay succeeds") {
NvLogicalGpuHandle logicalhandles[NVAPI_MAX_LOGICAL_GPUS]{};
NvU32 count;
REQUIRE(NvAPI_EnumLogicalGPUs(logicalhandles, &count) == NVAPI_OK);

NvDisplayHandle handle1 = nullptr;
NvDisplayHandle handle2 = nullptr;
NvDisplayHandle handle3 = nullptr;
REQUIRE(NvAPI_EnumNvidiaDisplayHandle(0U, &handle1) == NVAPI_OK);
REQUIRE(NvAPI_EnumNvidiaDisplayHandle(1U, &handle2) == NVAPI_OK);
REQUIRE(NvAPI_EnumNvidiaDisplayHandle(2U, &handle3) == NVAPI_OK);

NvLogicalGpuHandle logicalhandle1;
REQUIRE(NvAPI_GetLogicalGPUFromDisplay(handle1, &logicalhandle1) == NVAPI_OK);
REQUIRE(logicalhandle1 == reinterpret_cast<NvLogicalGpuHandle>(logicalhandles[0]));

NvLogicalGpuHandle logicalhandle2;
REQUIRE(NvAPI_GetLogicalGPUFromDisplay(handle2, &logicalhandle2) == NVAPI_OK);
REQUIRE(logicalhandle2 == reinterpret_cast<NvLogicalGpuHandle>(logicalhandles[0]));

NvLogicalGpuHandle logicalhandle3;
REQUIRE(NvAPI_GetLogicalGPUFromDisplay(handle3, &logicalhandle3) == NVAPI_OK);
REQUIRE(logicalhandle3 == reinterpret_cast<NvLogicalGpuHandle>(logicalhandles[1]));

auto invalid = reinterpret_cast<NvDisplayHandle>(0x1);
NvLogicalGpuHandle logicalhandle4;
REQUIRE(NvAPI_GetLogicalGPUFromDisplay(invalid, &logicalhandle4) == NVAPI_EXPECTED_DISPLAY_HANDLE);
}

SECTION("GetPhysicalGPUsFromLogicalGPU succeeds") {
NvLogicalGpuHandle handles[NVAPI_MAX_LOGICAL_GPUS]{};
NvU32 count;
Expand Down Expand Up @@ -208,9 +237,9 @@ TEST_CASE("Topology methods succeed", "[.sysinfo-topo]") {
REQUIRE(NvAPI_GetAssociatedNvidiaDisplayName(handle3, name3) == NVAPI_OK);
REQUIRE_THAT(name3, Equals("Output3"));

auto invalid = reinterpret_cast<NvDisplayHandle>(0x1);
NvAPI_ShortString name4;
NvDisplayHandle handle4 = nullptr;
REQUIRE(NvAPI_GetAssociatedNvidiaDisplayName(handle4, name4) == NVAPI_INVALID_ARGUMENT);
REQUIRE(NvAPI_GetAssociatedNvidiaDisplayName(invalid, name4) == NVAPI_EXPECTED_DISPLAY_HANDLE);
}

SECTION("GetAssociatedNvidiaDisplayHandle succeeds") {
Expand Down

0 comments on commit 138b319

Please sign in to comment.