Search code examples
direct3d11on12

D3D11On12Device::CreateWrappedResource method E_INVALIDARG


I'm getting E_INVALIDARG An invalid parameter was passed to the returning function.

The docs https://learn.microsoft.com/en-us/windows/win32/api/d3d11on12/nf-d3d11on12-id3d11on12device-createwrappedresource however, don't mention anything about the preconditions or the error/return codes.


Solution

  • You need to create pResource12 with D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET it seems

    auto desc = CD3DX12_RESOURCE_DESC::Tex2D(
        DXGI_FORMAT_R8G8B8A8_UNORM, width, height);
    desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
    

    Edit: I was parsing in these flags D3D11On12Device::CreateWrappedResource so obviously the DirectX12 resource needed the same flags

    D3D11_RESOURCE_FLAGS d3d11Flags = { .BindFlags = D3D11_BIND_RENDER_TARGET };