Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
b41b6b32
Commit
b41b6b32
authored
Jun 15, 2018
by
Danil Iashchenko
Committed by
Mark Thompson
Jun 17, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
libavfilter/opencl: Add macro for setting opencl kernel arguments
parent
89651c82
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
113 deletions
+46
-113
opencl.h
libavfilter/opencl.h
+15
-0
vf_convolution_opencl.c
libavfilter/vf_convolution_opencl.c
+6
-37
vf_overlay_opencl.c
libavfilter/vf_overlay_opencl.c
+16
-28
vf_unsharp_opencl.c
libavfilter/vf_unsharp_opencl.c
+9
-48
No files found.
libavfilter/opencl.h
View file @
b41b6b32
...
...
@@ -46,6 +46,21 @@ typedef struct OpenCLFilterContext {
int
output_height
;
}
OpenCLFilterContext
;
/**
* set argument to specific Kernel.
* This macro relies on usage of local label "fail" and variables:
* avctx, cle and err.
*/
#define CL_SET_KERNEL_ARG(kernel, arg_num, type, arg) \
cle = clSetKernelArg(kernel, arg_num, sizeof(type), arg); \
if (cle != CL_SUCCESS) { \
av_log(avctx, AV_LOG_ERROR, "Failed to set kernel " \
"argument %d: error %d.\n", arg_num, cle); \
err = AVERROR(EIO); \
goto fail; \
}
/**
* Return that all inputs and outputs support only AV_PIX_FMT_OPENCL.
*/
...
...
libavfilter/vf_convolution_opencl.c
View file @
b41b6b32
...
...
@@ -204,43 +204,12 @@ static int convolution_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
if
(
!
dst
)
break
;
cle
=
clSetKernelArg
(
ctx
->
kernel
,
0
,
sizeof
(
cl_mem
),
&
dst
);
if
(
cle
!=
CL_SUCCESS
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Failed to set kernel "
"destination image argument: %d.
\n
"
,
cle
);
goto
fail
;
}
cle
=
clSetKernelArg
(
ctx
->
kernel
,
1
,
sizeof
(
cl_mem
),
&
src
);
if
(
cle
!=
CL_SUCCESS
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Failed to set kernel "
"source image argument: %d.
\n
"
,
cle
);
goto
fail
;
}
cle
=
clSetKernelArg
(
ctx
->
kernel
,
2
,
sizeof
(
cl_int
),
&
ctx
->
dims
[
p
]);
if
(
cle
!=
CL_SUCCESS
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Failed to set kernel "
"matrix size argument: %d.
\n
"
,
cle
);
goto
fail
;
}
cle
=
clSetKernelArg
(
ctx
->
kernel
,
3
,
sizeof
(
cl_mem
),
&
ctx
->
matrix
[
p
]);
if
(
cle
!=
CL_SUCCESS
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Failed to set kernel "
"matrix argument: %d.
\n
"
,
cle
);
goto
fail
;
}
cle
=
clSetKernelArg
(
ctx
->
kernel
,
4
,
sizeof
(
cl_float
),
&
ctx
->
rdivs
[
p
]);
if
(
cle
!=
CL_SUCCESS
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Failed to set kernel "
"rdiv argument: %d.
\n
"
,
cle
);
goto
fail
;
}
cle
=
clSetKernelArg
(
ctx
->
kernel
,
5
,
sizeof
(
cl_float
),
&
ctx
->
biases
[
p
]);
if
(
cle
!=
CL_SUCCESS
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Failed to set kernel "
"bias argument: %d.
\n
"
,
cle
);
goto
fail
;
}
CL_SET_KERNEL_ARG
(
ctx
->
kernel
,
0
,
cl_mem
,
&
dst
);
CL_SET_KERNEL_ARG
(
ctx
->
kernel
,
1
,
cl_mem
,
&
src
);
CL_SET_KERNEL_ARG
(
ctx
->
kernel
,
2
,
cl_int
,
&
ctx
->
dims
[
p
]);
CL_SET_KERNEL_ARG
(
ctx
->
kernel
,
3
,
cl_mem
,
&
ctx
->
matrix
[
p
]);
CL_SET_KERNEL_ARG
(
ctx
->
kernel
,
4
,
cl_float
,
&
ctx
->
rdivs
[
p
]);
CL_SET_KERNEL_ARG
(
ctx
->
kernel
,
5
,
cl_float
,
&
ctx
->
biases
[
p
]);
err
=
ff_opencl_filter_work_size_from_image
(
avctx
,
global_work
,
output
,
p
,
0
);
if
(
err
<
0
)
...
...
libavfilter/vf_overlay_opencl.c
View file @
b41b6b32
...
...
@@ -167,47 +167,39 @@ static int overlay_opencl_blend(FFFrameSync *fs)
kernel_arg
=
0
;
mem
=
(
cl_mem
)
output
->
data
[
plane
];
cle
=
clSetKernelArg
(
ctx
->
kernel
,
kernel_arg
++
,
sizeof
(
cl_mem
),
&
mem
);
if
(
cle
!=
CL_SUCCESS
)
goto
fail_kernel_arg
;
CL_SET_KERNEL_ARG
(
ctx
->
kernel
,
kernel_arg
,
cl_mem
,
&
mem
);
kernel_arg
++
;
mem
=
(
cl_mem
)
input_main
->
data
[
plane
];
cle
=
clSetKernelArg
(
ctx
->
kernel
,
kernel_arg
++
,
sizeof
(
cl_mem
),
&
mem
);
if
(
cle
!=
CL_SUCCESS
)
goto
fail_kernel_arg
;
CL_SET_KERNEL_ARG
(
ctx
->
kernel
,
kernel_arg
,
cl_mem
,
&
mem
);
kernel_arg
++
;
mem
=
(
cl_mem
)
input_overlay
->
data
[
plane
];
cle
=
clSetKernelArg
(
ctx
->
kernel
,
kernel_arg
++
,
sizeof
(
cl_mem
),
&
mem
);
if
(
cle
!=
CL_SUCCESS
)
goto
fail_kernel_arg
;
CL_SET_KERNEL_ARG
(
ctx
->
kernel
,
kernel_arg
,
cl_mem
,
&
mem
);
kernel_arg
++
;
if
(
ctx
->
alpha_separate
)
{
mem
=
(
cl_mem
)
input_overlay
->
data
[
ctx
->
nb_planes
];
cle
=
clSetKernelArg
(
ctx
->
kernel
,
kernel_arg
++
,
sizeof
(
cl_mem
),
&
mem
);
if
(
cle
!=
CL_SUCCESS
)
goto
fail_kernel_arg
;
CL_SET_KERNEL_ARG
(
ctx
->
kernel
,
kernel_arg
,
cl_mem
,
&
mem
);
kernel_arg
++
;
}
x
=
ctx
->
x_position
/
(
plane
==
0
?
1
:
ctx
->
x_subsample
);
y
=
ctx
->
y_position
/
(
plane
==
0
?
1
:
ctx
->
y_subsample
);
cle
=
clSetKernelArg
(
ctx
->
kernel
,
kernel_arg
++
,
sizeof
(
cl_int
),
&
x
);
if
(
cle
!=
CL_SUCCESS
)
goto
fail_kernel_arg
;
cle
=
clSetKernelArg
(
ctx
->
kernel
,
kernel_arg
++
,
sizeof
(
cl_int
),
&
y
);
if
(
cle
!=
CL_SUCCESS
)
goto
fail_kernel_arg
;
CL_SET_KERNEL_ARG
(
ctx
->
kernel
,
kernel_arg
,
cl_int
,
&
x
);
kernel_arg
++
;
CL_SET_KERNEL_ARG
(
ctx
->
kernel
,
kernel_arg
,
cl_int
,
&
y
);
kernel_arg
++
;
if
(
ctx
->
alpha_separate
)
{
cl_int
alpha_adj_x
=
plane
==
0
?
1
:
ctx
->
x_subsample
;
cl_int
alpha_adj_y
=
plane
==
0
?
1
:
ctx
->
y_subsample
;
cle
=
clSetKernelArg
(
ctx
->
kernel
,
kernel_arg
++
,
sizeof
(
cl_int
),
&
alpha_adj_x
);
if
(
cle
!=
CL_SUCCESS
)
goto
fail_kernel_arg
;
cle
=
clSetKernelArg
(
ctx
->
kernel
,
kernel_arg
++
,
sizeof
(
cl_int
),
&
alpha_adj_y
);
if
(
cle
!=
CL_SUCCESS
)
goto
fail_kernel_arg
;
CL_SET_KERNEL_ARG
(
ctx
->
kernel
,
kernel_arg
,
cl_int
,
&
alpha_adj_x
);
kernel_arg
++
;
CL_SET_KERNEL_ARG
(
ctx
->
kernel
,
kernel_arg
,
cl_int
,
&
alpha_adj_y
);
kernel_arg
++
;
}
err
=
ff_opencl_filter_work_size_from_image
(
avctx
,
global_work
,
...
...
@@ -241,10 +233,6 @@ static int overlay_opencl_blend(FFFrameSync *fs)
return
ff_filter_frame
(
outlink
,
output
);
fail_kernel_arg:
av_log
(
avctx
,
AV_LOG_ERROR
,
"Failed to set kernel arg %d: %d.
\n
"
,
kernel_arg
,
cle
);
err
=
AVERROR
(
EIO
);
fail:
av_frame_free
(
&
output
);
return
err
;
...
...
libavfilter/vf_unsharp_opencl.c
View file @
b41b6b32
...
...
@@ -268,56 +268,17 @@ static int unsharp_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
if
(
!
dst
)
break
;
cle
=
clSetKernelArg
(
ctx
->
kernel
,
0
,
sizeof
(
cl_mem
),
&
dst
);
if
(
cle
!=
CL_SUCCESS
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Failed to set kernel "
"destination image argument: %d.
\n
"
,
cle
);
goto
fail
;
}
cle
=
clSetKernelArg
(
ctx
->
kernel
,
1
,
sizeof
(
cl_mem
),
&
src
);
if
(
cle
!=
CL_SUCCESS
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Failed to set kernel "
"source image argument: %d.
\n
"
,
cle
);
goto
fail
;
}
cle
=
clSetKernelArg
(
ctx
->
kernel
,
2
,
sizeof
(
cl_int
),
&
ctx
->
plane
[
p
].
size_x
);
if
(
cle
!=
CL_SUCCESS
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Failed to set kernel "
"matrix size argument: %d.
\n
"
,
cle
);
goto
fail
;
}
cle
=
clSetKernelArg
(
ctx
->
kernel
,
3
,
sizeof
(
cl_int
),
&
ctx
->
plane
[
p
].
size_y
);
if
(
cle
!=
CL_SUCCESS
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Failed to set kernel "
"matrix size argument: %d.
\n
"
,
cle
);
goto
fail
;
}
cle
=
clSetKernelArg
(
ctx
->
kernel
,
4
,
sizeof
(
cl_float
),
&
ctx
->
plane
[
p
].
amount
);
if
(
cle
!=
CL_SUCCESS
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Failed to set kernel "
"amount argument: %d.
\n
"
,
cle
);
goto
fail
;
}
CL_SET_KERNEL_ARG
(
ctx
->
kernel
,
0
,
cl_mem
,
&
dst
);
CL_SET_KERNEL_ARG
(
ctx
->
kernel
,
1
,
cl_mem
,
&
src
);
CL_SET_KERNEL_ARG
(
ctx
->
kernel
,
2
,
cl_int
,
&
ctx
->
plane
[
p
].
size_x
);
CL_SET_KERNEL_ARG
(
ctx
->
kernel
,
3
,
cl_int
,
&
ctx
->
plane
[
p
].
size_y
);
CL_SET_KERNEL_ARG
(
ctx
->
kernel
,
4
,
cl_float
,
&
ctx
->
plane
[
p
].
amount
);
if
(
ctx
->
global
)
{
cle
=
clSetKernelArg
(
ctx
->
kernel
,
5
,
sizeof
(
cl_mem
),
&
ctx
->
plane
[
p
].
matrix
);
if
(
cle
!=
CL_SUCCESS
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Failed to set kernel "
"matrix argument: %d.
\n
"
,
cle
);
goto
fail
;
}
CL_SET_KERNEL_ARG
(
ctx
->
kernel
,
5
,
cl_mem
,
&
ctx
->
plane
[
p
].
matrix
);
}
else
{
cle
=
clSetKernelArg
(
ctx
->
kernel
,
5
,
sizeof
(
cl_mem
),
&
ctx
->
plane
[
p
].
coef_x
);
if
(
cle
!=
CL_SUCCESS
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Failed to set kernel "
"x-coef argument: %d.
\n
"
,
cle
);
goto
fail
;
}
cle
=
clSetKernelArg
(
ctx
->
kernel
,
6
,
sizeof
(
cl_mem
),
&
ctx
->
plane
[
p
].
coef_y
);
if
(
cle
!=
CL_SUCCESS
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Failed to set kernel "
"y-coef argument: %d.
\n
"
,
cle
);
goto
fail
;
}
CL_SET_KERNEL_ARG
(
ctx
->
kernel
,
5
,
cl_mem
,
&
ctx
->
plane
[
p
].
coef_x
);
CL_SET_KERNEL_ARG
(
ctx
->
kernel
,
6
,
cl_mem
,
&
ctx
->
plane
[
p
].
coef_y
);
}
err
=
ff_opencl_filter_work_size_from_image
(
avctx
,
global_work
,
output
,
p
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment