最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++ - DirectX 11 Resource sharing from UMD - Stack Overflow

programmeradmin4浏览0评论

I'm developing a User Mode Driver (UMD) based on the Microsoft Indirect Display Driver Sample and want to share a D3D11 texture with real-time user-mode processes. However, when a client process tries to open the shared resource, OpenSharedResource fails with E_INVALIDARG.

I've tried

  • Ensured both the UMD and client use the same GPU adapter.
  • Ensured the handle was valid and had value.
  • CreateSharedHandle & OpenSharedResource1 vs GetSharedHandle & OpenSharedResource.
  • desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED | D3D11_RESOURCE_MISC_SHARED_NTHANDLE;
  • Converting the handle to UINT64 for 64-bit architecture.
  • The same code works on two regular processes

UMD Side - Sharing a Texture

HANDLE hPipe = CreateNamedPipeW(
    L"\\\\.\\pipe\\MyD3DSharedHandlePipe",
    PIPE_ACCESS_OUTBOUND,    
    PIPE_TYPE_BYTE | PIPE_WAIT,
    PIPE_UNLIMITED_INSTANCES,
    512, 512, 0, nullptr
);

D3D11_TEXTURE2D_DESC desc = {};
//...
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.SampleDesc.Count = 1;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED;

ComPtr<ID3D11Texture2D> _SharedTexture;
HRESULT hr = _Device->CreateTexture2D(&desc, nullptr, &_SharedTexture);

ComPtr<IDXGIResource> sharedResource;
_SharedTexture.As(&sharedResource);

HANDLE sharedHandle = nullptr;
hr = sharedResource->GetSharedHandle(&sharedHandle);
//Tried UINT64 as well.
BOOL written = WriteFile(hPipe, &sharedHandle, sizeof(sharedHandle), &bytesWritten, nullptr);

Client Side

ComPtr<ID3D11Texture2D> sharedTex;
HRESULT hr = device->OpenSharedResource(
    sharedHandle,
    __uuidof(ID3D11Texture2D),
    reinterpret_cast<void**>(sharedTex.GetAddressOf())
);

Is it possible at all to share a D3D11 texture from a UMD to regular user-mode processes?

发布评论

评论列表(0)

  1. 暂无评论