From 952ae33beec14f177112c6886736ac8f1f2678d8 Mon Sep 17 00:00:00 2001 From: szombathy-tamas Date: Sat, 7 Nov 2026 04:48:45 +0100 Subject: [PATCH 1/4] Upscaler: report failed vendor calls Failed vendor calls were silent: creation returned "FAILURE" with no message (a missing or incomplete FSR loader, "ffxCreateContext", the XeSS calls, NGX initialization and feature creation), and a failed dispatch ("ffxDispatch", "xessSetExposureMultiplier", "xessD3D12Execute", NGX evaluation) was an "NRI_CHECK", compiled out of release builds. Each now reports through "NRI_REPORT_ERROR", naming the call and its result, in release builds too. --- Source/Shared/UpscalerInterface.hpp | 77 ++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 17 deletions(-) diff --git a/Source/Shared/UpscalerInterface.hpp b/Source/Shared/UpscalerInterface.hpp index 5d391d37..65084bdc 100644 --- a/Source/Shared/UpscalerInterface.hpp +++ b/Source/Shared/UpscalerInterface.hpp @@ -1081,8 +1081,12 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { // Load library const char* libraryName = deviceDesc.graphicsAPI == GraphicsAPI::D3D12 ? "amd_fidelityfx_loader_dx12.dll" : "amd_fidelityfx_loader_vk.dll"; Library* ffxLibrary = LoadSharedLibrary(libraryName); - if (!ffxLibrary) + + if (!ffxLibrary) { + NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "'%s' can't be loaded", libraryName); + return Result::FAILURE; + } // Get functions m.ffx->library = ffxLibrary; @@ -1091,8 +1095,11 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { m.ffx->Dispatch = (PfnFfxDispatch)GetSharedLibraryFunction(*ffxLibrary, "ffxDispatch"); m.ffx->Query = (PfnFfxQuery)GetSharedLibraryFunction(*ffxLibrary, "ffxQuery"); - if (!m.ffx->CreateContext || !m.ffx->DestroyContext || !m.ffx->Dispatch || !m.ffx->Query) + if (!m.ffx->CreateContext || !m.ffx->DestroyContext || !m.ffx->Dispatch || !m.ffx->Query) { + NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "'%s' lacks an FFX API entry point", libraryName); + return Result::FAILURE; + } // Allocation callbacks m.ffx->allocationCallbacks.alloc = FfxAlloc; @@ -1170,8 +1177,12 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { # endif ffxReturnCode_t result = m.ffx->CreateContext(&m.ffx->context, &contextDesc.header, m.ffx->allocationCallbacksPtr); - if (result != FFX_API_RETURN_OK) + + if (result != FFX_API_RETURN_OK) { + NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "ffxCreateContext() failed, result = %d", (int32_t)result); + return FfxConvertError(result); + } ffxQueryGetProviderVersion providerVersion = {}; providerVersion.header.type = FFX_API_QUERY_DESC_TYPE_GET_PROVIDER_VERSION; @@ -1196,12 +1207,20 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { ID3D12Device* deviceNative = (ID3D12Device*)m_iCore.GetDeviceNativeObject(&m_Device); xess_result_t result = xessD3D12CreateContext(deviceNative, &m.xess->context); - if (result != XESS_RESULT_SUCCESS) + + if (result != XESS_RESULT_SUCCESS) { + NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "xessD3D12CreateContext() failed, result = %d", (int32_t)result); + return XessConvertError(result); + } result = xessForceLegacyScaleFactors(m.xess->context, true); - if (result != XESS_RESULT_SUCCESS) + + if (result != XESS_RESULT_SUCCESS) { + NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "xessForceLegacyScaleFactors() failed, result = %d", (int32_t)result); + return XessConvertError(result); + } xess_quality_settings_t qualitySetting = XESS_QUALITY_SETTING_ULTRA_PERFORMANCE; if (upscalerDesc.mode == UpscalerMode::NATIVE) @@ -1242,18 +1261,30 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { initParams.visibleNodeMask = NODE_MASK; result = xessD3D12BuildPipelines(m.xess->context, NULL, true, initParams.initFlags); - if (result != XESS_RESULT_SUCCESS) + + if (result != XESS_RESULT_SUCCESS) { + NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "xessD3D12BuildPipelines() failed, result = %d", (int32_t)result); + return XessConvertError(result); + } result = xessD3D12Init(m.xess->context, &initParams); - if (result != XESS_RESULT_SUCCESS) + + if (result != XESS_RESULT_SUCCESS) { + NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "xessD3D12Init() failed, result = %d", (int32_t)result); + return XessConvertError(result); + } if (upscalerDesc.preset != 0) { xess_network_model_t preset = (xess_network_model_t)(upscalerDesc.preset - 1); result = xessSelectNetworkModel(m.xess->context, preset); - if (result != XESS_RESULT_SUCCESS) + + if (result != XESS_RESULT_SUCCESS) { + NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "xessSelectNetworkModel() failed, result = %d", (int32_t)result); + return XessConvertError(result); + } } } # endif @@ -1322,8 +1353,11 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { # endif } - if (ngxResult != NVSDK_NGX_Result_Success) + if (ngxResult != NVSDK_NGX_Result_Success) { + NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "NGX initialization failed, result = 0x%08X", (uint32_t)ngxResult); + return Result::FAILURE; + } // Create command buffer if not provided Queue* graphicsQueue = nullptr; @@ -1470,8 +1504,11 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { if (result != Result::SUCCESS) return result; - if (ngxResult != NVSDK_NGX_Result_Success) + if (ngxResult != NVSDK_NGX_Result_Success) { + NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "NGX feature creation failed, result = 0x%08X", (uint32_t)ngxResult); + return Result::FAILURE; + } } #endif @@ -1653,8 +1690,9 @@ void UpscalerImpl::CmdDispatchUpscale(CommandBuffer& commandBuffer, const Dispat dispatchDesc.flags = (m_Desc.flags & UpscalerBits::SRGB) ? FFX_UPSCALE_FLAG_NON_LINEAR_COLOR_SRGB : 0; ffxReturnCode_t result = m.ffx->Dispatch(&m.ffx->context, &dispatchDesc.header); - MaybeUnused(result); - NRI_CHECK(result == FFX_API_RETURN_OK, "ffxDispatch() failed!"); + + if (result != FFX_API_RETURN_OK) + NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "ffxDispatch() failed, result = %d", (int32_t)result); } #endif @@ -1679,11 +1717,14 @@ void UpscalerImpl::CmdDispatchUpscale(CommandBuffer& commandBuffer, const Dispat ID3D12GraphicsCommandList* commandList = (ID3D12GraphicsCommandList*)m_iCore.GetCommandBufferNativeObject(&commandBuffer); xess_result_t result = xessSetExposureMultiplier(m.xess->context, 1.0f / preExposure); - NRI_CHECK(result == XESS_RESULT_SUCCESS, "xessSetExposureMultiplier() failed!"); + + if (result != XESS_RESULT_SUCCESS) + NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "xessSetExposureMultiplier() failed, result = %d", (int32_t)result); result = xessD3D12Execute(m.xess->context, commandList, &executeParams); - MaybeUnused(result); - NRI_CHECK(result == XESS_RESULT_SUCCESS, "xessD3D12Execute() failed!"); + + if (result != XESS_RESULT_SUCCESS) + NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "xessD3D12Execute() failed, result = %d", (int32_t)result); } #endif @@ -1754,7 +1795,8 @@ void UpscalerImpl::CmdDispatchUpscale(CommandBuffer& commandBuffer, const Dispat } # endif - NRI_CHECK(result == NVSDK_NGX_Result_Success, "DLSR evaluation failed!"); + if (result != NVSDK_NGX_Result_Success) + NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "DLSR evaluation failed, result = 0x%08X", (uint32_t)result); } if (m_Desc.type == UpscalerType::DLRR) { @@ -1859,7 +1901,8 @@ void UpscalerImpl::CmdDispatchUpscale(CommandBuffer& commandBuffer, const Dispat } # endif - NRI_CHECK(result == NVSDK_NGX_Result_Success, "DLRR evaluation failed!"); + if (result != NVSDK_NGX_Result_Success) + NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "DLRR evaluation failed, result = 0x%08X", (uint32_t)result); } #endif From 5e12091272ca0b7f61ce34b97e6e5235c309a128 Mon Sep 17 00:00:00 2001 From: szombathy-tamas Date: Wed, 11 Nov 2026 16:18:52 +0100 Subject: [PATCH 2/4] "Result::EXT_ERROR": failed 3rd party calls don't abort A failed vendor call is the vendor's answer, not a misuse of NRI, but it was reported with "Result::FAILURE", which calls "AbortExecution" (by default a break or a trap, in release builds too). New "Result::EXT_ERROR" (-5) is reported without it: - upscalers: creation reports and returns it for every failed FFX, XeSS and NGX call ("FfxConvertError" and "XessConvertError" are gone, they mapped vendor codes to aborting results); a failed dispatch and MetalFX scaler creation report it - NVAPI: "NRI_REPORT_ERROR_ON_BAD_NVAPI_STATUS" reports it; the Reflex calls report and return it instead of a bare "FAILURE"; a D3D11 shading rate view reports and returns it (it was an "INVALID_ARGUMENT" from "ID3D11Device::CreateXxxView") - AGS: device creation reports and returns it; D3D11 NVAPI and AGS commands report it ("NRI_RETURN_ON_EXT_FAILURE") - a failed "NvAPI_Initialize" or "agsInitialize" is a warning: the device is created without the extension, as with a missing AGS library. So is a refused "NvAPI_D3D12_EnableRaytracingValidation", which was silent --- Include/NRIDescs.h | 3 +- Source/D3D11/CommandBufferD3D11.hpp | 28 ++++----- Source/D3D11/DescriptorD3D11.hpp | 5 +- Source/D3D11/DeviceD3D11.hpp | 9 ++- Source/D3D11/SwapChainD3D11.hpp | 13 +++-- Source/D3D12/DeviceD3D12.hpp | 14 +++-- Source/D3D12/SwapChainD3D12.hpp | 13 +++-- Source/Shared/SharedExternal.h | 9 ++- Source/Shared/UpscalerInterface.hpp | 88 +++++++++-------------------- 9 files changed, 87 insertions(+), 95 deletions(-) diff --git a/Include/NRIDescs.h b/Include/NRIDescs.h index a6686a5b..e0dcc347 100644 --- a/Include/NRIDescs.h +++ b/Include/NRIDescs.h @@ -110,7 +110,8 @@ NriBits(GraphicsAPI, uint8_t, NriEnum(Result, int8_t, // All bad, but optionally require an action ("callbackInterface.AbortExecution" is not triggered) - NOT_READY = -4, // VK: zero surface extent during swap chain creation; WGPU: no swap chain texture available yet. Process window events and retry + EXT_ERROR = -5, // a 3rd party library (NVAPI, AGS, NGX, FFX, XeSS, MetalFX) failed, the reason is reported (potential reasons: a missing or outdated library or driver) + NOT_READY = -4, // VK: zero surface extent during swap chain creation; WGPU: no swap chain texture available yet. Process window events and retry DEVICE_LOST = -3, // may be returned by "QueueSubmit*", "*WaitIdle", "AcquireNextTexture", "QueuePresent", "WaitForPresent" OUT_OF_DATE = -2, // VK/WGPU: swap chain is out of date, can be triggered if "features.resizableSwapChain" is not supported; D3D12: shader cache is stale INVALID_SDK = -1, // D3D12: some interfaces are missing (potential reasons: unable to load "D3D12Core.dll", version or SDK mismatch, developer mode is not enabled) diff --git a/Source/D3D11/CommandBufferD3D11.hpp b/Source/D3D11/CommandBufferD3D11.hpp index 17e1bc52..bfda80a2 100644 --- a/Source/D3D11/CommandBufferD3D11.hpp +++ b/Source/D3D11/CommandBufferD3D11.hpp @@ -106,14 +106,14 @@ Result CommandBufferD3D11::Create(ID3D11DeviceContext* precreatedContext) { #if NRI_ENABLE_NVAPI if (m_Device.HasNvExt()) { NvAPI_Status res = NvAPI_D3D11_BeginUAVOverlap(m_DeferredContext); - NRI_RETURN_ON_FAILURE(&m_Device, res == NVAPI_OK, Result::FAILURE, "NvAPI_D3D11_BeginUAVOverlap() failed!"); + NRI_RETURN_ON_EXT_FAILURE(&m_Device, res == NVAPI_OK, Result::EXT_ERROR, "NvAPI_D3D11_BeginUAVOverlap() failed!"); } #endif #if NRI_ENABLE_AMDAGS if (m_Device.HasAmdExt()) { const AmdExtD3D11& amdExt = m_Device.GetAmdExt(); AGSReturnCode res = amdExt.BeginUAVOverlap(amdExt.context, m_DeferredContext); - NRI_RETURN_ON_FAILURE(&m_Device, res == AGS_SUCCESS, Result::FAILURE, "agsDriverExtensionsDX11_BeginUAVOverlap() failed!"); + NRI_RETURN_ON_EXT_FAILURE(&m_Device, res == AGS_SUCCESS, Result::EXT_ERROR, "agsDriverExtensionsDX11_BeginUAVOverlap() failed!"); } #endif } @@ -193,14 +193,14 @@ NRI_INLINE void CommandBufferD3D11::SetDepthBounds(float boundsMin, float bounds #if NRI_ENABLE_NVAPI if (m_Device.HasNvExt()) { NvAPI_Status status = NvAPI_D3D11_SetDepthBoundsTest(m_DeferredContext, isEnabled, boundsMin, boundsMax); - NRI_RETURN_ON_FAILURE(&m_Device, status == NVAPI_OK, ReturnVoid(), "NvAPI_D3D11_SetDepthBoundsTest() failed!"); + NRI_RETURN_ON_EXT_FAILURE(&m_Device, status == NVAPI_OK, ReturnVoid(), "NvAPI_D3D11_SetDepthBoundsTest() failed!"); } #endif #if NRI_ENABLE_AMDAGS if (m_Device.HasAmdExt()) { const AmdExtD3D11& amdExt = m_Device.GetAmdExt(); AGSReturnCode res = amdExt.SetDepthBounds(amdExt.context, m_DeferredContext, isEnabled, boundsMin, boundsMax); - NRI_RETURN_ON_FAILURE(&m_Device, res == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_SetDepthBounds() failed!"); + NRI_RETURN_ON_EXT_FAILURE(&m_Device, res == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_SetDepthBounds() failed!"); } #endif @@ -368,7 +368,7 @@ NRI_INLINE void CommandBufferD3D11::BeginRendering(const RenderingDesc& renderin if (m_Device.HasAmdExt() && m_Device.GetDesc().other.viewMaxNum > 1) { const AmdExtD3D11& amdExt = m_Device.GetAmdExt(); AGSReturnCode res = amdExt.SetViewBroadcastMasks(amdExt.context, renderingDesc.viewMask, renderingDesc.viewMask ? 0x1 : 0x0, 0); - NRI_RETURN_ON_FAILURE(&m_Device, res == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_SetViewBroadcastMasks() failed!"); + NRI_RETURN_ON_EXT_FAILURE(&m_Device, res == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_SetViewBroadcastMasks() failed!"); } #endif } @@ -487,18 +487,18 @@ NRI_INLINE void CommandBufferD3D11::DrawIndirect(const Buffer& buffer, uint64_t const BufferD3D11* countBufferD3D11 = (BufferD3D11*)countBuffer; const AmdExtD3D11& amdExt = m_Device.GetAmdExt(); AGSReturnCode res = amdExt.DrawIndirectCount(amdExt.context, m_DeferredContext, *countBufferD3D11, (uint32_t)countBufferOffset, bufferD3D11, (uint32_t)offset, stride); - NRI_RETURN_ON_FAILURE(&m_Device, res == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_MultiDrawInstancedIndirectCountIndirect() failed!"); + NRI_RETURN_ON_EXT_FAILURE(&m_Device, res == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_MultiDrawInstancedIndirectCountIndirect() failed!"); #endif } else if (m_Device.HasNvExt() && drawNum > 1) { #if NRI_ENABLE_NVAPI NvAPI_Status status = NvAPI_D3D11_MultiDrawInstancedIndirect(m_DeferredContext, drawNum, bufferD3D11, (uint32_t)offset, stride); - NRI_RETURN_ON_FAILURE(&m_Device, status == NVAPI_OK, ReturnVoid(), "NvAPI_D3D11_MultiDrawInstancedIndirect() failed!"); + NRI_RETURN_ON_EXT_FAILURE(&m_Device, status == NVAPI_OK, ReturnVoid(), "NvAPI_D3D11_MultiDrawInstancedIndirect() failed!"); #endif } else if (m_Device.HasAmdExt() && drawNum > 1) { #if NRI_ENABLE_AMDAGS const AmdExtD3D11& amdExt = m_Device.GetAmdExt(); AGSReturnCode res = amdExt.DrawIndirect(amdExt.context, m_DeferredContext, drawNum, bufferD3D11, (uint32_t)offset, stride); - NRI_RETURN_ON_FAILURE(&m_Device, res == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_MultiDrawInstancedIndirect() failed!"); + NRI_RETURN_ON_EXT_FAILURE(&m_Device, res == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_MultiDrawInstancedIndirect() failed!"); #endif } else { NRI_CHECK(!countBuffer, "'countBuffer' is unsupported"); @@ -519,18 +519,18 @@ NRI_INLINE void CommandBufferD3D11::DrawIndexedIndirect(const Buffer& buffer, ui const BufferD3D11* countBufferD3D11 = (BufferD3D11*)countBuffer; const AmdExtD3D11& amdExt = m_Device.GetAmdExt(); AGSReturnCode res = amdExt.DrawIndexedIndirectCount(amdExt.context, m_DeferredContext, *countBufferD3D11, (uint32_t)countBufferOffset, bufferD3D11, (uint32_t)offset, stride); - NRI_RETURN_ON_FAILURE(&m_Device, res == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_MultiDrawIndexedInstancedIndirectCountIndirect() failed!"); + NRI_RETURN_ON_EXT_FAILURE(&m_Device, res == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_MultiDrawIndexedInstancedIndirectCountIndirect() failed!"); #endif } else if (m_Device.HasNvExt() && drawNum > 1) { #if NRI_ENABLE_NVAPI NvAPI_Status status = NvAPI_D3D11_MultiDrawIndexedInstancedIndirect(m_DeferredContext, drawNum, bufferD3D11, (uint32_t)offset, stride); - NRI_RETURN_ON_FAILURE(&m_Device, status == NVAPI_OK, ReturnVoid(), "NvAPI_D3D11_MultiDrawIndexedInstancedIndirect() failed!"); + NRI_RETURN_ON_EXT_FAILURE(&m_Device, status == NVAPI_OK, ReturnVoid(), "NvAPI_D3D11_MultiDrawIndexedInstancedIndirect() failed!"); #endif } else if (m_Device.HasAmdExt() && drawNum > 1) { #if NRI_ENABLE_AMDAGS const AmdExtD3D11& amdExt = m_Device.GetAmdExt(); AGSReturnCode res = amdExt.DrawIndexedIndirect(amdExt.context, m_DeferredContext, drawNum, bufferD3D11, (uint32_t)offset, stride); - NRI_RETURN_ON_FAILURE(&m_Device, res == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_MultiDrawIndexedInstancedIndirect() failed!"); + NRI_RETURN_ON_EXT_FAILURE(&m_Device, res == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_MultiDrawIndexedInstancedIndirect() failed!"); #endif } else { NRI_CHECK(!countBuffer, "'countBuffer' is unsupported"); @@ -790,16 +790,16 @@ NRI_INLINE void CommandBufferD3D11::Barrier(const BarrierDesc& barrierDesc) { if (m_Device.HasNvExt()) { #if NRI_ENABLE_NVAPI NvAPI_Status res = NvAPI_D3D11_BeginUAVOverlapEx(m_DeferredContext, flags); - NRI_RETURN_ON_FAILURE(&m_Device, res == NVAPI_OK, ReturnVoid(), "NvAPI_D3D11_BeginUAVOverlap() failed!"); + NRI_RETURN_ON_EXT_FAILURE(&m_Device, res == NVAPI_OK, ReturnVoid(), "NvAPI_D3D11_BeginUAVOverlap() failed!"); #endif } else if (m_Device.HasAmdExt()) { #if NRI_ENABLE_AMDAGS // TODO: verify that this code actually works on AMD! const AmdExtD3D11& amdExt = m_Device.GetAmdExt(); AGSReturnCode res1 = amdExt.EndUAVOverlap(amdExt.context, m_DeferredContext); - NRI_RETURN_ON_FAILURE(&m_Device, res1 == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_EndUAVOverlap() failed!"); + NRI_RETURN_ON_EXT_FAILURE(&m_Device, res1 == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_EndUAVOverlap() failed!"); AGSReturnCode res2 = amdExt.BeginUAVOverlap(amdExt.context, m_DeferredContext); - NRI_RETURN_ON_FAILURE(&m_Device, res2 == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_BeginUAVOverlap() failed!"); + NRI_RETURN_ON_EXT_FAILURE(&m_Device, res2 == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_BeginUAVOverlap() failed!"); #endif } } diff --git a/Source/D3D11/DescriptorD3D11.hpp b/Source/D3D11/DescriptorD3D11.hpp index ee99e522..35ca8e7e 100644 --- a/Source/D3D11/DescriptorD3D11.hpp +++ b/Source/D3D11/DescriptorD3D11.hpp @@ -189,8 +189,9 @@ Result DescriptorD3D11::Create(const TextureViewDesc& textureViewDesc) { desc.Texture2D.MipSlice = 0; NvAPI_Status status = NvAPI_D3D11_CreateShadingRateResourceView(m_Device.GetNativeObject(), textureD3D11, &desc, (ID3D11NvShadingRateResourceView**)&m_Descriptor); - if (status == NVAPI_OK) - hr = S_OK; + NRI_RETURN_ON_EXT_FAILURE(&m_Device, status == NVAPI_OK, Result::EXT_ERROR, "NvAPI_D3D11_CreateShadingRateResourceView() failed, result = %d", (int32_t)status); + + hr = S_OK; } #endif diff --git a/Source/D3D11/DeviceD3D11.hpp b/Source/D3D11/DeviceD3D11.hpp index 22919764..6c706c67 100644 --- a/Source/D3D11/DeviceD3D11.hpp +++ b/Source/D3D11/DeviceD3D11.hpp @@ -230,7 +230,7 @@ Result DeviceD3D11::Create(const DeviceCreationDesc& desc, const DeviceCreationD result = m_AmdExt.CreateDeviceD3D11(m_AmdExt.context, &deviceCreationParams, &extensionsParams, &agsParams); } - NRI_RETURN_ON_FAILURE(this, result == AGS_SUCCESS, Result::FAILURE, "agsDriverExtensionsDX11_CreateDevice() returned %d", (int32_t)result); + NRI_RETURN_ON_EXT_FAILURE(this, result == AGS_SUCCESS, Result::EXT_ERROR, "agsDriverExtensionsDX11_CreateDevice() failed, result = %d", (int32_t)result); deviceTemp = (ID3D11DeviceBest*)agsParams.pDevice; isDepthBoundsTestSupported = agsParams.extensionsSupported.depthBoundsDeferredContexts; @@ -669,8 +669,10 @@ void DeviceD3D11::InitializeNvExt(bool disableNVAPIInitialization, bool isImport NRI_REPORT_WARNING(this, "NVAPI is disabled, because it's not loaded on the application side"); else { NvAPI_Status status = NvAPI_Initialize(); + if (status != NVAPI_OK) - NRI_REPORT_ERROR(this, "NvAPI_Initialize(): failed, result=%d!", (int32_t)status); + NRI_REPORT_WARNING(this, "NVAPI is disabled, because 'NvAPI_Initialize()' failed, result = %d", (int32_t)status); + m_NvExt.available = (status == NVAPI_OK); } #endif @@ -724,8 +726,9 @@ void DeviceD3D11::InitializeAmdExt(AGSContext* agsContext, bool isImported) { AGSConfiguration config = {}; if (!agsContext) { AGSReturnCode result = m_AmdExt.Initialize(AGS_CURRENT_VERSION, &config, &agsContext, &gpuInfo); + if (result != AGS_SUCCESS || !agsContext) { - NRI_REPORT_ERROR(this, "Failed to initialize AMDAGS: %d", (int32_t)result); + NRI_REPORT_WARNING(this, "AMDAGS is disabled, because 'agsInitialize()' failed, result = %d", (int32_t)result); UnloadSharedLibrary(*agsLibrary); return; diff --git a/Source/D3D11/SwapChainD3D11.hpp b/Source/D3D11/SwapChainD3D11.hpp index d09a7930..5e544abe 100644 --- a/Source/D3D11/SwapChainD3D11.hpp +++ b/Source/D3D11/SwapChainD3D11.hpp @@ -223,8 +223,9 @@ NRI_INLINE Result SwapChainD3D11::SetLatencySleepMode(const LatencySleepMode& la params.bUseMarkersToOptimize = true; NvAPI_Status status = NvAPI_D3D_SetSleepMode(m_Device.GetNativeObject(), ¶ms); + NRI_RETURN_ON_EXT_FAILURE(&m_Device, status == NVAPI_OK, Result::EXT_ERROR, "NvAPI_D3D_SetSleepMode() failed, result = %d", (int32_t)status); - return status == NVAPI_OK ? Result::SUCCESS : Result::FAILURE; + return Result::SUCCESS; #else MaybeUnused(latencySleepMode); @@ -239,8 +240,9 @@ NRI_INLINE Result SwapChainD3D11::SetLatencyMarker(uint64_t presentId, LatencyMa params.markerType = (NV_LATENCY_MARKER_TYPE)latencyMarker; NvAPI_Status status = NvAPI_D3D_SetLatencyMarker(m_Device.GetNativeObject(), ¶ms); + NRI_RETURN_ON_EXT_FAILURE(&m_Device, status == NVAPI_OK, Result::EXT_ERROR, "NvAPI_D3D_SetLatencyMarker() failed, result = %d", (int32_t)status); - return status == NVAPI_OK ? Result::SUCCESS : Result::FAILURE; + return Result::SUCCESS; #else MaybeUnused(presentId); MaybeUnused(latencyMarker); @@ -254,8 +256,9 @@ NRI_INLINE Result SwapChainD3D11::LatencySleep(uint64_t presentId) { #if NRI_ENABLE_NVAPI NvAPI_Status status = NvAPI_D3D_Sleep(m_Device.GetNativeObject()); + NRI_RETURN_ON_EXT_FAILURE(&m_Device, status == NVAPI_OK, Result::EXT_ERROR, "NvAPI_D3D_Sleep() failed, result = %d", (int32_t)status); - return status == NVAPI_OK ? Result::SUCCESS : Result::FAILURE; + return Result::SUCCESS; #else return Result::UNSUPPORTED; #endif @@ -286,7 +289,9 @@ NRI_INLINE Result SwapChainD3D11::GetLatencyReport(LatencyReport& latencyReport) return Result::SUCCESS; } - return Result::FAILURE; + NRI_REPORT_EXT_ERROR(&m_Device, "NvAPI_D3D_GetLatency() failed, result = %d", (int32_t)status); + + return Result::EXT_ERROR; #else return Result::UNSUPPORTED; #endif diff --git a/Source/D3D12/DeviceD3D12.hpp b/Source/D3D12/DeviceD3D12.hpp index d916cc44..a1c23bdf 100644 --- a/Source/D3D12/DeviceD3D12.hpp +++ b/Source/D3D12/DeviceD3D12.hpp @@ -589,7 +589,7 @@ Result DeviceD3D12::Create(const DeviceCreationDesc& desc, const DeviceCreationD AGSDX12ReturnedParams agsParams = {}; AGSReturnCode result = m_AmdExt.CreateDeviceD3D12(m_AmdExt.context, &deviceCreationParams, &extensionsParams, &agsParams); - NRI_RETURN_ON_FAILURE(this, result == AGS_SUCCESS, Result::FAILURE, "agsDriverExtensionsDX12_CreateDevice() failed: %d", (int32_t)result); + NRI_RETURN_ON_EXT_FAILURE(this, result == AGS_SUCCESS, Result::EXT_ERROR, "agsDriverExtensionsDX12_CreateDevice() failed, result = %d", (int32_t)result); deviceTemp = agsParams.pDevice; isShaderAtomicsI64Supported = agsParams.extensionsSupported.intrinsics19; @@ -711,7 +711,10 @@ Result DeviceD3D12::Create(const DeviceCreationDesc& desc, const DeviceCreationD // Enable ray tracing validation if (desc.enableD3D12RayTracingValidation) { NvAPI_Status status = NvAPI_D3D12_EnableRaytracingValidation(m_Device, NVAPI_D3D12_RAYTRACING_VALIDATION_FLAG_NONE); - if (status == NVAPI_OK) + + if (status != NVAPI_OK) + NRI_REPORT_WARNING(this, "Ray tracing validation is disabled, because 'NvAPI_D3D12_EnableRaytracingValidation()' failed, result = %d (requires envvar \"NV_ALLOW_RAYTRACING_VALIDATION=1\")", (int32_t)status); + else NRI_REPORT_ERROR_ON_BAD_NVAPI_STATUS(this, NvAPI_D3D12_RegisterRaytracingValidationMessageCallback(m_Device, NvapiMessageCallback, this, &m_CallbackHandle)); // TODO: if enabled, call "NvAPI_D3D12_FlushRaytracingValidationMessages()" after each submit? present? DEVICE_LOST? @@ -1339,8 +1342,10 @@ void DeviceD3D12::InitializeNvExt(bool disableNVAPIInitialization, bool isImport NRI_REPORT_WARNING(this, "NVAPI is disabled, because it's not loaded on the application side"); else { NvAPI_Status status = NvAPI_Initialize(); + if (status != NVAPI_OK) - NRI_REPORT_ERROR(this, "NvAPI_Initialize(): failed, result=%d!", (int32_t)status); + NRI_REPORT_WARNING(this, "NVAPI is disabled, because 'NvAPI_Initialize()' failed, result = %d", (int32_t)status); + m_NvExt.available = (status == NVAPI_OK); } #endif @@ -1386,8 +1391,9 @@ void DeviceD3D12::InitializeAmdExt(AGSContext* agsContext, bool isImported) { AGSConfiguration config = {}; if (!agsContext) { const AGSReturnCode result = m_AmdExt.Initialize(AGS_CURRENT_VERSION, &config, &agsContext, &gpuInfo); + if (result != AGS_SUCCESS || !agsContext) { - NRI_REPORT_ERROR(this, "Failed to initialize AMDAGS: %d", (int32_t)result); + NRI_REPORT_WARNING(this, "AMDAGS is disabled, because 'agsInitialize()' failed, result = %d", (int32_t)result); UnloadSharedLibrary(*agsLibrary); return; diff --git a/Source/D3D12/SwapChainD3D12.hpp b/Source/D3D12/SwapChainD3D12.hpp index 4b2a7507..a0a1a081 100644 --- a/Source/D3D12/SwapChainD3D12.hpp +++ b/Source/D3D12/SwapChainD3D12.hpp @@ -231,8 +231,9 @@ NRI_INLINE Result SwapChainD3D12::SetLatencySleepMode(const LatencySleepMode& la params.bUseMarkersToOptimize = true; NvAPI_Status status = NvAPI_D3D_SetSleepMode(m_Device.GetNativeObject(), ¶ms); + NRI_RETURN_ON_EXT_FAILURE(&m_Device, status == NVAPI_OK, Result::EXT_ERROR, "NvAPI_D3D_SetSleepMode() failed, result = %d", (int32_t)status); - return status == NVAPI_OK ? Result::SUCCESS : Result::FAILURE; + return Result::SUCCESS; #else MaybeUnused(latencySleepMode); @@ -247,8 +248,9 @@ NRI_INLINE Result SwapChainD3D12::SetLatencyMarker(uint64_t presentId, LatencyMa params.markerType = (NV_LATENCY_MARKER_TYPE)latencyMarker; NvAPI_Status status = NvAPI_D3D_SetLatencyMarker(m_Device.GetNativeObject(), ¶ms); + NRI_RETURN_ON_EXT_FAILURE(&m_Device, status == NVAPI_OK, Result::EXT_ERROR, "NvAPI_D3D_SetLatencyMarker() failed, result = %d", (int32_t)status); - return status == NVAPI_OK ? Result::SUCCESS : Result::FAILURE; + return Result::SUCCESS; #else MaybeUnused(presentId); MaybeUnused(latencyMarker); @@ -262,8 +264,9 @@ NRI_INLINE Result SwapChainD3D12::LatencySleep(uint64_t presentId) { #if NRI_ENABLE_NVAPI NvAPI_Status status = NvAPI_D3D_Sleep(m_Device.GetNativeObject()); + NRI_RETURN_ON_EXT_FAILURE(&m_Device, status == NVAPI_OK, Result::EXT_ERROR, "NvAPI_D3D_Sleep() failed, result = %d", (int32_t)status); - return status == NVAPI_OK ? Result::SUCCESS : Result::FAILURE; + return Result::SUCCESS; #else return Result::UNSUPPORTED; #endif @@ -294,7 +297,9 @@ NRI_INLINE Result SwapChainD3D12::GetLatencyReport(LatencyReport& latencyReport) return Result::SUCCESS; } - return Result::FAILURE; + NRI_REPORT_EXT_ERROR(&m_Device, "NvAPI_D3D_GetLatency() failed, result = %d", (int32_t)status); + + return Result::EXT_ERROR; #else return Result::UNSUPPORTED; #endif diff --git a/Source/Shared/SharedExternal.h b/Source/Shared/SharedExternal.h index 1d81fd12..57fb6d02 100644 --- a/Source/Shared/SharedExternal.h +++ b/Source/Shared/SharedExternal.h @@ -314,7 +314,7 @@ struct ComPtr { #define NRI_REPORT_ERROR_ON_BAD_NVAPI_STATUS(deviceBase, expression) \ if ((expression) != 0) { \ - (deviceBase)->ReportMessage(Message::ERROR, Result::FAILURE, __FILE__, __LINE__, "%s: " NRI_STRINGIFY(expression) " failed!", __FUNCTION__); \ + (deviceBase)->ReportMessage(Message::ERROR, Result::EXT_ERROR, __FILE__, __LINE__, "%s: " NRI_STRINGIFY(expression) " failed!", __FUNCTION__); \ } #define NRI_RETURN_ON_FAILURE(deviceBase, condition, returnCode, format, ...) \ @@ -323,9 +323,16 @@ struct ComPtr { return returnCode; \ } +#define NRI_RETURN_ON_EXT_FAILURE(deviceBase, condition, returnCode, format, ...) \ + if (!(condition)) { \ + (deviceBase)->ReportMessage(Message::ERROR, Result::EXT_ERROR, __FILE__, __LINE__, "%s: " format, __FUNCTION__, ##__VA_ARGS__); \ + return returnCode; \ + } + #define NRI_REPORT_INFO(deviceBase, format, ...) (deviceBase)->ReportMessage(Message::INFO, Result::SUCCESS, __FILE__, __LINE__, format, ##__VA_ARGS__) #define NRI_REPORT_WARNING(deviceBase, format, ...) (deviceBase)->ReportMessage(Message::WARNING, Result::SUCCESS, __FILE__, __LINE__, "%s(): " format, __FUNCTION__, ##__VA_ARGS__) #define NRI_REPORT_ERROR(deviceBase, format, ...) (deviceBase)->ReportMessage(Message::ERROR, Result::FAILURE, __FILE__, __LINE__, "%s(): " format, __FUNCTION__, ##__VA_ARGS__) +#define NRI_REPORT_EXT_ERROR(deviceBase, format, ...) (deviceBase)->ReportMessage(Message::ERROR, Result::EXT_ERROR, __FILE__, __LINE__, "%s(): " format, __FUNCTION__, ##__VA_ARGS__) #define NRI_REPORT_DEVICE_LOST_INFO(deviceBase, format, ...) (deviceBase)->ReportMessage(Message::INFO, Result::DEVICE_LOST, __FILE__, __LINE__, format, ##__VA_ARGS__) // Array validation diff --git a/Source/Shared/UpscalerInterface.hpp b/Source/Shared/UpscalerInterface.hpp index 65084bdc..a2539e3d 100644 --- a/Source/Shared/UpscalerInterface.hpp +++ b/Source/Shared/UpscalerInterface.hpp @@ -203,22 +203,6 @@ static inline PFN_vkVoidFunction VKAPI_PTR FfxVkGetDeviceProcAddr(VkDevice devic # endif -static inline Result FfxConvertError(ffxReturnCode_t code) { - switch (code) { - case FFX_API_RETURN_OK: - return Result::SUCCESS; - case FFX_API_RETURN_ERROR_UNKNOWN_DESCTYPE: - case FFX_API_RETURN_ERROR_PARAMETER: - return Result::INVALID_ARGUMENT; - case FFX_API_RETURN_ERROR_MEMORY: - return Result::OUT_OF_MEMORY; - case FFX_API_RETURN_NO_PROVIDER: - return Result::UNSUPPORTED; - } - - return Result::FAILURE; -} - static inline FfxApiSurfaceFormat FfxConvertFormat(Format format) { switch (format) { case Format::RGBA32_UINT: @@ -366,26 +350,6 @@ struct XessGlobals { Lock lock = {}; // methods in XESS library are NOT thread safe (see "Thread safety") } g_xess; -static inline Result XessConvertError(xess_result_t code) { - switch (code) { - case XESS_RESULT_WARNING_NONEXISTING_FOLDER: - case XESS_RESULT_WARNING_OLD_DRIVER: - case XESS_RESULT_ERROR_INVALID_ARGUMENT: - return Result::INVALID_ARGUMENT; - - case XESS_RESULT_SUCCESS: - return Result::SUCCESS; - - case XESS_RESULT_ERROR_UNSUPPORTED: - case XESS_RESULT_ERROR_UNSUPPORTED_DEVICE: - case XESS_RESULT_ERROR_UNSUPPORTED_DRIVER: - return Result::UNSUPPORTED; - - default: - return Result::FAILURE; - } -} - #endif //===================================================================================================================================== @@ -1083,9 +1047,9 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { Library* ffxLibrary = LoadSharedLibrary(libraryName); if (!ffxLibrary) { - NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "'%s' can't be loaded", libraryName); + NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "'%s' can't be loaded", libraryName); - return Result::FAILURE; + return Result::EXT_ERROR; } // Get functions @@ -1096,9 +1060,9 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { m.ffx->Query = (PfnFfxQuery)GetSharedLibraryFunction(*ffxLibrary, "ffxQuery"); if (!m.ffx->CreateContext || !m.ffx->DestroyContext || !m.ffx->Dispatch || !m.ffx->Query) { - NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "'%s' lacks an FFX API entry point", libraryName); + NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "'%s' lacks an FFX API entry point", libraryName); - return Result::FAILURE; + return Result::EXT_ERROR; } // Allocation callbacks @@ -1179,9 +1143,9 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { ffxReturnCode_t result = m.ffx->CreateContext(&m.ffx->context, &contextDesc.header, m.ffx->allocationCallbacksPtr); if (result != FFX_API_RETURN_OK) { - NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "ffxCreateContext() failed, result = %d", (int32_t)result); + NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "ffxCreateContext() failed, result = %d", (int32_t)result); - return FfxConvertError(result); + return Result::EXT_ERROR; } ffxQueryGetProviderVersion providerVersion = {}; @@ -1209,17 +1173,17 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { xess_result_t result = xessD3D12CreateContext(deviceNative, &m.xess->context); if (result != XESS_RESULT_SUCCESS) { - NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "xessD3D12CreateContext() failed, result = %d", (int32_t)result); + NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "xessD3D12CreateContext() failed, result = %d", (int32_t)result); - return XessConvertError(result); + return Result::EXT_ERROR; } result = xessForceLegacyScaleFactors(m.xess->context, true); if (result != XESS_RESULT_SUCCESS) { - NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "xessForceLegacyScaleFactors() failed, result = %d", (int32_t)result); + NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "xessForceLegacyScaleFactors() failed, result = %d", (int32_t)result); - return XessConvertError(result); + return Result::EXT_ERROR; } xess_quality_settings_t qualitySetting = XESS_QUALITY_SETTING_ULTRA_PERFORMANCE; @@ -1263,17 +1227,17 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { result = xessD3D12BuildPipelines(m.xess->context, NULL, true, initParams.initFlags); if (result != XESS_RESULT_SUCCESS) { - NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "xessD3D12BuildPipelines() failed, result = %d", (int32_t)result); + NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "xessD3D12BuildPipelines() failed, result = %d", (int32_t)result); - return XessConvertError(result); + return Result::EXT_ERROR; } result = xessD3D12Init(m.xess->context, &initParams); if (result != XESS_RESULT_SUCCESS) { - NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "xessD3D12Init() failed, result = %d", (int32_t)result); + NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "xessD3D12Init() failed, result = %d", (int32_t)result); - return XessConvertError(result); + return Result::EXT_ERROR; } if (upscalerDesc.preset != 0) { @@ -1281,9 +1245,9 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { result = xessSelectNetworkModel(m.xess->context, preset); if (result != XESS_RESULT_SUCCESS) { - NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "xessSelectNetworkModel() failed, result = %d", (int32_t)result); + NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "xessSelectNetworkModel() failed, result = %d", (int32_t)result); - return XessConvertError(result); + return Result::EXT_ERROR; } } } @@ -1354,9 +1318,9 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { } if (ngxResult != NVSDK_NGX_Result_Success) { - NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "NGX initialization failed, result = 0x%08X", (uint32_t)ngxResult); + NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "NGX initialization failed, result = 0x%08X", (uint32_t)ngxResult); - return Result::FAILURE; + return Result::EXT_ERROR; } // Create command buffer if not provided @@ -1505,9 +1469,9 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { return result; if (ngxResult != NVSDK_NGX_Result_Success) { - NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "NGX feature creation failed, result = 0x%08X", (uint32_t)ngxResult); + NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "NGX feature creation failed, result = 0x%08X", (uint32_t)ngxResult); - return Result::FAILURE; + return Result::EXT_ERROR; } } #endif @@ -1692,7 +1656,7 @@ void UpscalerImpl::CmdDispatchUpscale(CommandBuffer& commandBuffer, const Dispat ffxReturnCode_t result = m.ffx->Dispatch(&m.ffx->context, &dispatchDesc.header); if (result != FFX_API_RETURN_OK) - NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "ffxDispatch() failed, result = %d", (int32_t)result); + NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "ffxDispatch() failed, result = %d", (int32_t)result); } #endif @@ -1719,12 +1683,12 @@ void UpscalerImpl::CmdDispatchUpscale(CommandBuffer& commandBuffer, const Dispat xess_result_t result = xessSetExposureMultiplier(m.xess->context, 1.0f / preExposure); if (result != XESS_RESULT_SUCCESS) - NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "xessSetExposureMultiplier() failed, result = %d", (int32_t)result); + NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "xessSetExposureMultiplier() failed, result = %d", (int32_t)result); result = xessD3D12Execute(m.xess->context, commandList, &executeParams); if (result != XESS_RESULT_SUCCESS) - NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "xessD3D12Execute() failed, result = %d", (int32_t)result); + NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "xessD3D12Execute() failed, result = %d", (int32_t)result); } #endif @@ -1796,7 +1760,7 @@ void UpscalerImpl::CmdDispatchUpscale(CommandBuffer& commandBuffer, const Dispat # endif if (result != NVSDK_NGX_Result_Success) - NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "DLSR evaluation failed, result = 0x%08X", (uint32_t)result); + NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "DLSR evaluation failed, result = 0x%08X", (uint32_t)result); } if (m_Desc.type == UpscalerType::DLRR) { @@ -1902,7 +1866,7 @@ void UpscalerImpl::CmdDispatchUpscale(CommandBuffer& commandBuffer, const Dispat # endif if (result != NVSDK_NGX_Result_Success) - NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "DLRR evaluation failed, result = 0x%08X", (uint32_t)result); + NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "DLRR evaluation failed, result = 0x%08X", (uint32_t)result); } #endif @@ -1923,7 +1887,7 @@ void UpscalerImpl::CmdDispatchUpscale(CommandBuffer& commandBuffer, const Dispat isCreated = MetalFxCreateScaler(metalFx, deviceNative, m_iCore, m_Desc, dispatchUpscaleDesc); if (!isCreated) - NRI_REPORT_ERROR(&(DeviceBase&)m_Device, "MetalFX scaler creation failed"); + NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "MetalFX scaler creation failed"); } // The scaler is created for the "input" size of the first dispatch From 13e510d13ba7c44e21186aecf7be893497331618 Mon Sep 17 00:00:00 2001 From: dzhdan Date: Thu, 12 Nov 2026 10:31:49 +0800 Subject: [PATCH 3/4] Fixed vendor SDK error handling and XeSS warnings --- Include/NRIDescs.h | 4 +- Source/D3D11/CommandBufferD3D11.hpp | 28 +++--- Source/D3D11/DescriptorD3D11.hpp | 2 +- Source/D3D11/DeviceD3D11.hpp | 2 +- Source/D3D12/DeviceD3D12.hpp | 2 +- Source/Shared/SharedExternal.h | 2 +- Source/Shared/UpscalerInterface.hpp | 130 ++++++++++++++++++++-------- 7 files changed, 115 insertions(+), 55 deletions(-) diff --git a/Include/NRIDescs.h b/Include/NRIDescs.h index e0dcc347..dc4c77b4 100644 --- a/Include/NRIDescs.h +++ b/Include/NRIDescs.h @@ -110,8 +110,8 @@ NriBits(GraphicsAPI, uint8_t, NriEnum(Result, int8_t, // All bad, but optionally require an action ("callbackInterface.AbortExecution" is not triggered) - EXT_ERROR = -5, // a 3rd party library (NVAPI, AGS, NGX, FFX, XeSS, MetalFX) failed, the reason is reported (potential reasons: a missing or outdated library or driver) - NOT_READY = -4, // VK: zero surface extent during swap chain creation; WGPU: no swap chain texture available yet. Process window events and retry + EXT_ERROR = -5, // a potentially recoverable 3rd party SDK failure; details are reported + NOT_READY = -4, // VK: zero surface extent during swap chain creation; WGPU: no swap chain texture available yet. Process window events and retry DEVICE_LOST = -3, // may be returned by "QueueSubmit*", "*WaitIdle", "AcquireNextTexture", "QueuePresent", "WaitForPresent" OUT_OF_DATE = -2, // VK/WGPU: swap chain is out of date, can be triggered if "features.resizableSwapChain" is not supported; D3D12: shader cache is stale INVALID_SDK = -1, // D3D12: some interfaces are missing (potential reasons: unable to load "D3D12Core.dll", version or SDK mismatch, developer mode is not enabled) diff --git a/Source/D3D11/CommandBufferD3D11.hpp b/Source/D3D11/CommandBufferD3D11.hpp index bfda80a2..17e1bc52 100644 --- a/Source/D3D11/CommandBufferD3D11.hpp +++ b/Source/D3D11/CommandBufferD3D11.hpp @@ -106,14 +106,14 @@ Result CommandBufferD3D11::Create(ID3D11DeviceContext* precreatedContext) { #if NRI_ENABLE_NVAPI if (m_Device.HasNvExt()) { NvAPI_Status res = NvAPI_D3D11_BeginUAVOverlap(m_DeferredContext); - NRI_RETURN_ON_EXT_FAILURE(&m_Device, res == NVAPI_OK, Result::EXT_ERROR, "NvAPI_D3D11_BeginUAVOverlap() failed!"); + NRI_RETURN_ON_FAILURE(&m_Device, res == NVAPI_OK, Result::FAILURE, "NvAPI_D3D11_BeginUAVOverlap() failed!"); } #endif #if NRI_ENABLE_AMDAGS if (m_Device.HasAmdExt()) { const AmdExtD3D11& amdExt = m_Device.GetAmdExt(); AGSReturnCode res = amdExt.BeginUAVOverlap(amdExt.context, m_DeferredContext); - NRI_RETURN_ON_EXT_FAILURE(&m_Device, res == AGS_SUCCESS, Result::EXT_ERROR, "agsDriverExtensionsDX11_BeginUAVOverlap() failed!"); + NRI_RETURN_ON_FAILURE(&m_Device, res == AGS_SUCCESS, Result::FAILURE, "agsDriverExtensionsDX11_BeginUAVOverlap() failed!"); } #endif } @@ -193,14 +193,14 @@ NRI_INLINE void CommandBufferD3D11::SetDepthBounds(float boundsMin, float bounds #if NRI_ENABLE_NVAPI if (m_Device.HasNvExt()) { NvAPI_Status status = NvAPI_D3D11_SetDepthBoundsTest(m_DeferredContext, isEnabled, boundsMin, boundsMax); - NRI_RETURN_ON_EXT_FAILURE(&m_Device, status == NVAPI_OK, ReturnVoid(), "NvAPI_D3D11_SetDepthBoundsTest() failed!"); + NRI_RETURN_ON_FAILURE(&m_Device, status == NVAPI_OK, ReturnVoid(), "NvAPI_D3D11_SetDepthBoundsTest() failed!"); } #endif #if NRI_ENABLE_AMDAGS if (m_Device.HasAmdExt()) { const AmdExtD3D11& amdExt = m_Device.GetAmdExt(); AGSReturnCode res = amdExt.SetDepthBounds(amdExt.context, m_DeferredContext, isEnabled, boundsMin, boundsMax); - NRI_RETURN_ON_EXT_FAILURE(&m_Device, res == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_SetDepthBounds() failed!"); + NRI_RETURN_ON_FAILURE(&m_Device, res == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_SetDepthBounds() failed!"); } #endif @@ -368,7 +368,7 @@ NRI_INLINE void CommandBufferD3D11::BeginRendering(const RenderingDesc& renderin if (m_Device.HasAmdExt() && m_Device.GetDesc().other.viewMaxNum > 1) { const AmdExtD3D11& amdExt = m_Device.GetAmdExt(); AGSReturnCode res = amdExt.SetViewBroadcastMasks(amdExt.context, renderingDesc.viewMask, renderingDesc.viewMask ? 0x1 : 0x0, 0); - NRI_RETURN_ON_EXT_FAILURE(&m_Device, res == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_SetViewBroadcastMasks() failed!"); + NRI_RETURN_ON_FAILURE(&m_Device, res == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_SetViewBroadcastMasks() failed!"); } #endif } @@ -487,18 +487,18 @@ NRI_INLINE void CommandBufferD3D11::DrawIndirect(const Buffer& buffer, uint64_t const BufferD3D11* countBufferD3D11 = (BufferD3D11*)countBuffer; const AmdExtD3D11& amdExt = m_Device.GetAmdExt(); AGSReturnCode res = amdExt.DrawIndirectCount(amdExt.context, m_DeferredContext, *countBufferD3D11, (uint32_t)countBufferOffset, bufferD3D11, (uint32_t)offset, stride); - NRI_RETURN_ON_EXT_FAILURE(&m_Device, res == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_MultiDrawInstancedIndirectCountIndirect() failed!"); + NRI_RETURN_ON_FAILURE(&m_Device, res == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_MultiDrawInstancedIndirectCountIndirect() failed!"); #endif } else if (m_Device.HasNvExt() && drawNum > 1) { #if NRI_ENABLE_NVAPI NvAPI_Status status = NvAPI_D3D11_MultiDrawInstancedIndirect(m_DeferredContext, drawNum, bufferD3D11, (uint32_t)offset, stride); - NRI_RETURN_ON_EXT_FAILURE(&m_Device, status == NVAPI_OK, ReturnVoid(), "NvAPI_D3D11_MultiDrawInstancedIndirect() failed!"); + NRI_RETURN_ON_FAILURE(&m_Device, status == NVAPI_OK, ReturnVoid(), "NvAPI_D3D11_MultiDrawInstancedIndirect() failed!"); #endif } else if (m_Device.HasAmdExt() && drawNum > 1) { #if NRI_ENABLE_AMDAGS const AmdExtD3D11& amdExt = m_Device.GetAmdExt(); AGSReturnCode res = amdExt.DrawIndirect(amdExt.context, m_DeferredContext, drawNum, bufferD3D11, (uint32_t)offset, stride); - NRI_RETURN_ON_EXT_FAILURE(&m_Device, res == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_MultiDrawInstancedIndirect() failed!"); + NRI_RETURN_ON_FAILURE(&m_Device, res == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_MultiDrawInstancedIndirect() failed!"); #endif } else { NRI_CHECK(!countBuffer, "'countBuffer' is unsupported"); @@ -519,18 +519,18 @@ NRI_INLINE void CommandBufferD3D11::DrawIndexedIndirect(const Buffer& buffer, ui const BufferD3D11* countBufferD3D11 = (BufferD3D11*)countBuffer; const AmdExtD3D11& amdExt = m_Device.GetAmdExt(); AGSReturnCode res = amdExt.DrawIndexedIndirectCount(amdExt.context, m_DeferredContext, *countBufferD3D11, (uint32_t)countBufferOffset, bufferD3D11, (uint32_t)offset, stride); - NRI_RETURN_ON_EXT_FAILURE(&m_Device, res == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_MultiDrawIndexedInstancedIndirectCountIndirect() failed!"); + NRI_RETURN_ON_FAILURE(&m_Device, res == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_MultiDrawIndexedInstancedIndirectCountIndirect() failed!"); #endif } else if (m_Device.HasNvExt() && drawNum > 1) { #if NRI_ENABLE_NVAPI NvAPI_Status status = NvAPI_D3D11_MultiDrawIndexedInstancedIndirect(m_DeferredContext, drawNum, bufferD3D11, (uint32_t)offset, stride); - NRI_RETURN_ON_EXT_FAILURE(&m_Device, status == NVAPI_OK, ReturnVoid(), "NvAPI_D3D11_MultiDrawIndexedInstancedIndirect() failed!"); + NRI_RETURN_ON_FAILURE(&m_Device, status == NVAPI_OK, ReturnVoid(), "NvAPI_D3D11_MultiDrawIndexedInstancedIndirect() failed!"); #endif } else if (m_Device.HasAmdExt() && drawNum > 1) { #if NRI_ENABLE_AMDAGS const AmdExtD3D11& amdExt = m_Device.GetAmdExt(); AGSReturnCode res = amdExt.DrawIndexedIndirect(amdExt.context, m_DeferredContext, drawNum, bufferD3D11, (uint32_t)offset, stride); - NRI_RETURN_ON_EXT_FAILURE(&m_Device, res == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_MultiDrawIndexedInstancedIndirect() failed!"); + NRI_RETURN_ON_FAILURE(&m_Device, res == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_MultiDrawIndexedInstancedIndirect() failed!"); #endif } else { NRI_CHECK(!countBuffer, "'countBuffer' is unsupported"); @@ -790,16 +790,16 @@ NRI_INLINE void CommandBufferD3D11::Barrier(const BarrierDesc& barrierDesc) { if (m_Device.HasNvExt()) { #if NRI_ENABLE_NVAPI NvAPI_Status res = NvAPI_D3D11_BeginUAVOverlapEx(m_DeferredContext, flags); - NRI_RETURN_ON_EXT_FAILURE(&m_Device, res == NVAPI_OK, ReturnVoid(), "NvAPI_D3D11_BeginUAVOverlap() failed!"); + NRI_RETURN_ON_FAILURE(&m_Device, res == NVAPI_OK, ReturnVoid(), "NvAPI_D3D11_BeginUAVOverlap() failed!"); #endif } else if (m_Device.HasAmdExt()) { #if NRI_ENABLE_AMDAGS // TODO: verify that this code actually works on AMD! const AmdExtD3D11& amdExt = m_Device.GetAmdExt(); AGSReturnCode res1 = amdExt.EndUAVOverlap(amdExt.context, m_DeferredContext); - NRI_RETURN_ON_EXT_FAILURE(&m_Device, res1 == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_EndUAVOverlap() failed!"); + NRI_RETURN_ON_FAILURE(&m_Device, res1 == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_EndUAVOverlap() failed!"); AGSReturnCode res2 = amdExt.BeginUAVOverlap(amdExt.context, m_DeferredContext); - NRI_RETURN_ON_EXT_FAILURE(&m_Device, res2 == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_BeginUAVOverlap() failed!"); + NRI_RETURN_ON_FAILURE(&m_Device, res2 == AGS_SUCCESS, ReturnVoid(), "agsDriverExtensionsDX11_BeginUAVOverlap() failed!"); #endif } } diff --git a/Source/D3D11/DescriptorD3D11.hpp b/Source/D3D11/DescriptorD3D11.hpp index 35ca8e7e..39819523 100644 --- a/Source/D3D11/DescriptorD3D11.hpp +++ b/Source/D3D11/DescriptorD3D11.hpp @@ -189,7 +189,7 @@ Result DescriptorD3D11::Create(const TextureViewDesc& textureViewDesc) { desc.Texture2D.MipSlice = 0; NvAPI_Status status = NvAPI_D3D11_CreateShadingRateResourceView(m_Device.GetNativeObject(), textureD3D11, &desc, (ID3D11NvShadingRateResourceView**)&m_Descriptor); - NRI_RETURN_ON_EXT_FAILURE(&m_Device, status == NVAPI_OK, Result::EXT_ERROR, "NvAPI_D3D11_CreateShadingRateResourceView() failed, result = %d", (int32_t)status); + NRI_RETURN_ON_FAILURE(&m_Device, status == NVAPI_OK, Result::FAILURE, "NvAPI_D3D11_CreateShadingRateResourceView() failed, result = %d", (int32_t)status); hr = S_OK; } diff --git a/Source/D3D11/DeviceD3D11.hpp b/Source/D3D11/DeviceD3D11.hpp index 6c706c67..d1a8d404 100644 --- a/Source/D3D11/DeviceD3D11.hpp +++ b/Source/D3D11/DeviceD3D11.hpp @@ -230,7 +230,7 @@ Result DeviceD3D11::Create(const DeviceCreationDesc& desc, const DeviceCreationD result = m_AmdExt.CreateDeviceD3D11(m_AmdExt.context, &deviceCreationParams, &extensionsParams, &agsParams); } - NRI_RETURN_ON_EXT_FAILURE(this, result == AGS_SUCCESS, Result::EXT_ERROR, "agsDriverExtensionsDX11_CreateDevice() failed, result = %d", (int32_t)result); + NRI_RETURN_ON_FAILURE(this, result == AGS_SUCCESS, Result::FAILURE, "agsDriverExtensionsDX11_CreateDevice() failed, result = %d", (int32_t)result); deviceTemp = (ID3D11DeviceBest*)agsParams.pDevice; isDepthBoundsTestSupported = agsParams.extensionsSupported.depthBoundsDeferredContexts; diff --git a/Source/D3D12/DeviceD3D12.hpp b/Source/D3D12/DeviceD3D12.hpp index a1c23bdf..198fbbd5 100644 --- a/Source/D3D12/DeviceD3D12.hpp +++ b/Source/D3D12/DeviceD3D12.hpp @@ -589,7 +589,7 @@ Result DeviceD3D12::Create(const DeviceCreationDesc& desc, const DeviceCreationD AGSDX12ReturnedParams agsParams = {}; AGSReturnCode result = m_AmdExt.CreateDeviceD3D12(m_AmdExt.context, &deviceCreationParams, &extensionsParams, &agsParams); - NRI_RETURN_ON_EXT_FAILURE(this, result == AGS_SUCCESS, Result::EXT_ERROR, "agsDriverExtensionsDX12_CreateDevice() failed, result = %d", (int32_t)result); + NRI_RETURN_ON_FAILURE(this, result == AGS_SUCCESS, Result::FAILURE, "agsDriverExtensionsDX12_CreateDevice() failed, result = %d", (int32_t)result); deviceTemp = agsParams.pDevice; isShaderAtomicsI64Supported = agsParams.extensionsSupported.intrinsics19; diff --git a/Source/Shared/SharedExternal.h b/Source/Shared/SharedExternal.h index 57fb6d02..049464dd 100644 --- a/Source/Shared/SharedExternal.h +++ b/Source/Shared/SharedExternal.h @@ -314,7 +314,7 @@ struct ComPtr { #define NRI_REPORT_ERROR_ON_BAD_NVAPI_STATUS(deviceBase, expression) \ if ((expression) != 0) { \ - (deviceBase)->ReportMessage(Message::ERROR, Result::EXT_ERROR, __FILE__, __LINE__, "%s: " NRI_STRINGIFY(expression) " failed!", __FUNCTION__); \ + (deviceBase)->ReportMessage(Message::ERROR, Result::FAILURE, __FILE__, __LINE__, "%s: " NRI_STRINGIFY(expression) " failed!", __FUNCTION__); \ } #define NRI_RETURN_ON_FAILURE(deviceBase, condition, returnCode, format, ...) \ diff --git a/Source/Shared/UpscalerInterface.hpp b/Source/Shared/UpscalerInterface.hpp index a2539e3d..200cfc25 100644 --- a/Source/Shared/UpscalerInterface.hpp +++ b/Source/Shared/UpscalerInterface.hpp @@ -203,6 +203,23 @@ static inline PFN_vkVoidFunction VKAPI_PTR FfxVkGetDeviceProcAddr(VkDevice devic # endif +static inline Result FfxConvertError(ffxReturnCode_t code) { + switch (code) { + case FFX_API_RETURN_OK: + return Result::SUCCESS; + case FFX_API_RETURN_ERROR_UNKNOWN_DESCTYPE: + case FFX_API_RETURN_ERROR_PARAMETER: + return Result::INVALID_ARGUMENT; + case FFX_API_RETURN_ERROR_MEMORY: + return Result::OUT_OF_MEMORY; + case FFX_API_RETURN_NO_PROVIDER: + case FFX_API_RETURN_PROVIDER_NO_SUPPORT_NEW_DESCTYPE: + return Result::UNSUPPORTED; + default: + return Result::EXT_ERROR; + } +} + static inline FfxApiSurfaceFormat FfxConvertFormat(Format format) { switch (format) { case Format::RGBA32_UINT: @@ -350,6 +367,37 @@ struct XessGlobals { Lock lock = {}; // methods in XESS library are NOT thread safe (see "Thread safety") } g_xess; +static inline Result XessConvertError(xess_result_t code) { + if (code >= XESS_RESULT_SUCCESS) + return Result::SUCCESS; + + switch (code) { + case XESS_RESULT_ERROR_UNINITIALIZED: + case XESS_RESULT_ERROR_INVALID_ARGUMENT: + case XESS_RESULT_ERROR_INVALID_CONTEXT: + case XESS_RESULT_ERROR_WRONG_CALL_ORDER: + return Result::INVALID_ARGUMENT; + case XESS_RESULT_ERROR_UNSUPPORTED: + case XESS_RESULT_ERROR_UNSUPPORTED_DEVICE: + case XESS_RESULT_ERROR_UNSUPPORTED_DRIVER: + case XESS_RESULT_ERROR_NOT_IMPLEMENTED: + return Result::UNSUPPORTED; + case XESS_RESULT_ERROR_DEVICE_OUT_OF_MEMORY: + return Result::OUT_OF_MEMORY; + default: + return Result::EXT_ERROR; + } +} + +static inline Result XessReportResult(DeviceBase& device, xess_result_t code, const char* function) { + if (code > XESS_RESULT_SUCCESS) + NRI_REPORT_WARNING(&device, "%s() returned a warning, result = %d", function, (int32_t)code); + else if (code < XESS_RESULT_SUCCESS) + NRI_REPORT_EXT_ERROR(&device, "%s() failed, result = %d", function, (int32_t)code); + + return XessConvertError(code); +} + #endif //===================================================================================================================================== @@ -401,6 +449,28 @@ struct NgxGlobals { Lock lock = {}; // methods in NGX library are NOT thread safe (see the comment in "nvsdk_ngx.h") } g_ngx; +static inline Result NgxConvertError(NVSDK_NGX_Result code) { + switch (code) { + case NVSDK_NGX_Result_Success: + return Result::SUCCESS; + case NVSDK_NGX_Result_FAIL_InvalidParameter: + case NVSDK_NGX_Result_FAIL_ScratchBufferTooSmall: + case NVSDK_NGX_Result_FAIL_RWFlagMissing: + case NVSDK_NGX_Result_FAIL_MissingInput: + return Result::INVALID_ARGUMENT; + case NVSDK_NGX_Result_FAIL_FeatureNotSupported: + case NVSDK_NGX_Result_FAIL_UnsupportedInputFormat: + case NVSDK_NGX_Result_FAIL_UnsupportedFormat: + case NVSDK_NGX_Result_FAIL_UnsupportedParameter: + case NVSDK_NGX_Result_FAIL_NotImplemented: + return Result::UNSUPPORTED; + case NVSDK_NGX_Result_FAIL_OutOfGPUMemory: + return Result::OUT_OF_MEMORY; + default: + return Result::EXT_ERROR; + } +} + static inline int32_t NgxIncrRef(void* deviceNative) { uint32_t i = 0; for (; i < g_ngx.refCounterNum && g_ngx.refCounters[i].deviceNative != deviceNative; i++) @@ -682,9 +752,10 @@ UpscalerImpl::~UpscalerImpl() { if (m_Desc.type == UpscalerType::XESS && m.xess) { ExclusiveScope lock(g_xess.lock); - xess_result_t result = xessDestroyContext(m.xess->context); - MaybeUnused(result); - NRI_CHECK(result == XESS_RESULT_SUCCESS, "xessDestroyContext() failed!"); + if (m.xess->context) { + xess_result_t result = xessDestroyContext(m.xess->context); + XessReportResult((DeviceBase&)m_Device, result, "xessDestroyContext"); + } const auto& allocationCallbacks = ((DeviceBase&)m_Device).GetAllocationCallbacks(); Destroy(allocationCallbacks, m.xess); @@ -1145,7 +1216,7 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { if (result != FFX_API_RETURN_OK) { NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "ffxCreateContext() failed, result = %d", (int32_t)result); - return Result::EXT_ERROR; + return FfxConvertError(result); } ffxQueryGetProviderVersion providerVersion = {}; @@ -1172,19 +1243,15 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { xess_result_t result = xessD3D12CreateContext(deviceNative, &m.xess->context); - if (result != XESS_RESULT_SUCCESS) { - NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "xessD3D12CreateContext() failed, result = %d", (int32_t)result); - - return Result::EXT_ERROR; - } + Result nriResult = XessReportResult((DeviceBase&)m_Device, result, "xessD3D12CreateContext"); + if (nriResult != Result::SUCCESS) + return nriResult; result = xessForceLegacyScaleFactors(m.xess->context, true); - if (result != XESS_RESULT_SUCCESS) { - NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "xessForceLegacyScaleFactors() failed, result = %d", (int32_t)result); - - return Result::EXT_ERROR; - } + nriResult = XessReportResult((DeviceBase&)m_Device, result, "xessForceLegacyScaleFactors"); + if (nriResult != Result::SUCCESS) + return nriResult; xess_quality_settings_t qualitySetting = XESS_QUALITY_SETTING_ULTRA_PERFORMANCE; if (upscalerDesc.mode == UpscalerMode::NATIVE) @@ -1226,29 +1293,23 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { result = xessD3D12BuildPipelines(m.xess->context, NULL, true, initParams.initFlags); - if (result != XESS_RESULT_SUCCESS) { - NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "xessD3D12BuildPipelines() failed, result = %d", (int32_t)result); - - return Result::EXT_ERROR; - } + nriResult = XessReportResult((DeviceBase&)m_Device, result, "xessD3D12BuildPipelines"); + if (nriResult != Result::SUCCESS) + return nriResult; result = xessD3D12Init(m.xess->context, &initParams); - if (result != XESS_RESULT_SUCCESS) { - NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "xessD3D12Init() failed, result = %d", (int32_t)result); - - return Result::EXT_ERROR; - } + nriResult = XessReportResult((DeviceBase&)m_Device, result, "xessD3D12Init"); + if (nriResult != Result::SUCCESS) + return nriResult; if (upscalerDesc.preset != 0) { xess_network_model_t preset = (xess_network_model_t)(upscalerDesc.preset - 1); result = xessSelectNetworkModel(m.xess->context, preset); - if (result != XESS_RESULT_SUCCESS) { - NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "xessSelectNetworkModel() failed, result = %d", (int32_t)result); - - return Result::EXT_ERROR; - } + nriResult = XessReportResult((DeviceBase&)m_Device, result, "xessSelectNetworkModel"); + if (nriResult != Result::SUCCESS) + return nriResult; } } # endif @@ -1320,7 +1381,7 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { if (ngxResult != NVSDK_NGX_Result_Success) { NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "NGX initialization failed, result = 0x%08X", (uint32_t)ngxResult); - return Result::EXT_ERROR; + return NgxConvertError(ngxResult); } // Create command buffer if not provided @@ -1471,7 +1532,7 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { if (ngxResult != NVSDK_NGX_Result_Success) { NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "NGX feature creation failed, result = 0x%08X", (uint32_t)ngxResult); - return Result::EXT_ERROR; + return NgxConvertError(ngxResult); } } #endif @@ -1682,13 +1743,12 @@ void UpscalerImpl::CmdDispatchUpscale(CommandBuffer& commandBuffer, const Dispat xess_result_t result = xessSetExposureMultiplier(m.xess->context, 1.0f / preExposure); - if (result != XESS_RESULT_SUCCESS) - NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "xessSetExposureMultiplier() failed, result = %d", (int32_t)result); + if (XessReportResult((DeviceBase&)m_Device, result, "xessSetExposureMultiplier") != Result::SUCCESS) + return; result = xessD3D12Execute(m.xess->context, commandList, &executeParams); - if (result != XESS_RESULT_SUCCESS) - NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "xessD3D12Execute() failed, result = %d", (int32_t)result); + XessReportResult((DeviceBase&)m_Device, result, "xessD3D12Execute"); } #endif From 395237f21955a2d4b455a520b67e0cc53a742b64 Mon Sep 17 00:00:00 2001 From: dzhdan Date: Thu, 12 Nov 2026 10:46:33 +0800 Subject: [PATCH 4/4] Fixed XeSS preset setup and optional diagnostics --- Include/Extensions/NRIDeviceCreation.h | 2 +- Source/D3D12/DeviceD3D12.hpp | 11 +++++++-- Source/Shared/UpscalerInterface.hpp | 32 ++++++++++++++++---------- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/Include/Extensions/NRIDeviceCreation.h b/Include/Extensions/NRIDeviceCreation.h index cdb4c7a9..d2cae2ef 100644 --- a/Include/Extensions/NRIDeviceCreation.h +++ b/Include/Extensions/NRIDeviceCreation.h @@ -36,7 +36,7 @@ NriStruct(AllocationCallbacks) { NriStruct(CallbackInterface) { void (NRI_CALL *MessageCallback)(Nri(Message) messageType, const char* file, uint32_t line, const char* message, void* userArg); - NriOptional void (NRI_CALL *AbortExecution)(void* userArg); // break on "Message::ERROR" if provided + NriOptional void (NRI_CALL *AbortExecution)(void* userArg); // called when reporting a positive "Result" NriOptional void* userArg; }; diff --git a/Source/D3D12/DeviceD3D12.hpp b/Source/D3D12/DeviceD3D12.hpp index 198fbbd5..fff5a6b9 100644 --- a/Source/D3D12/DeviceD3D12.hpp +++ b/Source/D3D12/DeviceD3D12.hpp @@ -714,8 +714,15 @@ Result DeviceD3D12::Create(const DeviceCreationDesc& desc, const DeviceCreationD if (status != NVAPI_OK) NRI_REPORT_WARNING(this, "Ray tracing validation is disabled, because 'NvAPI_D3D12_EnableRaytracingValidation()' failed, result = %d (requires envvar \"NV_ALLOW_RAYTRACING_VALIDATION=1\")", (int32_t)status); - else - NRI_REPORT_ERROR_ON_BAD_NVAPI_STATUS(this, NvAPI_D3D12_RegisterRaytracingValidationMessageCallback(m_Device, NvapiMessageCallback, this, &m_CallbackHandle)); + else { + void* callbackHandle = nullptr; + status = NvAPI_D3D12_RegisterRaytracingValidationMessageCallback(m_Device, NvapiMessageCallback, this, &callbackHandle); + + if (status == NVAPI_OK) + m_CallbackHandle = callbackHandle; + else + NRI_REPORT_WARNING(this, "NvAPI_D3D12_RegisterRaytracingValidationMessageCallback() failed, result = %d", (int32_t)status); + } // TODO: if enabled, call "NvAPI_D3D12_FlushRaytracingValidationMessages()" after each submit? present? DEVICE_LOST? } diff --git a/Source/Shared/UpscalerInterface.hpp b/Source/Shared/UpscalerInterface.hpp index 200cfc25..23d9af27 100644 --- a/Source/Shared/UpscalerInterface.hpp +++ b/Source/Shared/UpscalerInterface.hpp @@ -1253,6 +1253,15 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { if (nriResult != Result::SUCCESS) return nriResult; + if (upscalerDesc.preset != 0) { + xess_network_model_t preset = (xess_network_model_t)(upscalerDesc.preset - 1); + result = xessSelectNetworkModel(m.xess->context, preset); + + nriResult = XessReportResult((DeviceBase&)m_Device, result, "xessSelectNetworkModel"); + if (nriResult != Result::SUCCESS) + return nriResult; + } + xess_quality_settings_t qualitySetting = XESS_QUALITY_SETTING_ULTRA_PERFORMANCE; if (upscalerDesc.mode == UpscalerMode::NATIVE) qualitySetting = XESS_QUALITY_SETTING_AA; @@ -1302,15 +1311,6 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { nriResult = XessReportResult((DeviceBase&)m_Device, result, "xessD3D12Init"); if (nriResult != Result::SUCCESS) return nriResult; - - if (upscalerDesc.preset != 0) { - xess_network_model_t preset = (xess_network_model_t)(upscalerDesc.preset - 1); - result = xessSelectNetworkModel(m.xess->context, preset); - - nriResult = XessReportResult((DeviceBase&)m_Device, result, "xessSelectNetworkModel"); - if (nriResult != Result::SUCCESS) - return nriResult; - } } # endif } @@ -1575,12 +1575,20 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { return Result::OUT_OF_MEMORY; // Scalers are created on the first dispatch, because resource formats are unknown here + NS::AutoreleasePool* autoreleasePool = NS::AutoreleasePool::alloc()->init(); + NS::Error* error = nullptr; MTL4::CompilerDescriptor* compilerDesc = MTL4::CompilerDescriptor::alloc()->init(); - m.metalfx->compiler = deviceNative->newCompiler(compilerDesc, nullptr); + m.metalfx->compiler = deviceNative->newCompiler(compilerDesc, &error); compilerDesc->release(); - if (!m.metalfx->compiler) - return Result::FAILURE; + if (!m.metalfx->compiler) { + NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "MetalFX compiler creation failed: %s", error ? error->localizedDescription()->utf8String() : "unknown error"); + autoreleasePool->release(); + + return Result::EXT_ERROR; + } + + autoreleasePool->release(); } #endif