I try to write D2D/DWrite content into a texture that is to be used as shader resource in D3D12. For that, I create an ID3D11On12Device
as in , but I do not want to map the D3D12 back buffers, but create my own textures. The properties of the resources are:
D3D12_RESOURCE_DESC desc;
::ZeroMemory(&desc, sizeof(desc));
desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
desc.MipLevels = 1;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.DepthOrArraySize = 1;
desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS;
desc.SampleDesc.Count = 1;
D3D12_HEAP_PROPERTIES heapProps;
::ZeroMemory(&heapProps, sizeof(heapProps));
heapProps.Type = D3D12_HEAP_TYPE_DEFAULT;
And I create the textures as follows:
THROW_IF_FAILED(d3d12Device->CreateCommittedResource(
&heapProps,
D3D12_HEAP_FLAG_SHARED,
&desc,
D3D12_RESOURCE_STATE_ALL_SHADER_RESOURCE,
&clear,
::IID_ID3D12Resource,
this->d3d12Targets[i].put_void()));
I have D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS
and D3D12_HEAP_FLAG_SHARED
set as described in Sharing ID3D11Buffer and ID3D12Resource.
However, when I subsequently create the wrapped resource
D3D11_RESOURCE_FLAGS flags = { D3D11_BIND_RENDER_TARGET };
THROW_IF_FAILED(this->d3d11On12Device->CreateWrappedResource(
this->d3d12Targets[i].get(),
&flags,
D3D12_RESOURCE_STATE_RENDER_TARGET,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
::IID_ID3D11Resource,
this->d3d11Targets[i].put_void()));
I get the validation error
D3D12 ERROR: ID3D12CompatibilityDevice::ReflectSharedProperties: Resource provided was not shared by D3D11, or with a D3D11 desc. [ MISCELLANEOUS ERROR #916: REFLECTSHAREDPROPERTIES_INVALIDOBJECT]
What am I missing here?