From f9499bcc097e22383d66895ee441b4a263dd0f31 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sat, 25 Jan 2025 09:14:33 +0100 Subject: [PATCH 01/23] nvapi: Shorten raw pointer checks More consistent with other parts of the code base. --- src/nvapi.cpp | 64 ++++++------ src/nvapi/lfx.cpp | 10 +- src/nvapi/nvapi_adapter_registry.cpp | 2 +- src/nvapi/nvapi_d3d11_device.cpp | 7 +- src/nvapi/nvapi_d3d_low_latency_device.cpp | 4 +- src/nvapi/nvml.cpp | 14 +-- src/nvapi_d3d.cpp | 26 ++--- src/nvapi_d3d11.cpp | 44 ++++----- src/nvapi_d3d12.cpp | 50 +++++----- src/nvapi_disp.cpp | 26 ++--- src/nvapi_drs.cpp | 6 +- src/nvapi_gpu.cpp | 108 ++++++++++----------- src/nvapi_sys.cpp | 22 ++--- 13 files changed, 192 insertions(+), 191 deletions(-) diff --git a/src/nvapi.cpp b/src/nvapi.cpp index 02463122..7f77aed0 100644 --- a/src/nvapi.cpp +++ b/src/nvapi.cpp @@ -19,10 +19,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(nvGPUHandle), log::fmt::ptr(pGpuCount)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (nvGPUHandle == nullptr || pGpuCount == nullptr) + if (!nvGPUHandle || !pGpuCount) return InvalidArgument(n); for (auto i = 0U; i < nvapiAdapterRegistry->GetAdapterCount(); i++) @@ -39,10 +39,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(nvGPUHandle), log::fmt::ptr(pGpuCount)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (nvGPUHandle == nullptr || pGpuCount == nullptr) + if (!nvGPUHandle || !pGpuCount) return InvalidArgument(n); for (auto i = 0U; i < nvapiAdapterRegistry->GetAdapterCount(); i++) @@ -59,10 +59,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(nvGPUHandle), log::fmt::ptr(pGpuCount)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (nvGPUHandle == nullptr || pGpuCount == nullptr) + if (!nvGPUHandle || !pGpuCount) return InvalidArgument(n); // There is no TCC mode on Linux, see https://forums.developer.nvidia.com/t/gpudirect-is-tcc-mode-a-requirement/79248 @@ -80,10 +80,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGpu), log::fmt::ptr(pGpuId)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pGpuId == nullptr) + if (!pGpuId) return InvalidArgument(n); auto adapter = reinterpret_cast(hPhysicalGpu); @@ -102,10 +102,10 @@ extern "C" { if (log::tracing()) log::trace(n, gpuId, log::fmt::ptr(hPhysicalGpu)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (hPhysicalGpu == nullptr) + if (!hPhysicalGpu) return InvalidArgument(n); NvapiAdapter* adapter = nullptr; @@ -113,7 +113,7 @@ extern "C" { if (nvapiAdapterRegistry->GetAdapter(i)->GetBoardId() == gpuId) adapter = nvapiAdapterRegistry->GetAdapter(i); - if (adapter == nullptr) + if (!adapter) return InvalidArgument(n); *hPhysicalGpu = reinterpret_cast(adapter); @@ -127,10 +127,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hNvDisplay), log::fmt::ptr(pVersion)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pVersion == nullptr) // Ignore hNvDisplay + if (!pVersion) // Ignore hNvDisplay return InvalidArgument(n); if (pVersion->version != NV_DISPLAY_DRIVER_VERSION_VER) @@ -152,10 +152,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGPU), log::fmt::ptr(pLogicalGPU)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pLogicalGPU == nullptr) + if (!pLogicalGPU) return InvalidArgument(n); auto adapter = reinterpret_cast(hPhysicalGPU); @@ -173,10 +173,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hNvDisp), log::fmt::ptr(pLogicalGPU)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pLogicalGPU == nullptr) + if (!pLogicalGPU) return InvalidArgument(n); auto output = reinterpret_cast(hNvDisp); @@ -194,10 +194,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hLogicalGPU), log::fmt::ptr(hPhysicalGPU), log::fmt::ptr(pGpuCount)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (hPhysicalGPU == nullptr || pGpuCount == nullptr) + if (!hPhysicalGPU || !pGpuCount) return InvalidArgument(n); auto adapter = reinterpret_cast(hLogicalGPU); @@ -216,10 +216,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hNvDisp), log::fmt::ptr(nvGPUHandle), log::fmt::ptr(pGpuCount)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (nvGPUHandle == nullptr || pGpuCount == nullptr) + if (!nvGPUHandle || !pGpuCount) return InvalidArgument(n); auto output = reinterpret_cast(hNvDisp); @@ -238,14 +238,14 @@ extern "C" { if (log::tracing()) log::trace(n, thisEnum, log::fmt::ptr(pNvDispHandle)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pNvDispHandle == nullptr) + if (!pNvDispHandle) return InvalidArgument(n); auto output = nvapiAdapterRegistry->GetOutput(thisEnum); - if (output == nullptr) + if (!output) return EndEnumeration(str::format(n, " (", thisEnum, ")")); *pNvDispHandle = reinterpret_cast(output); @@ -269,10 +269,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(NvDispHandle), log::fmt::ptr(szDisplayName)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (szDisplayName == nullptr) + if (!szDisplayName) return InvalidArgument(n); auto output = reinterpret_cast(NvDispHandle); @@ -290,14 +290,14 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(szDisplayName), log::fmt::ptr(pNvDispHandle)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (szDisplayName == nullptr || pNvDispHandle == nullptr) + if (!szDisplayName || !pNvDispHandle) return InvalidArgument(n); auto output = nvapiAdapterRegistry->FindOutput(szDisplayName); - if (output == nullptr) + if (!output) return NvidiaDeviceNotFound(n); *pNvDispHandle = reinterpret_cast(output); @@ -311,7 +311,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(szDesc)); - if (szDesc == nullptr) + if (!szDesc) return InvalidArgument(n); str::tonvss(szDesc, "NVAPI Open Source Interface (DXVK-NVAPI)"); @@ -325,7 +325,7 @@ extern "C" { if (log::tracing()) log::trace(n, nr, log::fmt::ptr(szDesc)); - if (szDesc == nullptr) + if (!szDesc) return InvalidArgument(n); auto error = fromErrorNr(nr); @@ -369,7 +369,7 @@ extern "C" { " ", DXVK_NVAPI_BUILD_TYPE, " (", env::getExecutableName(), ")")); - if (resourceFactory == nullptr) + if (!resourceFactory) resourceFactory = std::make_unique(); nvapiAdapterRegistry = std::make_unique(*resourceFactory); diff --git a/src/nvapi/lfx.cpp b/src/nvapi/lfx.cpp index da2cde50..8c775213 100644 --- a/src/nvapi/lfx.cpp +++ b/src/nvapi/lfx.cpp @@ -9,21 +9,21 @@ namespace dxvk { auto useFallbackEntrypoints = false; m_lfxModule = ::LoadLibraryA(lfxModuleName); - if (m_lfxModule != nullptr) + if (m_lfxModule) log::info(str::format("Successfully loaded ", lfxModuleName)); - if (m_lfxModule == nullptr && ::GetLastError() == ERROR_MOD_NOT_FOUND) { + if (!m_lfxModule && ::GetLastError() == ERROR_MOD_NOT_FOUND) { // Try fallback entrypoints. These were used by versions prior to [9c2836f]. // The fallback logic can be removed once enough time has passed since the release. // [9c2836f]: https://github.com/ishitatsuyuki/LatencyFleX/commit/9c2836faf14196190a915064b53c27e675e47960 m_lfxModule = ::LoadLibraryA(lfxModuleNameFallback); - if (m_lfxModule != nullptr) + if (m_lfxModule) log::info(str::format("Successfully loaded ", lfxModuleNameFallback)); useFallbackEntrypoints = true; } - if (m_lfxModule == nullptr) { + if (!m_lfxModule) { auto lastError = ::GetLastError(); if (lastError != ERROR_MOD_NOT_FOUND) // Ignore library not found log::info(str::format("Loading ", !useFallbackEntrypoints ? lfxModuleName : lfxModuleNameFallback, @@ -38,7 +38,7 @@ namespace dxvk { } Lfx::~Lfx() { - if (m_lfxModule == nullptr) + if (!m_lfxModule) return; ::FreeLibrary(m_lfxModule); diff --git a/src/nvapi/nvapi_adapter_registry.cpp b/src/nvapi/nvapi_adapter_registry.cpp index c112fd51..4bc487e9 100644 --- a/src/nvapi/nvapi_adapter_registry.cpp +++ b/src/nvapi/nvapi_adapter_registry.cpp @@ -32,7 +32,7 @@ namespace dxvk { return false; m_vk = m_resourceFactory.CreateVulkan(m_dxgiFactory); - if (m_vk == nullptr || !m_vk->IsAvailable()) + if (!m_vk || !m_vk->IsAvailable()) return false; m_nvml = m_resourceFactory.CreateNvml(); diff --git a/src/nvapi/nvapi_d3d11_device.cpp b/src/nvapi/nvapi_d3d11_device.cpp index ed6550d7..638027ec 100644 --- a/src/nvapi/nvapi_d3d11_device.cpp +++ b/src/nvapi/nvapi_d3d11_device.cpp @@ -64,11 +64,12 @@ namespace dxvk { } bool NvapiD3d11Device::DestroyCubinShader(NVDX_ObjectHandle hShader) { - auto cubinShader = reinterpret_cast(hShader); - if (cubinShader != nullptr) + if (auto cubinShader = reinterpret_cast(hShader)) { cubinShader->Release(); + return true; + } - return cubinShader != nullptr; + return false; } bool NvapiD3d11Device::GetResourceDriverHandle(ID3D11Resource* pResource, NVDX_ObjectHandle* phObject) { diff --git a/src/nvapi/nvapi_d3d_low_latency_device.cpp b/src/nvapi/nvapi_d3d_low_latency_device.cpp index b803c709..0245bc80 100644 --- a/src/nvapi/nvapi_d3d_low_latency_device.cpp +++ b/src/nvapi/nvapi_d3d_low_latency_device.cpp @@ -159,7 +159,7 @@ namespace dxvk { } Com NvapiD3dLowLatencyDevice::GetLowLatencyDevice(IUnknown* device) { - if (device == nullptr) + if (!device) return nullptr; std::scoped_lock lock(m_lowLatencyDeviceMutex); @@ -177,7 +177,7 @@ namespace dxvk { } Com NvapiD3dLowLatencyDevice::GetLowLatencyDevice(ID3D12CommandQueue* commandQueue) { - if (commandQueue == nullptr) + if (!commandQueue) return nullptr; auto unknown = static_cast(commandQueue); diff --git a/src/nvapi/nvml.cpp b/src/nvapi/nvml.cpp index a783d2a0..ec6f774a 100644 --- a/src/nvapi/nvml.cpp +++ b/src/nvapi/nvml.cpp @@ -6,10 +6,10 @@ namespace dxvk { Nvml::Nvml() { const auto nvmlModuleName = "nvml.dll"; m_nvmlModule = ::LoadLibraryA(nvmlModuleName); - if (m_nvmlModule != nullptr) + if (m_nvmlModule) log::info(str::format("Successfully loaded ", nvmlModuleName)); - if (m_nvmlModule == nullptr) { + if (!m_nvmlModule) { auto lastError = ::GetLastError(); if (lastError != ERROR_MOD_NOT_FOUND) // Ignore library not found log::info(str::format("Loading ", nvmlModuleName, " failed with error code: ", lastError)); @@ -39,10 +39,10 @@ namespace dxvk { #undef GETPROCADDR - if (m_nvmlInit_v2 == nullptr - || m_nvmlShutdown == nullptr - || m_nvmlErrorString == nullptr - || m_nvmlDeviceGetHandleByPciBusId_v2 == nullptr) + if (!m_nvmlInit_v2 + || !m_nvmlShutdown + || !m_nvmlErrorString + || !m_nvmlDeviceGetHandleByPciBusId_v2) log::info(str::format("NVML loaded but initialization failed")); else { auto result = m_nvmlInit_v2(); @@ -57,7 +57,7 @@ namespace dxvk { } Nvml::~Nvml() { - if (m_nvmlModule == nullptr) + if (!m_nvmlModule) return; m_nvmlShutdown(); diff --git a/src/nvapi_d3d.cpp b/src/nvapi_d3d.cpp index caff42f7..ec5f628f 100644 --- a/src/nvapi_d3d.cpp +++ b/src/nvapi_d3d.cpp @@ -13,7 +13,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), log::fmt::ptr(pResource), log::fmt::ptr(pHandle)); - if (pResource == nullptr || pHandle == nullptr) + if (!pResource || !pHandle) return InvalidArgument(n); // Fake-implement with a dumb passthrough, though no other NvAPI entry points @@ -60,7 +60,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), log::fmt::ptr(pSliState)); - if (pDevice == nullptr || pSliState == nullptr) + if (!pDevice || !pSliState) return InvalidArgument(n); switch (pSliState->version) { @@ -111,7 +111,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), structVersion, log::fmt::ptr(pGraphicsCaps)); - if (pGraphicsCaps == nullptr) + if (!pGraphicsCaps) return InvalidArgument(n); switch (structVersion) { @@ -149,10 +149,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pDevice == nullptr) + if (!pDevice) return InvalidArgument(n); if (!nvapiD3dInstance->IsReflexAvailable(pDevice)) @@ -176,10 +176,10 @@ extern "C" { static bool lastLowLatencyMode = false; static uint32_t lastMinimumIntervalUs = UINT32_MAX; - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pDevice == nullptr || pSetSleepModeParams == nullptr) + if (!pDevice || !pSetSleepModeParams) return InvalidArgument(n); if (pSetSleepModeParams->version != NV_SET_SLEEP_MODE_PARAMS_VER1) @@ -207,10 +207,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), log::fmt::ptr(pGetSleepStatusParams)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pDevice == nullptr || pGetSleepStatusParams == nullptr) + if (!pDevice || !pGetSleepStatusParams) return InvalidArgument(n); if (pGetSleepStatusParams->version != NV_GET_SLEEP_STATUS_PARAMS_VER1) @@ -233,10 +233,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDev), log::fmt::ptr(pGetLatencyParams)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pDev == nullptr || pGetLatencyParams == nullptr) + if (!pDev || !pGetLatencyParams) return InvalidArgument(n); if (pGetLatencyParams->version != NV_LATENCY_RESULT_PARAMS_VER1) @@ -261,10 +261,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDev), log::fmt::nv_latency_marker_params(pSetLatencyMarkerParams)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pDev == nullptr || pSetLatencyMarkerParams == nullptr) + if (!pDev || !pSetLatencyMarkerParams) return InvalidArgument(n); if (pSetLatencyMarkerParams->version != NV_LATENCY_MARKER_PARAMS_VER1) diff --git a/src/nvapi_d3d11.cpp b/src/nvapi_d3d11.cpp index 6505001f..984ba769 100644 --- a/src/nvapi_d3d11.cpp +++ b/src/nvapi_d3d11.cpp @@ -14,7 +14,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pAdapter), DriverType, Software, log::fmt::flags(Flags), log::fmt::ptr(pFeatureLevels), FeatureLevels, SDKVersion, log::fmt::ptr(ppDevice), log::fmt::ptr(pFeatureLevel), log::fmt::ptr(ppImmediateContext), log::fmt::ptr(pSupportedLevel)); - if (pSupportedLevel == nullptr) + if (!pSupportedLevel) return InvalidArgument(n); if (FAILED(::D3D11CreateDevice(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, ppDevice, pFeatureLevel, ppImmediateContext))) @@ -31,7 +31,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pAdapter), DriverType, Software, log::fmt::flags(Flags), log::fmt::ptr(pFeatureLevels), FeatureLevels, SDKVersion, log::fmt::ptr(pSwapChainDesc), log::fmt::ptr(ppSwapChain), log::fmt::ptr(ppDevice), log::fmt::ptr(pFeatureLevel), log::fmt::ptr(ppImmediateContext), log::fmt::ptr(pSupportedLevel)); - if (pSupportedLevel == nullptr) + if (!pSupportedLevel) return InvalidArgument(n); if (FAILED(::D3D11CreateDeviceAndSwapChain(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, pSwapChainDesc, ppSwapChain, ppDevice, pFeatureLevel, ppImmediateContext))) @@ -48,7 +48,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDeviceOrContext), code, log::fmt::ptr(supported)); - if (pDeviceOrContext == nullptr || supported == nullptr) + if (!pDeviceOrContext || !supported) return InvalidArgument(n); // DXVK does not know any NVIDIA intrinsics backdoors @@ -63,10 +63,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pMultiGPUCaps)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pMultiGPUCaps == nullptr) + if (!pMultiGPUCaps) return InvalidArgument(n); auto version = pMultiGPUCaps->version; @@ -112,7 +112,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDeviceOrContext), bEnable, log::fmt::flt(fMinDepth), log::fmt::flt(fMaxDepth)); - if (pDeviceOrContext == nullptr) + if (!pDeviceOrContext) return InvalidArgument(n); if (!NvapiD3d11Device::SetDepthBoundsTest(pDeviceOrContext, bEnable, fMinDepth, fMaxDepth)) @@ -129,7 +129,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDeviceOrContext)); - if (pDeviceOrContext == nullptr) + if (!pDeviceOrContext) return InvalidArgument(n); if (!NvapiD3d11Device::BeginUAVOverlap(pDeviceOrContext)) @@ -146,7 +146,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDeviceOrContext)); - if (pDeviceOrContext == nullptr) + if (!pDeviceOrContext) return InvalidArgument(n); if (!NvapiD3d11Device::EndUAVOverlap(pDeviceOrContext)) @@ -163,7 +163,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevContext11), drawCount, log::fmt::ptr(pBuffer), alignedByteOffsetForArgs, alignedByteStrideForArgs); - if (pDevContext11 == nullptr || pBuffer == nullptr) + if (!pDevContext11 || !pBuffer) return InvalidArgument(n); if (!NvapiD3d11Device::MultiDrawInstancedIndirect(pDevContext11, drawCount, pBuffer, alignedByteOffsetForArgs, alignedByteStrideForArgs)) @@ -180,7 +180,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevContext11), drawCount, log::fmt::ptr(pBuffer), alignedByteOffsetForArgs, alignedByteStrideForArgs); - if (pDevContext11 == nullptr || pBuffer == nullptr) + if (!pDevContext11 || !pBuffer) return InvalidArgument(n); if (!NvapiD3d11Device::MultiDrawIndexedInstancedIndirect(pDevContext11, drawCount, pBuffer, alignedByteOffsetForArgs, alignedByteStrideForArgs)) @@ -197,7 +197,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), log::fmt::ptr(pCubin), size, blockX, blockY, blockZ, log::fmt::ptr(phShader)); - if (pDevice == nullptr || pCubin == nullptr || phShader == nullptr) + if (!pDevice || !pCubin || !phShader) return InvalidArgument(n); if (!NvapiD3d11Device::CreateCubinComputeShaderWithName(pDevice, pCubin, size, blockX, blockY, blockZ, "", phShader)) @@ -214,7 +214,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), log::fmt::ptr(pCubin), size, blockX, blockY, blockZ, log::fmt::ptr(pShaderName), log::fmt::ptr(phShader)); - if (pDevice == nullptr || pCubin == nullptr || pShaderName == nullptr || phShader == nullptr) + if (!pDevice || !pCubin || !pShaderName || !phShader) return InvalidArgument(n); if (!NvapiD3d11Device::CreateCubinComputeShaderWithName(pDevice, pCubin, size, blockX, blockY, blockZ, pShaderName, phShader)) @@ -231,7 +231,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDeviceContext), log::fmt::hnd(hShader), gridX, gridY, gridZ, log::fmt::ptr(pParams), paramSize, log::fmt::ptr(pReadResources), numReadResources, log::fmt::ptr(pWriteResources), numWriteResources); - if (pDeviceContext == nullptr) + if (!pDeviceContext) return InvalidArgument(n); if (!NvapiD3d11Device::LaunchCubinShader(pDeviceContext, hShader, gridX, gridY, gridZ, pParams, paramSize, pReadResources, numReadResources, pWriteResources, numWriteResources)) @@ -248,7 +248,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), log::fmt::hnd(hShader)); - if (pDevice == nullptr) + if (!pDevice) return InvalidArgument(n); if (!NvapiD3d11Device::DestroyCubinShader(hShader)) @@ -264,7 +264,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), log::fmt::ptr(pSupported)); - if (pDevice == nullptr || pSupported == nullptr) + if (!pDevice || !pSupported) return InvalidArgument(n); *pSupported = NvapiD3d11Device::IsFatbinPTXSupported(pDevice); @@ -280,7 +280,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), log::fmt::ptr(pResource), log::fmt::ptr(pDesc), log::fmt::ptr(ppUAV), log::fmt::ptr(pDriverHandle)); - if (pDevice == nullptr || pResource == nullptr || pDesc == nullptr || ppUAV == nullptr || pDriverHandle == nullptr) + if (!pDevice || !pResource || !pDesc || !ppUAV || !pDriverHandle) return InvalidArgument(n); if (!NvapiD3d11Device::CreateUnorderedAccessViewAndGetDriverHandle(pDevice, pResource, pDesc, ppUAV, pDriverHandle)) @@ -297,7 +297,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), log::fmt::ptr(pResource), log::fmt::ptr(pDesc), log::fmt::ptr(ppSRV), log::fmt::ptr(pDriverHandle)); - if (pDevice == nullptr || pResource == nullptr || pDesc == nullptr || ppSRV == nullptr || pDriverHandle == nullptr) + if (!pDevice || !pResource || !pDesc || !ppSRV || !pDriverHandle) return InvalidArgument(n); if (!NvapiD3d11Device::CreateShaderResourceViewAndGetDriverHandle(pDevice, pResource, pDesc, ppSRV, pDriverHandle)) @@ -314,7 +314,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), log::fmt::ptr(pResource), log::fmt::ptr(phObject)); - if (pDevice == nullptr || pResource == nullptr || phObject == nullptr) + if (!pDevice || !pResource || !phObject) return InvalidArgument(n); if (!NvapiD3d11Device::GetResourceDriverHandle(pResource, phObject)) @@ -331,7 +331,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), log::fmt::hnd(hResource), log::fmt::ptr(pGpuVA)); - if (pDevice == nullptr || hResource == NVDX_OBJECT_NONE || pGpuVA == nullptr) + if (!pDevice || hResource == NVDX_OBJECT_NONE || !pGpuVA) return InvalidArgument(n); NvU64 dummy; @@ -349,7 +349,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), log::fmt::ptr(pParams)); - if (pDevice == nullptr || pParams == nullptr) + if (!pDevice || !pParams) return InvalidArgument(n); if (pParams->version != NV_GET_GPU_VIRTUAL_ADDRESS_VER1) @@ -372,7 +372,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), log::fmt::ptr(pSamplerDesc), log::fmt::ptr(ppSamplerState), log::fmt::ptr(pDriverHandle)); - if (pDevice == nullptr || pSamplerDesc == nullptr || ppSamplerState == nullptr || pDriverHandle == nullptr) + if (!pDevice || !pSamplerDesc || !ppSamplerState || !pDriverHandle) return InvalidArgument(n); if (!NvapiD3d11Device::CreateSamplerStateAndGetDriverHandle(pDevice, pSamplerDesc, ppSamplerState, reinterpret_cast(pDriverHandle))) @@ -389,7 +389,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), srvDriverHandle, samplerDriverHandle, log::fmt::ptr(pCudaTextureHandle)); - if (pDevice == nullptr || pCudaTextureHandle == nullptr) + if (!pDevice || !pCudaTextureHandle) return InvalidArgument(n); if (!NvapiD3d11Device::GetCudaTextureObject(pDevice, srvDriverHandle, samplerDriverHandle, reinterpret_cast(pCudaTextureHandle))) diff --git a/src/nvapi_d3d12.cpp b/src/nvapi_d3d12.cpp index f82162c4..bb75638f 100644 --- a/src/nvapi_d3d12.cpp +++ b/src/nvapi_d3d12.cpp @@ -16,7 +16,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), opCode, log::fmt::ptr(pSupported)); - if (pDevice == nullptr || pSupported == nullptr) + if (!pDevice || !pSupported) return InvalidArgument(n); // VKD3D-Proton does not know any NVIDIA intrinsics @@ -31,7 +31,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), log::fmt::ptr(pNumMetaCommands), log::fmt::ptr(pDescs)); - if (pDevice == nullptr || pNumMetaCommands == nullptr) + if (!pDevice || !pNumMetaCommands) return InvalidArgument(n); *pNumMetaCommands = 0; // No meta commands with this implementation @@ -47,7 +47,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), log::fmt::ptr(cubinData), cubinSize, blockX, blockY, blockZ, smemSize, log::fmt::ptr(shaderName), log::fmt::ptr(pShader)); - if (pDevice == nullptr || shaderName == nullptr || pShader == nullptr) + if (!pDevice || !shaderName || !pShader) return InvalidArgument(n); if (!NvapiD3d12Device::CreateCubinComputeShaderEx(pDevice, cubinData, cubinSize, blockX, blockY, blockZ, smemSize, shaderName, pShader)) @@ -64,7 +64,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), log::fmt::ptr(cubinData), cubinSize, blockX, blockY, blockZ, log::fmt::ptr(shaderName), log::fmt::ptr(pShader)); - if (pDevice == nullptr || shaderName == nullptr || pShader == nullptr) + if (!pDevice || !shaderName || !pShader) return InvalidArgument(n); if (!NvapiD3d12Device::CreateCubinComputeShaderWithName(pDevice, cubinData, cubinSize, blockX, blockY, blockZ, shaderName, pShader)) @@ -81,7 +81,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), log::fmt::ptr(cubinData), cubinSize, blockX, blockY, blockZ, log::fmt::ptr(pShader)); - if (pDevice == nullptr || pShader == nullptr) + if (!pDevice || !pShader) return InvalidArgument(n); if (!NvapiD3d12Device::CreateCubinComputeShaderWithName(pDevice, cubinData, cubinSize, blockX, blockY, blockZ, "", pShader)) @@ -98,7 +98,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), log::fmt::hnd(pShader)); - if (pDevice == nullptr) + if (!pDevice) return InvalidArgument(n); if (!NvapiD3d12Device::DestroyCubinComputeShader(pDevice, pShader)) @@ -115,7 +115,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), log::fmt::d3d12_cpu_descriptor_handle(srvHandle), log::fmt::d3d12_cpu_descriptor_handle(samplerHandle), log::fmt::ptr(cudaTextureHandle)); - if (pDevice == nullptr || cudaTextureHandle == nullptr) + if (!pDevice || !cudaTextureHandle) return InvalidArgument(n); if (!NvapiD3d12Device::GetCudaTextureObject(pDevice, srvHandle, samplerHandle, cudaTextureHandle)) @@ -132,7 +132,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), log::fmt::d3d12_cpu_descriptor_handle(uavHandle), log::fmt::ptr(cudaSurfaceHandle)); - if (pDevice == nullptr || cudaSurfaceHandle == nullptr) + if (!pDevice || !cudaSurfaceHandle) return InvalidArgument(n); if (!NvapiD3d12Device::GetCudaSurfaceObject(pDevice, uavHandle, cudaSurfaceHandle)) @@ -149,7 +149,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pCmdList), log::fmt::hnd(pShader), blockX, blockY, blockZ, log::fmt::ptr(params), paramSize); - if (pCmdList == nullptr) + if (!pCmdList) return InvalidArgument(n); if (!NvapiD3d12Device::LaunchCubinShader(pCmdList, pShader, blockX, blockY, blockZ, params, paramSize)) @@ -166,7 +166,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), log::fmt::ptr(pUAVInfo)); - if (pDevice == nullptr || pUAVInfo == nullptr) + if (!pDevice || !pUAVInfo) return InvalidArgument(n); if (!NvapiD3d12Device::CaptureUAVInfo(pDevice, pUAVInfo)) @@ -181,10 +181,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), structVersion, log::fmt::ptr(pGraphicsCaps)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pDevice == nullptr || pGraphicsCaps == nullptr) + if (!pDevice || !pGraphicsCaps) return InvalidArgument(n); if (structVersion != NV_D3D12_GRAPHICS_CAPS_VER1) @@ -202,7 +202,7 @@ extern "C" { if (luid.has_value()) adapter = nvapiAdapterRegistry->FindAdapter(luid.value()); - if (adapter == nullptr) + if (!adapter) return Ok(str::format(n, " (sm_0)")); // From https://arnon.dk/matching-sm-architectures-arch-and-gencode-for-various-nvidia-cards/ and https://en.wikipedia.org/wiki/CUDA#GPUs_supported @@ -230,7 +230,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), log::fmt::ptr(isSupported)); - if (pDevice == nullptr || isSupported == nullptr) + if (!pDevice || !isSupported) return InvalidArgument(n); *isSupported = NvapiD3d12Device::IsFatbinPTXSupported(pDevice); @@ -247,7 +247,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), log::fmt::ptr(pPSODesc), numExtensions, log::fmt::ptr(ppExtensions), log::fmt::ptr(ppPSO)); - if (pDevice == nullptr || pPSODesc == nullptr || ppExtensions == nullptr || ppPSO == nullptr) + if (!pDevice || !pPSODesc || !ppExtensions || !ppPSO) return InvalidArgument(n); if (numExtensions == 0) @@ -276,7 +276,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pCommandList), log::fmt::flt(minDepth), log::fmt::flt(maxDepth)); - if (pCommandList == nullptr) + if (!pCommandList) return InvalidArgument(n); if (!NvapiD3d12Device::SetDepthBoundsTestValues(pCommandList, minDepth, maxDepth)) @@ -291,7 +291,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), type, log::fmt::ptr(pData), dataSize); - if (pDevice == nullptr || pData == nullptr) + if (!pDevice || !pData) return InvalidPointer(n); switch (type) { @@ -385,13 +385,13 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDevice), log::fmt::ptr(pParams)); - if (pDevice == nullptr || pParams == nullptr) + if (!pDevice || !pParams) return InvalidArgument(n); if (pParams->version != NVAPI_GET_RAYTRACING_ACCELERATION_STRUCTURE_PREBUILD_INFO_EX_PARAMS_VER1) return IncompatibleStructVersion(n, pParams->version); - if (pParams->pDesc == nullptr || pParams->pInfo == nullptr) + if (!pParams->pDesc || !pParams->pInfo) return InvalidArgument(n); std::vector geometryDescs{}; @@ -412,13 +412,13 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pCommandList), log::fmt::ptr(pParams)); - if (pCommandList == nullptr || pParams == nullptr) + if (!pCommandList || !pParams) return InvalidArgument(n); if (pParams->version != NVAPI_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_EX_PARAMS_VER1) return IncompatibleStructVersion(n, pParams->version); - if (pParams->pDesc == nullptr || (pParams->numPostbuildInfoDescs != 0 && pParams->pPostbuildInfoDescs == nullptr)) + if (!pParams->pDesc || (pParams->numPostbuildInfoDescs != 0 && !pParams->pPostbuildInfoDescs)) return InvalidArgument(n); std::vector geometryDescs{}; @@ -446,10 +446,10 @@ extern "C" { if (log::tracing()) log::trace(n, cqType); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pCommandQueue == nullptr) + if (!pCommandQueue) return InvalidPointer(n); if (nvapiD3dInstance->IsUsingLfx() || !NvapiD3dLowLatencyDevice::SupportsLowLatency(pCommandQueue)) @@ -473,10 +473,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pCommandQueue), log::fmt::nv_async_frame_marker_params(pSetAsyncFrameMarkerParams)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pCommandQueue == nullptr || pSetAsyncFrameMarkerParams == nullptr) + if (!pCommandQueue || !pSetAsyncFrameMarkerParams) return InvalidPointer(n); if (pSetAsyncFrameMarkerParams->version != NV_LATENCY_MARKER_PARAMS_VER1) diff --git a/src/nvapi_disp.cpp b/src/nvapi_disp.cpp index b7cfeb84..07f45591 100644 --- a/src/nvapi_disp.cpp +++ b/src/nvapi_disp.cpp @@ -43,14 +43,14 @@ extern "C" { if (log::tracing()) log::trace(n, displayId, log::fmt::ptr(pHdrCapabilities)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pHdrCapabilities == nullptr) + if (!pHdrCapabilities) return InvalidArgument(n); auto output = nvapiAdapterRegistry->FindOutput(displayId); - if (output == nullptr) + if (!output) return InvalidArgument(n); const auto& data = output->GetColorData(); @@ -121,18 +121,18 @@ extern "C" { if (log::tracing()) log::trace(n, displayId, log::fmt::ptr(pHdrColorData)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pHdrColorData == nullptr) + if (!pHdrColorData) return InvalidArgument(n); auto output = nvapiAdapterRegistry->FindOutput(displayId); - if (output == nullptr) + if (!output) return InvalidArgument(n); auto interop = nvapiAdapterRegistry->GetInteropFactory(); - if (interop == nullptr) + if (!interop) return NoImplementation(str::format(n, " (0x", std::hex, displayId, ")")); auto& data = output->GetColorData(); @@ -218,14 +218,14 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(displayName), log::fmt::ptr(displayId)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (displayName == nullptr || displayId == nullptr) + if (!displayName || !displayId) return InvalidArgument(n); auto output = nvapiAdapterRegistry->FindOutput(std::string(displayName)); - if (output == nullptr) + if (!output) return InvalidArgument(str::format(n, " (", displayName, ")")); *displayId = output->GetId(); @@ -239,14 +239,14 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(displayId)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (displayId == nullptr) + if (!displayId) return InvalidArgument(n); auto output = nvapiAdapterRegistry->FindPrimaryOutput(); - if (output == nullptr) + if (!output) return NvidiaDeviceNotFound(n); *displayId = output->GetId(); diff --git a/src/nvapi_drs.cpp b/src/nvapi_drs.cpp index e819f6b5..6d34eb1e 100644 --- a/src/nvapi_drs.cpp +++ b/src/nvapi_drs.cpp @@ -15,7 +15,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(phSession)); - if (phSession == nullptr) + if (!phSession) return InvalidArgument(n); *phSession = nvapiDrsSession; @@ -56,7 +56,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hSession), log::fmt::ptr(phProfile)); - if (phProfile == nullptr) + if (!phProfile) return InvalidArgument(n); *phProfile = nvapiDrsProfile; @@ -70,7 +70,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hSession), log::fmt::ptr(phProfile)); - if (phProfile == nullptr) + if (!phProfile) return InvalidArgument(n); *phProfile = nvapiDrsProfile; diff --git a/src/nvapi_gpu.cpp b/src/nvapi_gpu.cpp index 5d2e6d28..2186e8b9 100644 --- a/src/nvapi_gpu.cpp +++ b/src/nvapi_gpu.cpp @@ -13,20 +13,20 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGpu), log::fmt::ptr(pDisplayIds), log::fmt::ptr(pDisplayIdCount), log::fmt::flags(flags)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); auto adapter = reinterpret_cast(hPhysicalGpu); if (!nvapiAdapterRegistry->IsAdapter(adapter)) return ExpectedPhysicalGpuHandle(n); - if (pDisplayIdCount == nullptr) + if (!pDisplayIdCount) return InvalidArgument(n); // TODO: return 0 when flags contain NV_GPU_CONNECTED_IDS_FLAG_SLI auto count = nvapiAdapterRegistry->GetOutputCount(adapter); - if (pDisplayIds == nullptr) { + if (!pDisplayIds) { *pDisplayIdCount = count; return Ok(n); } @@ -66,10 +66,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGpu), log::fmt::ptr(pWidth)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pWidth == nullptr) + if (!pWidth) return InvalidArgument(n); auto adapter = reinterpret_cast(hPhysicalGpu); @@ -108,10 +108,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGpu), log::fmt::ptr(pIRQ)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pIRQ == nullptr) + if (!pIRQ) return InvalidArgument(n); auto adapter = reinterpret_cast(hPhysicalGpu); @@ -150,10 +150,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGpu), log::fmt::ptr(pCount)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pCount == nullptr) + if (!pCount) return InvalidArgument(n); auto adapter = reinterpret_cast(hPhysicalGpu); @@ -192,10 +192,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGpu), log::fmt::ptr(pGpuType)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pGpuType == nullptr) + if (!pGpuType) return InvalidArgument(n); auto adapter = reinterpret_cast(hPhysicalGpu); @@ -213,10 +213,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGpu), log::fmt::ptr(pSystemType)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pSystemType == nullptr) + if (!pSystemType) return InvalidArgument(n); *pSystemType = NV_SYSTEM_TYPE_UNKNOWN; @@ -230,10 +230,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGpu), log::fmt::ptr(pDeviceId), log::fmt::ptr(pSubSystemId), log::fmt::ptr(pRevisionId), log::fmt::ptr(pExtDeviceId)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pDeviceId == nullptr || pSubSystemId == nullptr || pRevisionId == nullptr || pExtDeviceId == nullptr) + if (!pDeviceId || !pSubSystemId || !pRevisionId || !pExtDeviceId) return InvalidArgument(n); auto adapter = reinterpret_cast(hPhysicalGpu); @@ -254,10 +254,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGpu), log::fmt::ptr(szName)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (szName == nullptr) + if (!szName) return InvalidArgument(n); auto adapter = reinterpret_cast(hPhysicalGpu); @@ -275,10 +275,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGpu), log::fmt::ptr(pBusId)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pBusId == nullptr) + if (!pBusId) return InvalidArgument(n); auto adapter = reinterpret_cast(hPhysicalGpu); @@ -296,10 +296,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGpu), log::fmt::ptr(pBusSlotId)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pBusSlotId == nullptr) + if (!pBusSlotId) return InvalidArgument(n); auto adapter = reinterpret_cast(hPhysicalGpu); @@ -320,10 +320,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGpu), log::fmt::ptr(pBusType)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pBusType == nullptr) + if (!pBusType) return InvalidArgument(n); auto adapter = reinterpret_cast(hPhysicalGpu); @@ -353,10 +353,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGpu), log::fmt::ptr(pSize)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pSize == nullptr) + if (!pSize) return InvalidArgument(n); auto adapter = reinterpret_cast(hPhysicalGpu); @@ -374,10 +374,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGpu), log::fmt::ptr(pSize)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pSize == nullptr) + if (!pSize) return InvalidArgument(n); auto adapter = reinterpret_cast(hPhysicalGpu); @@ -396,10 +396,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGpu), log::fmt::ptr(pMemoryInfo)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pMemoryInfo == nullptr) + if (!pMemoryInfo) return InvalidArgument(n); auto adapter = reinterpret_cast(hPhysicalGpu); @@ -454,10 +454,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGpu), log::fmt::ptr(pMemoryInfo)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pMemoryInfo == nullptr) + if (!pMemoryInfo) return InvalidArgument(n); auto adapter = reinterpret_cast(hPhysicalGpu); @@ -495,10 +495,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGpu), log::fmt::ptr(pOSAdapterId)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pOSAdapterId == nullptr) + if (!pOSAdapterId) return InvalidArgument(n); auto adapter = reinterpret_cast(hPhysicalGpu); @@ -520,16 +520,16 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hLogicalGpu), log::fmt::ptr(pLogicalGpuData)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pLogicalGpuData == nullptr) + if (!pLogicalGpuData) return InvalidArgument(n); if (pLogicalGpuData->version != NV_LOGICAL_GPU_DATA_VER1) return IncompatibleStructVersion(n, pLogicalGpuData->version); - if (pLogicalGpuData->pOSAdapterId == nullptr) + if (!pLogicalGpuData->pOSAdapterId) return InvalidArgument(n); auto adapter = reinterpret_cast(hLogicalGpu); @@ -558,10 +558,10 @@ extern "C" { auto returnAddress = _ReturnAddress(); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pGpuArchInfo == nullptr) + if (!pGpuArchInfo) return InvalidArgument(n); auto adapter = reinterpret_cast(hPhysicalGpu); @@ -637,10 +637,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pComputeTopo)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pComputeTopo == nullptr) + if (!pComputeTopo) return InvalidArgument(n); if (pComputeTopo->version != NV_COMPUTE_GPU_TOPOLOGY_VER1) @@ -681,10 +681,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGpu), log::fmt::ptr(pGpuInfo)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pGpuInfo == nullptr) + if (!pGpuInfo) return InvalidArgument(n); auto adapter = reinterpret_cast(hPhysicalGpu); @@ -720,10 +720,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGpu), log::fmt::ptr(szBiosRevision)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (szBiosRevision == nullptr) + if (!szBiosRevision) return InvalidArgument(n); auto adapter = reinterpret_cast(hPhysicalGpu); @@ -762,10 +762,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGpu), log::fmt::ptr(pDynamicPstatesInfoEx)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pDynamicPstatesInfoEx == nullptr) + if (!pDynamicPstatesInfoEx) return InvalidArgument(n); if (pDynamicPstatesInfoEx->version != NV_GPU_DYNAMIC_PSTATES_INFO_EX_VER) @@ -860,10 +860,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGpu), sensorIndex, log::fmt::ptr(pThermalSettings)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pThermalSettings == nullptr) + if (!pThermalSettings) return InvalidArgument(n); if (pThermalSettings->version != NV_GPU_THERMAL_SETTINGS_VER_1 && pThermalSettings->version != NV_GPU_THERMAL_SETTINGS_VER_2) @@ -1016,10 +1016,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGpu), log::fmt::ptr(pCurrentPstate)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pCurrentPstate == nullptr) + if (!pCurrentPstate) return InvalidArgument(n); auto adapter = reinterpret_cast(hPhysicalGpu); @@ -1062,10 +1062,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGpu), log::fmt::ptr(pClkFreqs)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pClkFreqs == nullptr) + if (!pClkFreqs) return InvalidArgument(n); if (pClkFreqs->version != NV_GPU_CLOCK_FREQUENCIES_VER_1 && pClkFreqs->version != NV_GPU_CLOCK_FREQUENCIES_VER_2 && pClkFreqs->version != NV_GPU_CLOCK_FREQUENCIES_VER_3) @@ -1199,10 +1199,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::hnd(hPhysicalGpu), log::fmt::ptr(pPstatesInfo)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pPstatesInfo == nullptr) + if (!pPstatesInfo) return InvalidArgument(n); auto adapter = reinterpret_cast(hPhysicalGpu); diff --git a/src/nvapi_sys.cpp b/src/nvapi_sys.cpp index 4d0c0138..c8d61293 100644 --- a/src/nvapi_sys.cpp +++ b/src/nvapi_sys.cpp @@ -12,14 +12,14 @@ extern "C" { if (log::tracing()) log::trace(n, displayId, log::fmt::ptr(hPhysicalGpu)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (hPhysicalGpu == nullptr) + if (!hPhysicalGpu) return InvalidArgument(n); auto output = nvapiAdapterRegistry->FindOutput(displayId); - if (output == nullptr) + if (!output) return InvalidArgument(n); *hPhysicalGpu = reinterpret_cast(output->GetParent()); @@ -33,10 +33,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDriverVersion), log::fmt::ptr(szBuildBranchString)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pDriverVersion == nullptr || szBuildBranchString == nullptr) + if (!pDriverVersion || !szBuildBranchString) return InvalidArgument(n); *pDriverVersion = nvapiAdapterRegistry->GetFirstAdapter()->GetDriverVersion(); @@ -51,10 +51,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pDriverInfo)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pDriverInfo == nullptr) + if (!pDriverInfo) return InvalidArgument(n); if (pDriverInfo->version != NV_DISPLAY_DRIVER_INFO_VER1 && pDriverInfo->version != NV_DISPLAY_DRIVER_INFO_VER2) @@ -96,10 +96,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pPhysicalGPUs)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pPhysicalGPUs == nullptr) + if (!pPhysicalGPUs) return InvalidArgument(n); if (pPhysicalGPUs->version != NV_PHYSICAL_GPUS_VER1) @@ -121,10 +121,10 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(pLogicalGPUs)); - if (nvapiAdapterRegistry == nullptr) + if (!nvapiAdapterRegistry) return ApiNotInitialized(n); - if (pLogicalGPUs == nullptr) + if (!pLogicalGPUs) return InvalidArgument(n); if (pLogicalGPUs->version != NV_LOGICAL_GPUS_VER1) From d8d1db809611506910ef54a7b2cdca73d38af584 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sat, 25 Jan 2025 19:24:39 +0100 Subject: [PATCH 02/23] nvapi: Use cpp-style casts IDE hint. --- src/nvapi/resource_factory.cpp | 2 +- src/nvapi_d3d.cpp | 2 +- src/nvapi_d3d12.cpp | 6 +++--- src/nvapi_vulkan.cpp | 18 +++++++++--------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/nvapi/resource_factory.cpp b/src/nvapi/resource_factory.cpp index 10d2562d..ec3f2b3e 100644 --- a/src/nvapi/resource_factory.cpp +++ b/src/nvapi/resource_factory.cpp @@ -10,7 +10,7 @@ namespace dxvk { Com ResourceFactory::CreateDXGIFactory1() { Com dxgiFactory; - if (FAILED(::CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&dxgiFactory))) { + if (FAILED(::CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory)))) { log::info("Creating DXGI Factory (IDXGIFactory1) failed, please ensure that DXVK's dxgi.dll is present"); return nullptr; } diff --git a/src/nvapi_d3d.cpp b/src/nvapi_d3d.cpp index ec5f628f..0f753eb8 100644 --- a/src/nvapi_d3d.cpp +++ b/src/nvapi_d3d.cpp @@ -18,7 +18,7 @@ extern "C" { // Fake-implement with a dumb passthrough, though no other NvAPI entry points // we're likely to implement should care about the actual handle value. - *pHandle = (NVDX_ObjectHandle)pResource; + *pHandle = reinterpret_cast(pResource); return Ok(n, alreadyLogged); } diff --git a/src/nvapi_d3d12.cpp b/src/nvapi_d3d12.cpp index bb75638f..bc47ce3b 100644 --- a/src/nvapi_d3d12.cpp +++ b/src/nvapi_d3d12.cpp @@ -300,21 +300,21 @@ extern "C" { return InvalidArgument(n); // let's hope that NvAPI_D3D12_IsNvShaderExtnOpCodeSupported returning false is enough to discourage games from attempting to use Shader Execution Reordering - *(NVAPI_D3D12_RAYTRACING_THREAD_REORDERING_CAPS*)pData = NVAPI_D3D12_RAYTRACING_THREAD_REORDERING_CAP_NONE; + *static_cast(pData) = NVAPI_D3D12_RAYTRACING_THREAD_REORDERING_CAP_NONE; break; case NVAPI_D3D12_RAYTRACING_CAPS_TYPE_OPACITY_MICROMAP: if (dataSize != sizeof(NVAPI_D3D12_RAYTRACING_OPACITY_MICROMAP_CAPS)) return InvalidArgument(n); - *(NVAPI_D3D12_RAYTRACING_OPACITY_MICROMAP_CAPS*)pData = NVAPI_D3D12_RAYTRACING_OPACITY_MICROMAP_CAP_NONE; + *static_cast(pData) = NVAPI_D3D12_RAYTRACING_OPACITY_MICROMAP_CAP_NONE; break; case NVAPI_D3D12_RAYTRACING_CAPS_TYPE_DISPLACEMENT_MICROMAP: if (dataSize != sizeof(NVAPI_D3D12_RAYTRACING_DISPLACEMENT_MICROMAP_CAPS)) return InvalidArgument(n); - *(NVAPI_D3D12_RAYTRACING_DISPLACEMENT_MICROMAP_CAPS*)pData = NVAPI_D3D12_RAYTRACING_DISPLACEMENT_MICROMAP_CAP_NONE; + *static_cast(pData) = NVAPI_D3D12_RAYTRACING_DISPLACEMENT_MICROMAP_CAP_NONE; break; default: diff --git a/src/nvapi_vulkan.cpp b/src/nvapi_vulkan.cpp index 21c582cc..3f8476c9 100644 --- a/src/nvapi_vulkan.cpp +++ b/src/nvapi_vulkan.cpp @@ -17,7 +17,7 @@ extern "C" { NvapiVulkanLowLatencyDevice::Initialize(*resourceFactory); - auto device = reinterpret_cast(vkDevice); + auto device = static_cast(vkDevice); auto semaphore = reinterpret_cast(signalSemaphoreHandle); if (!device) @@ -52,7 +52,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(vkDevice)); - auto device = reinterpret_cast(vkDevice); + auto device = static_cast(vkDevice); if (!device) return InvalidArgument(n); @@ -67,7 +67,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(vkDevice), log::fmt::nv_vk_get_sleep_status_params(pGetSleepStatusParams)); - auto device = reinterpret_cast(vkDevice); + auto device = static_cast(vkDevice); if (!device) return InvalidArgument(n); @@ -96,7 +96,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(vkDevice), log::fmt::nv_vk_set_sleep_status_params(pSetSleepModeParams)); - auto device = reinterpret_cast(vkDevice); + auto device = static_cast(vkDevice); if (!device) return InvalidArgument(n); @@ -123,7 +123,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(vkDevice), signalValue); - auto device = reinterpret_cast(vkDevice); + auto device = static_cast(vkDevice); if (!device) return InvalidArgument(n); @@ -145,7 +145,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(vkDevice), log::fmt::nv_vk_latency_result_params(pGetLatencyParams)); - auto device = reinterpret_cast(vkDevice); + auto device = static_cast(vkDevice); if (!device) return InvalidArgument(n); @@ -187,7 +187,7 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(vkDevice), log::fmt::nv_vk_latency_marker_params(pSetLatencyMarkerParams)); - auto device = reinterpret_cast(vkDevice); + auto device = static_cast(vkDevice); if (!device) return InvalidArgument(n); @@ -224,8 +224,8 @@ extern "C" { if (log::tracing()) log::trace(n, log::fmt::ptr(vkDevice), log::fmt::ptr(queueHandle), queueType); - auto device = reinterpret_cast(vkDevice); - auto queue = reinterpret_cast(queueHandle); + auto device = static_cast(vkDevice); + auto queue = static_cast(queueHandle); if (!device || !queue) return InvalidArgument(n); From 920c0eb8282f5bef75c4a199884f0a74c8774574 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sat, 25 Jan 2025 19:29:17 +0100 Subject: [PATCH 03/23] nvapi-d3d: Declare functions const IDE hint --- src/nvapi/nvapi_d3d_instance.cpp | 4 ++-- src/nvapi/nvapi_d3d_instance.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/nvapi/nvapi_d3d_instance.cpp b/src/nvapi/nvapi_d3d_instance.cpp index 7238eb46..8c03dece 100644 --- a/src/nvapi/nvapi_d3d_instance.cpp +++ b/src/nvapi/nvapi_d3d_instance.cpp @@ -14,7 +14,7 @@ namespace dxvk { log::info("LatencyFleX loaded and initialized successfully"); } - bool NvapiD3dInstance::IsReflexAvailable(IUnknown* device) { + bool NvapiD3dInstance::IsReflexAvailable(IUnknown* device) const { return NvapiD3dLowLatencyDevice::SupportsLowLatency(device) || m_lfx->IsAvailable(); } @@ -40,7 +40,7 @@ namespace dxvk { return result; } - bool NvapiD3dInstance::Sleep(IUnknown* device) { + bool NvapiD3dInstance::Sleep(IUnknown* device) const { bool result = true; if (m_lfx->IsAvailable() && m_isLowLatencyEnabled) diff --git a/src/nvapi/nvapi_d3d_instance.h b/src/nvapi/nvapi_d3d_instance.h index 5b3cf6d2..0c2cd129 100644 --- a/src/nvapi/nvapi_d3d_instance.h +++ b/src/nvapi/nvapi_d3d_instance.h @@ -10,11 +10,11 @@ namespace dxvk { ~NvapiD3dInstance(); void Initialize(); - [[nodiscard]] bool IsReflexAvailable(IUnknown* device); + [[nodiscard]] bool IsReflexAvailable(IUnknown* device) const; [[nodiscard]] bool IsLowLatencyEnabled() const; [[nodiscard]] bool IsUsingLfx() const; [[nodiscard]] bool SetReflexMode(IUnknown* device, bool enable, bool boost, uint32_t frameTimeUs); - [[nodiscard]] bool Sleep(IUnknown* device); + [[nodiscard]] bool Sleep(IUnknown* device) const; private: constexpr static uint64_t kNanoInMicro = 1000; From f3156a00a8a230a7af42d56a5693238ededf72ae Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sat, 25 Jan 2025 19:35:13 +0100 Subject: [PATCH 04/23] nvapi: Move assignment into switch statement IDE hint. --- src/nvapi_d3d11.cpp | 3 +-- src/nvapi_gpu.cpp | 18 ++++++------------ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/nvapi_d3d11.cpp b/src/nvapi_d3d11.cpp index 984ba769..a5c27ab6 100644 --- a/src/nvapi_d3d11.cpp +++ b/src/nvapi_d3d11.cpp @@ -69,8 +69,7 @@ extern "C" { if (!pMultiGPUCaps) return InvalidArgument(n); - auto version = pMultiGPUCaps->version; - switch (version) { // NOLINT(*-multiway-paths-covered) + switch (auto version = pMultiGPUCaps->version) { // NOLINT(*-multiway-paths-covered) case NV_MULTIGPU_CAPS_VER2: *pMultiGPUCaps = {}; pMultiGPUCaps->version = version; diff --git a/src/nvapi_gpu.cpp b/src/nvapi_gpu.cpp index 2186e8b9..b40a75c1 100644 --- a/src/nvapi_gpu.cpp +++ b/src/nvapi_gpu.cpp @@ -36,8 +36,7 @@ extern "C" { return InsufficientBuffer(n); } - auto version = pDisplayIds->version; - switch (version) { + switch (auto version = pDisplayIds->version) { case NV_GPU_DISPLAYIDS_VER1: // Both versions use the same NV_GPU_DISPLAYIDS struct case NV_GPU_DISPLAYIDS_VER2: { *pDisplayIds = {}; @@ -83,8 +82,7 @@ extern "C" { return HandleInvalidated(str::format(n, ": NVML available but current adapter is not NVML compatible"), alreadyLoggedHandleInvalidated); unsigned int width; - auto result = adapter->GetNvmlDeviceGetCurrPcieLinkWidth(&width); - switch (result) { + switch (auto result = adapter->GetNvmlDeviceGetCurrPcieLinkWidth(&width)) { case NVML_SUCCESS: *pWidth = width; return Ok(n, alreadyLoggedOk); @@ -125,8 +123,7 @@ extern "C" { return HandleInvalidated(str::format(n, ": NVML available but current adapter is not NVML compatible"), alreadyLoggedHandleInvalidated); unsigned int irq; - auto result = adapter->GetNvmlDeviceGetIrqNum(&irq); - switch (result) { + switch (auto result = adapter->GetNvmlDeviceGetIrqNum(&irq)) { case NVML_SUCCESS: *pIRQ = irq; return Ok(n, alreadyLoggedOk); @@ -170,8 +167,7 @@ extern "C" { return HandleInvalidated(str::format(n, ": NVML available but current adapter is not NVML compatible"), alreadyLoggedHandleInvalidated); unsigned int cores; - auto result = adapter->GetNvmlDeviceNumGpuCores(&cores); - switch (result) { + switch (auto result = adapter->GetNvmlDeviceNumGpuCores(&cores)) { case NVML_SUCCESS: *pCount = cores; return Ok(n, alreadyLoggedOk); @@ -736,8 +732,7 @@ extern "C" { } char version[NVML_DEVICE_INFOROM_VERSION_BUFFER_SIZE]{}; - auto result = adapter->GetNvmlDeviceVbiosVersion(version, NVML_DEVICE_INFOROM_VERSION_BUFFER_SIZE); - switch (result) { + switch (auto result = adapter->GetNvmlDeviceVbiosVersion(version, NVML_DEVICE_INFOROM_VERSION_BUFFER_SIZE)) { case NVML_SUCCESS: str::tonvss(szBiosRevision, version); return Ok(n); @@ -1036,8 +1031,7 @@ extern "C" { return HandleInvalidated(str::format(n, ": NVML available but current adapter is not NVML compatible"), alreadyLoggedHandleInvalidated); nvmlPstates_t pState{}; - auto result = adapter->GetNvmlDevicePerformanceState(&pState); - switch (result) { + switch (auto result = adapter->GetNvmlDevicePerformanceState(&pState)) { case NVML_SUCCESS: *pCurrentPstate = static_cast(pState); return Ok(n, alreadyLoggedOk); From 59c9f41e5563066bdc0410d4e36267150a069149 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sat, 25 Jan 2025 19:35:57 +0100 Subject: [PATCH 05/23] nvapi: Use constexpr IDE hint. --- src/nvapi/nvapi_output.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvapi/nvapi_output.cpp b/src/nvapi/nvapi_output.cpp index 3b02329f..3a916ddb 100644 --- a/src/nvapi/nvapi_output.cpp +++ b/src/nvapi/nvapi_output.cpp @@ -27,7 +27,7 @@ namespace dxvk { if (SUCCEEDED(dxgiOutput->QueryInterface(IID_PPV_ARGS(&dxgiOutput6)))) { DXGI_OUTPUT_DESC1 desc1{}; dxgiOutput6->GetDesc1(&desc1); - const auto m = 50000.0f; + constexpr auto m = 50000.0f; m_colorData.HasST2084Support = desc1.ColorSpace == DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020; switch (desc1.BitsPerColor) { case 6: From 639d1a4678d21703ad1b210a0df67dc64a9ac841 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sat, 25 Jan 2025 19:36:40 +0100 Subject: [PATCH 06/23] nvapi: Use full qualifier IDE hint. --- src/nvapi/nvml.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvapi/nvml.cpp b/src/nvapi/nvml.cpp index ec6f774a..5e180360 100644 --- a/src/nvapi/nvml.cpp +++ b/src/nvapi/nvml.cpp @@ -49,7 +49,7 @@ namespace dxvk { if (result == NVML_SUCCESS) return; - log::info(str::format("NVML loaded but initialization failed with error: ", ErrorString(result))); + log::info(str::format("NVML loaded but initialization failed with error: ", Nvml::ErrorString(result))); } ::FreeLibrary(m_nvmlModule); From 149524626c1423fa79f3e93daf39260b434e8dcb Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sat, 25 Jan 2025 09:15:26 +0100 Subject: [PATCH 07/23] nvofapi: Add pragma IDE hint. --- src/nvofapi/nvofapi_image.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/nvofapi/nvofapi_image.h b/src/nvofapi/nvofapi_image.h index 6d7a78ad..68d84470 100644 --- a/src/nvofapi/nvofapi_image.h +++ b/src/nvofapi/nvofapi_image.h @@ -21,6 +21,8 @@ * DEALINGS IN THE SOFTWARE. */ +#pragma once + #include "../nvofapi_private.h" namespace dxvk { From 8900c6d9f703dad61f17cbe0e6f61d24e820efaa Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sat, 25 Jan 2025 19:25:46 +0100 Subject: [PATCH 08/23] nvofapi: Use cpp-style casts IDE hint. --- src/nvofapi/nvofapi_d3d12_instance.cpp | 25 ++++++++++------- src/nvofapi/nvofapi_instance.cpp | 10 +++---- src/nvofapi/nvofapi_vk_instance.cpp | 39 +++++++++++++++----------- 3 files changed, 42 insertions(+), 32 deletions(-) diff --git a/src/nvofapi/nvofapi_d3d12_instance.cpp b/src/nvofapi/nvofapi_d3d12_instance.cpp index 93a08f65..fcb1eb43 100644 --- a/src/nvofapi/nvofapi_d3d12_instance.cpp +++ b/src/nvofapi/nvofapi_d3d12_instance.cpp @@ -55,19 +55,24 @@ namespace dxvk { return false; } - m_vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr) reinterpret_cast(GetProcAddress(m_library, "vkGetInstanceProcAddr")); - m_vkGetDeviceProcAddr = (PFN_vkGetDeviceProcAddr)m_vkGetInstanceProcAddr(m_vkInstance, "vkGetDeviceProcAddr"); - m_vkGetPhysicalDeviceQueueFamilyProperties = (PFN_vkGetPhysicalDeviceQueueFamilyProperties)m_vkGetInstanceProcAddr(m_vkInstance, "vkGetPhysicalDeviceQueueFamilyProperties"); + m_vkGetInstanceProcAddr = reinterpret_cast(reinterpret_cast(GetProcAddress(m_library, "vkGetInstanceProcAddr"))); - m_vkCreateImageView = (PFN_vkCreateImageView)m_vkGetDeviceProcAddr(m_vkDevice, "vkCreateImageView"); - m_vkDestroyImageView = (PFN_vkDestroyImageView)m_vkGetDeviceProcAddr(m_vkDevice, "vkDestroyImageView"); +#define VK_GET_INSTANCE_PROC_ADDR(proc) m_##proc = reinterpret_cast(m_vkGetInstanceProcAddr(m_vkInstance, #proc)) + + VK_GET_INSTANCE_PROC_ADDR(vkGetDeviceProcAddr); + VK_GET_INSTANCE_PROC_ADDR(vkGetPhysicalDeviceQueueFamilyProperties); + +#define VK_GET_DEVICE_PROC_ADDR(proc) m_##proc = reinterpret_cast(m_vkGetDeviceProcAddr(m_vkDevice, #proc)) + + VK_GET_DEVICE_PROC_ADDR(vkCreateImageView); + VK_GET_DEVICE_PROC_ADDR(vkDestroyImageView); // Populate the optical flow related info here // fail to create if optical flow extension is unsupported - m_vkCreateOpticalFlowSessionNV = (PFN_vkCreateOpticalFlowSessionNV)m_vkGetDeviceProcAddr(m_vkDevice, "vkCreateOpticalFlowSessionNV"); - m_vkDestroyOpticalFlowSessionNV = (PFN_vkDestroyOpticalFlowSessionNV)m_vkGetDeviceProcAddr(m_vkDevice, "vkDestroyOpticalFlowSessionNV"); - m_vkBindOpticalFlowSessionImageNV = (PFN_vkBindOpticalFlowSessionImageNV)m_vkGetDeviceProcAddr(m_vkDevice, "vkBindOpticalFlowSessionImageNV"); - m_vkCmdOpticalFlowExecuteNV = (PFN_vkCmdOpticalFlowExecuteNV)m_vkGetDeviceProcAddr(m_vkDevice, "vkCmdOpticalFlowExecuteNV"); + VK_GET_DEVICE_PROC_ADDR(vkCreateOpticalFlowSessionNV); + VK_GET_DEVICE_PROC_ADDR(vkDestroyOpticalFlowSessionNV); + VK_GET_DEVICE_PROC_ADDR(vkBindOpticalFlowSessionImageNV); + VK_GET_DEVICE_PROC_ADDR(vkCmdOpticalFlowExecuteNV); // Get the OFA queue m_vkQueueFamilyIndex = GetVkOFAQueue(); @@ -80,7 +85,7 @@ namespace dxvk { return false; for (uint32_t i = 0; i < CMDS_IN_FLIGHT; i++) { - if (FAILED(m_d3ddevice->CreateCommandList1(0, D3D12_COMMAND_LIST_TYPE_DIRECT, (D3D12_COMMAND_LIST_FLAGS)0, IID_PPV_ARGS(&m_cmdLists[i])))) + if (FAILED(m_d3ddevice->CreateCommandList1(0, D3D12_COMMAND_LIST_TYPE_DIRECT, static_cast(0), IID_PPV_ARGS(&m_cmdLists[i])))) return false; } return true; diff --git a/src/nvofapi/nvofapi_instance.cpp b/src/nvofapi/nvofapi_instance.cpp index 6dd0a706..2782fb41 100644 --- a/src/nvofapi/nvofapi_instance.cpp +++ b/src/nvofapi/nvofapi_instance.cpp @@ -116,9 +116,9 @@ namespace dxvk { if (initParams->hPrivData != nullptr) { privData.sType = VK_STRUCTURE_TYPE_OPTICAL_FLOW_SESSION_CREATE_PRIVATE_DATA_INFO_NV; - privData.size = ((NV_OF_PRIV_DATA*)initParams->hPrivData)->size; - privData.id = ((NV_OF_PRIV_DATA*)initParams->hPrivData)->id; - privData.pPrivateData = ((NV_OF_PRIV_DATA*)initParams->hPrivData)->data; + privData.size = reinterpret_cast(initParams->hPrivData)->size; + privData.id = reinterpret_cast(initParams->hPrivData)->id; + privData.pPrivateData = reinterpret_cast(initParams->hPrivData)->data; createInfo.pNext = &privData; } @@ -177,8 +177,8 @@ namespace dxvk { BindImageToSession(outParams->bwdOutputCostBuffer, VK_OPTICAL_FLOW_SESSION_BINDING_POINT_BACKWARD_COST_NV); BindImageToSession(outParams->globalFlowBuffer, VK_OPTICAL_FLOW_SESSION_BINDING_POINT_GLOBAL_FLOW_NV); // Support INPUT_MIPS execute priv data - if (inParams->hPrivData != nullptr && ((NV_OF_PRIV_DATA*)inParams->hPrivData)->id == NV_OF_EXECUTE_PRIV_DATA_ID_INPUT_MIPS) { - NV_OF_EXECUTE_PRIV_DATA_INPUT_MIPS* mipData = ((NV_OF_EXECUTE_PRIV_DATA_INPUT_MIPS*)((NV_OF_PRIV_DATA*)inParams->hPrivData)->data); + if (inParams->hPrivData != nullptr && reinterpret_cast(inParams->hPrivData)->id == NV_OF_EXECUTE_PRIV_DATA_ID_INPUT_MIPS) { + auto mipData = static_cast(reinterpret_cast(inParams->hPrivData)->data); for (uint32_t i = 0; i < 6; i++) { if (mipData->input[i] && mipData->reference[i]) { BindImageToSession(mipData->input[i], VK_OPTICAL_FLOW_SESSION_BINDING_POINT_INPUT_NV); diff --git a/src/nvofapi/nvofapi_vk_instance.cpp b/src/nvofapi/nvofapi_vk_instance.cpp index 6aa4eca4..c4e6af91 100644 --- a/src/nvofapi/nvofapi_vk_instance.cpp +++ b/src/nvofapi/nvofapi_vk_instance.cpp @@ -34,30 +34,35 @@ namespace dxvk { return false; } - m_vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr) reinterpret_cast(GetProcAddress(m_library, "vkGetInstanceProcAddr")); - m_vkGetDeviceProcAddr = (PFN_vkGetDeviceProcAddr)m_vkGetInstanceProcAddr(m_vkInstance, "vkGetDeviceProcAddr"); - m_vkGetPhysicalDeviceQueueFamilyProperties = (PFN_vkGetPhysicalDeviceQueueFamilyProperties)m_vkGetInstanceProcAddr(m_vkInstance, "vkGetPhysicalDeviceQueueFamilyProperties"); + m_vkGetInstanceProcAddr = reinterpret_cast(reinterpret_cast(GetProcAddress(m_library, "vkGetInstanceProcAddr"))); - m_vkCreateImageView = (PFN_vkCreateImageView)m_vkGetDeviceProcAddr(m_vkDevice, "vkCreateImageView"); - m_vkDestroyImageView = (PFN_vkDestroyImageView)m_vkGetDeviceProcAddr(m_vkDevice, "vkDestroyImageView"); +#define VK_GET_INSTANCE_PROC_ADDR(proc) m_##proc = reinterpret_cast(m_vkGetInstanceProcAddr(m_vkInstance, #proc)) - m_vkGetDeviceQueue = (PFN_vkGetDeviceQueue)m_vkGetDeviceProcAddr(m_vkDevice, "vkGetDeviceQueue"); - m_vkCreateCommandPool = (PFN_vkCreateCommandPool)m_vkGetDeviceProcAddr(m_vkDevice, "vkCreateCommandPool"); - m_vkDestroyCommandPool = (PFN_vkDestroyCommandPool)m_vkGetDeviceProcAddr(m_vkDevice, "vkDestroyCommandPool"); - m_vkAllocateCommandBuffers = (PFN_vkAllocateCommandBuffers)m_vkGetDeviceProcAddr(m_vkDevice, "vkAllocateCommandBuffers"); - m_vkQueueSubmit2 = (PFN_vkQueueSubmit2)m_vkGetDeviceProcAddr(m_vkDevice, "vkQueueSubmit2"); + VK_GET_INSTANCE_PROC_ADDR(vkGetDeviceProcAddr); + VK_GET_INSTANCE_PROC_ADDR(vkGetPhysicalDeviceQueueFamilyProperties); - m_vkResetCommandBuffer = (PFN_vkResetCommandBuffer)m_vkGetDeviceProcAddr(m_vkDevice, "vkResetCommandBuffer"); - m_vkBeginCommandBuffer = (PFN_vkBeginCommandBuffer)m_vkGetDeviceProcAddr(m_vkDevice, "vkBeginCommandBuffer"); - m_vkEndCommandBuffer = (PFN_vkEndCommandBuffer)m_vkGetDeviceProcAddr(m_vkDevice, "vkEndCommandBuffer"); +#define VK_GET_DEVICE_PROC_ADDR(proc) m_##proc = reinterpret_cast(m_vkGetDeviceProcAddr(m_vkDevice, #proc)) + + VK_GET_DEVICE_PROC_ADDR(vkCreateImageView); + VK_GET_DEVICE_PROC_ADDR(vkDestroyImageView); + + VK_GET_DEVICE_PROC_ADDR(vkGetDeviceQueue); + VK_GET_DEVICE_PROC_ADDR(vkCreateCommandPool); + VK_GET_DEVICE_PROC_ADDR(vkDestroyCommandPool); + VK_GET_DEVICE_PROC_ADDR(vkAllocateCommandBuffers); + VK_GET_DEVICE_PROC_ADDR(vkQueueSubmit2); + + VK_GET_DEVICE_PROC_ADDR(vkResetCommandBuffer); + VK_GET_DEVICE_PROC_ADDR(vkBeginCommandBuffer); + VK_GET_DEVICE_PROC_ADDR(vkEndCommandBuffer); // Get NvapiAdapter from the vkPhysicalDevice // Populate the optical flow related info here // fail to create if optical flow extension is unsupported - m_vkCreateOpticalFlowSessionNV = (PFN_vkCreateOpticalFlowSessionNV)m_vkGetDeviceProcAddr(m_vkDevice, "vkCreateOpticalFlowSessionNV"); - m_vkDestroyOpticalFlowSessionNV = (PFN_vkDestroyOpticalFlowSessionNV)m_vkGetDeviceProcAddr(m_vkDevice, "vkDestroyOpticalFlowSessionNV"); - m_vkBindOpticalFlowSessionImageNV = (PFN_vkBindOpticalFlowSessionImageNV)m_vkGetDeviceProcAddr(m_vkDevice, "vkBindOpticalFlowSessionImageNV"); - m_vkCmdOpticalFlowExecuteNV = (PFN_vkCmdOpticalFlowExecuteNV)m_vkGetDeviceProcAddr(m_vkDevice, "vkCmdOpticalFlowExecuteNV"); + VK_GET_DEVICE_PROC_ADDR(vkCreateOpticalFlowSessionNV); + VK_GET_DEVICE_PROC_ADDR(vkDestroyOpticalFlowSessionNV); + VK_GET_DEVICE_PROC_ADDR(vkBindOpticalFlowSessionImageNV); + VK_GET_DEVICE_PROC_ADDR(vkCmdOpticalFlowExecuteNV); // Get the OFA queue VkCommandPoolCreateInfo createInfo{}; From 6953453f7ef9ec8d500a1c8195cbf36764c25860 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sat, 25 Jan 2025 19:30:16 +0100 Subject: [PATCH 09/23] nvofapi: Declare some functions const IDE hint. --- src/nvofapi/nvofapi_image.h | 2 +- src/nvofapi/nvofapi_instance.cpp | 10 +++++----- src/nvofapi/nvofapi_instance.h | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/nvofapi/nvofapi_image.h b/src/nvofapi/nvofapi_image.h index 68d84470..40b187cf 100644 --- a/src/nvofapi/nvofapi_image.h +++ b/src/nvofapi/nvofapi_image.h @@ -35,7 +35,7 @@ namespace dxvk { m_vkDestroyImageView(m_vkDevice, m_imageView, nullptr); } - VkImageView ImageView() { return m_imageView; } + [[nodiscard]] VkImageView ImageView() const { return m_imageView; } bool Initialize(PFN_vkCreateImageView CreateImageView, PFN_vkDestroyImageView DestroyImageView); diff --git a/src/nvofapi/nvofapi_instance.cpp b/src/nvofapi/nvofapi_instance.cpp index 2782fb41..89926492 100644 --- a/src/nvofapi/nvofapi_instance.cpp +++ b/src/nvofapi/nvofapi_instance.cpp @@ -42,7 +42,7 @@ namespace dxvk { constexpr uint32_t NV_OF_EXECUTE_PRIV_DATA_ID_INPUT_MIPS = 6; - uint32_t NvOFInstance::GetVkOFAQueue() { + uint32_t NvOFInstance::GetVkOFAQueue() const { uint32_t count = 0; m_vkGetPhysicalDeviceQueueFamilyProperties(m_vkPhysicalDevice, &count, nullptr); auto queueFamProps = std::vector(count); @@ -132,7 +132,7 @@ namespace dxvk { return ErrorGeneric(); } - NV_OF_STATUS NvOFInstance::BindImageToSession(NvOFGPUBufferHandle hBuffer, VkOpticalFlowSessionBindingPointNV bindingPoint) { + NV_OF_STATUS NvOFInstance::BindImageToSession(NvOFGPUBufferHandle hBuffer, VkOpticalFlowSessionBindingPointNV bindingPoint) const { auto nvOFImage = reinterpret_cast(hBuffer); if (!nvOFImage) @@ -149,7 +149,7 @@ namespace dxvk { return Success(); } - NV_OF_STATUS NvOFInstance::GetCaps(NV_OF_CAPS param, uint32_t* capsVal, uint32_t* size) { + NV_OF_STATUS NvOFInstance::GetCaps(NV_OF_CAPS param, uint32_t* capsVal, uint32_t* size) const { if (param == NV_OF_CAPS_SUPPORTED_OUTPUT_GRID_SIZES) { *size = 1; if (capsVal) { @@ -162,13 +162,13 @@ namespace dxvk { return ErrorGeneric(); } - void NvOFInstance::RegisterBuffer(const NV_OF_REGISTER_RESOURCE_PARAMS_VK* registerParams) { + void NvOFInstance::RegisterBuffer(const NV_OF_REGISTER_RESOURCE_PARAMS_VK* registerParams) const { auto nvOFImage = new NvOFImage(m_vkDevice, registerParams->image, registerParams->format); nvOFImage->Initialize(m_vkCreateImageView, m_vkDestroyImageView); *registerParams->hOFGpuBuffer = reinterpret_cast(nvOFImage); } - void NvOFInstance::RecordCmdBuf(const NV_OF_EXECUTE_INPUT_PARAMS_VK* inParams, NV_OF_EXECUTE_OUTPUT_PARAMS_VK* outParams, VkCommandBuffer cmdBuf) { + void NvOFInstance::RecordCmdBuf(const NV_OF_EXECUTE_INPUT_PARAMS_VK* inParams, NV_OF_EXECUTE_OUTPUT_PARAMS_VK* outParams, VkCommandBuffer cmdBuf) const { BindImageToSession(inParams->inputFrame, VK_OPTICAL_FLOW_SESSION_BINDING_POINT_INPUT_NV); BindImageToSession(inParams->referenceFrame, VK_OPTICAL_FLOW_SESSION_BINDING_POINT_REFERENCE_NV); BindImageToSession(outParams->outputBuffer, VK_OPTICAL_FLOW_SESSION_BINDING_POINT_FLOW_VECTOR_NV); diff --git a/src/nvofapi/nvofapi_instance.h b/src/nvofapi/nvofapi_instance.h index a4028b7a..dcf610c2 100644 --- a/src/nvofapi/nvofapi_instance.h +++ b/src/nvofapi/nvofapi_instance.h @@ -44,18 +44,18 @@ namespace dxvk { FreeLibrary(m_library); } - VkDevice GetVkDevice() { return m_vkDevice; } - VkOpticalFlowSessionNV GetOfaSession() { return m_vkOfaSession; } + [[nodiscard]] VkDevice GetVkDevice() const { return m_vkDevice; } + [[nodiscard]] VkOpticalFlowSessionNV GetOfaSession() const { return m_vkOfaSession; } - NV_OF_STATUS GetCaps(NV_OF_CAPS param, uint32_t* capsVal, uint32_t* size); + NV_OF_STATUS GetCaps(NV_OF_CAPS param, uint32_t* capsVal, uint32_t* size) const; NV_OF_STATUS InitSession(const NV_OF_INIT_PARAMS* initParams); - void RegisterBuffer(const NV_OF_REGISTER_RESOURCE_PARAMS_VK* registerParams); + void RegisterBuffer(const NV_OF_REGISTER_RESOURCE_PARAMS_VK* registerParams) const; - NV_OF_STATUS BindImageToSession(NvOFGPUBufferHandle hBuffer, VkOpticalFlowSessionBindingPointNV bindingPoint); + NV_OF_STATUS BindImageToSession(NvOFGPUBufferHandle hBuffer, VkOpticalFlowSessionBindingPointNV bindingPoint) const; - void RecordCmdBuf(const NV_OF_EXECUTE_INPUT_PARAMS_VK* inParams, NV_OF_EXECUTE_OUTPUT_PARAMS_VK* outParams, VkCommandBuffer cmdBuf); + void RecordCmdBuf(const NV_OF_EXECUTE_INPUT_PARAMS_VK* inParams, NV_OF_EXECUTE_OUTPUT_PARAMS_VK* outParams, VkCommandBuffer cmdBuf) const; protected: VkInstance m_vkInstance{}; @@ -74,6 +74,6 @@ namespace dxvk { PFN_vkGetPhysicalDeviceQueueFamilyProperties m_vkGetPhysicalDeviceQueueFamilyProperties{}; HMODULE m_library{}; - uint32_t GetVkOFAQueue(); + [[nodiscard]] uint32_t GetVkOFAQueue() const; }; } From 3c420e28327a91d3136d90ccf08a2f2feaedcd5c Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sat, 25 Jan 2025 19:31:56 +0100 Subject: [PATCH 10/23] nvofapi: Add missing override keyword IDE hint. --- src/nvofapi/nvofapi_vk_instance.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nvofapi/nvofapi_vk_instance.h b/src/nvofapi/nvofapi_vk_instance.h index 2792dbef..3b736f0e 100644 --- a/src/nvofapi/nvofapi_vk_instance.h +++ b/src/nvofapi/nvofapi_vk_instance.h @@ -31,7 +31,8 @@ namespace dxvk { public: NvOFInstanceVk(VkInstance vkInstance, VkPhysicalDevice vkPhysicalDevice, VkDevice vkDevice) : NvOFInstance(vkInstance, vkPhysicalDevice, vkDevice) { } - virtual ~NvOFInstanceVk() { + + ~NvOFInstanceVk() override { // free cmdbuffers m_vkFreeCommandBuffers(m_vkDevice, m_commandPool, CMDS_IN_FLIGHT, m_commandBuffers.data()); m_vkDestroyCommandPool(m_vkDevice, m_commandPool, nullptr); From f36ca0c38985633d62df02569514ba494873ac64 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sat, 25 Jan 2025 19:32:49 +0100 Subject: [PATCH 11/23] nvofapi: Remove not needed braces IDE hint. --- src/nvofapi/nvofapi_vk_instance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvofapi/nvofapi_vk_instance.cpp b/src/nvofapi/nvofapi_vk_instance.cpp index c4e6af91..05ae1662 100644 --- a/src/nvofapi/nvofapi_vk_instance.cpp +++ b/src/nvofapi/nvofapi_vk_instance.cpp @@ -141,7 +141,7 @@ namespace dxvk { submit.pWaitSemaphoreInfos = waitSyncs.data(); submit.commandBufferInfoCount = 1; submit.pCommandBufferInfos = &cmdbufInfo; - submit.signalSemaphoreInfoCount = (outParams->pSignalSync) ? 1 : 0; + submit.signalSemaphoreInfoCount = outParams->pSignalSync ? 1 : 0; submit.pSignalSemaphoreInfos = &signalSync; status = m_vkQueueSubmit2(m_queue, 1, &submit, VK_NULL_HANDLE); From ff0003b07a816375801a05101e80481898f30198 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sat, 25 Jan 2025 22:15:58 +0100 Subject: [PATCH 12/23] nvofapi: Shorten raw pointer checks More consistent with other parts of the code base. --- src/nvofapi/nvofapi_instance.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nvofapi/nvofapi_instance.cpp b/src/nvofapi/nvofapi_instance.cpp index 89926492..73d26029 100644 --- a/src/nvofapi/nvofapi_instance.cpp +++ b/src/nvofapi/nvofapi_instance.cpp @@ -114,7 +114,7 @@ namespace dxvk { // Need to get the size/id for the private data to pass it along to VK... VkOpticalFlowSessionCreatePrivateDataInfoNV privData{}; - if (initParams->hPrivData != nullptr) { + if (initParams->hPrivData) { privData.sType = VK_STRUCTURE_TYPE_OPTICAL_FLOW_SESSION_CREATE_PRIVATE_DATA_INFO_NV; privData.size = reinterpret_cast(initParams->hPrivData)->size; privData.id = reinterpret_cast(initParams->hPrivData)->id; @@ -177,7 +177,7 @@ namespace dxvk { BindImageToSession(outParams->bwdOutputCostBuffer, VK_OPTICAL_FLOW_SESSION_BINDING_POINT_BACKWARD_COST_NV); BindImageToSession(outParams->globalFlowBuffer, VK_OPTICAL_FLOW_SESSION_BINDING_POINT_GLOBAL_FLOW_NV); // Support INPUT_MIPS execute priv data - if (inParams->hPrivData != nullptr && reinterpret_cast(inParams->hPrivData)->id == NV_OF_EXECUTE_PRIV_DATA_ID_INPUT_MIPS) { + if (inParams->hPrivData && reinterpret_cast(inParams->hPrivData)->id == NV_OF_EXECUTE_PRIV_DATA_ID_INPUT_MIPS) { auto mipData = static_cast(reinterpret_cast(inParams->hPrivData)->data); for (uint32_t i = 0; i < 6; i++) { if (mipData->input[i] && mipData->reference[i]) { From 19e23b28f61e752f70c0ac72c9f0aa7ead3a9969 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sat, 25 Jan 2025 09:14:47 +0100 Subject: [PATCH 13/23] util: Shorten raw pointer checks More consistent with other parts of the code base. --- src/util/util_log.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/util/util_log.h b/src/util/util_log.h index e7dce09a..2c8e5b2d 100644 --- a/src/util/util_log.h +++ b/src/util/util_log.h @@ -13,14 +13,14 @@ namespace dxvk::log { #endif inline std::string hnd(const void* h) { - if (h == nullptr) + if (!h) return "hnd=0x0"; return str::format("hnd=", hex_prefix, std::hex, h); } inline std::string ptr(const void* p) { - if (p == nullptr) + if (!p) return "nullptr"; return str::format("ptr=", hex_prefix, std::hex, p); @@ -44,42 +44,42 @@ namespace dxvk::log { } inline std::string nv_latency_marker_params(NV_LATENCY_MARKER_PARAMS* p) { - if (p == nullptr) + if (!p) return "nullptr"; return str::format("{version=", p->version, ",frameID=", p->frameID, ",markerType=", fromLatencyMarkerType(p->markerType), ",rsvd}"); } inline std::string nv_async_frame_marker_params(NV_ASYNC_FRAME_MARKER_PARAMS* p) { - if (p == nullptr) + if (!p) return "nullptr"; return str::format("{version=", p->version, ",frameID=", p->frameID, ",markerType=", fromLatencyMarkerType(p->markerType), ",presentFrameID=", p->presentFrameID, ",rsvd}"); } inline std::string nv_vk_get_sleep_status_params(NV_VULKAN_GET_SLEEP_STATUS_PARAMS* p) { - if (p == nullptr) + if (!p) return "nullptr"; return str::format("{version=", p->version, ",...,rsvd}"); } inline std::string nv_vk_set_sleep_status_params(NV_VULKAN_SET_SLEEP_MODE_PARAMS* p) { - if (p == nullptr) + if (!p) return "nullptr"; return str::format("{version=", p->version, ",bLowLatencyMode=", static_cast(p->bLowLatencyMode), ",bLowLatencyBoost=", static_cast(p->bLowLatencyBoost), ",minimumIntervalUs=", p->minimumIntervalUs, ",rsvd}"); } inline std::string nv_vk_latency_result_params(NV_VULKAN_LATENCY_RESULT_PARAMS* p) { - if (p == nullptr) + if (!p) return "nullptr"; return str::format("{version=", p->version, ",...,rsvd}"); } inline std::string nv_vk_latency_marker_params(NV_VULKAN_LATENCY_MARKER_PARAMS* p) { - if (p == nullptr) + if (!p) return "nullptr"; return str::format("{version=", p->version, ",frameID=", p->frameID, ",markerType=", p->markerType, ",rsvd}"); From b5a56e5022ea6b9e25460b330403a8c3f1506ae6 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sat, 25 Jan 2025 19:26:15 +0100 Subject: [PATCH 14/23] util: Use cpp-style casts IDE hint. --- src/util/util_env.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/util/util_env.cpp b/src/util/util_env.cpp index 0c6e995b..54ae3293 100644 --- a/src/util/util_env.cpp +++ b/src/util/util_env.cpp @@ -52,7 +52,7 @@ namespace dxvk::env { // Get file path of caller DLL char modulePath[MAX_PATH]; HMODULE hModule = nullptr; - if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (const char*)pReturnAddress, &hModule)) { + if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, static_cast(pReturnAddress), &hModule)) { // Failed to get the path, won't try to WAR. return false; } @@ -85,7 +85,7 @@ namespace dxvk::env { VS_FIXEDFILEINFO* fixedInfo = nullptr; uint32_t fixedSize = 0; - VerQueryValueA(verInfo, "\\", (void**)&fixedInfo, &fixedSize); + VerQueryValueA(verInfo, "\\", reinterpret_cast(&fixedInfo), &fixedSize); // Double-check that we are reading a VS_FIXEDFILEINFO structure if (fixedInfo->dwSignature != 0xFEEF04BD) { @@ -105,7 +105,7 @@ namespace dxvk::env { // called by DLSS char* productName; uint32_t productNameSize; - VerQueryValueA(verInfo, R"(\StringFileInfo\040904E4\ProductName)", (void**)&productName, &productNameSize); + VerQueryValueA(verInfo, R"(\StringFileInfo\040904E4\ProductName)", reinterpret_cast(&productName), &productNameSize); if (strcmp(productName, "NVIDIA Deep Learning SuperSampling") == 0) { // A DLSS version between 2.0 and 2.4 was detected, applying WAR From 18b977d2b1aab72528addf1da6a8dd478361dcba Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sat, 25 Jan 2025 19:37:02 +0100 Subject: [PATCH 15/23] util: Move assignment into if statement IDE hint. --- src/util/util_log.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/util/util_log.cpp b/src/util/util_log.cpp index 530f1bbc..b0e67fa1 100644 --- a/src/util/util_log.cpp +++ b/src/util/util_log.cpp @@ -19,8 +19,7 @@ namespace dxvk::log { void initialize(std::ofstream& filestream, bool& skipAllLogging) { #ifdef _WIN32 - auto ntdllModule = ::GetModuleHandleA("ntdll.dll"); - if (ntdllModule != nullptr) + if (auto ntdllModule = ::GetModuleHandleA("ntdll.dll")) wineDbgOutput = reinterpret_cast(reinterpret_cast(GetProcAddress(ntdllModule, "__wine_dbg_output"))); #endif @@ -42,7 +41,7 @@ namespace dxvk::log { if (logPath.empty()) return; - if ((*logPath.rbegin()) != '/') + if (*logPath.rbegin() != '/') logPath += '/'; auto fullPath = logPath + logFileName; From dbd9a470fa99568c65b0d2de8e840b00c7aa51b5 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sat, 25 Jan 2025 19:37:25 +0100 Subject: [PATCH 16/23] util: Add typename keyword IDE hint. --- src/util/util_string.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/util_string.h b/src/util/util_string.h index 9271a770..721ee81a 100644 --- a/src/util/util_string.h +++ b/src/util/util_string.h @@ -45,7 +45,7 @@ namespace dxvk::str { #if __cpp_concepts >= 201907L requires std::default_initializable && std::constructible_from - && requires(T t, T::iterator it, T::value_type&& s) { + && requires(T t, typename T::iterator it, typename T::value_type&& s) { requires std::input_iterator; { t.end() } -> std::same_as; { t.insert(it, s) } -> std::same_as; From 5a1e7125adb2deda4a9668c5229c3cbbaf527c6a Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sat, 25 Jan 2025 09:15:38 +0100 Subject: [PATCH 17/23] tests: Add pragma IDE hint. --- tests/nvapi_tests_private.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/nvapi_tests_private.h b/tests/nvapi_tests_private.h index e5747071..d2f282f7 100644 --- a/tests/nvapi_tests_private.h +++ b/tests/nvapi_tests_private.h @@ -1,3 +1,5 @@ +#pragma once + #if defined(__GNUC__) || defined(__clang__) #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" #endif // defined(__GNUC__) || defined(__clang__) From fac608a3fc78ab113c5333f9fc051e03d8e88ea3 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sat, 25 Jan 2025 09:17:03 +0100 Subject: [PATCH 18/23] tests: Shorten raw pointer checks --- tests/nvapi_sysinfo_topo.cpp | 6 +++--- tests/resource_factory_util.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/nvapi_sysinfo_topo.cpp b/tests/nvapi_sysinfo_topo.cpp index d223eaed..3b1d7381 100644 --- a/tests/nvapi_sysinfo_topo.cpp +++ b/tests/nvapi_sysinfo_topo.cpp @@ -85,13 +85,13 @@ TEST_CASE("Topology methods succeed", "[.sysinfo-topo]") { NvDisplayHandle handle4 = nullptr; REQUIRE(NvAPI_EnumNvidiaDisplayHandle(3U, &handle4) == NVAPI_END_ENUMERATION); - REQUIRE(handle4 == nullptr); + REQUIRE_FALSE(handle4); } SECTION("EnumNvidiaUnAttachedDisplayHandle succeeds") { NvUnAttachedDisplayHandle handle = nullptr; REQUIRE(NvAPI_EnumNvidiaUnAttachedDisplayHandle(0U, &handle) == NVAPI_END_ENUMERATION); - REQUIRE(handle == nullptr); + REQUIRE_FALSE(handle); } SECTION("GetLogicalGPUFromPhysicalGPU succeeds") { @@ -215,7 +215,7 @@ TEST_CASE("Topology methods succeed", "[.sysinfo-topo]") { NvPhysicalGpuHandle handle4 = nullptr; REQUIRE(NvAPI_SYS_GetPhysicalGpuFromDisplayId(0x00000000, &handle4) == NVAPI_INVALID_ARGUMENT); - REQUIRE(handle4 == nullptr); + REQUIRE_FALSE(handle4); } SECTION("GetAssociatedNvidiaDisplayName succeeds") { diff --git a/tests/resource_factory_util.cpp b/tests/resource_factory_util.cpp index 8b885302..b26a0be0 100644 --- a/tests/resource_factory_util.cpp +++ b/tests/resource_factory_util.cpp @@ -31,7 +31,7 @@ void ResetGlobals() { NvapiD3dLowLatencyDevice::Reset(); NvapiVulkanLowLatencyDevice::Reset(); - if (resourceFactory == nullptr) + if (!resourceFactory) return; auto mockFactory = reinterpret_cast(resourceFactory.get()); From 0902f3243b36eed723e07daf7b1980d140be69b5 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sat, 25 Jan 2025 19:26:47 +0100 Subject: [PATCH 19/23] tests: Use cpp-style casts IDE hint. --- tests/nvapi_d3d11.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/nvapi_d3d11.cpp b/tests/nvapi_d3d11.cpp index f58ebe61..1d11ad3b 100644 --- a/tests/nvapi_d3d11.cpp +++ b/tests/nvapi_d3d11.cpp @@ -196,7 +196,7 @@ TEST_CASE("D3D11 methods succeed", "[.d3d11]") { REQUIRE(NvAPI_D3D11_GetResourceGPUVirtualAddress(static_cast(&device), NVDX_ObjectHandle(1), &gpuVAStart) == NVAPI_ERROR); NV_GET_GPU_VIRTUAL_ADDRESS gva; gva.version = NV_GET_GPU_VIRTUAL_ADDRESS_VER1; - gva.hResource = NVDX_ObjectHandle(1); + gva.hResource = reinterpret_cast(1); REQUIRE(NvAPI_D3D11_GetResourceGPUVirtualAddressEx(static_cast(&device), &gva) == NVAPI_ERROR); D3D11_SAMPLER_DESC samplerDesc; ID3D11SamplerState* samplerState; From ce01f9b343b5cd71d1bfaa1b1e93ee1906ab2b36 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sat, 25 Jan 2025 19:30:53 +0100 Subject: [PATCH 20/23] tests: Declare function const IDE hint. --- tests/mock_factory.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/mock_factory.h b/tests/mock_factory.h index 26ccac56..3d7afea5 100644 --- a/tests/mock_factory.h +++ b/tests/mock_factory.h @@ -41,7 +41,7 @@ class MockFactory : public dxvk::ResourceFactory { return std::move(m_lfxMock); } - [[nodiscard]] DXGIDxvkFactoryMock* GetDXGIDxvkFactoryMock() { + [[nodiscard]] DXGIDxvkFactoryMock* GetDXGIDxvkFactoryMock() const { return m_dxgiFactoryMock.get(); } From 73773e4c6a90a779af23b642e96f8397a968b459 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sat, 25 Jan 2025 19:37:49 +0100 Subject: [PATCH 21/23] tests: Remove not needed include IDE hint. --- tests/nvapi_sysinfo_mocks.h | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/nvapi_sysinfo_mocks.h b/tests/nvapi_sysinfo_mocks.h index 05a39f86..236423aa 100644 --- a/tests/nvapi_sysinfo_mocks.h +++ b/tests/nvapi_sysinfo_mocks.h @@ -2,7 +2,6 @@ #include "nvapi_tests_private.h" #include "../src/interfaces/dxvk_interfaces.h" -#include "../src/nvapi/vk.h" #include "../src/nvapi/nvml.h" class IDXGIDxvkFactoryMock : public IDXGIFactory1, public IDXGIVkInteropFactory1 {}; From fc496bacfbca85d5ef195d1f4fbcb62044fd9742 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sat, 25 Jan 2025 19:38:10 +0100 Subject: [PATCH 22/23] tests: Move variable to inner scope IDE hint. --- tests/nvapi_d3d.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/nvapi_d3d.cpp b/tests/nvapi_d3d.cpp index 7b039bed..6994e9a1 100644 --- a/tests/nvapi_d3d.cpp +++ b/tests/nvapi_d3d.cpp @@ -119,7 +119,6 @@ TEST_CASE("D3D Reflex/LatencyFleX depending methods succeed", "[.d3d]") { D3DLowLatencyDeviceMock lowLatencyDevice; DXGIDxvkAdapterMock* adapter = CreateDXGIDxvkAdapterMock(); DXGIOutput6Mock* output = CreateDXGIOutput6Mock(); - auto lowLatencyDeviceRefCount = 0; auto e = ConfigureDefaultTestEnvironment(*dxgiFactory, *vk, *nvml, *lfx, *adapter, *output); @@ -276,6 +275,7 @@ TEST_CASE("D3D Reflex/LatencyFleX depending methods succeed", "[.d3d]") { } SECTION("Reflex depending methods succeed when D3DLowLatencyDevice is available") { + auto lowLatencyDeviceRefCount = 0; ALLOW_CALL(unknown, QueryInterface(__uuidof(ID3DLowLatencyDevice), _)) .LR_SIDE_EFFECT(*_2 = static_cast(&lowLatencyDevice)) .LR_SIDE_EFFECT(lowLatencyDeviceRefCount++) From d6e11b5844c740d911464479e4862b6d0a35085a Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sat, 25 Jan 2025 19:38:36 +0100 Subject: [PATCH 23/23] tests: Use string.empty() IDE hint. --- tests/util.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/util.cpp b/tests/util.cpp index dd939e29..f38c37a8 100644 --- a/tests/util.cpp +++ b/tests/util.cpp @@ -86,13 +86,13 @@ TEST_CASE("String", "[.util]") { } SECTION("fromnullable") { - REQUIRE(dxvk::str::fromnullable(nullptr) == std::string()); - REQUIRE(dxvk::str::fromnullable("") == std::string()); + REQUIRE(dxvk::str::fromnullable(nullptr).empty()); + REQUIRE(dxvk::str::fromnullable("").empty()); REQUIRE(dxvk::str::fromnullable("string") == "string"); } SECTION("split") { - REQUIRE(dxvk::str::split>("", std::regex(",")).size() == 0); + REQUIRE(dxvk::str::split>("", std::regex(",")).empty()); auto result = dxvk::str::split>("foo,bar,baz", std::regex(",")); @@ -132,7 +132,7 @@ TEST_CASE("String", "[.util]") { } SECTION("implode") { - REQUIRE(dxvk::str::implode(",", std::vector{}) == std::string()); + REQUIRE(dxvk::str::implode(",", std::vector{}).empty()); REQUIRE(dxvk::str::implode(",", std::vector{"foo"}) == "foo"); REQUIRE(dxvk::str::implode(" ", std::vector{"foo", "bar"}) == "foo bar"); REQUIRE(dxvk::str::implode(", ", std::vector{"foo", "bar", "baz"}) == "foo, bar, baz");