Skip to content

Commit ddd1579

Browse files
Nullpoint56claude
andcommitted
NriExternalException for EXT_ERROR: a failed third-party call, to fall back on
NRI v192 returns Result::EXT_ERROR when a library it calls fails (an upscaler SDK, Reflex) and the device stays usable. It now has its own type beside NriDeviceLostException and NriUnsupportedException, derived from NriException, so a caller catches it by type; the message still carries the vendor call and code NRI reported. InteropTests holds the mapping, and UpscalerFailureTests holds NRI's real EXT_ERROR (a missing FSR or DLSS runtime) to it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NvXTk6Roe4sQLHFx9Zykv8
1 parent 404ef97 commit ddd1579

6 files changed

Lines changed: 46 additions & 6 deletions

File tree

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ L0 dotnet/Native/ ClangSharp output. Never referenced above L1 except des
9595
- L1 does four things a generator cannot: `InterfaceTable.Acquire<T>` (size check; `UNSUPPORTED` ->
9696
`NriUnsupportedException`, a capability answer); `Result` -> `NriException` with the call name and
9797
the error text reported on the calling thread since the previous check there (`DEVICE_LOST`,
98-
`UNSUPPORTED` get own types; Device creation and callbacks); `[UnmanagedCallersOnly]` thunks for
98+
`UNSUPPORTED` get own types, `NriExternalException` for `EXT_ERROR`; Device creation and callbacks); `[UnmanagedCallersOnly]` thunks for
9999
`CallbackInterface` and `AllocationCallbacks` recovering the receiver from a `GCHandle` in
100100
`userArg` (no managed exception crosses a native frame: a throwing handler loses that message, a
101101
throwing allocator returns null; bridges outlive the native device until `nriDestroyDevice`

‎docs/guide.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ ref readonly DeviceDesc caps = ref device.Desc;
169169
|---|---|
170170
| `NriDeviceOptions` | mirrors `DeviceCreationDesc` field for field |
171171
| `QueueFamilies` | empty means one graphics queue. Request every family up front: NRI trims the device's queue counts to what was created, so `Video` is `UNSUPPORTED` unless `VIDEO_DECODE` / `VIDEO_ENCODE` were requested |
172-
| `MessageHandler` | receives NRI and validation-layer messages. A throwing handler loses that one message. An `NriException` (and `NriDeviceLostException`, `NriUnsupportedException`) carries the last error text reported on its own thread since the binding last checked a result there: the failing call's own, or that of a refused `Cmd*` before it (those return nothing, so nothing checks them); never another thread's, and none when nothing was reported; `device.LastError` holds the device's last error text, from any thread. A Khronos layer message arrives as `[id] name: text` (patch 0015 adds the name, e.g. `BestPractices-vkBindImageMemory-small-dedicated-allocation`; upstream forwards the number and the text, and current layers no longer embed the name in the text) |
172+
| `MessageHandler` | receives NRI and validation-layer messages. A throwing handler loses that one message. An `NriException` (and `NriDeviceLostException`, `NriUnsupportedException`, `NriExternalException`) carries the last error text reported on its own thread since the binding last checked a result there: the failing call's own, or that of a refused `Cmd*` before it (those return nothing, so nothing checks them); never another thread's, and none when nothing was reported; `device.LastError` holds the device's last error text, from any thread. A Khronos layer message arrives as `[id] name: text` (patch 0015 adds the name, e.g. `BestPractices-vkBindImageMemory-small-dedicated-allocation`; upstream forwards the number and the text, and current layers no longer embed the name in the text) |
173173
| `BreakOnError` | breaks only when a debugger is attached; otherwise errors never terminate the process. Also decides the D3D12 debug layer's own break (`SetBreakOnSeverity` for ERROR and CORRUPTION), evaluated at device creation: on only with `BreakOnError` and a debugger attached then. Otherwise a D3D12 debug-layer error arrives as an error message, `[id] text` |
174174
| `EnableD3D12GpuBasedValidation` | D3D12 GPU-based validation: checks descriptors and resource states while shaders run. Slow; needs `EnableGraphicsApiValidation`. Process-global and never switched off: every D3D12 device created later in the process has it |
175175
| `Allocator` | `INriAllocator` for NRI's own host allocations; `NriCountingAllocator` counts them. It must not fail: a null (a throwing allocator returns one) fails an NRI object's creation with `OUT_OF_MEMORY`, but NRI's containers allocate through it too and crash on one, device creation's first allocation among them |
@@ -741,9 +741,9 @@ if (up.IsUpscalerSupported(UpscalerType.FSR) && up.IsRuntimeInstalled(UpscalerTy
741741
makes both hosts work. Put the files beside your app's assembly.
742742
- XeSS: D3D12 only. FSR: D3D12 and Vulkan. NIS: everywhere the Upscalers build runs. DLSR and
743743
DLRR (a `-WithDlss` build): NVIDIA adapters with ray tracing, both backends.
744-
- A failed vendor call reports an ERROR through your message handler. A failed creation throws `NriException`
745-
with `Result.EXT_ERROR` (NRI's result for a third-party failure, which never calls
746-
`AbortExecution`), or `INVALID_ARGUMENT`, `UNSUPPORTED` or `OUT_OF_MEMORY` when the vendor's code
744+
- A failed vendor call reports an ERROR through your message handler. A failed creation throws `NriExternalException`
745+
(`Result.EXT_ERROR`, NRI's result for a third-party failure, which never calls
746+
`AbortExecution`; catch it to fall back), or `NriUnsupportedException` or an `NriException` with `INVALID_ARGUMENT` or `OUT_OF_MEMORY` when the vendor's code
747747
says so; never a bare `FAILURE`. A failed dispatch returns nothing (a command). At creation the message
748748
names the missing FSR loader DLL or the NGX result, at dispatch the vendor call and its result
749749
(`ffxDispatch`, `xessD3D12Execute`, NGX's evaluation). DLSS may create without its DLL

‎docs/releases/v192.0.0-beta.1.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
## Added
22
- NRI v192
33
- `Nri.BindingVersion`, `Nri.DescsVersion`, `Nri.BindingNriVersion`, `Nri.DescsNriVersion`: the loaded packages' versions, read at run time
4+
- `NriExternalException`: a failed third-party call (`Result.EXT_ERROR`: an upscaler SDK, NVIDIA Reflex), for falling back
45
- D3D12: a refused pipeline cache reports why as an INFO (another driver version, another adapter, not a pipeline library); still `OUT_OF_DATE`
56

67
## Fixed
7-
- A failed vendor upscaler creation throws with `EXT_ERROR` (or `INVALID_ARGUMENT`, `UNSUPPORTED`, `OUT_OF_MEMORY` when the vendor's code says so) and reports an ERROR naming the call; a failed dispatch reports one too
8+
- A failed vendor upscaler creation throws `NriExternalException` (or `NriUnsupportedException`, or `NriException` with `INVALID_ARGUMENT` or `OUT_OF_MEMORY`, when the vendor's code says so) and reports an ERROR naming the call; a failed dispatch reports one too
89
- D3D12 device creation with the debug layer: no `[989]` `CheckFeatureSupport` warnings
910
- D3D12 debug layer: no warnings `[963]`, `[964]`, `[971]` for a pipeline not yet in the cache or a cache from another driver or adapter
1011
- An application's `ResolvingUnmanagedDll` handler for "NRI" runs whenever it was registered (SharpNRI's own handler threw and ended the chain); a missing NRI library is explained at device creation and adapter enumeration

‎dotnet/Interop/NriException.cs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ internal static NriException For(Result result, string call)
6363
{
6464
Result.DEVICE_LOST => new NriDeviceLostException(call, detail),
6565
Result.UNSUPPORTED => new NriUnsupportedException(call, detail),
66+
Result.EXT_ERROR => new NriExternalException(call, detail),
6667
_ => new NriException(result, call, detail),
6768
};
6869
}
@@ -83,3 +84,14 @@ public sealed class NriDeviceLostException(string call, string? detail = null)
8384
/// </summary>
8485
public sealed class NriUnsupportedException(string call, string? detail = null)
8586
: NriException(Result.UNSUPPORTED, call, detail);
87+
88+
/// <summary>
89+
/// A third-party library NRI calls failed (<c>Result.EXT_ERROR</c>): an upscaler SDK (FSR, XeSS,
90+
/// DLSS, a missing or outdated runtime among the causes) or NVIDIA Reflex. The device is still
91+
/// usable, so this is the point to fall back, for example to another upscaler. The message names the
92+
/// vendor call and its code, as NRI reported it; the code itself is not available as a value. A vendor
93+
/// failure whose code means unsupported, an invalid argument or out of memory arrives as
94+
/// <see cref="NriUnsupportedException"/> or an <see cref="NriException"/> with that result instead.
95+
/// </summary>
96+
public sealed class NriExternalException(string call, string? detail = null)
97+
: NriException(Result.EXT_ERROR, call, detail);

‎tests/SharpNRI.Tests/InteropTests.cs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,28 @@ private static bool HasDeviceExtension(VkInstanceApi instanceApi, VkPhysicalDevi
540540

541541
private static void Check(VkResult result, string call) => Assert.True(result == VkResult.Success, $"{call}: {result}");
542542

543+
/// <summary>
544+
/// A failed third-party call (NRI's <c>EXT_ERROR</c>) is an <see cref="NriExternalException"/>,
545+
/// still an <see cref="NriException"/> with its result, carrying the text NRI reported on the thread
546+
/// (the vendor call and its code); <c>DEVICE_LOST</c> and <c>UNSUPPORTED</c> keep their own types and
547+
/// every other result stays a plain <see cref="NriException"/>. The NRI side, a missing vendor
548+
/// runtime answered with <c>EXT_ERROR</c>, is <see cref="UpscalerFailureTests"/>.
549+
/// </summary>
550+
[Fact]
551+
public void EXT_ERROR_is_an_NriExternalException_carrying_the_reported_text()
552+
{
553+
NriException.Reported("nri::UpscalerImpl::Create(): 'amd_fidelityfx_loader_vk.dll' can't be loaded");
554+
var e = NriException.For(Result.EXT_ERROR, "CreateUpscaler");
555+
var external = Assert.IsType<NriExternalException>(e);
556+
Assert.Equal(Result.EXT_ERROR, external.Result);
557+
Assert.Equal("CreateUpscaler", external.Call);
558+
Assert.Equal("CreateUpscaler: EXT_ERROR — nri::UpscalerImpl::Create(): 'amd_fidelityfx_loader_vk.dll' can't be loaded", external.Message);
559+
560+
Assert.IsType<NriDeviceLostException>(NriException.For(Result.DEVICE_LOST, "QueueSubmit"));
561+
Assert.IsType<NriUnsupportedException>(NriException.For(Result.UNSUPPORTED, "CreateUpscaler"));
562+
foreach (var other in new[] { Result.FAILURE, Result.INVALID_ARGUMENT, Result.OUT_OF_MEMORY, Result.OUT_OF_DATE, Result.INVALID_SDK, Result.NOT_READY })
563+
Assert.Equal(typeof(NriException), NriException.For(other, "Call").GetType());
564+
}
543565

544566
/// <summary>
545567
/// CreateQueryPoolVK maps the VkQueryType of a raw pool made on NRI's own VkDevice to the

‎tests/SharpNRI.Tests/UpscalerFailureTests.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ private static unsafe int Child()
146146
Console.WriteLine($"FAIL {api} {type}: {result} with no message saying why");
147147
failed = true;
148148
}
149+
if (result == Result.EXT_ERROR && NriException.For(result, "CreateUpscaler") is not NriExternalException)
150+
{
151+
Console.WriteLine($"FAIL {api} {type}: EXT_ERROR is not mapped to NriExternalException");
152+
failed = true;
153+
}
149154
if (result == Result.FAILURE || (type == UpscalerType.FSR && result != Result.EXT_ERROR))
150155
{
151156
Console.WriteLine($"FAIL {api} {type}: {result}, expected EXT_ERROR for a missing vendor library{(type == UpscalerType.FSR ? "" : " or the vendor's mapped result")}");

0 commit comments

Comments
 (0)