History

avutil/hwcontext_opencl: Allocate pub and priv frames hwctx together

This is possible because the lifetime of both coincide. Besides reducing the number of allocations this also simplifies access to OpenCLFramesContext as one no longer has to go through AVHWFramesInternal.

Andreas Rheinhardt committed 2 years ago

Commit c0a1ce11 parent c305dbf1 file · +21 −17Browse files

Unified · Split

libavutil/hwcontext_opencl.c+21−17
@@ -143,6 +143,11 @@ typedef struct OpenCLDeviceContext { · 142 unmodified lines
143143 } OpenCLDeviceContext;
144144
145145 typedef struct OpenCLFramesContext {
146+ /**
147+ * The public AVOpenCLFramesContext. See hwcontext_opencl.h for it.
148+ */
149+ AVOpenCLFramesContext p;
150+
146151 // Command queue used for transfer/mapping operations on this frames
147152 // context. If the user supplies one, this is a reference to it.
148153 // Otherwise, it is a reference to the default command queue for the
@@ -1700,9 +1705,9 @@ fail: · 1551 unmodified lines
17001705
17011706 static int opencl_frames_init_command_queue(AVHWFramesContext *hwfc)
17021707 {
1703− AVOpenCLFramesContext *hwctx = hwfc->hwctx;
1708+ OpenCLFramesContext *priv = hwfc->hwctx;
1709+ AVOpenCLFramesContext *hwctx = &priv->p;
17041710 OpenCLDeviceContext *devpriv = hwfc->device_ctx->hwctx;
1705− OpenCLFramesContext *priv = hwfc->internal->priv;
17061711 cl_int cle;
17071712
17081713 priv->command_queue = hwctx->command_queue ? hwctx->command_queue
@@ -1732,7 +1737,7 @@ static int opencl_frames_init(AVHWFramesContext *hwfc) · 23 unmodified lines
17321737
17331738 static void opencl_frames_uninit(AVHWFramesContext *hwfc)
17341739 {
1735− OpenCLFramesContext *priv = hwfc->internal->priv;
1740+ OpenCLFramesContext *priv = hwfc->hwctx;
17361741 cl_int cle;
17371742
17381743 #if HAVE_OPENCL_DXVA2 || HAVE_OPENCL_D3D11
@@ -1826,7 +1831,7 @@ static int opencl_wait_events(AVHWFramesContext *hwfc, · 87 unmodified lines
18261831 static int opencl_transfer_data_from(AVHWFramesContext *hwfc,
18271832 AVFrame *dst, const AVFrame *src)
18281833 {
1829− OpenCLFramesContext *priv = hwfc->internal->priv;
1834+ OpenCLFramesContext *priv = hwfc->hwctx;
18301835 cl_image_format image_format;
18311836 cl_image_desc image_desc;
18321837 cl_int cle;
@@ -1881,7 +1886,7 @@ static int opencl_transfer_data_from(AVHWFramesContext *hwfc, · 48 unmodified lines
18811886 static int opencl_transfer_data_to(AVHWFramesContext *hwfc,
18821887 AVFrame *dst, const AVFrame *src)
18831888 {
1884− OpenCLFramesContext *priv = hwfc->internal->priv;
1889+ OpenCLFramesContext *priv = hwfc->hwctx;
18851890 cl_image_format image_format;
18861891 cl_image_desc image_desc;
18871892 cl_int cle;
@@ -1943,7 +1948,7 @@ typedef struct OpenCLMapping { · 55 unmodified lines
19431948 static void opencl_unmap_frame(AVHWFramesContext *hwfc,
19441949 HWMapDescriptor *hwmap)
19451950 {
1946− OpenCLFramesContext *priv = hwfc->internal->priv;
1951+ OpenCLFramesContext *priv = hwfc->hwctx;
19471952 OpenCLMapping *map = hwmap->priv;
19481953 cl_event events[AV_NUM_DATA_POINTERS];
19491954 int p, e;
@@ -1972,7 +1977,7 @@ static void opencl_unmap_frame(AVHWFramesContext *hwfc, · 22 unmodified lines
19721977 static int opencl_map_frame(AVHWFramesContext *hwfc, AVFrame *dst,
19731978 const AVFrame *src, int flags)
19741979 {
1975− OpenCLFramesContext *priv = hwfc->internal->priv;
1980+ OpenCLFramesContext *priv = hwfc->hwctx;
19761981 cl_map_flags map_flags;
19771982 cl_image_format image_format;
19781983 cl_image_desc image_desc;
@@ -2229,7 +2234,7 @@ static void opencl_unmap_from_qsv(AVHWFramesContext *dst_fc, · 250 unmodified lines
22292234 {
22302235 AVOpenCLFrameDescriptor *desc = hwmap->priv;
22312236 OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
2232− OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
2237+ OpenCLFramesContext *frames_priv = dst_fc->hwctx;
22332238 cl_event event;
22342239 cl_int cle;
22352240 int p;
@@ -2265,7 +2270,7 @@ static int opencl_map_from_qsv(AVHWFramesContext *dst_fc, AVFrame *dst, · 29 unmodified lines
22652270 (AVHWFramesContext*)src->hw_frames_ctx->data;
22662271 OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
22672272 AVOpenCLDeviceContext *dst_dev = &device_priv->p;
2268− OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
2273+ OpenCLFramesContext *frames_priv = dst_fc->hwctx;
22692274 AVOpenCLFrameDescriptor *desc;
22702275 VASurfaceID va_surface;
22712276 cl_mem_flags cl_flags;
@@ -2363,7 +2368,7 @@ static void opencl_unmap_from_dxva2(AVHWFramesContext *dst_fc, · 91 unmodified lines
23632368 {
23642369 AVOpenCLFrameDescriptor *desc = hwmap->priv;
23652370 OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
2366− OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
2371+ OpenCLFramesContext *frames_priv = dst_fc->hwctx;
23672372 cl_event event;
23682373 cl_int cle;
23692374
@@ -2388,7 +2393,7 @@ static int opencl_map_from_dxva2(AVHWFramesContext *dst_fc, AVFrame *dst, · 18 unmodified lines
23882393 (AVHWFramesContext*)src->hw_frames_ctx->data;
23892394 AVDXVA2FramesContext *src_hwctx = src_fc->hwctx;
23902395 OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
2391− OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
2396+ OpenCLFramesContext *frames_priv = dst_fc->hwctx;
23922397 AVOpenCLFrameDescriptor *desc;
23932398 cl_event event;
23942399 cl_int cle;
@@ -2451,7 +2456,7 @@ static int opencl_frames_derive_from_dxva2(AVHWFramesContext *dst_fc, · 56 unmodified lines
24512456 AVDXVA2FramesContext *src_hwctx = src_fc->hwctx;
24522457 OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
24532458 AVOpenCLDeviceContext *dst_dev = &device_priv->p;
2454− OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
2459+ OpenCLFramesContext *frames_priv = dst_fc->hwctx;
24552460 cl_mem_flags cl_flags;
24562461 cl_int cle;
24572462 int err, i, p, nb_planes;
@@ -2528,7 +2533,7 @@ static void opencl_unmap_from_d3d11(AVHWFramesContext *dst_fc, · 70 unmodified lines
25282533 {
25292534 AVOpenCLFrameDescriptor *desc = hwmap->priv;
25302535 OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
2531− OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
2536+ OpenCLFramesContext *frames_priv = dst_fc->hwctx;
25322537 cl_event event;
25332538 cl_int cle;
25342539
@@ -2547,7 +2552,7 @@ static int opencl_map_from_d3d11(AVHWFramesContext *dst_fc, AVFrame *dst, · 12 unmodified lines
25472552 const AVFrame *src, int flags)
25482553 {
25492554 OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
2550− OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
2555+ OpenCLFramesContext *frames_priv = dst_fc->hwctx;
25512556 AVOpenCLFrameDescriptor *desc;
25522557 cl_event event;
25532558 cl_int cle;
@@ -2607,7 +2612,7 @@ static int opencl_frames_derive_from_d3d11(AVHWFramesContext *dst_fc, · 53 unmodified lines
26072612 AVD3D11VAFramesContext *src_hwctx = src_fc->hwctx;
26082613 OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
26092614 AVOpenCLDeviceContext *dst_dev = &device_priv->p;
2610− OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
2615+ OpenCLFramesContext *frames_priv = dst_fc->hwctx;
26112616 cl_mem_flags cl_flags;
26122617 cl_int cle;
26132618 int err, i, p, nb_planes;
@@ -3036,8 +3041,7 @@ const HWContextType ff_hwcontext_type_opencl = { · 422 unmodified lines
30363041 .name = "OpenCL",
30373042
30383043 .device_hwctx_size = sizeof(OpenCLDeviceContext),
3039− .frames_hwctx_size = sizeof(AVOpenCLFramesContext),
3040− .frames_priv_size = sizeof(OpenCLFramesContext),
3044+ .frames_hwctx_size = sizeof(OpenCLFramesContext),
30413045
30423046 .device_create = &opencl_device_create,
30433047 .device_derive = &opencl_device_derive,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t