d3d12: Add support for Xbox GDK.

The big items in this patch:
- New screen file, to support the Xbox "windowing" system
- Lots of small macros/changes to support the Xbox D3D12 API without messing with the Win32 path too much
- A few changes to avoid requiring COM interfaces (the big one was QueryInterface which is unsupported)

Co-authored-by: Ethan Lee <flibitijibibo@gmail.com>
Co-authored-by: David Jacewicz <david.jacewicz@protonmail.com>
Co-authored-by: tieuchanlong <tieuchanlong@gmail.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19022>
This commit is contained in:
Caleb Cornett
2023-01-11 12:28:34 -05:00
committed by Marge Bot
parent 882a78b8ad
commit 97061dd7ee
12 changed files with 296 additions and 22 deletions

View File

@@ -41,8 +41,10 @@
#include <dxguids/dxguids.h>
#include <memory>
#ifndef _GAMING_XBOX
#include <wrl/client.h>
using Microsoft::WRL::ComPtr;
#endif
#ifndef GENERIC_ALL
// This is only added to winadapter.h in newer DirectX-Headers
@@ -462,6 +464,7 @@ d3d12_resource_from_handle(struct pipe_screen *pscreen,
HANDLE d3d_handle = (HANDLE) (intptr_t) handle->handle;
#endif
#ifndef _GAMING_XBOX
if (handle->type == WINSYS_HANDLE_TYPE_D3D12_RES) {
ComPtr<IUnknown> screen_device;
ComPtr<IUnknown> res_device;
@@ -487,6 +490,7 @@ d3d12_resource_from_handle(struct pipe_screen *pscreen,
}
}
}
#endif
#ifdef _WIN32
HANDLE d3d_handle_to_close = nullptr;
@@ -501,10 +505,11 @@ d3d12_resource_from_handle(struct pipe_screen *pscreen,
if (res->bo) {
d3d12_res = res->bo->res;
} else if (handle->type == WINSYS_HANDLE_TYPE_D3D12_RES) {
IUnknown *obj = (IUnknown *)handle->com_obj;
(void)obj->QueryInterface(&d3d12_res);
(void)obj->QueryInterface(&d3d12_heap);
obj->Release();
if (handle->modifier == 1) {
d3d12_heap = (ID3D12Heap *) handle->com_obj;
} else {
d3d12_res = (ID3D12Resource *) handle->com_obj;
}
} else {
screen->dev->OpenSharedHandle(d3d_handle, IID_PPV_ARGS(&d3d12_res));
}
@@ -892,7 +897,12 @@ d3d12_memobj_create_from_handle(struct pipe_screen *pscreen, struct winsys_handl
}
struct d3d12_screen *screen = d3d12_screen(pscreen);
IUnknown *obj;
#ifdef _GAMING_XBOX
IGraphicsUnknown
#else
IUnknown
#endif
*obj;
#ifdef _WIN32
HANDLE d3d_handle = handle->handle;
#else
@@ -927,8 +937,13 @@ d3d12_memobj_create_from_handle(struct pipe_screen *pscreen, struct winsys_handl
}
memobj->base.dedicated = dedicated;
(void)obj->QueryInterface(&memobj->res);
(void)obj->QueryInterface(&memobj->heap);
obj->AddRef();
if (handle->modifier == 1) {
memobj->heap = (ID3D12Heap *) obj;
} else {
memobj->res = (ID3D12Resource *) obj;
}
obj->Release();
if (!memobj->res && !memobj->heap) {
debug_printf("d3d12: Memory object isn't a resource or heap\n");
@@ -969,6 +984,7 @@ d3d12_resource_from_memobj(struct pipe_screen *pscreen,
whandle.com_obj = memobj->res ? (void *) memobj->res : (void *) memobj->heap;
whandle.offset = offset;
whandle.format = templ->format;
whandle.modifier = memobj->res ? 0 : 1;
// WINSYS_HANDLE_TYPE_D3D12_RES implies taking ownership of the reference
((IUnknown *)whandle.com_obj)->AddRef();