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/Include/NRIDescs.h b/Include/NRIDescs.h index a6686a5b..dc4c77b4 100644 --- a/Include/NRIDescs.h +++ b/Include/NRIDescs.h @@ -110,6 +110,7 @@ NriBits(GraphicsAPI, uint8_t, NriEnum(Result, int8_t, // All bad, but optionally require an action ("callbackInterface.AbortExecution" is not triggered) + 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 diff --git a/Source/D3D11/DescriptorD3D11.hpp b/Source/D3D11/DescriptorD3D11.hpp index ee99e522..39819523 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_FAILURE(&m_Device, status == NVAPI_OK, Result::FAILURE, "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..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_FAILURE(this, result == AGS_SUCCESS, Result::FAILURE, "agsDriverExtensionsDX11_CreateDevice() returned %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; @@ -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..fff5a6b9 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_FAILURE(this, result == AGS_SUCCESS, Result::FAILURE, "agsDriverExtensionsDX12_CreateDevice() failed, result = %d", (int32_t)result); deviceTemp = agsParams.pDevice; isShaderAtomicsI64Supported = agsParams.extensionsSupported.intrinsics19; @@ -711,8 +711,18 @@ 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) - NRI_REPORT_ERROR_ON_BAD_NVAPI_STATUS(this, NvAPI_D3D12_RegisterRaytracingValidationMessageCallback(m_Device, NvapiMessageCallback, this, &m_CallbackHandle)); + + 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 { + 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? } @@ -1339,8 +1349,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 +1398,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..049464dd 100644 --- a/Source/Shared/SharedExternal.h +++ b/Source/Shared/SharedExternal.h @@ -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 5d391d37..23d9af27 100644 --- a/Source/Shared/UpscalerInterface.hpp +++ b/Source/Shared/UpscalerInterface.hpp @@ -213,10 +213,11 @@ static inline Result FfxConvertError(ffxReturnCode_t code) { 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; } - - return Result::FAILURE; } static inline FfxApiSurfaceFormat FfxConvertFormat(Format format) { @@ -367,25 +368,36 @@ struct XessGlobals { } g_xess; static inline Result XessConvertError(xess_result_t code) { + if (code >= XESS_RESULT_SUCCESS) + return Result::SUCCESS; + switch (code) { - case XESS_RESULT_WARNING_NONEXISTING_FOLDER: - case XESS_RESULT_WARNING_OLD_DRIVER: + 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_SUCCESS: - return Result::SUCCESS; - 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::FAILURE; + 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 //===================================================================================================================================== @@ -437,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++) @@ -718,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); @@ -1081,8 +1116,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) - return Result::FAILURE; + + if (!ffxLibrary) { + NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "'%s' can't be loaded", libraryName); + + return Result::EXT_ERROR; + } // Get functions m.ffx->library = ffxLibrary; @@ -1091,8 +1130,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) - return Result::FAILURE; + if (!m.ffx->CreateContext || !m.ffx->DestroyContext || !m.ffx->Dispatch || !m.ffx->Query) { + NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "'%s' lacks an FFX API entry point", libraryName); + + return Result::EXT_ERROR; + } // Allocation callbacks m.ffx->allocationCallbacks.alloc = FfxAlloc; @@ -1170,8 +1212,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_EXT_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 +1242,25 @@ 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) - return XessConvertError(result); + + 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) - return XessConvertError(result); + + nriResult = XessReportResult((DeviceBase&)m_Device, result, "xessForceLegacyScaleFactors"); + 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) @@ -1242,19 +1301,16 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { initParams.visibleNodeMask = NODE_MASK; result = xessD3D12BuildPipelines(m.xess->context, NULL, true, initParams.initFlags); - if (result != XESS_RESULT_SUCCESS) - return XessConvertError(result); + + nriResult = XessReportResult((DeviceBase&)m_Device, result, "xessD3D12BuildPipelines"); + if (nriResult != Result::SUCCESS) + return nriResult; result = xessD3D12Init(m.xess->context, &initParams); - if (result != XESS_RESULT_SUCCESS) - 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) - return XessConvertError(result); - } + nriResult = XessReportResult((DeviceBase&)m_Device, result, "xessD3D12Init"); + if (nriResult != Result::SUCCESS) + return nriResult; } # endif } @@ -1322,8 +1378,11 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { # endif } - if (ngxResult != NVSDK_NGX_Result_Success) - return Result::FAILURE; + if (ngxResult != NVSDK_NGX_Result_Success) { + NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "NGX initialization failed, result = 0x%08X", (uint32_t)ngxResult); + + return NgxConvertError(ngxResult); + } // Create command buffer if not provided Queue* graphicsQueue = nullptr; @@ -1470,8 +1529,11 @@ Result UpscalerImpl::Create(const UpscalerDesc& upscalerDesc) { if (result != Result::SUCCESS) return result; - if (ngxResult != NVSDK_NGX_Result_Success) - return Result::FAILURE; + if (ngxResult != NVSDK_NGX_Result_Success) { + NRI_REPORT_EXT_ERROR(&(DeviceBase&)m_Device, "NGX feature creation failed, result = 0x%08X", (uint32_t)ngxResult); + + return NgxConvertError(ngxResult); + } } #endif @@ -1513,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 @@ -1653,8 +1723,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_EXT_ERROR(&(DeviceBase&)m_Device, "ffxDispatch() failed, result = %d", (int32_t)result); } #endif @@ -1679,11 +1750,13 @@ 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 (XessReportResult((DeviceBase&)m_Device, result, "xessSetExposureMultiplier") != Result::SUCCESS) + return; result = xessD3D12Execute(m.xess->context, commandList, &executeParams); - MaybeUnused(result); - NRI_CHECK(result == XESS_RESULT_SUCCESS, "xessD3D12Execute() failed!"); + + XessReportResult((DeviceBase&)m_Device, result, "xessD3D12Execute"); } #endif @@ -1754,7 +1827,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_EXT_ERROR(&(DeviceBase&)m_Device, "DLSR evaluation failed, result = 0x%08X", (uint32_t)result); } if (m_Desc.type == UpscalerType::DLRR) { @@ -1859,7 +1933,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_EXT_ERROR(&(DeviceBase&)m_Device, "DLRR evaluation failed, result = 0x%08X", (uint32_t)result); } #endif @@ -1880,7 +1955,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