aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2024-02-11 17:26:54 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2024-03-04 00:04:38 +0100
commitc305dbf745a7ce8f8f47bab33605b31d3879128f (patch)
treea8c9609cc4c650e860c2e92df89d771b69c1e059
parent1b7308b61db02fb2475585933a146253c87812de (diff)
downloadffmpeg-c305dbf745a7ce8f8f47bab33605b31d3879128f.tar.gz
avutil/hwcontext_opencl: Allocate pub and priv device hwctx together
This is possible because the lifetime of both coincide. Besides reducing the number of allocations this also simplifies access to OpenCLDeviceContext as one no longer has to go through AVHWDeviceInternal. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
-rw-r--r--libavutil/hwcontext_opencl.c50
1 files changed, 27 insertions, 23 deletions
diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c
index efd8d0e094..a089e32107 100644
--- a/libavutil/hwcontext_opencl.c
+++ b/libavutil/hwcontext_opencl.c
@@ -85,6 +85,11 @@ extern int ff_qsv_get_surface_base_handle(mfxFrameSurface1 *surf,
typedef struct OpenCLDeviceContext {
+ /**
+ * The public AVOpenCLDeviceContext. See hwcontext_opencl.h for it.
+ */
+ AVOpenCLDeviceContext p;
+
// Default command queue to use for transfer/mapping operations on
// the device. If the user supplies one, this is a reference to it.
// Otherwise, it is newly-created.
@@ -281,8 +286,8 @@ static int opencl_check_device_extension(cl_device_id device_id,
static av_unused int opencl_check_extension(AVHWDeviceContext *hwdev,
const char *name)
{
- AVOpenCLDeviceContext *hwctx = hwdev->hwctx;
- OpenCLDeviceContext *priv = hwdev->internal->priv;
+ OpenCLDeviceContext *priv = hwdev->hwctx;
+ AVOpenCLDeviceContext *hwctx = &priv->p;
if (opencl_check_platform_extension(priv->platform_id, name)) {
av_log(hwdev, AV_LOG_DEBUG,
@@ -663,8 +668,8 @@ static int opencl_device_create(AVHWDeviceContext *hwdev, const char *device,
static int opencl_device_init(AVHWDeviceContext *hwdev)
{
- AVOpenCLDeviceContext *hwctx = hwdev->hwctx;
- OpenCLDeviceContext *priv = hwdev->internal->priv;
+ OpenCLDeviceContext *priv = hwdev->hwctx;
+ AVOpenCLDeviceContext *hwctx = &priv->p;
cl_int cle;
if (hwctx->command_queue) {
@@ -899,7 +904,7 @@ static int opencl_device_init(AVHWDeviceContext *hwdev)
static void opencl_device_uninit(AVHWDeviceContext *hwdev)
{
- OpenCLDeviceContext *priv = hwdev->internal->priv;
+ OpenCLDeviceContext *priv = hwdev->hwctx;
cl_int cle;
if (priv->command_queue) {
@@ -1696,7 +1701,7 @@ fail:
static int opencl_frames_init_command_queue(AVHWFramesContext *hwfc)
{
AVOpenCLFramesContext *hwctx = hwfc->hwctx;
- OpenCLDeviceContext *devpriv = hwfc->device_ctx->internal->priv;
+ OpenCLDeviceContext *devpriv = hwfc->device_ctx->hwctx;
OpenCLFramesContext *priv = hwfc->internal->priv;
cl_int cle;
@@ -2091,8 +2096,8 @@ static int opencl_map_from_drm_beignet(AVHWFramesContext *dst_fc,
AVFrame *dst, const AVFrame *src,
int flags)
{
- AVOpenCLDeviceContext *hwctx = dst_fc->device_ctx->hwctx;
- OpenCLDeviceContext *priv = dst_fc->device_ctx->internal->priv;
+ OpenCLDeviceContext *priv = dst_fc->device_ctx->hwctx;
+ AVOpenCLDeviceContext *hwctx = &priv->p;
DRMBeignetToOpenCLMapping *mapping;
const AVDRMFrameDescriptor *desc;
cl_int cle;
@@ -2223,7 +2228,7 @@ static void opencl_unmap_from_qsv(AVHWFramesContext *dst_fc,
HWMapDescriptor *hwmap)
{
AVOpenCLFrameDescriptor *desc = hwmap->priv;
- OpenCLDeviceContext *device_priv = dst_fc->device_ctx->internal->priv;
+ OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
cl_event event;
cl_int cle;
@@ -2258,8 +2263,8 @@ static int opencl_map_from_qsv(AVHWFramesContext *dst_fc, AVFrame *dst,
{
AVHWFramesContext *src_fc =
(AVHWFramesContext*)src->hw_frames_ctx->data;
- AVOpenCLDeviceContext *dst_dev = dst_fc->device_ctx->hwctx;
- OpenCLDeviceContext *device_priv = dst_fc->device_ctx->internal->priv;
+ OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
+ AVOpenCLDeviceContext *dst_dev = &device_priv->p;
OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
AVOpenCLFrameDescriptor *desc;
VASurfaceID va_surface;
@@ -2357,7 +2362,7 @@ static void opencl_unmap_from_dxva2(AVHWFramesContext *dst_fc,
HWMapDescriptor *hwmap)
{
AVOpenCLFrameDescriptor *desc = hwmap->priv;
- OpenCLDeviceContext *device_priv = dst_fc->device_ctx->internal->priv;
+ OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
cl_event event;
cl_int cle;
@@ -2382,7 +2387,7 @@ static int opencl_map_from_dxva2(AVHWFramesContext *dst_fc, AVFrame *dst,
AVHWFramesContext *src_fc =
(AVHWFramesContext*)src->hw_frames_ctx->data;
AVDXVA2FramesContext *src_hwctx = src_fc->hwctx;
- OpenCLDeviceContext *device_priv = dst_fc->device_ctx->internal->priv;
+ OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
AVOpenCLFrameDescriptor *desc;
cl_event event;
@@ -2443,9 +2448,9 @@ fail:
static int opencl_frames_derive_from_dxva2(AVHWFramesContext *dst_fc,
AVHWFramesContext *src_fc, int flags)
{
- AVOpenCLDeviceContext *dst_dev = dst_fc->device_ctx->hwctx;
AVDXVA2FramesContext *src_hwctx = src_fc->hwctx;
- OpenCLDeviceContext *device_priv = dst_fc->device_ctx->internal->priv;
+ OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
+ AVOpenCLDeviceContext *dst_dev = &device_priv->p;
OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
cl_mem_flags cl_flags;
cl_int cle;
@@ -2522,7 +2527,7 @@ static void opencl_unmap_from_d3d11(AVHWFramesContext *dst_fc,
HWMapDescriptor *hwmap)
{
AVOpenCLFrameDescriptor *desc = hwmap->priv;
- OpenCLDeviceContext *device_priv = dst_fc->device_ctx->internal->priv;
+ OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
cl_event event;
cl_int cle;
@@ -2541,7 +2546,7 @@ static void opencl_unmap_from_d3d11(AVHWFramesContext *dst_fc,
static int opencl_map_from_d3d11(AVHWFramesContext *dst_fc, AVFrame *dst,
const AVFrame *src, int flags)
{
- OpenCLDeviceContext *device_priv = dst_fc->device_ctx->internal->priv;
+ OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
AVOpenCLFrameDescriptor *desc;
cl_event event;
@@ -2599,9 +2604,9 @@ fail:
static int opencl_frames_derive_from_d3d11(AVHWFramesContext *dst_fc,
AVHWFramesContext *src_fc, int flags)
{
- AVOpenCLDeviceContext *dst_dev = dst_fc->device_ctx->hwctx;
AVD3D11VAFramesContext *src_hwctx = src_fc->hwctx;
- OpenCLDeviceContext *device_priv = dst_fc->device_ctx->internal->priv;
+ OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
+ AVOpenCLDeviceContext *dst_dev = &device_priv->p;
OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
cl_mem_flags cl_flags;
cl_int cle;
@@ -2920,7 +2925,7 @@ static int opencl_map_from(AVHWFramesContext *hwfc, AVFrame *dst,
static int opencl_map_to(AVHWFramesContext *hwfc, AVFrame *dst,
const AVFrame *src, int flags)
{
- av_unused OpenCLDeviceContext *priv = hwfc->device_ctx->internal->priv;
+ av_unused OpenCLDeviceContext *priv = hwfc->device_ctx->hwctx;
av_assert0(dst->format == AV_PIX_FMT_OPENCL);
switch (src->format) {
#if HAVE_OPENCL_DRM_BEIGNET
@@ -2965,7 +2970,7 @@ static int opencl_map_to(AVHWFramesContext *hwfc, AVFrame *dst,
static int opencl_frames_derive_to(AVHWFramesContext *dst_fc,
AVHWFramesContext *src_fc, int flags)
{
- av_unused OpenCLDeviceContext *priv = dst_fc->device_ctx->internal->priv;
+ av_unused OpenCLDeviceContext *priv = dst_fc->device_ctx->hwctx;
switch (src_fc->device_ctx->type) {
#if HAVE_OPENCL_DRM_BEIGNET
case AV_HWDEVICE_TYPE_DRM:
@@ -3030,8 +3035,7 @@ const HWContextType ff_hwcontext_type_opencl = {
.type = AV_HWDEVICE_TYPE_OPENCL,
.name = "OpenCL",
- .device_hwctx_size = sizeof(AVOpenCLDeviceContext),
- .device_priv_size = sizeof(OpenCLDeviceContext),
+ .device_hwctx_size = sizeof(OpenCLDeviceContext),
.frames_hwctx_size = sizeof(AVOpenCLFramesContext),
.frames_priv_size = sizeof(OpenCLFramesContext),