D3D11On12 CreateWrappedResource fails

Levente Löffler 0 Reputation points
2023-03-27T20:48:21.4666667+00:00

I'm currently porting my D3D11 app to D3D12, and I found D3D11On12 very appealing for startes.
Right now my problem, which I for the life of me cannot figure out is this: I'm creating a texture resource in D3D12 as a commited resource, then I'm trying to wrap it with the ID3D11On12Device::CreateWrappedResource method, but it fails with error "ID3D12CompatibilityDevice::ReflectSharedProperties: Resource provided was not shared by D3D11, or with a D3D11 desc". Doing this exact same thing on swapchain buffers created with CreateSwapChainForHwnd and IDXGISwapChain::GetBuffer worked flawlessly. Am I missing something about how resources should be created? I tried the HEAP_FLAG_SHARED heap flag, but that didn't work either. Here is short version of the code:

// ...

D3D12_HEAP_PROPERTIES constexpr heapProps{
	.Type = D3D12_HEAP_TYPE_DEFAULT,
	.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN,
	.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN,
	.CreationNodeMask = 0,
	.VisibleNodeMask = 0
};

D3D12_RESOURCE_DESC const desc{
	.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D,
	.Alignment = 0,
	.Width = width,
	.Height = height,
	.DepthOrArraySize = 1,
	.MipLevels = 1,
	.Format = DXGI_FORMAT_R32G32B32A32_FLOAT,
	.SampleDesc = { .Count = 1, .Quality = 0 },
	.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN,
	.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET
};

ComPtr<ID3D12Resource> tex;

d3d12Device->CreateCommittedResource(&heapProps, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_RENDER_TARGET, &clearValue, IID_PPV_ARGS(tex.GetAddressOf());

// ...

D3D11_RESOURCE_FLAGS constexpr resourceFlags{
	.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE,
	.MiscFlags = 0,
	.CPUAccessFlags = 0,
	.StructureByteStride = 0
};

ComPtr<ID3D11Texture2D> wrappedTex;

d3d11On12Device->CreateWrappedResource(tex.Get(), &resourceFlags, D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_RENDER_TARGET, IID_PPV_ARGS(wrappedTex.GetAddressOf()); // This triggers the error
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,589 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Levente Löffler 0 Reputation points
    2023-04-03T05:40:39.88+00:00

    As I've said in the original post, I have already tried D3D12_HEAP_FLAG_SHARED with no success. The link you provided is about process interop between D3D11 and 12, and doesn't apply for D3D11On12. Anyway, I've moved on from D3D11On12 and now I'm porting directly to D3D12, as spending time debugging an underdocumented and uninformative interop API that I was eventually going to get rid of after completing the migration just doesn't make sense when I could spend that time on D3D12. Anyways, thank you for your time.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.