mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-22 23:40:23 +01:00
d3d12: Autodetect d3d12_video_buffer imported handle/resource format and dimensions when not passed
Reviewed-by: Jesse Natalie <jenatali@microsoft.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26456>
This commit is contained in:
parent
3f43b2eae5
commit
bee68059cb
1 changed files with 36 additions and 6 deletions
|
|
@ -33,6 +33,8 @@
|
|||
#include "vl/vl_video_buffer.h"
|
||||
#include "util/u_sampler.h"
|
||||
#include "frontend/winsys_handle.h"
|
||||
#include "d3d12_format.h"
|
||||
#include "d3d12_screen.h"
|
||||
|
||||
static struct pipe_video_buffer *
|
||||
d3d12_video_buffer_create_impl(struct pipe_context *pipe,
|
||||
|
|
@ -119,17 +121,45 @@ failed:
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* creates a video buffer from a handle
|
||||
*/
|
||||
struct pipe_video_buffer *
|
||||
d3d12_video_buffer_from_handle( struct pipe_context *pipe,
|
||||
const struct pipe_video_buffer *tmpl,
|
||||
struct winsys_handle *handle,
|
||||
unsigned usage)
|
||||
d3d12_video_buffer_from_handle(struct pipe_context *pipe,
|
||||
const struct pipe_video_buffer *tmpl,
|
||||
struct winsys_handle *handle,
|
||||
unsigned usage)
|
||||
{
|
||||
return d3d12_video_buffer_create_impl(pipe, tmpl, handle, usage);
|
||||
struct pipe_video_buffer updated_template = {};
|
||||
if ((handle->format == PIPE_FORMAT_NONE) || (tmpl == nullptr) || (tmpl->buffer_format == PIPE_FORMAT_NONE) ||
|
||||
(tmpl->width == 0) || (tmpl->height == 0)) {
|
||||
ID3D12Resource *d3d12_res = nullptr;
|
||||
if (handle->type == WINSYS_HANDLE_TYPE_D3D12_RES) {
|
||||
d3d12_res = (ID3D12Resource *) handle->com_obj;
|
||||
} else if (handle->type == WINSYS_HANDLE_TYPE_FD) {
|
||||
#ifdef _WIN32
|
||||
HANDLE d3d_handle = handle->handle;
|
||||
#else
|
||||
HANDLE d3d_handle = (HANDLE) (intptr_t) handle->handle;
|
||||
#endif
|
||||
if (FAILED(d3d12_screen(pipe->screen)->dev->OpenSharedHandle(d3d_handle, IID_PPV_ARGS(&d3d12_res)))) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
D3D12_RESOURCE_DESC res_desc = GetDesc(d3d12_res);
|
||||
updated_template.width = res_desc.Width;
|
||||
updated_template.height = res_desc.Height;
|
||||
updated_template.buffer_format = d3d12_get_pipe_format(res_desc.Format);
|
||||
handle->format = updated_template.buffer_format;
|
||||
|
||||
// if passed an external com_ptr (e.g WINSYS_HANDLE_TYPE_D3D12_RES) do not release it
|
||||
if (handle->type == WINSYS_HANDLE_TYPE_FD)
|
||||
d3d12_res->Release();
|
||||
} else {
|
||||
updated_template = *tmpl;
|
||||
}
|
||||
|
||||
return d3d12_video_buffer_create_impl(pipe, &updated_template, handle, usage);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue