beeradmoore/dlss-swapper · error · Exception

Failed to get version count. Return code

Error message

Failed to get version count. Return code: {returnCode}

What it means

After obtaining the ffxQuery delegate, GetVersions calls it with a QueryDescGetVersions to first learn how many upscaler versions exist. If the native call returns anything other than FFX_API_RETURN_OK, the helper throws this exception embedding the return code. It means the FidelityFX API rejected the version-count query itself.

Solutions

  1. Log/decode the returned FfxApiReturnCodes value and look it up in the FFX API headers to identify the exact failure.
  2. Confirm the loaded amd_fidelityfx DLL/driver version supports FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE queries.
  3. Verify QueryDescGetVersions struct layout and field marshaling match the SDK header version in use.
  4. Update GPU drivers and the FidelityFX SDK runtime to matching versions.

Example fix

// before
var returnCode = ffxQuery(IntPtr.Zero, ref versionQuery);
if (returnCode != FfxApiReturnCodes.FFX_API_RETURN_OK) throw new Exception($"Failed to get version count. Return code: {returnCode}");
// after
var returnCode = ffxQuery(IntPtr.Zero, ref versionQuery);
if (returnCode != FfxApiReturnCodes.FFX_API_RETURN_OK)
    throw new Exception($"Failed to get version count. Return code: {returnCode} ({DescribeFfxReturnCode(returnCode)}). DLL/driver may not support the upscale query.");
Defensive patterns

Strategy: try-catch

Validate before calling

// before calling, confirm the loaded SDK supports the query
if (!IsFfxUpscaleQuerySupported(loadedSdkVersion))
    throw new NotSupportedException("Loaded FidelityFX runtime does not support the upscale version query.");

Type guard

bool IsOk(FfxApiReturnCodes code) => code == FfxApiReturnCodes.FFX_API_RETURN_OK;

Try / catch

try
{
    GetVersions();
}
catch (Exception ex) when (ex.Message.StartsWith("Failed to get version count"))
{
    // decode return code from message, fall back to a default/known version list
}

Prevention

When it happens

Trigger: ffxQuery(IntPtr.Zero, ref versionQuery) returns a non-OK FfxApiReturnCodes value — e.g. the createDescType is not supported by the loaded backend (FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE unsupported), the descriptor struct layout is wrong for the loaded SDK version, or no FSR backend/context is available.

Common situations: Driver or FidelityFX runtime too old to support the upscale query; struct marshaling mismatch after an SDK upgrade changed QueryDescGetVersions layout; calling before any FSR context was ever created on a backend that requires it.

Related errors


AI-assisted analysis of beeradmoore/dlss-swapper@ab9b1e2d4b (2026-09-15). Data as JSON: /api/errors/49120ed00dd0d250. Report an issue: GitHub.

Appendix: source

Thrown at src/Helpers/FSR31/FSR31Helper.cs:73

            versionQuery.createDescType = FxxConsts.FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE;

            // versionQuery.device = GetDX12Device(); // only for DirectX 12 applications
            versionQuery.device = IntPtr.Zero;

            // uint64_t versionCount = 0;
            UInt64 versionCount = 0;
            versionQuery.outputCount = Marshal.AllocHGlobal(sizeof(UInt64));
            Marshal.WriteInt64(versionQuery.outputCount, (UInt32)versionCount);

            Logger.Info("AMDFidelityFXAPI - Reading version count");
            // get number of versions for allocation
            // ffxQuery(IntPtr.Zero, &versionQuery.header);
            var returnCode = ffxQuery(IntPtr.Zero, ref versionQuery);
            Logger.Info($"AMDFidelityFXAPI - returnCode: {returnCode}");

            if (returnCode != FfxApiReturnCodes.FFX_API_RETURN_OK)
            {
                throw new Exception($"Failed to get version count. Return code: {returnCode}");
            }

            versionCount = (UInt64)Marshal.ReadInt64(versionQuery.outputCount);
            Logger.Info($"AMDFidelityFXAPI - versionCount: {versionCount}");

            if (versionCount > 0)
            {
                var versionCountInt = (int)versionCount;

                //std::vector <const char*> versionNames;
                //std::vector<uint64_t> versionIds;
                //m_FsrVersionIds.resize(versionCount);
                //versionNames.resize(versionCount);
                var versionNames = new List<string?>(versionCountInt);
                var versionIds = new List<UInt64>(versionCountInt);

                var versionNamesPtrs = new IntPtr[versionCountInt];
                var versionIdsPtrs = new IntPtr[versionCountInt];

View on GitHub (pinned to ab9b1e2d4b)