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

Consistency and styling improvements #248

Merged
merged 23 commits into from
Jan 26, 2025
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
64 changes: 32 additions & 32 deletions src/nvapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand All @@ -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++)
Expand All @@ -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
Expand All @@ -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<NvapiAdapter*>(hPhysicalGpu);
Expand All @@ -102,18 +102,18 @@ 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;
for (auto i = 0U; i < nvapiAdapterRegistry->GetAdapterCount(); i++)
if (nvapiAdapterRegistry->GetAdapter(i)->GetBoardId() == gpuId)
adapter = nvapiAdapterRegistry->GetAdapter(i);

if (adapter == nullptr)
if (!adapter)
return InvalidArgument(n);

*hPhysicalGpu = reinterpret_cast<NvPhysicalGpuHandle>(adapter);
Expand All @@ -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)
Expand All @@ -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<NvapiAdapter*>(hPhysicalGPU);
Expand All @@ -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<NvapiOutput*>(hNvDisp);
Expand All @@ -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<NvapiAdapter*>(hLogicalGPU);
Expand All @@ -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<NvapiOutput*>(hNvDisp);
Expand All @@ -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<NvDisplayHandle>(output);
Expand All @@ -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<NvapiOutput*>(NvDispHandle);
Expand All @@ -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<NvDisplayHandle>(output);
Expand All @@ -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)");
Expand All @@ -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);
Expand Down Expand Up @@ -369,7 +369,7 @@ extern "C" {
" ", DXVK_NVAPI_BUILD_TYPE,
" (", env::getExecutableName(), ")"));

if (resourceFactory == nullptr)
if (!resourceFactory)
resourceFactory = std::make_unique<ResourceFactory>();

nvapiAdapterRegistry = std::make_unique<NvapiAdapterRegistry>(*resourceFactory);
Expand Down
10 changes: 5 additions & 5 deletions src/nvapi/lfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -38,7 +38,7 @@ namespace dxvk {
}

Lfx::~Lfx() {
if (m_lfxModule == nullptr)
if (!m_lfxModule)
return;

::FreeLibrary(m_lfxModule);
Expand Down
2 changes: 1 addition & 1 deletion src/nvapi/nvapi_adapter_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 4 additions & 3 deletions src/nvapi/nvapi_d3d11_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ namespace dxvk {
}

bool NvapiD3d11Device::DestroyCubinShader(NVDX_ObjectHandle hShader) {
auto cubinShader = reinterpret_cast<IUnknown*>(hShader);
if (cubinShader != nullptr)
if (auto cubinShader = reinterpret_cast<IUnknown*>(hShader)) {
cubinShader->Release();
return true;
}

return cubinShader != nullptr;
return false;
}

bool NvapiD3d11Device::GetResourceDriverHandle(ID3D11Resource* pResource, NVDX_ObjectHandle* phObject) {
Expand Down
4 changes: 2 additions & 2 deletions src/nvapi/nvapi_d3d_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/nvapi/nvapi_d3d_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/nvapi/nvapi_d3d_low_latency_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ namespace dxvk {
}

Com<ID3DLowLatencyDevice> NvapiD3dLowLatencyDevice::GetLowLatencyDevice(IUnknown* device) {
if (device == nullptr)
if (!device)
return nullptr;

std::scoped_lock lock(m_lowLatencyDeviceMutex);
Expand All @@ -177,7 +177,7 @@ namespace dxvk {
}

Com<ID3DLowLatencyDevice> NvapiD3dLowLatencyDevice::GetLowLatencyDevice(ID3D12CommandQueue* commandQueue) {
if (commandQueue == nullptr)
if (!commandQueue)
return nullptr;

auto unknown = static_cast<IUnknown*>(commandQueue);
Expand Down
2 changes: 1 addition & 1 deletion src/nvapi/nvapi_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions src/nvapi/nvml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -39,25 +39,25 @@ 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();
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);
m_nvmlModule = nullptr;
}

Nvml::~Nvml() {
if (m_nvmlModule == nullptr)
if (!m_nvmlModule)
return;

m_nvmlShutdown();
Expand Down
2 changes: 1 addition & 1 deletion src/nvapi/resource_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace dxvk {

Com<IDXGIFactory1> ResourceFactory::CreateDXGIFactory1() {
Com<IDXGIFactory1> 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;
}
Expand Down
Loading
Loading