d3d12: Hook up driver-private interop data

Reviewed-by: Adam Jackson <ajax@redhat.com>
Acked-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19242>
This commit is contained in:
Jesse Natalie 2022-10-21 15:57:49 -07:00 committed by Marge Bot
parent 20bdec1fc4
commit 7221cc6526
2 changed files with 84 additions and 0 deletions

View file

@ -0,0 +1,52 @@
/*
* Copyright © Microsoft Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include <stdint.h>
#ifndef D3D12_INTEROP_PUBLIC_H
#define D3D12_INTEROP_PUBLIC_H
#ifdef __cplusplus
extern "C" {
#endif
struct ID3D12Device;
struct ID3D12CommandQueue;
struct ID3D12Resource;
struct d3d12_interop_device_info {
uint64_t adapter_luid;
ID3D12Device *device;
ID3D12CommandQueue *queue;
};
struct d3d12_interop_resource_info {
ID3D12Resource *resource;
uint64_t buffer_offset;
};
#ifdef __cplusplus
}
#endif
#endif /* D3D12_INTEROP_PUBLIC_H */

View file

@ -32,6 +32,7 @@
#include "d3d12_video_screen.h"
#endif
#include "d3d12_format.h"
#include "d3d12_interop_public.h"
#include "d3d12_residency.h"
#include "d3d12_resource.h"
#include "d3d12_nir_passes.h"
@ -1143,6 +1144,35 @@ d3d12_set_fence_timeline_value(struct pipe_screen *pscreen, struct pipe_fence_ha
d3d12_fence(pfence)->value = value;
}
static uint32_t
d3d12_interop_query_device_info(struct pipe_screen *pscreen, uint32_t data_size, void *data)
{
if (data_size < sizeof(d3d12_interop_device_info) || !data)
return 0;
d3d12_interop_device_info *info = (d3d12_interop_device_info *)data;
struct d3d12_screen *screen = d3d12_screen(pscreen);
static_assert(sizeof(info->adapter_luid) == sizeof(screen->adapter_luid),
"Using uint64_t instead of Windows-specific type");
memcpy(&info->adapter_luid, &screen->adapter_luid, sizeof(screen->adapter_luid));
info->device = screen->dev;
info->queue = screen->cmdqueue;
return sizeof(*info);
}
static uint32_t
d3d12_interop_export_object(struct pipe_screen *pscreen, struct pipe_resource *res,
uint32_t data_size, void *data, bool *need_export_dmabuf)
{
if (data_size < sizeof(d3d12_interop_resource_info) || !data)
return 0;
d3d12_interop_resource_info *info = (d3d12_interop_resource_info *)data;
info->resource = d3d12_resource_underlying(d3d12_resource(res), &info->buffer_offset);
*need_export_dmabuf = false;
return sizeof(*info);
}
bool
d3d12_init_screen_base(struct d3d12_screen *screen, struct sw_winsys *winsys, LUID *adapter_luid)
{
@ -1174,6 +1204,8 @@ d3d12_init_screen_base(struct d3d12_screen *screen, struct sw_winsys *winsys, LU
screen->base.get_device_node_mask = d3d12_get_node_mask;
screen->base.create_fence_win32 = d3d12_create_fence_win32;
screen->base.set_fence_timeline_value = d3d12_set_fence_timeline_value;
screen->base.interop_query_device_info = d3d12_interop_query_device_info;
screen->base.interop_export_object = d3d12_interop_export_object;
screen->d3d12_mod = util_dl_open(UTIL_DL_PREFIX "d3d12" UTIL_DL_EXT);
if (!screen->d3d12_mod) {