Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a few trivial functions #176

Merged
merged 3 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/nvapi_drs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ extern "C" {
return Ok(n);
}

NvAPI_Status __cdecl NvAPI_DRS_GetCurrentGlobalProfile(NvDRSSessionHandle hSession, NvDRSProfileHandle* phProfile) {
constexpr auto n = __func__;

*phProfile = nvapiDrsProfile;

return Ok(n);
}

NvAPI_Status __cdecl NvAPI_DRS_GetSetting(NvDRSSessionHandle hSession, NvDRSProfileHandle hProfile, NvU32 settingId, NVDRS_SETTING* pSetting) {
constexpr auto n = __func__;

Expand Down
32 changes: 32 additions & 0 deletions src/nvapi_gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,20 @@ extern "C" {
return Ok(n);
}

NvAPI_Status __cdecl NvAPI_GPU_GetSystemType(NvPhysicalGpuHandle hPhysicalGpu, NV_SYSTEM_TYPE* pSystemType) {
constexpr auto n = __func__;

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

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

*pSystemType = NV_SYSTEM_TYPE_UNKNOWN;

return Ok(n);
}

NvAPI_Status __cdecl NvAPI_GPU_GetPCIIdentifiers(NvPhysicalGpuHandle hPhysicalGpu, NvU32* pDeviceId, NvU32* pSubSystemId, NvU32* pRevisionId, NvU32* pExtDeviceId) {
constexpr auto n = __func__;

Expand Down Expand Up @@ -313,6 +327,24 @@ extern "C" {
return Ok(n);
}

NvAPI_Status __cdecl NvAPI_GPU_GetVirtualFrameBufferSize(NvPhysicalGpuHandle hPhysicalGpu, NvU32* pSize) {
constexpr auto n = __func__;

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

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

auto adapter = reinterpret_cast<NvapiAdapter*>(hPhysicalGpu);
if (!nvapiAdapterRegistry->IsAdapter(adapter))
return ExpectedPhysicalGpuHandle(n);

*pSize = adapter->GetVirtualVRamSize();

return Ok(n);
}

NvAPI_Status __cdecl NvAPI_GPU_GetAdapterIdFromPhysicalGpu(NvPhysicalGpuHandle hPhysicalGpu, void* pOSAdapterId) {
constexpr auto n = __func__;

Expand Down
3 changes: 3 additions & 0 deletions src/nvapi_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ extern "C" {
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GPU_GetIRQ)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GPU_GetGpuCoreCount)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GPU_GetGPUType)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GPU_GetSystemType)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GPU_GetPCIIdentifiers)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GPU_GetFullName)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GPU_GetBusId)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GPU_GetBusSlotId)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GPU_GetBusType)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GPU_GetPhysicalFrameBufferSize)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GPU_GetVirtualFrameBufferSize)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GPU_GetAdapterIdFromPhysicalGpu)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GPU_GetLogicalGpuInfo)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GPU_GetArchInfo)
Expand All @@ -108,6 +110,7 @@ extern "C" {
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_DRS_FindProfileByName)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_DRS_GetSetting)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_DRS_GetBaseProfile)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_DRS_GetCurrentGlobalProfile);
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_DRS_LoadSettings)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_DRS_DestroySession)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_DRS_CreateSession)
Expand Down
5 changes: 5 additions & 0 deletions src/sysinfo/nvapi_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ namespace dxvk {
return m_dxgiDesc.DedicatedVideoMemory / 1024;
}

uint32_t NvapiAdapter::GetVirtualVRamSize() const {
// Report VRAM size from DXVK to honor memory overrides
return (m_dxgiDesc.DedicatedVideoMemory + m_dxgiDesc.DedicatedSystemMemory) / 1024;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In reality DedicatedSystemMemory will always be zero, see https://github.com/doitsujin/dxvk/blob/master/src/dxgi/dxgi_adapter.cpp#L371

}

std::optional<LUID> NvapiAdapter::GetLuid() const {
if (!m_vkIdProperties.deviceLUIDValid)
return {};
Expand Down
1 change: 1 addition & 0 deletions src/sysinfo/nvapi_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace dxvk {
[[nodiscard]] uint32_t GetPciDeviceId() const;
[[nodiscard]] uint32_t GetBoardId() const;
[[nodiscard]] uint32_t GetVRamSize() const;
[[nodiscard]] uint32_t GetVirtualVRamSize() const;
[[nodiscard]] std::optional<LUID> GetLuid() const;
[[nodiscard]] NV_GPU_ARCHITECTURE_ID GetArchitectureId() const;

Expand Down
6 changes: 6 additions & 0 deletions tests/nvapi_drs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ TEST_CASE("DRS methods succeed", "[.drs]") {
REQUIRE(NvAPI_DRS_GetBaseProfile(handle, &profile) == NVAPI_OK);
}

SECTION("GetCurrentGlobalProfile returns OK") {
NvDRSSessionHandle handle{};
NvDRSProfileHandle profile;
REQUIRE(NvAPI_DRS_GetCurrentGlobalProfile(handle, &profile) == NVAPI_OK);
}

SECTION("GetSetting returns setting-not-found") {
struct Data {
int32_t settingId;
Expand Down
32 changes: 32 additions & 0 deletions tests/nvapi_sysinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,18 @@ TEST_CASE("Sysinfo methods succeed", "[.sysinfo]") {
REQUIRE(type == NV_SYSTEM_TYPE_DGPU);
}

SECTION("GetSystemType returns OK") {
SetupResourceFactory(std::move(dxgiFactory), std::move(vulkan), std::move(nvml), std::move(lfx));
REQUIRE(NvAPI_Initialize() == NVAPI_OK);

NvPhysicalGpuHandle handle;
REQUIRE(NvAPI_SYS_GetPhysicalGpuFromDisplayId(primaryDisplayId, &handle) == NVAPI_OK);

NV_SYSTEM_TYPE type;
REQUIRE(NvAPI_GPU_GetSystemType(handle, &type) == NVAPI_OK);
REQUIRE(type == NV_SYSTEM_TYPE_UNKNOWN);
}

SECTION("GetPCIIdentifiers returns OK") {
ALLOW_CALL(adapter, GetDesc1(_))
.SIDE_EFFECT({
Expand Down Expand Up @@ -508,6 +520,26 @@ TEST_CASE("Sysinfo methods succeed", "[.sysinfo]") {
REQUIRE(size == 8191);
}

SECTION("GetVirtualFrameBufferSize returns OK") {
ALLOW_CALL(adapter, GetDesc1(_))
.SIDE_EFFECT({
_1->VendorId = 0x10de;
_1->DedicatedVideoMemory = 8191 * 1024;
_1->DedicatedSystemMemory = 1014 * 1024;
})
.RETURN(S_OK);

SetupResourceFactory(std::move(dxgiFactory), std::move(vulkan), std::move(nvml), std::move(lfx));
REQUIRE(NvAPI_Initialize() == NVAPI_OK);

NvPhysicalGpuHandle handle;
REQUIRE(NvAPI_SYS_GetPhysicalGpuFromDisplayId(primaryDisplayId, &handle) == NVAPI_OK);

NvU32 size;
REQUIRE(NvAPI_GPU_GetVirtualFrameBufferSize(handle, &size) == NVAPI_OK);
REQUIRE(size == 9205);
}

SECTION("GetAdapterIdFromPhysicalGpu returns OK") {
ALLOW_CALL(*vulkan, GetPhysicalDeviceProperties2(_, _, _))
.SIDE_EFFECT(
Expand Down