I try to create new ID3D11Texture2D for map it to DXGI_MAPPED_RECT further.
I receive some ID3D11Texture2D that I have no power on (can not change way of creation of).
Here is the part of the code:
CComPtr<IDXGIResource> cpDXGIResource;
RET_HR_NULL(_pTexIn->QueryInterface(__uuidof(IDXGIResource), (void**)&cpDXGIResource), cpDXGIResource);
HANDLE sharedHandle;
cpDXGIResource->GetSharedHandle(&sharedHandle);
CComPtr<ID3D11Texture2D> cpTexIn;
cpD3D11Device->OpenSharedResource(sharedHandle, __uuidof(ID3D11Resource), (void**)(&cpTexIn));
D3D11_TEXTURE2D_DESC td;
cpTexIn->GetDesc(&td);
td.Usage = D3D11_USAGE_STAGING;
td.BindFlags = D3D11_BIND_SHADER_RESOURCE;
td.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
CComPtr<ID3D11Texture2D> cpNewTexture;
RET_HR_NULL(cpD3D11Device->CreateTexture2D(&td, NULL, &cpNewTexture), cpNewTexture);
cpD3D11DeviceContext->CopyResource(cpNewTexture, cpTexIn);
CComPtr<IDXGISurface> cpDXGISurface;
RET_HR_NULL(cpNewTexture->QueryInterface(&cpDXGISurface), cpDXGISurface);
DXGI_MAPPED_RECT bitmap2Dmap;
RET_HR(cpDXGISurface->Map(&bitmap2Dmap, DXGI_MAP_READ));
_pTexIn
is an input ID3D11Texture2D.
I get the error below while CreateTexture2D()
:
D3D11 ERROR: ID3D11Device::CreateTexture2D: A D3D11_USAGE_STAGING Resource cannot be shared via D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX or D3D11_RESOURCE_MISC_SHARED. [ STATE_CREATION ERROR #103: CREATETEXTURE2D_INVALIDMISCFLAGS]
Here is content of D3D11_TEXTURE2D_DESC:
Width 0x00000354 unsigned int
Height 0x000001e0 unsigned int
MipLevels 0x00000001 unsigned int
ArraySize 0x00000001 unsigned int
Format DXGI_FORMAT_B8G8R8A8_UNORM (0x00000057) DXGI_FORMAT
SampleDesc {Count=0x00000001 Quality=0x00000000 } DXGI_SAMPLE_DESC
Usage D3D11_USAGE_STAGING (0x00000003) D3D11_USAGE
BindFlags 0x00000008 unsigned int
CPUAccessFlags 0x00020000 unsigned int
MiscFlags 0x00000002 unsigned int
It is exactly what the debug layer says
A D3D11_USAGE_STAGING Resource cannot be shared via D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX or D3D11_RESOURCE_MISC_SHARED. [ STATE_CREATION ERROR #103: CREATETEXTURE2D_INVALIDMISCFLAGS]
meaning that if you need to have both sharing and staging capabilities, you need to have two separate textures created on one device. One will be shareable and the other one will be staging, you will copy data from one to another following the logic of your data flow. You cannot have staging sharable texture by design.
User contributions licensed under CC BY-SA 3.0