AvaloniaUI/Avalonia · error · ArgumentException

Not supported format

Error message

Not supported format

What it means

Thrown by D3DMemoryHelper.CreateMemoryHandle (ArgumentException) when the requested VulkanFormat is anything other than R8G8B8A8Unorm. The D3D11 shared texture is hardcoded to Format.FormatR8G8B8A8Unorm for the Vulkan/D3D memory-handle interop, so only that format is accepted.

Source

Thrown at samples/GpuInterop/VulkanDemo/D3DMemoryHelper.cs:74

        ComPtr<IDXGIAdapter> adapter = default;

        while (factory.EnumAdapters(index, adapter.GetAddressOf()) != DxgiErrorNotFound)
        {
            AdapterDesc adapterDesc;
            if (adapter.GetDesc(&adapterDesc) == 0 & AreLuidsEqual(adapterDesc.AdapterLuid, luid))
                return adapter;

            adapter.Dispose();
            ++index;
        }

        throw new ArgumentException("Device with the corresponding LUID not found");
    }

    public static unsafe ComPtr<ID3D11Texture2D> CreateMemoryHandle(ComPtr<ID3D11Device> device, PixelSize size, VulkanFormat format)
    {
        if (format != VulkanFormat.R8G8B8A8Unorm)
            throw new ArgumentException("Not supported format");

        ComPtr<ID3D11Texture2D> texture = default;
        var textureDesc = new Texture2DDesc
        {
            Format = Format.FormatR8G8B8A8Unorm,
            Width = (uint)size.Width,
            Height = (uint)size.Height,
            ArraySize = 1,
            MipLevels = 1,
            SampleDesc = new SampleDesc(1, 0),
            Usage = Usage.Default,
            BindFlags = (uint)(BindFlag.RenderTarget | BindFlag.ShaderResource),
            CPUAccessFlags = 0,
            MiscFlags = (uint)(ResourceMiscFlag.SharedKeyedmutex | ResourceMiscFlag.SharedNthandle)
        };
        ThrowHResult(device.CreateTexture2D(&textureDesc, (SubresourceData*)null, texture.GetAddressOf()));

        return texture;

View on GitHub (pinned to 11c5427268)

Solutions

  1. Convert/rendezvous the source data to VulkanFormat.R8G8B8A8Unorm before calling CreateMemoryHandle.
  2. If BGRA is required, swizzle the pixels to RGBA8 or extend the helper to support FormatR8G8B8A8->BGRA mapping.
  3. Validate the format at the call site and surface a clear message instead of letting the interop throw.

Example fix

// before
var handle = D3DMemoryHelper.CreateMemoryHandle(device, size, VulkanFormat.B8G8R8A8Unorm); // throws

// after
var handle = D3DMemoryHelper.CreateMemoryHandle(device, size, VulkanFormat.R8G8B8A8Unorm);
Defensive patterns

Strategy: validation

Validate before calling

if (format != VulkanFormat.R8G8B8A8Unorm) { /* convert source to RGBA8 before calling */ }

Type guard

static bool IsSupportedInteropFormat(VulkanFormat f) => f == VulkanFormat.R8G8B8A8Unorm;

Try / catch

try { return D3DMemoryHelper.CreateMemoryHandle(device, size, format); }
catch (ArgumentException ex) when (ex.Message.Contains("Not supported format")) { /* swizzle to RGBA8 and retry */ throw; }

Prevention

When it happens

Trigger: Calling CreateMemoryHandle(device, size, format) with format != VulkanFormat.R8G8B8A8Unorm (e.g. BGRA, RGB, compressed, or HDR formats). Any other format is rejected before the texture is created.

Common situations: Rendering pipeline configured for BGRA8 (common on Windows) but the interop expects RGBA8; passing a swapchain/surface format directly; HDR or 10-bit format requested for the shared handle.

Related errors


AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13). Data as JSON: /api/errors/83497e7c8a338aa8. Report an issue: GitHub.