d3d12: resource_from_handle to validate importing resource ptr from same d3d12 device
Reviewed-by: Jesse Natalie <jenatali@microsoft.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19063>
This commit is contained in:
@@ -41,6 +41,9 @@
|
||||
#include <dxguids/dxguids.h>
|
||||
#include <memory>
|
||||
|
||||
#include <wrl/client.h>
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
#ifndef GENERIC_ALL
|
||||
// This is only added to winadapter.h in newer DirectX-Headers
|
||||
#define GENERIC_ALL 0x10000000L
|
||||
@@ -449,6 +452,32 @@ d3d12_resource_from_handle(struct pipe_screen *pscreen,
|
||||
HANDLE d3d_handle = (HANDLE) (intptr_t) handle->handle;
|
||||
#endif
|
||||
|
||||
if (handle->type == WINSYS_HANDLE_TYPE_D3D12_RES) {
|
||||
ComPtr<IUnknown> screen_device;
|
||||
ComPtr<IUnknown> res_device;
|
||||
screen->dev->QueryInterface(screen_device.GetAddressOf());
|
||||
((ID3D12DeviceChild *)handle->com_obj)->GetDevice(IID_PPV_ARGS(res_device.GetAddressOf()));
|
||||
|
||||
if (screen_device.Get() != res_device.Get()) {
|
||||
debug_printf("d3d12: Importing resource - Resource's parent device (%p) does not"
|
||||
" match d3d12 device (%p) instance from this pipe_screen."
|
||||
" Attempting to re-import via NT Handle...\n", screen_device.Get(), res_device.Get());
|
||||
|
||||
handle->type = WINSYS_HANDLE_TYPE_FD;
|
||||
HRESULT hr = screen->dev->CreateSharedHandle(((ID3D12DeviceChild *)handle->com_obj),
|
||||
nullptr,
|
||||
GENERIC_ALL,
|
||||
nullptr,
|
||||
&d3d_handle);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
debug_printf("d3d12: Error %x - Couldn't export incoming resource com_obj "
|
||||
"(%p) via shared NT handle.\n", hr, handle->com_obj);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
HANDLE d3d_handle_to_close = nullptr;
|
||||
if (handle->type == WINSYS_HANDLE_TYPE_WIN32_NAME) {
|
||||
|
Reference in New Issue
Block a user